Actualizar usuarios.html
This commit is contained in:
@@ -175,7 +175,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
// LÓGICA DE CARGA USANDO TU PROPIA BASE DE DATOS
|
||||
async function fetchMunicipios(provName) {
|
||||
const selMun = document.getElementById('selMunicipio');
|
||||
const loader = document.getElementById('loaderMun');
|
||||
@@ -183,21 +182,9 @@
|
||||
selMun.disabled = true;
|
||||
if(!provName) return;
|
||||
|
||||
loader.classList.remove('hidden');
|
||||
try {
|
||||
// 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}`, {
|
||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||
});
|
||||
@@ -215,7 +202,6 @@
|
||||
selMun.innerHTML += '<option value="OTRO">-- NO ESTÁ EN LA LISTA (MANUAL) --</option>';
|
||||
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;
|
||||
}
|
||||
@@ -225,7 +211,60 @@
|
||||
if (loader) 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;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
async function fetchGuilds() {
|
||||
try {
|
||||
@@ -361,7 +400,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 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>`;
|
||||
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 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