function researchRoom() { var research = document.getElementById('research').value; var xhr = new XMLHttpRequest(); xhr.open('GET', 'api/request.php?research='+encodeURI(research), true); xhr.onload = function() { var table = document.getElementById('research-results'); table.innerHTML = ''; document.getElementById('research-results-table').style.display = 'block'; res = JSON.parse(xhr.responseText); for (var i=0; i' + res[i].name + '\ \ ' + '??' + '\ '; } }; xhr.send(null); } function httpGetAsync(theUrl, callback) { var xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { callback(xmlHttp.responseText, xmlHttp.status); } } xmlHttp.open("GET", theUrl, true); xmlHttp.send(null); } function selectRoom(roomId) { var svg = document.getElementById('plan'); var selectedRooms = plan.contentDocument.getElementsByClassName('current-room'); for (var i = 0; i < selectedRooms.length; i++) { selectedRooms[i].classList.remove('current-room'); } var room = svg.contentDocument.getElementById('salle-' + roomId); if (room == null) { console.log('Error: the room salle-'+roomId+' does not exist'); return; } room.classList.add('current-room'); httpGetAsync("api/request.php?salle="+room.id.substring("salle-".length), function (s,errcode){ window.clearTimeout(document.wnsTimeout); if (s == "404") { document.getElementById('room-name').innerText = 'Salle inconnue'; document.getElementById('room-owners').style.display = 'none'; document.getElementById('room-description').innerHTML = "Aucune information n'est disponible pour cette salle. Si vous en avez, indiquez-les à l'adresse samy.avrillon@ens-lyon.fr en indiquant l'identifiant de la salle : " + roomId; return; } salle = JSON.parse(s) if (room.id == "salle-" + salle["id"]) { if (errcode == 200) { titres = ((salle.aliaz.length!=0)?(salle.aliaz.join(' ou ')):"Aucun alias connu."); document.getElementById('room-name').innerText = titres; document.getElementById('room-description').innerText = salle.description; if (salle.locataires.length == 0) { document.getElementById('room-owners').style.display = 'none'; document.getElementById('room-owners-list').innerText = ''; } else { document.getElementById('room-owners').style.display = 'block'; document.getElementById('room-owners-list').innerText = salle.locataires.join(", "); } } else { console.log("Error " + errcode); } } }); } // Update the current room based on the current anchor function updateCurrentRoom() { // Hide room research modal var modal = bootstrap.Modal.getInstance(document.getElementById('room-research-modal')); if (modal != null) { modal.hide(); } var id = window.location.hash.substring(1); // Remove # selectRoom(id); } function initSvgSupport() { var plan = document.getElementById('plan'); svgPanZoom(plan, {zoomEnabled: true, controlIconsEnabled: true}); var salles = plan.contentDocument.querySelectorAll('#salles-group path'); for (var i = 0; i < salles.length; i++) { salles[i].addEventListener('click', function(e) { var id = e.target.id.substring('salle-'.length); // Remove prefix selectRoom(id); }); } } window.addEventListener('load', function() { // Init SVG var plan = document.getElementById('plan'); if (plan.contentDocument == null) { plan.addEventListener('load', initSvgSupport); } else { initSvgSupport(); } // Update the current room if (window.location.hash != "") { updateCurrentRoom(); } window.onhashchange = function() { updateCurrentRoom(); } });