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: b93e903621efefc0c64029a1ea7ffe4a0e524595 (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
/* eslint-disable no-new, arrow-parens, no-param-reassign, comma-dangle, max-len */
/* global Flash */

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

  gl.ProtectedTagEdit = class {
    constructor(options) {
      this.$wrap = options.$wrap;
      this.$allowedToPushDropdown = this.$wrap.find('.js-allowed-to-push');

      this.buildDropdowns();
    }

    buildDropdowns() {
      // Allowed to push dropdown
      new gl.ProtectedTagAccessDropdown({
        $dropdown: this.$allowedToPushDropdown,
        data: gon.push_access_levels,
        onSelect: this.onSelect.bind(this)
      });
    }

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

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

      this.$allowedToPushDropdown.disable();

      $.ajax({
        type: 'POST',
        url: this.$wrap.data('url'),
        dataType: 'json',
        data: {
          _method: 'PATCH',
          protected_tag: {
            push_access_levels_attributes: [{
              id: this.$allowedToPushDropdown.data('access-level-id'),
              access_level: $allowedToPushInput.val()
            }]
          }
        },
        error() {
          $.scrollTo(0);
          new Flash('Failed to update tag!');
        }
      }).always(() => {
        this.$allowedToPushDropdown.enable();
      });
    }
  };
})(window);