X-Git-Url: https://code.delx.au/comingnext/blobdiff_plain/b4c29ae7d590d094104243f85e8e95a1dc49049f..5f9fab5de1f21312fb80ee1c64f02343fb73cad1:/comingNext/index.html
diff --git a/comingNext/index.html b/comingNext/index.html
index 0b8687c..145ac24 100644
--- a/comingNext/index.html
+++ b/comingNext/index.html
@@ -7,23 +7,23 @@
@@ -57,6 +57,7 @@ var config = {
hideWidgetOnCalendarOpen: { Type: 'Bool', Default: false, Value: false,},
showCalendarIndicator: { Type: 'Bool', Default: true, Value: true,},
excludedCalendars: { Type: 'Array', Default: [], Value: [],},
+ enableLogging: { Type: 'Bool', Default: false, Value: false,},
cssStyle_background: { Type: 'String', Default: 'color:#ffffff; background-color:#000000', Value: 'color:#ffffff; background-color:#000000',},
cssStyle_backgroundFullscreen: { Type: 'String', Default: 'color:#ffffff; background-color:#000000', Value: 'color:#ffffff; background-color:#000000',},
cssStyle_weekDay: { Type: 'String', Default: '', Value: '',},
@@ -98,8 +99,11 @@ var calendarList = [];
var calendarColors = [];
var updateTimer = null;
var screenRotationTimer = null;
-var lastUpdateTime = now;
+var lastUpdateTime = now; // last time we updated the display
+var lastReloadTime = null; // last time we fetched calendar data
+var reloadInterval = 6 * 60 * 60 * 1000; // = 6 hours; time interval for reloading calendar data
var errorOccured = false;
+var entryLists = null; // stores all fetched calendar entries until data is refreshed
// vars for daylight saving time
var summertime = false; // true, if current date is in summer, false if in winter
@@ -290,7 +294,7 @@ function collectLocales()
month = tmp;
}
- console.info(entry.StartTime + ' -> ' + month + ' ' + counter);
+ log(entry.StartTime + ' -> ' + month + ' ' + counter);
ids[counter] = entry.id;
months_translated[month] = counter + 1;
counter++;
@@ -299,7 +303,7 @@ function collectLocales()
error(e + ', line ' + e.line);
return;
}
- console.info(ids);
+ log(ids);
try {
var criteria = new Object();
criteria.Type = "CalendarEntry";
@@ -363,13 +367,14 @@ function cancelNotification()
function callback(transId, eventCode, result)
{
- console.info("callback(): panelNum: %d transId: %d eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);
+ log("callback(): panelNum: %d transId: %d eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);
+ lastReloadTime = null; // force calendar data reload on next update
updateData();
}
function settingsCallback(transId, eventCode, result)
{
- console.info("settingsCallback(): panelNum: %d transId: %d eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);
+ log("settingsCallback(): panelNum: %d transId: %d eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);
loadSettings();
}
@@ -437,11 +442,11 @@ function parseDate(dateString)
// work around bug in Nokias calendar api resulting in dates within a different DST to be off by 1 hour
if (summertime && !dateSummerTime) {
result = new Date(result.getTime() - 1000 * 60 * 60 * config['daylightSavingOffset'].Value); // -1 hour
- console.info('parseDate(): fixing time -1h: ' + result);
+ log('parseDate(): fixing time -1h: ' + result);
}
else if (!summertime && dateSummerTime) {
result = new Date(result.getTime() + 1000 * 60 * 60 * config['daylightSavingOffset'].Value); // +1 hour
- console.info('parseDate(): fixing time +1h: ' + result);
+ log('parseDate(): fixing time +1h: ' + result);
}
}
@@ -518,7 +523,7 @@ function formatTime(date)
function updateData()
{
- console.info('updateData()');
+ log('updateData()');
if (errorOccured) {
return;
}
@@ -530,65 +535,72 @@ function updateData()
updateCalendarColors();
cancelNotification();
requestNotification();
+ lastReloadTime = null; // force calendar data reload on this update
}
-
- try {
- // meetings have time
- // note: anniveraries have a start time of 12:00am. So since we want to include them, we have to query the whole day and check if events have passed later
- now = new Date();
- summertime = isSummertime(now); // cache summer time info for today
- var meetingList = [];
- for(var i=0; i < calendarList.length; i++) {
- // ignore excluded calendars
- if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1)
- continue;
- var meetingListFiltering = {
- Type:'CalendarEntry',
- Filter:{
- CalendarName: calendarList[i],
- StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)),
- EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(), 0, 0, 0))
- }
- }
- var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering);
- if (meetingResult.ErrorCode != 0)
- throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage);
- var list = meetingResult.ReturnValue;
- meetingList = meetingList.concat(listToArray(list, calendarList[i]));
- }
- console.info("updateData(): meetingList.sort()");
- meetingList.sort(sortCalendarEntries);
- // todos don't, they start on 00:00 hrs., but should be visible anyway
- // this will generate a list of passed todos. We have to check if they have been marked as "done" yet
- if (config['includeTodos'].Value) {
- var todayTodoList = [];
+ now = new Date();
+
+ // only reload calendar data every 6 hours, visual updates occure more often
+ if (!lastReloadTime || now.getTime() - lastReloadTime.getTime() > reloadInterval) {
+ log('updateData(): reloading calendar data');
+ try {
+ // meetings have time
+ // note: anniveraries have a start time of 12:00am. So since we want to include them, we have to query the whole day and check if events have passed later
+ summertime = isSummertime(now); // cache summer time info for today
+ var meetingList = [];
for(var i=0; i < calendarList.length; i++) {
// ignore excluded calendars
if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1)
continue;
- var todayTodoListFiltering = {
+ var meetingListFiltering = {
Type:'CalendarEntry',
Filter:{
CalendarName: calendarList[i],
- Type: 'ToDo',
- StartRange: (new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)),
- EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1))
+ StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)),
+ EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(), 0, 0, 0))
+ }
+ }
+ var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering);
+ if (meetingResult.ErrorCode != 0)
+ throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage);
+ var list = meetingResult.ReturnValue;
+ meetingList = meetingList.concat(listToArray(list, calendarList[i]));
+ }
+ log("updateData(): meetingList.sort()");
+ meetingList.sort(sortCalendarEntries);
+
+ // todos don't, they start on 00:00 hrs., but should be visible anyway
+ // this will generate a list of passed todos. We have to check if they have been marked as "done" yet
+ if (config['includeTodos'].Value) {
+ var todayTodoList = [];
+ for(var i=0; i < calendarList.length; i++) {
+ // ignore excluded calendars
+ if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1)
+ continue;
+ var todayTodoListFiltering = {
+ Type:'CalendarEntry',
+ Filter:{
+ CalendarName: calendarList[i],
+ Type: 'ToDo',
+ StartRange: (new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)),
+ EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1))
+ }
}
+ var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);
+ var list = todayTodoResult.ReturnValue;
+ todayTodoList = todayTodoList.concat(listToArray(list, calendarList[i]));
}
- var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);
- var list = todayTodoResult.ReturnValue;
- todayTodoList = todayTodoList.concat(listToArray(list, calendarList[i]));
+ log("updateData(): todayTodoList.sort()");
+ todayTodoList.sort(sortCalendarEntries);
+ entryLists = [todayTodoList, meetingList];
+ } else {
+ entryLists = [meetingList];
}
- console.info("updateData(): todayTodoList.sort()");
- todayTodoList.sort(sortCalendarEntries);
- var entryLists = [todayTodoList, meetingList];
- } else {
- var entryLists = [meetingList];
+ lastReloadTime = new Date();
+ } catch(e) {
+ error('loading Calendar items list:' + e + ', line ' + e.line);
+ return;
}
- } catch(e) {
- error('loading Calendar items list:' + e + ', line ' + e.line);
- return;
}
try {
@@ -621,16 +633,18 @@ function updateData()
else
max = 30; // we can display a lot more events in fullscreen mode
- var listinfo = "";
- for (var i=0; i < entryLists.length; i++) {
- listinfo = listinfo + " " + entryLists[i].length;
- var entrieslist = "";
- for (var j=0; j < entryLists[i].length; j++) {
- entrieslist += entryLists[i][j].Summary + ", ";
+ if (config['enableLogging'].Value) {
+ var listinfo = "";
+ for (var i=0; i < entryLists.length; i++) {
+ listinfo = listinfo + " " + entryLists[i].length;
+ var entrieslist = "";
+ for (var j=0; j < entryLists[i].length; j++) {
+ entrieslist += entryLists[i][j].Summary + ", ";
+ }
+ log("updateData(): entrieslist: " + entrieslist);
}
- console.info("updateData(): entrieslist: " + entrieslist);
+ log("updateData(): inner loop, " + entryLists.length + " lists, [" + listinfo + "] entries");
}
- console.info("updateData(): inner loop, " + entryLists.length + " lists, [" + listinfo + "] entries");
// the first outer loop iteration is for passed ToDos, the second loop is for all upcomming events (may also include ToDos)
for (var i=0; counter < max && i < entryLists.length; i++) {
@@ -645,18 +659,18 @@ function updateData()
entryInfo += entryFields[k] + "=" + entry[entryFields[k]] + ",";
}
}
- console.info(entryInfo);
+ log(entryInfo);
// we don't want ToDos when includeTodos == false or when they are completed
if (entry.Type == 'ToDo' && (entry.Status == "TodoCompleted" || !config['includeTodos'].Value)) {
- console.info('skipping ' + entry.id );
+ log('skipping ' + entry.id );
counter--;
continue;
}
// make sure that we don't include an event twice (useful for ToDos that might come up twice)
if (eventIds[entry.id] == 1 && entry.Type == 'ToDo') {
- console.info('skipped (already included) ' + entry.id);
+ log('skipped (already included) ' + entry.id);
counter--;
continue;
} else
@@ -679,15 +693,15 @@ function updateData()
// Convert date/time string to Date object
var date = parseDate(entryDate);
- console.info('date: ' + date);
+ log('date: ' + date);
var endDate = ((entryEndTime == null) ? null : parseDate(entryEndTime));
- console.info('endDate: ' + endDate);
+ log('endDate: ' + endDate);
// check if meeting event has already passed
if (entry.Type == 'Meeting') {
var compareTime = ((endDate == null) ? date.getTime() : endDate.getTime());
if (now.getTime() > compareTime) {
- console.info('skipping Meeting (already passed) ' + entry.id);
+ log('skipping Meeting (already passed) ' + entry.id);
counter--;
eventIds[entry.id] = 0;
continue;
@@ -698,7 +712,7 @@ function updateData()
if (entry.Type == 'Anniversary') {
var tmp = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0,0,0);
if (date.getTime() < tmp.getTime()) {
- console.info('skipping Anniversary (already passed) ' + entry.id);
+ log('skipping Anniversary (already passed) ' + entry.id);
counter--;
eventIds[entry.id] = 0;
continue;
@@ -708,9 +722,9 @@ function updateData()
// fix DayEvents end time. End times are off by 1 Second. It's possible that the event has already passed
if (entry.Type == 'DayEvent' && endDate != null) {
endDate.setMinutes(endDate.getMinutes() - 1);
- console.info('fixing DayEvent endDate: ' + endDate);
+ log('fixing DayEvent endDate: ' + endDate);
if (now.getTime() > endDate.getTime()) {
- console.info('event already passed ' + entry.id);
+ log('event already passed ' + entry.id);
counter--;
eventIds[entry.id] = 0;
continue;
@@ -722,13 +736,13 @@ function updateData()
// check if we are between start and endtime
if ((date.getTime() < now.getTime()) && (now.getTime() < endDate.getTime())) {
date = now; // change appointment date/time to now
- console.info('event is currently taking place: ' + date);
+ log('event is currently taking place: ' + date);
}
}
// skip events for the first panel in case this is the second one and we're not in fullscreen mode
if (mode == 0 && panelNum > 0 && counter < panelNum * config['eventsPerWidget'].Value + 1) {
- console.info('skipping (already in first widget) ' + entry.id);
+ log('skipping (already in first widget) ' + entry.id);
continue;
}
@@ -824,7 +838,7 @@ function updateScreen()
var time = new Date();
if (time.getTime() - lastUpdateTime.getTime() > config['updateDataInterval'].Value * 60 * 1000) {
- console.info('updateScreen(): force updateData() because last update was too long ago (' + (time.getTime() - lastUpdateTime.getTime()) / 1000 + 's)');
+ log('updateScreen(): force updateData() because last update was too long ago (' + (time.getTime() - lastUpdateTime.getTime()) / 1000 + 's)');
clearUpdateTimer();
updateData();
setUpdateTimer(); // reinitialize update timer
@@ -845,7 +859,7 @@ function launchCalendar()
function init()
{
- console.info('New widget instance starting up...');
+ log('New widget instance starting up...');
try {
// call calendar service
@@ -872,12 +886,12 @@ function init()
else {
mode = 1;
}
- console.info("init(): updateScreen()");
+ log("init(): updateScreen()");
updateScreen();
if (config['useBackgroundImage'].Value)
// check for screen rotation every 1 secs
screenRotationTimer = window.setInterval('updateScreen()', 1000 * 1);
- console.info("init(): finished...");
+ log("init(): finished...");
}
function setUpdateTimer()
@@ -892,7 +906,7 @@ function clearUpdateTimer()
function updateTimerCallback()
{
- console.info("updateTimerCallback()");
+ log("updateTimerCallback()");
updateData();
}
@@ -933,16 +947,13 @@ function showSettings()
config[key].Value = document.forms[0].elements["settings." + key].value;
else if (config[key].Type == 'Int') {
config[key].Value = parseInt(document.forms[0].elements["settings." + key].value);
- if (config[key].Value < 0 || isNaN(config[key].Value))
+ if (config[key].Value < 0)
config[key].Value = config[key].Default;
}
else if (config[key].Type == 'Bool')
config[key].Value = document.forms[0].elements["settings." + key].checked;
- else if (config[key].Type == 'UID') {
+ else if (config[key].Type == 'UID')
config[key].Value = parseInt(document.forms[0].elements["settings." + key].value);
- if (isNaN(config[key].Value))
- config[key].Value = config[key].Default;
- }
else if (config[key].Type == 'Enum') {
config[key].Value = document.forms[0].elements["settings." + key].value;
if (config[key].ValidValues.indexOf(config[key].Value) == -1)
@@ -1052,7 +1063,7 @@ function getSettingsCalEntryId()
var entry = list.getNext();
if (entry != undefined) {
settingsCalEntryId = entry.LocalId;
- console.info("settingsCalEntryId=" + settingsCalEntryId);
+ log("settingsCalEntryId=" + settingsCalEntryId);
}
else { // create settings item
var item = new Object();
@@ -1099,7 +1110,7 @@ function loadSettings()
}
var entry = result.ReturnValue.getNext();
if (entry != undefined) {
- console.info("Loading Settings...");
+ log("Loading Settings...");
// only reload settings if they chanced since the last reload
if (settingsCache != entry.Summary)
{
@@ -1110,23 +1121,17 @@ function loadSettings()
var pair = stringlist[i].split('=');
var key = pair[0];
var value = pair[1];
- console.info('stringlist: ' + key + '=\'' + value + '\'');
- if (config[key].Type == 'Int') {
+ log('stringlist: ' + key + '=\'' + value + '\'');
+ if (config[key].Type == 'Int')
config[key].Value = Number(value);
- if (isNaN(config[key].Value))
- config[key].Value = config[key].Default;
- }
else if (config[key].Type == 'String')
config[key].Value = value;
else if (config[key].Type == 'Bool')
config[key].Value = (value == 'true')
else if (config[key].Type == 'Enum')
config[key].Value = value;
- else if (config[key].Type == 'UID') {
+ else if (config[key].Type == 'UID')
config[key].Value = Number(value);
- if (isNaN(config[key].Value))
- config[key].Value = config[key].Default;
- }
else if (config[key].Type == 'Array') {
config[key].Value = value.split("^");
if (config[key].Value.length == 1 && config[key].Value[0] == "") {
@@ -1138,7 +1143,7 @@ function loadSettings()
updateCssClasses();
}
else {
- console.info("Settings already cached and did not change");
+ log("Settings already cached and did not change");
}
}
else {
@@ -1175,7 +1180,7 @@ function saveSettings()
criteria.Type = "CalendarEntry";
criteria.Item = item;
- console.info("Saving settings to calendar entry: " + item.Summary);
+ log("Saving settings to calendar entry: " + item.Summary);
try {
var result = calendarService.IDataSource.Add(criteria);
if (result.ErrorCode)
@@ -1184,6 +1189,7 @@ function saveSettings()
error("saveSettings: " + e + ', line ' + e.line);
}
+ lastReloadTime = null; // force calendar data reload on next update
clearUpdateTimer();
setUpdateTimer();
}
@@ -1232,7 +1238,7 @@ function updateFullscreen()
function showFullscreen()
{
- console.info("showFullscreen()");
+ log("showFullscreen()");
hideViews();
document.getElementById("fullscreenView").style.display = "block";
document.getElementById('body').className = "backgroundFullscreen";
@@ -1280,7 +1286,7 @@ function updateHomescreen()
function showHomescreen()
{
- console.info("showHomescreen()");
+ log("showHomescreen()");
hideViews();
document.getElementById("homescreenView").style.display = "block";
document.getElementById('body').className = "background";
@@ -1382,7 +1388,7 @@ function listCalendars()
while (( item = calendarListIterator.getNext()) != undefined ) {
calendars[count++] = item;
}
- console.info("Available Calendars: " + calendars.join(", "));
+ log("Available Calendars: " + calendars.join(", "));
return calendars;
} catch(e) {
error('listing calendars:' + e + ', line ' + e.line);
@@ -1409,14 +1415,14 @@ function listToArray(list, calendarName)
array.push(itemCopy);
txt += array[array.length - 1].Summary + ", ";
}
- console.info("listToArray(): " + txt);
+ log("listToArray(): " + txt);
return array;
}
function sortCalendarEntries(a, b)
{
var atime, btime;
- console.info("sortCalendarEntries(" + a.Summary + "," + b.Summary + ")");
+ log("sortCalendarEntries(" + a.Summary + "," + b.Summary + ")");
if (a.InstanceStartTime != null) {
atime = a.InstanceStartTime;
@@ -1511,13 +1517,19 @@ function updateCalendarColors()
var maxColors = 6;
calendarColors = [];
if (calendarList.length > maxColors) {
- console.info("updateCalendarColors(): Warning: more calendars than available indicator colors");
+ log("updateCalendarColors(): Warning: more calendars than available indicator colors");
}
for(var i=0; i < calendarList.length; i++) {
calendarColors[calendarList[i]] = (i % maxColors) + 1;
}
}
+function log(message) {
+ if (config['enableLogging'].Value) {
+ console.info(message);
+ }
+}
+