diff --git a/configuracion.html b/configuracion.html index 70f106d..cfcaf37 100644 --- a/configuracion.html +++ b/configuracion.html @@ -59,6 +59,7 @@
Tipos de Mensaje
+ @@ -79,6 +80,7 @@ +
@@ -149,6 +151,20 @@ +
+
+
+
+

Asignado a Operario

+

Se envía cuando asignas un técnico al servicio.

+
+
+
+ + +
+
+
@@ -468,22 +484,17 @@ } } - // ========================================== - // RESTO DE FUNCIONES (INTACTAS) - // ========================================== - - async function loadWaSettings() { + async function loadWaSettings() { try { - // 1. Pedimos al servidor cómo están los botones (ON/OFF) const res = await fetch(`${API_URL}/whatsapp/settings`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const data = await res.json(); const s = data.settings || {}; - // 2. Colocamos los interruptores según lo que diga la base de datos - document.getElementById('cfg_delay').checked = s.wa_delay_enabled !== false; // Por defecto ON + document.getElementById('cfg_delay').checked = s.wa_delay_enabled !== false; document.getElementById('cfg_evt_welcome').checked = s.wa_evt_welcome || false; + document.getElementById('cfg_evt_assigned').checked = s.wa_evt_assigned || false; // NUEVO document.getElementById('cfg_evt_date').checked = s.wa_evt_date || false; document.getElementById('cfg_evt_onway').checked = s.wa_evt_onway || false; document.getElementById('cfg_evt_finished').checked = s.wa_evt_finished || false; @@ -492,17 +503,16 @@ } async function saveWaSettings() { - // 1. Leemos cómo has dejado los botones en la pantalla const settings = { wa_delay_enabled: document.getElementById('cfg_delay').checked, wa_evt_welcome: document.getElementById('cfg_evt_welcome').checked, + wa_evt_assigned: document.getElementById('cfg_evt_assigned').checked, // NUEVO wa_evt_date: document.getElementById('cfg_evt_date').checked, wa_evt_onway: document.getElementById('cfg_evt_onway').checked, wa_evt_finished: document.getElementById('cfg_evt_finished').checked, wa_evt_survey: document.getElementById('cfg_evt_survey').checked }; - // 2. Se lo enviamos al servidor para que lo guarde en la base de datos try { const res = await fetch(`${API_URL}/whatsapp/settings`, { method: 'POST', @@ -574,19 +584,31 @@ } } 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'); + if (b.querySelector('span').classList.contains('bg-orange-600')) { + b.querySelector('span').classList.replace('bg-orange-600', 'bg-orange-100'); + b.querySelector('span').classList.replace('text-white', 'text-orange-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'); + const span = btn.querySelector('span'); + if (span.classList.contains('bg-blue-100')) { + span.classList.replace('bg-blue-100', 'bg-blue-600'); + span.classList.replace('text-blue-600', 'text-white'); + } else if (span.classList.contains('bg-orange-100')) { + span.classList.replace('bg-orange-100', 'bg-orange-600'); + span.classList.replace('text-orange-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; @@ -597,6 +619,7 @@ 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; @@ -626,6 +649,7 @@ lucide.createIcons(); } catch(e) { list.innerHTML = '

Error

'; } } + async function addCompany() { const input = document.getElementById('newCompanyInput'); const name = input.value.trim(); @@ -635,15 +659,13 @@ 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(); } - // ========================================== - // CARGA DE ESTADOS Y GESTIÓN DE SEGURIDAD - // ========================================== async function loadStatusesConfig() { const list = document.getElementById('listStatuses'); list.innerHTML = '

Cargando...

'; @@ -654,8 +676,6 @@ 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"; - - // SI ES DEL SISTEMA, PONEMOS UN CANDADO. SI NO, LA PAPELERA. const actionBtn = s.is_system ? `` : ``; @@ -698,14 +718,12 @@ } catch(e) { showToast("Error de conexión", 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); } - \ No newline at end of file