From f5997d89ad15cff3874e3ed384bb3b9ceb35281a Mon Sep 17 00:00:00 2001 From: jps Date: Tue, 20 Jan 2026 15:55:10 +0100 Subject: [PATCH] adaptation couleur --- assets/js/modules/agenda-event-mapper.js | 54 ++++++++++++------ assets/js/modules/agenda-fullcalendar.js | 70 +++++++++++++++++++++--- 2 files changed, 98 insertions(+), 26 deletions(-) diff --git a/assets/js/modules/agenda-event-mapper.js b/assets/js/modules/agenda-event-mapper.js index 2621183..362196f 100644 --- a/assets/js/modules/agenda-event-mapper.js +++ b/assets/js/modules/agenda-event-mapper.js @@ -269,28 +269,46 @@ export function mapEventToFullCalendar(ev) { }); } } else if (isPermanenceAssigned) { - // 2) Attribuée : a type intervention ? couleur type : couleur défaut - let typeInterventionId = null; - if (ev.id_type_intervention) { - typeInterventionId = parseInt(ev.id_type_intervention); - } else if (ev.type_intervention && ev.type_intervention.id) { - typeInterventionId = parseInt(ev.type_intervention.id); - } + // 2) Attribuée : ordre de priorité - département puis local - if (typeInterventionId && !isNaN(typeInterventionId) && window.crviAjax && window.crviAjax.couleurs_types_intervention) { - const couleurTypeIntervention = window.crviAjax.couleurs_types_intervention[typeInterventionId]; - if (couleurTypeIntervention) { - backgroundColor = couleurTypeIntervention; - console.log('🎨 [COULEUR] Permanence assignée - avec type intervention:', { - eventId: ev.id, - typeInterventionId: typeInterventionId, - backgroundColor: backgroundColor, - source: 'permanence_assignee_type' - }); + // Priorité 1 : Couleur du département + const departementId = ev.id_departement ? parseInt(ev.id_departement) : null; + if (departementId && !isNaN(departementId) && window.crviACFData && window.crviACFData.departements) { + // Chercher le département par ID + for (const key in window.crviACFData.departements) { + const dept = window.crviACFData.departements[key]; + if (dept.id === departementId && dept.couleur) { + backgroundColor = dept.couleur; + console.log('🎨 [COULEUR] Permanence assignée - département:', { + eventId: ev.id, + departementId: departementId, + departementNom: dept.nom, + backgroundColor: backgroundColor, + source: 'departement' + }); + break; + } } } - // Si pas de type d'intervention, utiliser couleur défaut + // Priorité 2 : Couleur du local (type de local) + if (!backgroundColor && ev.local) { + const localType = ev.local.type || ev.local_type; + if (localType && window.crviACFData && window.crviACFData.types_local) { + const typeLocalConfig = window.crviACFData.types_local[localType]; + if (typeLocalConfig && typeLocalConfig.couleur) { + backgroundColor = typeLocalConfig.couleur; + console.log('🎨 [COULEUR] Permanence assignée - type de local:', { + eventId: ev.id, + localType: localType, + backgroundColor: backgroundColor, + source: 'type_local' + }); + } + } + } + + // Fallback : couleur par défaut des permanences if (!backgroundColor) { backgroundColor = (window.crviACFData && window.crviACFData.couleurs_permanence && window.crviACFData.couleurs_permanence.permanence) ? window.crviACFData.couleurs_permanence.permanence diff --git a/assets/js/modules/agenda-fullcalendar.js b/assets/js/modules/agenda-fullcalendar.js index 8c8dd45..33a2806 100644 --- a/assets/js/modules/agenda-fullcalendar.js +++ b/assets/js/modules/agenda-fullcalendar.js @@ -558,16 +558,44 @@ export function initializeCalendar() { bgColor = window.crviAjax.couleur_permanence_non_attribuee; } } else if (isPermanenceAssigned) { - // 2) Attribuée : a type intervention ? couleur type : couleur défaut - const typeInterventionId = eventProps.id_type_intervention ? parseInt(eventProps.id_type_intervention) : null; + // 2) Attribuée : ordre de priorité - département puis local - if (typeInterventionId && !isNaN(typeInterventionId) && window.crviAjax && window.crviAjax.couleurs_types_intervention) { - const couleurType = window.crviAjax.couleurs_types_intervention[typeInterventionId]; - if (couleurType) { - bgColor = couleurType; + // Priorité 1 : Couleur du département + const departementId = eventProps.id_departement ? parseInt(eventProps.id_departement) : null; + if (departementId && !isNaN(departementId) && crviACFData && crviACFData.departements) { + // Chercher le département par ID + for (const key in crviACFData.departements) { + const dept = crviACFData.departements[key]; + if (dept.id === departementId && dept.couleur) { + bgColor = dept.couleur; + console.log('🎨 [COULEUR] Département trouvé:', { + eventId: event.id, + departementId: departementId, + departementNom: dept.nom, + couleur: bgColor + }); + break; + } } } + // Priorité 2 : Couleur du local (type de local) + if (!bgColor && eventProps.local) { + const localType = eventProps.local.type || eventProps.local_type; + if (localType && crviACFData && crviACFData.types_local) { + const typeLocalConfig = crviACFData.types_local[localType]; + if (typeLocalConfig && typeLocalConfig.couleur) { + bgColor = typeLocalConfig.couleur; + console.log('🎨 [COULEUR] Type de local trouvé:', { + eventId: event.id, + localType: localType, + couleur: bgColor + }); + } + } + } + + // Fallback : couleur par défaut des permanences if (!bgColor) { bgColor = (crviACFData && crviACFData.couleurs_permanence && crviACFData.couleurs_permanence.permanence) ? crviACFData.couleurs_permanence.permanence @@ -821,8 +849,6 @@ export function initializeCalendar() { `; - - console.log('popoverContent:', popoverContent); // Initialiser le popover Bootstrap avec titre coloré if (window.bootstrap && window.bootstrap.Popover) { @@ -856,6 +882,20 @@ export function initializeCalendar() { if (bodyElement && txtColor) { bodyElement.style.color = txtColor; } + + // Appliquer les styles du statut + const statutElement = popoverElement.querySelector('.event-status'); + if (statutElement) { + const statutDisplay = getStatutDisplay(eventProps.statut, eventProps.type); + statutElement.style.backgroundColor = statutDisplay.color; + statutElement.style.color = getTextColor(statutDisplay.color); + statutElement.style.padding = '2px 8px'; + statutElement.style.borderRadius = '3px'; + console.log('🎨 [POPOVER] Styles de statut appliqués:', { + statut: statutDisplay.text, + backgroundColor: statutDisplay.color + }); + } } }); @@ -874,6 +914,20 @@ export function initializeCalendar() { color: popoverTextColor }); } + + // Appliquer aussi les styles du statut + const statutElement = node.querySelector('.event-status'); + if (statutElement) { + const statutDisplay = getStatutDisplay(eventProps.statut, eventProps.type); + statutElement.style.backgroundColor = statutDisplay.color; + statutElement.style.color = getTextColor(statutDisplay.color); + statutElement.style.padding = '2px 8px'; + statutElement.style.borderRadius = '3px'; + console.log('🎨 [POPOVER] Styles de statut appliqués via observer:', { + statut: statutDisplay.text, + backgroundColor: statutDisplay.color + }); + } } }); });