2017-10-03 14:17:26 +02:00
|
|
|
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;
|
2017-10-04 11:25:59 +02:00
|
|
|
var emptyCoursesShown = false;
|
2017-09-25 15:26:06 +02:00
|
|
|
|
|
|
|
function getTable() {
|
|
|
|
// Send XHR to totalTable
|
2017-09-25 17:17:24 +02:00
|
|
|
loadingDiv.style.display = "";
|
|
|
|
errorDiv.style.display = "none";
|
|
|
|
|
2017-09-25 15:26:06 +02:00
|
|
|
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);
|
2017-09-25 15:26:06 +02:00
|
|
|
xhr.send();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setData(text) {
|
|
|
|
loadingDiv.style.display = "none";
|
2017-09-25 17:17:24 +02:00
|
|
|
errorDiv.style.display = "none";
|
2017-09-25 15:26:06 +02:00
|
|
|
resultDiv.innerHTML = text;
|
2017-10-04 11:25:59 +02:00
|
|
|
emptyCoursesShown = false;
|
2017-10-03 14:17:26 +02:00
|
|
|
|
|
|
|
var emptyCourses = document.getElementsByClassName('no-courses');
|
|
|
|
if (emptyCourses.length === 0) {
|
|
|
|
showEmptyCourses();
|
2017-10-04 11:25:59 +02:00
|
|
|
document.getElementById('extend').style.display = "none";
|
2017-10-03 14:17:26 +02:00
|
|
|
} else {
|
|
|
|
hideEmptyCourses();
|
|
|
|
document.getElementById('extend').addEventListener('click', function() {
|
2017-10-04 11:25:59 +02:00
|
|
|
switchEmptyCourses();
|
2017-10-03 14:17:26 +02:00
|
|
|
});
|
|
|
|
}
|
2017-10-04 11:25:59 +02:00
|
|
|
updateExtendText();
|
2017-10-03 14:17:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function showEmptyCourses() {
|
2017-10-04 11:25:59 +02:00
|
|
|
emptyCoursesShown = true;
|
2017-10-03 14:17:26 +02:00
|
|
|
var emptyCourses = document.getElementsByClassName('no-courses');
|
|
|
|
for (var i = 0; i < emptyCourses.length; i++) {
|
|
|
|
emptyCourses[i].style.display = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideEmptyCourses() {
|
2017-10-04 11:25:59 +02:00
|
|
|
emptyCoursesShown = false;
|
2017-10-03 14:17:26 +02:00
|
|
|
var emptyCourses = document.getElementsByClassName('no-courses');
|
|
|
|
for (var i = 0; i < emptyCourses.length; i++) {
|
|
|
|
emptyCourses[i].style.display = "none";
|
|
|
|
}
|
2017-10-04 11:25:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function switchEmptyCourses() {
|
|
|
|
if (emptyCoursesShown) {
|
|
|
|
hideEmptyCourses();
|
|
|
|
} else {
|
|
|
|
showEmptyCourses();
|
|
|
|
}
|
|
|
|
updateExtendText();
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateExtendText() {
|
|
|
|
document.getElementById('extendText').innerHTML =
|
|
|
|
"Courses with null TD equivalent " + (emptyCoursesShown ? "(hide)" : "(show)");
|
|
|
|
|
2017-09-25 15:26:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setError() {
|
|
|
|
loadingDiv.style.display = "none";
|
2017-09-25 17:17:24 +02:00
|
|
|
errorDiv.style.display = "";
|
2017-09-25 15:26:06 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 17:17:24 +02:00
|
|
|
document.getElementById('tryAgain').addEventListener('click', getTable);
|
2017-09-25 15:26:06 +02:00
|
|
|
getTable();
|