project_variables.js.es6 1.01 KB
Newer Older
1
(() => {
2 3 4 5
  const HIDDEN_VALUE_TEXT = '******';

  class ProjectVariables {
    constructor() {
6 7
      this.$revealBtn = $('.js-btn-toggle-reveal-values');
      this.$revealBtn.on('click', this.toggleRevealState.bind(this));
8 9
    }

10 11
    toggleRevealState(e) {
      e.preventDefault();
12

13 14 15
      const oldStatus = this.$revealBtn.attr('data-status');
      let newStatus = 'hidden';
      let newAction = 'Reveal Values';
16

17 18 19
      if (oldStatus === 'hidden') {
        newStatus = 'revealed';
        newAction = 'Hide Values';
20 21
      }

22
      this.$revealBtn.attr('data-status', newStatus);
23

24
      const $variables = $('.variable-value');
25

26 27
      $variables.each((_, variable) => {
        const $variable = $(variable);
28 29
        let newText = HIDDEN_VALUE_TEXT;

30
        if (newStatus === 'revealed') {
31 32 33 34
          newText = $variable.attr('data-value');
        }

        $variable.text(newText);
35
      });
36

37
      this.$revealBtn.text(newAction);
38 39 40
    }
  }

41 42 43
  window.gl = window.gl || {};
  window.gl.ProjectVariables = ProjectVariables;
})();