summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/protected_branches/protected_branch_access_dropdown.js
blob: e7fff57ff452c0991f3b21c0bec4d3f2024af8a4 (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
/* eslint-disable arrow-parens, no-param-reassign, object-shorthand, no-else-return, comma-dangle, max-len */

(global => {
  global.gl = global.gl || {};

  gl.ProtectedBranchAccessDropdown = class {
    constructor(options) {
      const { $dropdown, data, onSelect } = options;

      $dropdown.glDropdown({
        data: data,
        selectable: true,
        inputId: $dropdown.data('input-id'),
        fieldName: $dropdown.data('field-name'),
        toggleLabel(item, el) {
          if (el.is('.is-active')) {
            return item.text;
          } else {
            return 'Select';
          }
        },
        clicked(item, $el, e) {
          e.preventDefault();
          onSelect();
        }
      });
    }
  };
})(window);