fa2af5e0f5
Reduced the technical debt around our JS flash function by making it a module that is imported rather than relying on the global function. The global function still exists mainly for technical debt with how some requests are being completed, but new JS should import the module directly. Also reduces some tech debt in the file by removing the need for jQuery. Instead Flash is now 100% vanilla JS.
31 lines
1.4 KiB
JavaScript
31 lines
1.4 KiB
JavaScript
/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, one-var-declaration-per-line, no-unused-vars, consistent-return, prefer-arrow-callback, no-else-return, max-len */
|
|
import Flash from './flash';
|
|
|
|
(function() {
|
|
this.NotificationsDropdown = (function() {
|
|
function NotificationsDropdown() {
|
|
$(document).off('click', '.update-notification').on('click', '.update-notification', function(e) {
|
|
var form, label, notificationLevel;
|
|
e.preventDefault();
|
|
if ($(this).is('.is-active') && $(this).data('notification-level') === 'custom') {
|
|
return;
|
|
}
|
|
notificationLevel = $(this).data('notification-level');
|
|
label = $(this).data('notification-title');
|
|
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);
|
|
return form.submit();
|
|
});
|
|
$(document).off('ajax:success', '.notification-form').on('ajax:success', '.notification-form', function(e, data) {
|
|
if (data.saved) {
|
|
return $(e.currentTarget).closest('.js-notification-dropdown').replaceWith(data.html);
|
|
} else {
|
|
return new Flash('Failed to save new settings', 'alert');
|
|
}
|
|
});
|
|
}
|
|
|
|
return NotificationsDropdown;
|
|
})();
|
|
}).call(window);
|