From 3a8ae3ed904a6bccf63a4d694324d93e5f0a34fd Mon Sep 17 00:00:00 2001 From: Michael Prager Date: Sun, 10 Oct 2010 22:45:59 +0200 Subject: [PATCH] added support for multiple calendars (Symbian^3 and N8 make use of those) --- comingNext/index.html | 155 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 137 insertions(+), 18 deletions(-) diff --git a/comingNext/index.html b/comingNext/index.html index dde6a7a..459441c 100644 --- a/comingNext/index.html +++ b/comingNext/index.html @@ -80,6 +80,7 @@ var settingsCalEntryId = null; var settingsCache = null; var notificationRequest1; var notificationRequest2; +var calendarList = []; // vars for daylight saving time var daylightsavingWinter = 0; @@ -458,31 +459,43 @@ function updateData() // 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(); - var meetingListFiltering = { - Type:'CalendarEntry', - Filter:{ - 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 meetingList = []; + for(var i=0; i < calendarList.length; i++) { + 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)); } - var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering); - if (meetingResult.ErrorCode != 0) - throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage); - var meetingList = meetingResult.ReturnValue; + 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 todayTodoListFiltering = { - Type:'CalendarEntry', - Filter:{ - 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 todayTodoList = []; + for(var i=0; i < calendarList.length; i++) { + 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)); } - var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering); - var todayTodoList = todayTodoResult.ReturnValue; + todayTodoList.sort(sortCalendarEntries); var entryLists = [todayTodoList, meetingList]; } else { var entryLists = [meetingList]; @@ -524,7 +537,8 @@ function updateData() // 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++) { - while (counter < max && (entry = entryLists[i].getNext()) != undefined) { + for (var j=0; (counter < max) && (j < entryLists[i].length); j++) { + entry = entryLists[i][j]; counter++; // output event info for debugging @@ -737,6 +751,7 @@ function init() return; } + calendarList = listCalendars(); loadSettings(); collectLocales(); //updateData(); @@ -1158,6 +1173,110 @@ function hideViews() document.getElementById("settingsView").style.display = "none"; document.getElementById("updateView").style.display = "none"; } + +function listCalendars() +{ + try { + var criteria = { + Type:'Calendar', + Filter:{ + DefaultCalendar: false + } + } + + var calendarsResult = calendarService.IDataSource.GetList(criteria); + if (calendarsResult.ErrorCode != 0) + throw("Error fetching list of calendars: " + calendarsResult.ErrorCode + ': ' + calendarsResult.ErrorMessage); + var calendarListIterator = calendarsResult.ReturnValue; + + var calendars = []; + var count = 0; + var item; + while (( item = calendarListIterator.getNext()) != undefined ) { + calendars[count++] = item; + } + console.info("Available Calendars: " + calendars.join(", ")); + return calendars; + } catch(e) { + error('listing calendars:' + e + ', line ' + e.line); + return null; + } +} + +function listToArray(list) +{ + var array = []; + var item; + while (( item = list.getNext()) != undefined ) { + array.push(item); + } + return array; +} + +function sortCalendarEntries(a, b) +{ + var atime, btime; + + if (a['InstanceStartTime'] != null) { + atime = a['InstanceStartTime']; + } + else if (a['StartTime'] != null) { + atime = a['StartTime']; + } + else if (a['InstanceEndTime'] != null) { + atime = a['InstanceEndTime']; + } + else if (a['EndTime'] != null) { + atime = a['EndTime']; + } + + if (b['InstanceStartTime'] != null) { + btime = b['InstanceStartTime']; + } + else if (b['StartTime'] != null) { + btime = b['StartTime']; + } + else if (b['InstanceEndTime'] != null) { + btime = b['InstanceEndTime']; + } + else if (b['EndTime'] != null) { + btime = b['EndTime']; + } + + if (atime && btime) { + + atime = parseDate(atime); + btime = parseDate(btime); + + // sort by date & time + if (atime < btime) { + return -1; + } + else if (atime > btime) { + return 1; + } + // sort by type + else if (a['Type'] != b['Type']) { + if (a['Type'] < b['Type']) { + return -1; + } + else if (a['Type'] > b['Type']) { + return 1; + } + } + // sort by description + else if (a['Summary'] && b['Summary'] && a['Summary'] != b['Summary']) { + if (a['Summary'] < b['Summary']) { + return -1; + } + else if (a['Summary'] > b['Summary']) { + return 1; + } + } + } + + return 0; +}