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 console.info(
"updateData(): meetingList.sort()");
492 meetingList.sort(sortCalendarEntries);
494 // todos don't, they start on
00:
00 hrs., but should be visible anyway
495 // this will generate a list of passed todos. We have to check if they have been marked as
"done" yet
496 if (config['includeTodos'].Value) {
497 var todayTodoList = [];
498 for(var i=
0; i < calendarList.length; i++) {
499 var todayTodoListFiltering = {
500 Type:'CalendarEntry',
502 CalendarName: calendarList[i],
504 StartRange: (new Date(now.getFullYear() -
1, now.getMonth(), now.getDate(),
0,
0,
0)),
505 EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(),
0,
0,
1))
508 var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);
509 var list = todayTodoResult.ReturnValue;
510 todayTodoList = todayTodoList.concat(listToArray(list));
512 console.info(
"updateData(): todayTodoList.sort()");
513 todayTodoList.sort(sortCalendarEntries);
514 var entryLists = [todayTodoList, meetingList];
516 var entryLists = [meetingList];
519 error('loading Calendar items list:' + e + ', line ' + e.line);
528 var fontsize = 'normal';
530 if (config['eventsPerWidget'].Value ==
3) {
532 changeCssClass('.icon', 'width:
20px; height:
20px');
534 else if (config['eventsPerWidget'].Value ==
5) {
536 changeCssClass('.icon', 'width:
10px; height:
10px');
538 else if (config['eventsPerWidget'].Value ==
6) {
540 changeCssClass('.icon', 'width:
8px; height:
8px');
544 changeCssClass('.icon', config['cssStyle_icon'].Value);
545 var entriesHtml = '
<table style=
"font-size:' + fontsize + ';">';
549 max = (panelNum +
1) * config['eventsPerWidget'].Value;
551 max =
30; // we can display a lot more events in fullscreen mode
554 for (var i=
0; i < entryLists.length; i++) {
555 listinfo = listinfo +
" " + entryLists[i].length;
556 var entrieslist =
"";
557 for (var j=
0; j < entryLists[i].length; j++) {
558 entrieslist += entryLists[i][j].Summary +
", ";
560 console.info(
"updateData(): entrieslist: " + entrieslist);
562 console.info(
"updateData(): inner loop, " + entryLists.length +
" lists, [" + listinfo +
"] entries");
564 // the first outer loop iteration is for passed ToDos, the second loop is for all upcomming events (may also include ToDos)
565 for (var i=
0; counter < max && i < entryLists.length; i++) {
566 for (var j=
0; (counter < max) && (j < entryLists[i].length); j++) {
567 entry = entryLists[i][j];
570 // output event info for debugging
571 var entryInfo =
"event: ";
572 for(var k=
0; k < entryFields.length; ++k) {
573 if (entry[entryFields[k]] != undefined) {
574 entryInfo += entryFields[k] +
"=" + entry[entryFields[k]] +
",";
577 console.info(entryInfo);
579 // we don't want ToDos when includeTodos == false or when they are completed
580 if (entry.Type == 'ToDo' && (entry.Status ==
"TodoCompleted" || !config['includeTodos'].Value)) {
581 console.info('skipping ' + entry.id );
586 // make sure that we don't include an event twice (useful for ToDos that might come up twice)
587 if (eventIds[entry.id] ==
1 && entry.Type == 'ToDo') {
588 console.info('skipped (already included) ' + entry.id);
592 eventIds[entry.id] =
1;
594 // summary can be undefined!
595 var Summary = ((entry.Summary == null) ? '' : entry.Summary);
596 if (entry.Type == 'Meeting' && entry.Location != '' && config['showLocation'].Value)
597 Summary += ', ' + entry.Location;
599 // fix by yves: determine start and end dates/times
600 entryStartTime = ((entry.InstanceStartTime == null) ? entry.StartTime : entry.InstanceStartTime);
601 entryEndTime = ((entry.InstanceEndTime == null) ? entry.EndTime : entry.InstanceEndTime);
603 // there can be ToDos that have no date at all!
604 if (entry.Type == 'ToDo' && entry.EndTime == null)
605 entryDate =
""; // this will cause parseDate(entryDate) to return null;
607 entryDate = ((entry.Type == 'ToDo') ? entryEndTime : entryStartTime); // ToDo's use their EndTime, the rest use StartTime
609 // Convert date/time string to Date object
610 var date = parseDate(entryDate);
611 console.info('date: ' + date);
612 var endDate = ((entryEndTime == null) ? null : parseDate(entryEndTime));
613 console.info('endDate: ' + endDate);
615 // check if meeting event has already passed
616 if (entry.Type == 'Meeting') {
617 var compareTime = ((endDate == null) ? date.getTime() : endDate.getTime());
618 if (now.getTime()
> compareTime) {
619 console.info('skipping Meeting (already passed) ' + entry.id);
621 eventIds[entry.id] =
0;
626 // check if anniversary passed (not sure why they are in the list, the query was only for today - nokia?)
627 if (entry.Type == 'Anniversary') {
628 var tmp = new Date(now.getFullYear(), now.getMonth(), now.getDate(),
0,
0,
0);
629 if (date.getTime() < tmp.getTime()) {
630 console.info('skipping Anniversary (already passed) ' + entry.id);
632 eventIds[entry.id] =
0;
637 // fix DayEvents end time. End times are off by
1 Second. It's possible that the event has already passed
638 if (entry.Type == 'DayEvent' && endDate != null) {
639 endDate.setMinutes(endDate.getMinutes() -
1);
640 console.info('fixing DayEvent endDate: ' + endDate);
641 if (now.getTime()
> endDate.getTime()) {
642 console.info('event already passed ' + entry.id);
644 eventIds[entry.id] =
0;
649 // check if the event is currently taking place
650 if (entryStartTime != null && entryEndTime != null && date != null && endDate != null) {
651 // check if we are between start and endtime
652 if ((date.getTime() < now.getTime()) && (now.getTime() < endDate.getTime())) {
653 date = now; // change appointment date/time to now
654 console.info('event is currently taking place: ' + date);
658 // skip events for the first panel in case this is the second one and we're not in fullscreen mode
659 if (mode ==
0 && panelNum
> 0 && counter < panelNum * config['eventsPerWidget'].Value +
1) {
660 console.info('skipping (already in first widget) ' + entry.id);
664 // mark overdue todos
666 if (entry.Type == 'ToDo' && date != null) {
667 var tmp1 = new Date(date.getFullYear(), date.getMonth(), date.getDate(),
0,
0,
0);
668 var tmp2 = new Date(now.getFullYear(), now.getMonth(), now.getDate(),
0,
0,
0);
669 if (tmp1.getTime() < tmp2.getTime()) {
674 // generate html output
675 entriesHtml += '
<tr><td><img class=
"icon" src=
"' + entry.Type + '.png" /></td>';
677 // some languages have very strange locale date formats, can't parse all those. Also some todos don't have dates at all.
678 entriesHtml += '
<td colspan=
"4"><span class=
"date">' + entryDate + '
</span> ';
680 var weekDay = date.toLocaleDateString().substr(
0,config['weekDayLength'].Value);
681 var time = formatTime(date);
682 var dateStr = formatDate(date, entryDate);
683 if (entry.Type == 'ToDo' && overdue && config['markOverdueTodos'].Value) {
684 dateStr = '
<span class=
"overdue">' + config['overdueText'].Value + '
</span>';
685 entriesHtml += '
<td colspan=
"4" width=
"1px"><span class=
"date">' + dateStr + '
</span> ';
686 } else if (entry.Type == 'ToDo' || entry.Type == 'Anniversary' || entry.Type == 'DayEvent' || entry.Type == 'Reminder') {
687 if ((isToday(date) || isTomorrow(date)) && config['showTodayAsText'].Value) // show weekday if the date string is not text. looks odd otherwise
688 entriesHtml += '
<td colspan=
"4" width=
"1px"><span class=
"date">' + dateStr + '
</span> ';
690 entriesHtml += '
<td class=
"weekDay" width=
"1px">' + weekDay + '
</td><td width=
"1px" class=
"date">' + dateStr + '
</td><td colspan=
"2">';
691 } else if (entry.Type == 'Meeting') {
692 if (config['showCombinedDateTime'].Value) {
694 entriesHtml += '
<td width=
"1px" colspan=
"4"><span class=
"today">' + time + '
</span> ';
695 else if (isTomorrow(date))
696 entriesHtml += '
<td width=
"1px" colspan=
"4"><span class=
"tomorrow">' + dateStr + '
</span> <span class=
"time">' + time + '
</span> ';
698 entriesHtml += '
<td width=
"1px" class=
"weekDay">' + weekDay + '
</td><td width=
"1px" class=
"date">' + dateStr + '
</td><td colspan=
"2">';
700 if ((isToday(date) || isTomorrow(date)) && config['showTodayAsText'].Value)
701 entriesHtml += '
<td colspan=
"4" width=
"1px"><span class=
"today">' + dateStr + '
</span> <span class=
"time">' + time + '
</span> ';
703 entriesHtml += '
<td width=
"1px" class=
"weekDay">' + weekDay + '
</td><td width=
"1px" class=
"date">' + dateStr + '
</td><td width=
"1px" class=
"time">' + time + '
</td><td>';
707 entriesHtml += '
<span class=
"description">' + Summary + '
</span></td></tr>';
710 entriesHtml += '
</table>';
711 if (config['showNothingText'].Value && entriesHtml == '
<table></table>') {
712 var text = config['nothingText'].Value.replace(/%d/, config['monthRange'].Value);
713 entriesHtml = '
<div style=
"width:295px; height:75px; text-align:center; line-height:75px; overflow:visible;">' + text + '
</div>';
715 if (cacheEntriesHtml != entriesHtml) {
717 document.getElementById('calendarList').innerHTML = entriesHtml;
719 document.getElementById('fullscreenCalendarList').innerHTML = entriesHtml;
720 cacheEntriesHtml = entriesHtml;
723 error('displaying list:' + e + ', line ' + e.line);
728 function updateScreen()
730 // check if opening fullscreen
731 if( window.innerHeight
> 91 && mode ==
0) {
733 cacheEntriesHtml = '';
734 document.getElementById('body').style.backgroundImage =
"";
737 else if (window.innerHeight <=
91 && mode !=
0) {
739 cacheEntriesHtml = '';
749 function launchCalendar()
752 widget.openApplication(config['calendarApp'].Value,
"");
753 if (config['hideWidgetOnCalendarOpen'].Value)
756 error('starting Calendar App');
763 console.info('New widget instance starting up...');
766 // call calendar service
767 if (device !=
"undefined")
768 calendarService = device.getServiceObject(
"Service.Calendar",
"IDataSource");
770 throw('device object does not exist');
772 error('loading Calendar service: ' + e + ', line ' + e.line);
776 calendarList = listCalendars();
780 requestNotification();
781 window.setInterval('updateData()',
1000 *
60 * config['updateDataInterval'].Value);
782 document.getElementById(
"settingsTitle").innerHTML = getLocalizedText('menu.settings');
784 if (window.innerHeight
> 91) {
785 mode =
0; // we're starting fullscreen, we set mode to homescreen in order to let updateScreen() do all the work for us
790 console.info(
"init(): updateScreen()");
792 if (config['useBackgroundImage'].Value)
793 // check for screen rotation every
1 secs
794 window.setInterval('updateScreen()',
1000 *
1);
795 console.info(
"init(): finished...");
798 function createMenu()
800 window.menu.setLeftSoftkeyLabel(
"",null);
801 window.menu.setRightSoftkeyLabel(
"",null);
803 var menuSettings = new MenuItem(getLocalizedText('menu.settings'), id++);
804 var menuCallApp = new MenuItem(getLocalizedText('menu.openCalendarApp'), id++);
805 var menuUpdate = new MenuItem(getLocalizedText('menu.update'), id++);
806 var menuAbout = new MenuItem(getLocalizedText('menu.about'), id++);
807 menuSettings.onSelect = showSettings;
808 menuAbout.onSelect = showAbout;
809 menuCallApp.onSelect = launchCalendar;
810 menuUpdate.onSelect = showUpdate;
812 window.menu.append(menuCallApp);
813 window.menu.append(menuSettings);
814 window.menu.append(menuUpdate);
815 window.menu.append(menuAbout);
818 function showSettings()
822 document.getElementById(
"settingsView").style.display =
"block";
823 document.onclick = null;
825 window.menu.setLeftSoftkeyLabel(getLocalizedText('settings.save'), function()
827 for (var key in config) {
828 if (config[key].Type == 'String')
829 config[key].Value = document.forms[
0].elements[
"settings." + key].value;
830 else if (config[key].Type == 'Int') {
831 config[key].Value = parseInt(document.forms[
0].elements[
"settings." + key].value);
832 if (config[key].Value <
0)
833 config[key].Value = config[key].Default;
835 else if (config[key].Type == 'Bool')
836 config[key].Value = document.forms[
0].elements[
"settings." + key].checked;
837 else if (config[key].Type == 'UID')
838 config[key].Value = parseInt(document.forms[
0].elements[
"settings." + key].value);
839 else if (config[key].Type == 'Enum') {
840 config[key].Value = document.forms[
0].elements[
"settings." + key].value;
841 if (config[key].ValidValues.indexOf(config[key].Value) == -
1)
842 config[key].Value = config[key].Default;
853 window.menu.setRightSoftkeyLabel(getLocalizedText('settings.cancel'), function()
859 var settingsHtml = '
<form>';
860 for (var key in config) {
861 if (config[key].Type == 'String') {
863 if (key.substring(
0,
9) ==
"cssStyle_")
864 prefix = getLocalizedText('settings.cssStyle_prefix');
865 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 />';
867 else if (config[key].Type == 'Int')
868 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 />';
869 else if (config[key].Type == 'Bool')
870 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 />';
871 else if (config[key].Type == 'UID')
872 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 />';
873 else if (config[key].Type == 'Enum') {
874 settingsHtml += '
<table><tr><td>' + getLocalizedText('settings.name.' + key) + '
<br /><select name=
"settings.' + key + '" size=
"1">';
875 for(var i =
0; i < config[key].ValidValues.length; i++)
876 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>';
877 settingsHtml += '
</select></div></td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '
<hr />';
880 settingsHtml += '
<input name=
"reset" type=
"button" value=
"' + getLocalizedText('settings.restoreDefaults') + '" onclick=
"javascript:restoreDefaultSettings();showSettings();" />';
881 settingsHtml += '
</form>';
882 document.getElementById(
"settingsList").innerHTML = settingsHtml;
885 function changeCssClass(classname, properties)
887 for(var i =
0; i < document.styleSheets[
0]['cssRules'].length; i++)
889 if (document.styleSheets[
0]['cssRules'][i].selectorText == classname) {
890 document.styleSheets[
0].deleteRule(i);
891 document.styleSheets[
0].insertRule(classname + ' { ' + properties + ' }', document.styleSheets[
0]['cssRules'].length);
897 function updateCssClasses()
899 for(var key in config) {
900 changeCssClass(getLocalizedText('settings.name.' + key), config[key].Value);
904 function getSettingsCalEntryId()
906 if (settingsCalEntryId == null) {
907 // check if entry already exists
908 var listFiltering = {
909 Type:'CalendarEntry',
911 StartRange: new Date(
2000,
0,
1),
912 EndRange: new Date(
2000,
0,
1),
913 SearchText: 'ComingNext Settings|',
917 var result = calendarService.IDataSource.GetList(listFiltering);
918 if (result.ErrorCode) {
919 error(result.ErrorMessage);
922 var list = result.ReturnValue;
923 var entry = list.getNext();
924 if (entry != undefined) {
925 settingsCalEntryId = entry.LocalId;
926 console.info(
"settingsCalEntryId=" + settingsCalEntryId);
928 else { // create settings item
929 var item = new Object();
930 item.Type =
"DayEvent";
931 item.StartTime = new Date(
2000,
0,
1);
932 item.Summary =
"ComingNext Settings|";
934 var criteria = new Object();
935 criteria.Type =
"CalendarEntry";
936 criteria.Item = item;
939 var result = calendarService.IDataSource.Add(criteria);
940 if (result.ErrorCode)
941 error(result.ErrorMessage);
943 error(
"getSettingsCalEntryId: " + e + ', line ' + e.line);
946 getSettingsCalEntryId();
951 function restoreDefaultSettings()
953 for (var key in config)
954 config[key].Value = config[key].Default;
957 function loadSettings()
959 getSettingsCalEntryId();
960 var listFiltering = {
961 Type:'CalendarEntry',
963 LocalId: settingsCalEntryId
966 var result = calendarService.IDataSource.GetList(listFiltering);
967 if (result.ErrorCode) {
968 error(result.ErrorMessage);
971 var entry = result.ReturnValue.getNext();
972 if (entry != undefined) {
973 console.info(
"Loading Settings...");
974 // only reload settings if they chanced since the last reload
975 if (settingsCache != entry.Summary)
977 restoreDefaultSettings();
978 var stringlist = entry.Summary.split(
"|");
979 // skip the first two entries, those contain header and version info
980 for(var i =
2; i < stringlist.length -
1; i++) {
981 var pair = stringlist[i].split('=');
984 console.info('stringlist: ' + key + '=\'' + value + '\'');
985 if (config[key].Type == 'Int')
986 config[key].Value = Number(value);
987 else if (config[key].Type == 'String')
988 config[key].Value = value;
989 else if (config[key].Type == 'Bool')
990 config[key].Value = (value == 'true')
991 else if (config[key].Type == 'Enum')
992 config[key].Value = value;
993 else if (config[key].Type == 'UID')
994 config[key].Value = Number(value);
996 settingsCache = entry.Summary;
1000 console.info(
"Settings already cached and did not change");
1004 error(
"Failed to load settings, calendar entry could not be found");
1008 function saveSettings()
1010 getSettingsCalEntryId();
1011 var item = new Object();
1012 item.Type =
"DayEvent";
1013 item.StartTime = new Date(
2000,
0,
1);
1014 item.LocalId = settingsCalEntryId;
1015 item.Summary =
"ComingNext Settings|" + version +
"|";
1017 for (var key in config) {
1018 if (config[key].Type == 'Int')
1019 item.Summary += key +
"=" + config[key].Value.toString() +
"|";
1020 else if (config[key].Type == 'String')
1021 item.Summary += key +
"=" + config[key].Value +
"|";
1022 else if (config[key].Type == 'Bool')
1023 item.Summary += key +
"=" + (config[key].Value ? 'true' : 'false') +
"|";
1024 else if (config[key].Type == 'Enum')
1025 item.Summary += key +
"=" + config[key].Value +
"|";
1026 else if (config[key].Type == 'UID')
1027 item.Summary += key +
"=" + config[key].Value.toString() +
"|";
1029 settingsCache = item.Summary;
1031 var criteria = new Object();
1032 criteria.Type =
"CalendarEntry";
1033 criteria.Item = item;
1035 console.info(
"Saving settings to calendar entry: " + item.Summary);
1037 var result = calendarService.IDataSource.Add(criteria);
1038 if (result.ErrorCode)
1039 error(result.ErrorMessage);
1041 error(
"saveSettings: " + e + ', line ' + e.line);
1045 function toggleVisibility(elementId)
1047 if (document.getElementById(elementId).style.display ==
"none")
1048 document.getElementById(elementId).style.display =
"block";
1050 document.getElementById(elementId).style.display =
"none";
1054 function printHintBox(text)
1057 return '
<td width=
"1%" align=
"right" onclick=
"javascript:toggleVisibility(\'info' + uniqueId + '\')">' + getLocalizedText('settings.help') + '
</td></tr></table>'+
1058 '
<div class=
"settingsInfo" id=
"info' + uniqueId + '">' + text + '
</div>';
1061 function showAbout()
1065 document.getElementById(
"aboutView").style.display =
"block";
1066 document.onclick = null;
1068 window.menu.setLeftSoftkeyLabel(
" ", function(){});
1069 window.menu.setRightSoftkeyLabel(getLocalizedText('softkey.back'), function()
1075 //document.getElementById(
"aboutView").innerHTML = 'aboutView';
1076 document.getElementById(
"name").innerHTML =
"Coming Next " + version;
1079 function updateFullscreen()
1083 function showFullscreen()
1085 console.info(
"showFullscreen()");
1087 document.getElementById(
"fullscreenView").style.display =
"block";
1088 document.getElementById('body').className =
"backgroundFullscreen";
1089 document.onclick = launchCalendar;
1094 function getBackgroundImage()
1097 if (config['backgroundImageLocation'].Value == config['backgroundImageLocation'].ValidValues[
0]) // internal
1098 bgImage = 'background_' + orientation + '.png';
1100 bgImage = 'C:/Data/background_' + panelNum + '_' + orientation + '.png';
1104 function updateHomescreen()
1106 if (config['useBackgroundImage'].Value) {
1107 // check for screen rotation
1108 if (orientation != 'portrait' && screen.width ==
360 && screen.height ==
640) {
1109 window.widget.prepareForTransition(
"fade");
1110 orientation = 'portrait';
1111 document.getElementById('body').style.backgroundImage = 'url(' + getBackgroundImage() + ')';
1112 document.getElementById('body').style.backgroundColor = 'none';
1113 window.widget.performTransition();
1114 } else if (orientation != 'landscape' && screen.width ==
640 && screen.height ==
360) {
1115 window.widget.prepareForTransition(
"fade");
1116 orientation = 'landscape';
1117 document.getElementById('body').style.backgroundImage = 'url(' + getBackgroundImage() + ')';
1118 document.getElementById('body').style.backgroundColor = 'none';
1119 window.widget.performTransition();
1121 else if (document.getElementById('body').style.backgroundImage ==
"")
1123 document.getElementById('body').style.backgroundImage = 'url(' + getBackgroundImage() + ')';
1128 function showHomescreen()
1130 console.info(
"showHomescreen()");
1132 document.getElementById(
"homescreenView").style.display =
"block";
1133 document.getElementById('body').className =
"background";
1134 document.onclick = null;
1138 function getLocalizedText(p_Txt)
1140 if (localizedText[p_Txt])
1141 return localizedText[p_Txt];
1143 return 'ERROR: missing translation for ' + p_Txt;
1146 function showUpdate()
1150 document.getElementById(
"updateView").style.display =
"block";
1151 document.onclick = null;
1153 window.menu.setLeftSoftkeyLabel(getLocalizedText('update.checknow'), function(){
1156 window.menu.setRightSoftkeyLabel(getLocalizedText('softkey.back'), function()
1162 document.getElementById(
"currentVersion").innerHTML = getLocalizedText(
"update.current") + version;
1166 function checkForUpdate()
1168 // asynch XHR to server url
1169 reqV = new XMLHttpRequest();
1170 reqV.onreadystatechange = checkForUpdateCallback;
1171 document.getElementById(
"updateDiv").innerHTML = getLocalizedText(
"update.checking");
1172 reqV.open(
"GET", versionURL, true);
1173 reqV.setRequestHeader(
"If-Modified-Since",
"Sat, 1 Jan 2000 00:00:00 GMT" ); // disable caching
1177 function checkForUpdateCallback()
1179 if (reqV.readyState ==
4) {
1180 if (reqV.status ==
200) {
1181 var resultXml = reqV.responseText;
1183 var div = document.getElementById(
"tmp");
1184 div.innerHTML = resultXml;
1185 var newVersion = div.getElementsByTagName('version')[
0].innerHTML;
1186 var newVersionURL = div.getElementsByTagName('url')[
0].innerHTML;
1188 if (version != newVersion) {
1189 document.getElementById(
"updateDiv").innerHTML = getLocalizedText(
"update.download").replace(/%
1/, newVersion).replace(/%
2/, newVersionURL);
1192 document.getElementById(
"updateDiv").innerHTML = getLocalizedText(
"update.nonewversion");
1197 document.getElementById(
"updateDiv").innerHTML = getLocalizedText(
"update.error") + reqV.status +
" " + reqV.responseText;
1202 function hideViews()
1204 document.getElementById(
"homescreenView").style.display =
"none";
1205 document.getElementById(
"fullscreenView").style.display =
"none";
1206 document.getElementById(
"aboutView").style.display =
"none";
1207 document.getElementById(
"settingsView").style.display =
"none";
1208 document.getElementById(
"updateView").style.display =
"none";
1211 function listCalendars()
1217 DefaultCalendar: false
1221 var calendarsResult = calendarService.IDataSource.GetList(criteria);
1222 if (calendarsResult.ErrorCode !=
0)
1223 throw(
"Error fetching list of calendars: " + calendarsResult.ErrorCode + ': ' + calendarsResult.ErrorMessage);
1224 var calendarListIterator = calendarsResult.ReturnValue;
1229 while (( item = calendarListIterator.getNext()) != undefined ) {
1230 calendars[count++] = item;
1232 console.info(
"Available Calendars: " + calendars.join(
", "));
1235 error('listing calendars:' + e + ', line ' + e.line);
1240 // Copies all objects and their properties to an array. Data is copied so nothing gets lost when the reference is removed
1241 function listToArray(list)
1243 var array = new Array();
1246 while (( item = list.getNext()) != undefined ) {
1247 var itemCopy = new Object();
1248 for(var i=
0; i < entryFields.length; i++) {
1249 itemCopy[entryFields[i]] = item[entryFields[i]];
1251 array.push(itemCopy);
1252 txt += array[array.length -
1].Summary +
", ";
1254 console.info(
"listToArray(): " + txt);
1258 function sortCalendarEntries(a, b)
1261 console.info(
"sortCalendarEntries(" + a.Summary +
"," + b.Summary +
")");
1263 if (a.InstanceStartTime != null) {
1264 atime = a.InstanceStartTime;
1266 else if (a.StartTime != null) {
1267 atime = a.StartTime;
1269 else if (a.InstanceEndTime != null) {
1270 atime = a.InstanceEndTime;
1272 else if (a.EndTime != null) {
1276 if (b.InstanceStartTime != null) {
1277 btime = b.InstanceStartTime;
1279 else if (b.StartTime != null) {
1280 btime = b.StartTime;
1282 else if (b.InstanceEndTime != null) {
1283 btime = b.InstanceEndTime;
1285 else if (b.EndTime != null) {
1289 if (atime && btime) {
1291 atime = parseDate(atime);
1292 btime = parseDate(btime);
1294 // sort by date & time
1295 if (atime < btime) {
1298 else if (atime
> btime) {
1302 else if (a.Type != b.Type) {
1303 if (a.Type < b.Type) {
1306 else if (a.Type
> b.Type) {
1310 // sort by description
1311 else if (a.Summary && b.Summary && a.Summary != b.Summary) {
1312 if (a.Summary < b.Summary) {
1315 else if (a.Summary
> b.Summary) {
1326 <style type=
"text/css">
1327 table { margin:
0px; padding:
0px; border-spacing:
0px; }
1328 td { padding:
0px
5px
0px
0px; white-space:nowrap; overflow:hidden; }
1329 hr { color:#ffffff; background-color:#ffffff; height:
1px; text-align:left; border-style:none; }
1330 .settingsInfo { display:none; font-style:italic; }
1331 .title { font-weight:bold; font-size:
14pt; }
1332 .textInput { width:
90%; }
1333 .credits { margin-left:
40px; text-indent: -
20px; margin-bottom:
0px; }
1334 #homescreenView { width:
315px; height:
91px; overflow:hidden; }
1335 #calendarList { position:absolute; left:
10px; top:
4px; width:
295px; height:
75px; overflow:hidden; }
1336 #name { text-align:center; }
1337 #appicon { display: block; margin-left: auto; margin-right: auto; margin-top:
10px; }
1338 #smallappicon { width:
22px; height:
22px; margin-right:
10px; float:left; }
1343 <body id=
"body" class=
"background">
1344 <div id=
"homescreenView">
1345 <div id=
"calendarList"></div>
1347 <div id=
"fullscreenView" style=
"display:none;">
1348 <img src=
"Icon.png" id=
"smallappicon">
1349 <h1 class=
"title">Coming Next
</h1>
1351 <div id=
"fullscreenCalendarList">loading...
</div>
1353 <div id=
"settingsView" style=
"display:none">
1354 <img src=
"Icon.png" id=
"smallappicon">
1355 <h1 id=
"settingsTitle" class=
"title">Settings
</h1>
1357 <div id=
"settingsList"></div>
1359 <div id=
"aboutView" style=
"display:none">
1360 <img src=
"Icon.png" id=
"appicon">
1361 <h1 id=
"name">Coming Next
</h1>
1363 <p>Created by Dr. Cochambre and Michael Prager.
</p>
1364 <p>Contributions:
</p>
1365 <p class=
"credits">Paul Moore (bug fixes, new features and code cleanup)
</p>
1366 <p class=
"credits">Manfred Hanselmann (DST support)
</p>
1367 <p class=
"credits">Christophe Milsent (translation support & french translation)
</p>
1368 <p class=
"credits">Flavio Nathan (portuguese-brazilian translation)
</p>
1369 <p class=
"credits">Tokeda (russian translation)
</p>
1370 <p>This software is open source and licensed under the GPLv3.
</p>
1371 <p>Visit sourceforge.net/projects/comingnext for free updates.
</p>
1374 <div id=
"updateView" style=
"display:none">
1375 <img src=
"Icon.png" id=
"smallappicon">
1376 <h1 class=
"title">Check for update
</h1>
1378 <div id=
"currentVersion">Coming Next ??
</div>
1379 <div id=
"updateDiv"></div>
1380 <div id=
"tmp" style=
"display:none;"></div>