debian-mirror-gitlab/app/assets/javascripts/issue.js.coffee

118 lines
3.8 KiB
CoffeeScript
Raw Normal View History

#= require flash
2015-09-11 14:41:01 +05:30
#= require jquery.waitforimages
#= require task_list
2015-04-26 12:48:37 +05:30
class @Issue
2014-09-02 18:07:02 +05:30
constructor: ->
2015-09-11 14:41:01 +05:30
# Prevent duplicate event bindings
@disableTaskList()
if $('a.btn-close').length
2015-09-11 14:41:01 +05:30
@initTaskList()
@initIssueBtnEventListeners()
2015-09-11 14:41:01 +05:30
2016-06-02 11:05:42 +05:30
@initMergeRequests()
@initRelatedBranches()
@initCanCreateBranch()
2015-09-11 14:41:01 +05:30
initTaskList: ->
2015-12-23 02:04:40 +05:30
$('.detail-page-description .js-task-list-container').taskList('enable')
$(document).on 'tasklist:changed', '.detail-page-description .js-task-list-container', @updateTaskList
2015-09-11 14:41:01 +05:30
initIssueBtnEventListeners: ->
_this = @
issueFailMessage = 'Unable to update this issue at this time.'
$('a.btn-close, a.btn-reopen').on 'click', (e) ->
e.preventDefault()
e.stopImmediatePropagation()
$this = $(this)
isClose = $this.hasClass('btn-close')
shouldSubmit = $this.hasClass('btn-comment')
if shouldSubmit
_this.submitNoteForm($this.closest('form'))
$this.prop('disabled', true)
url = $this.attr('href')
$.ajax
type: 'PUT'
url: url,
error: (jqXHR, textStatus, errorThrown) ->
issueStatus = if isClose then 'close' else 'open'
new Flash(issueFailMessage, 'alert')
success: (data, textStatus, jqXHR) ->
2016-06-02 11:05:42 +05:30
if 'id' of data
2016-04-02 18:10:28 +05:30
$(document).trigger('issuable:change');
if isClose
$('a.btn-close').addClass('hidden')
$('a.btn-reopen').removeClass('hidden')
$('div.status-box-closed').removeClass('hidden')
$('div.status-box-open').addClass('hidden')
else
$('a.btn-reopen').addClass('hidden')
$('a.btn-close').removeClass('hidden')
$('div.status-box-closed').addClass('hidden')
$('div.status-box-open').removeClass('hidden')
else
new Flash(issueFailMessage, 'alert')
$this.prop('disabled', false)
submitNoteForm: (form) =>
noteText = form.find("textarea.js-note-text").val()
if noteText.trim().length > 0
form.submit()
2015-09-11 14:41:01 +05:30
disableTaskList: ->
2015-12-23 02:04:40 +05:30
$('.detail-page-description .js-task-list-container').taskList('disable')
$(document).off 'tasklist:changed', '.detail-page-description .js-task-list-container'
2015-04-26 12:48:37 +05:30
2015-09-11 14:41:01 +05:30
# 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()}
2015-04-26 12:48:37 +05:30
2015-09-11 14:41:01 +05:30
$.ajax
type: 'PATCH'
url: $('form.js-issuable-update').attr('action')
data: patchData
2016-06-02 11:05:42 +05:30
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)
initCanCreateBranch: ->
$container = $('div#new-branch')
# If the user doesn't have the required permissions the container isn't
# rendered at all.
2016-08-24 12:49:21 +05:30
return if $container.length is 0
2016-06-02 11:05:42 +05:30
$.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()