protected_branch_create.js.es6 1.22 KB
Newer Older
1
class ProtectedBranchCreate {
2 3 4 5 6 7 8 9 10 11 12 13 14
  constructor() {
    this.$wrap = this.$form = $('#new_protected_branch');
    this.buildDropdowns();
  }

  buildDropdowns() {
    // Allowed to Merge dropdowns
    new AllowedToMergeDropdowns({
      $dropdowns: this.$wrap.find('.js-allowed-to-merge'),
      onSelect: this.onSelect.bind(this)
    });

    // Allowed to Push dropdowns
15
    new AllowedToPushDropdowns({
16 17 18 19
      $dropdowns: this.$wrap.find('.js-allowed-to-push'),
      onSelect: this.onSelect.bind(this)
    });

20
    new ProtectedBranchDropdowns({
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
      $dropdowns: this.$wrap.find('.js-protected-branch-select'),
      onSelect: this.onSelect.bind(this)
    });
  }

  // This will run after clicked callback
  onSelect() {
    // Enable submit button
    const $branchInput = this.$wrap.find('input[name="protected_branch[name]"]');
    const $allowedToMergeInput = this.$wrap.find('input[name="protected_branch[merge_access_level_attributes][access_level]"]');
    const $allowedToPushInput = this.$wrap.find('input[name="protected_branch[push_access_level_attributes][access_level]"]');

    if ($branchInput.val() && $allowedToMergeInput.val() && $allowedToPushInput.val()){
      this.$form.find('[type="submit"]').removeAttr('disabled');
    }
  }
}