templates/home/search.html.twig line 1
{% extends 'base_search.html.twig' %}
{% block title %}{{ 'search.title'|trans }}{% endblock %}
{% block body %}
<!-- Contenu principal -->
<div class="flex justify-center">
<!-- Formulaire de recherche -->
<form id="search-form" method="GET" action="{{ path('advanced_search') }}" class="space-y-4 w-full max-w-4xl"> <br/>
<!-- Champs de recherche -->
<div class="flex flex-col md:flex-row gap-4">
<!-- Où allez-vous ? (+ rayon) -->
<div class="flex flex-col relative w-full md:w-1/2">
<input
id="address"
type="text"
name="city"
value="{{ app.request.query.get('city') }}"
placeholder="{{ 'tenant.search_placeholder'|trans }}"
class="px-4 py-2 w-full border border-gray-300 rounded-lg">
</div>
<!-- Champs cachés pour lat et lng -->
<input type="hidden" name="lat" id="lat" value="{{ app.request.query.get('lat') }}">
<input type="hidden" name="lng" id="lng" value="{{ app.request.query.get('lng') }}">
<!-- Type de logement -->
<div class="flex flex-col relative w-full md:w-1/2">
<select
id="housing-type-search"
name="type"
class="border border-gray-300 rounded-lg px-4 py-2 w-full text-base">
<option value="" {% if not app.request.query.get('type') %}selected{% endif %}>{{ 'search.housing_type_search'|trans }}</option>
<option value="Appartement" {% if app.request.query.get('type') == 'Appartement' %}selected{% endif %}>{{ 'search.housing_type_apartment'|trans }}</option>
<option value="Maison" {% if app.request.query.get('type') == 'Maison' %}selected{% endif %}>{{ 'search.housing_type_house'|trans }}</option>
<option value="Chambre privée" {% if app.request.query.get('type') == 'Chambre privée' %}selected{% endif %}>{{ 'search.housing_type_private_room'|trans }}</option>
</select>
</div>
</div>
<!-- Budget and Surface Inputs -->
<div class="flex flex-col md:flex-row gap-4 mt-4">
<div class="flex flex-col relative w-full md:w-1/4">
<input
id="min-price"
type="number"
name="minPrice"
placeholder="{{ 'tenant.min_price'|trans }}"
value="{{ app.request.query.get('minPrice') }}"
class="px-4 py-2 w-full border border-gray-300 rounded-lg"
min="0">
</div>
<!-- Budget maximum -->
<div class="flex flex-col relative w-full md:w-1/4">
<input
id="max-price"
type="number"
name="maxPrice"
placeholder="{{ 'tenant.max_price'|trans }}"
value="{{ app.request.query.get('maxPrice') }}"
class="px-4 py-2 w-full border border-gray-300 rounded-lg"
min="0">
</div>
<!-- Surface minimum -->
<div class="flex flex-col relative w-full md:w-1/4">
<input
id="min-surface"
type="number"
name="minSurface"
placeholder="{{ 'tenant.min_surface'|trans }}"
value="{{ app.request.query.get('minSurface') }}"
class="px-4 py-2 w-full border border-gray-300 rounded-lg"
min="0">
</div>
<!-- Surface maximum -->
<div class="flex flex-col relative w-full md:w-1/4">
<input
id="max-surface"
type="number"
name="maxSurface"
placeholder="{{ 'tenant.max_surface'|trans }}"
value="{{ app.request.query.get('maxSurface') }}"
class="px-4 py-2 w-full border border-gray-300 rounded-lg"
min="0">
</div>
</div>
<!-- Affiner les critères de recherche -->
<div class="mt-6">
<h4 class="text-lg font-semibold text-gray-900 text-center">{{ 'tenant.refine_search'|trans }}</h4>
</div>
<div class="flex flex-wrap justify-center gap-4 mt-4">
<!-- Colocation / Coliving -->
<div class="flex items-center space-x-2">
<label class="flex items-center space-x-1">
<input
type="checkbox"
name="isShared"
value="1"
{% if app.request.query.get('isShared') == '1' %}checked{% endif %}
class="form-checkbox text-blue-500">
<span>{{ 'tenant.shared_accommodation'|trans }}</span>
</label>
</div>
<!-- Logement meublé -->
<div class="flex items-center space-x-2">
<label class="flex items-center space-x-1">
<input
type="checkbox"
name="isFurnished"
value="1"
{% if app.request.query.get('isFurnished') == '1' %}checked{% endif %}
class="form-checkbox text-blue-500">
<span>{{ 'tenant.furnished'|trans }}</span>
</label>
</div>
<!-- Salle de bain privée -->
<div class="flex items-center space-x-2">
<label class="flex items-center space-x-1">
<input
type="checkbox"
name="bathroomType"
value="private"
id="bathroom-private"
{% if app.request.query.get('bathroomType') == 'private' %}checked{% endif %}
class="form-checkbox text-purple-500">
<span>{{ 'tenant.bathroom'|trans }}</span>
</label>
</div>
<!-- Filles uniquement -->
<div class="flex items-center space-x-2">
<label class="flex items-center space-x-1">
<input
type="checkbox"
name="girlsOnly"
value="1"
{% if app.request.query.get('girlsOnly') == '1' %}checked{% endif %}
class="form-checkbox text-purple-500">
<span>{{ 'houseRules.fille'|trans }}</span>
</label>
</div>
<!-- Garçons uniquement -->
<div class="flex items-center space-x-2">
<label class="flex items-center space-x-1">
<input
type="checkbox"
name="boysOnly"
value="1"
{% if app.request.query.get('boysOnly') == '1' %}checked{% endif %}
class="form-checkbox text-purple-500">
<span>{{ 'houseRules.garcon'|trans }}</span>
</label>
</div>
<!-- Fumeur autorisé -->
<div class="flex items-center space-x-2">
<label class="flex items-center space-x-1">
<input
type="checkbox"
name="smokingAllowed"
value="1"
{% if app.request.query.get('smokingAllowed') == '1' %}checked{% endif %}
class="form-checkbox text-purple-500">
<span>{{ 'houseRules.fume'|trans }}</span>
</label>
</div>
</div>
<div class="mt-4 flex justify-center">
<div id="dpe-buttons" class="flex gap-2 flex-wrap">
<!-- Boutons A à G -->
{% for grade in ['A', 'B', 'C', 'D', 'E', 'F', 'G'] %}
<button type="button"
data-grade="{{ grade }}"
class="dpe-btn px-3 py-1 rounded-full border-2 font-semibold text-gray-700 border-gray-300 hover:bg-gray-100">
{{ grade }}
</button>
{% endfor %}
<button type="button"
data-grade="Vierge"
class="dpe-btn px-3 py-1 rounded-full border-2 font-semibold text-gray-700 border-gray-300 hover:bg-gray-100">
{{ 'search.vierge'|trans }}
</button>
</div>
</div>
<!-- Bouton de soumission -->
<div class="mt-4 flex justify-center">
<button type="submit" class="text-black bg-[#ffcc00] hover:bg-[#ffcc00] focus:ring-4 focus:outline-none focus:ring-yellow-300 font-medium rounded-full text-sm px-5 py-2.5 text-center w-full md:w-auto">
{{ 'nav.trouverlogement'|trans }}
</button>
</div>
</form>
</div>
<br/>
<script src="https://unpkg.com/flowbite@1.4.0/dist/flowbite.js"></script>
<style>
#map {
height: 400px;
width: 100%;
filter: blur(0px);
transition: filter 0.3s ease-in-out;
}
.image-container {
position: relative;
}
.pagination-button {
background-color: #ffcc00; /* Couleur jaune */
color: black; /* Couleur du texte */
padding: 8px 16px; /* Espacement intérieur */
border-radius: 4px; /* Coins arrondis */
text-decoration: none; /* Supprimer le soulignement */
border: none; /* Supprimer la bordure */
}
.pagination-button:hover {
background-color: #e6b800; /* Couleur jaune légèrement plus foncée au survol */
}
</style>
<div class="container mx-auto">
<h1 class="text-2xl font-bold mb-4">{{ 'search.search_results'|trans }} {{ city }}</h1>
<br><br>
<div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-4">
{% if selectedBuildings is not empty %}
{% for building in selectedBuildings %}
{% set filteredFiles = building.buildingDocuments|filter(item => item.name starts with 'file') %}
<div class="flex flex-col">
<a href="{{ path('detail_building', {id : building.id}) }}" class="building-link">
{% if filteredFiles is not empty %}
<div id="default-carousel" class="relative z-0" data-carousel="static">
<div class="overflow-hidden relative h-[14rem] md:h-[10rem] lg:h-[14rem]">
{% for bd in filteredFiles %}
<a href="{{ path('detail_building', {id : building.id}) }}" class="building-link">
<div class="rounded-xl max-h-[300px] bg-[url({{ asset('images/files/' ~ bd.imageFile) }})] bg-cover bg-no-repeat bg-center hidden duration-700 ease-in-out {% if loop.first %}active{% endif %}" data-carousel-item>
</div>
</a>
{% endfor %}
</div>
<div class="flex absolute border-black bottom-5 left-1/2 z-30 space-x-3 -translate-x-1/2">
{% for document in building.buildingDocuments %}
{% if loop.index0 <= 2 %}
<button type="button" style="border: 1px grey solid;" class="w-3 h-3 rounded-full border border-black" aria-current="false" aria-label="Slide {{building.id}}" data-carousel-slide-to="{{building.id}}"></button>
{% endif %}
{% endfor %}
</div>
{% if building.buildingDocuments|length > 1 %}
<button type="button" class="flex absolute top-0 left-0 z-30 justify-center items-center px-4 h-full cursor-pointer group focus:outline-none" data-carousel-prev>
<span class="inline-flex justify-center items-center w-8 h-8 rounded-full sm:w-10 sm:h-10 bg-white/30 group-hover:bg-white/50 group-focus:ring-4 group-focus:ring-white group-focus:outline-none">
<svg class="w-5 h-5 text-white sm:w-6 sm:h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path></svg>
<span class="hidden">Previous</span>
</span>
</button>
<button type="button" class="flex absolute top-0 right-0 z-30 justify-center items-center px-4 h-full cursor-pointer group focus:outline-none" data-carousel-next>
<span class="inline-flex justify-center items-center w-8 h-8 rounded-full sm:w-10 sm:h-10 bg-white/30 group-hover:bg-white/50 group-focus:ring-4 group-focus:ring-white group-focus:outline-none">
<svg class="w-5 h-5 text-white sm:w-6 sm:h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
<span class="hidden">Next</span>
</span>
</button>
{% endif %}
</div>
{% endif %}
</a>
<div class="row mt-4">
<div class="grid grid-cols-2 gap-4">
<a href="{{ path('detail_building', {id : building.id}) }}" class="cursor-pointer text-sm font-bold">{{ building.cityEntity.city }}, {{ building.cityEntity.country }}</a>
</div>
<div>
<a href="{{ path('detail_building', {id : building.id}) }}" class="cursor-pointer text-sm font-bold">{{ building.rent / 100 }} €</a>
{{ 'accueil.parmois'|trans }}<br>
<a href="{{ path('detail_building', {id : building.id}) }}" class="cursor-pointer text-gray-500 text-sm">{{ 'accueil.add'|trans }}{{ building.createdAt|date('d/m/y') }}<br></a>
{% if building.status == 'Disponible' %}
{% if building.dateStartAt %}
<p class="text-gray-500 text-sm">{{ 'accueil.availableDate'|trans }} {{ building.dateStartAt|date('d/m/y') }}</p>
{% else %}
<p class="text-gray-500 text-sm">{{ 'accueil.availableDateNow'|trans }}</p>
{% endif %}
{% elseif building.dateStartAt %}
<p class="text-gray-500 text-sm">{{ 'accueil.dateStartAt'|trans }} {{ building.dateStartAt|date('d/m/y') }}</p>
{% endif %}
</div>
</div>
</div>
{% endfor %}
{% else %}
<style>
.no-wrap {
white-space: nowrap;
}
</style>
<p class="no-wrap">{{ 'Aucun bien disponible dans cette ville actuellement'|trans }}</p>
{% endif %}
</div> <br/>
<!-- Contrôles de pagination -->
<div class="flex justify-center space-x-2">
{# Affiche "Précédent" uniquement si on est au moins à la page 2 #}
{% if currentPage > 1 %}
<a href="{{ path('advanced_search', query|merge({'page': currentPage - 1})) }}" class="pagination-button">
{{ 'search.previous'|trans }}
</a>
{% endif %}
{# Déterminer les pages à afficher (max 5) #}
{% set startPage = currentPage > 3 ? currentPage - 2 : 1 %}
{% set endPage = (startPage + 4) > pagesCount ? pagesCount : startPage + 4 %}
{# Réajuster startPage si on est proche de la fin #}
{% if endPage - startPage < 4 and pagesCount >= 5 %}
{% set startPage = endPage - 4 > 0 ? endPage - 4 : 1 %}
{% endif %}
{# Boucle sur les pages à afficher #}
{% for page in startPage..endPage %}
{% if page != 0 %}
<a href="{{ path('advanced_search', query|merge({'page': page})) }}"
class="pagination-button {{ page == currentPage ? 'bg-blue-500 text-white' : '' }}">
{{ page }}
</a>
{% endif %}
{% endfor %}
{# Affiche "Suivant" uniquement si on n'est pas à la dernière page #}
{% if currentPage < pagesCount %}
<a href="{{ path('advanced_search', query|merge({'page': currentPage + 1})) }}" class="pagination-button">
{{ 'search.next'|trans }}
</a>
{% endif %}
</div>
<br><br>
<div id="map" style="height: 600px;"></div>
<br><br>
</div>
{% set googleMapsApiKey = app.request.server.get('GOOGLEMAP_KEY') %}
<script>
const googleMapsApiKey = "{{ googleMapsApiKey }}";
var iconMap = "{{ asset('/images/icons/Bons Plans.png') }}";
var selectedBuildingsMap = {{ selectedBuildingsMap|json_encode|raw }};
async function initMap() {
const map = new google.maps.Map(document.getElementById("map"), {
mapId: "b47cb966043d1a05",
center: {
lat: {{ lat }},
lng: {{ lng }}
},
zoom: 12
});
const pinSvgString = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="30px" height="34px" viewBox="0 0 30 40" version="1.1">
<defs>
<filter id="alpha" filterUnits="objectBoundingBox" x="0%" y="0%" width="100%" height="100%">
<feColorMatrix type="matrix" in="SourceGraphic" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0"/>
</filter>
<mask id="mask0">
<g filter="url(#alpha)">
<rect x="0" y="0" width="30" height="40" style="fill:rgb(0%,0%,0%);fill-opacity:0.996078;stroke:none;"/>
</g>
</mask>
<clipPath id="clip1">
<rect x="0" y="0" width="30" height="40"/>
</clipPath>
<g id="surface5" clip-path="url(#clip1)">
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(99.607843%,80.392157%,0%);fill-opacity:1;" d="M 14.472656 0.429688 C 18.484375 0.265625 21.949219 1.511719 24.871094 4.164062 C 28.933594 7.972656 30.359375 12.582031 29.152344 17.984375 C 28.730469 19.613281 28.15625 21.183594 27.425781 22.703125 C 26.023438 25.640625 24.378906 28.429688 22.492188 31.066406 C 20.523438 33.816406 18.417969 36.464844 16.179688 39.019531 C 15.96875 39.238281 15.730469 39.414062 15.457031 39.550781 C 15.1875 39.574219 14.917969 39.574219 14.648438 39.550781 C 14.339844 39.378906 14.066406 39.167969 13.820312 38.914062 C 11.074219 35.8125 8.558594 32.539062 6.273438 29.105469 C 4.929688 27.042969 3.71875 24.894531 2.644531 22.667969 C 1.714844 20.746094 1.066406 18.738281 0.703125 16.644531 C 0.132812 12.804688 1.015625 9.328125 3.347656 6.214844 C 6.113281 2.582031 9.820312 0.65625 14.472656 0.429688 Z M 14.472656 0.429688 "/>
</g>
</defs>
<g id="surface1">
<use xlink:href="#surface5" mask="url(#mask0)"/>
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(7.45098%,7.843137%,8.627451%);fill-opacity:1;" d="M 14.257812 7.695312 C 15.882812 7.558594 17.367188 7.757812 18.984375 8.296875 C 20.640625 8.976562 21.609375 10.1875 21.890625 11.925781 C 22.273438 14.070312 21.621094 15.84375 19.933594 17.246094 C 19.6875 17.445312 19.429688 17.628906 19.160156 17.796875 C 18.753906 18.105469 18.699219 18.46875 19 18.882812 C 20.109375 20.59375 21.199219 22.316406 22.28125 24.042969 C 22.476562 24.546875 22.351562 24.957031 21.910156 25.265625 C 21.496094 25.585938 21.023438 25.746094 20.5 25.75 C 20.308594 25.6875 20.148438 25.578125 20.023438 25.421875 C 18.710938 23.203125 17.417969 20.980469 16.144531 18.742188 C 16.097656 18.542969 16.132812 18.359375 16.25 18.191406 C 16.613281 17.933594 16.984375 17.6875 17.363281 17.453125 C 18.5625 16.527344 19.171875 15.316406 19.195312 13.820312 C 19.253906 12.777344 18.953125 11.847656 18.296875 11.03125 C 17.738281 10.5 17.074219 10.148438 16.304688 9.984375 C 15.792969 9.886719 15.273438 9.816406 14.753906 9.777344 C 14.714844 9.300781 14.605469 8.835938 14.417969 8.382812 C 14.335938 8.246094 14.253906 8.105469 14.171875 7.96875 C 14.136719 7.855469 14.167969 7.765625 14.257812 7.695312 Z M 14.257812 7.695312 "/>
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(7.45098%,7.843137%,8.627451%);fill-opacity:1;" d="M 11.617188 7.726562 C 12.667969 7.652344 13.367188 8.101562 13.714844 9.070312 C 13.890625 9.921875 13.628906 10.605469 12.921875 11.117188 C 11.960938 11.558594 11.179688 11.359375 10.574219 10.515625 C 10.011719 9.496094 10.195312 8.644531 11.121094 7.953125 C 11.285156 7.867188 11.449219 7.792969 11.617188 7.726562 Z M 11.617188 7.726562 "/>
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(7.45098%,7.843137%,8.627451%);fill-opacity:1;" d="M 11.582031 12.132812 C 12.0625 12.101562 12.53125 12.152344 12.992188 12.289062 C 13.125 12.359375 13.210938 12.46875 13.253906 12.617188 C 13.265625 13.429688 13.277344 14.246094 13.289062 15.058594 C 13.320312 15.238281 13.417969 15.359375 13.589844 15.421875 C 14.53125 15.421875 15.472656 15.445312 16.410156 15.492188 C 16.589844 15.550781 16.65625 15.671875 16.605469 15.851562 C 16.511719 16.046875 16.375 16.214844 16.199219 16.351562 C 15.34375 16.9375 14.390625 17.246094 13.34375 17.28125 C 12.695312 17.304688 12.050781 17.304688 11.402344 17.28125 C 11.003906 17.261719 10.761719 17.058594 10.679688 16.679688 C 10.65625 15.324219 10.65625 13.96875 10.730469 12.617188 C 10.730469 12.5 10.808594 12.402344 10.910156 12.324219 C 11.128906 12.234375 11.351562 12.167969 11.582031 12.132812 Z M 11.582031 12.132812 "/>
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(7.45098%,7.843137%,8.627451%);fill-opacity:1;" d="M 8.441406 13.167969 C 8.796875 13.160156 9.148438 13.167969 9.5 13.183594 C 9.621094 13.222656 9.710938 13.296875 9.765625 13.40625 C 9.789062 14.589844 9.789062 15.773438 9.765625 16.953125 C 9.71875 17.101562 9.621094 17.1875 9.464844 17.210938 C 9.085938 17.242188 8.710938 17.230469 8.335938 17.175781 C 8.027344 17.046875 7.835938 16.824219 7.753906 16.507812 C 7.730469 15.609375 7.730469 14.714844 7.753906 13.820312 C 7.886719 13.5 8.117188 13.285156 8.441406 13.167969 Z M 8.441406 13.167969 "/>
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(7.45098%,7.843137%,8.627451%);fill-opacity:1;" d="M 11.441406 18.191406 C 11.816406 18.1875 12.191406 18.191406 12.566406 18.210938 C 12.894531 18.234375 13.125 18.390625 13.253906 18.675781 C 13.277344 20.5 13.277344 22.324219 13.253906 24.148438 C 13.21875 24.523438 13.046875 24.828125 12.742188 25.058594 C 12.265625 25.433594 11.726562 25.667969 11.121094 25.765625 C 10.886719 25.761719 10.742188 25.644531 10.679688 25.421875 C 10.65625 23.195312 10.65625 20.96875 10.679688 18.742188 C 10.71875 18.601562 10.792969 18.480469 10.910156 18.382812 C 11.082031 18.296875 11.257812 18.234375 11.441406 18.191406 Z M 11.441406 18.191406 "/>
</g>
</svg>`
const encodedPins = 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(pinSvgString);
const icon = {
url: encodedPins,
scaledSize: new google.maps.Size(30, 40),
};
//markers pour chaque bâtiment
for (let i = 0; i < selectedBuildingsMap.length; i++) {
let building = selectedBuildingsMap[i];
let lat = parseFloat(selectedBuildingsMap[i].latitude);
let lng = parseFloat(selectedBuildingsMap[i].longitude);
map.setCenter({ lat: parseFloat(selectedBuildingsMap[0].latitude), lng: parseFloat(selectedBuildingsMap[0].longitude) });
if (lat && lng) {
let marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map,
icon,
});
const urlTemplate = '{{ path('detail_building', { id: 'idBuilding' }) }}';
let urlDetailBuilding = urlTemplate.replace('idBuilding', selectedBuildingsMap[i].id);
marker.addListener("click", ()=> { window.location.href = urlDetailBuilding});
}
}
initAutocomplete();
}
window.initMap = initMap;
</script>
{% block scripts %}
<script async src="{{ 'https://maps.googleapis.com/maps/api/js' ~ '?key=' ~ googleMapsApiKey ~ '&callback=initMap&v=beta&libraries=places,geometry,marker' }}"></script>
<script>
var buildings = {{ buildingsMap|json_encode|raw }};
document.addEventListener('DOMContentLoaded', function () {
initMap();
const toggleFiltersButton = document.getElementById('toggle-filters');
const filterOptions = document.getElementById('filter-options');
// Toggle visibility des filtres
toggleFiltersButton.addEventListener('click', function (event) {
event.preventDefault();
filterOptions.classList.toggle('hidden');
});
// Validation du formulaire avant l'envoi
const form = document.querySelector('form');
const addressInput = document.getElementById('address');
const latInput = document.getElementById('lat');
const lngInput = document.getElementById('lng');
const errorMessage = document.createElement('div');
errorMessage.style.color = 'red';
errorMessage.style.marginTop = '10px';
errorMessage.style.display = 'none';
errorMessage.textContent = "{{ 'Indiquez au moins la ville de votre recherche.'|trans }}";
addressInput.parentElement.appendChild(errorMessage);
form.addEventListener('submit', function(event) {
const city = addressInput.value.trim();
const lat = latInput.value.trim();
const lng = lngInput.value.trim();
console.log("City:", city, "Lat:", lat, "Lng:", lng); // Ajout de logs pour le débogage
if (!city || !lat || !lng) {
event.preventDefault(); // Empêcher l'envoi du formulaire
errorMessage.style.display = 'block'; // Afficher le message d'erreur
} else {
errorMessage.style.display = 'none'; // Masquer le message d'erreur si le champ est rempli
}
});
// Gestion des cases à cocher pour la salle de bain
const privateBathroomCheckbox = document.getElementById('bathroom-private');
const sharedBathroomCheckbox = document.getElementById('bathroom-shared');
privateBathroomCheckbox.addEventListener('change', function () {
if (this.checked) {
sharedBathroomCheckbox.checked = false;
}
});
sharedBathroomCheckbox.addEventListener('change', function () {
if (this.checked) {
privateBathroomCheckbox.checked = false;
}
});
});
var autocomplete;
function initAutocomplete() {
var input = document.getElementById('address');
var options = {
types: ['(cities)'], // Limiter aux villes
componentRestrictions: { country: 'fr' } // Limiter aux villes en France
};
// Initialiser l'autocomplétion
autocomplete = new google.maps.places.Autocomplete(input, options);
// Ajouter un écouteur d'événements pour récupérer les données de l'adresse
autocomplete.addListener('place_changed', function () {
var place = autocomplete.getPlace();
var city = "";
// Récupérer les coordonnées latitude et longitude
if (place.geometry) {
document.getElementById('lat').value = place.geometry.location.lat();
document.getElementById('lng').value = place.geometry.location.lng();
initMap()
}
// Extraire uniquement le nom de la ville
place.address_components.forEach(component => {
if (component.types.includes("locality")) {
city = component.long_name;
}
});
// Mettre à jour l'input avec le nom de la ville
document.getElementById('address').value = city;
const form = input.closest('form');
if (form) {
form.submit();
}
});
}
window.initMap = initMap;
</script>
{% endblock %}
{% endblock %}