0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-22 21:45:24 +02:00
gitea/web_src/js/features/repo-settings-actions.ts
2025-12-26 09:18:59 +01:00

47 lines
1.7 KiB
TypeScript

export function initActionsPermissionsTable(): void {
const modeRadios = document.querySelectorAll<HTMLInputElement>('.js-permission-mode-radio');
const permTable = document.querySelector<HTMLTableElement>('table.js-permissions-table');
const tableSection = document.querySelector<HTMLElement>('#max-permissions-section');
const followOrgCheckbox = document.querySelector<HTMLInputElement>('.js-follow-org-config');
const modeSection = document.querySelector<HTMLElement>('.js-permission-mode-section');
if (!modeRadios.length) return;
function updateTableState(): void {
const followOrg = followOrgCheckbox?.checked ?? false;
const selectedMode = document.querySelector<HTMLInputElement>('input[name="token_permission_mode"]:checked');
const isCustom = selectedMode?.value === 'custom';
// Disable entire form when following org config
for (const radio of modeRadios) {
radio.disabled = followOrg;
}
if (modeSection) {
modeSection.style.opacity = followOrg ? '0.5' : '1';
}
// Disable table if not custom OR following org
const tableDisabled = !isCustom || followOrg;
if (permTable) {
const inputs = permTable.querySelectorAll<HTMLInputElement>('input[type="radio"]');
for (const input of inputs) {
input.disabled = tableDisabled;
}
permTable.style.opacity = tableDisabled ? '0.5' : '1';
}
if (tableSection) {
tableSection.style.opacity = tableDisabled ? '0.5' : '1';
}
}
for (const radio of modeRadios) {
radio.addEventListener('change', updateTableState);
}
followOrgCheckbox?.addEventListener('change', updateTableState);
updateTableState();
}