From a81b3ed4fa50966691105d82dcffed7dcbe86474 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Aug 2026 10:49:58 +0000 Subject: [PATCH] =?UTF-8?q?Filtrer=20les=20types=20d'=C3=A9quipement=20par?= =?UTF-8?q?=20salle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_new/interventions/templates/detail.html | 23 ++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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(); })();