1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
6 <title>Coming Next
</title>
8 <style type=
"text/css">
9 /* The following classes can be modified by widget settings */
11 .backgroundFullscreen { }
23 <script type=
"text/javascript" src=
"localizedTextStrings.js" charset=
"utf-8" />
26 // valid types for the config object are 'Int', 'Bool', 'String', 'Enum', 'UID'
28 monthRange: { Type: 'Int', Default:
2, Value:
2,},
29 includeTodos: { Type: 'Bool', Default: true, Value: true,},
30 useBackgroundImage: { Type: 'Bool', Default: true, Value: true,},
31 backgroundImageLocation: { Type: 'Enum', Default: 'internal', Value: 'internal', ValidValues: ['internal', 'external']},
32 showCombinedDateTime: { Type: 'Bool', Default: false, Value: false,},
33 showLocation: { Type: 'Bool', Default: true, Value: true,},
34 showTodayAsText: { Type: 'Bool', Default: true, Value: true,},
35 todayText: { Type: 'String', Default: getLocalizedText('settings.default.todayText'), Value: getLocalizedText('settings.default.todayText'),},
36 tomorrowText: { Type: 'String', Default: getLocalizedText('settings.default.tomorrowText'), Value: getLocalizedText('settings.default.tomorrowText'),},
37 showNowAsText: { Type: 'Bool', Default: true, Value: true,},
38 nowText: { Type: 'String', Default: getLocalizedText('settings.default.nowText'), Value: getLocalizedText('settings.default.nowText'),},
39 markOverdueTodos: { Type: 'Bool', Default: true, Value: true,},
40 overdueText: {Type: 'String', Default: getLocalizedText('settings.default.overdueText'), Value: getLocalizedText('settings.default.overdueText'),},
41 dateSeparator: { Type: 'String', Default: getLocalizedText('settings.default.dateSeparator'), Value: getLocalizedText('settings.default.dateSeparator'),},
42 dateFormat: { Type: 'Enum', Default: 'auto', Value: 'auto', ValidValues: ['auto', 'DDMM', 'MMDD'],},
43 weekDayLength: { Type: 'Int', Default:
2, Value:
2,},
44 updateDataInterval: { Type: 'Int', Default:
5, Value:
5,},
45 calendarApp: { Type: 'UID', Default:
0x10005901, Value:
0x10005901,},
46 eventsPerWidget: { Type: 'Int', Default:
4, Value:
4,},
47 showNothingText: { Type: 'Bool', Default: true, Value: true,},
48 nothingText: { Type: 'String', Default: getLocalizedText('settings.default.nothingText'), Value: getLocalizedText('settings.default.nothingText'),},
49 enableDaylightSaving: { Type: 'Bool', Default: true, Value: true,},
50 hideWidgetOnCalendarOpen: { Type: 'Bool', Default: false, Value: false,},
51 cssStyle_background: { Type: 'String', Default: 'color:#ffffff; background-color:#
000000', Value: 'color:#ffffff; background-color:#
000000',},
52 cssStyle_backgroundFullscreen: { Type: 'String', Default: 'color:#ffffff; background-color:#
000000', Value: 'color:#ffffff; background-color:#
000000',},
53 cssStyle_weekDay: { Type: 'String', Default: '', Value: '',},
54 cssStyle_date: { Type: 'String', Default: '', Value: '',},
55 cssStyle_today: { Type: 'String', Default: 'color:#ff0000', Value: 'color:#ff0000',},
56 cssStyle_tomorrow: { Type: 'String', Default: 'color:#
0000ff', Value: 'color:#
0000ff',},
57 cssStyle_time: { Type: 'String', Default: '', Value: '',},
58 cssStyle_now: { Type: 'String', Default: 'color:#ff00ff', Value: 'color:#ff00ff',},
59 cssStyle_description: { Type: 'String', Default: '', Value: '',},
60 cssStyle_icon: { Type: 'String', Default: 'width:
15px; height:
15px', Value: 'width:
15px; height:
15px',},
61 cssStyle_overdue: { Type: 'String', Default: 'color:#ffff00', Value: 'color:#ffff00',},
66 //-------------------------------------------------------
67 // Nothing of interest from here on...
68 //-------------------------------------------------------
69 var panelNum =
0; // use
1 for second panel
71 var versionURL =
"http://comingnext.sourceforge.net/version.xml";
72 var calendarService = null;
73 var cacheEntriesHtml = [];
74 var months_translated = [];
77 var mode =
0; //
0 = homescreen,
1 = fullscreen,
2 = settings,
3 = about,
4 = check for update
79 var settingsCalEntryId = null;
80 var settingsCache = null;
81 var notificationRequest1;
82 var notificationRequest2;
83 var calendarList = [];
85 // vars for daylight saving time
86 var daylightsavingWinter =
0;
87 var daylightsavingSummer =
0;
88 var summertime = false;
90 // this is a list of data fields a calendar event can have
103 window.onload = init;
104 window.onresize = updateScreen;
105 window.onshow = updateScreen;
107 function isLeapYear( year ) {
108 if (( year %
4 ==
0 && year %
100 !=
0 ) || year %
400 ==
0 )
114 function calcLeapYear(year, days)
116 if (isLeapYear(year))
122 function subToSunday(myDate, year, days, prevMonthDays)
124 for (i = myDate.getDay(); i
> 0 ;i--)
126 days -= prevMonthDays;
127 days = isLeapYear(year) ? --days : days;
131 function calcDaylightSaving()
133 var thisYearS = new Date(now.getFullYear(),
3,
0,
0,
0,
0 );
134 var thisYearW = new Date(now.getFullYear(),
10,
0,
0,
0,
0 );
135 var nextYearS = new Date(now.getFullYear() +
1,
3,
0,
0,
0,
0 );
136 var nextYearW = new Date(now.getFullYear() +
1,
10,
0,
0,
0,
0 );
140 thisYearSDays = nextYearSDays =
90;
141 thisYearWDays = nextYearWDays =
304;
143 thisYearSDays = calcLeapYear(now.getFullYear(), thisYearSDays);
144 thisYearWDays = calcLeapYear(now.getFullYear(), thisYearWDays);
145 nextYearSDays = calcLeapYear(now.getFullYear() +
1, nextYearSDays);
146 nextYearWDays = calcLeapYear(now.getFullYear() +
1, nextYearWDays);
148 thisYearSDays = subToSunday(thisYearS, now.getFullYear(), thisYearSDays,
59);
149 thisYearWDays = subToSunday(thisYearW, now.getFullYear(), thisYearWDays,
273);
150 nextYearSDays = subToSunday(nextYearS, now.getFullYear() +
1, nextYearSDays,
59);
151 nextYearWDays = subToSunday(nextYearW, now.getFullYear() +
1, nextYearWDays,
273);
153 daylightsavingSummer = new Date (now.getFullYear(),
03-
1, thisYearSDays,
2,
0,
0);
154 daylightsavingWinter = new Date (now.getFullYear(),
10-
1, thisYearWDays,
2,
0,
0);
155 if (daylightsavingSummer < now) {
156 daylightsavingSummer = new Date (now.getFullYear()+
1,
03-
1, nextYearSDays,
2,
0,
0);
159 if (daylightsavingWinter < now) {
160 daylightsavingWinter = new Date (now.getFullYear()+
1,
10-
1, nextYearWDays,
2,
0,
0);
163 if (summer && !winter)
169 function error(message)
171 console.info('Error: ' + message);
172 document.getElementById(
"calendarList").innerHTML = 'Error: ' + message;
175 function areDatesEqual(date1, date2)
177 return (date1.getFullYear() == date2.getFullYear() &&
178 date1.getMonth() == date2.getMonth() &&
179 date1.getDate() == date2.getDate());
182 function isTomorrow(date)
184 // tommorow = now +
1 day
185 // ToDo: some days can be shorter as
24 hours(daylight saving change day)
186 return areDatesEqual(date, new Date (now.getTime() +
24*
60*
60*
1000));
189 function isToday(date)
191 return areDatesEqual(date, now);
194 function collectLocales()
196 var tmpyear =
2000 + panelNum;
199 if (months_translated.length
> 0)
201 for (month =
0; month <
12; month++) {
202 var startDate = new Date(tmpyear, month,
15);
204 var item = new Object();
205 item.Type =
"DayEvent";
206 item.StartTime = startDate;
207 item.Summary =
"__temp" + month;
209 var criteria = new Object();
210 criteria.Type =
"CalendarEntry";
211 criteria.Item = item;
214 var result = calendarService.IDataSource.Add(criteria);
215 if (result.ErrorCode)
216 error(result.ErrorMessage);
218 error(
"collectLocales: " + e + ', line ' + e.line);
222 var startTime = new Date(tmpyear,
0,
1);
223 var endTime = new Date(tmpyear,
11,
31);
224 var listFiltering = {
225 Type:'CalendarEntry',
227 StartRange: startTime,
229 SearchText: '__temp',
233 var result = calendarService.IDataSource.GetList(listFiltering);
234 if (result.ErrorCode) {
235 error(result.ErrorMessage);
238 var list = result.ReturnValue;
240 error(e + ', line ' + e.line);
243 var ids = new Array();
249 while (list && (entry = list.getNext()) != undefined) {
250 dateArr = entry.StartTime.replace(/,/g,'').replace(/\./g,':').replace(/ /g,' ').split(' ');
251 var day = dateArr[
1];
252 var month = dateArr[
2];
253 var year = dateArr[
3];
255 // make sure month is set properly
256 if (isNaN(parseInt(day))) {
260 } else if (isNaN(parseInt(year))) {
266 console.info(entry.StartTime + ' -
> ' + month + ' ' + counter);
267 ids[counter] = entry.id;
268 months_translated[month] = counter +
1;
272 error(e + ', line ' + e.line);
277 var criteria = new Object();
278 criteria.Type =
"CalendarEntry";
283 var result = calendarService.IDataSource.Delete(criteria);
284 if (result.ErrorCode)
285 error(result.ErrorMessage);
287 error('deleting temp calendar entries:' + e + ', line ' + e.line);
292 function requestNotification()
294 var criteria = new Object();
295 criteria.Type =
"CalendarEntry";
298 notificationRequest1 = calendarService.IDataSource.RequestNotification(criteria, callback);
299 if (notificationRequest1.ErrorCode)
300 error('requestNotification failed with error code ' + notificationRequest1.ErrorCode);
302 error(
"requestNotification: " + e + ', line ' + e.line);
305 var criteria2 = new Object();
306 criteria2.Type =
"CalendarEntry";
307 criteria2.Filter = new Object();
308 criteria2.Filter.LocalIdList = new Array();
309 criteria2.Filter.LocalIdList[
0] = settingsCalEntryId;
312 notificationRequest2 = calendarService.IDataSource.RequestNotification(criteria2, settingsCallback);
313 if (notificationRequest2.ErrorCode)
314 error('requestNotification failed with error code ' + notificationRequest2.ErrorCode);
316 error(
"requestNotification: " + e + ', line ' + e.line);
320 function callback(transId, eventCode, result)
322 console.info(
"callback(): panelNum: %d transId: %d eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);
326 function settingsCallback(transId, eventCode, result)
328 console.info(
"settingsCallback(): panelNum: %d transId: %d eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);
332 function parseDate(dateString)
335 Dates my look very differently. Also keep in mind that the names are localized!!! These are the possibilities depending on the users date format setting:
336 Wednesday,
26 August,
2009 24:
00:
00
337 Wednesday,
26 August,
2009 12:
00:
00 am
338 Wednesday, August
26,
2009 12:
00:
00 am
339 Wednesday,
2009 August,
26 12:
00:
00 am
340 Wednesday,
2009 August,
28 8.00.00 pm
341 Wednesday,
2009 August,
28 08:
00:
00 PM
344 if (dateString ==
"" || dateString == null)
346 var dateArr = dateString.replace(/,/g,'').replace(/\./g,':').replace(/ /g,' ').split(' ');
347 if (dateArr.length !=
5 && dateArr.length !=
6)
351 var weekDay = dateArr[
0];
352 var day = dateArr[
1];
353 var month = dateArr[
2];
354 var year = dateArr[
3];
355 // make sure month is set properly
356 if (isNaN(parseInt(day))) {
360 } else if (isNaN(parseInt(year))) {
365 // make sure day and year are set properly
366 if (Number(day)
> Number(year)) {
371 month = months_translated[month];
374 var timeArr = dateArr[
4].split(':');
375 if (timeArr.length !=
3)
377 var hours = Number(timeArr[
0]);
378 var minutes = Number(timeArr[
1]);
379 var seconds = Number(timeArr[
2]);
380 if (dateArr.length ==
6 && dateArr[
5].toLowerCase() == 'pm' && hours <
12)
382 if (dateArr.length ==
6 && dateArr[
5].toLowerCase() == 'am' && hours ==
12)
385 console.info('year=' + year + ' month=' + month + ' day=' + day + ' hours=' + hours + ' minutes=' + minutes+ ' seconds=' + seconds);
387 // take care of daylight saving time
388 if (config['enableDaylightSaving'].Value) {
389 var date = new Date(year, month -
1, day, hours, minutes, seconds);
390 if (summertime && date
> daylightsavingWinter && date < daylightsavingSummer)
392 else if (!summertime && date
> daylightsavingSummer && date < daylightsavingWinter)
396 return new Date(year, month -
1, day, hours, minutes, seconds);
399 // returns a short date as string (
"31.12" or
"12.31") based on the format string which should look like
"Wednesday, 26 August, 2009 12:00:00 am"
400 function formatDate(date, format)
402 var day = date.getDate().toString();
403 var month = (date.getMonth() +
1).toString();
404 while (day.length <
2) { day = '
0' + day; }
405 while (month.length <
2) { month = '
0' + month; }
407 if (config['showTodayAsText'].Value && isToday(date))
408 return '
<span class=
"today">' + config['todayText'].Value + '
</span>';
409 if (config['showTodayAsText'].Value && isTomorrow(date))
410 return '
<span class=
"tomorrow">' + config['tomorrowText'].Value + '
</span>';
412 var dateArr = format.replace(/,/g,'').replace(/\./g,':').replace(/ /g,' ').split(' ');
413 if (dateArr.length !=
5 && dateArr.length !=
6) {
414 // we don't know how to format this
415 if (config['dateFormat'].Value == 'auto' || config['dateFormat'].Value == 'DDMM')
416 return day + config['dateSeparator'].Value + month;
418 return month + config['dateSeparator'].Value + day;
422 if (config['dateFormat'].Value == 'MMDD')
424 else if (config['dateFormat'].Value == 'DDMM')
427 // config['dateFormat'].Value == 'auto', try to detect system setting
429 var day_ = dateArr[
1];
430 var month_ = dateArr[
2];
431 var year_ = dateArr[
3];
432 // make sure month is set properly
433 if (isNaN(parseInt(day_))) {
438 } else if (isNaN(parseInt(year_))) {
444 // make sure day and year are set properly
445 if (Number(day_)
> Number(year_))
450 return day + config['dateSeparator'].Value + month;
452 return month + config['dateSeparator'].Value + day;
455 function formatTime(date)
457 // date is a Date() object
458 date.setSeconds(
0); // we don't care about seconds
459 var time = date.toLocaleTimeString().replace(/[\.:]
00/, ''); // remove seconds from string
460 if (time.replace(/\./, ':').split(':')[
0].length <
2)
462 if (config['showNowAsText'].Value && date.getTime() == now.getTime())
463 time = '
<span class=
"now">' + config['nowText'].Value + '
</span>';
467 function updateData()
469 console.info('updateData()');
470 calcDaylightSaving();
472 // meetings have time
473 // 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
475 var meetingList = [];
476 for(var i=
0; i < calendarList.length; i++) {
477 var meetingListFiltering = {
478 Type:'CalendarEntry',
480 CalendarName: calendarList[i],
481 StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(),
0,
0,
0)),
482 EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(),
0,
0,
0))
485 var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering);
486 if (meetingResult.ErrorCode !=
0)
487 throw(
"Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage);
488 var list = meetingResult.ReturnValue;
489 meetingList = meetingList.concat(listToArray(list));
491 meetingList.sort(sortCalendarEntries);
493 // todos don't, they start on
00:
00 hrs., but should be visible anyway
494 // this will generate a list of passed todos. We have to check if they have been marked as
"done" yet
495 if (config['includeTodos'].Value) {
496 var todayTodoList = [];
497 for(var i=
0; i < calendarList.length; i++) {
498 var todayTodoListFiltering = {
499 Type:'CalendarEntry',
501 CalendarName: calendarList[i],
503 StartRange: (new Date(now.getFullYear() -
1, now.getMonth(), now.getDate(),
0,
0,
0)),
504 EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(),
0,
0,
1))
507 var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);
508 var list = todayTodoResult.ReturnValue;
509 todayTodoList = todayTodoList.concat(listToArray(list));
511 todayTodoList.sort(sortCalendarEntries);
512 var entryLists = [todayTodoList, meetingList];
514 var entryLists = [meetingList];
517 error('loading Calendar items list:' + e + ', line ' + e.line);
526 var fontsize = 'normal';
528 if (config['eventsPerWidget'].Value ==
3) {
530 changeCssClass('.icon', 'width:
20px; height:
20px');
532 else if (config['eventsPerWidget'].Value ==
5) {
534 changeCssClass('.icon', 'width:
10px; height:
10px');
536 else if (config['eventsPerWidget'].Value ==
6) {
538 changeCssClass('.icon', 'width:
8px; height:
8px');
542 changeCssClass('.icon', config['cssStyle_icon'].Value);
543 var entriesHtml = '
<table style=
"font-size:' + fontsize + ';">';
547 max = (panelNum +
1) * config['eventsPerWidget'].Value;
549 max =
30; // we can display a lot more events in fullscreen mode
551 // the first outer loop iteration is for passed ToDos, the second loop is for all upcomming events (may also include ToDos)
552 for (var i=
0; counter < max && i < entryLists.length; i++) {
553 for (var j=
0; (counter < max) && (j < entryLists[i].length); j++) {
554 entry = entryLists[i][j];
557 // output event info for debugging
559 'event: Id=' + entry.id +
560 ',Type=' + entry.Type +
561 ',Summary=' + entry.Summary +
562 ',Location=' + entry.Location +
563 ',Status=' + entry.Status +
564 ',StartTime=' + entry.StartTime +
565 ',EndTime=' + entry.EndTime +
566 ',InstanceStartTime=' + entry.InstanceStartTime +
567 ',InstanceEndTime=' + entry.InstanceEndTime
570 // we don't want ToDos when includeTodos == false or when they are completed
571 if (entry.Type == 'ToDo' && (entry.Status ==
"TodoCompleted" || !config['includeTodos'].Value)) {
572 console.info('skipping ' + entry.id );
577 // make sure that we don't include an event twice (useful for ToDos that might come up twice)
578 if (eventIds[entry.id] ==
1 && entry.Type == 'ToDo') {
579 console.info('skipped (already included) ' + entry.id);
583 eventIds[entry.id] =
1;
585 // summary can be undefined!
586 var Summary = ((entry.Summary == null) ? '' : entry.Summary);
587 if (entry.Type == 'Meeting' && entry.Location != '' && config['showLocation'].Value)
588 Summary += ', ' + entry.Location;
590 // fix by yves: determine start and end dates/times
591 entryStartTime = ((entry.InstanceStartTime == null) ? entry.StartTime : entry.InstanceStartTime);
592 entryEndTime = ((entry.InstanceEndTime == null) ? entry.EndTime : entry.InstanceEndTime);
594 // there can be ToDos that have no date at all!
595 if (entry.Type == 'ToDo' && entry.EndTime == null)
596 entryDate =
""; // this will cause parseDate(entryDate) to return null;
598 entryDate = ((entry.Type == 'ToDo') ? entryEndTime : entryStartTime); // ToDo's use their EndTime, the rest use StartTime
600 // Convert date/time string to Date object
601 var date = parseDate(entryDate);
602 console.info('date: ' + date);
603 var endDate = ((entryEndTime == null) ? null : parseDate(entryEndTime));
604 console.info('endDate: ' + endDate);
606 // check if meeting event has already passed
607 if (entry.Type == 'Meeting') {
608 var compareTime = ((endDate == null) ? date.getTime() : endDate.getTime());
609 if (now.getTime()
> compareTime) {
610 console.info('skipping Meeting (already passed) ' + entry.id);
612 eventIds[entry.id] =
0;
617 // check if anniversary passed (not sure why they are in the list, the query was only for today - nokia?)
618 if (entry.Type == 'Anniversary') {
619 var tmp = new Date(now.getFullYear(), now.getMonth(), now.getDate(),
0,
0,
0);
620 if (date.getTime() < tmp.getTime()) {
621 console.info('skipping Anniversary (already passed) ' + entry.id);
623 eventIds[entry.id] =
0;
628 // fix DayEvents end time. End times are off by
1 Second. It's possible that the event has already passed
629 if (entry.Type == 'DayEvent' && endDate != null) {
630 endDate.setMinutes(endDate.getMinutes() -
1);
631 console.info('fixing DayEvent endDate: ' + endDate);
632 if (now.getTime()
> endDate.getTime()) {
633 console.info('event already passed ' + entry.id);
635 eventIds[entry.id] =
0;
640 // check if the event is currently taking place
641 if (entryStartTime != null && entryEndTime != null && date != null && endDate != null) {
642 // check if we are between start and endtime
643 if ((date.getTime() < now.getTime()) && (now.getTime() < endDate.getTime())) {
644 date = now; // change appointment date/time to now
645 console.info('event is currently taking place: ' + date);
649 // skip events for the first panel in case this is the second one and we're not in fullscreen mode
650 if (mode ==
0 && panelNum
> 0 && counter < panelNum * config['eventsPerWidget'].Value +
1) {
651 console.info('skipping (already in first widget) ' + entry.id);
655 // mark overdue todos
657 if (entry.Type == 'ToDo' && date != null) {
658 var tmp1 = new Date(date.getFullYear(), date.getMonth(), date.getDate(),
0,
0,
0);
659 var tmp2 = new Date(now.getFullYear(), now.getMonth(), now.getDate(),
0,
0,
0);
660 if (tmp1.getTime() < tmp2.getTime()) {
665 // generate html output
666 entriesHtml += '
<tr><td><img class=
"icon" src=
"' + entry.Type + '.png" /></td>';
668 // some languages have very strange locale date formats, can't parse all those. Also some todos don't have dates at all.
669 entriesHtml += '
<td colspan=
"4"><span class=
"date">' + entryDate + '
</span> ';
671 var weekDay = date.toLocaleDateString().substr(
0,config['weekDayLength'].Value);
672 var time = formatTime(date);
673 var dateStr = formatDate(date, entryDate);
674 if (entry.Type == 'ToDo' && overdue && config['markOverdueTodos'].Value) {
675 dateStr = '
<span class=
"overdue">' + config['overdueText'].Value + '
</span>';
676 entriesHtml += '
<td colspan=
"4" width=
"1px"><span class=
"date">' + dateStr + '
</span> ';
677 } else if (entry.Type == 'ToDo' || entry.Type == 'Anniversary' || entry.Type == 'DayEvent' || entry.Type == 'Reminder') {
678 if ((isToday(date) || isTomorrow(date)) && config['showTodayAsText'].Value) // show weekday if the date string is not text. looks odd otherwise
679 entriesHtml += '
<td colspan=
"4" width=
"1px"><span class=
"date">' + dateStr + '
</span> ';
681 entriesHtml += '
<td class=
"weekDay" width=
"1px">' + weekDay + '
</td><td width=
"1px" class=
"date">' + dateStr + '
</td><td colspan=
"2">';
682 } else if (entry.Type == 'Meeting') {
683 if (config['showCombinedDateTime'].Value) {
685 entriesHtml += '
<td width=
"1px" colspan=
"4"><span class=
"today">' + time + '
</span> ';
686 else if (isTomorrow(date))
687 entriesHtml += '
<td width=
"1px" colspan=
"4"><span class=
"tomorrow">' + dateStr + '
</span> <span class=
"time">' + time + '
</span> ';
689 entriesHtml += '
<td width=
"1px" class=
"weekDay">' + weekDay + '
</td><td width=
"1px" class=
"date">' + dateStr + '
</td><td colspan=
"2">';
691 if ((isToday(date) || isTomorrow(date)) && config['showTodayAsText'].Value)
692 entriesHtml += '
<td colspan=
"4" width=
"1px"><span class=
"today">' + dateStr + '
</span> <span class=
"time">' + time + '
</span> ';
694 entriesHtml += '
<td width=
"1px" class=
"weekDay">' + weekDay + '
</td><td width=
"1px" class=
"date">' + dateStr + '
</td><td width=
"1px" class=
"time">' + time + '
</td><td>';
698 entriesHtml += '
<span class=
"description">' + Summary + '
</span></td></tr>';
701 entriesHtml += '
</table>';
702 if (config['showNothingText'].Value && entriesHtml == '
<table></table>') {
703 var text = config['nothingText'].Value.replace(/%d/, config['monthRange'].Value);
704 entriesHtml = '
<div style=
"width:295px; height:75px; text-align:center; line-height:75px; overflow:visible;">' + text + '
</div>';
706 if (cacheEntriesHtml != entriesHtml) {
708 document.getElementById('calendarList').innerHTML = entriesHtml;
710 document.getElementById('fullscreenCalendarList').innerHTML = entriesHtml;
711 cacheEntriesHtml = entriesHtml;
714 error('displaying list:' + e + ', line ' + e.line);
719 function updateScreen()
721 // check if opening fullscreen
722 if( window.innerHeight
> 91 && mode ==
0) {
724 cacheEntriesHtml = '';
725 document.getElementById('body').style.backgroundImage =
"";
728 else if (window.innerHeight <=
91 && mode !=
0) {
730 cacheEntriesHtml = '';
740 function launchCalendar()
743 widget.openApplication(config['calendarApp'].Value,
"");
744 if (config['hideWidgetOnCalendarOpen'].Value)
747 error('starting Calendar App');
754 console.info('New widget instance starting up...');
757 // call calendar service
758 if (device !=
"undefined")
759 calendarService = device.getServiceObject(
"Service.Calendar",
"IDataSource");
761 throw('device object does not exist');
763 error('loading Calendar service: ' + e + ', line ' + e.line);
767 calendarList = listCalendars();
771 requestNotification();
772 window.setInterval('updateData()',
1000 *
60 * config['updateDataInterval'].Value);
773 document.getElementById(
"settingsTitle").innerHTML = getLocalizedText('menu.settings');
775 if (window.innerHeight
> 91) {
776 mode =
0; // we're starting fullscreen, we set mode to homescreen in order to let updateScreen() do all the work for us
782 if (config['useBackgroundImage'].Value)
783 // check for screen rotation every
1 secs
784 window.setInterval('updateScreen()',
1000 *
1);
787 function createMenu()
789 window.menu.setLeftSoftkeyLabel(
"",null);
790 window.menu.setRightSoftkeyLabel(
"",null);
792 var menuSettings = new MenuItem(getLocalizedText('menu.settings'), id++);
793 var menuCallApp = new MenuItem(getLocalizedText('menu.openCalendarApp'), id++);
794 var menuUpdate = new MenuItem(getLocalizedText('menu.update'), id++);
795 var menuAbout = new MenuItem(getLocalizedText('menu.about'), id++);
796 menuSettings.onSelect = showSettings;
797 menuAbout.onSelect = showAbout;
798 menuCallApp.onSelect = launchCalendar;
799 menuUpdate.onSelect = showUpdate;
801 window.menu.append(menuCallApp);
802 window.menu.append(menuSettings);
803 window.menu.append(menuUpdate);
804 window.menu.append(menuAbout);
807 function showSettings()
811 document.getElementById(
"settingsView").style.display =
"block";
812 document.onclick = null;
814 window.menu.setLeftSoftkeyLabel(getLocalizedText('settings.save'), function()
816 for (var key in config) {
817 if (config[key].Type == 'String')
818 config[key].Value = document.forms[
0].elements[
"settings." + key].value;
819 else if (config[key].Type == 'Int') {
820 config[key].Value = parseInt(document.forms[
0].elements[
"settings." + key].value);
821 if (config[key].Value <
0)
822 config[key].Value = config[key].Default;
824 else if (config[key].Type == 'Bool')
825 config[key].Value = document.forms[
0].elements[
"settings." + key].checked;
826 else if (config[key].Type == 'UID')
827 config[key].Value = parseInt(document.forms[
0].elements[
"settings." + key].value);
828 else if (config[key].Type == 'Enum') {
829 config[key].Value = document.forms[
0].elements[
"settings." + key].value;
830 if (config[key].ValidValues.indexOf(config[key].Value) == -
1)
831 config[key].Value = config[key].Default;
842 window.menu.setRightSoftkeyLabel(getLocalizedText('settings.cancel'), function()
848 var settingsHtml = '
<form>';
849 for (var key in config) {
850 if (config[key].Type == 'String') {
852 if (key.substring(
0,
9) ==
"cssStyle_")
853 prefix = getLocalizedText('settings.cssStyle_prefix');
854 settingsHtml += '
<table><tr><td>' + prefix + getLocalizedText('settings.name.' + key) + '
<br /><input class=
"textInput" name=
"settings.' + key + '" type=
"text" value=
"' + config[key].Value + '" /></td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '
<hr />';
856 else if (config[key].Type == 'Int')
857 settingsHtml += '
<table><tr><td>' + getLocalizedText('settings.name.' + key) + '
<br /><input class=
"textInput" name=
"settings.' + key + '" type=
"text" value=
"' + config[key].Value + '" /></td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '
<hr />';
858 else if (config[key].Type == 'Bool')
859 settingsHtml += '
<table><tr><td>' + getLocalizedText('settings.name.' + key) + '
<br /><input name=
"settings.' + key + '" type=
"checkbox" value=
"true" ' + (config[key].Value ? '
checked=
"checked"' : '') + '
/></td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '
<hr />';
860 else if (config[key].Type == 'UID')
861 settingsHtml += '
<table><tr><td>' + getLocalizedText('settings.name.' + key) + '
<br /><input class=
"textInput" name=
"settings.' + key + '" type=
"text" value=
"0x' + config[key].Value.toString(16) + '" /></td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '
<hr />';
862 else if (config[key].Type == 'Enum') {
863 settingsHtml += '
<table><tr><td>' + getLocalizedText('settings.name.' + key) + '
<br /><select name=
"settings.' + key + '" size=
"1">';
864 for(var i =
0; i < config[key].ValidValues.length; i++)
865 settingsHtml += '
<option value=
"' + config[key].ValidValues[i] + '"' + (config[key].Value == config[key].ValidValues[i] ? '
selected=
"selected"' : '') + '
>' + getLocalizedText('settings.validValues.' + key + '.' + config[key].ValidValues[i]) + '
</option>';
866 settingsHtml += '
</select></div></td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '
<hr />';
869 settingsHtml += '
<input name=
"reset" type=
"button" value=
"' + getLocalizedText('settings.restoreDefaults') + '" onclick=
"javascript:restoreDefaultSettings();showSettings();" />';
870 settingsHtml += '
</form>';
871 document.getElementById(
"settingsList").innerHTML = settingsHtml;
874 function changeCssClass(classname, properties)
876 for(var i =
0; i < document.styleSheets[
0]['cssRules'].length; i++)
878 if (document.styleSheets[
0]['cssRules'][i].selectorText == classname) {
879 document.styleSheets[
0].deleteRule(i);
880 document.styleSheets[
0].insertRule(classname + ' { ' + properties + ' }', document.styleSheets[
0]['cssRules'].length);
886 function updateCssClasses()
888 for(var key in config) {
889 changeCssClass(getLocalizedText('settings.name.' + key), config[key].Value);
893 function getSettingsCalEntryId()
895 if (settingsCalEntryId == null) {
896 // check if entry already exists
897 var listFiltering = {
898 Type:'CalendarEntry',
900 StartRange: new Date(
2000,
0,
1),
901 EndRange: new Date(
2000,
0,
1),
902 SearchText: 'ComingNext Settings|',
906 var result = calendarService.IDataSource.GetList(listFiltering);
907 if (result.ErrorCode) {
908 error(result.ErrorMessage);
911 var list = result.ReturnValue;
912 var entry = list.getNext();
913 if (entry != undefined) {
914 settingsCalEntryId = entry.LocalId;
915 console.info(
"settingsCalEntryId=" + settingsCalEntryId);
917 else { // create settings item
918 var item = new Object();
919 item.Type =
"DayEvent";
920 item.StartTime = new Date(
2000,
0,
1);
921 item.Summary =
"ComingNext Settings|";
923 var criteria = new Object();
924 criteria.Type =
"CalendarEntry";
925 criteria.Item = item;
928 var result = calendarService.IDataSource.Add(criteria);
929 if (result.ErrorCode)
930 error(result.ErrorMessage);
932 error(
"getSettingsCalEntryId: " + e + ', line ' + e.line);
935 getSettingsCalEntryId();
940 function restoreDefaultSettings()
942 for (var key in config)
943 config[key].Value = config[key].Default;
946 function loadSettings()
948 getSettingsCalEntryId();
949 var listFiltering = {
950 Type:'CalendarEntry',
952 LocalId: settingsCalEntryId
955 var result = calendarService.IDataSource.GetList(listFiltering);
956 if (result.ErrorCode) {
957 error(result.ErrorMessage);
960 var entry = result.ReturnValue.getNext();
961 if (entry != undefined) {
962 // only reload settings if they chanced since the last reload
963 if (settingsCache != entry.Summary)
965 restoreDefaultSettings();
966 var stringlist = entry.Summary.split(
"|");
967 // skip the first two entries, those contain header and version info
968 for(var i =
2; i < stringlist.length -
1; i++) {
969 var pair = stringlist[i].split('=');
972 console.info('stringlist: ' + key + '=\'' + value + '\'');
973 if (config[key].Type == 'Int')
974 config[key].Value = Number(value);
975 else if (config[key].Type == 'String')
976 config[key].Value = value;
977 else if (config[key].Type == 'Bool')
978 config[key].Value = (value == 'true')
979 else if (config[key].Type == 'Enum')
980 config[key].Value = value;
981 else if (config[key].Type == 'UID')
982 config[key].Value = Number(value);
984 settingsCache = entry.Summary;
989 error(
"Failed to load settings, calendar entry could not be found");
993 function saveSettings()
995 getSettingsCalEntryId();
996 var item = new Object();
997 item.Type =
"DayEvent";
998 item.StartTime = new Date(
2000,
0,
1);
999 item.LocalId = settingsCalEntryId;
1000 item.Summary =
"ComingNext Settings|" + version +
"|";
1002 for (var key in config) {
1003 if (config[key].Type == 'Int')
1004 item.Summary += key +
"=" + config[key].Value.toString() +
"|";
1005 else if (config[key].Type == 'String')
1006 item.Summary += key +
"=" + config[key].Value +
"|";
1007 else if (config[key].Type == 'Bool')
1008 item.Summary += key +
"=" + (config[key].Value ? 'true' : 'false') +
"|";
1009 else if (config[key].Type == 'Enum')
1010 item.Summary += key +
"=" + config[key].Value +
"|";
1011 else if (config[key].Type == 'UID')
1012 item.Summary += key +
"=" + config[key].Value.toString() +
"|";
1014 settingsCache = item.Summary;
1016 var criteria = new Object();
1017 criteria.Type =
"CalendarEntry";
1018 criteria.Item = item;
1020 console.info(
"Saving settings to calendar entry: " + item.Summary);
1022 var result = calendarService.IDataSource.Add(criteria);
1023 if (result.ErrorCode)
1024 error(result.ErrorMessage);
1026 error(
"saveSettings: " + e + ', line ' + e.line);
1030 function toggleVisibility(elementId)
1032 if (document.getElementById(elementId).style.display ==
"none")
1033 document.getElementById(elementId).style.display =
"block";
1035 document.getElementById(elementId).style.display =
"none";
1039 function printHintBox(text)
1042 return '
<td width=
"1%" align=
"right" onclick=
"javascript:toggleVisibility(\'info' + uniqueId + '\')">' + getLocalizedText('settings.help') + '
</td></tr></table>'+
1043 '
<div class=
"settingsInfo" id=
"info' + uniqueId + '">' + text + '
</div>';
1046 function showAbout()
1050 document.getElementById(
"aboutView").style.display =
"block";
1051 document.onclick = null;
1053 window.menu.setLeftSoftkeyLabel(
" ", function(){});
1054 window.menu.setRightSoftkeyLabel(getLocalizedText('softkey.back'), function()
1060 //document.getElementById(
"aboutView").innerHTML = 'aboutView';
1061 document.getElementById(
"name").innerHTML =
"Coming Next " + version;
1064 function updateFullscreen()
1068 function showFullscreen()
1071 document.getElementById(
"fullscreenView").style.display =
"block";
1072 document.getElementById('body').className =
"backgroundFullscreen";
1073 document.onclick = launchCalendar;
1078 function getBackgroundImage()
1081 if (config['backgroundImageLocation'].Value == config['backgroundImageLocation'].ValidValues[
0]) // internal
1082 bgImage = 'background_' + orientation + '.png';
1084 bgImage = 'C:/Data/background_' + panelNum + '_' + orientation + '.png';
1088 function updateHomescreen()
1090 if (config['useBackgroundImage'].Value) {
1091 // check for screen rotation
1092 if (orientation != 'portrait' && screen.width ==
360 && screen.height ==
640) {
1093 window.widget.prepareForTransition(
"fade");
1094 orientation = 'portrait';
1095 document.getElementById('body').style.backgroundImage = 'url(' + getBackgroundImage() + ')';
1096 document.getElementById('body').style.backgroundColor = 'none';
1097 window.widget.performTransition();
1098 } else if (orientation != 'landscape' && screen.width ==
640 && screen.height ==
360) {
1099 window.widget.prepareForTransition(
"fade");
1100 orientation = 'landscape';
1101 document.getElementById('body').style.backgroundImage = 'url(' + getBackgroundImage() + ')';
1102 document.getElementById('body').style.backgroundColor = 'none';
1103 window.widget.performTransition();
1105 else if (document.getElementById('body').style.backgroundImage ==
"")
1107 document.getElementById('body').style.backgroundImage = 'url(' + getBackgroundImage() + ')';
1112 function showHomescreen()
1115 document.getElementById(
"homescreenView").style.display =
"block";
1116 document.getElementById('body').className =
"background";
1117 document.onclick = null;
1121 function getLocalizedText(p_Txt)
1123 if (localizedText[p_Txt])
1124 return localizedText[p_Txt];
1126 return 'ERROR: missing translation for ' + p_Txt;
1129 function showUpdate()
1133 document.getElementById(
"updateView").style.display =
"block";
1134 document.onclick = null;
1136 window.menu.setLeftSoftkeyLabel(getLocalizedText('update.checknow'), function(){
1139 window.menu.setRightSoftkeyLabel(getLocalizedText('softkey.back'), function()
1145 document.getElementById(
"currentVersion").innerHTML = getLocalizedText(
"update.current") + version;
1149 function checkForUpdate()
1151 // asynch XHR to server url
1152 reqV = new XMLHttpRequest();
1153 reqV.onreadystatechange = checkForUpdateCallback;
1154 document.getElementById(
"updateDiv").innerHTML = getLocalizedText(
"update.checking");
1155 reqV.open(
"GET", versionURL, true);
1156 reqV.setRequestHeader(
"If-Modified-Since",
"Sat, 1 Jan 2000 00:00:00 GMT" ); // disable caching
1160 function checkForUpdateCallback()
1162 if (reqV.readyState ==
4) {
1163 if (reqV.status ==
200) {
1164 var resultXml = reqV.responseText;
1166 var div = document.getElementById(
"tmp");
1167 div.innerHTML = resultXml;
1168 var newVersion = div.getElementsByTagName('version')[
0].innerHTML;
1169 var newVersionURL = div.getElementsByTagName('url')[
0].innerHTML;
1171 if (version != newVersion) {
1172 document.getElementById(
"updateDiv").innerHTML = getLocalizedText(
"update.download").replace(/%
1/, newVersion).replace(/%
2/, newVersionURL);
1175 document.getElementById(
"updateDiv").innerHTML = getLocalizedText(
"update.nonewversion");
1180 document.getElementById(
"updateDiv").innerHTML = getLocalizedText(
"update.error") + reqV.status +
" " + reqV.responseText;
1185 function hideViews()
1187 document.getElementById(
"homescreenView").style.display =
"none";
1188 document.getElementById(
"fullscreenView").style.display =
"none";
1189 document.getElementById(
"aboutView").style.display =
"none";
1190 document.getElementById(
"settingsView").style.display =
"none";
1191 document.getElementById(
"updateView").style.display =
"none";
1194 function listCalendars()
1200 DefaultCalendar: false
1204 var calendarsResult = calendarService.IDataSource.GetList(criteria);
1205 if (calendarsResult.ErrorCode !=
0)
1206 throw(
"Error fetching list of calendars: " + calendarsResult.ErrorCode + ': ' + calendarsResult.ErrorMessage);
1207 var calendarListIterator = calendarsResult.ReturnValue;
1212 while (( item = calendarListIterator.getNext()) != undefined ) {
1213 calendars[count++] = item;
1215 console.info(
"Available Calendars: " + calendars.join(
", "));
1218 error('listing calendars:' + e + ', line ' + e.line);
1223 // Copies all objects and their properties to an array. Data is copied so nothing gets lost when the reference is removed
1224 function listToArray(list)
1226 var array = new Array();
1229 while (( item = list.getNext()) != undefined ) {
1230 var itemCopy = new Object();
1231 for(var i=
0; i < entryFields.length; i++) {
1232 itemCopy[entryFields[i]] = item[entryFields[i]];
1234 array.push(itemCopy);
1235 txt += array[array.length -
1].Summary +
", ";
1237 console.info(
"listToArray(): " + txt);
1241 function sortCalendarEntries(a, b)
1245 if (a['InstanceStartTime'] != null) {
1246 atime = a['InstanceStartTime'];
1248 else if (a['StartTime'] != null) {
1249 atime = a['StartTime'];
1251 else if (a['InstanceEndTime'] != null) {
1252 atime = a['InstanceEndTime'];
1254 else if (a['EndTime'] != null) {
1255 atime = a['EndTime'];
1258 if (b['InstanceStartTime'] != null) {
1259 btime = b['InstanceStartTime'];
1261 else if (b['StartTime'] != null) {
1262 btime = b['StartTime'];
1264 else if (b['InstanceEndTime'] != null) {
1265 btime = b['InstanceEndTime'];
1267 else if (b['EndTime'] != null) {
1268 btime = b['EndTime'];
1271 if (atime && btime) {
1273 atime = parseDate(atime);
1274 btime = parseDate(btime);
1276 // sort by date & time
1277 if (atime < btime) {
1280 else if (atime
> btime) {
1284 else if (a['Type'] != b['Type']) {
1285 if (a['Type'] < b['Type']) {
1288 else if (a['Type']
> b['Type']) {
1292 // sort by description
1293 else if (a['Summary'] && b['Summary'] && a['Summary'] != b['Summary']) {
1294 if (a['Summary'] < b['Summary']) {
1297 else if (a['Summary']
> b['Summary']) {
1307 <style type=
"text/css">
1308 table { margin:
0px; padding:
0px; border-spacing:
0px; }
1309 td { padding:
0px
5px
0px
0px; white-space:nowrap; overflow:hidden; }
1310 hr { color:#ffffff; background-color:#ffffff; height:
1px; text-align:left; border-style:none; }
1311 .settingsInfo { display:none; font-style:italic; }
1312 .title { font-weight:bold; font-size:
14pt; }
1313 .textInput { width:
90%; }
1314 .credits { margin-left:
40px; text-indent: -
20px; margin-bottom:
0px; }
1315 #homescreenView { width:
315px; height:
91px; overflow:hidden; }
1316 #calendarList { position:absolute; left:
10px; top:
4px; width:
295px; height:
75px; overflow:hidden; }
1317 #name { text-align:center; }
1318 #appicon { display: block; margin-left: auto; margin-right: auto; margin-top:
10px; }
1319 #smallappicon { width:
22px; height:
22px; margin-right:
10px; float:left; }
1324 <body id=
"body" class=
"background">
1325 <div id=
"homescreenView">
1326 <div id=
"calendarList"></div>
1328 <div id=
"fullscreenView" style=
"display:none;">
1329 <img src=
"Icon.png" id=
"smallappicon">
1330 <h1 class=
"title">Coming Next
</h1>
1332 <div id=
"fullscreenCalendarList">loading...
</div>
1334 <div id=
"settingsView" style=
"display:none">
1335 <img src=
"Icon.png" id=
"smallappicon">
1336 <h1 id=
"settingsTitle" class=
"title">Settings
</h1>
1338 <div id=
"settingsList"></div>
1340 <div id=
"aboutView" style=
"display:none">
1341 <img src=
"Icon.png" id=
"appicon">
1342 <h1 id=
"name">Coming Next
</h1>
1344 <p>Created by Dr. Cochambre and Michael Prager.
</p>
1345 <p>Contributions:
</p>
1346 <p class=
"credits">Paul Moore (bug fixes, new features and code cleanup)
</p>
1347 <p class=
"credits">Manfred Hanselmann (DST support)
</p>
1348 <p class=
"credits">Christophe Milsent (translation support & french translation)
</p>
1349 <p class=
"credits">Flavio Nathan (portuguese-brazilian translation)
</p>
1350 <p class=
"credits">Tokeda (russian translation)
</p>
1351 <p>This software is open source and licensed under the GPLv3.
</p>
1352 <p>Visit sourceforge.net/projects/comingnext for free updates.
</p>
1355 <div id=
"updateView" style=
"display:none">
1356 <img src=
"Icon.png" id=
"smallappicon">
1357 <h1 class=
"title">Check for update
</h1>
1359 <div id=
"currentVersion">Coming Next ??
</div>
1360 <div id=
"updateDiv"></div>
1361 <div id=
"tmp" style=
"display:none;"></div>