2017-01-11 23:27:41 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, 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, max-len, prefer-arrow-callback */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global MergeRequestTabs */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-05-16 16:52:40 -04:00
|
|
|
import 'vendor/jquery.waitforimages';
|
|
|
|
import './task_list';
|
|
|
|
import './merge_request_tabs';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
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 : {};
|
2017-05-08 15:01:56 -04:00
|
|
|
this.submitNoteForm = this.submitNoteForm.bind(this);
|
2016-07-24 16:45:11 -04:00
|
|
|
this.$el = $('.merge-request');
|
|
|
|
this.$('.show-all-commits').on('click', (function(_this) {
|
|
|
|
return function() {
|
|
|
|
return _this.showAllCommits();
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
this.initTabs();
|
|
|
|
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) {
|
2017-02-07 01:42:21 -05:00
|
|
|
this.taskList = new gl.TaskList({
|
|
|
|
dataType: 'merge_request',
|
2017-02-15 00:53:17 -05:00
|
|
|
fieldName: 'description',
|
2017-02-08 04:23:45 -05:00
|
|
|
selector: '.detail-page-description',
|
|
|
|
onSuccess: (result) => {
|
|
|
|
document.querySelector('#task_status').innerText = result.task_status;
|
|
|
|
document.querySelector('#task_status_short').innerText = result.task_status_short;
|
|
|
|
}
|
2017-02-07 01:42:21 -05:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.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');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-05 05:46:43 -05:00
|
|
|
MergeRequest.prototype.initCommitMessageListeners = function() {
|
2017-01-28 17:30:43 -05:00
|
|
|
$(document).on('click', 'a.js-with-description-link', function(e) {
|
|
|
|
var textarea = $('textarea.js-commit-message');
|
2016-12-05 05:46:43 -05:00
|
|
|
e.preventDefault();
|
2016-11-28 06:30:25 -05:00
|
|
|
|
|
|
|
textarea.val(textarea.data('messageWithDescription'));
|
2017-02-10 12:21:20 -05:00
|
|
|
$('.js-with-description-hint').hide();
|
|
|
|
$('.js-without-description-hint').show();
|
2016-11-28 06:30:25 -05:00
|
|
|
});
|
|
|
|
|
2017-01-28 17:30:43 -05:00
|
|
|
$(document).on('click', 'a.js-without-description-link', function(e) {
|
|
|
|
var textarea = $('textarea.js-commit-message');
|
2016-11-28 06:30:25 -05:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
textarea.val(textarea.data('messageWithoutDescription'));
|
2017-02-10 12:21:20 -05:00
|
|
|
$('.js-with-description-hint').show();
|
|
|
|
$('.js-without-description-hint').hide();
|
2016-11-28 06:30:25 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
MergeRequest.prototype.updateStatusText = function(classToRemove, classToAdd, newStatusText) {
|
|
|
|
$('.detail-page-header .status-box')
|
|
|
|
.removeClass(classToRemove)
|
|
|
|
.addClass(classToAdd)
|
|
|
|
.find('span')
|
|
|
|
.text(newStatusText);
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.decreaseCounter = function(by = 1) {
|
|
|
|
const $el = $('.nav-links .js-merge-counter');
|
|
|
|
const count = Math.max((parseInt($el.text().replace(/[^\d]/, ''), 10) - by), 0);
|
|
|
|
|
|
|
|
$el.text(gl.text.addDelimiter(count));
|
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return MergeRequest;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|