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