summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/project_variables.js.es6
blob: 6c905f58c855f0c5f8e068f598432b852185771e (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
/* eslint-disable */
((global) => {
  const HIDDEN_VALUE_TEXT = '******';

  class ProjectVariables {
    constructor() {
      this.$reveal = $('.js-btn-toggle-reveal-values');

      this.$reveal.on('click', this.toggleRevealState.bind(this));
    }

    toggleRevealState(event) {
      event.preventDefault();

      const $btn = $(event.currentTarget);
      const oldStatus = $btn.attr('data-status');

      if (oldStatus == 'hidden') {
        [newStatus, newAction] = ['revealed', 'Hide Values'];
      } else {
        [newStatus, newAction] = ['hidden', 'Reveal Values'];
      }

      $btn.attr('data-status', newStatus);

      let $variables = $('.variable-value');

      $variables.each(function (_, variable) {
        let $variable = $(variable);
        let newText = HIDDEN_VALUE_TEXT;

        if (newStatus == 'revealed') {
          newText = $variable.attr('data-value');
        }

        $variable.text(newText);
      });

      $btn.text(newAction);
    }
  }

  global.ProjectVariables = ProjectVariables;
})(window.gl || (window.gl = {}));