summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/new_commit_form.js
blob: acb529023fa5138d3637f7562a9a958e94c82896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable */
(function() {
  var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  this.NewCommitForm = (function() {
    function NewCommitForm(form) {
      this.renderDestination = bind(this.renderDestination, this);
      this.newBranch = form.find('.js-target-branch');
      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.renderDestination();
      this.newBranch.keyup(this.renderDestination);
    }

    NewCommitForm.prototype.renderDestination = function() {
      var different;
      different = this.newBranch.val() !== this.originalBranch.val();
      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(this);