Commit e487b099 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Improve functionality

parent 8b3ed9c3
class @LabelManager class @LabelManager
errorMessage: 'Unable to update label prioritization at this time'
constructor: (opts = {}) -> constructor: (opts = {}) ->
# Defaults # Defaults
{ {
...@@ -27,7 +29,7 @@ class @LabelManager ...@@ -27,7 +29,7 @@ class @LabelManager
action = if $btn.parents('.js-prioritized-labels').length then 'remove' else 'add' action = if $btn.parents('.js-prioritized-labels').length then 'remove' else 'add'
_this.toggleLabelPriority($label, action) _this.toggleLabelPriority($label, action)
toggleLabelPriority: ($label, action, persistState = false) -> toggleLabelPriority: ($label, action, persistState = true) ->
_this = @ _this = @
url = $label.find('.js-toggle-priority').data 'url' url = $label.find('.js-toggle-priority').data 'url'
...@@ -48,31 +50,32 @@ class @LabelManager ...@@ -48,31 +50,32 @@ class @LabelManager
$label.detach().appendTo($target) $label.detach().appendTo($target)
# Return if we are not persisting state # Return if we are not persisting state
return if persistState return unless persistState
if action is 'remove' if action is 'remove'
xhr = $.ajax url: url, type: 'DELETE' 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 else
@savePrioritySort() xhr = @savePrioritySort($label, action)
xhr.fail @rollbackLabelPosition.bind(@, $label, action)
onPrioritySortUpdate: -> onPrioritySortUpdate: ->
@savePrioritySort() xhr = @savePrioritySort()
savePrioritySort: -> xhr.fail ->
xhr = $.post new Flash(@errorMessage, 'alert')
savePrioritySort: () ->
$.post
url: @prioritizedLabels.data('url') url: @prioritizedLabels.data('url')
data: data:
label_ids: @getSortedLabelsIds() label_ids: @getSortedLabelsIds()
xhr.fail -> rollbackLabelPosition: ($label, originalAction)->
new Flash('Unable to update label prioritization at this time' , 'alert') action = if originalAction is 'remove' then 'add' else 'remove'
@toggleLabelPriority($label, action, false)
new Flash(@errorMessage, 'alert')
getSortedLabelsIds: -> getSortedLabelsIds: ->
sortedIds = [] sortedIds = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment