X-Git-Url: https://code.delx.au/comingnext/blobdiff_plain/4776048cf0d0fb60d5cf49e8591220c786a0266d..5f9fab5de1f21312fb80ee1c64f02343fb73cad1:/comingNext/index.html
diff --git a/comingNext/index.html b/comingNext/index.html
index fa571f5..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,6 +99,11 @@ var calendarList = [];
var calendarColors = [];
var updateTimer = null;
var screenRotationTimer = null;
+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
@@ -192,6 +198,9 @@ function error(message)
{
console.info('Error: ' + message);
document.getElementById("calendarList").innerHTML = 'Error: ' + message;
+ document.getElementById("fullscreenCalendarList").innerHTML = 'Error: ' + message;
+ errorOccured = true;
+ document.onclick = null;
}
function areDatesEqual(date1, date2)
@@ -285,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++;
@@ -294,7 +303,7 @@ function collectLocales()
error(e + ', line ' + e.line);
return;
}
- console.info(ids);
+ log(ids);
try {
var criteria = new Object();
criteria.Type = "CalendarEntry";
@@ -358,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();
}
@@ -432,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);
}
}
@@ -513,7 +523,10 @@ function formatTime(date)
function updateData()
{
- console.info('updateData()');
+ log('updateData()');
+ if (errorOccured) {
+ return;
+ }
// check if we got additional or less calendars since our last update
var newCalendarList = listCalendars();
@@ -522,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 {
@@ -613,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++) {
@@ -637,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
@@ -671,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;
@@ -690,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;
@@ -700,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;
@@ -714,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;
}
@@ -786,6 +808,8 @@ function updateData()
document.getElementById('fullscreenCalendarList').innerHTML = entriesHtml;
cacheEntriesHtml = entriesHtml;
}
+
+ lastUpdateTime = new Date();
} catch(e) {
error('displaying list:' + e + ', line ' + e.line);
return;
@@ -811,6 +835,14 @@ function updateScreen()
updateHomescreen();
else if (mode == 1)
updateFullscreen();
+
+ var time = new Date();
+ if (time.getTime() - lastUpdateTime.getTime() > config['updateDataInterval'].Value * 60 * 1000) {
+ log('updateScreen(): force updateData() because last update was too long ago (' + (time.getTime() - lastUpdateTime.getTime()) / 1000 + 's)');
+ clearUpdateTimer();
+ updateData();
+ setUpdateTimer(); // reinitialize update timer
+ }
}
function launchCalendar()
@@ -827,7 +859,7 @@ function launchCalendar()
function init()
{
- console.info('New widget instance starting up...');
+ log('New widget instance starting up...');
try {
// call calendar service
@@ -836,8 +868,8 @@ function init()
else
throw('device object does not exist');
} catch(e) {
- error('loading Calendar service: ' + e + ', line ' + e.line);
- return;
+ error('loading Calendar service: ' + e + ', line ' + e.line + '
' + getLocalizedText('menu.help') + '');
+ //return;
}
calendarList = listCalendars();
@@ -854,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()
@@ -874,7 +906,7 @@ function clearUpdateTimer()
function updateTimerCallback()
{
- console.info("updateTimerCallback()");
+ log("updateTimerCallback()");
updateData();
}
@@ -885,15 +917,18 @@ function createMenu()
var id = 0;
var menuSettings = new MenuItem(getLocalizedText('menu.settings'), id++);
var menuCallApp = new MenuItem(getLocalizedText('menu.openCalendarApp'), id++);
+ var menuHelp = new MenuItem(getLocalizedText('menu.help'), id++);
var menuUpdate = new MenuItem(getLocalizedText('menu.update'), id++);
var menuAbout = new MenuItem(getLocalizedText('menu.about'), id++);
menuSettings.onSelect = showSettings;
menuAbout.onSelect = showAbout;
menuCallApp.onSelect = launchCalendar;
menuUpdate.onSelect = showUpdate;
+ menuHelp.onSelect = showHelp;
window.menu.clear();
window.menu.append(menuCallApp);
window.menu.append(menuSettings);
+ window.menu.append(menuHelp);
window.menu.append(menuUpdate);
window.menu.append(menuAbout);
}
@@ -1028,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();
@@ -1075,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)
{
@@ -1086,7 +1121,7 @@ function loadSettings()
var pair = stringlist[i].split('=');
var key = pair[0];
var value = pair[1];
- console.info('stringlist: ' + key + '=\'' + value + '\'');
+ log('stringlist: ' + key + '=\'' + value + '\'');
if (config[key].Type == 'Int')
config[key].Value = Number(value);
else if (config[key].Type == 'String')
@@ -1108,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 {
@@ -1145,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)
@@ -1154,6 +1189,7 @@ function saveSettings()
error("saveSettings: " + e + ', line ' + e.line);
}
+ lastReloadTime = null; // force calendar data reload on next update
clearUpdateTimer();
setUpdateTimer();
}
@@ -1192,23 +1228,30 @@ function showAbout()
document.getElementById("name").innerHTML = "Coming Next " + version;
}
+function showHelp() {
+ widget.openURL('http://comingnext.sf.net/help');
+}
+
function updateFullscreen()
{
}
function showFullscreen()
{
- console.info("showFullscreen()");
+ log("showFullscreen()");
hideViews();
document.getElementById("fullscreenView").style.display = "block";
document.getElementById('body').className = "backgroundFullscreen";
- document.onclick = launchCalendar;
+ if (!errorOccured)
+ document.onclick = launchCalendar;
createMenu();
updateData();
}
function getBackgroundImage()
{
+ if (errorOccured)
+ return '';
var bgImage;
if (config['backgroundImageLocation'].Value == config['backgroundImageLocation'].ValidValues[0]) // internal
bgImage = 'background_' + orientation + '.png';
@@ -1243,7 +1286,7 @@ function updateHomescreen()
function showHomescreen()
{
- console.info("showHomescreen()");
+ log("showHomescreen()");
hideViews();
document.getElementById("homescreenView").style.display = "block";
document.getElementById('body').className = "background";
@@ -1345,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);
@@ -1372,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;
@@ -1474,16 +1517,23 @@ 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);
+ }
+}
+