diff --git a/app_new/interventions/templates/detail.html b/app_new/interventions/templates/detail.html index 85dc684..e640590 100644 --- a/app_new/interventions/templates/detail.html +++ b/app_new/interventions/templates/detail.html @@ -596,6 +596,26 @@ const category = document.getElementById('intervention-category'); const equipment = document.getElementById('intervention-equipment'); if (!room || !category || !equipment) return; + const equipmentOptions = [...equipment.options].filter(option => option.value); + const filterCategories = () => { + const roomId = room.value; + const presentCategories = new Set( + equipmentOptions + .filter(option => roomId && option.dataset.room === roomId) + .map(option => option.dataset.category) + .filter(Boolean) + ); + [...category.options].forEach(option => { + if (!option.value) { + option.hidden = false; + option.textContent = roomId ? '— Choisir un type présent —' : '— Sélectionnez d’abord une salle —'; + return; + } + option.hidden = !roomId || !presentCategories.has(option.value); + if (option.hidden && option.selected) category.value = ''; + }); + category.disabled = !roomId || presentCategories.size === 0; + }; const filter = () => { const roomId = room.value; const categoryId = category.value; @@ -607,8 +627,9 @@ if (option.hidden && option.selected) equipment.value = ''; }); }; - room.addEventListener('change', filter); + room.addEventListener('change', () => { filterCategories(); filter(); }); category.addEventListener('change', filter); + filterCategories(); filter(); })();