diff --git a/calendario.html b/calendario.html index 60af148..3e4b1ca 100644 --- a/calendario.html +++ b/calendario.html @@ -46,7 +46,7 @@ .desc-box { background: white; border: 1px solid #e2e8f0; border-radius: 1.5rem; padding: 1.25rem; } - +
@@ -70,7 +70,7 @@

Consultando Base de Datos...

- + @@ -111,17 +111,17 @@
- -
-
+

Compañía

@@ -131,12 +131,12 @@ -
-
+

Ubicación

@@ -151,10 +151,10 @@
-
+

Asignar Fechas y Tiempos

-
+
@@ -166,8 +166,8 @@
- -
+ +
-
-
+

Descripción Técnica

--
-
+
- +
-
+
@@ -237,9 +237,8 @@ let systemStatuses = []; let systemGuilds = []; let currentWeekStart = new Date(); - let selectedDateStr = ""; + let selectedDateStr = ""; - // --- SISTEMA DE TEMA DINÁMICO --- async function applyTheme() { try { let theme = JSON.parse(localStorage.getItem('app_theme')); @@ -338,7 +337,7 @@ function selectDate(isoDate) { selectedDateStr = isoDate; buildWeekCalendar(); - renderServices(); + renderServices(); } async function loadStatuses() { @@ -416,11 +415,22 @@ let compShort = (raw["Compañía"] || "Particular").split('-')[0].trim().substring(0, 15); const guildObj = systemGuilds.find(g => String(g.id) === String(s.guild_id || raw.guild_id)); + // LÓGICA DE ICONO SEGÚN ESTADO + let iconName = "clock"; + const dbStatId = raw.status_operativo; + const statusObj = systemStatuses.find(st => String(st.id) === String(dbStatId)); + const stName = (statusObj?.name || "").toLowerCase(); + + if (stName.includes('camino')) iconName = "car"; + else if (stName.includes('trabajando') || stName.includes('llegado')) iconName = "wrench"; + else if (stName.includes('incidencia') || stName.includes('pausa')) iconName = "alert-triangle"; + else if (stName.includes('citado')) iconName = "calendar"; + return ` -
+
${s.is_urgent ? '
Urgente
' : ''}
- + ${time}
@@ -463,30 +473,30 @@ document.getElementById('detDesc').innerHTML = (raw["Descripción"] || raw["DESCRIPCION"] || "Sin notas.").replace(/\n/g, '
'); const extraContainer = document.getElementById('extraDataBox'); + extraContainer.innerHTML = ''; let detailsHtml = ''; - const skipKeys = ["Nombre Cliente", "CLIENTE", "Dirección", "DOMICILIO", "Población", "POBLACION-PROVINCIA", "scheduled_date", "scheduled_time", "status_operativo", "duration_minutes", "assigned_to", "guild_id", "Código Postal", "assigned_to_name", "Descripción", "DESCRIPCION", "Compañía", "COMPAÑIA"]; + const skipKeys = ["Nombre Cliente", "CLIENTE", "Dirección", "DOMICILIO", "Población", "POBLACION-PROVINCIA", "scheduled_date", "scheduled_time", "status_operativo", "duration_minutes", "assigned_to", "guild_id", "Código Postal", "assigned_to_name", "Descripción", "DESCRIPCION", "Compañía", "COMPAÑIA", "called_times", "appointment_status"]; for(let key in raw) { if(skipKeys.includes(key)) continue; let valStr = String(raw[key] || ""); - if(valStr.trim() === "") continue; + if(valStr.trim() === "" || valStr === "null") continue; detailsHtml += `
${key}${valStr}
`; } extraContainer.innerHTML = detailsHtml || '

Sin datos adicionales.

'; - // CARGAMOS LA FECHA, LA HORA Y LA DURACIÓN EN EL MODAL document.getElementById('dateInput').value = raw.scheduled_date || ""; document.getElementById('timeInput').value = raw.scheduled_time || ""; document.getElementById('durationInput').value = raw.duration_minutes || "60"; const dbStat = raw.status_operativo; - const foundById = systemStatuses.find(st => String(st.id) === String(dbStat)); - if(foundById) document.getElementById('detStatusMap').value = foundById.id; + if(dbStat) document.getElementById('detStatusMap').value = dbStat; const modal = document.getElementById('serviceModal'); modal.style.display = 'flex'; setTimeout(() => modal.classList.remove('translate-y-full'), 10); calculateDistance(fullAddress); + safeLoadIcons(); } function closeModal() { @@ -501,6 +511,9 @@ async function calculateDistance(dest) { if(!navigator.geolocation) return; + document.getElementById('gpsLoading').classList.remove('hidden'); + document.getElementById('gpsResult').classList.add('hidden'); + navigator.geolocation.getCurrentPosition(async (pos) => { const lat = pos.coords.latitude; const lon = pos.coords.longitude; try { @@ -540,7 +553,6 @@ } catch (e) { alert("Error"); } } - // --- FUNCIÓN ACTUALIZADA PARA CAPTURAR LA DURACIÓN --- async function saveAppointment() { const id = document.getElementById('detId').value; const date = document.getElementById('dateInput').value; @@ -558,23 +570,30 @@ const originalContent = btn.innerHTML; btn.innerHTML = ` Guardando...`; btn.disabled = true; + safeLoadIcons(); try { - await fetch(`${API_URL}/services/set-appointment/${id}`, { + const res = await fetch(`${API_URL}/services/set-appointment/${id}`, { method: 'PUT', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, body: JSON.stringify({ date, time, duration_minutes: duration, status_operativo: statusMap }) }); - closeDetailModal(); showToast("Estado actualizado"); refreshData(); - } catch (e) { alert("Error"); } - finally { btn.innerHTML = originalContent; btn.disabled = false; } + if (res.ok) { + showToast("Estado actualizado"); + closeModal(); + refreshData(); + } else { + alert("Error al guardar"); + } + } catch (e) { alert("Error de conexión"); } + finally { btn.innerHTML = originalContent; btn.disabled = false; safeLoadIcons(); } } function showToast(m) { const t = document.getElementById('toast'); document.getElementById('toastMsg').innerText = m; - t.classList.remove('opacity-0', '-translate-y-10'); t.classList.add('translate-y-0'); - setTimeout(() => { t.classList.add('opacity-0', '-translate-y-10'); t.classList.remove('translate-y-0'); }, 2000); + t.classList.remove('opacity-0', 'pointer-events-none', '-translate-y-10'); t.classList.add('translate-y-0'); + setTimeout(() => { t.classList.add('opacity-0', 'pointer-events-none', '-translate-y-10'); t.classList.remove('translate-y-0'); }, 2000); } function logout() { localStorage.clear(); window.location.href = "index.html"; }