summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/admin/application_settings/metrics_and_profiling/usage_statistics.js
blob: bf27b1a81ff9fce6d1b0ed9c8f3c37350c87ed66 (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
import { __ } from '~/locale';

export const HELPER_TEXT_SERVICE_PING_DISABLED = __(
  'To enable Registration Features, make sure "Enable service ping" is checked.',
);

export const HELPER_TEXT_SERVICE_PING_ENABLED = __(
  'You can enable Registration Features because Service Ping is enabled. To continue using Registration Features in the future, you will also need to register with GitLab via a new cloud licensing service.',
);

function setHelperText(usagePingCheckbox) {
  const helperTextId = document.getElementById('service_ping_features_helper_text');

  const usagePingFeaturesLabel = document.getElementById('service_ping_features_label');

  const usagePingFeaturesCheckbox = document.getElementById(
    'application_setting_usage_ping_features_enabled',
  );

  helperTextId.textContent = usagePingCheckbox.checked
    ? HELPER_TEXT_SERVICE_PING_ENABLED
    : HELPER_TEXT_SERVICE_PING_DISABLED;

  usagePingFeaturesLabel.classList.toggle('gl-cursor-not-allowed', !usagePingCheckbox.checked);

  usagePingFeaturesCheckbox.disabled = !usagePingCheckbox.checked;

  if (!usagePingCheckbox.checked) {
    usagePingFeaturesCheckbox.disabled = true;
    usagePingFeaturesCheckbox.checked = false;
  }
}

export default function initSetHelperText() {
  const usagePingCheckbox = document.getElementById('application_setting_usage_ping_enabled');

  setHelperText(usagePingCheckbox);
  usagePingCheckbox.addEventListener('change', () => {
    setHelperText(usagePingCheckbox);
  });
}