gitlab-org--gitlab-foss/app/assets/javascripts/due_date_select.js.coffee
2016-04-20 15:42:09 -04:00

48 lines
1.5 KiB
CoffeeScript

class @DueDateSelect
constructor: ->
$('.js-due-date-select').each (i, dropdown) ->
$dropdown = $(dropdown)
$dropdownParent = $dropdown.closest('.dropdown')
$addBtn = $('.js-due-date-add', $dropdownParent)
$datePicker = $dropdownParent.find('.js-due-date-calendar')
$block = $dropdown.closest('.block')
$loading = $block.find('.block-loading').hide()
$selectbox = $dropdown.closest('.selectbox')
$value = $block.find('.value')
fieldName = $dropdown.data('field-name')
abilityName = $dropdown.data('ability-name')
issueUpdateURL = $dropdown.data('issue-update')
$addBtn.on 'click', (e) ->
e.preventDefault()
e.stopPropagation()
# Create the post date
value = $("input[name='#{fieldName}']").val()
mediumDate = $.datepicker.formatDate("M d, yy", new Date(value))
data = {}
data[abilityName] = {}
data[abilityName].due_date = value
$.ajax(
type: 'PUT'
url: issueUpdateURL
data: data
beforeSend: ->
$loading.fadeIn()
$dropdown.trigger('loading.gl.dropdown')
$selectbox.hide()
$value.removeAttr('style')
$value.html(mediumDate)
).done (data) ->
$dropdown.trigger('loaded.gl.dropdown')
$loading.fadeOut()
$datePicker.datepicker(
dateFormat: "yy-mm-dd",
defaultDate: $("input[name='#{fieldName}']").val()
altField: "input[name='#{fieldName}']"
)