summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/protected_branches/protected_branch_access_dropdown.js
blob: 41e295387ae36d31372f802d4d60efeeced30038 (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
import { __ } from '~/locale';

export default class ProtectedBranchAccessDropdown {
  constructor(options) {
    this.options = options;
    this.initDropdown();
  }

  initDropdown() {
    const { $dropdown, data, onSelect } = this.options;
    $dropdown.glDropdown({
      data,
      selectable: true,
      inputId: $dropdown.data('inputId'),
      fieldName: $dropdown.data('fieldName'),
      toggleLabel(item, $el) {
        if ($el.is('.is-active')) {
          return item.text;
        }
        return __('Select');
      },
      clicked(options) {
        options.e.preventDefault();
        onSelect();
      },
    });
  }
}