Skip to content

Commit 89ea36a

Browse files
committed
Add room details modal with dynamic content rendering
1 parent c36049d commit 89ea36a

3 files changed

Lines changed: 123 additions & 0 deletions

File tree

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ <h2>Rooms</h2>
163163
}
164164
</script>
165165
<script src="script.js"></script>
166+
167+
<!-- Room Details Modal -->
168+
<div id="room-details-modal" class="modal">
169+
<div class="modal-content">
170+
<span class="close-button" onclick="closeRoomDetails()">&times;</span>
171+
<h3>Détails de la salle</h3>
172+
<div id="room-details-content"></div>
173+
</div>
174+
</div>
166175
</body>
167176

168177
</html>

script.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

style.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,51 @@ body, html {
230230
.rooms-container::-webkit-scrollbar-thumb:hover {
231231
background: #666;
232232
}
233+
234+
/* ========================================
235+
Room Details Modal
236+
======================================== */
237+
.modal {
238+
display: none;
239+
position: fixed;
240+
z-index: 1000;
241+
left: 0;
242+
top: 0;
243+
width: 100%;
244+
height: 100%;
245+
background-color: rgba(0, 0, 0, 0.5);
246+
}
247+
248+
.modal-content {
249+
background-color: white;
250+
margin: 15% auto;
251+
padding: 20px;
252+
border: 1px solid #888;
253+
width: 80%;
254+
max-width: 500px;
255+
border-radius: 8px;
256+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
257+
position: relative;
258+
}
259+
260+
.close-button {
261+
color: #aaa;
262+
float: right;
263+
font-size: 28px;
264+
font-weight: bold;
265+
cursor: pointer;
266+
}
267+
268+
.close-button:hover,
269+
.close-button:focus {
270+
color: black;
271+
text-decoration: none;
272+
}
273+
274+
#room-details-content p {
275+
margin: 10px 0;
276+
}
277+
278+
#room-details-content strong {
279+
color: #333;
280+
}

0 commit comments

Comments
 (0)