Ajout d'un filtre sur la page des lieux

This commit is contained in:
Jean-Marie Favreau 2025-05-03 15:55:36 +02:00
parent 51e820821a
commit b3ac6814aa

View File

@ -40,18 +40,21 @@
</header> </header>
<div class="grid"> <div class="grid">
<div id="map_location"></div> <div id="map_location"></div>
<div class="vertical-max"> <div>
{% with cache_timeout=user.is_authenticated|yesno:"300,6000" %} {% with cache_timeout=user.is_authenticated|yesno:"300,6000" %}
{% cache cache_timeout place_lists user.is_authenticated %} {% cache cache_timeout place_lists user.is_authenticated %}
{% if object_list %} {% if object_list %}
<input type="search" id="searchInput" placeholder="Rechercher un lieu...">
<div class="vertical-max" id="placeList">
{% for place in object_list %} {% for place in object_list %}
<div class="item">
<h3> <h3>
<a href="{{ place.get_absolute_url }}">{{ place.name }}</a><a id="open-map-{{ place.id }}" <a href="{{ place.get_absolute_url }}">{{ place.name }}</a><a id="open-map-{{ place.id }}"
href="#map_location" href="#map_location"
data-tooltip="afficher sur la carte">{% picto_from_name "map" %}</a> data-tooltip="afficher sur la carte">{% picto_from_name "map" %}</a>
</h3> </h3>
<ul> <ul>
<li> <li class="address">
<strong>Adresse&nbsp;:</strong> <strong>Adresse&nbsp;:</strong>
{% if place.address %}{{ place.address }},{% endif %} {% if place.address %}{{ place.address }},{% endif %}
{{ place.city }} {{ place.city }}
@ -63,7 +66,9 @@
{% if nb > 0 %}<li>{{ nb }} événement{{ nb|pluralize }} à venir</li>{% endif %} {% if nb > 0 %}<li>{{ nb }} événement{{ nb|pluralize }} à venir</li>{% endif %}
{% endwith %} {% endwith %}
</ul> </ul>
</div>
{% endfor %} {% endfor %}
</div>
{% else %} {% else %}
<p>Il n'y a aucun lieu défini.</p> <p>Il n'y a aucun lieu défini.</p>
{% endif %} {% endif %}
@ -91,6 +96,9 @@
markerArray = []; markerArray = [];
var markers = L.markerClusterGroup({disableClusteringAtZoom:16}); var markers = L.markerClusterGroup({disableClusteringAtZoom:16});
window.mMapping = {}; window.mMapping = {};
{% with cache_timeout=user.is_authenticated|yesno:"300,6000" %}
{% cache cache_timeout place_lists_js_all user.is_authenticated %}
{% if object_list %} {% if object_list %}
{% for place in object_list %} {% for place in object_list %}
markerArray.push(L.marker([{{ place.location|tocoords }}], {'icon': pinIcon}).bindPopup('<a href="{{ place.get_absolute_url }}">{{ place.name }}</a><br />{% if place.address %}{{ place.address }}, {% endif %}{{ place.city }}')) markerArray.push(L.marker([{{ place.location|tocoords }}], {'icon': pinIcon}).bindPopup('<a href="{{ place.get_absolute_url }}">{{ place.name }}</a><br />{% if place.address %}{{ place.address }}, {% endif %}{{ place.city }}'))
@ -102,9 +110,23 @@
}); });
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endcache %}
{% endwith %}
map.addLayer(markers); map.addLayer(markers);
//var group = L.featureGroup(window.markerArray).addTo(map); //var group = L.featureGroup(window.markerArray).addTo(map);
map.fitBounds(markers.getBounds()); map.fitBounds(markers.getBounds());
document.getElementById("searchInput").addEventListener("input", function () {
const filter = this.value.toLowerCase();
const items = document.querySelectorAll("#placeList .item");
items.forEach(item => {
const title = item.querySelector("h3")?.textContent.toLowerCase() || "";
const address = item.querySelector("li.address")?.textContent.toLowerCase() || "";
const content = title + " " + address;
item.style.display = content.includes(filter) ? "" : "none";
});});
</script> </script>
{% endblock %} {% endblock %}