2017-01-10 18:02:20 -05:00
|
|
|
/* 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 */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Flash */
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(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) {
|
2016-12-18 15:07:06 -05:00
|
|
|
return $(e.currentTarget).closest('.js-notification-dropdown').replaceWith(data.html);
|
2016-07-24 16:45:11 -04:00
|
|
|
} else {
|
|
|
|
return new Flash('Failed to save new settings', 'alert');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return NotificationsDropdown;
|
|
|
|
})();
|
|
|
|
}).call(this);
|