Enforce topology rules and fix device deletion flow
This commit is contained in:
@@ -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);
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user