diff options
author | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2016-03-13 15:08:42 -0400 |
---|---|---|
committer | Jacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home> | 2016-03-25 08:07:57 -0400 |
commit | 3753ace9bacb5036d7fe9b3a647f5f92d53a51be (patch) | |
tree | aad9f4aa84e1d148900c1c9b00caecc96d36a16a /app/assets | |
parent | 024dc8073ec1f315d3ded16b7d112cd5686c1c26 (diff) | |
download | gitlab-ce-3753ace9bacb5036d7fe9b3a647f5f92d53a51be.tar.gz |
Add labels as proper POST arrays using new dropdown
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/labels_select.js.coffee | 73 | ||||
-rw-r--r-- | app/assets/javascripts/milestone_select.js.coffee | 26 |
2 files changed, 54 insertions, 45 deletions
diff --git a/app/assets/javascripts/labels_select.js.coffee b/app/assets/javascripts/labels_select.js.coffee index 7b60bfd8614..59496043eed 100644 --- a/app/assets/javascripts/labels_select.js.coffee +++ b/app/assets/javascripts/labels_select.js.coffee @@ -6,8 +6,8 @@ class @LabelsSelect labelUrl = $dropdown.data('labels') issueUpdateURL = $dropdown.data('issueUpdate') selectedLabel = $dropdown.data('selected') - if selectedLabel - selectedLabel = selectedLabel.toString().split(',') + if selectedLabel? + selectedLabel = selectedLabel.split(',') newLabelField = $('#new_label_name') newColorField = $('#new_label_color') showNo = $dropdown.data('show-no') @@ -17,19 +17,6 @@ class @LabelsSelect $block = $selectbox.closest('.block') $value = $block.find('.value') $loading = $block.find('.block-loading').fadeOut() - issueURLSplit = issueUpdateURL.split('/') - labelHTMLTemplate = _.template( - '<% _.each(labels, function(label){ %>'+ - '<a href="'+ - ['',issueURLSplit[1], issueURLSplit[2],''].join('/') + - 'issues?label_name=<%= label.title %>">'+ - '<span class="label color-label" '+ - 'style="background-color: <%= label.color %>; '+ - 'color: #FFFFFF">'+ - '<%= label.title %>'+ - '</span>'+ - '</a>'+ - '<% }); %>'); if newLabelField.length $newLabelCreateButton = $('.js-new-label-btn') @@ -39,6 +26,24 @@ class @LabelsSelect # Suggested colors in the dropdown to chose from pre-chosen colors $('.suggest-colors-dropdown a').on 'click', (e) -> + + issueURLSplit = issueURL.split('/') if issueURL? + if issueURL + labelHTMLTemplate = _.template( + '<% _.each(labels, function(label){ %>'+ + '<a href="'+ + ['',issueURLSplit[1], issueURLSplit[2],''].join('/') + + 'issues?label_name=<%= label.title %>">'+ + '<span class="label color-label" '+ + 'style="background-color: <%= label.color %>; '+ + 'color: #FFFFFF">'+ + '<%= label.title %>'+ + '</span>'+ + '</a>'+ + '<% }); %>'); + + if newLabelField.length and $dropdown.hasClass 'js-extra-options' + $('.suggest-colors-dropdown a').on "click", (e) -> e.preventDefault() e.stopPropagation() newColorField @@ -113,22 +118,23 @@ class @LabelsSelect $.ajax( url: labelUrl ).done (data) -> - if showNo - data.unshift( - id: 0 - title: 'No Label' - ) - - if showAny - data.unshift( - isAny: true - title: 'Any Label' - ) - - if data.length > 2 - data.splice 2, 0, 'divider' - + if $dropdown.hasClass 'js-extra-options' + if showNo + data.unshift( + id: 0 + title: 'No Label' + ) + + if showAny + data.unshift( + isAny: true + title: 'Any Label' + ) + + if data.length > 2 + data.splice 2, 0, 'divider' callback data + renderRow: (label) -> if $.isArray(selectedLabel) selected = '' @@ -184,16 +190,19 @@ class @LabelsSelect .closest('.selectbox') .find('input[type="hidden"]') .val() + console.log 'selected', selected # need inline-block here instead of show, # which will default to the element's style in this case inline. + selected = if selected? then [ selected ] else [''] + console.log 'selected', selected $loading .fadeIn() $.ajax( type: 'PUT' - url: issueUpdateURL + url: issueURL data: issue: - label_ids: [selected] + label_ids: selected ).done (data) -> $loading.fadeOut() $selectbox.hide() diff --git a/app/assets/javascripts/milestone_select.js.coffee b/app/assets/javascripts/milestone_select.js.coffee index 14d1c74f835..876b9d1ae86 100644 --- a/app/assets/javascripts/milestone_select.js.coffee +++ b/app/assets/javascripts/milestone_select.js.coffee @@ -21,21 +21,21 @@ class @MilestoneSelect $.ajax( url: milestonesUrl ).done (data) -> - if showNo - data.unshift( - id: '0' - title: 'No Milestone' - ) + if $dropdown.hasClass "js-extra-options" + if showNo + data.unshift( + id: '0' + title: 'No Milestone' + ) - if showAny - data.unshift( - isAny: true - title: 'Any Milestone' - ) - - if data.length > 2 - data.splice 2, 0, 'divider' + if showAny + data.unshift( + isAny: true + title: 'Any Milestone' + ) + if data.length > 2 + data.splice 2, 0, 'divider' callback(data) filterable: true search: |