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

protected_tag_edit_list.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: 444d6e9cf767966cff6e63261c21b60c6c76b717 (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
import Vue from 'vue';
import * as Sentry from '@sentry/browser';
import ProtectedTagEdit from './protected_tag_edit.vue';

export default class ProtectedTagEditList {
  constructor(options) {
    this.hasLicense = options.hasLicense;
    this.initEditForm();
  }

  initEditForm() {
    document
      .querySelector('.protected-tags-list')
      .querySelectorAll('.js-protected-tag-edit-form')
      ?.forEach((el) => {
        const accessDropdownEl = el.querySelector('.js-allowed-to-create');
        this.initAccessDropdown(accessDropdownEl, {
          url: el.dataset.url,
          hasLicense: this.hasLicense,
          accessLevelsData: gon.create_access_levels.roles,
        });
      });
  }

  // eslint-disable-next-line class-methods-use-this
  initAccessDropdown(el, options) {
    if (!el) return null;

    let preselected = [];
    try {
      preselected = JSON.parse(el.dataset.preselectedItems);
    } catch (e) {
      Sentry.captureException(e);
    }

    return new Vue({
      el,
      render(createElement) {
        return createElement(ProtectedTagEdit, {
          props: {
            preselectedItems: preselected,
            searchEnabled: el.dataset.filter !== undefined,
            ...options,
          },
        });
      },
    });
  }
}