Actualizar usuarios.html
This commit is contained in:
@@ -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 = '<option value="">-- Seleccionar --</option>';
|
||||
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 += `<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-300 hover:text-red-500 transition-colors"><i data-lucide="trash-2" class="w-3.5 h-3.5"></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 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();
|
||||
}
|
||||
@@ -379,7 +381,7 @@
|
||||
const area = document.getElementById('guildsCheckboxArea');
|
||||
area.innerHTML = availableGuilds.length === 0 ? '<p class="text-xs text-gray-300 italic">No hay gremios registrados...</p>' : "";
|
||||
availableGuilds.forEach(g => {
|
||||
area.innerHTML += `<label class="flex items-center space-x-2 cursor-pointer p-2 hover:bg-white rounded border border-transparent hover:border-green-200 transition-all"><input type="checkbox" value="${g.id}" class="guild-checkbox h-4 w-4 text-green-600 border-gray-300 rounded"><span class="text-[10px] font-black uppercase text-slate-500">${g.name}</span></label>`;
|
||||
area.innerHTML += `<label class="flex items-center space-x-2 cursor-pointer p-2 hover:bg-white rounded border border-transparent hover:border-green-200 transition-all text-left"><input type="checkbox" value="${g.id}" class="guild-checkbox form-checkbox h-4 w-4 text-green-600 border-gray-300 rounded text-left"><span class="text-[10px] font-black uppercase text-slate-500 text-left">${g.name}</span></label>`;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user