2015-09-11 14:41:01 +05:30
|
|
|
#= require jquery.waitforimages
|
|
|
|
#= require task_list
|
|
|
|
|
|
|
|
#= require merge_request_tabs
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class @MergeRequest
|
2015-09-11 14:41:01 +05:30
|
|
|
# Initialize MergeRequest behavior
|
|
|
|
#
|
|
|
|
# Options:
|
|
|
|
# action - String, current controller action
|
|
|
|
#
|
2014-09-02 18:07:02 +05:30
|
|
|
constructor: (@opts) ->
|
|
|
|
this.$el = $('.merge-request')
|
|
|
|
|
|
|
|
this.$('.show-all-commits').on 'click', =>
|
|
|
|
this.showAllCommits()
|
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
@fixAffixScroll();
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
@initTabs()
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
# Prevent duplicate event bindings
|
|
|
|
@disableTaskList()
|
2016-01-14 18:37:52 +05:30
|
|
|
@initMRBtnListeners()
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
if $("a.btn-close").length
|
2015-09-11 14:41:01 +05:30
|
|
|
@initTaskList()
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
# Local jQuery finder
|
|
|
|
$: (selector) ->
|
|
|
|
this.$el.find(selector)
|
|
|
|
|
2016-01-19 16:12:03 +05:30
|
|
|
fixAffixScroll: ->
|
|
|
|
fixAffix = ->
|
|
|
|
$discussion = $('.issuable-discussion')
|
|
|
|
$sidebar = $('.issuable-sidebar')
|
|
|
|
if $sidebar.hasClass('no-affix')
|
|
|
|
$sidebar.removeClass(['affix-top','affix'])
|
|
|
|
discussionHeight = $discussion.height()
|
|
|
|
sidebarHeight = $sidebar.height()
|
|
|
|
if sidebarHeight > discussionHeight
|
|
|
|
$discussion.height(sidebarHeight + 50)
|
|
|
|
$sidebar.addClass('no-affix')
|
|
|
|
$(window).on('resize', fixAffix)
|
|
|
|
fixAffix()
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
initTabs: ->
|
|
|
|
if @opts.action != 'new'
|
|
|
|
# `MergeRequests#new` has no tab-persisting or lazy-loading behavior
|
|
|
|
new MergeRequestTabs(@opts)
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
2015-09-11 14:41:01 +05:30
|
|
|
# Show the first tab (Commits)
|
|
|
|
$('.merge-request-tabs a[data-toggle="tab"]:first').tab('show')
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
showAllCommits: ->
|
|
|
|
this.$('.first-commits').remove()
|
|
|
|
this.$('.all-commits').removeClass 'hide'
|
|
|
|
|
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
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
initMRBtnListeners: ->
|
|
|
|
_this = @
|
|
|
|
$('a.btn-close, a.btn-reopen').on 'click', (e) ->
|
|
|
|
$this = $(this)
|
|
|
|
shouldSubmit = $this.hasClass('btn-comment')
|
2016-01-19 16:12:03 +05:30
|
|
|
if shouldSubmit && $this.data('submitted')
|
|
|
|
return
|
2016-01-14 18:37:52 +05:30
|
|
|
if shouldSubmit
|
2016-01-19 16:12:03 +05:30
|
|
|
if $this.hasClass('btn-comment-and-close') || $this.hasClass('btn-comment-and-reopen')
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopImmediatePropagation()
|
|
|
|
_this.submitNoteForm($this.closest('form'),$this)
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
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-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'
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
# 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()}
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
$.ajax
|
2015-09-11 14:41:01 +05:30
|
|
|
type: 'PATCH'
|
|
|
|
url: $('form.js-issuable-update').attr('action')
|
|
|
|
data: patchData
|