@@ -27,6 +27,7 @@ function renderRooms(rooms) {
2727 div . className = 'room-item' ;
2828 div . dataset . roomId = room . id ;
2929 div . textContent = name ;
30+ div . onclick = ( ) => clickHandler ( room . id ) ;
3031 container . appendChild ( div ) ;
3132 }
3233}
@@ -39,3 +40,68 @@ async function get(path) {
3940 }
4041 return await response . json ( ) ;
4142}
43+
44+ async function clickHandler ( id ) {
45+ try {
46+ const roomData = await get ( 'rooms/' + id ) ;
47+ showRoomDetails ( roomData ) ;
48+ } catch ( err ) {
49+ console . error ( 'Failed to load room details:' , err ) ;
50+ alert ( 'Erreur lors du chargement des informations de la salle.' ) ;
51+ }
52+ }
53+
54+ function showRoomDetails ( roomData ) {
55+ // Supprimer l'encadré existant s'il y en a un
56+ const existingModal = document . getElementById ( 'room-details-modal' ) ;
57+ if ( existingModal ) {
58+ existingModal . remove ( ) ;
59+ }
60+
61+ // Créer l'encadré
62+ const modal = document . createElement ( 'div' ) ;
63+ modal . id = 'room-details-modal' ;
64+ modal . style . position = 'fixed' ;
65+ modal . style . top = '50%' ;
66+ modal . style . left = '50%' ;
67+ modal . style . transform = 'translate(-50%, -50%)' ;
68+ modal . style . backgroundColor = 'white' ;
69+ modal . style . border = '1px solid #ccc' ;
70+ modal . style . padding = '20px' ;
71+ modal . style . boxShadow = '0 4px 8px rgba(0,0,0,0.1)' ;
72+ modal . style . zIndex = '1000' ;
73+ modal . style . maxWidth = '400px' ;
74+ modal . style . borderRadius = '8px' ;
75+
76+ // Contenu
77+ let content = '<h3>Détails de la salle</h3>' ;
78+ for ( const [ key , value ] of Object . entries ( roomData ) ) {
79+ if ( key === 'classes' && Array . isArray ( value ) ) {
80+ content += `<p><strong>${ key } :</strong> ${ value . map ( c => c . name || c . id ) . join ( ', ' ) } </p>` ;
81+ } else if ( key === 'features' && Array . isArray ( value ) ) {
82+ content += `<p><strong>${ key } :</strong> ${ value . map ( f => f . name || f . code ) . join ( ', ' ) } </p>` ;
83+ } else {
84+ content += `<p><strong>${ key } :</strong> ${ value } </p>` ;
85+ }
86+ }
87+ content += '<button onclick="closeRoomDetails()">Fermer</button>' ;
88+
89+ modal . innerHTML = content ;
90+
91+ // Ajouter au body
92+ document . body . appendChild ( modal ) ;
93+
94+ // Fermer en cliquant en dehors
95+ modal . addEventListener ( 'click' , ( e ) => {
96+ if ( e . target === modal ) {
97+ closeRoomDetails ( ) ;
98+ }
99+ } ) ;
100+ }
101+
102+ function closeRoomDetails ( ) {
103+ const modal = document . getElementById ( 'room-details-modal' ) ;
104+ if ( modal ) {
105+ modal . remove ( ) ;
106+ }
107+ }
0 commit comments