2015-12-24 01:57:16 +00:00
|
|
|
#= require flash
|
2015-05-06 16:57:12 +00:00
|
|
|
#= require jquery.waitforimages
|
2015-05-06 19:31:08 +00:00
|
|
|
#= require task_list
|
2015-05-06 16:57:12 +00:00
|
|
|
|
2014-10-20 20:48:07 +00:00
|
|
|
class @Issue
|
2014-02-18 11:15:43 +00:00
|
|
|
constructor: ->
|
2015-04-29 20:47:31 +00:00
|
|
|
# Prevent duplicate event bindings
|
|
|
|
@disableTaskList()
|
2014-10-05 05:53:44 +00:00
|
|
|
|
2015-12-21 22:10:27 +00:00
|
|
|
if $('a.btn-close').length
|
2015-04-29 20:47:31 +00:00
|
|
|
@initTaskList()
|
2015-12-21 18:06:09 +00:00
|
|
|
@initIssueBtnEventListeners()
|
2015-02-18 00:14:49 +00:00
|
|
|
|
2015-04-29 20:47:31 +00:00
|
|
|
initTaskList: ->
|
2015-12-16 15:13:22 +00:00
|
|
|
$('.detail-page-description .js-task-list-container').taskList('enable')
|
|
|
|
$(document).on 'tasklist:changed', '.detail-page-description .js-task-list-container', @updateTaskList
|
2015-04-29 20:47:31 +00:00
|
|
|
|
2015-12-21 18:06:09 +00:00
|
|
|
initIssueBtnEventListeners: ->
|
2015-12-23 22:41:05 +00:00
|
|
|
issueFailMessage = 'Unable to update this issue at this time.'
|
2015-12-21 22:10:27 +00:00
|
|
|
$('a.btn-close, a.btn-reopen').on 'click', (e) ->
|
2015-12-21 18:06:09 +00:00
|
|
|
e.preventDefault()
|
|
|
|
e.stopImmediatePropagation()
|
|
|
|
$this = $(this)
|
|
|
|
isClose = $this.hasClass('btn-close')
|
2015-12-21 22:10:27 +00:00
|
|
|
$this.prop('disabled', true)
|
2015-12-21 21:45:52 +00:00
|
|
|
url = $this.attr('href')
|
2015-12-21 18:06:09 +00:00
|
|
|
$.ajax
|
|
|
|
type: 'PUT'
|
|
|
|
url: url,
|
|
|
|
error: (jqXHR, textStatus, errorThrown) ->
|
|
|
|
issueStatus = if isClose then 'close' else 'open'
|
2015-12-23 22:41:05 +00:00
|
|
|
new Flash(issueFailMessage, 'alert')
|
2015-12-21 18:06:09 +00:00
|
|
|
success: (data, textStatus, jqXHR) ->
|
|
|
|
if data.saved
|
|
|
|
$this.addClass('hidden')
|
|
|
|
if isClose
|
|
|
|
$('a.btn-reopen').removeClass('hidden')
|
2015-12-21 22:10:27 +00:00
|
|
|
$('div.status-box-closed').removeClass('hidden')
|
|
|
|
$('div.status-box-open').addClass('hidden')
|
2015-12-21 18:06:09 +00:00
|
|
|
else
|
|
|
|
$('a.btn-close').removeClass('hidden')
|
2015-12-21 22:10:27 +00:00
|
|
|
$('div.status-box-closed').addClass('hidden')
|
|
|
|
$('div.status-box-open').removeClass('hidden')
|
2015-12-21 18:06:09 +00:00
|
|
|
else
|
2015-12-23 22:41:05 +00:00
|
|
|
new Flash(issueFailMessage, 'alert')
|
2015-12-21 18:06:09 +00:00
|
|
|
$this.prop('disabled', false)
|
|
|
|
|
2015-04-29 20:47:31 +00:00
|
|
|
disableTaskList: ->
|
2015-12-16 15:13:22 +00:00
|
|
|
$('.detail-page-description .js-task-list-container').taskList('disable')
|
|
|
|
$(document).off 'tasklist:changed', '.detail-page-description .js-task-list-container'
|
2015-04-29 20:47:31 +00:00
|
|
|
|
|
|
|
# TODO (rspeicher): Make the issue description inline-editable like a note so
|
|
|
|
# that we can re-use its form here
|
|
|
|
updateTaskList: ->
|
|
|
|
patchData = {}
|
|
|
|
patchData['issue'] = {'description': $('.js-task-list-field', this).val()}
|
|
|
|
|
|
|
|
$.ajax
|
|
|
|
type: 'PATCH'
|
2015-06-26 13:05:30 +00:00
|
|
|
url: $('form.js-issuable-update').attr('action')
|
2015-04-29 20:47:31 +00:00
|
|
|
data: patchData
|