debian-mirror-gitlab/app/assets/javascripts/clusters/gke_cluster_namespace/index.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-10-12 21:52:04 +05:30
/**
* Disables & hides the namespace inputs when the gitlab-managed checkbox is checked/unchecked.
*/
const setDisabled = (el, isDisabled) => {
if (isDisabled) {
el.classList.add('hidden');
el.querySelector('input').setAttribute('disabled', true);
} else {
el.classList.remove('hidden');
el.querySelector('input').removeAttribute('disabled');
}
};
2021-03-08 18:12:59 +05:30
const setState = (glManagedCheckbox) => {
2019-10-12 21:52:04 +05:30
const glManaged = document.querySelector('.js-namespace-prefixed');
const selfManaged = document.querySelector('.js-namespace');
if (glManagedCheckbox.checked) {
setDisabled(glManaged, false);
setDisabled(selfManaged, true);
} else {
setDisabled(glManaged, true);
setDisabled(selfManaged, false);
}
};
const initGkeNamespace = () => {
const glManagedCheckbox = document.querySelector('.js-gl-managed');
if (glManagedCheckbox) {
setState(glManagedCheckbox); // this is needed in order to set the initial state
glManagedCheckbox.addEventListener('change', () => setState(glManagedCheckbox));
}
};
export default initGkeNamespace;