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

27 lines
892 B
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import 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();
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');
2018-03-17 18:26:18 +05:30
const form = $(this).parents('.notification-form:first');
form.find('.js-notification-loading').toggleClass('fa-bell fa-spin fa-spinner');
form.find('#notification_setting_level').val(notificationLevel);
form.submit();
});
$(document).on('ajax:success', '.notification-form', (e, data) => {
if (data.saved) {
$(e.currentTarget).closest('.js-notification-dropdown').replaceWith(data.html);
} else {
Flash('Failed to save new settings', 'alert');
}
});
}