2016-03-08 03:38:16 -05:00
|
|
|
class @MilestoneSelect
|
2016-03-22 15:18:29 -04:00
|
|
|
constructor: (currentProject) ->
|
|
|
|
if currentProject?
|
|
|
|
_this = @
|
|
|
|
@currentProject = JSON.parse(currentProject)
|
2016-03-08 03:38:16 -05:00
|
|
|
$('.js-milestone-select').each (i, dropdown) ->
|
2016-03-18 06:12:52 -04:00
|
|
|
$dropdown = $(dropdown)
|
|
|
|
projectId = $dropdown.data('project-id')
|
|
|
|
milestonesUrl = $dropdown.data('milestones')
|
2016-03-11 14:20:44 -05:00
|
|
|
issueUpdateURL = $dropdown.data('issueUpdate')
|
2016-03-18 06:12:52 -04:00
|
|
|
selectedMilestone = $dropdown.data('selected')
|
|
|
|
showNo = $dropdown.data('show-no')
|
|
|
|
showAny = $dropdown.data('show-any')
|
2016-03-24 04:40:46 -04:00
|
|
|
showUpcoming = $dropdown.data('show-upcoming')
|
2016-03-18 06:12:52 -04:00
|
|
|
useId = $dropdown.data('use-id')
|
2016-03-18 08:21:07 -04:00
|
|
|
defaultLabel = $dropdown.data('default-label')
|
2016-03-11 00:28:10 -05:00
|
|
|
issuableId = $dropdown.data('issuable-id')
|
2016-03-17 09:14:46 -04:00
|
|
|
abilityName = $dropdown.data('ability-name')
|
2016-03-12 06:52:50 -05:00
|
|
|
$selectbox = $dropdown.closest('.selectbox')
|
|
|
|
$block = $selectbox.closest('.block')
|
2016-03-27 11:04:51 -04:00
|
|
|
$sidebarCollapsedValue = $block.find('.sidebar-collapsed-icon')
|
2016-03-12 06:52:50 -05:00
|
|
|
$value = $block.find('.value')
|
2016-03-12 11:34:26 -05:00
|
|
|
$loading = $block.find('.block-loading').fadeOut()
|
2016-03-08 03:38:16 -05:00
|
|
|
|
2016-03-22 15:18:29 -04:00
|
|
|
if issueUpdateURL
|
|
|
|
milestoneLinkTemplate = _.template(
|
2016-06-02 17:01:11 -04:00
|
|
|
'<a href="/<%= namespace %>/<%= path %>/milestones/<%= iid %>">
|
2016-06-08 12:40:32 -04:00
|
|
|
<span class="has-tooltip" data-container="body" title="<%= remaining %>">
|
2016-06-02 17:01:11 -04:00
|
|
|
<%= _.escape(title) %>
|
|
|
|
</span>
|
|
|
|
</a>'
|
2016-03-22 15:18:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
milestoneLinkNoneTemplate = '<div class="light">None</div>'
|
|
|
|
|
2016-06-02 17:01:11 -04:00
|
|
|
collapsedSidebarLabelTemplate = _.template(
|
2016-06-08 12:40:32 -04:00
|
|
|
'<span class="has-tooltip" data-container="body" title="<%= remaining %>" data-placement="left">
|
2016-06-02 17:01:11 -04:00
|
|
|
<%= _.escape(title) %>
|
|
|
|
</span>'
|
|
|
|
)
|
|
|
|
|
2016-03-18 06:12:52 -04: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) ->
|
2016-03-24 04:40:46 -04:00
|
|
|
extraOptions = []
|
|
|
|
if showAny
|
|
|
|
extraOptions.push(
|
2016-03-24 11:20:35 -04:00
|
|
|
id: 0
|
|
|
|
name: ''
|
2016-03-24 04:40:46 -04:00
|
|
|
title: 'Any Milestone'
|
|
|
|
)
|
|
|
|
|
|
|
|
if showNo
|
|
|
|
extraOptions.push(
|
2016-03-24 11:20:35 -04:00
|
|
|
id: -1
|
|
|
|
name: 'No Milestone'
|
2016-03-24 04:40:46 -04:00
|
|
|
title: 'No Milestone'
|
|
|
|
)
|
|
|
|
|
|
|
|
if showUpcoming
|
|
|
|
extraOptions.push(
|
2016-03-24 11:20:35 -04:00
|
|
|
id: -2
|
|
|
|
name: '#upcoming'
|
2016-03-24 04:40:46 -04:00
|
|
|
title: 'Upcoming'
|
|
|
|
)
|
2016-03-08 05:24:03 -05:00
|
|
|
|
2016-03-29 07:17:22 -04:00
|
|
|
if extraOptions.length > 2
|
|
|
|
extraOptions.push 'divider'
|
|
|
|
|
|
|
|
callback(extraOptions.concat(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
|
2016-03-15 14:20:22 -04:00
|
|
|
toggleLabel: (selected) ->
|
2016-03-18 06:12:52 -04:00
|
|
|
if selected && 'id' of selected
|
2016-03-15 14:20:22 -04:00
|
|
|
selected.title
|
|
|
|
else
|
|
|
|
defaultLabel
|
2016-03-18 06:12:52 -04:00
|
|
|
fieldName: $dropdown.data('field-name')
|
2016-03-08 03:38:16 -05:00
|
|
|
text: (milestone) ->
|
2016-04-19 13:41:08 -04:00
|
|
|
_.escape(milestone.title)
|
2016-03-08 03:38:16 -05:00
|
|
|
id: (milestone) ->
|
2016-03-08 07:32:04 -05:00
|
|
|
if !useId
|
2016-03-24 11:20:35 -04:00
|
|
|
milestone.name
|
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) ->
|
2016-03-24 11:20:35 -04:00
|
|
|
milestone.name is selectedMilestone
|
2016-03-12 15:37:02 -05:00
|
|
|
hidden: ->
|
|
|
|
$selectbox.hide()
|
2016-03-26 11:43:42 -04:00
|
|
|
|
|
|
|
# display:block overrides the hide-collapse rule
|
2016-06-01 05:11:30 -04:00
|
|
|
$value.css('display', '')
|
2016-03-31 14:25:08 -04:00
|
|
|
clicked: (selected) ->
|
2016-04-11 06:38:24 -04:00
|
|
|
page = $('body').data 'page'
|
|
|
|
isIssueIndex = page is 'projects:issues:index'
|
|
|
|
isMRIndex = page is page is 'projects:merge_requests:index'
|
|
|
|
|
2016-03-26 09:30:37 -04:00
|
|
|
if $dropdown.hasClass 'js-filter-bulk-update'
|
|
|
|
return
|
2016-03-23 12:44:09 -04:00
|
|
|
|
2016-04-11 06:38:24 -04:00
|
|
|
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
|
2016-03-31 14:25:08 -04:00
|
|
|
if selected.name?
|
|
|
|
selectedMilestone = selected.name
|
|
|
|
else
|
|
|
|
selectedMilestone = ''
|
2016-04-20 12:00:12 -04:00
|
|
|
Issuable.filterResults $dropdown.closest('form')
|
2016-04-11 06:38:24 -04:00
|
|
|
else if $dropdown.hasClass('js-filter-submit')
|
|
|
|
$dropdown.closest('form').submit()
|
2016-03-11 00:28:10 -05:00
|
|
|
else
|
2016-03-19 11:39:34 -04:00
|
|
|
selected = $selectbox
|
2016-03-11 00:28:10 -05:00
|
|
|
.find('input[type="hidden"]')
|
|
|
|
.val()
|
2016-03-17 09:14:46 -04:00
|
|
|
data = {}
|
|
|
|
data[abilityName] = {}
|
|
|
|
data[abilityName].milestone_id = selected
|
2016-03-12 11:34:26 -05:00
|
|
|
$loading
|
|
|
|
.fadeIn()
|
2016-03-27 11:04:51 -04:00
|
|
|
$dropdown.trigger('loading.gl.dropdown')
|
2016-03-11 14:20:44 -05:00
|
|
|
$.ajax(
|
|
|
|
type: 'PUT'
|
|
|
|
url: issueUpdateURL
|
2016-03-17 09:14:46 -04:00
|
|
|
data: data
|
2016-03-11 14:20:44 -05:00
|
|
|
).done (data) ->
|
2016-03-27 11:04:51 -04:00
|
|
|
$dropdown.trigger('loaded.gl.dropdown')
|
2016-03-12 11:34:26 -05:00
|
|
|
$loading.fadeOut()
|
2016-03-12 06:52:50 -05:00
|
|
|
$selectbox.hide()
|
2016-06-01 05:11:30 -04:00
|
|
|
$value.css('display', '')
|
2016-03-22 15:18:29 -04:00
|
|
|
if data.milestone?
|
|
|
|
data.milestone.namespace = _this.currentProject.namespace
|
|
|
|
data.milestone.path = _this.currentProject.path
|
2016-06-02 17:01:11 -04:00
|
|
|
data.milestone.remaining = $.timefor data.milestone.due_date
|
2016-03-22 15:18:29 -04:00
|
|
|
$value.html(milestoneLinkTemplate(data.milestone))
|
2016-06-02 17:01:11 -04:00
|
|
|
$sidebarCollapsedValue.find('span').html(collapsedSidebarLabelTemplate(data.milestone))
|
2016-03-22 15:18:29 -04:00
|
|
|
else
|
|
|
|
$value.html(milestoneLinkNoneTemplate)
|
2016-03-27 11:04:51 -04:00
|
|
|
$sidebarCollapsedValue.find('span').text('No')
|
2016-03-31 14:25:08 -04:00
|
|
|
)
|