2015-12-23 20:57:16 -05:00
|
|
|
#= require flash
|
2015-05-06 12:57:12 -04:00
|
|
|
#= require jquery.waitforimages
|
2015-05-06 15:31:08 -04:00
|
|
|
#= require task_list
|
2015-05-06 12:57:12 -04:00
|
|
|
|
2014-10-20 16:48:07 -04:00
|
|
|
class @Issue
|
2014-02-18 06:15:43 -05:00
|
|
|
constructor: ->
|
2015-04-29 16:47:31 -04:00
|
|
|
# Prevent duplicate event bindings
|
|
|
|
@disableTaskList()
|
2015-12-21 17:10:27 -05:00
|
|
|
if $('a.btn-close').length
|
2015-04-29 16:47:31 -04:00
|
|
|
@initTaskList()
|
2015-12-21 13:06:09 -05:00
|
|
|
@initIssueBtnEventListeners()
|
2015-02-17 19:14:49 -05:00
|
|
|
|
2016-04-12 09:55:54 -04:00
|
|
|
@initMergeRequests()
|
|
|
|
@initRelatedBranches()
|
2016-04-21 10:34:00 -04:00
|
|
|
@initCanCreateBranch()
|
2016-04-12 09:55:54 -04:00
|
|
|
|
2015-04-29 16:47:31 -04:00
|
|
|
initTaskList: ->
|
2015-12-16 10:13:22 -05: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 16:47:31 -04:00
|
|
|
|
2015-12-21 13:06:09 -05:00
|
|
|
initIssueBtnEventListeners: ->
|
2015-12-29 12:53:21 -05:00
|
|
|
_this = @
|
2015-12-23 17:41:05 -05:00
|
|
|
issueFailMessage = 'Unable to update this issue at this time.'
|
2015-12-21 17:10:27 -05:00
|
|
|
$('a.btn-close, a.btn-reopen').on 'click', (e) ->
|
2015-12-21 13:06:09 -05:00
|
|
|
e.preventDefault()
|
|
|
|
e.stopImmediatePropagation()
|
|
|
|
$this = $(this)
|
|
|
|
isClose = $this.hasClass('btn-close')
|
2015-12-29 12:53:21 -05:00
|
|
|
shouldSubmit = $this.hasClass('btn-comment')
|
|
|
|
if shouldSubmit
|
|
|
|
_this.submitNoteForm($this.closest('form'))
|
2015-12-21 17:10:27 -05:00
|
|
|
$this.prop('disabled', true)
|
2015-12-21 16:45:52 -05:00
|
|
|
url = $this.attr('href')
|
2015-12-21 13:06:09 -05:00
|
|
|
$.ajax
|
|
|
|
type: 'PUT'
|
|
|
|
url: url,
|
|
|
|
error: (jqXHR, textStatus, errorThrown) ->
|
|
|
|
issueStatus = if isClose then 'close' else 'open'
|
2015-12-23 17:41:05 -05:00
|
|
|
new Flash(issueFailMessage, 'alert')
|
2015-12-21 13:06:09 -05:00
|
|
|
success: (data, textStatus, jqXHR) ->
|
2016-04-05 14:43:30 -04:00
|
|
|
if 'id' of data
|
2016-01-26 00:25:41 -05:00
|
|
|
$(document).trigger('issuable:change');
|
2015-12-21 13:06:09 -05:00
|
|
|
if isClose
|
2015-12-29 12:53:21 -05:00
|
|
|
$('a.btn-close').addClass('hidden')
|
2015-12-21 13:06:09 -05:00
|
|
|
$('a.btn-reopen').removeClass('hidden')
|
2015-12-21 17:10:27 -05:00
|
|
|
$('div.status-box-closed').removeClass('hidden')
|
|
|
|
$('div.status-box-open').addClass('hidden')
|
2015-12-21 13:06:09 -05:00
|
|
|
else
|
2015-12-29 12:53:21 -05:00
|
|
|
$('a.btn-reopen').addClass('hidden')
|
2015-12-21 13:06:09 -05:00
|
|
|
$('a.btn-close').removeClass('hidden')
|
2015-12-21 17:10:27 -05:00
|
|
|
$('div.status-box-closed').addClass('hidden')
|
|
|
|
$('div.status-box-open').removeClass('hidden')
|
2015-12-21 13:06:09 -05:00
|
|
|
else
|
2015-12-23 17:41:05 -05:00
|
|
|
new Flash(issueFailMessage, 'alert')
|
2015-12-21 13:06:09 -05:00
|
|
|
$this.prop('disabled', false)
|
|
|
|
|
2015-12-29 12:53:21 -05:00
|
|
|
submitNoteForm: (form) =>
|
|
|
|
noteText = form.find("textarea.js-note-text").val()
|
|
|
|
if noteText.trim().length > 0
|
|
|
|
form.submit()
|
|
|
|
|
2015-04-29 16:47:31 -04:00
|
|
|
disableTaskList: ->
|
2015-12-16 10:13:22 -05:00
|
|
|
$('.detail-page-description .js-task-list-container').taskList('disable')
|
|
|
|
$(document).off 'tasklist:changed', '.detail-page-description .js-task-list-container'
|
2015-04-29 16:47:31 -04: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 09:05:30 -04:00
|
|
|
url: $('form.js-issuable-update').attr('action')
|
2015-04-29 16:47:31 -04:00
|
|
|
data: patchData
|
2016-04-12 09:55:54 -04:00
|
|
|
|
|
|
|
initMergeRequests: ->
|
|
|
|
$container = $('#merge-requests')
|
|
|
|
|
|
|
|
$.getJSON($container.data('url'))
|
|
|
|
.error ->
|
|
|
|
new Flash('Failed to load referenced merge requests', 'alert')
|
|
|
|
.success (data) ->
|
|
|
|
if 'html' of data
|
|
|
|
$container.html(data.html)
|
|
|
|
|
|
|
|
initRelatedBranches: ->
|
|
|
|
$container = $('#related-branches')
|
|
|
|
|
|
|
|
$.getJSON($container.data('url'))
|
|
|
|
.error ->
|
|
|
|
new Flash('Failed to load related branches', 'alert')
|
|
|
|
.success (data) ->
|
|
|
|
if 'html' of data
|
|
|
|
$container.html(data.html)
|
2016-04-21 10:34:00 -04:00
|
|
|
|
|
|
|
initCanCreateBranch: ->
|
|
|
|
$container = $('div#new-branch')
|
|
|
|
|
|
|
|
# If the user doesn't have the required permissions the container isn't
|
|
|
|
# rendered at all.
|
|
|
|
return unless $container
|
|
|
|
|
|
|
|
$.getJSON($container.data('path'))
|
|
|
|
.error ->
|
|
|
|
$container.find('.checking').hide()
|
|
|
|
$container.find('.unavailable').show()
|
|
|
|
|
|
|
|
new Flash('Failed to check if a new branch can be created.', 'alert')
|
|
|
|
.success (data) ->
|
|
|
|
if data.can_create_branch
|
|
|
|
$container.find('.checking').hide()
|
|
|
|
$container.find('.available').show()
|
|
|
|
$container.find('a').attr('disabled', false)
|
|
|
|
else
|
|
|
|
$container.find('.checking').hide()
|
|
|
|
$container.find('.unavailable').show()
|