[F.END] Please, use strict

This commit is contained in:
giuliof 2020-09-21 21:27:25 +02:00
parent c5fe9a33f5
commit de0032d639
1 changed files with 29 additions and 29 deletions

View File

@ -1,13 +1,14 @@
function zerocalcareDisplay() { "use strict"
zerocalcareOutput = document.getElementById('zerocalcareOutput');
function zerocalcareDisplay(xhr) {
let zerocalcareOutput = document.getElementById('zerocalcareOutput');
if (xhr.readyState == 4 && xhr.status == 200) { if (xhr.readyState == 4 && xhr.status == 200) {
var json_obj = JSON.parse(xhr.responseText); let json_obj = JSON.parse(xhr.responseText);
var atLeastOne = false; let atLeastOne = false;
for (i in json_obj) { for (let i in json_obj) {
// Do not display private events // Do not display private events
if (typeof json_obj[i]['CLASS'] === 'string' && json_obj[i]['CLASS'] == 'PRIVATE') { if (typeof json_obj[i]['CLASS'] === 'string' && json_obj[i]['CLASS'] == 'PRIVATE') {
continue; continue;
@ -15,20 +16,20 @@ function zerocalcareDisplay() {
// Future improvements needed for a better backend output date in ISO format // Future improvements needed for a better backend output date in ISO format
// Now we have to parse the string :( very very ugly // Now we have to parse the string :( very very ugly
var date = new Date(json_obj[i]['DATETIME']); let date = new Date(json_obj[i]['DATETIME']);
var m = new moment(date); let m = new moment(date);
m.locale('it'); m.locale('it');
var eventElement = document.createElement('div'); let eventElement = document.createElement('div');
var titleElement = document.createElement('h5'); let titleElement = document.createElement('h5');
titleElement.appendChild(document.createTextNode(decodeURI(json_obj[i]['SUMMARY']))); titleElement.appendChild(document.createTextNode(decodeURI(json_obj[i]['SUMMARY'])));
titleElement.style.fontStyle = 'italic'; titleElement.style.fontStyle = 'italic';
titleElement.classList.add('widget-title'); titleElement.classList.add('widget-title');
eventElement.appendChild(titleElement); eventElement.appendChild(titleElement);
var contentEventElement = document.createElement('div'); let contentEventElement = document.createElement('div');
eventElement.appendChild(contentEventElement); eventElement.appendChild(contentEventElement);
// Check if event is not confirmed // Check if event is not confirmed
@ -38,7 +39,7 @@ function zerocalcareDisplay() {
contentEventElement.style.fontStyle = 'italic'; contentEventElement.style.fontStyle = 'italic';
contentEventElement.style.color = 'gray'; contentEventElement.style.color = 'gray';
// Add note // Add note
var unconfirmedElement = document.createElement('div'); let unconfirmedElement = document.createElement('div');
unconfirmedElement.style.fontWeight = 'bold'; unconfirmedElement.style.fontWeight = 'bold';
unconfirmedElement.appendChild(document.createTextNode('⚠️ Non confermato!')); unconfirmedElement.appendChild(document.createTextNode('⚠️ Non confermato!'));
contentEventElement.appendChild(unconfirmedElement); contentEventElement.appendChild(unconfirmedElement);
@ -49,31 +50,31 @@ function zerocalcareDisplay() {
timeText.style.textDecoration = 'line-through'; timeText.style.textDecoration = 'line-through';
locationText.style.textDecoration = 'line-through'; locationText.style.textDecoration = 'line-through';
// Add note // Add note
var unconfirmedElement = document.createElement('div'); let unconfirmedElement = document.createElement('div');
unconfirmedElement.style.fontWeight = 'bold'; unconfirmedElement.style.fontWeight = 'bold';
unconfirmedElement.appendChild(document.createTextNode('⚠️ Cancellato!')); unconfirmedElement.appendChild(document.createTextNode('⚠️ Cancellato!'));
contentEventElement.appendChild(unconfirmedElement); contentEventElement.appendChild(unconfirmedElement);
} }
} }
var dateElement = document.createElement('div'); let dateElement = document.createElement('div');
var dateText = document.createElement('span'); let dateText = document.createElement('span');
dateText.appendChild(document.createTextNode(m.format('dddd D MMMM YYYY'))); dateText.appendChild(document.createTextNode(m.format('dddd D MMMM YYYY')));
dateElement.appendChild(document.createTextNode('📅 ')); dateElement.appendChild(document.createTextNode('📅 '));
dateElement.appendChild(dateText); dateElement.appendChild(dateText);
contentEventElement.appendChild(dateElement); contentEventElement.appendChild(dateElement);
var timeElement = document.createElement('div'); let timeElement = document.createElement('div');
var timeText = document.createElement('span'); let timeText = document.createElement('span');
var timeString = (json_obj[i]['ALLDAY'] == true) ? 'Tutto il giorno' : ('ore ' + m.format('HH:mm')); let timeString = (json_obj[i]['ALLDAY'] == true) ? 'Tutto il giorno' : ('ore ' + m.format('HH:mm'));
timeText.appendChild(document.createTextNode(timeString)); timeText.appendChild(document.createTextNode(timeString));
timeElement.appendChild(document.createTextNode('⏰ ')); timeElement.appendChild(document.createTextNode('⏰ '));
timeElement.appendChild(timeText); timeElement.appendChild(timeText);
contentEventElement.appendChild(timeElement); contentEventElement.appendChild(timeElement);
// add if location is not empty -- default location should be selected by backend // add if location is not empty -- default location should be selected by backend
var locationElement = document.createElement('div'); let locationElement = document.createElement('div');
var locationText = document.createElement('span'); let locationText = document.createElement('span');
if (json_obj[i]['LOCATION'] !== undefined && json_obj[i]['LOCATION'] != '') { if (json_obj[i]['LOCATION'] !== undefined && json_obj[i]['LOCATION'] != '') {
locationText.appendChild(document.createTextNode(decodeURI(json_obj[i]['LOCATION']))); locationText.appendChild(document.createTextNode(decodeURI(json_obj[i]['LOCATION'])));
} }
@ -85,17 +86,17 @@ function zerocalcareDisplay() {
contentEventElement.appendChild(locationElement); contentEventElement.appendChild(locationElement);
if (json_obj[i]['DESCRIPTION'] !== undefined && json_obj[i]['DESCRIPTION'] != '') { if (json_obj[i]['DESCRIPTION'] !== undefined && json_obj[i]['DESCRIPTION'] != '') {
var descriptionElement = document.createElement('div'); let descriptionElement = document.createElement('div');
var descriptionText = document.createElement('span'); let descriptionText = document.createElement('span');
descriptionText.appendChild(document.createTextNode(decodeURI(json_obj[i]['DESCRIPTION']))); descriptionText.appendChild(document.createTextNode(decodeURI(json_obj[i]['DESCRIPTION'])));
descriptionElement.appendChild(document.createTextNode('📝 ')); descriptionElement.appendChild(document.createTextNode('📝 '));
descriptionElement.appendChild(descriptionText); descriptionElement.appendChild(descriptionText);
descriptionElement.style.display = "none"; descriptionElement.style.display = "none";
// Display a clickable "..." button. // Display a clickable "..." button.
var moreElement = document.createElement('div'); let moreElement = document.createElement('div');
var moreShowText = document.createElement('a'); let moreShowText = document.createElement('a');
var moreHideText = document.createElement('a'); let moreHideText = document.createElement('a');
moreShowText.appendChild(document.createTextNode('⬇️ Più informazioni...')); moreShowText.appendChild(document.createTextNode('⬇️ Più informazioni...'));
moreElement.appendChild(moreShowText); moreElement.appendChild(moreShowText);
@ -135,9 +136,8 @@ function zerocalcareTrigger(url) {
if (typeof url !== "string") if (typeof url !== "string")
return return
xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.onload = zerocalcareDisplay; xhr.onload = () => { zerocalcareDisplay(xhr) };
xhr.open('GET', url, true); xhr.open('GET', url, true);
xhr.send(null); xhr.send(null);
}
}