2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { Rails } from '~/lib/utils/rails_ujs';
|
2019-07-07 11:18:12 +05:30
|
|
|
import { __ } from '~/locale';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { deprecatedCreateFlash as Flash } from './flash';
|
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');
|
2021-03-08 18:12:59 +05:30
|
|
|
const form = $(this).parents('.notification-form').first();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
form.find('.js-notification-loading').toggleClass('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);
|
2021-01-03 14:25:43 +05:30
|
|
|
Rails.fire(form[0], 'submit');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
$(document).on('ajax:success', '.notification-form', (e) => {
|
2021-01-03 14:25:43 +05:30
|
|
|
const data = e.detail[0];
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if (data.saved) {
|
2021-03-08 18:12:59 +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
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|