+\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
+// Copies all objects and their properties to an array. Data is copied so nothing gets lost when the reference is removed\r
+// Note: this will also set the "CalendarName" property of every entry to the name specified by the calendarName parameter if it has not been defined already\r
+function listToArray(list, calendarName)\r
+{\r
+ var array = new Array();\r
+ var item;\r
+ var txt = "";\r
+ while (( item = list.getNext()) != undefined ) {\r
+ var itemCopy = new Object();\r
+ for(var i=0; i < entryFields.length; i++) {\r
+ itemCopy[entryFields[i]] = item[entryFields[i]];\r
+ }\r
+ // for some reason, the CalendarName property is never correctly queried, so we assign it manually here\r
+ if (!itemCopy['CalendarName']) {\r
+ itemCopy['CalendarName'] = calendarName;\r
+ }\r
+ array.push(itemCopy);\r
+ txt += array[array.length - 1].Summary + ", ";\r
+ }\r
+ console.info("listToArray(): " + txt);\r
+ return array;\r
+}\r
+\r
+function sortCalendarEntries(a, b)\r
+{\r
+ var atime, btime;\r
+ console.info("sortCalendarEntries(" + a.Summary + "," + b.Summary + ")");\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
+\r
+function updateCalendarColors()\r
+{\r
+ var maxColors = 6;\r
+ calendarColors = [];\r
+ if (calendarList.length > maxColors) {\r
+ console.info("updateCalendarColors(): Warning: more calendars than available indicator colors");\r
+ }\r
+ for(var i=0; i < calendarList.length; i++) {\r
+ calendarColors[calendarList[i]] = (i % maxColors) + 1;\r
+ }\r
+}\r
+\r