Welcome to mirror list, hosted at ThFree Co, Russian Federation.

protected_tag_edit.js « protected_tags « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 70bfd71abcebb7032348cd73ddc13732185c8184 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import flash from '../flash';
import axios from '../lib/utils/axios_utils';
import ProtectedTagAccessDropdown from './protected_tag_access_dropdown';
import { __ } from '~/locale';

export default class ProtectedTagEdit {
  constructor(options) {
    this.$wrap = options.$wrap;
    this.$allowedToCreateDropdownButton = this.$wrap.find('.js-allowed-to-create');
    this.onSelectCallback = this.onSelect.bind(this);

    this.buildDropdowns();
  }

  buildDropdowns() {
    // Allowed to create dropdown
    this.protectedTagAccessDropdown = new ProtectedTagAccessDropdown({
      $dropdown: this.$allowedToCreateDropdownButton,
      data: gon.create_access_levels,
      onSelect: this.onSelectCallback,
    });
  }

  onSelect() {
    const $allowedToCreateInput = this.$wrap.find(
      `input[name="${this.$allowedToCreateDropdownButton.data('fieldName')}"]`,
    );

    // Do not update if one dropdown has not selected any option
    if (!$allowedToCreateInput.length) return;

    this.$allowedToCreateDropdownButton.disable();

    axios
      .patch(this.$wrap.data('url'), {
        protected_tag: {
          create_access_levels_attributes: [
            {
              id: this.$allowedToCreateDropdownButton.data('accessLevelId'),
              access_level: $allowedToCreateInput.val(),
            },
          ],
        },
      })
      .then(() => {
        this.$allowedToCreateDropdownButton.enable();
      })
      .catch(() => {
        this.$allowedToCreateDropdownButton.enable();

        flash(
          __('Failed to update tag!'),
          'alert',
          document.querySelector('.js-protected-tags-list'),
        );
      });
  }
}