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

40 lines
1.2 KiB
JavaScript
Raw Normal View History

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';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as 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
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-01-03 14:25:43 +05:30
$(document).on('ajax:success', '.notification-form', e => {
const data = e.detail[0];
2018-03-17 18:26:18 +05:30
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
}
});
}