Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfredo Sumaran <alfredo@gitlab.com>2016-06-03 09:15:32 +0300
committerAlfredo Sumaran <alfredo@gitlab.com>2016-06-06 19:59:49 +0300
commite487b0995cef810fead3f03cce45bc220a6111c2 (patch)
treec2eeb1669f6aa1781bfba6d5cc866d3b8684ab06 /app/assets/javascripts/LabelManager.js.coffee
parent8b3ed9c35513a8d8ee576ffdb69630a08c53875b (diff)
Improve functionality
Diffstat (limited to 'app/assets/javascripts/LabelManager.js.coffee')
-rw-r--r--app/assets/javascripts/LabelManager.js.coffee39
1 files changed, 21 insertions, 18 deletions
diff --git a/app/assets/javascripts/LabelManager.js.coffee b/app/assets/javascripts/LabelManager.js.coffee
index 8a561ad1a46..365a062bb81 100644
--- a/app/assets/javascripts/LabelManager.js.coffee
+++ b/app/assets/javascripts/LabelManager.js.coffee
@@ -1,4 +1,6 @@
class @LabelManager
+ errorMessage: 'Unable to update label prioritization at this time'
+
constructor: (opts = {}) ->
# Defaults
{
@@ -27,7 +29,7 @@ class @LabelManager
action = if $btn.parents('.js-prioritized-labels').length then 'remove' else 'add'
_this.toggleLabelPriority($label, action)
- toggleLabelPriority: ($label, action, persistState = false) ->
+ toggleLabelPriority: ($label, action, persistState = true) ->
_this = @
url = $label.find('.js-toggle-priority').data 'url'
@@ -48,31 +50,32 @@ class @LabelManager
$label.detach().appendTo($target)
# Return if we are not persisting state
- return if persistState
+ return unless persistState
if action is 'remove'
xhr = $.ajax url: url, type: 'DELETE'
-
- # If request fails, put label back to Other labels group
- xhr.fail ->
- _this.toggleLabelPriority($label, 'remove', true)
-
- # Show a message
- new Flash('Unable to update label prioritization at this time' , 'alert')
else
- @savePrioritySort()
+ xhr = @savePrioritySort($label, action)
- onPrioritySortUpdate: ->
- @savePrioritySort()
+ xhr.fail @rollbackLabelPosition.bind(@, $label, action)
- savePrioritySort: ->
- xhr = $.post
- url: @prioritizedLabels.data('url')
- data:
- label_ids: @getSortedLabelsIds()
+ onPrioritySortUpdate: ->
+ xhr = @savePrioritySort()
xhr.fail ->
- new Flash('Unable to update label prioritization at this time' , 'alert')
+ new Flash(@errorMessage, 'alert')
+
+ savePrioritySort: () ->
+ $.post
+ url: @prioritizedLabels.data('url')
+ data:
+ label_ids: @getSortedLabelsIds()
+
+ rollbackLabelPosition: ($label, originalAction)->
+ action = if originalAction is 'remove' then 'add' else 'remove'
+ @toggleLabelPriority($label, action, false)
+
+ new Flash(@errorMessage, 'alert')
getSortedLabelsIds: ->
sortedIds = []