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

37 lines
1.1 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
import Flash from './flash';
import { __ } from '~/locale';
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');
const form = $(this)
.parents('.notification-form')
.first();
2017-12-15 04:31:58 -05:00
form.find('.js-notification-loading').toggleClass('fa-bell fa-spin fa-spinner');
if (form.hasClass('no-label')) {
form.find('.js-notification-loading').toggleClass('hidden');
form.find('.js-notifications-icon').toggleClass('hidden');
}
2017-12-15 04:31:58 -05:00
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);
2017-12-15 04:31:58 -05:00
} else {
Flash(__('Failed to save new settings'), 'alert');
2017-12-15 04:31:58 -05:00
}
});
}