Filterrestriktionen Ernährungsform, Button um Filter zu löschen
This commit is contained in:
1 parent
895c173847
commit
a540f0348d
4 files changed
+135
-11
No files matched your search
+116
-5
@@ -167,6 +167,7 @@
|
||||
dateFilter.value = savedDate;
|
||||
}
|
||||
|
||||
updateDietAvailability();
|
||||
applyFilters();
|
||||
} catch (error) {
|
||||
console.error('Fehler:', error);
|
||||
@@ -631,6 +632,59 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Verhindert widersprüchliche Ernährungsformen:
|
||||
// Fleisch/Fisch schliessen Vegetarisch/Vegan aus.
|
||||
// Vegan schliesst alles andere (Fleisch, Fisch, Vegetarisch) aus.
|
||||
// Vegetarisch schliesst Fleisch/Fisch aus, aber nicht Vegan.
|
||||
function updateDietAvailability() {
|
||||
const dietButtons = Array.from(filterButtons).filter(btn => btn.getAttribute('data-diet') !== null);
|
||||
const meatFishButtons = dietButtons.filter(btn => ['Fleisch', 'Fisch'].includes(btn.getAttribute('data-diet')));
|
||||
const plantButtons = dietButtons.filter(btn => ['Vegetarisch', 'Vegan'].includes(btn.getAttribute('data-diet')));
|
||||
const vegetarischBtn = dietButtons.find(btn => btn.getAttribute('data-diet') === 'Vegetarisch');
|
||||
const veganBtn = dietButtons.find(btn => btn.getAttribute('data-diet') === 'Vegan');
|
||||
|
||||
const hasVegan = activeDiets.has('Vegan');
|
||||
const hasVegetarisch = activeDiets.has('Vegetarisch');
|
||||
const hasMeatOrFish = meatFishButtons.some(btn => activeDiets.has(btn.getAttribute('data-diet')));
|
||||
|
||||
// If Vegan is selected, disable everything else
|
||||
if (hasVegan) {
|
||||
meatFishButtons.forEach(btn => {
|
||||
btn.classList.add('disabled');
|
||||
});
|
||||
if (vegetarischBtn) {
|
||||
vegetarischBtn.classList.add('disabled');
|
||||
}
|
||||
}
|
||||
// If Vegetarisch is selected, disable only Fleisch/Fisch
|
||||
else if (hasVegetarisch) {
|
||||
meatFishButtons.forEach(btn => {
|
||||
btn.classList.add('disabled');
|
||||
});
|
||||
if (veganBtn) {
|
||||
veganBtn.classList.remove('disabled');
|
||||
}
|
||||
}
|
||||
// If Fleisch/Fisch is selected, disable both Vegetarisch and Vegan
|
||||
else if (hasMeatOrFish) {
|
||||
if (vegetarischBtn) {
|
||||
vegetarischBtn.classList.add('disabled');
|
||||
}
|
||||
if (veganBtn) {
|
||||
veganBtn.classList.add('disabled');
|
||||
}
|
||||
}
|
||||
// No conflicts, enable everything
|
||||
else {
|
||||
plantButtons.forEach(btn => {
|
||||
btn.classList.remove('disabled');
|
||||
});
|
||||
meatFishButtons.forEach(btn => {
|
||||
btn.classList.remove('disabled');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Category filter interactions: mutually exclusive (radio button behavior).
|
||||
filterButtons.forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
@@ -642,12 +696,34 @@
|
||||
// Category filter: exclusive selection
|
||||
activeCategory = categoryValue;
|
||||
} else if (dietValue !== null) {
|
||||
// Diet filter: toggle selection
|
||||
if (activeDiets.has(dietValue)) {
|
||||
activeDiets.delete(dietValue);
|
||||
// Diet filter: toggle selection with conflict handling
|
||||
const isCurrentlySelected = activeDiets.has(dietValue);
|
||||
|
||||
if (!isCurrentlySelected) {
|
||||
// Adding a diet - handle conflicts
|
||||
if (dietValue === 'Vegetarisch') {
|
||||
// Vegetarisch removes Fleisch/Fisch but not Vegan
|
||||
activeDiets.delete('Fleisch');
|
||||
activeDiets.delete('Fisch');
|
||||
activeDiets.add('Vegetarisch');
|
||||
} else if (dietValue === 'Vegan') {
|
||||
// Vegan removes all other options
|
||||
activeDiets.delete('Vegetarisch');
|
||||
activeDiets.delete('Fleisch');
|
||||
activeDiets.delete('Fisch');
|
||||
activeDiets.add('Vegan');
|
||||
} else if (dietValue === 'Fleisch' || dietValue === 'Fisch') {
|
||||
// Fleisch/Fisch remove Vegetarisch/Vegan
|
||||
activeDiets.delete('Vegetarisch');
|
||||
activeDiets.delete('Vegan');
|
||||
activeDiets.add(dietValue);
|
||||
}
|
||||
} else {
|
||||
activeDiets.add(dietValue);
|
||||
// Removing a diet
|
||||
activeDiets.delete(dietValue);
|
||||
}
|
||||
|
||||
updateDietAvailability();
|
||||
} else if (allergieValue !== null) {
|
||||
// Allergie filter: toggle selection
|
||||
if (activeAllergies.has(allergieValue)) {
|
||||
@@ -679,10 +755,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Clear all filters button
|
||||
const clearAllFiltersBtn = document.getElementById('clear-all-filters');
|
||||
if (clearAllFiltersBtn) {
|
||||
clearAllFiltersBtn.addEventListener('click', () => {
|
||||
activeCategory = 'ALLE';
|
||||
activeDiets.clear();
|
||||
activeAllergies.clear();
|
||||
|
||||
if (locationFilter) {
|
||||
locationFilter.value = 'ALLE_ORTE';
|
||||
}
|
||||
if (dateFilter) {
|
||||
dateFilter.value = '';
|
||||
}
|
||||
|
||||
updateDietAvailability();
|
||||
applyFilters();
|
||||
});
|
||||
}
|
||||
|
||||
// Info button modal behavior
|
||||
const infoButton = document.getElementById('info-button');
|
||||
const infoModal = document.getElementById('info-modal');
|
||||
const modalClose = infoModal?.querySelector('.modal-close');
|
||||
const modalClose = infoModal?.querySelector('modal-close');
|
||||
|
||||
if (infoButton && infoModal) {
|
||||
infoButton.addEventListener('click', () => {
|
||||
@@ -717,3 +813,18 @@
|
||||
// Kick off initial load/render cycle.
|
||||
fetchEvents();
|
||||
});
|
||||
|
||||
// Modal closing helper functions
|
||||
function closeRegisterModal() {
|
||||
const modal = document.getElementById('register-confirm-modal');
|
||||
if (modal) {
|
||||
modal.classList.remove('show');
|
||||
}
|
||||
}
|
||||
|
||||
function closeUnregisterModal() {
|
||||
const modal = document.getElementById('unregister-confirm-modal');
|
||||
if (modal) {
|
||||
modal.classList.remove('show');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user