gitlab-org--gitlab-foss/app/assets/javascripts/issue.js.coffee

58 lines
1.9 KiB
CoffeeScript
Raw Normal View History

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
constructor: ->
2015-04-29 20:47:31 +00:00
# Prevent duplicate event bindings
@disableTaskList()
2015-04-29 20:47:31 +00:00
if $("a.btn-close").length
@initTaskList()
@initIssueBtnEventListeners()
2015-02-18 00:14:49 +00:00
2015-04-29 20:47:31 +00:00
initTaskList: ->
$('.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
initIssueBtnEventListeners: ->
$("a.btn-close, a.btn-reopen").on "click", (e) ->
e.preventDefault()
e.stopImmediatePropagation()
$this = $(this)
isClose = $this.hasClass('btn-close')
$this.prop("disabled", true)
url = $this.data('url')
$.ajax
type: 'PUT'
url: url,
error: (jqXHR, textStatus, errorThrown) ->
issueStatus = if isClose then 'close' else 'open'
success: (data, textStatus, jqXHR) ->
if data.saved
$this.addClass('hidden')
if isClose
$('a.btn-reopen').removeClass('hidden')
$('div.issue-box-closed').removeClass('hidden')
$('div.issue-box-open').addClass('hidden')
else
$('a.btn-close').removeClass('hidden')
$('div.issue-box-closed').addClass('hidden')
$('div.issue-box-open').removeClass('hidden')
else
$this.prop('disabled', false)
2015-04-29 20:47:31 +00:00
disableTaskList: ->
$('.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'
url: $('form.js-issuable-update').attr('action')
2015-04-29 20:47:31 +00:00
data: patchData