summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notifications_dropdown.js.coffee
blob: 74d2298c1fa74bbf4f5110b90340e51519d89a4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class @NotificationsDropdown
  $ ->
    $(document)
      .off 'click', '.update-notification'
      .on 'click', '.update-notification', (e) ->
        e.preventDefault()

        return if $(this).is('.is-active') and $(this).data('notification-level') is 'custom'

        notificationLevel = $(@).data 'notification-level'
        label = $(@).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)
        form.submit()

    $(document)
      .off 'ajax:success', '.notification-form'
      .on 'ajax:success', '.notification-form', (e, data) ->
        if data.saved
          new Flash('Notification settings saved', 'notice')
          $(e.currentTarget).closest('.notification-dropdown').replaceWith(data.html)
        else
          new Flash('Failed to save new settings', 'alert')