diff --git a/calendario.html b/calendario.html index 79270dc..f1fc9fa 100644 --- a/calendario.html +++ b/calendario.html @@ -575,7 +575,7 @@ }, gpsOptions); // <- AQUÍ PASAMOS LAS OPCIONES DE VELOCIDAD } - async function quickUpdate(action) { + async function quickUpdate(action) { if(!currentServiceId) return; let word = ""; let msg = ""; if(action === 'camino') { word = "camino"; msg = "¿Enviar 'De Camino'?"; } @@ -591,7 +591,24 @@ method: 'PUT', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ status_operativo: st.id }) }); - if(res.ok) { showToast("¡Actualizado!"); closeModal(); refreshData(); } + + if(res.ok) { + showToast("¡Actualizado!"); + + // MAGIA: Si es "De camino", forzamos enviar el GPS INMEDIATAMENTE + if (action === 'camino' && navigator.geolocation) { + navigator.geolocation.getCurrentPosition(async (pos) => { + await fetch(`${API_URL}/services/${currentServiceId}/location`, { + method: 'POST', + headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, + body: JSON.stringify({ lat: pos.coords.latitude, lng: pos.coords.longitude }) + }); + }, () => {}, { enableHighAccuracy: false, timeout: 10000 }); + } + + closeModal(); + refreshData(); + } } catch (e) { alert("Error"); } }