2016-03-31 11:05:32 +02:00
|
|
|
/* global Module */
|
|
|
|
|
|
|
|
/* Magic Mirror
|
2018-06-11 23:09:00 +02:00
|
|
|
* Module: Calendar
|
|
|
|
*
|
|
|
|
* By Michael Teeuw http://michaelteeuw.nl
|
|
|
|
* MIT Licensed.
|
|
|
|
*/
|
2016-03-31 11:05:32 +02:00
|
|
|
|
2016-10-14 15:23:03 +02:00
|
|
|
Module.register("calendar", {
|
2016-03-31 11:05:32 +02:00
|
|
|
|
2018-06-11 23:09:00 +02:00
|
|
|
// Define module defaults
|
2016-03-31 11:05:32 +02:00
|
|
|
defaults: {
|
|
|
|
maximumEntries: 10, // Total Maximum Entries
|
2016-04-03 19:52:13 +02:00
|
|
|
maximumNumberOfDays: 365,
|
2016-03-31 11:05:32 +02:00
|
|
|
displaySymbol: true,
|
2016-05-10 11:58:05 -06:00
|
|
|
defaultSymbol: "calendar", // Fontawesome Symbol see http://fontawesome.io/cheatsheet/
|
2019-04-08 21:49:19 +02:00
|
|
|
showLocation: false,
|
2016-04-26 22:34:12 +02:00
|
|
|
displayRepeatingCountTitle: false,
|
2016-10-14 15:23:03 +02:00
|
|
|
defaultRepeatingCountTitle: "",
|
2016-04-03 19:52:13 +02:00
|
|
|
maxTitleLength: 25,
|
2017-04-02 15:06:58 -05:00
|
|
|
wrapEvents: false, // wrap events to multiple lines breaking at maxTitleLength
|
2019-01-16 22:51:44 -08:00
|
|
|
maxTitleLines: 3,
|
2016-03-31 11:05:32 +02:00
|
|
|
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
|
|
|
|
animationSpeed: 2000,
|
2016-04-03 19:52:13 +02:00
|
|
|
fade: true,
|
2016-05-10 01:01:00 -06:00
|
|
|
urgency: 7,
|
|
|
|
timeFormat: "relative",
|
2016-11-10 17:26:29 +01:00
|
|
|
dateFormat: "MMM Do",
|
2019-02-19 14:07:01 +01:00
|
|
|
dateEndFormat: "LT",
|
2017-05-02 21:20:35 +02:00
|
|
|
fullDayEventDateFormat: "MMM Do",
|
2018-10-26 15:22:05 +02:00
|
|
|
showEnd: false,
|
2016-09-04 00:05:02 +02:00
|
|
|
getRelative: 6,
|
2016-03-31 11:05:32 +02:00
|
|
|
fadePoint: 0.25, // Start on 1/4th of the list.
|
2016-11-30 21:24:04 +01:00
|
|
|
hidePrivate: false,
|
2018-04-08 14:57:28 +03:00
|
|
|
hideOngoing: false,
|
2017-01-29 00:59:38 +01:00
|
|
|
colored: false,
|
2018-04-27 11:06:45 -05:00
|
|
|
coloredSymbolOnly: false,
|
2018-06-11 12:54:27 +02:00
|
|
|
tableClass: "small",
|
2016-04-05 14:35:11 -04:00
|
|
|
calendars: [
|
2016-03-31 11:05:32 +02:00
|
|
|
{
|
2016-04-05 14:35:11 -04:00
|
|
|
symbol: "calendar",
|
|
|
|
url: "http://www.calendarlabs.com/templates/ical/US-Holidays.ics",
|
2016-03-31 11:05:32 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
titleReplace: {
|
2016-06-06 12:05:41 +02:00
|
|
|
"De verjaardag van ": "",
|
|
|
|
"'s birthday": ""
|
2016-04-05 10:01:54 +02:00
|
|
|
},
|
2017-03-12 11:36:40 -05:00
|
|
|
broadcastEvents: true,
|
2019-02-18 21:11:24 +01:00
|
|
|
excludedEvents: [],
|
2019-04-01 15:39:25 -04:00
|
|
|
sliceMultiDayEvents: false,
|
2019-04-10 16:50:18 -04:00
|
|
|
broadcastPastEvents: false,
|
2019-04-13 15:03:55 +02:00
|
|
|
nextDaysRelative: false
|
2016-03-31 11:05:32 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Define required scripts.
|
2016-10-14 15:23:03 +02:00
|
|
|
getStyles: function () {
|
2019-01-09 21:38:07 +00:00
|
|
|
return ["calendar.css", "font-awesome.css"];
|
2016-03-31 11:05:32 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Define required scripts.
|
2016-10-14 15:23:03 +02:00
|
|
|
getScripts: function () {
|
2016-04-05 14:35:11 -04:00
|
|
|
return ["moment.js"];
|
2016-03-31 11:05:32 +02:00
|
|
|
},
|
|
|
|
|
2016-04-21 01:04:00 +02:00
|
|
|
// Define required translations.
|
2016-10-14 15:23:03 +02:00
|
|
|
getTranslations: function () {
|
2017-03-30 22:14:11 +02:00
|
|
|
// The translations for the default modules are defined in the core translation files.
|
|
|
|
// Therefor we can just return false. Otherwise we should have returned a dictionary.
|
2016-06-04 20:32:55 -06:00
|
|
|
// If you're trying to build your own module including translations, check out the documentation.
|
2016-05-11 12:38:41 +02:00
|
|
|
return false;
|
2016-04-21 01:04:00 +02:00
|
|
|
},
|
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
// Override start method.
|
2016-10-14 15:23:03 +02:00
|
|
|
start: function () {
|
2016-04-05 14:35:11 -04:00
|
|
|
Log.log("Starting module: " + this.name);
|
2016-03-31 11:05:32 +02:00
|
|
|
|
|
|
|
// Set locale.
|
2017-07-31 22:09:08 +02:00
|
|
|
moment.updateLocale(config.language, this.getLocaleSpecification(config.timeFormat));
|
2017-06-26 13:03:03 +02:00
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
for (var c in this.config.calendars) {
|
|
|
|
var calendar = this.config.calendars[c];
|
2016-04-05 14:35:11 -04:00
|
|
|
calendar.url = calendar.url.replace("webcal://", "http://");
|
2017-01-30 16:26:42 -06:00
|
|
|
|
|
|
|
var calendarConfig = {
|
|
|
|
maximumEntries: calendar.maximumEntries,
|
2019-04-01 15:39:25 -04:00
|
|
|
maximumNumberOfDays: calendar.maximumNumberOfDays,
|
2019-04-10 16:50:18 -04:00
|
|
|
broadcastPastEvents: calendar.broadcastPastEvents,
|
2017-01-30 16:26:42 -06:00
|
|
|
};
|
2018-10-04 02:07:08 +02:00
|
|
|
if (calendar.symbolClass === "undefined" || calendar.symbolClass === null) {
|
|
|
|
calendarConfig.symbolClass = "";
|
|
|
|
}
|
|
|
|
if (calendar.titleClass === "undefined" || calendar.titleClass === null) {
|
|
|
|
calendarConfig.titleClass = "";
|
|
|
|
}
|
|
|
|
if (calendar.timeClass === "undefined" || calendar.timeClass === null) {
|
|
|
|
calendarConfig.timeClass = "";
|
|
|
|
}
|
2017-01-30 16:26:42 -06:00
|
|
|
|
2017-03-07 00:12:43 +01:00
|
|
|
// we check user and password here for backwards compatibility with old configs
|
2018-06-11 23:09:00 +02:00
|
|
|
if(calendar.user && calendar.pass) {
|
2017-07-30 22:32:28 -04:00
|
|
|
Log.warn("Deprecation warning: Please update your calendar authentication configuration.");
|
|
|
|
Log.warn("https://github.com/MichMich/MagicMirror/tree/v2.1.2/modules/default/calendar#calendar-authentication-options");
|
2017-03-07 00:12:43 +01:00
|
|
|
calendar.auth = {
|
|
|
|
user: calendar.user,
|
|
|
|
pass: calendar.pass
|
2019-06-05 10:23:58 +02:00
|
|
|
};
|
2017-03-07 00:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.addCalendar(calendar.url, calendar.auth, calendarConfig);
|
2019-02-25 22:47:30 +00:00
|
|
|
|
|
|
|
// Trigger ADD_CALENDAR every fetchInterval to make sure there is always a calendar
|
|
|
|
// fetcher running on the server side.
|
|
|
|
var self = this;
|
|
|
|
setInterval(function() {
|
|
|
|
self.addCalendar(calendar.url, calendar.auth, calendarConfig);
|
|
|
|
}, self.config.fetchInterval);
|
2016-03-31 11:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.calendarData = {};
|
2016-04-05 10:01:54 +02:00
|
|
|
this.loaded = false;
|
2016-03-31 11:05:32 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Override socket notification handler.
|
2016-10-14 15:23:03 +02:00
|
|
|
socketNotificationReceived: function (notification, payload) {
|
2016-04-05 14:35:11 -04:00
|
|
|
if (notification === "CALENDAR_EVENTS") {
|
2016-03-31 11:05:32 +02:00
|
|
|
if (this.hasCalendarURL(payload.url)) {
|
|
|
|
this.calendarData[payload.url] = payload.events;
|
2016-04-05 10:01:54 +02:00
|
|
|
this.loaded = true;
|
2016-10-14 15:23:03 +02:00
|
|
|
|
|
|
|
if (this.config.broadcastEvents) {
|
|
|
|
this.broadcastEvents();
|
|
|
|
}
|
2016-03-31 11:05:32 +02:00
|
|
|
}
|
2016-04-05 14:35:11 -04:00
|
|
|
} else if (notification === "FETCH_ERROR") {
|
|
|
|
Log.error("Calendar Error. Could not fetch calendar: " + payload.url);
|
2019-06-14 14:03:07 +02:00
|
|
|
this.loaded = true;
|
2016-04-05 14:35:11 -04:00
|
|
|
} else if (notification === "INCORRECT_URL") {
|
|
|
|
Log.error("Calendar Error. Incorrect url: " + payload.url);
|
2016-03-31 11:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.updateDom(this.config.animationSpeed);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Override dom generator.
|
2016-10-14 15:23:03 +02:00
|
|
|
getDom: function () {
|
2016-03-31 11:05:32 +02:00
|
|
|
|
|
|
|
var events = this.createEventList();
|
|
|
|
var wrapper = document.createElement("table");
|
2018-06-11 12:54:27 +02:00
|
|
|
wrapper.className = this.config.tableClass;
|
2016-03-31 11:05:32 +02:00
|
|
|
|
|
|
|
if (events.length === 0) {
|
2016-04-21 01:04:00 +02:00
|
|
|
wrapper.innerHTML = (this.loaded) ? this.translate("EMPTY") : this.translate("LOADING");
|
2018-06-11 12:54:27 +02:00
|
|
|
wrapper.className = this.config.tableClass + " dimmed";
|
2016-03-31 11:05:32 +02:00
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
2018-11-21 09:32:56 +01:00
|
|
|
if (this.config.fade && this.config.fadePoint < 1) {
|
|
|
|
if (this.config.fadePoint < 0) {
|
|
|
|
this.config.fadePoint = 0;
|
|
|
|
}
|
|
|
|
var startFade = events.length * this.config.fadePoint;
|
|
|
|
var fadeSteps = events.length - startFade;
|
|
|
|
}
|
2018-11-21 12:10:39 +01:00
|
|
|
|
2018-11-21 09:32:56 +01:00
|
|
|
var currentFadeStep = 0;
|
2018-05-10 19:54:01 -04:00
|
|
|
var lastSeenDate = "";
|
2018-05-09 22:32:15 -04:00
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
for (var e in events) {
|
|
|
|
var event = events[e];
|
2018-05-09 22:32:15 -04:00
|
|
|
var dateAsString = moment(event.startDate, "x").format(this.config.dateFormat);
|
2018-06-11 23:09:00 +02:00
|
|
|
if(this.config.timeFormat === "dateheaders"){
|
|
|
|
if(lastSeenDate !== dateAsString){
|
2018-05-09 22:32:15 -04:00
|
|
|
var dateRow = document.createElement("tr");
|
2018-10-04 02:07:08 +02:00
|
|
|
dateRow.className = "normal";
|
2018-05-09 22:32:15 -04:00
|
|
|
var dateCell = document.createElement("td");
|
|
|
|
|
|
|
|
dateCell.colSpan = "3";
|
|
|
|
dateCell.innerHTML = dateAsString;
|
2019-12-20 15:20:12 +01:00
|
|
|
dateCell.style.paddingTop = "10px";
|
2018-05-09 22:32:15 -04:00
|
|
|
dateRow.appendChild(dateCell);
|
|
|
|
wrapper.appendChild(dateRow);
|
|
|
|
|
2018-11-21 09:32:56 +01:00
|
|
|
if (e >= startFade) { //fading
|
|
|
|
currentFadeStep = e - startFade;
|
|
|
|
dateRow.style.opacity = 1 - (1 / fadeSteps * currentFadeStep);
|
|
|
|
}
|
2018-05-09 22:32:15 -04:00
|
|
|
|
|
|
|
lastSeenDate = dateAsString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
var eventWrapper = document.createElement("tr");
|
2017-01-28 18:21:02 +01:00
|
|
|
|
2018-04-27 11:06:45 -05:00
|
|
|
if (this.config.colored && !this.config.coloredSymbolOnly) {
|
2017-01-29 00:59:38 +01:00
|
|
|
eventWrapper.style.cssText = "color:" + this.colorForUrl(event.url);
|
|
|
|
}
|
2017-01-28 18:21:02 +01:00
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
eventWrapper.className = "normal";
|
|
|
|
|
|
|
|
if (this.config.displaySymbol) {
|
2016-10-14 15:23:03 +02:00
|
|
|
var symbolWrapper = document.createElement("td");
|
2018-04-27 11:06:45 -05:00
|
|
|
|
|
|
|
if (this.config.colored && this.config.coloredSymbolOnly) {
|
2018-05-05 08:31:58 -05:00
|
|
|
symbolWrapper.style.cssText = "color:" + this.colorForUrl(event.url);
|
2018-04-27 11:06:45 -05:00
|
|
|
}
|
|
|
|
|
2018-10-04 02:07:08 +02:00
|
|
|
var symbolClass = this.symbolClassForUrl(event.url);
|
|
|
|
symbolWrapper.className = "symbol align-right " + symbolClass;
|
|
|
|
|
2017-03-16 16:57:55 +01:00
|
|
|
var symbols = this.symbolsForUrl(event.url);
|
2018-06-11 23:09:00 +02:00
|
|
|
if(typeof symbols === "string") {
|
2017-03-16 16:57:55 +01:00
|
|
|
symbols = [symbols];
|
|
|
|
}
|
|
|
|
|
2018-06-11 23:09:00 +02:00
|
|
|
for(var i = 0; i < symbols.length; i++) {
|
2017-03-16 16:57:55 +01:00
|
|
|
var symbol = document.createElement("span");
|
2017-11-25 12:08:40 +01:00
|
|
|
symbol.className = "fa fa-fw fa-" + symbols[i];
|
2018-06-11 23:09:00 +02:00
|
|
|
if(i > 0){
|
2017-03-16 16:57:55 +01:00
|
|
|
symbol.style.paddingLeft = "5px";
|
|
|
|
}
|
|
|
|
symbolWrapper.appendChild(symbol);
|
|
|
|
}
|
2016-03-31 11:05:32 +02:00
|
|
|
eventWrapper.appendChild(symbolWrapper);
|
2019-06-05 09:32:10 +02:00
|
|
|
} else if(this.config.timeFormat === "dateheaders"){
|
2018-05-09 22:32:15 -04:00
|
|
|
var blankCell = document.createElement("td");
|
2018-10-04 02:07:08 +02:00
|
|
|
blankCell.innerHTML = " ";
|
2018-05-09 22:32:15 -04:00
|
|
|
eventWrapper.appendChild(blankCell);
|
2016-03-31 11:05:32 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 22:34:12 +02:00
|
|
|
var titleWrapper = document.createElement("td"),
|
2016-10-14 15:23:03 +02:00
|
|
|
repeatingCountTitle = "";
|
2016-05-11 12:38:41 +02:00
|
|
|
|
2019-01-16 22:53:28 -08:00
|
|
|
if (this.config.displayRepeatingCountTitle && event.firstYear !== undefined) {
|
2016-05-11 12:38:41 +02:00
|
|
|
|
2016-05-03 11:56:24 +02:00
|
|
|
repeatingCountTitle = this.countTitleForUrl(event.url);
|
2016-05-11 12:38:41 +02:00
|
|
|
|
2016-10-14 15:23:03 +02:00
|
|
|
if (repeatingCountTitle !== "") {
|
2016-12-29 15:31:01 +01:00
|
|
|
var thisYear = new Date(parseInt(event.startDate)).getFullYear(),
|
2016-04-26 22:34:12 +02:00
|
|
|
yearDiff = thisYear - event.firstYear;
|
2016-05-11 12:38:41 +02:00
|
|
|
|
2016-10-14 15:23:03 +02:00
|
|
|
repeatingCountTitle = ", " + yearDiff + ". " + repeatingCountTitle;
|
2016-04-26 22:34:12 +02:00
|
|
|
}
|
2016-05-11 12:38:41 +02:00
|
|
|
}
|
|
|
|
|
2016-04-26 22:34:12 +02:00
|
|
|
titleWrapper.innerHTML = this.titleTransform(event.title) + repeatingCountTitle;
|
2017-01-28 18:21:02 +01:00
|
|
|
|
2018-10-04 02:07:08 +02:00
|
|
|
var titleClass = this.titleClassForUrl(event.url);
|
|
|
|
|
2017-01-29 00:59:38 +01:00
|
|
|
if (!this.config.colored) {
|
2018-10-04 02:07:08 +02:00
|
|
|
titleWrapper.className = "title bright " + titleClass;
|
2017-01-29 00:59:38 +01:00
|
|
|
} else {
|
2018-10-04 02:07:08 +02:00
|
|
|
titleWrapper.className = "title " + titleClass;
|
2017-01-29 00:59:38 +01:00
|
|
|
}
|
2017-01-28 18:21:02 +01:00
|
|
|
|
2018-06-11 23:09:00 +02:00
|
|
|
if(this.config.timeFormat === "dateheaders"){
|
2018-05-10 19:54:01 -04:00
|
|
|
|
2018-05-09 22:32:15 -04:00
|
|
|
if (event.fullDayEvent) {
|
|
|
|
titleWrapper.colSpan = "2";
|
|
|
|
titleWrapper.align = "left";
|
2018-05-10 19:54:01 -04:00
|
|
|
|
2019-06-05 09:32:10 +02:00
|
|
|
} else {
|
2018-10-04 02:07:08 +02:00
|
|
|
|
|
|
|
var timeClass = this.timeClassForUrl(event.url);
|
2018-05-09 22:32:15 -04:00
|
|
|
var timeWrapper = document.createElement("td");
|
2018-10-04 02:07:08 +02:00
|
|
|
timeWrapper.className = "time light " + timeClass;
|
2018-05-09 22:32:15 -04:00
|
|
|
timeWrapper.align = "left";
|
|
|
|
timeWrapper.style.paddingLeft = "2px";
|
2018-11-21 12:10:39 +01:00
|
|
|
timeWrapper.innerHTML = moment(event.startDate, "x").format("LT");
|
2018-05-09 22:32:15 -04:00
|
|
|
eventWrapper.appendChild(timeWrapper);
|
|
|
|
titleWrapper.align = "right";
|
2016-04-20 21:40:56 +02:00
|
|
|
}
|
2018-05-10 19:54:01 -04:00
|
|
|
|
2018-05-09 22:32:15 -04:00
|
|
|
eventWrapper.appendChild(titleWrapper);
|
2019-06-05 09:32:10 +02:00
|
|
|
} else {
|
2018-05-09 22:32:15 -04:00
|
|
|
var timeWrapper = document.createElement("td");
|
|
|
|
|
|
|
|
eventWrapper.appendChild(titleWrapper);
|
|
|
|
//console.log(event.today);
|
|
|
|
var now = new Date();
|
|
|
|
// Define second, minute, hour, and day variables
|
|
|
|
var oneSecond = 1000; // 1,000 milliseconds
|
|
|
|
var oneMinute = oneSecond * 60;
|
|
|
|
var oneHour = oneMinute * 60;
|
|
|
|
var oneDay = oneHour * 24;
|
|
|
|
if (event.fullDayEvent) {
|
2018-11-21 09:32:56 +01:00
|
|
|
//subtract one second so that fullDayEvents end at 23:59:59, and not at 0:00:00 one the next day
|
2018-11-21 12:10:39 +01:00
|
|
|
event.endDate -= oneSecond;
|
2018-05-09 22:32:15 -04:00
|
|
|
if (event.today) {
|
|
|
|
timeWrapper.innerHTML = this.capFirst(this.translate("TODAY"));
|
|
|
|
} else if (event.startDate - now < oneDay && event.startDate - now > 0) {
|
|
|
|
timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW"));
|
|
|
|
} else if (event.startDate - now < 2 * oneDay && event.startDate - now > 0) {
|
|
|
|
if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
|
|
|
|
timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW"));
|
2016-05-10 01:01:00 -06:00
|
|
|
} else {
|
2018-05-09 22:32:15 -04:00
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
2016-05-10 01:01:00 -06:00
|
|
|
}
|
2016-04-19 10:34:14 +02:00
|
|
|
} else {
|
2016-05-10 11:58:05 -06:00
|
|
|
/* Check to see if the user displays absolute or relative dates with their events
|
2018-06-11 23:09:00 +02:00
|
|
|
* Also check to see if an event is happening within an 'urgency' time frameElement
|
|
|
|
* For example, if the user set an .urgency of 7 days, those events that fall within that
|
|
|
|
* time frame will be displayed with 'in xxx' time format or moment.fromNow()
|
|
|
|
*
|
|
|
|
* Note: this needs to be put in its own function, as the whole thing repeats again verbatim
|
|
|
|
*/
|
2016-05-10 01:01:00 -06:00
|
|
|
if (this.config.timeFormat === "absolute") {
|
2016-10-14 15:23:03 +02:00
|
|
|
if ((this.config.urgency > 1) && (event.startDate - now < (this.config.urgency * oneDay))) {
|
2016-05-10 11:58:05 -06:00
|
|
|
// This event falls within the config.urgency period that the user has set
|
2019-02-19 07:06:22 -06:00
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").from(moment().format("YYYYMMDD")));
|
2016-05-10 01:01:00 -06:00
|
|
|
} else {
|
2018-05-09 22:32:15 -04:00
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.fullDayEventDateFormat));
|
2016-05-10 01:01:00 -06:00
|
|
|
}
|
|
|
|
} else {
|
2019-02-18 07:18:07 -06:00
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").from(moment().format("YYYYMMDD")));
|
2016-05-10 01:01:00 -06:00
|
|
|
}
|
2016-04-19 10:34:14 +02:00
|
|
|
}
|
2018-08-28 17:35:53 +02:00
|
|
|
if(this.config.showEnd){
|
|
|
|
timeWrapper.innerHTML += "-" ;
|
2020-03-15 15:49:34 +01:00
|
|
|
timeWrapper.innerHTML += this.capFirst(moment(event.endDate , "x").format(this.config.fullDayEventDateFormat));
|
2018-08-28 17:35:53 +02:00
|
|
|
}
|
2016-04-15 13:13:06 +02:00
|
|
|
} else {
|
2018-05-09 22:32:15 -04:00
|
|
|
if (event.startDate >= new Date()) {
|
|
|
|
if (event.startDate - now < 2 * oneDay) {
|
|
|
|
// This event is within the next 48 hours (2 days)
|
|
|
|
if (event.startDate - now < this.config.getRelative * oneHour) {
|
|
|
|
// If event is within 6 hour, display 'in xxx' time format or moment.fromNow()
|
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
|
|
|
} else {
|
2019-04-13 15:03:55 +02:00
|
|
|
if(this.config.timeFormat === "absolute" && !this.config.nextDaysRelative) {
|
2018-08-05 19:47:27 +03:00
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.dateFormat));
|
|
|
|
} else {
|
|
|
|
// Otherwise just say 'Today/Tomorrow at such-n-such time'
|
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").calendar());
|
|
|
|
}
|
2018-05-09 22:32:15 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Check to see if the user displays absolute or relative dates with their events
|
2018-06-11 23:09:00 +02:00
|
|
|
* Also check to see if an event is happening within an 'urgency' time frameElement
|
|
|
|
* For example, if the user set an .urgency of 7 days, those events that fall within that
|
|
|
|
* time frame will be displayed with 'in xxx' time format or moment.fromNow()
|
|
|
|
*
|
|
|
|
* Note: this needs to be put in its own function, as the whole thing repeats again verbatim
|
|
|
|
*/
|
2018-05-09 22:32:15 -04:00
|
|
|
if (this.config.timeFormat === "absolute") {
|
|
|
|
if ((this.config.urgency > 1) && (event.startDate - now < (this.config.urgency * oneDay))) {
|
|
|
|
// This event falls within the config.urgency period that the user has set
|
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
|
|
|
} else {
|
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.dateFormat));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
timeWrapper.innerHTML = this.capFirst(
|
|
|
|
this.translate("RUNNING", {
|
|
|
|
fallback: this.translate("RUNNING") + " {timeUntilEnd}",
|
|
|
|
timeUntilEnd: moment(event.endDate, "x").fromNow(true)
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2018-08-28 17:35:53 +02:00
|
|
|
if (this.config.showEnd) {
|
|
|
|
timeWrapper.innerHTML += "-";
|
|
|
|
timeWrapper.innerHTML += this.capFirst(moment(event.endDate, "x").format(this.config.dateEndFormat));
|
|
|
|
|
|
|
|
}
|
2016-04-15 13:13:06 +02:00
|
|
|
}
|
2018-05-09 22:32:15 -04:00
|
|
|
//timeWrapper.innerHTML += ' - '+ moment(event.startDate,'x').format('lll');
|
|
|
|
//console.log(event);
|
2018-10-04 02:07:08 +02:00
|
|
|
var timeClass = this.timeClassForUrl(event.url);
|
|
|
|
timeWrapper.className = "time light " + timeClass;
|
2018-05-09 22:32:15 -04:00
|
|
|
eventWrapper.appendChild(timeWrapper);
|
2016-04-15 12:50:34 +02:00
|
|
|
}
|
2016-03-31 11:05:32 +02:00
|
|
|
|
|
|
|
wrapper.appendChild(eventWrapper);
|
|
|
|
|
|
|
|
// Create fade effect.
|
2018-11-21 09:32:56 +01:00
|
|
|
if (e >= startFade) {
|
|
|
|
currentFadeStep = e - startFade;
|
|
|
|
eventWrapper.style.opacity = 1 - (1 / fadeSteps * currentFadeStep);
|
2016-03-31 11:05:32 +02:00
|
|
|
}
|
2019-04-08 21:49:19 +02:00
|
|
|
|
|
|
|
if (this.config.showLocation) {
|
|
|
|
if (event.location !== false) {
|
|
|
|
var locationRow = document.createElement("tr");
|
|
|
|
locationRow.className = "normal xsmall light";
|
|
|
|
|
|
|
|
if (this.config.displaySymbol) {
|
|
|
|
var symbolCell = document.createElement("td");
|
|
|
|
locationRow.appendChild(symbolCell);
|
|
|
|
}
|
|
|
|
|
|
|
|
var descCell = document.createElement("td");
|
|
|
|
descCell.className = "location";
|
|
|
|
descCell.colSpan = "2";
|
|
|
|
descCell.innerHTML = event.location;
|
|
|
|
locationRow.appendChild(descCell);
|
|
|
|
|
|
|
|
wrapper.appendChild(locationRow);
|
|
|
|
|
|
|
|
if (e >= startFade) {
|
|
|
|
currentFadeStep = e - startFade;
|
|
|
|
locationRow.style.opacity = 1 - (1 / fadeSteps * currentFadeStep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 11:05:32 +02:00
|
|
|
}
|
2018-11-21 12:10:39 +01:00
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
return wrapper;
|
|
|
|
},
|
|
|
|
|
2017-07-31 22:09:08 +02:00
|
|
|
/**
|
2018-06-11 23:09:00 +02:00
|
|
|
* This function accepts a number (either 12 or 24) and returns a moment.js LocaleSpecification with the
|
|
|
|
* corresponding timeformat to be used in the calendar display. If no number is given (or otherwise invalid input)
|
|
|
|
* it will a localeSpecification object with the system locale time format.
|
|
|
|
*
|
|
|
|
* @param {number} timeFormat Specifies either 12 or 24 hour time format
|
|
|
|
* @returns {moment.LocaleSpecification}
|
|
|
|
*/
|
|
|
|
getLocaleSpecification: function(timeFormat) {
|
2017-07-31 22:09:08 +02:00
|
|
|
switch (timeFormat) {
|
|
|
|
case 12: {
|
2018-06-11 23:09:00 +02:00
|
|
|
return { longDateFormat: {LT: "h:mm A"} };
|
2017-07-31 22:09:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 24: {
|
2018-06-11 23:09:00 +02:00
|
|
|
return { longDateFormat: {LT: "HH:mm"} };
|
2017-07-31 22:09:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2018-06-11 23:09:00 +02:00
|
|
|
return { longDateFormat: {LT: moment.localeData().longDateFormat("LT")} };
|
2017-07-31 22:09:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
/* hasCalendarURL(url)
|
2018-06-11 23:09:00 +02:00
|
|
|
* Check if this config contains the calendar url.
|
|
|
|
*
|
|
|
|
* argument url string - Url to look for.
|
|
|
|
*
|
|
|
|
* return bool - Has calendar url
|
|
|
|
*/
|
2016-10-14 15:23:03 +02:00
|
|
|
hasCalendarURL: function (url) {
|
2016-03-31 11:05:32 +02:00
|
|
|
for (var c in this.config.calendars) {
|
|
|
|
var calendar = this.config.calendars[c];
|
|
|
|
if (calendar.url === url) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* createEventList()
|
2018-06-11 23:09:00 +02:00
|
|
|
* Creates the sorted list of all events.
|
|
|
|
*
|
|
|
|
* return array - Array with events.
|
|
|
|
*/
|
2016-10-14 15:23:03 +02:00
|
|
|
createEventList: function () {
|
2016-03-31 11:05:32 +02:00
|
|
|
var events = [];
|
2016-04-05 14:35:11 -04:00
|
|
|
var today = moment().startOf("day");
|
2018-04-08 14:57:28 +03:00
|
|
|
var now = new Date();
|
2019-04-10 10:31:55 +02:00
|
|
|
var future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
|
2016-03-31 11:05:32 +02:00
|
|
|
for (var c in this.calendarData) {
|
|
|
|
var calendar = this.calendarData[c];
|
|
|
|
for (var e in calendar) {
|
2019-04-10 10:31:55 +02:00
|
|
|
var event = JSON.parse(JSON.stringify(calendar[e])); // clone object
|
2019-04-01 15:39:25 -04:00
|
|
|
if(event.endDate < now) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-06-11 23:09:00 +02:00
|
|
|
if(this.config.hidePrivate) {
|
|
|
|
if(event.class === "PRIVATE") {
|
2020-04-20 22:16:23 +02:00
|
|
|
// do not add the current event, skip it
|
|
|
|
continue;
|
2018-04-08 14:57:28 +03:00
|
|
|
}
|
|
|
|
}
|
2018-06-11 23:09:00 +02:00
|
|
|
if(this.config.hideOngoing) {
|
|
|
|
if(event.startDate < now) {
|
2018-04-08 14:57:28 +03:00
|
|
|
continue;
|
2016-11-30 21:09:57 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-11 23:09:00 +02:00
|
|
|
if(this.listContainsEvent(events,event)){
|
2018-05-09 22:32:15 -04:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-31 11:05:32 +02:00
|
|
|
event.url = c;
|
2016-04-05 11:20:47 +02:00
|
|
|
event.today = event.startDate >= today && event.startDate < (today + 24 * 60 * 60 * 1000);
|
2019-02-18 21:11:24 +01:00
|
|
|
|
|
|
|
/* if sliceMultiDayEvents is set to true, multiday events (events exceeding at least one midnight) are sliced into days,
|
|
|
|
* otherwise, esp. in dateheaders mode it is not clear how long these events are.
|
|
|
|
*/
|
2019-05-14 09:53:34 -05:00
|
|
|
var maxCount = Math.ceil(((event.endDate - 1) - moment(event.startDate, "x").endOf("day").format("x"))/(1000*60*60*24)) + 1;
|
|
|
|
if (this.config.sliceMultiDayEvents && maxCount > 1) {
|
2019-04-10 10:31:55 +02:00
|
|
|
var splitEvents = [];
|
|
|
|
var midnight = moment(event.startDate, "x").clone().startOf("day").add(1, "day").format("x");
|
2019-02-18 21:11:24 +01:00
|
|
|
var count = 1;
|
2019-04-10 10:31:55 +02:00
|
|
|
while (event.endDate > midnight) {
|
2019-06-05 10:23:58 +02:00
|
|
|
var thisEvent = JSON.parse(JSON.stringify(event)); // clone object
|
2019-04-10 10:31:55 +02:00
|
|
|
thisEvent.today = thisEvent.startDate >= today && thisEvent.startDate < (today + 24 * 60 * 60 * 1000);
|
|
|
|
thisEvent.endDate = midnight;
|
|
|
|
thisEvent.title += " (" + count + "/" + maxCount + ")";
|
|
|
|
splitEvents.push(thisEvent);
|
|
|
|
|
|
|
|
event.startDate = midnight;
|
|
|
|
count += 1;
|
|
|
|
midnight = moment(midnight, "x").add(1, "day").format("x"); // next day
|
|
|
|
}
|
|
|
|
// Last day
|
|
|
|
event.title += " ("+count+"/"+maxCount+")";
|
|
|
|
splitEvents.push(event);
|
|
|
|
|
|
|
|
for (event of splitEvents) {
|
|
|
|
if ((event.endDate > now) && (event.endDate <= future)) {
|
|
|
|
events.push(event);
|
|
|
|
}
|
|
|
|
}
|
2019-02-18 21:11:24 +01:00
|
|
|
} else {
|
|
|
|
events.push(event);
|
|
|
|
}
|
2016-03-31 11:05:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:23:03 +02:00
|
|
|
events.sort(function (a, b) {
|
2016-03-31 11:05:32 +02:00
|
|
|
return a.startDate - b.startDate;
|
|
|
|
});
|
2017-10-01 21:36:43 +02:00
|
|
|
return events.slice(0, this.config.maximumEntries);
|
2016-03-31 11:05:32 +02:00
|
|
|
},
|
|
|
|
|
2018-06-11 23:09:00 +02:00
|
|
|
listContainsEvent: function(eventList, event){
|
2018-08-16 11:45:34 -04:00
|
|
|
for(var evt of eventList){
|
2018-06-11 23:09:00 +02:00
|
|
|
if(evt.title === event.title && parseInt(evt.startDate) === parseInt(event.startDate)){
|
2018-05-09 22:32:15 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
/* createEventList(url)
|
2018-06-11 23:09:00 +02:00
|
|
|
* Requests node helper to add calendar url.
|
|
|
|
*
|
|
|
|
* argument url string - Url to add.
|
|
|
|
*/
|
2017-03-07 00:12:43 +01:00
|
|
|
addCalendar: function (url, auth, calendarConfig) {
|
2016-04-05 14:35:11 -04:00
|
|
|
this.sendSocketNotification("ADD_CALENDAR", {
|
2016-03-31 11:05:32 +02:00
|
|
|
url: url,
|
2017-07-27 17:59:23 +02:00
|
|
|
excludedEvents: calendarConfig.excludedEvents || this.config.excludedEvents,
|
2017-01-30 16:26:42 -06:00
|
|
|
maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries,
|
|
|
|
maximumNumberOfDays: calendarConfig.maximumNumberOfDays || this.config.maximumNumberOfDays,
|
2016-09-08 17:36:30 +02:00
|
|
|
fetchInterval: this.config.fetchInterval,
|
2018-10-04 02:07:08 +02:00
|
|
|
symbolClass: calendarConfig.symbolClass,
|
|
|
|
titleClass: calendarConfig.titleClass,
|
|
|
|
timeClass: calendarConfig.timeClass,
|
2019-04-01 15:39:25 -04:00
|
|
|
auth: auth,
|
2019-04-10 16:50:18 -04:00
|
|
|
broadcastPastEvents: calendarConfig.broadcastPastEvents || this.config.broadcastPastEvents,
|
2016-03-31 11:05:32 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-04 02:07:08 +02:00
|
|
|
/**
|
|
|
|
* symbolsForUrl(url)
|
2018-06-11 23:09:00 +02:00
|
|
|
* Retrieves the symbols for a specific url.
|
|
|
|
*
|
|
|
|
* argument url string - Url to look for.
|
|
|
|
*
|
|
|
|
* return string/array - The Symbols
|
|
|
|
*/
|
2017-03-16 16:57:55 +01:00
|
|
|
symbolsForUrl: function (url) {
|
2017-02-08 00:05:28 +01:00
|
|
|
return this.getCalendarProperty(url, "symbol", this.config.defaultSymbol);
|
2016-03-31 11:05:32 +02:00
|
|
|
},
|
2017-01-28 18:21:02 +01:00
|
|
|
|
2018-10-04 02:07:08 +02:00
|
|
|
/**
|
|
|
|
* symbolClassForUrl(url)
|
|
|
|
* Retrieves the symbolClass for a specific url.
|
|
|
|
*
|
|
|
|
* @param url string - Url to look for.
|
|
|
|
*
|
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
symbolClassForUrl: function (url) {
|
|
|
|
return this.getCalendarProperty(url, "symbolClass", "");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* titleClassForUrl(url)
|
|
|
|
* Retrieves the titleClass for a specific url.
|
|
|
|
*
|
|
|
|
* @param url string - Url to look for.
|
|
|
|
*
|
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
titleClassForUrl: function (url) {
|
|
|
|
return this.getCalendarProperty(url, "titleClass", "");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* timeClassForUrl(url)
|
|
|
|
* Retrieves the timeClass for a specific url.
|
|
|
|
*
|
|
|
|
* @param url string - Url to look for.
|
|
|
|
*
|
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
timeClassForUrl: function (url) {
|
|
|
|
return this.getCalendarProperty(url, "timeClass", "");
|
|
|
|
},
|
|
|
|
|
2019-03-26 09:02:19 -04:00
|
|
|
/* calendarNameForUrl(url)
|
|
|
|
* Retrieves the calendar name for a specific url.
|
|
|
|
*
|
|
|
|
* argument url string - Url to look for.
|
|
|
|
*
|
|
|
|
* return string - The name of the calendar
|
|
|
|
*/
|
|
|
|
calendarNameForUrl: function (url) {
|
|
|
|
return this.getCalendarProperty(url, "name", "");
|
|
|
|
},
|
|
|
|
|
2017-01-29 00:59:38 +01:00
|
|
|
/* colorForUrl(url)
|
2018-06-11 23:09:00 +02:00
|
|
|
* Retrieves the color for a specific url.
|
|
|
|
*
|
|
|
|
* argument url string - Url to look for.
|
|
|
|
*
|
|
|
|
* return string - The Color
|
|
|
|
*/
|
2017-01-28 18:21:02 +01:00
|
|
|
colorForUrl: function (url) {
|
2017-02-08 00:05:28 +01:00
|
|
|
return this.getCalendarProperty(url, "color", "#fff");
|
2017-01-28 18:21:02 +01:00
|
|
|
},
|
2017-02-07 23:51:13 +01:00
|
|
|
|
2016-04-26 22:34:12 +02:00
|
|
|
/* countTitleForUrl(url)
|
2018-06-11 23:09:00 +02:00
|
|
|
* Retrieves the name for a specific url.
|
|
|
|
*
|
|
|
|
* argument url string - Url to look for.
|
|
|
|
*
|
|
|
|
* return string - The Symbol
|
|
|
|
*/
|
2016-10-14 15:23:03 +02:00
|
|
|
countTitleForUrl: function (url) {
|
2017-02-07 23:51:13 +01:00
|
|
|
return this.getCalendarProperty(url, "repeatingCountTitle", this.config.defaultRepeatingCountTitle);
|
|
|
|
},
|
2016-04-26 22:34:12 +02:00
|
|
|
|
2017-02-07 23:51:13 +01:00
|
|
|
/* getCalendarProperty(url, property, defaultValue)
|
2018-06-11 23:09:00 +02:00
|
|
|
* Helper method to retrieve the property for a specific url.
|
|
|
|
*
|
|
|
|
* argument url string - Url to look for.
|
|
|
|
* argument property string - Property to look for.
|
|
|
|
* argument defaultValue string - Value if property is not found.
|
|
|
|
*
|
|
|
|
* return string - The Property
|
|
|
|
*/
|
2017-02-07 23:51:13 +01:00
|
|
|
getCalendarProperty: function (url, property, defaultValue) {
|
2017-02-08 00:05:28 +01:00
|
|
|
for (var c in this.config.calendars) {
|
|
|
|
var calendar = this.config.calendars[c];
|
2017-03-16 16:57:55 +01:00
|
|
|
if (calendar.url === url && calendar.hasOwnProperty(property)) {
|
2017-02-08 00:05:28 +01:00
|
|
|
return calendar[property];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultValue;
|
2016-04-26 22:34:12 +02:00
|
|
|
},
|
2016-03-31 11:05:32 +02:00
|
|
|
|
2017-07-29 16:02:53 +02:00
|
|
|
/**
|
2018-06-11 23:09:00 +02:00
|
|
|
* Shortens a string if it's longer than maxLength and add a ellipsis to the end
|
|
|
|
*
|
|
|
|
* @param {string} string Text string to shorten
|
|
|
|
* @param {number} maxLength The max length of the string
|
|
|
|
* @param {boolean} wrapEvents Wrap the text after the line has reached maxLength
|
2019-01-16 22:51:44 -08:00
|
|
|
* @param {number} maxTitleLines The max number of vertical lines before cutting event title
|
2018-06-11 23:09:00 +02:00
|
|
|
* @returns {string} The shortened string
|
|
|
|
*/
|
2019-01-16 22:51:44 -08:00
|
|
|
shorten: function (string, maxLength, wrapEvents, maxTitleLines) {
|
2017-07-29 16:02:53 +02:00
|
|
|
if (typeof string !== "string") {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wrapEvents === true) {
|
2017-04-02 15:06:58 -05:00
|
|
|
var temp = "";
|
|
|
|
var currentLine = "";
|
|
|
|
var words = string.split(" ");
|
2019-01-16 22:51:44 -08:00
|
|
|
var line = 0;
|
2017-04-02 15:06:58 -05:00
|
|
|
|
|
|
|
for (var i = 0; i < words.length; i++) {
|
|
|
|
var word = words[i];
|
2017-07-29 16:02:53 +02:00
|
|
|
if (currentLine.length + word.length < (typeof maxLength === "number" ? maxLength : 25) - 1) { // max - 1 to account for a space
|
2017-04-02 15:06:58 -05:00
|
|
|
currentLine += (word + " ");
|
|
|
|
} else {
|
2019-01-16 22:51:44 -08:00
|
|
|
line++;
|
|
|
|
if (line > maxTitleLines - 1) {
|
2019-01-21 00:47:53 -08:00
|
|
|
if (i < words.length) {
|
|
|
|
currentLine += "…";
|
|
|
|
}
|
2019-01-16 22:51:44 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-02 15:06:58 -05:00
|
|
|
if (currentLine.length > 0) {
|
|
|
|
temp += (currentLine + "<br>" + word + " ");
|
|
|
|
} else {
|
|
|
|
temp += (word + "<br>");
|
|
|
|
}
|
|
|
|
currentLine = "";
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 11:05:32 +02:00
|
|
|
|
2017-07-29 16:02:53 +02:00
|
|
|
return (temp + currentLine).trim();
|
2017-04-02 15:06:58 -05:00
|
|
|
} else {
|
2017-07-29 16:02:53 +02:00
|
|
|
if (maxLength && typeof maxLength === "number" && string.length > maxLength) {
|
|
|
|
return string.trim().slice(0, maxLength) + "…";
|
2017-04-02 15:06:58 -05:00
|
|
|
} else {
|
2017-07-29 16:02:53 +02:00
|
|
|
return string.trim();
|
2017-04-02 15:06:58 -05:00
|
|
|
}
|
|
|
|
}
|
2016-03-31 11:05:32 +02:00
|
|
|
},
|
|
|
|
|
2016-09-03 00:39:46 +02:00
|
|
|
/* capFirst(string)
|
2018-06-11 23:09:00 +02:00
|
|
|
* Capitalize the first letter of a string
|
|
|
|
* Return capitalized string
|
|
|
|
*/
|
2016-10-14 15:23:03 +02:00
|
|
|
capFirst: function (string) {
|
2016-09-03 00:39:46 +02:00
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
|
},
|
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
/* titleTransform(title)
|
2018-06-11 23:09:00 +02:00
|
|
|
* Transforms the title of an event for usage.
|
|
|
|
* Replaces parts of the text as defined in config.titleReplace.
|
|
|
|
* Shortens title based on config.maxTitleLength and config.wrapEvents
|
|
|
|
*
|
|
|
|
* argument title string - The title to transform.
|
|
|
|
*
|
|
|
|
* return string - The transformed title.
|
|
|
|
*/
|
2016-10-14 15:23:03 +02:00
|
|
|
titleTransform: function (title) {
|
2016-03-31 11:05:32 +02:00
|
|
|
for (var needle in this.config.titleReplace) {
|
|
|
|
var replacement = this.config.titleReplace[needle];
|
2017-01-16 02:49:08 +01:00
|
|
|
|
|
|
|
var regParts = needle.match(/^\/(.+)\/([gim]*)$/);
|
|
|
|
if (regParts) {
|
2020-04-20 22:16:23 +02:00
|
|
|
// the parsed pattern is a regexp.
|
|
|
|
needle = new RegExp(regParts[1], regParts[2]);
|
2017-01-16 02:49:08 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
title = title.replace(needle, replacement);
|
|
|
|
}
|
|
|
|
|
2019-01-16 22:51:44 -08:00
|
|
|
title = this.shorten(title, this.config.maxTitleLength, this.config.wrapEvents, this.config.maxTitleLines);
|
2016-03-31 11:05:32 +02:00
|
|
|
return title;
|
2016-10-14 15:23:03 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/* broadcastEvents()
|
2018-06-11 23:09:00 +02:00
|
|
|
* Broadcasts the events to all other modules for reuse.
|
|
|
|
* The all events available in one array, sorted on startdate.
|
|
|
|
*/
|
2016-10-14 15:23:03 +02:00
|
|
|
broadcastEvents: function () {
|
|
|
|
var eventList = [];
|
2017-06-11 11:53:55 +02:00
|
|
|
for (var url in this.calendarData) {
|
2016-10-14 15:23:03 +02:00
|
|
|
var calendar = this.calendarData[url];
|
2017-06-11 11:53:55 +02:00
|
|
|
for (var e in calendar) {
|
2016-10-14 15:23:03 +02:00
|
|
|
var event = cloneObject(calendar[e]);
|
2017-07-06 11:57:16 +02:00
|
|
|
event.symbol = this.symbolsForUrl(url);
|
2019-03-26 09:02:19 -04:00
|
|
|
event.calendarName = this.calendarNameForUrl(url);
|
2017-07-06 11:57:16 +02:00
|
|
|
event.color = this.colorForUrl(url);
|
2016-10-14 15:23:03 +02:00
|
|
|
delete event.url;
|
|
|
|
eventList.push(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-11 23:09:00 +02:00
|
|
|
eventList.sort(function(a,b) {
|
2016-10-14 15:23:03 +02:00
|
|
|
return a.startDate - b.startDate;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.sendNotification("CALENDAR_EVENTS", eventList);
|
|
|
|
|
2016-03-31 11:05:32 +02:00
|
|
|
}
|
2016-04-03 19:52:13 +02:00
|
|
|
});
|