2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2021-12-11 22:18:48 +05:30
|
|
|
import eventHub from '~/projects/new/event_hub';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
// Values are from lib/gitlab/visibility_level.rb
|
|
|
|
const visibilityLevel = {
|
|
|
|
private: 0,
|
|
|
|
internal: 10,
|
|
|
|
public: 20,
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
function setVisibilityOptions({ name, visibility, showPath, editPath }) {
|
2021-03-08 18:12:59 +05:30
|
|
|
document.querySelectorAll('.visibility-level-setting .form-check').forEach((option) => {
|
2021-12-11 22:18:48 +05:30
|
|
|
// Don't change anything if the option is restricted by admin
|
|
|
|
if (option.classList.contains('restricted')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
const optionInput = option.querySelector('input[type=radio]');
|
2021-12-11 22:18:48 +05:30
|
|
|
const optionValue = optionInput ? parseInt(optionInput.value, 10) : 0;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
if (visibilityLevel[visibility] < optionValue) {
|
|
|
|
option.classList.add('disabled');
|
|
|
|
optionInput.disabled = true;
|
|
|
|
const reason = option.querySelector('.option-disabled-reason');
|
|
|
|
if (reason) {
|
|
|
|
const optionTitle = option.querySelector('.option-title');
|
|
|
|
const optionName = optionTitle ? optionTitle.innerText.toLowerCase() : '';
|
|
|
|
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.`;
|
|
|
|
}
|
2021-12-11 22:18:48 +05:30
|
|
|
} else {
|
|
|
|
option.classList.remove('disabled');
|
|
|
|
optionInput.disabled = false;
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
function handleSelect2DropdownChange(namespaceSelector) {
|
|
|
|
if (!namespaceSelector || !('selectedIndex' in namespaceSelector)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const selectedNamespace = namespaceSelector.options[namespaceSelector.selectedIndex];
|
|
|
|
setVisibilityOptions(selectedNamespace.dataset);
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
export default function initProjectVisibilitySelector() {
|
2021-12-11 22:18:48 +05:30
|
|
|
eventHub.$on('update-visibility', setVisibilityOptions);
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
const namespaceSelector = document.querySelector('select.js-select-namespace');
|
|
|
|
if (namespaceSelector) {
|
2021-12-11 22:18:48 +05:30
|
|
|
$('.select2.js-select-namespace').on('change', () =>
|
|
|
|
handleSelect2DropdownChange(namespaceSelector),
|
|
|
|
);
|
|
|
|
handleSelect2DropdownChange(namespaceSelector);
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
|
|
|
}
|