gitlab-org--gitlab-foss/app/assets/javascripts/new_commit_form.js

38 lines
1.5 KiB
JavaScript
Raw Normal View History

/* 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() {
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; };
2016-07-24 16:45:11 -04:00
this.NewCommitForm = (function() {
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);
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');
this.targetBranchDropdown.on('change.branch', this.renderDestination);
2016-07-24 16:45:11 -04:00
this.renderDestination();
}
NewCommitForm.prototype.renderDestination = function() {
var different;
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;
})();
}).call(window);