Crvi/assets/js/crvi_main.js
2026-01-20 07:54:37 +01:00

173 lines
7.3 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Les librairies JS sont importées depuis crvi_libraries.js
// Import de vos modules locaux
/* import './extra/agenda-loading-feedback.js'; */
import { initializeCalendar } from './modules/agenda-fullcalendar.js';
import { initializeIntervenantCalendar, initializeIntervenantAgendaTabs } from './modules/agenda-intervenant-calendar.js';
import { initializeIntervenantHub } from './modules/agenda-intervenant-hub.js';
import { initializeProfile } from './modules/agenda-intervenant-profile.js';
import { initializePermanences } from './modules/agenda-intervenant-permanences.js';
import { initializeAdminPermanences } from './modules/agenda-admin-permanences.js';
import { initStatsTable } from './modules/agenda-stats-table.js';
/**
* FIX GLOBAL : Corriger le stacking context de TOUTES les modales Bootstrap
* pour éviter que le backdrop passe devant les modales (problème avec Avada)
*/
function fixAllModalsStackingContext() {
// Attendre que Bootstrap soit chargé
if (typeof window.bootstrap === 'undefined') {
setTimeout(fixAllModalsStackingContext, 100);
return;
}
// Récupérer TOUTES les modales Bootstrap
const allModals = document.querySelectorAll('.modal');
allModals.forEach(modal => {
// 1. Forcer la modal à être enfant direct du body (échappe au stacking context Avada)
if (modal.parentNode !== document.body) {
document.body.appendChild(modal);
}
// 2. Fixer l'ordre backdrop/modal à chaque ouverture
modal.addEventListener('shown.bs.modal', function fixBackdropOrder() {
const backdrop = document.querySelector('.modal-backdrop');
if (backdrop && modal && document.body && document.body.children) {
try {
// Vérifier l'ordre dans le DOM
const bodyChildren = Array.from(document.body.children);
const modalIndex = bodyChildren.indexOf(modal);
const backdropIndex = bodyChildren.indexOf(backdrop);
// Si backdrop vient après modal, réordonner (backdrop AVANT modal)
if (backdropIndex > modalIndex && modalIndex !== -1 && backdropIndex !== -1) {
document.body.insertBefore(backdrop, modal);
}
} catch (error) {
console.warn('Erreur lors de la réorganisation du backdrop:', error);
}
}
});
});
console.log(`✅ Fix stacking context appliqué à ${allModals.length} modal(es)`);
}
// Initialisation au chargement de la page
document.addEventListener('DOMContentLoaded', function() {
console.log('DOM chargé, initialisation des modules...');
console.log('CRVI crviACFData', crviACFData);
/* configureToastr(); */
// ✨ FIX : Appliquer le fix stacking context à TOUTES les modales
fixAllModalsStackingContext();
// Détecter le contexte : intervenant ou admin
const isIntervenantContext = detectIntervenantContext();
if (isIntervenantContext) {
console.log('🔄 Contexte détecté : Espace Intervenant');
// Initialiser les modules selon la page
const hubEl = document.getElementById('intervenant-hub-container');
if (hubEl) {
console.log('📋 Initialisation du Hub intervenant...');
initializeIntervenantHub();
}
const agendaEl = document.getElementById('intervenant-agenda-container');
if (agendaEl) {
console.log('📅 Initialisation de l\'agenda intervenant...');
// Vérifier si on a des onglets (agenda + collègues) ou juste l'agenda simple
const agendaTabs = document.getElementById('agendaTabs');
if (agendaTabs) {
console.log('📑 Onglets détectés, initialisation avec basculement...');
initializeIntervenantAgendaTabs();
} else {
console.log('📅 Mode simple, initialisation agenda seul...');
initializeIntervenantCalendar();
}
}
const profileEl = document.getElementById('intervenant-profile-container');
if (profileEl) {
console.log('👤 Initialisation du profil intervenant...');
initializeProfile();
}
const permanencesEl = document.getElementById('intervenant-permanences-container');
if (permanencesEl) {
console.log('📝 Initialisation du formulaire permanences...');
initializePermanences();
}
} else {
// Contexte admin - vérifier quelle page on est
console.log('🔄 Contexte détecté : Admin');
// Vérifier si on est sur la page stats (priorité)
const statsTableEl = document.getElementById('stats-events-table');
const statsFiltersEl = document.querySelector('.stats-filters-container');
if (statsTableEl || statsFiltersEl) {
console.log('📊 Initialisation du tableau de stats...');
initStatsTable();
} else {
// Sinon, vérifier si on est sur la page agenda avec calendrier
const calendarEl = document.getElementById('agenda-calendar');
if (calendarEl) {
console.log('📅 Initialisation du calendrier admin...');
const calendar = initializeCalendar();
if (calendar) {
console.log('✅ Calendrier initialisé avec succès');
} else {
console.warn('⚠️ Échec de l\'initialisation du calendrier');
}
const modal = document.getElementById('eventModal');
if (modal) {
// Vérifier que bootstrap est disponible
if (typeof window.bootstrap !== 'undefined' && window.bootstrap.Modal) {
const bsModal = new window.bootstrap.Modal(modal);
} else {
console.warn('Bootstrap n\'est pas encore chargé, modal ne sera pas initialisé');
}
} else {
console.warn('Modal eventModal non trouvé (normal si pas sur page agenda admin)');
}
} else {
console.log(' Élément agenda-calendar non trouvé (normal si pas sur page agenda)');
}
}
// Vérifier si on est sur la page admin permanences
const adminPermanencesEl = document.getElementById('admin-permanences-container');
if (adminPermanencesEl) {
console.log('📝 Initialisation du formulaire permanences admin...');
initializeAdminPermanences();
}
}
// Initialiser Select2 sur les <select> (commun à tous les contextes)
jQuery('.select2').select2();
});
/**
* Détecte si on est dans un contexte intervenant
* @returns {boolean}
*/
function detectIntervenantContext() {
// Vérifier la présence des conteneurs intervenant
const intervenantContainers = [
'intervenant-hub-container',
'intervenant-agenda-container',
'intervenant-profile-container',
'intervenant-permanences-container'
];
return intervenantContainers.some(id => document.getElementById(id) !== null);
}