summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-06-14 15:36:36 -0300
committerFelipe Artur <felipefac@gmail.com>2016-06-16 23:34:21 -0300
commitf82ab42d0534950c1ceb458e0152f329df80ae9d (patch)
treefbb3d51a8d2c899eb5037176ff3c247b09b68793 /app/assets/javascripts
parent5c45d5933faa0cc27e1b465322067bd2861b3e47 (diff)
downloadgitlab-ce-f82ab42d0534950c1ceb458e0152f329df80ae9d.tar.gz
Re-use notifications dropdown on user profile
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/dispatcher.js.coffee3
-rw-r--r--app/assets/javascripts/notifications_dropdown.js.coffee21
-rw-r--r--app/assets/javascripts/notifications_form.js.coffee13
-rw-r--r--app/assets/javascripts/profile.js.coffee4
-rw-r--r--app/assets/javascripts/project.js.coffee21
5 files changed, 35 insertions, 27 deletions
diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee
index ad0d2617294..404101710b9 100644
--- a/app/assets/javascripts/dispatcher.js.coffee
+++ b/app/assets/javascripts/dispatcher.js.coffee
@@ -126,6 +126,8 @@ class Dispatcher
shortcut_handler = new ShortcutsDashboardNavigation()
when 'profiles'
new Profile()
+ new NotificationsForm()
+ new NotificationsDropdown()
when 'projects'
new Project()
new ProjectAvatar()
@@ -139,6 +141,7 @@ class Dispatcher
new ProjectNew()
when 'show'
new ProjectShow()
+ new NotificationsDropdown()
when 'wikis'
new Wikis()
shortcut_handler = new ShortcutsNavigation()
diff --git a/app/assets/javascripts/notifications_dropdown.js.coffee b/app/assets/javascripts/notifications_dropdown.js.coffee
new file mode 100644
index 00000000000..15daf027c0a
--- /dev/null
+++ b/app/assets/javascripts/notifications_dropdown.js.coffee
@@ -0,0 +1,21 @@
+class @NotificationsDropdown
+ $ ->
+ $(document)
+ .off 'click', '.update-notification'
+ .on 'click', '.update-notification', (e) ->
+ e.preventDefault()
+ notificationLevel = $(@).data 'notification-level'
+ label = $(@).data 'notification-title'
+ form = $(this).parents('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')
diff --git a/app/assets/javascripts/notifications_form.js.coffee b/app/assets/javascripts/notifications_form.js.coffee
index cfe8e133b66..51faa5fcace 100644
--- a/app/assets/javascripts/notifications_form.js.coffee
+++ b/app/assets/javascripts/notifications_form.js.coffee
@@ -1,7 +1,5 @@
class @NotificationsForm
constructor: ->
- @form = $('.custom-notifications-form')
-
@removeEventListeners()
@initEventListeners()
@@ -14,7 +12,7 @@ class @NotificationsForm
toggleCheckbox: (e) =>
$checkbox = $(e.currentTarget)
$parent = $checkbox.closest('.checkbox')
-
+ console.log($parent)
@saveEvent($checkbox, $parent)
showCheckboxLoadingSpinner: ($parent) ->
@@ -26,11 +24,14 @@ class @NotificationsForm
.removeClass 'is-done'
saveEvent: ($checkbox, $parent) ->
+ form = $parent.parents('form:first')
+ console.log(form)
+
$.ajax(
- url: @form.attr('action')
- method: 'patch'
+ url: form.attr('action')
+ method: form.attr('method')
dataType: 'json'
- data: @form.serialize()
+ data: form.serialize()
beforeSend: =>
@showCheckboxLoadingSpinner($parent)
).done (data) ->
diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee
index 26a12423521..1583d1ba6f9 100644
--- a/app/assets/javascripts/profile.js.coffee
+++ b/app/assets/javascripts/profile.js.coffee
@@ -8,6 +8,10 @@ class @Profile
$('.js-preferences-form').on 'change.preference', 'input[type=radio]', ->
$(this).parents('form').submit()
+ # Automatically submit email form when it changes
+ $('#user_notification_email').on 'change', ->
+ $(this).parents('form').submit()
+
$('.update-username').on 'ajax:before', ->
$('.loading-username').show()
$(this).find('.update-success').hide()
diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee
index 236f0899147..d12bad97a05 100644
--- a/app/assets/javascripts/project.js.coffee
+++ b/app/assets/javascripts/project.js.coffee
@@ -34,27 +34,6 @@ class @Project
$(@).parents('.no-password-message').remove()
e.preventDefault()
- $(document)
- .off 'click', '.update-notification'
- .on 'click', '.update-notification', (e) ->
- e.preventDefault()
- notificationLevel = $(@).data 'notification-level'
- label = $(@).data 'notification-title'
- $('.js-notification-loading').toggleClass 'fa-bell fa-spin fa-spinner'
- $('#notification_setting_level').val(notificationLevel)
- $('#notification-form').submit()
-
- $(document)
- .off 'ajax:success', '#notification-form'
- .on 'ajax:success', '#notification-form', (e, data) ->
- if data.saved
- new Flash('Notification settings saved', 'notice')
- $('.js-notification-toggle-btns')
- .closest('.notification-dropdown')
- .replaceWith(data.html)
- else
- new Flash('Failed to save new settings', 'alert')
-
@projectSelectDropdown()