2018-11-23 19:58:13 +00:00
|
|
|
function zerocalcareDisplay() {
|
|
|
|
|
|
|
|
zerocalcareOutput = document.getElementById('zerocalcareOutput');
|
|
|
|
|
|
|
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
|
|
|
|
|
|
|
var json_obj = JSON.parse(xhr.responseText);
|
2020-07-27 19:38:21 +00:00
|
|
|
var atLeastOne = false;
|
2019-09-03 13:14:09 +00:00
|
|
|
|
2018-11-23 19:58:13 +00:00
|
|
|
for (i in json_obj) {
|
2020-04-17 20:35:46 +00:00
|
|
|
// Do not display private events
|
|
|
|
if (typeof json_obj[i]['CLASS'] === 'string' && json_obj[i]['CLASS'] == 'PRIVATE') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-11-23 19:58:13 +00:00
|
|
|
// Future improvements needed for a better backend output date in ISO format
|
|
|
|
// Now we have to parse the string :( very very ugly
|
2018-11-24 12:10:33 +00:00
|
|
|
var date = new Date(json_obj[i]['DATETIME']);
|
2018-11-23 19:58:13 +00:00
|
|
|
|
2018-11-24 12:10:33 +00:00
|
|
|
var m = new moment(date);
|
|
|
|
m.locale('it');
|
2018-11-23 19:58:13 +00:00
|
|
|
|
|
|
|
var eventElement = document.createElement('div');
|
|
|
|
|
|
|
|
var titleElement = document.createElement('h5');
|
2020-07-15 21:03:46 +00:00
|
|
|
titleElement.appendChild(document.createTextNode(decodeURI(json_obj[i]['NAME'])));
|
2018-11-23 19:58:13 +00:00
|
|
|
titleElement.style.fontStyle = 'italic';
|
|
|
|
titleElement.classList.add('widget-title');
|
|
|
|
|
|
|
|
var dateElement = document.createElement('div');
|
2020-04-17 19:10:11 +00:00
|
|
|
var dateText = document.createElement('span');
|
2020-04-17 19:12:26 +00:00
|
|
|
dateText.appendChild(document.createTextNode(m.format('dddd D MMMM YYYY')));
|
2020-04-17 19:10:11 +00:00
|
|
|
dateElement.appendChild(document.createTextNode('📅 '));
|
|
|
|
dateElement.appendChild(dateText);
|
2018-11-23 19:58:13 +00:00
|
|
|
|
|
|
|
var timeElement = document.createElement('div');
|
2020-04-17 19:10:11 +00:00
|
|
|
var timeText = document.createElement('span');
|
2019-01-05 14:41:49 +00:00
|
|
|
var timeString = (json_obj[i]['ALLDAY'] == true) ? 'Tutto il giorno' : ('ore ' + m.format('HH:mm'));
|
2020-04-17 19:10:11 +00:00
|
|
|
timeText.appendChild(document.createTextNode(timeString));
|
|
|
|
timeElement.appendChild(document.createTextNode('⏰ '));
|
|
|
|
timeElement.appendChild(timeText);
|
|
|
|
|
2018-11-23 19:58:13 +00:00
|
|
|
|
|
|
|
// add if location is not empty -- default location should be selected by backend
|
|
|
|
var locationElement = document.createElement('div');
|
2020-04-17 19:10:11 +00:00
|
|
|
var locationText = document.createElement('span');
|
2018-11-23 19:58:13 +00:00
|
|
|
if (typeof json_obj[i]['LOCATION'] !== 'undefined' && json_obj[i]['LOCATION'] != '') {
|
2020-04-17 19:10:11 +00:00
|
|
|
locationText.appendChild(document.createTextNode(json_obj[i]['LOCATION']));
|
2018-11-23 19:58:13 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-04-17 19:10:11 +00:00
|
|
|
locationText.appendChild(document.createTextNode('Officina Informatica'));
|
2018-11-23 19:58:13 +00:00
|
|
|
}
|
2020-04-17 19:10:11 +00:00
|
|
|
locationElement.appendChild(document.createTextNode('📍 '));
|
|
|
|
locationElement.appendChild(locationText);
|
2020-04-17 18:59:05 +00:00
|
|
|
|
2018-11-23 19:58:13 +00:00
|
|
|
eventElement.appendChild(titleElement);
|
2020-04-17 18:59:05 +00:00
|
|
|
// Check if event is not confirmed
|
2020-04-17 20:35:46 +00:00
|
|
|
if (typeof json_obj[i]['STATUS'] === 'string') {
|
2020-04-18 19:07:24 +00:00
|
|
|
if (json_obj[i]['STATUS'] == 'TENTATIVE') {
|
|
|
|
// Make the text a bit lighter and italic
|
|
|
|
dateText.style.fontStyle =
|
|
|
|
timeText.style.fontStyle =
|
|
|
|
locationText.style.fontStyle = 'italic';
|
|
|
|
dateText.style.color =
|
|
|
|
timeText.style.color =
|
|
|
|
locationText.style.color = 'gray';
|
|
|
|
// Add note
|
|
|
|
var unconfirmedElement = document.createElement('div');
|
|
|
|
unconfirmedElement.style.fontWeight = 'bold';
|
|
|
|
unconfirmedElement.appendChild(document.createTextNode('⚠️ Non confermato!'));
|
|
|
|
eventElement.appendChild(unconfirmedElement);
|
|
|
|
}
|
|
|
|
else if (json_obj[i]['STATUS'] == 'CANCELLED') {
|
|
|
|
// Strike time, date and location to remark this concept
|
2020-04-17 20:35:46 +00:00
|
|
|
dateText.style.textDecoration = 'line-through';
|
|
|
|
timeText.style.textDecoration = 'line-through';
|
|
|
|
locationText.style.textDecoration = 'line-through';
|
2020-04-18 19:07:24 +00:00
|
|
|
// Add note
|
2020-04-17 20:35:46 +00:00
|
|
|
var unconfirmedElement = document.createElement('div');
|
|
|
|
unconfirmedElement.style.fontWeight = 'bold';
|
2020-04-18 19:07:24 +00:00
|
|
|
unconfirmedElement.appendChild(document.createTextNode('⚠️ Cancellato!'));
|
2020-04-17 20:35:46 +00:00
|
|
|
eventElement.appendChild(unconfirmedElement);
|
|
|
|
}
|
2020-04-17 18:59:05 +00:00
|
|
|
}
|
2018-11-23 19:58:13 +00:00
|
|
|
eventElement.appendChild(dateElement);
|
|
|
|
eventElement.appendChild(timeElement);
|
|
|
|
eventElement.appendChild(locationElement);
|
|
|
|
zerocalcareOutput.appendChild(eventElement);
|
2020-07-27 19:38:21 +00:00
|
|
|
atLeastOne = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atLeastOne == false) {
|
|
|
|
zerocalcareOutput.childNodes[0].textContent = 'Nessun appuntamento in programma';
|
2018-11-23 19:58:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
zerocalcareOutput.childNodes[0].textContent = 'API Error: Calendario non disponibile';
|
|
|
|
}
|
2018-11-18 18:18:45 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 19:58:13 +00:00
|
|
|
function zerocalcareTrigger() {
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.onload = zerocalcareDisplay;
|
|
|
|
xhr.open('GET', 'https://golem.linux.it/cgi/zerocalcare/main.py?interval=4weeks', true);
|
|
|
|
xhr.send(null);
|
2018-11-22 22:40:48 +00:00
|
|
|
|
2018-11-18 18:18:45 +00:00
|
|
|
}
|