Actualizar usuarios.html
This commit is contained in:
@@ -186,79 +186,45 @@
|
|||||||
loader.classList.remove('hidden');
|
loader.classList.remove('hidden');
|
||||||
try {
|
try {
|
||||||
// Llamada a tu propio endpoint del server
|
// Llamada a tu propio endpoint del server
|
||||||
|
async function fetchMunicipios(provName) {
|
||||||
|
const selMun = document.getElementById('selMunicipio');
|
||||||
|
const loader = document.getElementById('loaderMun');
|
||||||
|
|
||||||
|
selMun.innerHTML = '<option value="">-- Cargando... --</option>';
|
||||||
|
selMun.disabled = true;
|
||||||
|
if(!provName) return;
|
||||||
|
|
||||||
|
if (loader) loader.classList.remove('hidden');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Llamamos a tu propia base de datos a través del servidor
|
||||||
const res = await fetch(`${API_URL}/api/geo/municipios/${provName}`, {
|
const res = await fetch(`${API_URL}/api/geo/municipios/${provName}`, {
|
||||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.ok) {
|
if (data.ok && data.municipios.length > 0) {
|
||||||
selMun.innerHTML = '<option value="">-- Selecciona Pueblo --</option>';
|
selMun.innerHTML = '<option value="">-- Selecciona Pueblo --</option>';
|
||||||
data.municipios.forEach(m => {
|
data.municipios.forEach(m => {
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
opt.value = m.municipio;
|
opt.value = m.municipio;
|
||||||
opt.dataset.cp = m.codigo_postal;
|
opt.dataset.cp = m.codigo_postal;
|
||||||
opt.innerText = m.municipio.toUpperCase();
|
opt.innerText = `${m.municipio.toUpperCase()} (${m.codigo_postal})`;
|
||||||
selMun.appendChild(opt);
|
selMun.appendChild(opt);
|
||||||
});
|
});
|
||||||
// Opción de respaldo manual
|
|
||||||
selMun.innerHTML += '<option value="OTRO">-- NO ESTÁ EN LA LISTA (MANUAL) --</option>';
|
selMun.innerHTML += '<option value="OTRO">-- NO ESTÁ EN LA LISTA (MANUAL) --</option>';
|
||||||
selMun.disabled = false;
|
selMun.disabled = false;
|
||||||
|
} else {
|
||||||
|
// Si la provincia no tiene datos aún en la DB, mostramos la opción manual
|
||||||
|
selMun.innerHTML = '<option value="OTRO">-- ESCRIBIR MANUALMENTE --</option>';
|
||||||
|
selMun.disabled = false;
|
||||||
}
|
}
|
||||||
} catch (e) { showToast("Error al cargar municipios desde la DB local", true); }
|
} catch (e) {
|
||||||
finally { loader.classList.add('hidden'); lucide.createIcons(); }
|
console.error("Error de conexión con la DB geográfica");
|
||||||
}
|
} finally {
|
||||||
|
if (loader) loader.classList.add('hidden');
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addZoneToUser() {
|
|
||||||
const prov = document.getElementById('selProvince').value;
|
|
||||||
const mun = document.getElementById('selMunicipio').value;
|
|
||||||
const cp = document.getElementById('cpInput').value.trim();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
tempUserZones.push({ province: prov, city: mun, cps: cp });
|
|
||||||
renderTempZones();
|
|
||||||
document.getElementById('cpInput').value = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeTempZone(idx) {
|
|
||||||
tempUserZones.splice(idx, 1);
|
|
||||||
renderTempZones();
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderTempZones() {
|
|
||||||
const area = document.getElementById('userZonesArea');
|
|
||||||
area.innerHTML = tempUserZones.length === 0 ? '<p class="text-[10px] text-gray-300 italic p-1">Sin zonas añadidas...</p>' : "";
|
|
||||||
tempUserZones.forEach((z, i) => {
|
|
||||||
area.innerHTML += `
|
|
||||||
<span class="bg-blue-100 text-blue-700 px-3 py-1.5 rounded-lg text-[10px] font-black border border-blue-200 flex items-center gap-2">
|
|
||||||
${z.city} (${z.cps})
|
|
||||||
<button type="button" onclick="removeTempZone(${i})" class="text-blue-400 hover:text-red-500"><i data-lucide="x" class="w-3 h-3"></i></button>
|
|
||||||
</span>`;
|
|
||||||
});
|
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchGuilds() {
|
async function fetchGuilds() {
|
||||||
|
|||||||
Reference in New Issue
Block a user