Actualizar usuarios.html
This commit is contained in:
217
usuarios.html
217
usuarios.html
@@ -6,40 +6,59 @@
|
||||
<title>Gestión de Usuarios - IntegraRepara</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script src="https://unpkg.com/lucide@latest"></script>
|
||||
<style>.fade-in { animation: fadeIn 0.5s ease-in-out; } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } .no-scrollbar::-webkit-scrollbar { display: none; }</style>
|
||||
<style>
|
||||
/* VARIABLES CORPORATIVAS DINÁMICAS */
|
||||
:root {
|
||||
--primary: #2563eb;
|
||||
--secondary: #10b981; /* Verde base para algunas acciones */
|
||||
--app-bg: #f8fafc;
|
||||
}
|
||||
|
||||
body { background-color: var(--app-bg); }
|
||||
.fade-in { animation: fadeIn 0.5s ease-in-out; }
|
||||
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
||||
.no-scrollbar::-webkit-scrollbar { display: none; }
|
||||
|
||||
/* Clases CSS dinámicas para aplicar las variables */
|
||||
.text-primary-dynamic { color: var(--primary) !important; }
|
||||
.bg-primary-dynamic { background-color: var(--primary) !important; }
|
||||
.border-primary-dynamic { border-color: var(--primary) !important; }
|
||||
.ring-primary-dynamic { --tw-ring-color: var(--primary) !important; }
|
||||
.focus\:ring-primary-dynamic:focus { --tw-ring-color: var(--primary) !important; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-gray-50 text-gray-800 font-sans antialiased text-left">
|
||||
<body class="text-slate-800 font-sans antialiased text-left">
|
||||
|
||||
<div class="flex h-screen overflow-hidden text-left">
|
||||
<div id="sidebar-container" class="h-full shrink-0"></div>
|
||||
<div class="flex-1 flex flex-col overflow-hidden relative">
|
||||
<div id="header-container"></div>
|
||||
|
||||
<main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-50 p-8 fade-in">
|
||||
<h2 class="text-2xl font-bold text-gray-800 mb-8 text-left">Gestión de Equipo y Zonas</h2>
|
||||
<main class="flex-1 overflow-x-hidden overflow-y-auto p-8 fade-in relative z-10">
|
||||
<h2 class="text-2xl font-black text-slate-800 mb-8 text-left tracking-tight">Gestión de Equipo y Zonas</h2>
|
||||
|
||||
<div class="flex flex-col gap-8 max-w-5xl mx-auto text-left">
|
||||
|
||||
<div class="w-full bg-white p-6 rounded-xl shadow-sm border border-gray-100">
|
||||
<div class="flex items-center gap-3 mb-4 text-blue-600 text-left">
|
||||
<div class="w-full bg-white p-6 rounded-[2rem] shadow-sm border border-slate-100">
|
||||
<div class="flex items-center gap-3 mb-4 text-primary-dynamic text-left">
|
||||
<i data-lucide="hammer" class="w-6 h-6"></i>
|
||||
<h3 class="text-lg font-bold text-gray-800">1. Gremios / Especialidades</h3>
|
||||
<h3 class="text-lg font-black text-slate-800 tracking-tight">1. Gremios / Especialidades</h3>
|
||||
</div>
|
||||
<div class="flex flex-col md:flex-row gap-6 text-left">
|
||||
<form onsubmit="addGuild(event)" class="flex gap-2 h-10 w-full md:w-1/2 text-left">
|
||||
<input type="text" id="newGuildName" placeholder="NUEVO GREMIO (EJ. LIMPIEZA)" required class="flex-1 px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm uppercase">
|
||||
<button type="submit" class="bg-slate-800 text-white px-4 rounded-lg hover:bg-slate-700 font-bold"><i data-lucide="plus" class="w-5 h-5"></i></button>
|
||||
<form onsubmit="addGuild(event)" class="flex gap-3 h-12 w-full md:w-1/2 text-left">
|
||||
<input type="text" id="newGuildName" placeholder="NUEVO GREMIO (EJ. LIMPIEZA)" required class="flex-1 px-4 py-3 border border-slate-200 rounded-xl focus:ring-2 focus:ring-primary-dynamic focus:border-primary-dynamic outline-none text-sm font-bold uppercase transition-all bg-slate-50">
|
||||
<button type="submit" class="bg-primary-dynamic text-white px-5 rounded-xl hover:opacity-90 font-black shadow-md transition-all active:scale-95 flex items-center justify-center"><i data-lucide="plus" class="w-5 h-5"></i></button>
|
||||
</form>
|
||||
<div class="w-full md:w-1/2 border rounded-lg bg-gray-50 p-2 max-h-40 overflow-y-auto space-y-2 no-scrollbar" id="guildsList"></div>
|
||||
<div class="w-full md:w-1/2 border border-slate-200 rounded-xl bg-slate-50 p-3 max-h-40 overflow-y-auto space-y-2 no-scrollbar" id="guildsList"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-full bg-white p-6 rounded-xl shadow-sm border border-gray-100 relative text-left">
|
||||
<button onclick="resetUserForm()" id="btnCancelEdit" class="hidden absolute top-6 right-6 text-sm text-red-500 hover:underline font-bold">Cancelar Edición</button>
|
||||
<div class="w-full bg-white p-8 rounded-[2rem] shadow-sm border border-slate-100 relative text-left">
|
||||
<button onclick="resetUserForm()" id="btnCancelEdit" class="hidden absolute top-8 right-8 text-xs text-rose-500 hover:text-rose-600 font-black uppercase tracking-widest bg-rose-50 px-3 py-1.5 rounded-lg transition-colors border border-rose-100">Cancelar Edición</button>
|
||||
|
||||
<div class="flex items-center gap-3 mb-6 text-green-600 text-left">
|
||||
<div class="flex items-center gap-3 mb-6 text-emerald-600 text-left">
|
||||
<i data-lucide="user-plus" class="w-6 h-6"></i>
|
||||
<h3 class="text-lg font-bold text-gray-800" id="formTitle">2. Ficha de Usuario y Cobertura</h3>
|
||||
<h3 class="text-lg font-black text-slate-800 tracking-tight" id="formTitle">2. Ficha de Usuario y Cobertura</h3>
|
||||
</div>
|
||||
|
||||
<form onsubmit="handleUserSubmit(event)" class="space-y-6 text-left">
|
||||
@@ -47,88 +66,89 @@
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 text-left">
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-xs font-black text-gray-400 uppercase mb-1">Nombre Completo</label>
|
||||
<input type="text" id="uName" required class="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-green-500 outline-none font-bold">
|
||||
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5 ml-1">Nombre Completo</label>
|
||||
<input type="text" id="uName" required class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-emerald-500/30 focus:border-emerald-500 outline-none font-bold text-sm transition-all shadow-inner">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-black text-gray-400 uppercase mb-1">Correo Electrónico</label>
|
||||
<input type="email" id="uEmail" required class="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-green-500 outline-none">
|
||||
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5 ml-1">Correo Electrónico</label>
|
||||
<input type="email" id="uEmail" required class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-emerald-500/30 focus:border-emerald-500 outline-none font-bold text-sm transition-all shadow-inner">
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-xs font-black text-gray-400 uppercase mb-1">Teléfono</label>
|
||||
<input type="tel" id="uPhone" required placeholder="+34 600..." class="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-green-500 outline-none font-bold text-green-700">
|
||||
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5 ml-1">Teléfono</label>
|
||||
<input type="tel" id="uPhone" required placeholder="+34 600..." class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-emerald-500/30 focus:border-emerald-500 outline-none font-black text-emerald-700 text-sm transition-all shadow-inner">
|
||||
</div>
|
||||
<div class="flex gap-4 text-left">
|
||||
<div class="w-1/2">
|
||||
<label class="block text-xs font-black text-gray-400 uppercase mb-1">Rol</label>
|
||||
<select id="uRole" class="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-green-500 outline-none bg-white font-bold">
|
||||
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5 ml-1">Rol</label>
|
||||
<select id="uRole" class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-emerald-500/30 focus:border-emerald-500 outline-none font-bold text-sm transition-all shadow-inner uppercase tracking-wider text-slate-600 appearance-none cursor-pointer">
|
||||
<option value="operario">Operario</option>
|
||||
<option value="facturacion">Facturación</option>
|
||||
<option value="admin">Administrador</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="w-1/2">
|
||||
<label class="block text-xs font-black text-gray-400 uppercase mb-1">Contraseña</label>
|
||||
<input type="password" id="uPass" class="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-green-500 outline-none" placeholder="••••••••">
|
||||
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5 ml-1">Contraseña</label>
|
||||
<input type="password" id="uPass" class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-emerald-500/30 focus:border-emerald-500 outline-none font-bold text-sm transition-all shadow-inner" placeholder="••••••••">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pt-2 text-left">
|
||||
<label class="block text-xs font-black text-gray-400 uppercase mb-2">Gremios Asignados</label>
|
||||
<div class="p-4 border rounded-lg bg-gray-50 grid grid-cols-2 md:grid-cols-4 gap-3 text-left" id="guildsCheckboxArea"></div>
|
||||
<div class="pt-4 text-left border-t border-slate-100">
|
||||
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-3 ml-1 flex items-center gap-1.5"><i data-lucide="hammer" class="w-3 h-3 text-emerald-500"></i> Gremios Asignados</label>
|
||||
<div class="p-4 border border-slate-200 rounded-2xl bg-slate-50 grid grid-cols-2 md:grid-cols-4 gap-3 text-left shadow-inner" id="guildsCheckboxArea"></div>
|
||||
</div>
|
||||
|
||||
<div class="pt-2 text-left">
|
||||
<label class="block text-xs font-black text-blue-600 uppercase mb-2 tracking-widest text-left">Cobertura Geográfica (Toda España)</label>
|
||||
<div class="bg-blue-50/50 border-2 border-blue-100 rounded-2xl p-5 space-y-4 text-left">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-3 text-left">
|
||||
<div class="pt-4 text-left border-t border-slate-100">
|
||||
<label class="block text-[10px] font-black text-primary-dynamic uppercase mb-3 tracking-widest text-left flex items-center gap-1.5"><i data-lucide="map" class="w-3 h-3"></i> Cobertura Geográfica (Toda España)</label>
|
||||
<div class="bg-primary-dynamic/5 border-2 border-primary-dynamic/20 rounded-[1.5rem] p-6 space-y-5 text-left">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-left">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-blue-500 mb-1 uppercase">1. Provincia</label>
|
||||
<select id="selProvince" onchange="fetchMunicipios(this.value)" class="w-full text-sm p-2.5 border rounded-lg outline-none focus:border-blue-500 font-bold bg-white">
|
||||
<label class="block text-[9px] font-black text-primary-dynamic mb-1.5 uppercase tracking-widest">1. Provincia</label>
|
||||
<select id="selProvince" onchange="fetchMunicipios(this.value)" class="w-full text-xs font-bold p-3.5 border border-primary-dynamic/30 rounded-xl outline-none focus:ring-2 focus:ring-primary-dynamic/40 bg-white cursor-pointer shadow-sm text-slate-700">
|
||||
<option value="">-- Seleccionar --</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="relative text-left">
|
||||
<label class="block text-[10px] font-bold text-blue-500 mb-1 uppercase text-left">2. Municipio</label>
|
||||
<select id="selMunicipio" onchange="autoFillCP(this.value)" class="w-full text-sm p-2.5 border rounded-lg outline-none focus:border-blue-500 font-bold bg-white disabled:opacity-50" disabled>
|
||||
<label class="block text-[9px] font-black text-primary-dynamic mb-1.5 uppercase tracking-widest text-left">2. Municipio</label>
|
||||
<select id="selMunicipio" onchange="autoFillCP(this.value)" class="w-full text-xs font-bold p-3.5 border border-primary-dynamic/30 rounded-xl outline-none focus:ring-2 focus:ring-primary-dynamic/40 bg-white disabled:opacity-50 cursor-pointer shadow-sm text-slate-700" disabled>
|
||||
<option value="">-- Elige Municipio --</option>
|
||||
</select>
|
||||
<div id="loaderMun" class="hidden absolute right-10 top-9"><i data-lucide="loader-2" class="w-4 h-4 animate-spin text-blue-500"></i></div>
|
||||
<div id="loaderMun" class="hidden absolute right-10 top-11"><i data-lucide="loader-2" class="w-4 h-4 animate-spin text-primary-dynamic"></i></div>
|
||||
</div>
|
||||
<div class="text-left">
|
||||
<label class="block text-[10px] font-bold text-blue-500 mb-1 uppercase text-left">3. Código(s) Postal(es)</label>
|
||||
<div class="flex gap-1 text-left">
|
||||
<input type="text" id="cpInput" placeholder="Ej: 11201-11207" class="flex-1 text-sm p-2.5 border rounded-lg font-black outline-none focus:border-blue-500 text-blue-700">
|
||||
<button type="button" onclick="addZoneToUser()" class="bg-blue-600 text-white px-4 rounded-lg font-black hover:bg-blue-700 transition-all shadow-md active:scale-95">
|
||||
<label class="block text-[9px] font-black text-primary-dynamic mb-1.5 uppercase tracking-widest text-left">3. Código(s) Postal(es)</label>
|
||||
<div class="flex gap-2 text-left">
|
||||
<input type="text" id="cpInput" placeholder="Ej: 11201-11207" class="flex-1 text-xs font-black p-3.5 border border-primary-dynamic/30 rounded-xl outline-none focus:ring-2 focus:ring-primary-dynamic/40 bg-white text-primary-dynamic shadow-inner">
|
||||
<button type="button" onclick="addZoneToUser()" class="bg-primary-dynamic text-white px-5 rounded-xl font-black hover:opacity-90 transition-all shadow-md active:scale-95 flex items-center justify-center">
|
||||
<i data-lucide="plus" class="w-5 h-5"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="userZonesArea" class="flex flex-wrap gap-2 min-h-[50px] p-3 bg-white rounded-xl border border-blue-100 shadow-inner text-left"></div>
|
||||
<div id="userZonesArea" class="flex flex-wrap gap-2 min-h-[60px] p-4 bg-white rounded-[1.5rem] border border-primary-dynamic/20 shadow-inner text-left"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pt-4 border-t border-gray-100 text-left">
|
||||
<button type="submit" id="btnSubmitUser" class="w-full bg-green-600 hover:bg-green-700 text-white font-black py-4 rounded-xl transition-all shadow-lg shadow-green-500/30 uppercase tracking-widest text-sm text-left justify-center flex items-center">
|
||||
Guardar Usuario y Zonas
|
||||
<div class="pt-6 text-left">
|
||||
<button type="submit" id="btnSubmitUser" class="w-full bg-emerald-500 hover:bg-emerald-600 text-white font-black py-4 rounded-[1.5rem] transition-all shadow-lg shadow-emerald-500/30 uppercase tracking-widest text-xs text-left justify-center flex items-center gap-2 active:scale-95">
|
||||
<i data-lucide="save" class="w-4 h-4"></i> Guardar Usuario y Zonas
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="w-full bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden text-left">
|
||||
<div class="p-6 border-b border-gray-100 bg-gray-50 text-left">
|
||||
<h3 class="font-bold text-gray-800">Listado de Equipo</h3>
|
||||
<div class="w-full bg-white rounded-[2rem] shadow-sm border border-slate-100 overflow-hidden text-left mb-10">
|
||||
<div class="p-6 border-b border-slate-100 bg-slate-50 text-left flex items-center gap-2">
|
||||
<i data-lucide="users" class="w-5 h-5 text-slate-400"></i>
|
||||
<h3 class="font-black text-slate-800 uppercase tracking-tight">Listado de Equipo</h3>
|
||||
</div>
|
||||
<div class="overflow-x-auto no-scrollbar text-left">
|
||||
<div class="overflow-x-auto no-scrollbar text-left p-2">
|
||||
<table class="w-full text-left border-collapse">
|
||||
<thead>
|
||||
<tr class="bg-white text-gray-400 text-[10px] font-black uppercase tracking-[0.2em] border-b text-left">
|
||||
<tr class="bg-white text-slate-400 text-[10px] font-black uppercase tracking-[0.2em] border-b border-slate-100 text-left">
|
||||
<th class="p-4">Personal</th>
|
||||
<th class="p-4">Contacto</th>
|
||||
<th class="p-4">Rol / Gremios</th>
|
||||
@@ -136,7 +156,7 @@
|
||||
<th class="p-4 text-right">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="usersListBody" class="text-sm divide-y divide-gray-100 text-left"></tbody>
|
||||
<tbody id="usersListBody" class="text-sm divide-y divide-slate-50 text-left"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -146,18 +166,44 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="fixed bottom-5 right-5 bg-slate-800 text-white px-6 py-3 rounded-lg shadow-2xl transform translate-y-20 opacity-0 transition-all duration-300 z-50 flex items-center gap-3"><span id="toastMsg">Mensaje</span></div>
|
||||
<div id="toast" class="fixed bottom-5 right-5 bg-slate-800 text-white px-6 py-3 rounded-xl shadow-2xl transform translate-y-20 opacity-0 transition-all duration-300 z-50 flex items-center gap-3 font-bold text-xs uppercase tracking-widest"><span id="toastMsg">Mensaje</span></div>
|
||||
|
||||
<script src="js/layout.js"></script>
|
||||
<script>
|
||||
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
||||
? 'http://localhost:3000'
|
||||
: 'https://integrarepara-api.integrarepara.es';
|
||||
|
||||
let availableGuilds = [];
|
||||
let currentUsers = [];
|
||||
let tempUserZones = [];
|
||||
|
||||
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", () => {
|
||||
// --- SISTEMA DE TEMA DINÁMICO ---
|
||||
async function applyTheme() {
|
||||
try {
|
||||
let theme = JSON.parse(localStorage.getItem('app_theme'));
|
||||
const res = await fetch(`${API_URL}/config/company`, {
|
||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||
});
|
||||
const data = await res.json();
|
||||
if(data.ok && data.config && data.config.portal_settings && data.config.portal_settings.app_settings) {
|
||||
theme = data.config.portal_settings.app_settings;
|
||||
localStorage.setItem('app_theme', JSON.stringify(theme));
|
||||
}
|
||||
if(theme) {
|
||||
document.documentElement.style.setProperty('--primary', theme.primary);
|
||||
document.documentElement.style.setProperty('--secondary', theme.secondary);
|
||||
document.documentElement.style.setProperty('--app-bg', theme.bg);
|
||||
}
|
||||
} catch (e) { console.warn("Usando tema por defecto"); }
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
if (!localStorage.getItem("token")) { window.location.href = "index.html"; return; }
|
||||
await applyTheme();
|
||||
lucide.createIcons();
|
||||
fetchGuilds();
|
||||
fetchUsers();
|
||||
setupProvinceSelect();
|
||||
@@ -263,7 +309,7 @@
|
||||
function renderTempZones() {
|
||||
const area = document.getElementById('userZonesArea');
|
||||
if(!area) return;
|
||||
area.innerHTML = tempUserZones.length === 0 ? '<p class="text-[10px] text-gray-300 italic p-1">Sin zonas añadidas...</p>' : "";
|
||||
area.innerHTML = tempUserZones.length === 0 ? '<p class="text-[10px] text-slate-400 italic p-1 font-bold">Sin zonas añadidas...</p>' : "";
|
||||
|
||||
const visualGroup = tempUserZones.reduce((acc, curr) => {
|
||||
if(!acc[curr.city]) acc[curr.city] = [];
|
||||
@@ -273,9 +319,9 @@
|
||||
|
||||
Object.keys(visualGroup).forEach(city => {
|
||||
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">
|
||||
<span class="bg-primary-dynamic/10 text-primary-dynamic px-3 py-1.5 rounded-lg text-[10px] font-black border border-primary-dynamic/20 flex items-center gap-2 shadow-sm">
|
||||
${city} (${visualGroup[city].length} CPs)
|
||||
<button type="button" onclick="removeTempCity('${city}')" class="text-blue-400 hover:text-red-500"><i data-lucide="x" class="w-3 h-3"></i></button>
|
||||
<button type="button" onclick="removeTempCity('${city}')" class="text-primary-dynamic hover:text-red-500 transition-colors"><i data-lucide="x" class="w-3.5 h-3.5"></i></button>
|
||||
</span>`;
|
||||
});
|
||||
lucide.createIcons();
|
||||
@@ -319,7 +365,8 @@
|
||||
const userId = document.getElementById('editUserId').value;
|
||||
const isEdit = !!userId;
|
||||
const btn = document.getElementById('btnSubmitUser');
|
||||
btn.disabled = true; btn.innerText = "PROCESANDO...";
|
||||
btn.disabled = true; btn.innerHTML = '<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i> PROCESANDO...';
|
||||
lucide.createIcons();
|
||||
|
||||
const selectedGuilds = Array.from(document.querySelectorAll('.guild-checkbox:checked')).map(cb => cb.value);
|
||||
const data = {
|
||||
@@ -340,10 +387,10 @@
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.ok) { showToast(isEdit ? "Actualizado" : "Creado"); resetUserForm(); fetchUsers(); }
|
||||
if (json.ok) { showToast(isEdit ? "Usuario Actualizado" : "Usuario Creado"); resetUserForm(); fetchUsers(); }
|
||||
else { showToast("Error: " + json.error, true); }
|
||||
} catch (e) { showToast("Error conexión", true); }
|
||||
finally { btn.disabled = false; btn.innerText = isEdit ? "Actualizar Datos" : "Guardar Usuario y Zonas"; }
|
||||
finally { btn.disabled = false; btn.innerHTML = isEdit ? '<i data-lucide="save" class="w-4 h-4"></i> Actualizar Datos' : '<i data-lucide="save" class="w-4 h-4"></i> Guardar Usuario y Zonas'; lucide.createIcons(); }
|
||||
}
|
||||
|
||||
function editUser(id) {
|
||||
@@ -365,10 +412,10 @@
|
||||
}
|
||||
|
||||
async function deleteUser(id) {
|
||||
if(!confirm("¿Borrar usuario?")) return;
|
||||
if(!confirm("¿Borrar usuario definitivamente?")) return;
|
||||
try {
|
||||
await fetch(`${API_URL}/admin/users/${id}`, { method: 'DELETE', headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||
fetchUsers(); showToast("Borrado");
|
||||
fetchUsers(); showToast("Usuario borrado");
|
||||
} catch(e) { showToast("Error", true); }
|
||||
}
|
||||
|
||||
@@ -380,7 +427,7 @@
|
||||
document.getElementById('uPass').value = "";
|
||||
tempUserZones = [];
|
||||
renderTempZones();
|
||||
document.getElementById('formTitle').innerText = "2. Nuevo Usuario";
|
||||
document.getElementById('formTitle').innerText = "2. Nueva Ficha de Usuario";
|
||||
document.getElementById('btnCancelEdit').classList.add('hidden');
|
||||
document.querySelectorAll('.guild-checkbox').forEach(cb => cb.checked = false);
|
||||
}
|
||||
@@ -389,23 +436,23 @@
|
||||
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-400 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.5 rounded-xl border border-slate-100 shadow-sm"><span class="text-[10px] font-black uppercase tracking-widest text-slate-700">${g.name}</span><button onclick="deleteGuild(${g.id})" class="text-slate-300 hover:text-red-500 transition-colors p-1 bg-slate-50 rounded-md"><i data-lucide="trash-2" class="w-3.5 h-3.5"></i></button></div>`;
|
||||
});
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
function renderGuildsCheckboxes() {
|
||||
const area = document.getElementById('guildsCheckboxArea');
|
||||
area.innerHTML = availableGuilds.length === 0 ? '<p class="text-xs text-gray-300 italic">No hay gremios...</p>' : "";
|
||||
area.innerHTML = availableGuilds.length === 0 ? '<p class="text-xs text-slate-400 italic">No hay gremios...</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.5 hover:bg-emerald-50 rounded-xl border border-transparent hover:border-emerald-200 transition-all"><input type="checkbox" value="${g.id}" class="guild-checkbox h-4 w-4 text-emerald-600 border-slate-300 rounded focus:ring-emerald-500"><span class="text-[10px] font-black uppercase tracking-widest text-slate-600">${g.name}</span></label>`;
|
||||
});
|
||||
}
|
||||
|
||||
function renderUsersTable() {
|
||||
const tbody = document.getElementById('usersListBody');
|
||||
if (!tbody) return;
|
||||
tbody.innerHTML = currentUsers.length === 0 ? `<tr><td colspan="5" class="p-8 text-center text-gray-300 font-bold uppercase tracking-widest text-left">Cargando equipo...</td></tr>` : "";
|
||||
tbody.innerHTML = currentUsers.length === 0 ? `<tr><td colspan="5" class="p-8 text-center text-slate-400 font-black uppercase tracking-widest text-xs">Cargando equipo...</td></tr>` : "";
|
||||
|
||||
currentUsers.forEach(u => {
|
||||
const isActive = u.status === 'active';
|
||||
@@ -418,30 +465,33 @@
|
||||
}, {});
|
||||
|
||||
const uZonesHtml = Object.keys(groupedZones).map(city => {
|
||||
return `<div class="mb-1 last:mb-0"><span class="font-black ${isActive ? 'text-blue-600' : 'text-gray-400'} text-[10px] uppercase">📍 ${city}</span> <span class="text-gray-500 text-[9px]">(${groupedZones[city].join(", ")})</span></div>`;
|
||||
}).join("") || '<span class="text-[9px] text-gray-300 italic">Sin zona</span>';
|
||||
return `<div class="mb-1.5 last:mb-0"><span class="font-black ${isActive ? 'text-primary-dynamic' : 'text-slate-400'} text-[10px] uppercase tracking-wider"><i data-lucide="map-pin" class="w-3 h-3 inline"></i> ${city}</span> <span class="text-slate-500 text-[9px] font-bold">(${groupedZones[city].join(", ")})</span></div>`;
|
||||
}).join("") || '<span class="text-[9px] text-slate-400 font-bold italic">Sin zona</span>';
|
||||
|
||||
tbody.innerHTML += `
|
||||
<tr class="${isActive ? 'bg-white' : 'bg-gray-100 opacity-60'} hover:bg-gray-50 transition border-b">
|
||||
<tr class="${isActive ? 'bg-white' : 'bg-slate-50 opacity-70'} hover:bg-slate-50/80 transition-colors border-b border-slate-100">
|
||||
<td class="p-4">
|
||||
<div class="flex flex-col">
|
||||
<div class="flex items-center gap-2">
|
||||
${!isActive ? '<i data-lucide="lock" class="w-3 h-3 text-red-500"></i>' : ''}
|
||||
<span class="font-black ${isActive ? 'text-slate-800' : 'text-gray-500'} uppercase">${u.full_name}</span>
|
||||
${!isActive ? '<i data-lucide="lock" class="w-3.5 h-3.5 text-rose-500"></i>' : '<div class="w-2 h-2 rounded-full bg-emerald-500"></div>'}
|
||||
<span class="font-black ${isActive ? 'text-slate-800' : 'text-slate-500'} uppercase text-xs">${u.full_name}</span>
|
||||
</div>
|
||||
<span class="text-[9px] text-gray-400 font-bold">${u.email}</span>
|
||||
${!isActive ? '<span class="text-[8px] font-black text-red-500 mt-1 uppercase tracking-tighter">[ Baja Temporal ]</span>' : ''}
|
||||
<span class="text-[10px] text-slate-400 font-bold mt-1">${u.email}</span>
|
||||
${!isActive ? '<span class="text-[8px] font-black text-rose-500 mt-1.5 uppercase tracking-widest bg-rose-50 px-2 py-0.5 rounded-md w-max border border-rose-100">[ Baja Temporal ]</span>' : ''}
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-4 font-black ${isActive ? 'text-green-600' : 'text-gray-400'}">${u.phone}</td>
|
||||
<td class="p-4"><span class="${isActive ? 'bg-slate-100 text-slate-600' : 'bg-gray-200 text-gray-400'} px-2 py-0.5 rounded text-[10px] font-black uppercase">${u.role}</span><p class="text-[9px] text-gray-400 mt-1 uppercase font-bold">${uGuildNames || '-'}</p></td>
|
||||
<td class="p-4 font-black ${isActive ? 'text-emerald-600' : 'text-slate-400'} text-xs">${u.phone}</td>
|
||||
<td class="p-4">
|
||||
<span class="${isActive ? 'bg-blue-50 text-blue-600 border border-blue-100' : 'bg-slate-200 text-slate-500 border border-slate-300'} px-2.5 py-1 rounded-lg text-[9px] font-black uppercase tracking-widest">${u.role}</span>
|
||||
<p class="text-[9px] text-slate-500 mt-2 uppercase font-bold tracking-wider leading-tight">${uGuildNames || '-'}</p>
|
||||
</td>
|
||||
<td class="p-4 text-left"><div class="max-h-24 overflow-y-auto no-scrollbar">${uZonesHtml}</div></td>
|
||||
<td class="p-4 text-right space-x-2">
|
||||
<button onclick="editUser(${u.id})" class="text-blue-500 hover:text-blue-700 font-black text-[10px] uppercase">Editar</button>
|
||||
<button onclick="toggleUserStatus(${u.id}, '${u.status || 'active'}')" class="${isActive ? 'text-amber-500 hover:text-amber-700' : 'text-green-500 hover:text-green-700'} font-black text-[10px] uppercase">
|
||||
${isActive ? 'Baja' : 'Activar'}
|
||||
<button onclick="editUser(${u.id})" class="text-blue-500 hover:text-white hover:bg-blue-500 font-black text-[9px] uppercase tracking-widest border border-blue-200 px-3 py-1.5 rounded-lg transition-all shadow-sm">Editar</button>
|
||||
<button onclick="toggleUserStatus(${u.id}, '${u.status || 'active'}')" class="${isActive ? 'text-amber-600 hover:bg-amber-500 hover:text-white border-amber-200' : 'text-emerald-600 hover:bg-emerald-500 hover:text-white border-emerald-200'} font-black text-[9px] uppercase tracking-widest border px-3 py-1.5 rounded-lg transition-all shadow-sm">
|
||||
${isActive ? 'Pausar' : 'Activar'}
|
||||
</button>
|
||||
<button onclick="deleteUser(${u.id})" class="text-red-400 hover:text-red-700 font-black text-[10px] uppercase">Borrar</button>
|
||||
<button onclick="deleteUser(${u.id})" class="text-rose-500 hover:bg-rose-500 hover:text-white font-black text-[9px] uppercase tracking-widest border border-rose-200 px-3 py-1.5 rounded-lg transition-all shadow-sm">Borrar</button>
|
||||
</td>
|
||||
</tr>`;
|
||||
});
|
||||
@@ -450,7 +500,7 @@
|
||||
|
||||
async function toggleUserStatus(id, currentStatus) {
|
||||
const newStatus = currentStatus === 'active' ? 'inactive' : 'active';
|
||||
const msg = newStatus === 'active' ? "¿Reactivar operario?" : "¿Dar de baja temporal?";
|
||||
const msg = newStatus === 'active' ? "¿Reactivar operario para que reciba avisos?" : "¿Dar de baja temporal? (No verá avisos)";
|
||||
if(!confirm(msg)) return;
|
||||
|
||||
try {
|
||||
@@ -464,7 +514,7 @@
|
||||
});
|
||||
const data = await res.json();
|
||||
if(data.ok) {
|
||||
showToast(newStatus === 'active' ? "Operario activado" : "Operario en baja temporal");
|
||||
showToast(newStatus === 'active' ? "Operario activado" : "Operario en baja");
|
||||
fetchUsers();
|
||||
}
|
||||
} catch(e) { showToast("Error de conexión", true); }
|
||||
@@ -472,8 +522,9 @@
|
||||
|
||||
function showToast(msg, err=false){
|
||||
const t=document.getElementById('toast'), m=document.getElementById('toastMsg');
|
||||
t.className=`fixed bottom-5 right-5 px-6 py-3 rounded-xl shadow-2xl transition-all duration-300 z-50 flex items-center gap-3 font-bold ${err?'bg-red-600':'bg-slate-900'} text-white`;
|
||||
m.innerText=msg; t.classList.remove('translate-y-20','opacity-0');
|
||||
t.className=`fixed bottom-5 right-5 px-6 py-4 rounded-2xl shadow-2xl transition-all duration-300 z-50 flex items-center gap-3 font-bold text-xs uppercase tracking-widest ${err?'bg-rose-600':'bg-slate-900'} text-white`;
|
||||
m.innerText=msg;
|
||||
t.classList.remove('translate-y-20','opacity-0');
|
||||
setTimeout(()=>t.classList.add('translate-y-20','opacity-0'),3000);
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user