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

61 lines
1.7 KiB
CoffeeScript
Raw Normal View History

2016-03-08 03:38:16 -05:00
class @MilestoneSelect
constructor: ->
$('.js-milestone-select').each (i, dropdown) ->
projectId = $(dropdown).data('project-id')
milestonesUrl = $(dropdown).data('milestones')
2016-03-08 03:38:16 -05:00
selectedMilestone = $(dropdown).data('selected')
showNo = $(dropdown).data('show-no')
showAny = $(dropdown).data('show-any')
useId = $(dropdown).data('use-id')
2016-03-08 03:38:16 -05:00
$(dropdown).glDropdown(
2016-03-08 04:09:39 -05:00
data: (term, callback) ->
$.ajax(
url: milestonesUrl
).done (data) ->
html = $(data)
data = []
html.find('.milestone strong a').each ->
link = $(@).attr("href").split("/")
data.push(
id: link[link.length - 1]
title: $(@).text().trim()
)
if showNo
data.unshift(
id: "0"
2016-03-09 08:34:39 -05:00
title: 'No Milestone'
)
2016-03-08 06:58:14 -05:00
if showAny
data.unshift(
2016-03-09 08:34:39 -05:00
title: 'Any Milestone'
)
if data.length > 2
data.splice 2, 0, "divider"
callback(data)
2016-03-08 03:38:16 -05:00
filterable: true
search:
2016-03-08 04:09:39 -05:00
fields: ['title']
2016-03-08 03:38:16 -05:00
selectable: true
fieldName: $(dropdown).data('field-name')
text: (milestone) ->
milestone.title
id: (milestone) ->
if !useId
if milestone.title isnt "Any milestone"
milestone.title
else
""
else
milestone.id
2016-03-08 03:38:16 -05:00
isSelected: (milestone) ->
milestone.title is selectedMilestone
clicked: ->
2016-03-08 06:58:14 -05:00
if $(dropdown).hasClass "js-filter-submit"
$(dropdown).parents('form').submit()
2016-03-08 03:38:16 -05:00
)