gitlab-org--gitlab-foss/app/assets/javascripts/labels_select.js.coffee

54 lines
1.7 KiB
CoffeeScript
Raw Normal View History

2016-03-07 17:17:11 +00:00
class @LabelsSelect
constructor: ->
$('.js-label-select').each (i, dropdown) ->
projectId = $(dropdown).data('project-id')
2016-03-08 08:38:16 +00:00
selectedLabel = $(dropdown).data('selected')
2016-03-08 11:23:54 +00:00
newLabelField = $('#new_label_name')
newColorField = $('#new_label_color')
if newLabelField.length
$('.suggest-colors-dropdown a').on "click", (e) ->
e.preventDefault()
e.stopPropagation()
newColorField.val $(this).data("color")
$('.js-dropdown-label-color-preview')
.css 'background-color', $(this).data("color")
.addClass 'is-active'
$('.js-new-label-btn').on "click", (e) ->
e.preventDefault()
e.stopPropagation()
if newLabelField.val() isnt "" && newColorField.val() isnt ""
$('.js-new-label-btn').disable()
# Create new label with API
Api.newLabel projectId, {
name: newLabelField.val()
color: newColorField.val()
}, (label) ->
$('.js-new-label-btn').enable()
$('.dropdown-menu-back', $(dropdown).parent()).trigger "click"
2016-03-07 17:17:11 +00:00
$(dropdown).glDropdown(
2016-03-08 09:09:39 +00:00
data: (term, callback) ->
2016-03-07 17:17:11 +00:00
Api.projectLabels 8, callback
renderRow: (label) ->
2016-03-08 08:38:16 +00:00
selected = if label.name is selectedLabel then "is-active" else ""
2016-03-07 17:17:11 +00:00
"<li>
2016-03-08 08:38:16 +00:00
<a href='#' class='#{selected}'>
2016-03-07 17:17:11 +00:00
#{label.name}
</a>
</li>"
filterable: true
search:
fields: ['name']
selectable: true
fieldName: $(dropdown).data('field-name')
id: (label) ->
label.name
clicked: ->
$(dropdown).parents('form').submit()
)