2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-10-02 08:32:53 -04:00
|
|
|
import Flash from './flash';
|
2019-04-03 12:15:15 -04:00
|
|
|
import { __ } from '~/locale';
|
2016-12-14 00:26:26 -05:00
|
|
|
|
2017-12-15 04:31:58 -05:00
|
|
|
export default function notificationsDropdown() {
|
|
|
|
$(document).on('click', '.update-notification', function updateNotificationCallback(e) {
|
|
|
|
e.preventDefault();
|
2019-03-27 17:33:20 -04:00
|
|
|
|
2018-02-20 17:20:48 -05:00
|
|
|
if ($(this).is('.is-active') && $(this).data('notificationLevel') === 'custom') {
|
2017-12-15 04:31:58 -05:00
|
|
|
return;
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
|
2018-02-20 17:20:48 -05:00
|
|
|
const notificationLevel = $(this).data('notificationLevel');
|
2017-12-15 04:31:58 -05:00
|
|
|
const form = $(this).parents('.notification-form:first');
|
|
|
|
|
|
|
|
form.find('.js-notification-loading').toggleClass('fa-bell fa-spin fa-spinner');
|
2018-12-07 09:11:42 -05:00
|
|
|
if (form.hasClass('no-label')) {
|
|
|
|
form.find('.js-notification-loading').toggleClass('hidden');
|
|
|
|
form.find('.js-notifications-icon').toggleClass('hidden');
|
|
|
|
}
|
2017-12-15 04:31:58 -05:00
|
|
|
form.find('#notification_setting_level').val(notificationLevel);
|
|
|
|
form.submit();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('ajax:success', '.notification-form', (e, data) => {
|
|
|
|
if (data.saved) {
|
2018-10-10 03:13:34 -04:00
|
|
|
$(e.currentTarget)
|
|
|
|
.closest('.js-notification-dropdown')
|
|
|
|
.replaceWith(data.html);
|
2017-12-15 04:31:58 -05:00
|
|
|
} else {
|
2019-04-03 12:15:15 -04:00
|
|
|
Flash(__('Failed to save new settings'), 'alert');
|
2017-12-15 04:31:58 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|