2017-01-11 23:27:41 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-return-assign, max-len */
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
2017-01-11 23:27:41 -05:00
|
|
|
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; };
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
this.NewCommitForm = (function() {
|
2016-12-22 01:21:40 -05:00
|
|
|
function NewCommitForm(form, targetBranchName = 'target_branch') {
|
|
|
|
this.form = form;
|
|
|
|
this.targetBranchName = targetBranchName;
|
2016-07-24 16:45:11 -04:00
|
|
|
this.renderDestination = bind(this.renderDestination, this);
|
2016-12-22 01:21:40 -05:00
|
|
|
this.targetBranchDropdown = form.find('button.js-target-branch');
|
2016-07-24 16:45:11 -04:00
|
|
|
this.originalBranch = form.find('.js-original-branch');
|
|
|
|
this.createMergeRequest = form.find('.js-create-merge-request');
|
|
|
|
this.createMergeRequestContainer = form.find('.js-create-merge-request-container');
|
2016-12-22 01:21:40 -05:00
|
|
|
this.targetBranchDropdown.on('change.branch', this.renderDestination);
|
2016-07-24 16:45:11 -04:00
|
|
|
this.renderDestination();
|
|
|
|
}
|
|
|
|
|
|
|
|
NewCommitForm.prototype.renderDestination = function() {
|
|
|
|
var different;
|
2016-12-22 01:21:40 -05:00
|
|
|
var targetBranch = this.form.find(`input[name="${this.targetBranchName}"]`);
|
|
|
|
|
|
|
|
different = targetBranch.val() !== this.originalBranch.val();
|
2016-07-24 16:45:11 -04:00
|
|
|
if (different) {
|
|
|
|
this.createMergeRequestContainer.show();
|
|
|
|
if (!this.wasDifferent) {
|
|
|
|
this.createMergeRequest.prop('checked', true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.createMergeRequestContainer.hide();
|
|
|
|
this.createMergeRequest.prop('checked', false);
|
|
|
|
}
|
|
|
|
return this.wasDifferent = different;
|
|
|
|
};
|
|
|
|
|
|
|
|
return NewCommitForm;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|