adejs/static/js/totalTable.js

65 lines
1.8 KiB
JavaScript
Raw Normal View History

var loadingDiv = document.getElementById('loading');
var errorDiv = document.getElementById('error');
var resultDiv = document.getElementById('result');
2017-09-25 17:17:24 +02:00
const timeout = 10000;
function getTable() {
// Send XHR to totalTable
2017-09-25 17:17:24 +02:00
loadingDiv.style.display = "";
errorDiv.style.display = "none";
let xhr = new XMLHttpRequest();
xhr.timeout = timeout;
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
setData(xhr.responseText);
} else {
setError();
}
}
};
2017-10-03 10:54:49 +02:00
xhr.open('GET', TABLE_URL, true);
xhr.send();
}
function setData(text) {
loadingDiv.style.display = "none";
2017-09-25 17:17:24 +02:00
errorDiv.style.display = "none";
resultDiv.innerHTML = text;
var emptyCourses = document.getElementsByClassName('no-courses');
if (emptyCourses.length === 0) {
showEmptyCourses();
} else {
hideEmptyCourses();
document.getElementById('extend').addEventListener('click', function() {
showEmptyCourses();
});
}
}
function showEmptyCourses() {
var emptyCourses = document.getElementsByClassName('no-courses');
for (var i = 0; i < emptyCourses.length; i++) {
emptyCourses[i].style.display = "";
}
document.getElementById('extend').style.display = "none";
}
function hideEmptyCourses() {
var emptyCourses = document.getElementsByClassName('no-courses');
for (var i = 0; i < emptyCourses.length; i++) {
emptyCourses[i].style.display = "none";
}
document.getElementById('extend').style.display = "";
}
function setError() {
loadingDiv.style.display = "none";
2017-09-25 17:17:24 +02:00
errorDiv.style.display = "";
}
2017-09-25 17:17:24 +02:00
document.getElementById('tryAgain').addEventListener('click', getTable);
getTable();