Actualizar usuarios.html
This commit is contained in:
@@ -169,13 +169,13 @@
|
|||||||
sel.innerHTML = '<option value="">-- Seleccionar --</option>';
|
sel.innerHTML = '<option value="">-- Seleccionar --</option>';
|
||||||
provinciasES.sort().forEach(p => {
|
provinciasES.sort().forEach(p => {
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
opt.value = p;
|
opt.value = p.toUpperCase();
|
||||||
opt.innerText = p.toUpperCase();
|
opt.innerText = p.toUpperCase();
|
||||||
sel.appendChild(opt);
|
sel.appendChild(opt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// LÓGICA DE CARGA CORREGIDA (NUEVA API)
|
// LÓGICA DE CARGA USANDO TU PROPIA BASE DE DATOS
|
||||||
async function fetchMunicipios(provName) {
|
async function fetchMunicipios(provName) {
|
||||||
const selMun = document.getElementById('selMunicipio');
|
const selMun = document.getElementById('selMunicipio');
|
||||||
const loader = document.getElementById('loaderMun');
|
const loader = document.getElementById('loaderMun');
|
||||||
@@ -185,32 +185,46 @@
|
|||||||
|
|
||||||
loader.classList.remove('hidden');
|
loader.classList.remove('hidden');
|
||||||
try {
|
try {
|
||||||
// Fuente estable de municipios de España
|
// Llamada a tu propio endpoint del server
|
||||||
const res = await fetch(`https://raw.githubusercontent.com/palmerabollo/municipios-es/master/municipios.json`);
|
const res = await fetch(`${API_URL}/api/geo/municipios/${provName}`, {
|
||||||
const allData = await res.json();
|
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||||
const filtered = allData.filter(m => m.provincia.toUpperCase() === provName.toUpperCase());
|
|
||||||
|
|
||||||
selMun.innerHTML = '<option value="">-- Selecciona Pueblo --</option>';
|
|
||||||
filtered.sort((a,b) => a.nombre.localeCompare(b.nombre)).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();
|
|
||||||
selMun.appendChild(opt);
|
|
||||||
});
|
});
|
||||||
selMun.disabled = false;
|
const data = await res.json();
|
||||||
} catch (e) { showToast("Error cargando municipios", true); }
|
|
||||||
|
if (data.ok) {
|
||||||
|
selMun.innerHTML = '<option value="">-- Selecciona Pueblo --</option>';
|
||||||
|
data.municipios.forEach(m => {
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
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 al cargar municipios desde la DB local", true); }
|
||||||
finally { loader.classList.add('hidden'); lucide.createIcons(); }
|
finally { loader.classList.add('hidden'); lucide.createIcons(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function autoFillCP(munName) {
|
function autoFillCP(munName) {
|
||||||
const sel = document.getElementById('selMunicipio');
|
const sel = document.getElementById('selMunicipio');
|
||||||
const selectedOpt = sel.options[sel.selectedIndex];
|
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) {
|
if(selectedOpt && selectedOpt.dataset.cp) {
|
||||||
document.getElementById('cpInput').value = 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 prov = document.getElementById('selProvince').value;
|
||||||
const mun = document.getElementById('selMunicipio').value;
|
const mun = document.getElementById('selMunicipio').value;
|
||||||
const cp = document.getElementById('cpInput').value.trim();
|
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)) {
|
if (tempUserZones.some(z => z.city === mun && z.cps === cp)) {
|
||||||
showToast("Esta zona ya está añadida", true); return;
|
showToast("Esta zona ya está añadida", true); return;
|
||||||
@@ -372,7 +386,7 @@
|
|||||||
const list = document.getElementById('guildsList');
|
const list = document.getElementById('guildsList');
|
||||||
list.innerHTML = "";
|
list.innerHTML = "";
|
||||||
availableGuilds.forEach(g => {
|
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();
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user