summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/project_variables.js
blob: 567c311f119a87deb520e79fda976ff211811b92 (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

const HIDDEN_VALUE_TEXT = '******';

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

  toggleRevealState(e) {
    e.preventDefault();

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

    if (oldStatus === 'hidden') {
      newStatus = 'revealed';
      newAction = 'Hide Values';
    }

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

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

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

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

      $variable.text(newText);
    });

    this.$revealBtn.text(newAction);
  }
}