Enforce topology rules and fix device deletion flow

This commit is contained in:
2026-02-19 09:13:03 +01:00
parent 9121a2ddfd
commit 9ece132df5
7 changed files with 80 additions and 12 deletions

View File

@@ -51,8 +51,49 @@
});
}
function enforceTopologyTypeRules(typeA, typeB) {
const allowWithPatchpanel = { patchpanel: true, outlet: true };
const selectedA = typeA.value;
const selectedB = typeB.value;
const applyRules = (sourceType, targetSelect) => {
for (const option of targetSelect.options) {
const value = option.value;
if (!value) {
option.disabled = false;
continue;
}
if (sourceType === 'patchpanel') {
option.disabled = !allowWithPatchpanel[value];
} else {
option.disabled = false;
}
}
if (targetSelect.selectedOptions.length > 0 && targetSelect.selectedOptions[0].disabled) {
targetSelect.value = '';
}
};
applyRules(selectedA, typeB);
applyRules(selectedB, typeA);
}
document.addEventListener('DOMContentLoaded', () => {
bindPair('port_a_type', 'port_a_id');
bindPair('port_b_type', 'port_b_id');
const typeA = document.getElementById('port_a_type');
const typeB = document.getElementById('port_b_type');
if (!typeA || !typeB) {
return;
}
const syncRules = () => {
enforceTopologyTypeRules(typeA, typeB);
};
syncRules();
typeA.addEventListener('change', syncRules);
typeB.addEventListener('change', syncRules);
});
})();