2016-03-08 03:38:16 -05:00
|
|
|
class @MilestoneSelect
|
|
|
|
constructor: ->
|
|
|
|
$('.js-milestone-select').each (i, dropdown) ->
|
|
|
|
projectId = $(dropdown).data('project-id')
|
2016-03-08 07:32:04 -05:00
|
|
|
milestonesUrl = $(dropdown).data('milestones')
|
2016-03-08 03:38:16 -05:00
|
|
|
selectedMilestone = $(dropdown).data('selected')
|
2016-03-08 05:24:03 -05:00
|
|
|
showNo = $(dropdown).data('show-no')
|
|
|
|
showAny = $(dropdown).data('show-any')
|
2016-03-08 07:32:04 -05:00
|
|
|
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) ->
|
2016-03-08 07:32:04 -05:00
|
|
|
$.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()
|
|
|
|
)
|
2016-03-08 05:24:03 -05:00
|
|
|
|
|
|
|
if showNo
|
|
|
|
data.unshift(
|
2016-03-08 07:32:04 -05:00
|
|
|
id: "0"
|
2016-03-09 08:34:39 -05:00
|
|
|
title: 'No Milestone'
|
2016-03-08 05:24:03 -05:00
|
|
|
)
|
2016-03-08 06:58:14 -05:00
|
|
|
|
2016-03-08 05:24:03 -05:00
|
|
|
if showAny
|
|
|
|
data.unshift(
|
2016-03-09 08:34:39 -05:00
|
|
|
title: 'Any Milestone'
|
2016-03-08 05:24:03 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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) ->
|
2016-03-08 07:32:04 -05:00
|
|
|
if !useId
|
|
|
|
if milestone.title isnt "Any milestone"
|
|
|
|
milestone.title
|
|
|
|
else
|
|
|
|
""
|
2016-03-08 05:24:03 -05:00
|
|
|
else
|
2016-03-08 07:32:04 -05:00
|
|
|
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
|
|
|
)
|