2015-05-06 16:53:35 -04:00
|
|
|
#= require jquery.waitforimages
|
2015-05-06 15:31:08 -04:00
|
|
|
#= require task_list
|
|
|
|
|
2015-06-17 16:11:57 -04:00
|
|
|
#= require merge_request_tabs
|
|
|
|
|
2014-10-20 16:48:07 -04:00
|
|
|
class @MergeRequest
|
2015-05-27 22:39:11 -04:00
|
|
|
# Initialize MergeRequest behavior
|
|
|
|
#
|
|
|
|
# Options:
|
2015-06-17 16:11:57 -04:00
|
|
|
# action - String, current controller action
|
2015-05-27 22:39:11 -04:00
|
|
|
#
|
2014-02-18 09:22:57 -05:00
|
|
|
constructor: (@opts) ->
|
|
|
|
this.$el = $('.merge-request')
|
|
|
|
|
|
|
|
this.$('.show-all-commits').on 'click', =>
|
|
|
|
this.showAllCommits()
|
|
|
|
|
2015-07-18 18:05:07 -04:00
|
|
|
@initTabs()
|
2015-06-17 16:11:57 -04:00
|
|
|
|
2015-04-29 17:00:30 -04:00
|
|
|
# Prevent duplicate event bindings
|
|
|
|
@disableTaskList()
|
2016-01-12 16:29:14 -05:00
|
|
|
@initMRBtnListeners()
|
2015-04-29 17:00:30 -04:00
|
|
|
|
2014-10-06 20:19:12 -04:00
|
|
|
if $("a.btn-close").length
|
2015-04-29 17:00:30 -04:00
|
|
|
@initTaskList()
|
2014-02-18 09:22:57 -05:00
|
|
|
|
|
|
|
# Local jQuery finder
|
|
|
|
$: (selector) ->
|
|
|
|
this.$el.find(selector)
|
|
|
|
|
2015-07-18 18:05:07 -04:00
|
|
|
initTabs: ->
|
|
|
|
if @opts.action != 'new'
|
|
|
|
# `MergeRequests#new` has no tab-persisting or lazy-loading behavior
|
|
|
|
new MergeRequestTabs(@opts)
|
|
|
|
else
|
|
|
|
# Show the first tab (Commits)
|
|
|
|
$('.merge-request-tabs a[data-toggle="tab"]:first').tab('show')
|
|
|
|
|
2014-02-18 09:22:57 -05:00
|
|
|
showAllCommits: ->
|
|
|
|
this.$('.first-commits').remove()
|
|
|
|
this.$('.all-commits').removeClass 'hide'
|
|
|
|
|
2015-04-29 17:00:30 -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 17:00:30 -04:00
|
|
|
|
2016-01-12 16:29:14 -05:00
|
|
|
initMRBtnListeners: ->
|
|
|
|
_this = @
|
|
|
|
$('a.btn-close, a.btn-reopen').on 'click', (e) ->
|
|
|
|
$this = $(this)
|
|
|
|
if $this.data('submitted')
|
|
|
|
return
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopImmediatePropagation()
|
|
|
|
shouldSubmit = $this.hasClass('btn-comment')
|
|
|
|
console.log("shouldSubmit")
|
|
|
|
if shouldSubmit
|
|
|
|
_this.submitNoteForm($this.closest('form'),$this)
|
|
|
|
|
|
|
|
submitNoteForm: (form, $button) =>
|
|
|
|
noteText = form.find("textarea.js-note-text").val()
|
|
|
|
if noteText.trim().length > 0
|
|
|
|
form.submit()
|
|
|
|
$button.data('submitted',true)
|
|
|
|
$button.trigger('click')
|
|
|
|
|
|
|
|
|
2015-04-29 17:00:30 -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 17:00:30 -04:00
|
|
|
|
|
|
|
# TODO (rspeicher): Make the merge request description inline-editable like a
|
|
|
|
# note so that we can re-use its form here
|
|
|
|
updateTaskList: ->
|
|
|
|
patchData = {}
|
|
|
|
patchData['merge_request'] = {'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 17:00:30 -04:00
|
|
|
data: patchData
|