debian-mirror-gitlab/app/assets/javascripts/service_ping_consent.js

36 lines
1,018 B
JavaScript
Raw Normal View History

2018-11-20 20:47:30 +05:30
import $ from 'jquery';
2021-09-30 23:02:18 +05:30
import createFlash, { hideFlash } from './flash';
2021-03-11 19:13:27 +05:30
import axios from './lib/utils/axios_utils';
2019-02-15 15:39:39 +05:30
import { parseBoolean } from './lib/utils/common_utils';
2019-09-04 21:01:54 +05:30
import { __ } from './locale';
2018-11-20 20:47:30 +05:30
export default () => {
2021-09-30 23:02:18 +05:30
$('body').on('click', '.js-service-ping-consent-action', (e) => {
2018-11-20 20:47:30 +05:30
e.preventDefault();
e.stopImmediatePropagation(); // overwrite rails listener
2021-09-30 23:02:18 +05:30
const { url, checkEnabled, servicePingEnabled } = e.target.dataset;
2018-11-20 20:47:30 +05:30
const data = {
application_setting: {
2019-02-15 15:39:39 +05:30
version_check_enabled: parseBoolean(checkEnabled),
2021-09-30 23:02:18 +05:30
service_ping_enabled: parseBoolean(servicePingEnabled),
2018-11-20 20:47:30 +05:30
},
};
2021-09-30 23:02:18 +05:30
const hideConsentMessage = () =>
hideFlash(document.querySelector('.service-ping-consent-message'));
2018-11-20 20:47:30 +05:30
2018-12-13 13:39:08 +05:30
axios
.put(url, data)
2018-11-20 20:47:30 +05:30
.then(() => {
hideConsentMessage();
})
.catch(() => {
hideConsentMessage();
2021-09-30 23:02:18 +05:30
createFlash({
message: __('Something went wrong. Try again later.'),
});
2018-11-20 20:47:30 +05:30
});
});
};