dynamically disable/enable visibility options when changing namespaces in new project form
This commit is contained in:
parent
77a5d9db83
commit
62be748ef8
|
@ -74,6 +74,7 @@ import PerformanceBar from './performance_bar';
|
|||
import initNotes from './init_notes';
|
||||
import initLegacyFilters from './init_legacy_filters';
|
||||
import initIssuableSidebar from './init_issuable_sidebar';
|
||||
import initProjectVisibilitySelector from './project_visibility';
|
||||
import GpgBadges from './gpg_badges';
|
||||
import UserFeatureHelper from './helpers/user_feature_helper';
|
||||
import initChangesDropdown from './init_changes_dropdown';
|
||||
|
@ -575,6 +576,7 @@ import initChangesDropdown from './init_changes_dropdown';
|
|||
break;
|
||||
case 'new':
|
||||
new ProjectNew();
|
||||
initProjectVisibilitySelector();
|
||||
break;
|
||||
case 'show':
|
||||
new Star();
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
function setVisibilityOptions(namespaceSelector) {
|
||||
if (!namespaceSelector || !('selectedIndex' in namespaceSelector)) {
|
||||
return;
|
||||
}
|
||||
const selectedNamespace = namespaceSelector.options[namespaceSelector.selectedIndex];
|
||||
const { name, visibility, visibilityLevel } = selectedNamespace.dataset;
|
||||
|
||||
document.querySelectorAll('.visibility-level-setting .radio').forEach((option) => {
|
||||
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) {
|
||||
reason.innerText = `This project cannot be ${optionName} because the visibility of ${name} is ${visibility}.`;
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@ module NamespacesHelper
|
|||
|
||||
elements = namespaces.sort_by(&:human_name).map! do |n|
|
||||
[display_path ? n.full_path : n.human_name, n.id,
|
||||
data: { options_parent: type, visibility_level: n.visibility_level_value, name: n.human_name }]
|
||||
data: { options_parent: type, visibility_level: n.visibility_level_value, visibility: n.visibility, name: n.name }]
|
||||
end
|
||||
|
||||
[type.camelize, elements]
|
||||
|
|
Loading…
Reference in New Issue