2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-10-02 08:32:53 -04:00
|
|
|
import Flash from './flash';
|
2016-12-14 00:26:26 -05:00
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|