From 8d838d7a1ae0c4181c255697f86aa2a76b6099fb Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 15 Feb 2026 16:20:08 +0000 Subject: [PATCH] Actualizar usuarios.html --- usuarios.html | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/usuarios.html b/usuarios.html index 6cacd17..c7b8c41 100644 --- a/usuarios.html +++ b/usuarios.html @@ -154,20 +154,19 @@ let currentUsers = []; let tempUserZones = []; - // Listado de Provincias const provinciasES = ["Álava","Albacete","Alicante","Almería","Asturias","Ávila","Badajoz","Baleares","Barcelona","Burgos","Cáceres","Cádiz","Cantabria","Castellón","Ciudad Real","Córdoba","A Coruña","Cuenca","Gipuzkoa","Girona","Granada","Guadalajara","Huelva","Huesca","Jaén","León","Lleida","Lugo","Madrid","Málaga","Murcia","Navarra","Ourense","Palencia","Las Palmas","Pontevedra","La Rioja","Salamanca","Segovia","Sevilla","Soria","Tarragona","Santa Cruz de Tenerife","Teruel","Toledo","Valencia","Valladolid","Bizkaia","Zamora","Zaragoza","Ceuta","Melilla"]; document.addEventListener("DOMContentLoaded", () => { if (!localStorage.getItem("token")) { window.location.href = "index.html"; return; } fetchGuilds(); fetchUsers(); - setupProvinceSelect(); // + setupProvinceSelect(); }); - // --- LÓGICA DE GEOGRAFÍA (API) --- function setupProvinceSelect() { const sel = document.getElementById('selProvince'); if(!sel) return; + sel.innerHTML = ''; provinciasES.sort().forEach(p => { const opt = document.createElement('option'); opt.value = p; @@ -176,6 +175,7 @@ }); } + // LÓGICA DE CARGA CORREGIDA (NUEVA API) async function fetchMunicipios(provName) { const selMun = document.getElementById('selMunicipio'); const loader = document.getElementById('loaderMun'); @@ -185,8 +185,8 @@ loader.classList.remove('hidden'); try { - // API Pública de Municipios - const res = await fetch(`https://raw.githubusercontent.com/IversoftSolutions/municipios-espana/master/municipios.json`); + // 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()); @@ -194,7 +194,8 @@ filtered.sort((a,b) => a.nombre.localeCompare(b.nombre)).forEach(m => { const opt = document.createElement('option'); opt.value = m.nombre; - opt.dataset.cp = m.cp_base || m.codigo_postal || ""; + // Sugerimos el código postal si viene en la API + opt.dataset.cp = m.codigo_postal || ""; opt.innerText = m.nombre.toUpperCase(); selMun.appendChild(opt); }); @@ -208,6 +209,8 @@ const selectedOpt = sel.options[sel.selectedIndex]; if(selectedOpt && selectedOpt.dataset.cp) { document.getElementById('cpInput').value = selectedOpt.dataset.cp; + } else { + document.getElementById('cpInput').value = ""; } } @@ -223,6 +226,7 @@ tempUserZones.push({ province: prov, city: mun, cps: cp }); renderTempZones(); + document.getElementById('cpInput').value = ""; } function removeTempZone(idx) { @@ -243,7 +247,6 @@ lucide.createIcons(); } - // --- GREMIOS --- async function fetchGuilds() { try { const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); @@ -273,7 +276,6 @@ } catch(e) { showToast("Error", true); } } - // --- USUARIOS --- async function fetchUsers() { try { const res = await fetch(`${API_URL}/admin/users`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); @@ -370,7 +372,7 @@ const list = document.getElementById('guildsList'); list.innerHTML = ""; availableGuilds.forEach(g => { - list.innerHTML += `
${g.name}
`; + list.innerHTML += `
${g.name}
`; }); lucide.createIcons(); } @@ -379,7 +381,7 @@ const area = document.getElementById('guildsCheckboxArea'); area.innerHTML = availableGuilds.length === 0 ? '

No hay gremios registrados...

' : ""; availableGuilds.forEach(g => { - area.innerHTML += ``; + area.innerHTML += ``; }); }