gitlab-org--gitlab-foss/app/assets/javascripts/notifications_dropdown.js

27 lines
892 B
JavaScript
Raw Normal View History

import $ from 'jquery';
import Flash from './flash';
2017-12-15 04:31:58 -05:00
export default function notificationsDropdown() {
$(document).on('click', '.update-notification', function updateNotificationCallback(e) {
e.preventDefault();
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');
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');
}
});
}