2016-04-08 08:04:20 -04:00
|
|
|
class @DueDateSelect
|
|
|
|
constructor: ->
|
2016-06-02 03:30:38 -04:00
|
|
|
# Milestone edit/new form
|
|
|
|
$datePicker = $('.datepicker')
|
2016-06-02 07:23:17 -04:00
|
|
|
|
|
|
|
if $datePicker.length
|
|
|
|
$dueDate = $('#milestone_due_date')
|
|
|
|
$datePicker.datepicker
|
|
|
|
dateFormat: 'yy-mm-dd'
|
|
|
|
onSelect: (dateText, inst) ->
|
|
|
|
$dueDate.val(dateText)
|
|
|
|
.datepicker('setDate', $.datepicker.parseDate('yy-mm-dd', $dueDate.val()))
|
2016-06-02 03:30:38 -04:00
|
|
|
|
|
|
|
$('.js-clear-due-date').on 'click', (e) ->
|
|
|
|
e.preventDefault()
|
2016-06-10 07:04:21 -04:00
|
|
|
$.datepicker._clearDate($datePicker)
|
2016-06-02 03:30:38 -04:00
|
|
|
|
|
|
|
# Issuable sidebar
|
2016-04-14 04:53:03 -04:00
|
|
|
$loading = $('.js-issuable-update .due_date')
|
|
|
|
.find('.block-loading')
|
|
|
|
.hide()
|
2016-04-08 11:23:59 -04:00
|
|
|
|
2016-04-08 08:04:20 -04:00
|
|
|
$('.js-due-date-select').each (i, dropdown) ->
|
|
|
|
$dropdown = $(dropdown)
|
|
|
|
$dropdownParent = $dropdown.closest('.dropdown')
|
|
|
|
$datePicker = $dropdownParent.find('.js-due-date-calendar')
|
|
|
|
$block = $dropdown.closest('.block')
|
|
|
|
$selectbox = $dropdown.closest('.selectbox')
|
|
|
|
$value = $block.find('.value')
|
2016-05-19 06:34:40 -04:00
|
|
|
$valueContent = $block.find('.value-content')
|
2016-04-11 06:07:02 -04:00
|
|
|
$sidebarValue = $('.js-due-date-sidebar-value', $block)
|
2016-04-08 08:04:20 -04:00
|
|
|
|
|
|
|
fieldName = $dropdown.data('field-name')
|
|
|
|
abilityName = $dropdown.data('ability-name')
|
|
|
|
issueUpdateURL = $dropdown.data('issue-update')
|
|
|
|
|
2016-04-08 11:23:59 -04:00
|
|
|
$dropdown.glDropdown(
|
|
|
|
hidden: ->
|
|
|
|
$selectbox.hide()
|
2016-06-01 05:11:30 -04:00
|
|
|
$value.css('display', '')
|
2016-04-08 11:23:59 -04:00
|
|
|
)
|
|
|
|
|
2016-05-23 04:33:48 -04:00
|
|
|
addDueDate = (isDropdown) ->
|
2016-04-08 08:04:20 -04:00
|
|
|
# Create the post date
|
|
|
|
value = $("input[name='#{fieldName}']").val()
|
2016-05-19 06:34:40 -04:00
|
|
|
|
|
|
|
if value isnt ''
|
|
|
|
date = new Date value.replace(new RegExp('-', 'g'), ',')
|
|
|
|
mediumDate = $.datepicker.formatDate 'M d, yy', date
|
|
|
|
else
|
2016-06-02 06:03:33 -04:00
|
|
|
mediumDate = 'No due date'
|
2016-04-08 08:04:20 -04:00
|
|
|
|
|
|
|
data = {}
|
|
|
|
data[abilityName] = {}
|
|
|
|
data[abilityName].due_date = value
|
|
|
|
|
|
|
|
$.ajax(
|
|
|
|
type: 'PUT'
|
|
|
|
url: issueUpdateURL
|
|
|
|
data: data
|
2016-06-01 05:11:30 -04:00
|
|
|
dataType: 'json'
|
2016-04-08 08:04:20 -04:00
|
|
|
beforeSend: ->
|
|
|
|
$loading.fadeIn()
|
2016-05-23 04:33:48 -04:00
|
|
|
if isDropdown
|
|
|
|
$dropdown.trigger('loading.gl.dropdown')
|
|
|
|
$selectbox.hide()
|
2016-06-01 05:11:30 -04:00
|
|
|
$value.css('display', '')
|
2016-04-08 08:04:20 -04:00
|
|
|
|
2016-06-10 03:42:03 -04:00
|
|
|
cssClass = if Date.parse(mediumDate) then 'bold' else 'no-value'
|
2016-06-02 06:03:33 -04:00
|
|
|
$valueContent.html("<span class='#{cssClass}'>#{mediumDate}</span>")
|
2016-04-11 06:07:02 -04:00
|
|
|
$sidebarValue.html(mediumDate)
|
2016-05-19 06:34:40 -04:00
|
|
|
|
|
|
|
if value isnt ''
|
|
|
|
$('.js-remove-due-date-holder').removeClass 'hidden'
|
|
|
|
else
|
|
|
|
$('.js-remove-due-date-holder').addClass 'hidden'
|
2016-04-08 08:04:20 -04:00
|
|
|
).done (data) ->
|
2016-05-23 04:33:48 -04:00
|
|
|
if isDropdown
|
|
|
|
$dropdown.trigger('loaded.gl.dropdown')
|
|
|
|
$dropdown.dropdown('toggle')
|
2016-04-08 08:04:20 -04:00
|
|
|
$loading.fadeOut()
|
|
|
|
|
2016-05-19 06:34:40 -04:00
|
|
|
$block.on 'click', '.js-remove-due-date', (e) ->
|
|
|
|
e.preventDefault()
|
|
|
|
$("input[name='#{fieldName}']").val ''
|
2016-05-23 04:33:48 -04:00
|
|
|
addDueDate(false)
|
2016-05-19 06:34:40 -04:00
|
|
|
|
2016-04-08 08:04:20 -04:00
|
|
|
$datePicker.datepicker(
|
2016-04-14 04:53:03 -04:00
|
|
|
dateFormat: 'yy-mm-dd',
|
2016-04-08 08:04:20 -04:00
|
|
|
defaultDate: $("input[name='#{fieldName}']").val()
|
|
|
|
altField: "input[name='#{fieldName}']"
|
2016-04-14 04:53:03 -04:00
|
|
|
onSelect: ->
|
2016-05-23 04:33:48 -04:00
|
|
|
addDueDate(true)
|
2016-04-08 08:04:20 -04:00
|
|
|
)
|
2016-04-11 05:08:27 -04:00
|
|
|
|
|
|
|
$(document)
|
|
|
|
.off 'click', '.ui-datepicker-header a'
|
|
|
|
.on 'click', '.ui-datepicker-header a', (e) ->
|
|
|
|
e.stopImmediatePropagation()
|