adejs/static/js/calendar.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-12-04 14:53:17 +01:00
var loadingDiv = document.getElementById('loading');
var errorDiv = document.getElementById('error');
var resultDiv = document.getElementById('result');
const timeout = 10000;
var emptyCoursesShown = false;
var calendar;
function getTable() {
// Send XHR to totalTable
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) {
let events = JSON.parse(xhr.responseText);
setData(events);
} else {
setError();
}
}
};
xhr.open('GET', CALENDAR_URL, true);
xhr.send();
}
function setData(events) {
console.log(events);
loadingDiv.style.display = "none";
errorDiv.style.display = "none";
calendar = new FullCalendar.Calendar(resultDiv, {
events: events,
defaultView: 'agendaWeek',
minTime: "07:00:00",
maxTime: "19:00:00",
2018-12-04 14:55:17 +01:00
timeZone: 'local',
2018-12-04 14:53:17 +01:00
});
calendar.render();
}
function setError() {
loadingDiv.style.display = "none";
errorDiv.style.display = "";
}
document.getElementById('tryAgain').addEventListener('click', getTable);
getTable();