| 
									
										
										
										
											2025-06-06 13:26:44 +02:00
										 |  |  | function colorHeadingTable() { | 
					
						
							|  |  |  |   const headers = document.querySelectorAll('th'); | 
					
						
							|  |  |  |   headers.forEach(header => { | 
					
						
							|  |  |  |     const text = header.textContent; | 
					
						
							|  |  |  |     const match = text.match(/\((\d+)\s*\/\s*(\d+)\)/); | 
					
						
							|  |  |  |     if (match) { | 
					
						
							|  |  |  |       const [_, completed, total] = match; | 
					
						
							|  |  |  |       const ratio = completed / total; | 
					
						
							|  |  |  |       const alpha = ratio.toFixed(2); | 
					
						
							|  |  |  |       header.style.backgroundColor = `rgba(154, 205, 50, ${alpha})`; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-06 23:01:03 +02:00
										 |  |  | function check_validity(e) { | 
					
						
							| 
									
										
										
										
											2025-06-07 00:23:36 +02:00
										 |  |  |   list_inputs_good_to_fill = [ | 
					
						
							|  |  |  |     'input[name="commerce_tag_value__contact:email"]', | 
					
						
							|  |  |  |     'input[name="commerce_tag_value__contact:phone"]', | 
					
						
							|  |  |  |     'input[name="commerce_tag_value__contact:website"]', | 
					
						
							| 
									
										
										
										
											2025-06-17 16:23:29 +02:00
										 |  |  |     'input[name="commerce_tag_value__contact:mastodon"]', | 
					
						
							| 
									
										
										
										
											2025-06-07 00:23:36 +02:00
										 |  |  |     'input[name="commerce_tag_value__address"]', | 
					
						
							|  |  |  |     'input[name="custom_opening_hours"]', | 
					
						
							|  |  |  |     'input[name="commerce_tag_value__contact:street"]', | 
					
						
							|  |  |  |     'input[name="commerce_tag_value__contact:housenumber"]', | 
					
						
							|  |  |  |     'input[name="custom__cuisine"]', | 
					
						
							|  |  |  |   ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   list_inputs_good_to_fill.forEach(selector => { | 
					
						
							|  |  |  |     const input = document.querySelector(selector); | 
					
						
							|  |  |  |     if (input) { | 
					
						
							|  |  |  |       if (input.value.trim() !== '') { | 
					
						
							|  |  |  |         input.classList.add('good_filled'); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         input.classList.remove('good_filled'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2025-06-06 23:01:03 +02:00
										 |  |  |   let errors = []; | 
					
						
							|  |  |  |   document.querySelectorAll('.is-invalid').forEach(input => { | 
					
						
							|  |  |  |     input.classList.remove('is-invalid'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const nameInput = document.querySelector('input[name="commerce_tag_value__name"]'); | 
					
						
							|  |  |  |   if (!nameInput.value.trim()) { | 
					
						
							|  |  |  |     errors.push("Le nom de l'établissement est obligatoire"); | 
					
						
							|  |  |  |     nameInput.classList.add('is-invalid'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const emailInput = document.querySelector('input[name="commerce_tag_value__contact:email"]'); | 
					
						
							|  |  |  |   if (emailInput && emailInput.value) { | 
					
						
							|  |  |  |     const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | 
					
						
							|  |  |  |     if (!emailRegex.test(emailInput.value)) { | 
					
						
							|  |  |  |       errors.push("L'adresse email n'est pas valide"); | 
					
						
							|  |  |  |       emailInput.classList.add('is-invalid'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const phoneInput = document.querySelector('input[name="commerce_tag_value__contact:phone"]'); | 
					
						
							|  |  |  |   if (phoneInput && phoneInput.value) { | 
					
						
							|  |  |  |     const phoneRegex = /^(\+33|0)[1-9](\d{2}){4}$/; | 
					
						
							|  |  |  |     if (!phoneRegex.test(phoneInput.value.replace(/\s/g, ''))) { | 
					
						
							|  |  |  |       errors.push("Le numéro de téléphone n'est pas valide"); | 
					
						
							|  |  |  |       phoneInput.classList.add('is-invalid'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (errors.length > 0) { | 
					
						
							|  |  |  |     e.preventDefault(); | 
					
						
							|  |  |  |     document.querySelector('#validation_messages').innerHTML = errors.join('<br>'); | 
					
						
							|  |  |  |     document.querySelector('#validation_messages').classList.add('is-invalid'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export const genererCouleurPastel = () => { | 
					
						
							| 
									
										
										
										
											2025-06-06 23:01:03 +02:00
										 |  |  |   const r = Math.floor(Math.random() * 75 + 180); | 
					
						
							|  |  |  |   const g = Math.floor(Math.random() * 75 + 180); | 
					
						
							|  |  |  |   const b = Math.floor(Math.random() * 75 + 180); | 
					
						
							|  |  |  |   return `rgb(${r}, ${g}, ${b})`; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function searchInseeCode(query) { | 
					
						
							|  |  |  |   try { | 
					
						
							|  |  |  |     document.querySelector('#loading_search_insee').classList.remove('d-none'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const response = await fetch(`https://geo.api.gouv.fr/communes?nom=${query}&fields=nom,code,codesPostaux&limit=10`); | 
					
						
							|  |  |  |     const data = await response.json(); | 
					
						
							|  |  |  |     document.querySelector('#loading_search_insee').classList.add('d-none'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return data.map(commune => ({ | 
					
						
							|  |  |  |       label: `${commune.nom} (${commune.codesPostaux.join(', ')}, code insee ${commune.code})`, | 
					
						
							|  |  |  |       insee: commune.code, | 
					
						
							|  |  |  |       postcodes: commune.codesPostaux | 
					
						
							|  |  |  |     })); | 
					
						
							|  |  |  |   } catch (error) { | 
					
						
							|  |  |  |     console.error('Erreur lors de la recherche du code INSEE:', error); | 
					
						
							|  |  |  |     return []; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-06 23:28:35 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-23 00:38:13 +02:00
										 |  |  | export function updateMapHeightForLargeScreens() { | 
					
						
							| 
									
										
										
										
											2025-06-06 23:28:35 +02:00
										 |  |  |   const mapFound = document.querySelector('#map'); | 
					
						
							| 
									
										
										
										
											2025-06-26 19:18:29 +02:00
										 |  |  |   const canvasFound = document.querySelector('#map canvas'); | 
					
						
							|  |  |  |   const newHeight = window.innerHeight * 0.5 + 'px' | 
					
						
							| 
									
										
										
										
											2025-06-06 23:28:35 +02:00
										 |  |  |   if (mapFound && window.innerHeight > 800 && window.innerWidth > 800) { | 
					
						
							| 
									
										
										
										
											2025-06-26 19:18:29 +02:00
										 |  |  |     mapFound.style.height = newHeight; | 
					
						
							| 
									
										
										
										
											2025-06-06 23:28:35 +02:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     console.log('window.innerHeight', window.innerHeight); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function listChangesets() { | 
					
						
							|  |  |  |   const options = { | 
					
						
							|  |  |  |     headers: { | 
					
						
							|  |  |  |       'Accept': 'application/json' | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   const changesets = await fetch('https://api.openstreetmap.org/api/0.6/changesets?display_name=osm-commerce-fr', options); | 
					
						
							|  |  |  |   const data = await changesets.json(); | 
					
						
							|  |  |  |   console.log(data.changesets.length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const now = new Date(); | 
					
						
							|  |  |  |   const last24h = new Date(now - 24 * 60 * 60 * 1000); | 
					
						
							|  |  |  |   const last7days = new Date(now - 7 * 24 * 60 * 60 * 1000); | 
					
						
							|  |  |  |   const last30days = new Date(now - 30 * 24 * 60 * 60 * 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const stats = { | 
					
						
							|  |  |  |     last24h: 0, | 
					
						
							|  |  |  |     last7days: 0, | 
					
						
							|  |  |  |     last30days: 0 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   data.changesets.forEach(changeset => { | 
					
						
							|  |  |  |     const changesetDate = new Date(changeset.closed_at); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (changesetDate >= last24h) { | 
					
						
							|  |  |  |       stats.last24h++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (changesetDate >= last7days) { | 
					
						
							|  |  |  |       stats.last7days++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (changesetDate >= last30days) { | 
					
						
							|  |  |  |       stats.last30days++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const historyDiv = document.getElementById('userChangesHistory'); | 
					
						
							|  |  |  |   if (historyDiv) { | 
					
						
							|  |  |  |     historyDiv.innerHTML = `
 | 
					
						
							|  |  |  |       <div id="changesets_history"> | 
					
						
							|  |  |  |         <p>Changesets créés :</p> | 
					
						
							|  |  |  |         <div class="row"> | 
					
						
							|  |  |  |            <div class="col-6">Dernières 24h :</div> <div class="col-6 text-right">${stats.last24h}</div> | 
					
						
							|  |  |  |            <div class="col-6">7 derniers jours :</div> <div class="col-6 text-right">${stats.last7days}</div> | 
					
						
							|  |  |  |            <div class="col-6">30 derniers jours :</div> <div class="col-6 text-right">${stats.last30days}</div> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function openInPanoramax() { | 
					
						
							|  |  |  |   const center = map.getCenter(); | 
					
						
							|  |  |  |   const zoom = map.getZoom(); | 
					
						
							|  |  |  |   const panoramaxUrl = `https://api.panoramax.xyz/?focus=map&map=${zoom}/${center.lat}/${center.lng}`; | 
					
						
							|  |  |  |   window.open(panoramaxUrl); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export function enableLabourageForm() { | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |   const citySearchInput = document.getElementById('citySearch'); | 
					
						
							|  |  |  |   const citySuggestionsList = document.getElementById('citySuggestions'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (citySearchInput && citySuggestionsList) { | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |     const form = citySearchInput.closest('form'); | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |     setupCitySearch('citySearch', 'citySuggestions', function (result_search) { | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |       if (form) { | 
					
						
							| 
									
										
										
										
											2025-06-23 00:38:13 +02:00
										 |  |  |         const labourageBtn = form.querySelector('button[type="submit"]'); | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |         if (labourageBtn) { | 
					
						
							| 
									
										
										
										
											2025-06-23 00:38:13 +02:00
										 |  |  |             // Remplir le champ caché avec le code INSEE
 | 
					
						
							|  |  |  |             const inseeInput = form.querySelector('#selectedZipCode'); | 
					
						
							|  |  |  |             if (inseeInput) { | 
					
						
							|  |  |  |                 inseeInput.value = result_search.insee; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             // Changer l'action du formulaire pour pointer vers la bonne URL
 | 
					
						
							|  |  |  |             form.action = getLabourerUrl(result_search); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Changer le texte du bouton et le désactiver
 | 
					
						
							| 
									
										
										
										
											2025-08-21 11:56:02 +02:00
										 |  |  |             labourageBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Ajout de ' + result_search.name + '...'; | 
					
						
							| 
									
										
										
										
											2025-06-23 00:38:13 +02:00
										 |  |  |             labourageBtn.disabled = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Soumettre le formulaire
 | 
					
						
							|  |  |  |             form.submit(); | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-06-26 19:18:29 +02:00
										 |  |  |       }else{ | 
					
						
							|  |  |  |         console.warn('pas de form pour labourage trouvé') | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2025-06-26 19:18:29 +02:00
										 |  |  |   }else{ | 
					
						
							|  |  |  |     console.warn('pas de labourage citySearchInput citySuggestionsList trouvé', citySearchInput,citySuggestionsList ) | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export function setupCitySearch(inputId, suggestionListId, onSelect) { | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |   const searchInput = document.getElementById(inputId); | 
					
						
							|  |  |  |   const suggestionList = document.getElementById(suggestionListId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!searchInput || !suggestionList) return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let timeoutId = null; | 
					
						
							|  |  |  |   let searchOngoing = false; | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-23 00:38:13 +02:00
										 |  |  |   searchInput.addEventListener('keyup', function () { | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |     clearTimeout(timeoutId); | 
					
						
							|  |  |  |     const query = this.value.trim(); | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |     if (query.length < 3) { | 
					
						
							|  |  |  |       clearSuggestions(); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |     timeoutId = setTimeout(() => { | 
					
						
							|  |  |  |       if (!searchOngoing) { | 
					
						
							|  |  |  |         searchOngoing = true; | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |         performSearch(query).then(() => { | 
					
						
							|  |  |  |             searchOngoing = false; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     }, 300); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |   async function performSearch(query) { | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       const response = await fetch(`https://geo.api.gouv.fr/communes?nom=${encodeURIComponent(query)}&fields=nom,code,codesPostaux&limit=5`); | 
					
						
							|  |  |  |       const data = await response.json(); | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |       const citySuggestions = data.map(city => ({ | 
					
						
							|  |  |  |         name: city.nom, | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |         insee: city.code, | 
					
						
							| 
									
										
										
										
											2025-07-12 13:45:09 +02:00
										 |  |  |         postcodes: city.codesPostaux, | 
					
						
							|  |  |  |         postcode: city.codesPostaux && city.codesPostaux.length > 0 ? city.codesPostaux[0] : '', | 
					
						
							|  |  |  |         display_name: `${city.nom} (${city.codesPostaux && city.codesPostaux.length > 0 ? city.codesPostaux[0] : ''})` | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |       })); | 
					
						
							|  |  |  |       displaySuggestions(citySuggestions); | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |     } catch (error) { | 
					
						
							|  |  |  |       console.error("Erreur de recherche:", error); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |   function displaySuggestions(suggestions) { | 
					
						
							|  |  |  |     clearSuggestions(); | 
					
						
							|  |  |  |     suggestions.forEach(suggestion => { | 
					
						
							|  |  |  |       const item = document.createElement('div'); | 
					
						
							|  |  |  |       item.classList.add('suggestion-item'); | 
					
						
							| 
									
										
										
										
											2025-07-12 13:32:08 +02:00
										 |  |  |       // Nouveau rendu : nom en gras, INSEE et CP en petit/gris
 | 
					
						
							|  |  |  |       item.innerHTML = `
 | 
					
						
							| 
									
										
										
										
											2025-07-12 13:45:09 +02:00
										 |  |  |         <span class="suggestion-name" style="font-weight:bold;">${suggestion.name}</span><br> | 
					
						
							|  |  |  |         <span class="suggestion-details" style="font-size:0.95em;color:#666;"> | 
					
						
							|  |  |  |           <span>INSEE : <b>${suggestion.insee}</b></span> | 
					
						
							|  |  |  |           <span style="margin-left:12px;">CP : <b>${Array.isArray(suggestion.postcodes) ? suggestion.postcodes.join(', ') : suggestion.postcode}</b></span> | 
					
						
							| 
									
										
										
										
											2025-07-12 13:32:08 +02:00
										 |  |  |         </span> | 
					
						
							|  |  |  |       `;
 | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |       item.addEventListener('click', () => { | 
					
						
							| 
									
										
										
										
											2025-07-12 13:32:08 +02:00
										 |  |  |         searchInput.value = suggestion.name; | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |         clearSuggestions(); | 
					
						
							|  |  |  |         if (onSelect) { | 
					
						
							|  |  |  |           onSelect(suggestion); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       suggestionList.appendChild(item); | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |     suggestionList.style.display = 'block'; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |   function clearSuggestions() { | 
					
						
							|  |  |  |     suggestionList.innerHTML = ''; | 
					
						
							|  |  |  |     suggestionList.style.display = 'none'; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |   document.addEventListener('click', (e) => { | 
					
						
							|  |  |  |     if (!searchInput.contains(e.target) && !suggestionList.contains(e.target)) { | 
					
						
							|  |  |  |       clearSuggestions(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export function getLabourerUrl(obj) { | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |   if (obj && obj.insee) { | 
					
						
							| 
									
										
										
										
											2025-08-21 11:56:02 +02:00
										 |  |  |     return `/add-city-without-labourage/${obj.insee}`; | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   return '#'; | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export function handleAddCityFormSubmit(event) { | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |     event.preventDefault(); | 
					
						
							|  |  |  |     const zipCode = document.getElementById('selectedZipCode').value; | 
					
						
							|  |  |  |     if (zipCode && zipCode.match(/^\d{5}$/)) { | 
					
						
							| 
									
										
										
										
											2025-08-21 11:56:02 +02:00
										 |  |  |         window.location.href = `/add-city-without-labourage/${zipCode}`; | 
					
						
							| 
									
										
										
										
											2025-06-21 10:26:55 +02:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         alert('Veuillez sélectionner une ville valide avec un code postal.'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export function colorizePercentageCells(selector, color = '154, 205, 50') { | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |   document.querySelectorAll(selector).forEach(cell => { | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |     const percentage = parseInt(cell.textContent.replace('%', ''), 10); | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |     if (!isNaN(percentage)) { | 
					
						
							|  |  |  |       const alpha = percentage / 100; | 
					
						
							|  |  |  |       cell.style.backgroundColor = `rgba(${color}, ${alpha})`; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export function colorizePercentageCellsRelative(selector, color = '154, 205, 50') { | 
					
						
							|  |  |  |   let min = Infinity; | 
					
						
							|  |  |  |   let max = -Infinity; | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |   const cells = document.querySelectorAll(selector); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   cells.forEach(cell => { | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |     const value = parseInt(cell.textContent.replace('%', ''), 10); | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |     if (!isNaN(value)) { | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |       min = Math.min(min, value); | 
					
						
							|  |  |  |       max = Math.max(max, value); | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (max > min) { | 
					
						
							|  |  |  |     cells.forEach(cell => { | 
					
						
							|  |  |  |       const value = parseInt(cell.textContent.replace('%', ''), 10); | 
					
						
							|  |  |  |       if (!isNaN(value)) { | 
					
						
							|  |  |  |         const ratio = (value - min) / (max - min); | 
					
						
							|  |  |  |         cell.style.backgroundColor = `rgba(${color}, ${ratio.toFixed(2)})`; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export function adjustListGroupFontSize(selector, minFont = 0.8, maxFont = 1.2) { | 
					
						
							|  |  |  |   const listItems = document.querySelectorAll(selector); | 
					
						
							|  |  |  |   if (listItems.length === 0) return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |   let fontSize = maxFont; | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |   const count = listItems.length; | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |   if (count > 0) { | 
					
						
							|  |  |  |     fontSize = Math.max(minFont, maxFont - (count - 5) * 0.05); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  |   listItems.forEach(item => { | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  |     item.style.fontSize = fontSize + 'rem'; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | export function calculateCompletion(properties) { | 
					
						
							|  |  |  |     let completed = 0; | 
					
						
							|  |  |  |     const total = 7; // Nombre de critères
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (properties.name) completed++; | 
					
						
							|  |  |  |     if (properties['addr:housenumber'] && properties['addr:street']) completed++; | 
					
						
							|  |  |  |     if (properties.opening_hours) completed++; | 
					
						
							|  |  |  |     if (properties.website || properties['contact:website']) completed++; | 
					
						
							|  |  |  |     if (properties.phone || properties['contact:phone']) completed++; | 
					
						
							|  |  |  |     if (properties.wheelchair) completed++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |         percentage: total > 0 ? (completed / total) * 100 : 0, | 
					
						
							|  |  |  |         completed: completed, | 
					
						
							|  |  |  |         total: total | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-21 18:37:31 +02:00
										 |  |  | export function toggleCompletionInfo() { | 
					
						
							|  |  |  |     const content = document.getElementById('completionInfoContent'); | 
					
						
							|  |  |  |     const icon = document.getElementById('completionInfoIcon'); | 
					
						
							|  |  |  |     if (content) { | 
					
						
							|  |  |  |         const isVisible = content.style.display === 'block'; | 
					
						
							|  |  |  |         content.style.display = isVisible ? 'none' : 'block'; | 
					
						
							|  |  |  |         if (icon) { | 
					
						
							|  |  |  |             icon.classList.toggle('bi-chevron-down', isVisible); | 
					
						
							|  |  |  |             icon.classList.toggle('bi-chevron-up', !isVisible); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-18 00:41:24 +02:00
										 |  |  | window.check_validity = check_validity; | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | window.colorHeadingTable = colorHeadingTable; | 
					
						
							| 
									
										
										
										
											2025-06-06 23:28:35 +02:00
										 |  |  | window.openInPanoramax = openInPanoramax; | 
					
						
							|  |  |  | window.listChangesets = listChangesets; | 
					
						
							| 
									
										
										
										
											2025-06-21 11:28:31 +02:00
										 |  |  | window.adjustListGroupFontSize = adjustListGroupFontSize;  | 
					
						
							| 
									
										
										
										
											2025-06-21 18:37:31 +02:00
										 |  |  | window.calculateCompletion = calculateCompletion; | 
					
						
							|  |  |  | window.toggleCompletionInfo = toggleCompletionInfo; |