mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-06-20 01:44:42 +02:00
93 lines
No EOL
3 KiB
JavaScript
93 lines
No EOL
3 KiB
JavaScript
|
|
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})`;
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function check_validity(e) {
|
|
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');
|
|
}
|
|
}
|
|
// Générer une couleur pastel aléatoire
|
|
const genererCouleurPastel = () => {
|
|
// Utiliser des valeurs plus claires (180-255) pour obtenir des tons pastel
|
|
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})`;
|
|
};
|
|
|
|
|
|
function updateMapHeightForLargeScreens() {
|
|
|
|
const mapFound = document.querySelector('#map');
|
|
if (mapFound && window.innerHeight > 800 && window.innerWidth > 800) {
|
|
mapFound.style.height = '80vh';
|
|
} else {
|
|
console.log('window.innerHeight', window.innerHeight);
|
|
}
|
|
}
|
|
|
|
async function searchInseeCode(query) {
|
|
try {
|
|
|
|
// Afficher l'indicateur de chargement
|
|
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 [];
|
|
}
|
|
} |