Actualizar usuarios.html
This commit is contained in:
@@ -169,13 +169,13 @@
|
||||
sel.innerHTML = '<option value="">-- Seleccionar --</option>';
|
||||
provinciasES.sort().forEach(p => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = p;
|
||||
opt.value = p.toUpperCase();
|
||||
opt.innerText = p.toUpperCase();
|
||||
sel.appendChild(opt);
|
||||
});
|
||||
}
|
||||
|
||||
// LÓGICA DE CARGA CORREGIDA (NUEVA API)
|
||||
// LÓGICA DE CARGA USANDO TU PROPIA BASE DE DATOS
|
||||
async function fetchMunicipios(provName) {
|
||||
const selMun = document.getElementById('selMunicipio');
|
||||
const loader = document.getElementById('loaderMun');
|
||||
@@ -185,32 +185,46 @@
|
||||
|
||||
loader.classList.remove('hidden');
|
||||
try {
|
||||
// Fuente estable de municipios de España
|
||||
const res = await fetch(`https://raw.githubusercontent.com/palmerabollo/municipios-es/master/municipios.json`);
|
||||
const allData = await res.json();
|
||||
const filtered = allData.filter(m => m.provincia.toUpperCase() === provName.toUpperCase());
|
||||
// Llamada a tu propio endpoint del server
|
||||
const res = await fetch(`${API_URL}/api/geo/municipios/${provName}`, {
|
||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.ok) {
|
||||
selMun.innerHTML = '<option value="">-- Selecciona Pueblo --</option>';
|
||||
filtered.sort((a,b) => a.nombre.localeCompare(b.nombre)).forEach(m => {
|
||||
data.municipios.forEach(m => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = m.nombre;
|
||||
// Sugerimos el código postal si viene en la API
|
||||
opt.dataset.cp = m.codigo_postal || "";
|
||||
opt.innerText = m.nombre.toUpperCase();
|
||||
opt.value = m.municipio;
|
||||
opt.dataset.cp = m.codigo_postal;
|
||||
opt.innerText = m.municipio.toUpperCase();
|
||||
selMun.appendChild(opt);
|
||||
});
|
||||
// Opción de respaldo manual
|
||||
selMun.innerHTML += '<option value="OTRO">-- NO ESTÁ EN LA LISTA (MANUAL) --</option>';
|
||||
selMun.disabled = false;
|
||||
} catch (e) { showToast("Error cargando municipios", true); }
|
||||
}
|
||||
} catch (e) { showToast("Error al cargar municipios desde la DB local", true); }
|
||||
finally { loader.classList.add('hidden'); lucide.createIcons(); }
|
||||
}
|
||||
|
||||
function autoFillCP(munName) {
|
||||
const sel = document.getElementById('selMunicipio');
|
||||
const selectedOpt = sel.options[sel.selectedIndex];
|
||||
if (munName === "OTRO") {
|
||||
const customMun = prompt("Nombre del Municipio:");
|
||||
if (customMun) {
|
||||
const newOpt = document.createElement('option');
|
||||
newOpt.value = customMun.toUpperCase();
|
||||
newOpt.innerText = customMun.toUpperCase();
|
||||
newOpt.selected = true;
|
||||
sel.appendChild(newOpt);
|
||||
document.getElementById('cpInput').focus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(selectedOpt && selectedOpt.dataset.cp) {
|
||||
document.getElementById('cpInput').value = selectedOpt.dataset.cp;
|
||||
} else {
|
||||
document.getElementById('cpInput').value = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +232,7 @@
|
||||
const prov = document.getElementById('selProvince').value;
|
||||
const mun = document.getElementById('selMunicipio').value;
|
||||
const cp = document.getElementById('cpInput').value.trim();
|
||||
if (!prov || !mun || !cp) { showToast("Completa los datos de zona", true); return; }
|
||||
if (!prov || !mun || !cp || mun === "OTRO") { showToast("Completa los datos de zona", true); return; }
|
||||
|
||||
if (tempUserZones.some(z => z.city === mun && z.cps === cp)) {
|
||||
showToast("Esta zona ya está añadida", true); return;
|
||||
@@ -372,7 +386,7 @@
|
||||
const list = document.getElementById('guildsList');
|
||||
list.innerHTML = "";
|
||||
availableGuilds.forEach(g => {
|
||||
list.innerHTML += `<div class="flex justify-between items-center bg-white p-2 rounded border shadow-sm"><span class="text-xs font-black uppercase text-slate-700">${g.name}</span><button onclick="deleteGuild(${g.id})" class="text-gray-400 hover:text-red-500 transition-colors text-left"><i data-lucide="trash-2" class="w-3.5 h-3.5 text-left"></i></button></div>`;
|
||||
list.innerHTML += `<div class="flex justify-between items-center bg-white p-2 rounded border shadow-sm"><span class="text-xs font-black uppercase text-slate-700">${g.name}</span><button type="button" onclick="deleteGuild(${g.id})" class="text-gray-400 hover:text-red-500 transition-colors text-left"><i data-lucide="trash-2" class="w-3.5 h-3.5 text-left"></i></button></div>`;
|
||||
});
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user