]> code.delx.au - comingnext/commitdiff
added support for multiple calendars (Symbian^3 and N8 make use of those)
authorMichael Prager <michael@pragers.de>
Sun, 10 Oct 2010 20:45:59 +0000 (22:45 +0200)
committerMichael Prager <michael@pragers.de>
Sun, 10 Oct 2010 20:45:59 +0000 (22:45 +0200)
comingNext/index.html

index dde6a7afcb895eb1a31e7bc74b646ac76e2c1be3..459441c5f3d64b5094669b5cc95f6b8886739ea9 100644 (file)
@@ -80,6 +80,7 @@ var settingsCalEntryId = null;
 var settingsCache = null;\r
 var notificationRequest1;\r
 var notificationRequest2;\r
+var calendarList = [];\r
 \r
 // vars for daylight saving time\r
 var daylightsavingWinter = 0;\r
@@ -458,31 +459,43 @@ function updateData()
                // meetings have time\r
                // 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\r
                now = new Date();\r
-               var meetingListFiltering = {\r
-                       Type:'CalendarEntry',\r
-                       Filter:{\r
-                               StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)),\r
-                               EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(), 0, 0, 0))\r
+               var meetingList = [];\r
+               for(var i=0; i < calendarList.length; i++) {\r
+                       var meetingListFiltering = {\r
+                               Type:'CalendarEntry',\r
+                               Filter:{\r
+                                       CalendarName: calendarList[i],\r
+                                       StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)),\r
+                                       EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(), 0, 0, 0))\r
+                               }\r
                        }\r
+                       var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering);\r
+                       if (meetingResult.ErrorCode != 0)\r
+                               throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage);\r
+                       var list = meetingResult.ReturnValue;\r
+                       meetingList = meetingList.concat(listToArray(list));\r
                }\r
-               var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering);\r
-               if (meetingResult.ErrorCode != 0)\r
-                       throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage);\r
-               var meetingList = meetingResult.ReturnValue;\r
+               meetingList.sort(sortCalendarEntries);\r
 \r
                // todos don't, they start on 00:00 hrs., but should be visible anyway\r
                // this will generate a list of passed todos. We have to check if they have been marked as "done" yet\r
                if (config['includeTodos'].Value) {\r
-                       var todayTodoListFiltering = {\r
-                               Type:'CalendarEntry',\r
-                               Filter:{\r
-                                       Type: 'ToDo',\r
-                                       StartRange: (new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)),\r
-                                       EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1))\r
+                       var todayTodoList = [];\r
+                       for(var i=0; i < calendarList.length; i++) {\r
+                               var todayTodoListFiltering = {\r
+                                       Type:'CalendarEntry',\r
+                                       Filter:{\r
+                                               CalendarName: calendarList[i],\r
+                                               Type: 'ToDo',\r
+                                               StartRange: (new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)),\r
+                                               EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1))\r
+                                       }\r
                                }\r
+                               var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);\r
+                               var list = todayTodoResult.ReturnValue;\r
+                               todayTodoList = todayTodoList.concat(listToArray(list));\r
                        }\r
-                       var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);\r
-                       var todayTodoList = todayTodoResult.ReturnValue;\r
+                       todayTodoList.sort(sortCalendarEntries);\r
                        var entryLists = [todayTodoList, meetingList];\r
                } else {\r
                        var entryLists = [meetingList];\r
@@ -524,7 +537,8 @@ function updateData()
 \r
                // the first outer loop iteration is for passed ToDos, the second loop is for all upcomming events (may also include ToDos)\r
                for (var i=0; counter < max && i < entryLists.length; i++) {\r
-                       while (counter < max && (entry = entryLists[i].getNext()) != undefined) {\r
+                       for (var j=0; (counter < max) && (j < entryLists[i].length); j++) {\r
+                               entry = entryLists[i][j];\r
                                counter++;\r
 \r
                                // output event info for debugging\r
@@ -737,6 +751,7 @@ function init()
                return;\r
        }\r
 \r
+       calendarList = listCalendars();\r
        loadSettings();\r
        collectLocales();\r
        //updateData();\r
@@ -1158,6 +1173,110 @@ function hideViews()
        document.getElementById("settingsView").style.display = "none";\r
        document.getElementById("updateView").style.display = "none";\r
 }\r
+\r
+function listCalendars()\r
+{\r
+       try {\r
+               var criteria = {\r
+                       Type:'Calendar', \r
+                       Filter:{\r
+                               DefaultCalendar: false\r
+                       }\r
+               }\r
+               \r
+               var calendarsResult = calendarService.IDataSource.GetList(criteria);\r
+               if (calendarsResult.ErrorCode != 0)\r
+                       throw("Error fetching list of calendars: " + calendarsResult.ErrorCode + ': ' + calendarsResult.ErrorMessage);\r
+               var calendarListIterator = calendarsResult.ReturnValue;\r
+               \r
+               var calendars = [];\r
+               var count = 0;\r
+               var item;\r
+               while (( item = calendarListIterator.getNext()) != undefined ) {\r
+                       calendars[count++] = item;\r
+               }\r
+               console.info("Available Calendars: " + calendars.join(", "));\r
+               return calendars;\r
+       } catch(e) {\r
+               error('listing calendars:' + e + ', line ' + e.line);\r
+               return null;\r
+       }\r
+}\r
+\r
+function listToArray(list)\r
+{\r
+       var array = [];\r
+       var item;\r
+       while (( item = list.getNext()) != undefined ) {\r
+               array.push(item);\r
+       }\r
+       return array;\r
+}\r
+\r
+function sortCalendarEntries(a, b)\r
+{\r
+       var atime, btime;\r
+       \r
+       if (a['InstanceStartTime'] != null) {\r
+               atime = a['InstanceStartTime'];\r
+       }\r
+       else if (a['StartTime'] != null) {\r
+               atime = a['StartTime'];\r
+       }\r
+       else if (a['InstanceEndTime'] != null) {\r
+               atime = a['InstanceEndTime'];\r
+       }\r
+       else if (a['EndTime'] != null) {\r
+               atime = a['EndTime'];\r
+       }\r
+       \r
+       if (b['InstanceStartTime'] != null) {\r
+               btime = b['InstanceStartTime'];\r
+       }\r
+       else if (b['StartTime'] != null) {\r
+               btime = b['StartTime'];\r
+       }\r
+       else if (b['InstanceEndTime'] != null) {\r
+               btime = b['InstanceEndTime'];\r
+       }\r
+       else if (b['EndTime'] != null) {\r
+               btime = b['EndTime'];\r
+       }\r
+       \r
+       if (atime && btime) {\r
+       \r
+               atime = parseDate(atime);\r
+               btime = parseDate(btime);\r
+       \r
+               // sort by date & time\r
+               if (atime < btime) {\r
+                       return -1;\r
+               }\r
+               else if (atime > btime) {\r
+                       return 1;\r
+               }\r
+               // sort by type\r
+               else if (a['Type'] != b['Type']) {\r
+                       if (a['Type'] < b['Type']) {\r
+                               return -1;\r
+                       }\r
+                       else if (a['Type'] > b['Type']) {\r
+                               return 1;\r
+                       }\r
+               }\r
+               // sort by description\r
+               else if (a['Summary'] && b['Summary'] && a['Summary'] != b['Summary']) {\r
+                       if (a['Summary'] < b['Summary']) {\r
+                               return -1;\r
+                       }\r
+                       else if (a['Summary'] > b['Summary']) {\r
+                               return 1;\r
+                       }\r
+               }               \r
+       }\r
+\r
+       return 0;\r
+}\r
 </script>\r
 \r
 <style type="text/css">\r