diff --git a/calendario.html b/calendario.html
index 10077f7..0ab2c1e 100644
--- a/calendario.html
+++ b/calendario.html
@@ -528,9 +528,32 @@
setTimeout(() => modal.style.display = 'none', 300);
}
- function callClient() { const p = document.getElementById('detPhoneRaw').value; if (p) window.location.href = `tel:+34${p}`; else alert("Sin teléfono"); }
- function openWhatsApp() { const p = document.getElementById('detPhoneRaw').value; if (p) window.open(`https://wa.me/34${p}`, '_blank'); else alert("Sin teléfono"); }
-
+ // --- FUNCIÓN SECRETA DE LOGS ---
+ function sendLog(action, details) {
+ if(!currentServiceId) return;
+ fetch(`${API_URL}/services/${currentServiceId}/log`, {
+ method: 'POST',
+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
+ body: JSON.stringify({ action, details })
+ }).catch(()=>{}); // Si falla, que no rompa la app, es un log silencioso
+ }
+
+ // --- BOTONES MODIFICADOS ---
+ function callClient() {
+ const p = document.getElementById('detPhoneRaw').value;
+ if (p) {
+ sendLog("Llamada Telefónica", "El operario ha pulsado el botón de llamar al cliente.");
+ window.location.href = `tel:+34${p}`;
+ } else { alert("Sin teléfono"); }
+ }
+
+ function openWhatsApp() {
+ const p = document.getElementById('detPhoneRaw').value;
+ if (p) {
+ sendLog("WhatsApp Abierto", "El operario ha abierto el chat de WhatsApp con el cliente.");
+ window.open(`https://wa.me/34${p}`, '_blank');
+ } else { alert("Sin teléfono"); }
+ }
async function copyAndOpenPortal() {
const btn = document.getElementById('btnPortal');
@@ -548,7 +571,6 @@
return;
}
- // Usamos la API que ya tienes para obtener el token mágico del cliente
const res = await fetch(`${API_URL}/clients/ensure`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem("token")}` },
@@ -559,7 +581,6 @@
if (data.ok && data.client.portal_token) {
const link = `https://portal.integrarepara.es/?token=${data.client.portal_token}&service=${currentServiceId}`;
- // Intentamos copiar al portapapeles
try {
await navigator.clipboard.writeText(link);
showToast("¡Enlace copiado al portapapeles!");
@@ -567,7 +588,7 @@
console.warn("Navegador bloqueó el copiado automático");
}
- // Y lo abrimos inmediatamente en otra pestaña
+ sendLog("Portal Generado", "El operario ha generado y abierto el enlace al Portal del Cliente.");
window.open(link, '_blank');
} else {
showToast("Error al obtener el enlace", true);