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

32 lines
900 B
JavaScript
Raw Normal View History

2018-11-20 20:47:30 +05:30
import $ from 'jquery';
import axios from './lib/utils/axios_utils';
import Flash, { hideFlash } from './flash';
2019-02-15 15:39:39 +05:30
import { parseBoolean } from './lib/utils/common_utils';
2018-11-20 20:47:30 +05:30
export default () => {
2018-12-13 13:39:08 +05:30
$('body').on('click', '.js-usage-consent-action', e => {
2018-11-20 20:47:30 +05:30
e.preventDefault();
e.stopImmediatePropagation(); // overwrite rails listener
const { url, checkEnabled, pingEnabled } = e.target.dataset;
const data = {
application_setting: {
2019-02-15 15:39:39 +05:30
version_check_enabled: parseBoolean(checkEnabled),
usage_ping_enabled: parseBoolean(pingEnabled),
2018-11-20 20:47:30 +05:30
},
};
const hideConsentMessage = () => hideFlash(document.querySelector('.ping-consent-message'));
2018-12-13 13:39:08 +05:30
axios
.put(url, data)
2018-11-20 20:47:30 +05:30
.then(() => {
hideConsentMessage();
})
.catch(() => {
hideConsentMessage();
Flash('Something went wrong. Try again later.');
});
});
};