Actualizar configuracion.html
This commit is contained in:
@@ -24,36 +24,45 @@
|
||||
<main class="flex-1 overflow-hidden flex flex-col p-6 fade-in">
|
||||
|
||||
<h2 class="text-2xl font-bold text-gray-800 mb-6 flex items-center gap-2">
|
||||
<i data-lucide="settings" class="text-blue-600"></i> Configuración Avanzada
|
||||
<i data-lucide="settings" class="text-blue-600"></i> Configuración
|
||||
</h2>
|
||||
|
||||
<div class="flex border-b border-gray-200 mb-6 overflow-x-auto">
|
||||
<button onclick="showTab('zones')" id="tab-zones" class="tab-btn px-6 py-3 text-sm font-bold text-blue-600 border-b-2 border-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
||||
<i data-lucide="map" class="inline w-4 h-4 mr-1"></i> Zonas de Actuación
|
||||
</button>
|
||||
</div>
|
||||
<button onclick="showTab('templates')" id="tab-templates" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
||||
<i data-lucide="file-text" class="inline w-4 h-4 mr-1"></i> Plantillas
|
||||
</button>
|
||||
<button onclick="showTab('whatsapp')" id="tab-whatsapp" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
||||
<i data-lucide="message-circle" class="inline w-4 h-4 mr-1"></i> WhatsApp
|
||||
</button>
|
||||
<button onclick="showTab('providers')" id="tab-providers" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
||||
<i data-lucide="truck" class="inline w-4 h-4 mr-1"></i> Proveedores
|
||||
</button>
|
||||
<button onclick="showTab('portal')" id="tab-portal" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-50 transition whitespace-nowrap">
|
||||
<i data-lucide="globe" class="inline w-4 h-4 mr-1"></i> Portal Cliente
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-hidden relative">
|
||||
|
||||
<div id="view-zones" class="tab-content h-full flex flex-col">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 h-full">
|
||||
|
||||
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden">
|
||||
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700">1. Selecciona Provincia</div>
|
||||
<div class="p-2 border-b"><input type="text" id="searchProv" placeholder="Filtrar..." class="w-full text-xs p-2 border rounded" onkeyup="filterProvinces()"></div>
|
||||
<div id="listProvinces" class="flex-1 overflow-y-auto scroller p-2 space-y-1"></div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden opacity-50 pointer-events-none transition-opacity" id="colZones">
|
||||
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700 flex justify-between items-center">
|
||||
<span>2. Zonas Definidas</span>
|
||||
<span>2. Crear/Elegir Zona</span>
|
||||
<button onclick="openZoneModal()" class="text-blue-600 hover:bg-blue-100 p-1 rounded font-bold flex items-center gap-1 text-xs"><i data-lucide="plus" class="w-3 h-3"></i> Nueva</button>
|
||||
</div>
|
||||
<div id="listZones" class="flex-1 overflow-y-auto scroller p-2 space-y-1 text-sm">
|
||||
<p class="text-center text-gray-400 mt-10">Selecciona una provincia</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-full overflow-hidden opacity-50 pointer-events-none transition-opacity" id="colOperators">
|
||||
<div class="p-3 bg-gray-50 border-b border-gray-200 font-bold text-sm text-gray-700 flex justify-between items-center">
|
||||
<span>3. Asignar Operarios</span>
|
||||
@@ -66,6 +75,38 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="view-templates" class="tab-content hidden h-full">
|
||||
<div class="bg-white rounded-xl shadow p-8 text-center border border-gray-100">
|
||||
<i data-lucide="file-text" class="w-12 h-12 text-gray-300 mx-auto mb-4"></i>
|
||||
<h3 class="text-lg font-bold text-gray-700">Gestor de Plantillas</h3>
|
||||
<p class="text-gray-500 mb-4">Configura aquí los textos predefinidos.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="view-whatsapp" class="tab-content hidden h-full">
|
||||
<div class="bg-white rounded-xl shadow p-8 text-center border border-gray-100">
|
||||
<i data-lucide="message-circle" class="w-12 h-12 text-green-500 mx-auto mb-4"></i>
|
||||
<h3 class="text-lg font-bold text-gray-700">Conexión WhatsApp</h3>
|
||||
<p class="text-gray-500 mb-4">Configuración de API.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="view-providers" class="tab-content hidden h-full">
|
||||
<div class="bg-white rounded-xl shadow p-8 text-center border border-gray-100">
|
||||
<i data-lucide="truck" class="w-12 h-12 text-gray-300 mx-auto mb-4"></i>
|
||||
<h3 class="text-lg font-bold text-gray-700">Proveedores</h3>
|
||||
<p class="text-gray-500 mb-4">Gestión de proveedores.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="view-portal" class="tab-content hidden h-full">
|
||||
<div class="bg-white rounded-xl shadow p-8 text-center border border-gray-100">
|
||||
<i data-lucide="globe" class="w-12 h-12 text-blue-300 mx-auto mb-4"></i>
|
||||
<h3 class="text-lg font-bold text-gray-700">Portal del Cliente</h3>
|
||||
<p class="text-gray-500 mb-4">Configuración de acceso.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
@@ -102,11 +143,17 @@
|
||||
function showTab(tabId) {
|
||||
document.querySelectorAll('.tab-content').forEach(el => el.classList.add('hidden'));
|
||||
document.getElementById(`view-${tabId}`).classList.remove('hidden');
|
||||
|
||||
document.querySelectorAll('.tab-btn').forEach(el => {
|
||||
el.classList.remove('text-blue-600', 'border-b-2', 'border-blue-600', 'font-bold');
|
||||
el.classList.add('text-gray-500', 'font-medium');
|
||||
});
|
||||
const btn = document.getElementById(`tab-${tabId}`);
|
||||
btn.classList.add('text-blue-600', 'border-b-2', 'border-blue-600', 'font-bold');
|
||||
btn.classList.remove('text-gray-500', 'font-medium');
|
||||
}
|
||||
|
||||
// ============================
|
||||
// LÓGICA DE ZONAS
|
||||
// ============================
|
||||
// --- LÓGICA DE ZONAS ---
|
||||
async function loadProvinces() {
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/provinces`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||
@@ -155,13 +202,8 @@
|
||||
data.zones.forEach(z => {
|
||||
const div = document.createElement('div');
|
||||
div.className = "p-3 border border-gray-100 rounded hover:border-blue-300 cursor-pointer bg-white mb-2 zone-item";
|
||||
let townsText = z.towns_names && z.towns_names.length > 0 ? z.towns_names.join(", ") : "Sin poblaciones";
|
||||
|
||||
// Mostrar pueblos agrupados (si existen)
|
||||
let townsText = "Sin poblaciones";
|
||||
if(z.towns_names && z.towns_names.length > 0) {
|
||||
townsText = z.towns_names.join(", ");
|
||||
}
|
||||
|
||||
div.innerHTML = `
|
||||
<div class="flex justify-between items-start">
|
||||
<span class="font-bold text-gray-700 block">${z.name}</span>
|
||||
@@ -169,19 +211,17 @@
|
||||
</div>
|
||||
<p class="text-xs text-gray-400 mt-1 truncate">${townsText}</p>
|
||||
`;
|
||||
|
||||
div.onclick = () => selectZone(z.id, div);
|
||||
list.appendChild(div);
|
||||
});
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
// --- CREACIÓN DE ZONAS (NUEVO) ---
|
||||
async function openZoneModal() {
|
||||
if(!currentProvId) return;
|
||||
document.getElementById('newZoneName').value = "";
|
||||
|
||||
// Cargar pueblos de la provincia
|
||||
// Cargar pueblos
|
||||
const res = await fetch(`${API_URL}/provinces/${currentProvId}/towns`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||
const data = await res.json();
|
||||
const list = document.getElementById('townsList');
|
||||
@@ -190,14 +230,8 @@
|
||||
if(data.towns.length === 0) list.innerHTML = '<p class="col-span-2 text-center text-gray-400">No hay poblaciones cargadas.</p>';
|
||||
|
||||
data.towns.forEach(t => {
|
||||
list.innerHTML += `
|
||||
<label class="flex items-center gap-2 p-1 hover:bg-blue-50 rounded">
|
||||
<input type="checkbox" value="${t.id}" class="town-check text-blue-600 rounded">
|
||||
<span class="truncate">${t.name}</span>
|
||||
</label>
|
||||
`;
|
||||
list.innerHTML += `<label class="flex items-center gap-2 p-1 hover:bg-blue-50 rounded"><input type="checkbox" value="${t.id}" class="town-check text-blue-600 rounded"> <span class="truncate">${t.name}</span></label>`;
|
||||
});
|
||||
|
||||
document.getElementById('zoneModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
@@ -206,7 +240,7 @@
|
||||
const checks = document.querySelectorAll('.town-check:checked');
|
||||
const townIds = Array.from(checks).map(c => c.value);
|
||||
|
||||
if(!name) { alert("Pon un nombre a la zona"); return; }
|
||||
if(!name) { alert("Pon un nombre"); return; }
|
||||
|
||||
await fetch(`${API_URL}/zones`, {
|
||||
method: 'POST',
|
||||
@@ -237,7 +271,7 @@
|
||||
const dataOps = await resOps.json();
|
||||
|
||||
const resAssigned = await fetch(`${API_URL}/zones/${zoneId}/operators`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
||||
const dataAssigned = await resAssigned.json();
|
||||
const dataAssigned = await resAssigned.json();
|
||||
const assignedSet = new Set(dataAssigned.assignedIds);
|
||||
|
||||
const list = document.getElementById('listOperators');
|
||||
@@ -245,12 +279,7 @@
|
||||
|
||||
dataOps.operators.forEach(op => {
|
||||
const checked = assignedSet.has(op.id) ? 'checked' : '';
|
||||
list.innerHTML += `
|
||||
<label class="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
|
||||
<input type="checkbox" value="${op.id}" class="op-zone-check w-4 h-4 text-green-600 rounded mr-3" ${checked}>
|
||||
<span class="text-sm font-medium text-gray-700">${op.full_name}</span>
|
||||
</label>
|
||||
`;
|
||||
list.innerHTML += `<label class="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer"><input type="checkbox" value="${op.id}" class="op-zone-check w-4 h-4 text-green-600 rounded mr-3" ${checked}><span class="text-sm font-medium text-gray-700">${op.full_name}</span></label>`;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user