348 lines
26 KiB
HTML
348 lines
26 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Configuración - IntegraRepara</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script src="https://unpkg.com/lucide@latest"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
|
|
<style>
|
|
.fade-in { animation: fadeIn 0.3s ease-in-out; }
|
|
.scroller::-webkit-scrollbar { width: 6px; }
|
|
.scroller::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 4px; }
|
|
</style>
|
|
</head>
|
|
<body class="bg-gray-50 text-gray-800 font-sans h-screen overflow-hidden flex">
|
|
|
|
<div id="sidebar-container" class="h-full shrink-0"></div>
|
|
|
|
<div class="flex-1 flex flex-col h-full relative min-w-0">
|
|
<div id="header-container"></div>
|
|
|
|
<main class="flex-1 flex flex-col overflow-hidden relative">
|
|
|
|
<div class="bg-gray-50 p-6 pb-0 z-20 shrink-0">
|
|
<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
|
|
</h2>
|
|
|
|
<div class="flex border-b border-gray-200 overflow-x-auto no-scrollbar">
|
|
<button onclick="showTab('templates')" id="tab-templates" class="tab-btn px-6 py-3 text-sm font-bold text-blue-600 border-b-2 border-blue-600 hover:bg-gray-100 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-100 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-100 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-100 transition whitespace-nowrap">
|
|
<i data-lucide="globe" class="inline w-4 h-4 mr-1"></i> Portal Cliente
|
|
</button>
|
|
<button onclick="showTab('others')" id="tab-others" class="tab-btn px-6 py-3 text-sm font-medium text-gray-500 hover:text-blue-600 hover:bg-gray-100 transition whitespace-nowrap">
|
|
<i data-lucide="sliders" class="inline w-4 h-4 mr-1"></i> Otras Configuraciones
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex-1 overflow-hidden p-6 bg-gray-50">
|
|
|
|
<div id="view-templates" class="tab-content h-full fade-in flex flex-col md:flex-row gap-6">
|
|
<div class="w-full md:w-1/3 bg-white rounded-xl shadow border border-gray-100 overflow-hidden flex flex-col">
|
|
<div class="p-4 bg-gray-50 border-b border-gray-200 font-bold text-gray-700 text-sm uppercase tracking-wide">Tipos de Mensaje</div>
|
|
<div class="flex-1 overflow-y-auto p-2 space-y-1">
|
|
<button onclick="selectTemplate('welcome', this)" class="tpl-btn w-full text-left p-3 rounded-lg hover:bg-blue-50 text-sm font-medium text-gray-600 transition-colors flex items-center gap-3 group"><span class="bg-blue-100 text-blue-600 p-1.5 rounded-md group-hover:bg-blue-200 transition"><i data-lucide="hand" class="w-4 h-4"></i></span> Bienvenida / Alta</button>
|
|
<button onclick="selectTemplate('no_contact', this)" class="tpl-btn w-full text-left p-3 rounded-lg hover:bg-blue-50 text-sm font-medium text-gray-600 transition-colors flex items-center gap-3 group"><span class="bg-orange-100 text-orange-600 p-1.5 rounded-md group-hover:bg-orange-200 transition"><i data-lucide="phone-off" class="w-4 h-4"></i></span> Cliente No Localizado</button>
|
|
<button onclick="selectTemplate('appointment', this)" class="tpl-btn w-full text-left p-3 rounded-lg hover:bg-blue-50 text-sm font-medium text-gray-600 transition-colors flex items-center gap-3 group"><span class="bg-green-100 text-green-600 p-1.5 rounded-md group-hover:bg-green-200 transition"><i data-lucide="calendar-check" class="w-4 h-4"></i></span> Cita Creada</button>
|
|
<button onclick="selectTemplate('update', this)" class="tpl-btn w-full text-left p-3 rounded-lg hover:bg-blue-50 text-sm font-medium text-gray-600 transition-colors flex items-center gap-3 group"><span class="bg-purple-100 text-purple-600 p-1.5 rounded-md group-hover:bg-purple-200 transition"><i data-lucide="refresh-cw" class="w-4 h-4"></i></span> Modificación de Servicio</button>
|
|
<button onclick="selectTemplate('on_way', this)" class="tpl-btn w-full text-left p-3 rounded-lg hover:bg-blue-50 text-sm font-medium text-gray-600 transition-colors flex items-center gap-3 group"><span class="bg-teal-100 text-teal-600 p-1.5 rounded-md group-hover:bg-teal-200 transition"><i data-lucide="truck" class="w-4 h-4"></i></span> Técnico de Camino</button>
|
|
<button onclick="selectTemplate('survey', this)" class="tpl-btn w-full text-left p-3 rounded-lg hover:bg-blue-50 text-sm font-medium text-gray-600 transition-colors flex items-center gap-3 group"><span class="bg-yellow-100 text-yellow-600 p-1.5 rounded-md group-hover:bg-yellow-200 transition"><i data-lucide="star" class="w-4 h-4"></i></span> Encuesta de Calidad</button>
|
|
</div>
|
|
</div>
|
|
<div class="flex-1 bg-white rounded-xl shadow border border-gray-100 flex flex-col overflow-hidden">
|
|
<div class="p-4 border-b bg-gray-50 flex justify-between items-center shrink-0">
|
|
<div><span class="block font-bold text-gray-800" id="editorTitle">Selecciona una plantilla</span><span class="text-xs text-gray-500">Edita el mensaje que se enviará por WhatsApp/Email</span></div>
|
|
<button onclick="saveTemplate()" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg text-sm font-bold shadow-lg transition-all transform active:scale-95 flex items-center gap-2"><i data-lucide="save" class="w-4 h-4"></i> Guardar</button>
|
|
</div>
|
|
<div class="p-3 border-b bg-gray-50/50 flex flex-wrap gap-2 items-center">
|
|
<span class="text-[10px] font-bold text-gray-400 uppercase tracking-wide mr-1">Variables:</span>
|
|
<button onclick="insertVar('{{NOMBRE}}')" class="var-btn">{{NOMBRE}}</button>
|
|
<button onclick="insertVar('{{DIRECCION}}')" class="var-btn">{{DIRECCION}}</button>
|
|
<button onclick="insertVar('{{FECHA}}')" class="var-btn">{{FECHA}}</button>
|
|
<button onclick="insertVar('{{HORA}}')" class="var-btn">{{HORA}}</button>
|
|
<button onclick="insertVar('{{COMPANIA}}')" class="var-btn">{{COMPANIA}}</button>
|
|
<button onclick="insertVar('{{REFERENCIA}}')" class="var-btn">{{REFERENCIA}}</button>
|
|
</div>
|
|
<textarea id="tplContent" class="flex-1 p-6 outline-none resize-none text-sm leading-relaxed text-gray-700 font-sans" placeholder="Selecciona un tipo de mensaje a la izquierda..."></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="view-whatsapp" class="tab-content hidden h-full fade-in">
|
|
<div class="max-w-2xl mx-auto mt-10">
|
|
<div class="bg-white rounded-xl shadow-lg border border-gray-100 p-8 flex flex-col items-center text-center">
|
|
<div class="w-16 h-16 bg-blue-50 rounded-full flex items-center justify-center mb-6">
|
|
<i data-lucide="smartphone" class="w-8 h-8 text-blue-600"></i>
|
|
</div>
|
|
|
|
<h2 class="text-2xl font-bold text-gray-800 mb-2">Conexión con WhatsApp</h2>
|
|
<p class="text-gray-500 mb-8 max-w-md">Escanea el código QR para vincular tu número de empresa. Esto permitirá enviar notificaciones automáticas.</p>
|
|
|
|
<div id="waStatusContainer" class="w-full flex flex-col items-center justify-center min-h-[250px] bg-gray-50 rounded-xl border-2 border-dashed border-gray-200 p-6 mb-6">
|
|
<div class="animate-pulse flex flex-col items-center">
|
|
<div class="w-10 h-10 border-4 border-blue-200 border-t-blue-600 rounded-full animate-spin mb-4"></div>
|
|
<span class="text-sm font-bold text-gray-400">Iniciando instancia segura...</span>
|
|
</div>
|
|
</div>
|
|
|
|
<button onclick="checkWhatsappStatus()" class="bg-slate-800 hover:bg-slate-700 text-white font-bold py-3 px-8 rounded-xl transition shadow-lg flex items-center gap-2">
|
|
<i data-lucide="refresh-cw" class="w-4 h-4"></i> Actualizar Estado
|
|
</button>
|
|
|
|
<p class="text-[10px] text-gray-400 mt-6">Instancia segura gestionada automáticamente por el servidor.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="view-providers" class="tab-content hidden h-full fade-in">
|
|
<div class="bg-white rounded-xl shadow p-10 text-center border border-gray-100">
|
|
<i data-lucide="truck" class="w-16 h-16 text-gray-200 mx-auto mb-4"></i>
|
|
<h3 class="text-xl font-bold text-gray-700">Proveedores</h3>
|
|
<p class="text-gray-500 mt-2">Próximamente</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="view-portal" class="tab-content hidden h-full fade-in">
|
|
<div class="bg-white rounded-xl shadow p-10 text-center border border-gray-100">
|
|
<i data-lucide="globe" class="w-16 h-16 text-blue-200 mx-auto mb-4"></i>
|
|
<h3 class="text-xl font-bold text-gray-700">Portal del Cliente</h3>
|
|
<p class="text-gray-500 mt-2">Próximamente</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="view-others" class="tab-content hidden h-full fade-in flex flex-col">
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-[500px]">
|
|
<div class="p-4 bg-gray-50 border-b border-gray-200 shrink-0"><h3 class="font-bold text-gray-700 flex items-center gap-2"><i data-lucide="shield" class="w-4 h-4 text-blue-600"></i> Compañías de Seguros</h3></div>
|
|
<div class="p-4 border-b border-gray-100 bg-white"><div class="flex gap-2"><input type="text" id="newCompanyInput" placeholder="Nombre..." class="flex-1 border rounded-lg px-3 py-2 text-sm outline-none focus:border-blue-500"><button onclick="addCompany()" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg text-xs font-bold transition-colors">Añadir</button></div></div>
|
|
<div id="listCompanies" class="flex-1 overflow-y-auto scroller p-2 space-y-1"><p class="text-center text-xs text-gray-400 mt-10">Cargando...</p></div>
|
|
</div>
|
|
<div class="bg-white rounded-xl shadow border border-gray-100 flex flex-col h-[500px]">
|
|
<div class="p-4 bg-gray-50 border-b border-gray-200 shrink-0"><h3 class="font-bold text-gray-700 flex items-center gap-2"><i data-lucide="activity" class="w-4 h-4 text-blue-600"></i> Estados del Servicio</h3></div>
|
|
<div class="p-4 border-b border-gray-100 bg-white"><div class="flex gap-2"><input type="text" id="newStatusInput" placeholder="Nuevo estado..." class="flex-1 border rounded-lg px-3 py-2 text-sm outline-none focus:border-blue-500"><select id="newStatusColor" class="border rounded-lg px-2 text-sm text-gray-600 outline-none focus:border-blue-500 bg-gray-50"><option value="gray">Gris</option><option value="blue">Azul</option><option value="green">Verde</option><option value="red">Rojo</option><option value="yellow">Amarillo</option><option value="purple">Morado</option></select><button onclick="addStatus()" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg text-xs font-bold transition-colors">Añadir</button></div></div>
|
|
<div id="listStatuses" class="flex-1 overflow-y-auto scroller p-2 space-y-1"><p class="text-center text-xs text-gray-400 mt-10">Cargando...</p></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
</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">Msg</span></div>
|
|
|
|
<script src="js/layout.js"></script>
|
|
<style>.var-btn { @apply px-2 py-1 bg-white border border-gray-200 rounded text-xs font-mono font-medium text-gray-600 hover:border-blue-400 hover:text-blue-600 transition shadow-sm; }</style>
|
|
<script>
|
|
let cachedTemplates = {};
|
|
let currentTemplateType = null;
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
|
showTab('templates');
|
|
loadTemplates();
|
|
});
|
|
|
|
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');
|
|
|
|
if(tabId === 'others') { loadCompanies(); loadStatusesConfig(); }
|
|
if(tabId === 'whatsapp') { checkWhatsappStatus(); }
|
|
}
|
|
|
|
// --- WHATSAPP STATUS (AUTOMÁTICO) ---
|
|
async function checkWhatsappStatus() {
|
|
const container = document.getElementById('waStatusContainer');
|
|
container.innerHTML = `
|
|
<div class="flex flex-col items-center animate-pulse">
|
|
<i data-lucide="loader-2" class="w-8 h-8 text-blue-500 animate-spin mb-3"></i>
|
|
<span class="text-sm text-blue-600 font-medium">Verificando instancia...</span>
|
|
</div>`;
|
|
lucide.createIcons();
|
|
|
|
try {
|
|
// Llamamos a NUESTRO backend, que gestiona todo con Evolution
|
|
const res = await fetch(`${API_URL}/whatsapp/status`, {
|
|
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
|
});
|
|
|
|
const data = await res.json();
|
|
|
|
if (!data.ok) throw new Error(data.error || "Error desconocido");
|
|
|
|
if (data.state === "open") {
|
|
container.innerHTML = `
|
|
<div class="flex flex-col items-center">
|
|
<div class="w-20 h-20 bg-green-100 rounded-full flex items-center justify-center mb-4 shadow-sm border border-green-200">
|
|
<i data-lucide="check" class="w-10 h-10 text-green-600"></i>
|
|
</div>
|
|
<h4 class="text-xl font-bold text-green-700">Conectado</h4>
|
|
<p class="text-sm text-green-600 mt-1 font-medium">Instancia: ${data.instanceName}</p>
|
|
</div>`;
|
|
} else if (data.qr) {
|
|
container.innerHTML = `
|
|
<div class="flex flex-col items-center w-full">
|
|
<div id="qrcode" class="bg-white p-3 border rounded-lg shadow-sm"></div>
|
|
<p class="text-xs text-orange-500 mt-4 font-bold animate-pulse">Esperando escaneo...</p>
|
|
</div>`;
|
|
|
|
if(data.qr.startsWith('data:image')) {
|
|
document.getElementById('qrcode').innerHTML = `<img src="${data.qr}" class="w-48 h-48">`;
|
|
} else {
|
|
new QRCode(document.getElementById("qrcode"), { text: data.qr, width: 180, height: 180 });
|
|
}
|
|
} else {
|
|
container.innerHTML = `<p class="text-orange-500 font-bold">Iniciando... intenta de nuevo en unos segundos.</p>`;
|
|
}
|
|
} catch(e) {
|
|
container.innerHTML = `
|
|
<div class="text-center text-red-500 p-4">
|
|
<i data-lucide="alert-triangle" class="w-10 h-10 mx-auto mb-2 opacity-80"></i>
|
|
<p class="font-bold">Error de conexión</p>
|
|
<p class="text-xs mt-1 bg-red-50 p-2 rounded">${e.message}</p>
|
|
</div>`;
|
|
}
|
|
lucide.createIcons();
|
|
}
|
|
|
|
// --- GESTIÓN DE PLANTILLAS ---
|
|
async function loadTemplates() {
|
|
try {
|
|
const res = await fetch(`${API_URL}/templates`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const data = await res.json();
|
|
if(data.ok) {
|
|
data.templates.forEach(t => { cachedTemplates[t.type] = t.content; });
|
|
if (!currentTemplateType) { const firstBtn = document.querySelector('.tpl-btn'); if(firstBtn) firstBtn.click(); }
|
|
}
|
|
} catch(e) { console.error("Error templates"); }
|
|
}
|
|
function selectTemplate(type, btn) {
|
|
currentTemplateType = type;
|
|
document.querySelectorAll('.tpl-btn').forEach(b => {
|
|
b.classList.remove('bg-blue-50', 'ring-1', 'ring-blue-200');
|
|
b.querySelector('span').classList.replace('bg-blue-600', 'bg-blue-100');
|
|
b.querySelector('span').classList.replace('text-white', 'text-blue-600');
|
|
});
|
|
btn.classList.add('bg-blue-50', 'ring-1', 'ring-blue-200');
|
|
btn.querySelector('span').classList.replace('bg-blue-100', 'bg-blue-600');
|
|
btn.querySelector('span').classList.replace('text-blue-600', 'text-white');
|
|
document.getElementById('editorTitle').innerText = btn.innerText.trim();
|
|
document.getElementById('tplContent').value = cachedTemplates[type] || "";
|
|
}
|
|
function insertVar(text) {
|
|
const textarea = document.getElementById('tplContent');
|
|
if (!textarea) return;
|
|
const start = textarea.selectionStart;
|
|
const end = textarea.selectionEnd;
|
|
const val = textarea.value;
|
|
textarea.value = val.substring(0, start) + text + val.substring(end);
|
|
textarea.focus();
|
|
textarea.selectionStart = textarea.selectionEnd = start + text.length;
|
|
}
|
|
async function saveTemplate() {
|
|
if(!currentTemplateType) { showToast("Selecciona plantilla", true); return; }
|
|
const content = document.getElementById('tplContent').value;
|
|
try {
|
|
const res = await fetch(`${API_URL}/templates`, {
|
|
method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
|
body: JSON.stringify({ type: currentTemplateType, content: content })
|
|
});
|
|
if(res.ok) { cachedTemplates[currentTemplateType] = content; showToast("Guardado"); } else { showToast("Error", true); }
|
|
} catch(e) { showToast("Error", true); }
|
|
}
|
|
|
|
// --- GESTIÓN DE COMPAÑÍAS Y ESTADOS (MANTENIDO) ---
|
|
async function loadCompanies() {
|
|
const list = document.getElementById('listCompanies');
|
|
list.innerHTML = '<p class="text-center text-xs text-gray-400 mt-10">Cargando...</p>';
|
|
try {
|
|
const res = await fetch(`${API_URL}/companies`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const data = await res.json();
|
|
list.innerHTML = "";
|
|
if(data.companies.length === 0) { list.innerHTML = '<p class="text-center text-xs text-gray-400 mt-4">Sin compañías.</p>'; return; }
|
|
data.companies.forEach(c => {
|
|
const div = document.createElement('div');
|
|
div.className = "p-3 border border-gray-100 rounded-lg bg-gray-50 flex justify-between items-center group hover:border-blue-200 transition-colors";
|
|
div.innerHTML = `<span class="font-bold text-gray-700 text-sm">${c.name}</span><button onclick="deleteCompany(${c.id})" class="text-gray-300 hover:text-red-500"><i data-lucide="trash-2" class="w-4 h-4"></i></button>`;
|
|
list.appendChild(div);
|
|
});
|
|
lucide.createIcons();
|
|
} catch(e) { list.innerHTML = '<p class="text-red-500 text-xs text-center">Error</p>'; }
|
|
}
|
|
async function addCompany() {
|
|
const input = document.getElementById('newCompanyInput');
|
|
const name = input.value.trim();
|
|
if(!name) return;
|
|
try {
|
|
const res = await fetch(`${API_URL}/companies`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ name: name }) });
|
|
if(res.ok) { showToast("Añadido"); input.value = ""; loadCompanies(); }
|
|
} catch(e) { showToast("Error", true); }
|
|
}
|
|
async function deleteCompany(id) {
|
|
if(!confirm("¿Borrar?")) return;
|
|
await fetch(`${API_URL}/companies/${id}`, { method: 'DELETE', headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
loadCompanies();
|
|
}
|
|
async function loadStatusesConfig() {
|
|
const list = document.getElementById('listStatuses');
|
|
list.innerHTML = '<p class="text-center text-xs text-gray-400 mt-10">Cargando...</p>';
|
|
try {
|
|
const res = await fetch(`${API_URL}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const data = await res.json();
|
|
list.innerHTML = "";
|
|
data.statuses.forEach(s => {
|
|
const div = document.createElement('div');
|
|
div.className = "p-3 border border-gray-100 rounded-lg bg-gray-50 flex justify-between items-center group hover:border-blue-200 transition-colors";
|
|
div.innerHTML = `<div class="flex items-center gap-3"><div class="w-3 h-3 rounded-full bg-${s.color}-500"></div><span class="font-bold text-gray-700 text-sm">${s.name}</span></div><button onclick="deleteStatus(${s.id})" class="text-gray-300 hover:text-red-500"><i data-lucide="trash-2" class="w-4 h-4"></i></button>`;
|
|
list.appendChild(div);
|
|
});
|
|
lucide.createIcons();
|
|
} catch(e) { list.innerHTML = '<p class="text-red-500 text-xs text-center">Error</p>'; }
|
|
}
|
|
async function addStatus() {
|
|
const input = document.getElementById('newStatusInput');
|
|
const color = document.getElementById('newStatusColor').value;
|
|
const name = input.value.trim();
|
|
if(!name) return;
|
|
try {
|
|
const res = await fetch(`${API_URL}/statuses`, { method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ name: name, color: color }) });
|
|
if(res.ok) { showToast("Añadido"); input.value = ""; loadStatusesConfig(); }
|
|
} catch(e) { showToast("Error", true); }
|
|
}
|
|
async function deleteStatus(id) {
|
|
if(!confirm("¿Borrar?")) return;
|
|
try {
|
|
const res = await fetch(`${API_URL}/statuses/${id}`, { method: 'DELETE', headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
|
|
const json = await res.json();
|
|
if(res.ok) { showToast("Eliminado"); loadStatusesConfig(); } else { showToast(json.error || "Error", true); }
|
|
} catch(e) { showToast("Error", true); }
|
|
}
|
|
|
|
function showToast(msg, isError = false) {
|
|
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
|
|
t.className = `fixed bottom-5 right-5 px-6 py-3 rounded-lg shadow-xl transition-all duration-300 z-50 flex items-center gap-3 ${isError ? 'bg-red-600' : 'bg-slate-800'} text-white font-medium`;
|
|
m.innerText = msg; t.classList.remove('translate-y-20', 'opacity-0');
|
|
setTimeout(() => t.classList.add('translate-y-20', 'opacity-0'), 3000);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |