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