2016-12-08 06:39:16 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, space-before-blocks, prefer-rest-params, wrap-iife, quotes, no-underscore-dangle, one-var, one-var-declaration-per-line, consistent-return, dot-notation, quote-props, comma-dangle, object-shorthand, padded-blocks, max-len, prefer-arrow-callback */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global MergeRequestTabs */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
/*= require jquery.waitforimages */
|
|
|
|
/*= require task_list */
|
|
|
|
/*= require merge_request_tabs */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
|
|
|
|
|
|
|
this.MergeRequest = (function() {
|
|
|
|
function MergeRequest(opts) {
|
2016-07-26 23:32:10 -04:00
|
|
|
// Initialize MergeRequest behavior
|
|
|
|
//
|
|
|
|
// Options:
|
|
|
|
// action - String, current controller action
|
|
|
|
//
|
2016-07-24 16:45:11 -04:00
|
|
|
this.opts = opts != null ? opts : {};
|
|
|
|
this.submitNoteForm = bind(this.submitNoteForm, this);
|
|
|
|
this.$el = $('.merge-request');
|
|
|
|
this.$('.show-all-commits').on('click', (function(_this) {
|
|
|
|
return function() {
|
|
|
|
return _this.showAllCommits();
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
this.initTabs();
|
2016-07-26 23:32:10 -04:00
|
|
|
// Prevent duplicate event bindings
|
2016-07-24 16:45:11 -04:00
|
|
|
this.disableTaskList();
|
|
|
|
this.initMRBtnListeners();
|
2016-12-05 05:46:43 -05:00
|
|
|
this.initCommitMessageListeners();
|
2016-07-24 16:45:11 -04:00
|
|
|
if ($("a.btn-close").length) {
|
|
|
|
this.initTaskList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-26 23:32:10 -04:00
|
|
|
// Local jQuery finder
|
2016-07-24 16:45:11 -04:00
|
|
|
MergeRequest.prototype.$ = function(selector) {
|
|
|
|
return this.$el.find(selector);
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.initTabs = function() {
|
2016-09-19 19:02:52 -04:00
|
|
|
if (window.mrTabs) {
|
|
|
|
window.mrTabs.unbindEvents();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2016-10-25 11:42:25 -04:00
|
|
|
window.mrTabs = new gl.MergeRequestTabs(this.opts);
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.showAllCommits = function() {
|
|
|
|
this.$('.first-commits').remove();
|
|
|
|
return this.$('.all-commits').removeClass('hide');
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.initTaskList = function() {
|
|
|
|
$('.detail-page-description .js-task-list-container').taskList('enable');
|
|
|
|
return $(document).on('tasklist:changed', '.detail-page-description .js-task-list-container', this.updateTaskList);
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.initMRBtnListeners = function() {
|
|
|
|
var _this;
|
|
|
|
_this = this;
|
|
|
|
return $('a.btn-close, a.btn-reopen').on('click', function(e) {
|
|
|
|
var $this, shouldSubmit;
|
|
|
|
$this = $(this);
|
|
|
|
shouldSubmit = $this.hasClass('btn-comment');
|
|
|
|
if (shouldSubmit && $this.data('submitted')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (shouldSubmit) {
|
|
|
|
if ($this.hasClass('btn-comment-and-close') || $this.hasClass('btn-comment-and-reopen')) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
return _this.submitNoteForm($this.closest('form'), $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.submitNoteForm = function(form, $button) {
|
|
|
|
var noteText;
|
|
|
|
noteText = form.find("textarea.js-note-text").val();
|
|
|
|
if (noteText.trim().length > 0) {
|
|
|
|
form.submit();
|
|
|
|
$button.data('submitted', true);
|
|
|
|
return $button.trigger('click');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.disableTaskList = function() {
|
|
|
|
$('.detail-page-description .js-task-list-container').taskList('disable');
|
|
|
|
return $(document).off('tasklist:changed', '.detail-page-description .js-task-list-container');
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.updateTaskList = function() {
|
|
|
|
var patchData;
|
|
|
|
patchData = {};
|
|
|
|
patchData['merge_request'] = {
|
|
|
|
'description': $('.js-task-list-field', this).val()
|
|
|
|
};
|
|
|
|
return $.ajax({
|
|
|
|
type: 'PATCH',
|
|
|
|
url: $('form.js-issuable-update').attr('action'),
|
2016-09-26 17:36:11 -04:00
|
|
|
data: patchData,
|
|
|
|
success: function(mergeRequest) {
|
|
|
|
document.querySelector('#task_status').innerText = mergeRequest.task_status;
|
|
|
|
document.querySelector('#task_status_short').innerText = mergeRequest.task_status_short;
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2016-07-26 23:32:10 -04:00
|
|
|
// TODO (rspeicher): Make the merge request description inline-editable like a
|
|
|
|
// note so that we can re-use its form here
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
2016-12-05 05:46:43 -05:00
|
|
|
MergeRequest.prototype.initCommitMessageListeners = function() {
|
|
|
|
var textarea = $('textarea.js-commit-message');
|
2016-11-28 06:30:25 -05:00
|
|
|
|
2016-12-05 06:43:40 -05:00
|
|
|
$('a.js-with-description-link').on('click', function(e) {
|
2016-12-05 05:46:43 -05:00
|
|
|
e.preventDefault();
|
2016-11-28 06:30:25 -05:00
|
|
|
|
|
|
|
textarea.val(textarea.data('messageWithDescription'));
|
2016-12-05 06:43:40 -05:00
|
|
|
$('p.js-with-description-hint').hide();
|
|
|
|
$('p.js-without-description-hint').show();
|
2016-11-28 06:30:25 -05:00
|
|
|
});
|
|
|
|
|
2016-12-05 06:43:40 -05:00
|
|
|
$('a.js-without-description-link').on('click', function(e) {
|
2016-11-28 06:30:25 -05:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
textarea.val(textarea.data('messageWithoutDescription'));
|
2016-12-05 06:43:40 -05:00
|
|
|
$('p.js-with-description-hint').show();
|
|
|
|
$('p.js-without-description-hint').hide();
|
2016-11-28 06:30:25 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return MergeRequest;
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
}).call(this);
|