2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
function setVisibilityOptions(namespaceSelector) {
|
|
|
|
if (!namespaceSelector || !('selectedIndex' in namespaceSelector)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const selectedNamespace = namespaceSelector.options[namespaceSelector.selectedIndex];
|
|
|
|
const { name, visibility, visibilityLevel, showPath, editPath } = selectedNamespace.dataset;
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
document.querySelectorAll('.visibility-level-setting .form-check').forEach((option) => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const optionInput = option.querySelector('input[type=radio]');
|
|
|
|
const optionValue = optionInput ? optionInput.value : 0;
|
|
|
|
const optionTitle = option.querySelector('.option-title');
|
|
|
|
const optionName = optionTitle ? optionTitle.innerText.toLowerCase() : '';
|
|
|
|
|
|
|
|
// don't change anything if the option is restricted by admin
|
|
|
|
if (!option.classList.contains('restricted')) {
|
|
|
|
if (visibilityLevel < optionValue) {
|
|
|
|
option.classList.add('disabled');
|
|
|
|
optionInput.disabled = true;
|
|
|
|
const reason = option.querySelector('.option-disabled-reason');
|
|
|
|
if (reason) {
|
2018-12-13 13:39:08 +05:30
|
|
|
reason.innerHTML = `This project cannot be ${optionName} because the visibility of
|
2018-03-17 18:26:18 +05:30
|
|
|
<a href="${showPath}">${name}</a> is ${visibility}. To make this project
|
|
|
|
${optionName}, you must first <a href="${editPath}">change the visibility</a>
|
|
|
|
of the parent group.`;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
option.classList.remove('disabled');
|
|
|
|
optionInput.disabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function initProjectVisibilitySelector() {
|
|
|
|
const namespaceSelector = document.querySelector('select.js-select-namespace');
|
|
|
|
if (namespaceSelector) {
|
|
|
|
$('.select2.js-select-namespace').on('change', () => setVisibilityOptions(namespaceSelector));
|
|
|
|
setVisibilityOptions(namespaceSelector);
|
|
|
|
}
|
|
|
|
}
|