adejs/static/js/calendar.js

68 lines
1.8 KiB
JavaScript
Raw Permalink 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
2018-12-04 15:31:04 +01:00
resultDiv.innerHTML = '';
2018-12-04 14:53:17 +01: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) {
let events = JSON.parse(xhr.responseText);
setData(events);
} else {
setError();
}
}
};
xhr.open('GET', CALENDAR_URL, true);
xhr.send();
}
function setData(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',
nowIndicator: true,
allDaySlot: false,
eventClick: function(info) {
info.jsEvent.preventDefault();
},
2018-12-04 15:31:04 +01:00
customButtons: {
refreshCalendar: {
text: "Refresh",
click: function() {
getTable();
},
},
},
header: {
left: 'title',
center: '',
2018-12-04 15:31:04 +01:00
right: 'refreshCalendar month,agendaWeek,agendaDay prev,next today'
}
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();