Filtrer les types d'équipement par salle
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
This commit is contained in:
parent
4141c7016a
commit
a81b3ed4fa
1 changed files with 22 additions and 1 deletions
|
|
@ -596,6 +596,26 @@
|
||||||
const category = document.getElementById('intervention-category');
|
const category = document.getElementById('intervention-category');
|
||||||
const equipment = document.getElementById('intervention-equipment');
|
const equipment = document.getElementById('intervention-equipment');
|
||||||
if (!room || !category || !equipment) return;
|
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 filter = () => {
|
||||||
const roomId = room.value;
|
const roomId = room.value;
|
||||||
const categoryId = category.value;
|
const categoryId = category.value;
|
||||||
|
|
@ -607,8 +627,9 @@
|
||||||
if (option.hidden && option.selected) equipment.value = '';
|
if (option.hidden && option.selected) equipment.value = '';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
room.addEventListener('change', filter);
|
room.addEventListener('change', () => { filterCategories(); filter(); });
|
||||||
category.addEventListener('change', filter);
|
category.addEventListener('change', filter);
|
||||||
|
filterCategories();
|
||||||
filter();
|
filter();
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue