notifications_dropdown.js 910 字节
Newer Older
1
import $ from 'jquery';
P
Phil Hughes 已提交
2
import Flash from './flash';
3

P
Phil Hughes 已提交
4 5 6
export default function notificationsDropdown() {
  $(document).on('click', '.update-notification', function updateNotificationCallback(e) {
    e.preventDefault();
J
Jacob Schatz 已提交
7
    if ($(this).is('.is-active') && $(this).data('notificationLevel') === 'custom') {
P
Phil Hughes 已提交
8
      return;
F
Fatih Acet 已提交
9 10
    }

J
Jacob Schatz 已提交
11
    const notificationLevel = $(this).data('notificationLevel');
P
Phil Hughes 已提交
12 13 14 15 16 17 18 19 20
    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) {
21 22 23
      $(e.currentTarget)
        .closest('.js-notification-dropdown')
        .replaceWith(data.html);
P
Phil Hughes 已提交
24 25 26 27 28
    } else {
      Flash('Failed to save new settings', 'alert');
    }
  });
}