BigW Consortium Gitlab

notifications_dropdown.js 1.38 KB
Newer Older
1
/* 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 */
2 3
/* global Flash */

Fatih Acet committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
(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) {
22
          return $(e.currentTarget).closest('.js-notification-dropdown').replaceWith(data.html);
Fatih Acet committed
23 24 25 26 27 28 29 30
        } else {
          return new Flash('Failed to save new settings', 'alert');
        }
      });
    }

    return NotificationsDropdown;
  })();
31
}).call(window);