]> code.delx.au - comingnext/blobdiff - comingNext/index.html
Revert "added NaN validation check for settings with numbers"
[comingnext] / comingNext / index.html
index d66fd2917a992e14c4f05b49760e00b20ac8ea1c..7e774b94776fc97fb990360e248f64f20c02d9f6 100644 (file)
 .description { }\r
 .icon { }\r
 .overdue {}\r
+.calendar1 {}\r
+.calendar2 {}\r
+.calendar3 {}\r
+.calendar4 {}\r
+.calendar5 {}\r
+.calendar6 {}\r
 </style>\r
 \r
 <script type="text/javascript" src="localizedTextStrings.js" charset="utf-8" />\r
 \r
 <script>\r
-// valid types for the config object are 'Int', 'Bool', 'String', 'Enum', 'UID'\r
+// valid types for the config object are 'Int', 'Bool', 'String', 'Enum', 'UID', 'Array'\r
 var config = {\r
        monthRange: { Type: 'Int', Default: 2, Value: 2,},\r
        includeTodos: { Type: 'Bool', Default: true, Value: true,},\r
@@ -49,6 +55,8 @@ var config = {
        enableDaylightSaving: { Type: 'Bool', Default: true, Value: true,},\r
        daylightSavingOffset: { Type: 'Int', Default: 1, Value: 1,},\r
        hideWidgetOnCalendarOpen: { Type: 'Bool', Default: false, Value: false,},\r
+       showCalendarIndicator: { Type: 'Bool', Default: true, Value: true,},\r
+       excludedCalendars: { Type: 'Array', Default: [], Value: [],},\r
        cssStyle_background: { Type: 'String', Default: 'color:#ffffff; background-color:#000000', Value: 'color:#ffffff; background-color:#000000',},\r
        cssStyle_backgroundFullscreen: { Type: 'String', Default: 'color:#ffffff; background-color:#000000', Value: 'color:#ffffff; background-color:#000000',},\r
        cssStyle_weekDay: { Type: 'String', Default: '', Value: '',},\r
@@ -60,6 +68,12 @@ var config = {
        cssStyle_description: { Type: 'String', Default: '', Value: '',},\r
        cssStyle_icon: { Type: 'String', Default: 'width:15px; height:15px', Value: 'width:15px; height:15px',},\r
        cssStyle_overdue: { Type: 'String', Default: 'color:#ffff00', Value: 'color:#ffff00',},\r
+       cssStyle_calendar1: { Type: 'String', Default: 'background-color:#0757cf', Value: 'background-color:#0757cf',},\r
+       cssStyle_calendar2: { Type: 'String', Default: 'background-color:#579f37', Value: 'background-color:#579f37',},\r
+       cssStyle_calendar3: { Type: 'String', Default: 'background-color:#ff9f07', Value: 'background-color:#ff9f07',},\r
+       cssStyle_calendar4: { Type: 'String', Default: 'background-color:#af8fef', Value: 'background-color:#af8fef',},\r
+       cssStyle_calendar5: { Type: 'String', Default: 'background-color:#57afbf', Value: 'background-color:#57afbf',},\r
+       cssStyle_calendar6: { Type: 'String', Default: 'background-color:#9fdf57', Value: 'background-color:#9fdf57',},\r
 }\r
 \r
 \r
@@ -68,7 +82,7 @@ var config = {
 // Nothing of interest from here on...\r
 //-------------------------------------------------------\r
 var panelNum = 0; // use 1 for second panel\r
-var version = "1.29";\r
+var version = "1.31";\r
 var versionURL = "http://comingnext.sourceforge.net/version.xml";\r
 var calendarService = null;\r
 var cacheEntriesHtml = [];\r
@@ -79,9 +93,13 @@ var mode = 0; // 0 = homescreen, 1 = fullscreen, 2 = settings, 3 = about, 4 = ch
 var reqV = null; \r
 var settingsCalEntryId = null;\r
 var settingsCache = null;\r
-var notificationRequest1;\r
-var notificationRequest2;\r
+var notificationRequests = new Array();\r
 var calendarList = [];\r
+var calendarColors = [];\r
+var updateTimer = null;\r
+var screenRotationTimer = null;\r
+var lastUpdateTime = now;\r
+var errorOccured = false;\r
 \r
 // vars for daylight saving time\r
 var summertime = false; // true, if current date is in summer, false if in winter\r
@@ -91,6 +109,7 @@ var daylightSavingDates = new Object(); // caches calculated DST winter and summ
 var entryFields = [\r
        "id",\r
        "Type",\r
+       "CalendarName",\r
        "Summary",\r
        "Location",\r
        "Status",\r
@@ -175,6 +194,9 @@ function error(message)
 {\r
        console.info('Error: ' + message);\r
        document.getElementById("calendarList").innerHTML = 'Error: ' + message;\r
+       document.getElementById("fullscreenCalendarList").innerHTML = 'Error: ' + message;\r
+       errorOccured = true;\r
+       document.onclick = null;\r
 }\r
 \r
 function areDatesEqual(date1, date2)\r
@@ -298,13 +320,17 @@ function requestNotification()
 {\r
        var criteria = new Object();\r
        criteria.Type = "CalendarEntry";\r
-\r
-       try {\r
-               notificationRequest1 = calendarService.IDataSource.RequestNotification(criteria, callback);\r
-               if (notificationRequest1.ErrorCode)\r
-                       error('requestNotification failed with error code ' + notificationRequest1.ErrorCode);\r
-       } catch (e) {\r
-               error("requestNotification: " + e + ', line ' + e.line);\r
+       criteria.Filter = new Object();\r
+       for(var i=0; i < calendarList.length; i++) {\r
+               criteria.Filter.CalendarName = calendarList[i];\r
+               try {\r
+                       var notificationRequest = calendarService.IDataSource.RequestNotification(criteria, callback);\r
+                       if (notificationRequest.ErrorCode)\r
+                               error('requestNotification failed with error code ' + notificationRequest.ErrorCode);\r
+                       notificationRequests.push(notificationRequest);\r
+               } catch (e) {\r
+                       error("requestNotification: " + e + ', line ' + e.line);\r
+               }\r
        }\r
 \r
        var criteria2 = new Object();\r
@@ -312,16 +338,29 @@ function requestNotification()
        criteria2.Filter = new Object();\r
        criteria2.Filter.LocalIdList = new Array();\r
        criteria2.Filter.LocalIdList[0] = settingsCalEntryId;\r
-\r
        try {\r
-               notificationRequest2 = calendarService.IDataSource.RequestNotification(criteria2, settingsCallback);\r
-               if (notificationRequest2.ErrorCode)\r
-                       error('requestNotification failed with error code ' + notificationRequest2.ErrorCode);\r
+               var notificationRequest = calendarService.IDataSource.RequestNotification(criteria2, settingsCallback);\r
+               if (notificationRequest.ErrorCode)\r
+                       error('requestNotification failed with error code ' + notificationRequest.ErrorCode);\r
+               notificationRequests.push(notificationRequest);\r
        } catch (e) {\r
                error("requestNotification: " + e + ', line ' + e.line);\r
        }\r
 }\r
 \r
+function cancelNotification()\r
+{\r
+       for(var i=0; i < notificationRequests.length; i++) {\r
+               try {\r
+                       var result = calendarService.IDataSource.Cancel(notificationRequests[i]);\r
+                       if (result.ErrorCode)\r
+                               error('cancelNotification failed with error code ' + result.ErrorCode);\r
+               } catch (e) {\r
+                       error("cancelNotification: " + e + ', line ' + e.line);\r
+               }\r
+       }\r
+}\r
+\r
 function callback(transId, eventCode, result)\r
 {\r
        console.info("callback(): panelNum: %d  transId: %d  eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode);\r
@@ -480,6 +519,19 @@ function formatTime(date)
 function updateData()\r
 {\r
        console.info('updateData()');\r
+       if (errorOccured) {\r
+               return;\r
+       }\r
+\r
+       // check if we got additional or less calendars since our last update\r
+       var newCalendarList = listCalendars();\r
+       if (newCalendarList.length != calendarList.length) {\r
+               calendarList = newCalendarList;\r
+               updateCalendarColors();\r
+               cancelNotification();\r
+               requestNotification();\r
+       }\r
+       \r
        try {\r
                // 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
@@ -487,6 +539,9 @@ function updateData()
                summertime = isSummertime(now); // cache summer time info for today\r
                var meetingList = [];\r
                for(var i=0; i < calendarList.length; i++) {\r
+                       // ignore excluded calendars\r
+                       if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1)\r
+                               continue;\r
                        var meetingListFiltering = {\r
                                Type:'CalendarEntry',\r
                                Filter:{\r
@@ -499,7 +554,7 @@ function updateData()
                        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
+                       meetingList = meetingList.concat(listToArray(list, calendarList[i]));\r
                }\r
                console.info("updateData(): meetingList.sort()");\r
                meetingList.sort(sortCalendarEntries);\r
@@ -509,6 +564,9 @@ function updateData()
                if (config['includeTodos'].Value) {\r
                        var todayTodoList = [];\r
                        for(var i=0; i < calendarList.length; i++) {\r
+                               // ignore excluded calendars\r
+                               if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1)\r
+                                       continue;\r
                                var todayTodoListFiltering = {\r
                                        Type:'CalendarEntry',\r
                                        Filter:{\r
@@ -520,7 +578,7 @@ function updateData()
                                }\r
                                var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering);\r
                                var list = todayTodoResult.ReturnValue;\r
-                               todayTodoList = todayTodoList.concat(listToArray(list));\r
+                               todayTodoList = todayTodoList.concat(listToArray(list, calendarList[i]));\r
                        }\r
                        console.info("updateData(): todayTodoList.sort()");\r
                        todayTodoList.sort(sortCalendarEntries);\r
@@ -685,7 +743,11 @@ function updateData()
                                }\r
 \r
                                // generate html output\r
-                               entriesHtml += '<tr><td><img class="icon" src="' + entry.Type + '.png" /></td>';\r
+                               entriesHtml += '<tr>';\r
+                               if (config['showCalendarIndicator'].Value && calendarList.length - config['excludedCalendars'].Value.length > 1) {\r
+                                       entriesHtml += '<td><span class="calendar' + calendarColors[entry.CalendarName] + '">&nbsp;</span></td>';\r
+                               }\r
+                               entriesHtml += '<td><img class="icon" src="' + entry.Type + '.png" /></td>';\r
                                if(date == null) {\r
                                        // some languages have very strange locale date formats, can't parse all those. Also some todos don't have dates at all.\r
                                        entriesHtml += '<td colspan="4"><span class="date">' + entryDate + '</span> ';\r
@@ -732,6 +794,8 @@ function updateData()
                                document.getElementById('fullscreenCalendarList').innerHTML = entriesHtml;\r
                        cacheEntriesHtml = entriesHtml;\r
                }\r
+               \r
+               lastUpdateTime = new Date();\r
        } catch(e) {\r
                error('displaying list:' + e + ', line ' + e.line);\r
                return;\r
@@ -757,6 +821,14 @@ function updateScreen()
                updateHomescreen();\r
        else if (mode == 1)\r
                updateFullscreen();\r
+       \r
+       var time = new Date();\r
+       if (time.getTime() - lastUpdateTime.getTime() > config['updateDataInterval'].Value * 60 * 1000) {\r
+               console.info('updateScreen(): force updateData() because last update was too long ago (' + (time.getTime() - lastUpdateTime.getTime()) / 1000 + 's)');\r
+               clearUpdateTimer();\r
+               updateData();\r
+               setUpdateTimer(); // reinitialize update timer\r
+       }\r
 }\r
 \r
 function launchCalendar()\r
@@ -782,18 +854,18 @@ function init()
                else\r
                        throw('device object does not exist');\r
        } catch(e) {\r
-               error('loading Calendar service: ' + e + ', line ' + e.line);\r
-               return;\r
+               error('loading Calendar service: ' + e + ', line ' + e.line + '<br /><a onclick="widget.openURL(\'http://comingnext.sf.net/help\'); return false;" href="http://comingnext.sf.net/help">' + getLocalizedText('menu.help') + '</a>');\r
+               //return;\r
        }\r
 \r
        calendarList = listCalendars();\r
        loadSettings();\r
+       updateCalendarColors();\r
        collectLocales();\r
        //updateData();\r
        requestNotification();\r
-       window.setInterval('updateData()', 1000 * 60 * config['updateDataInterval'].Value);\r
        document.getElementById("settingsTitle").innerHTML = getLocalizedText('menu.settings');\r
-\r
+       setUpdateTimer();\r
        if (window.innerHeight > 91) {\r
                mode = 0; // we're starting fullscreen, we set mode to homescreen in order to let updateScreen() do all the work for us\r
        }\r
@@ -804,10 +876,26 @@ function init()
        updateScreen();\r
        if (config['useBackgroundImage'].Value)\r
                // check for screen rotation every 1 secs\r
-               window.setInterval('updateScreen()', 1000 * 1);\r
+               screenRotationTimer = window.setInterval('updateScreen()', 1000 * 1);\r
        console.info("init(): finished...");\r
 }\r
 \r
+function setUpdateTimer()\r
+{\r
+       updateTimer = window.setInterval('updateTimerCallback()', 1000 * 60 * config['updateDataInterval'].Value);\r
+}\r
+\r
+function clearUpdateTimer() \r
+{\r
+       window.clearInterval(updateTimer);\r
+}\r
+\r
+function updateTimerCallback()\r
+{\r
+       console.info("updateTimerCallback()");\r
+       updateData();\r
+}\r
+\r
 function createMenu()\r
 {\r
        window.menu.setLeftSoftkeyLabel("",null);\r
@@ -815,15 +903,18 @@ function createMenu()
        var id = 0;\r
        var menuSettings = new MenuItem(getLocalizedText('menu.settings'), id++);\r
        var menuCallApp = new MenuItem(getLocalizedText('menu.openCalendarApp'), id++);\r
+       var menuHelp = new MenuItem(getLocalizedText('menu.help'), id++);\r
        var menuUpdate = new MenuItem(getLocalizedText('menu.update'), id++);\r
        var menuAbout = new MenuItem(getLocalizedText('menu.about'), id++);\r
        menuSettings.onSelect = showSettings;\r
        menuAbout.onSelect = showAbout;\r
        menuCallApp.onSelect = launchCalendar;\r
        menuUpdate.onSelect = showUpdate;\r
+       menuHelp.onSelect = showHelp;\r
        window.menu.clear();\r
        window.menu.append(menuCallApp);\r
        window.menu.append(menuSettings);\r
+       window.menu.append(menuHelp);\r
        window.menu.append(menuUpdate);\r
        window.menu.append(menuAbout);  \r
 }\r
@@ -854,6 +945,16 @@ function showSettings()
                                if (config[key].ValidValues.indexOf(config[key].Value) == -1)\r
                                        config[key].Value = config[key].Default;\r
                        }\r
+                       else if (config[key].Type == 'Array') {\r
+                               if (key == 'excludedCalendars') {\r
+                                       config[key].Value = new Array();\r
+                                       for(var i=0; i < calendarList.length; i++) {\r
+                                               var element = document.forms[0].elements["settings." + key + "." + calendarList[i]];\r
+                                               if (element != null && element.checked == false)\r
+                                                       config[key].Value.push(calendarList[i]);\r
+                                       }\r
+                               }\r
+                       }\r
                }\r
                                \r
                updateCssClasses();\r
@@ -889,6 +990,18 @@ function showSettings()
                                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>';\r
                        settingsHtml += '</select></div></td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '<hr />';\r
                }\r
+               else if (config[key].Type == 'Array') {\r
+                       settingsHtml += '<table><tr><td>' + getLocalizedText('settings.name.' + key) + '<br />';\r
+                       if (key == 'excludedCalendars') {\r
+                               for(var i=0; i < calendarList.length; i++) {\r
+                                       var checked = 'checked="checked"';\r
+                                       if (config[key].Value.indexOf(calendarList[i]) != -1)\r
+                                               checked = '';\r
+                                       settingsHtml += '<input name="settings.' + key + '.' + calendarList[i] + '" type="checkbox" value="' + calendarList[i] + '" ' + checked + '/> ' + calendarList[i] + '<br />';\r
+                               }\r
+                       }\r
+                       settingsHtml += '</td>' + printHintBox(getLocalizedText('settings.info.' + key)) + '<hr />';\r
+               }\r
        }\r
        settingsHtml += '<input name="reset" type="button" value="' + getLocalizedText('settings.restoreDefaults') + '" onclick="javascript:restoreDefaultSettings();showSettings();" />';\r
        settingsHtml += '</form>';\r
@@ -1005,6 +1118,12 @@ function loadSettings()
                                        config[key].Value = value;\r
                                else if (config[key].Type == 'UID')\r
                                        config[key].Value = Number(value);\r
+                               else if (config[key].Type == 'Array') {\r
+                                       config[key].Value = value.split("^");\r
+                                       if (config[key].Value.length == 1 && config[key].Value[0] == "") {\r
+                                               config[key].Value = [];\r
+                                       }\r
+                               }\r
                        }\r
                        settingsCache = entry.Summary;\r
                        updateCssClasses();\r
@@ -1038,6 +1157,8 @@ function saveSettings()
                        item.Summary += key + "=" + config[key].Value + "|";\r
                else if (config[key].Type == 'UID')\r
                        item.Summary += key + "=" + config[key].Value.toString() + "|";\r
+               else if (config[key].Type == 'Array')\r
+                       item.Summary += key + "=" + config[key].Value.join("^") + "|";\r
        }\r
        settingsCache = item.Summary;\r
        \r
@@ -1053,6 +1174,9 @@ function saveSettings()
        } catch (e) {\r
                error("saveSettings: " + e + ', line ' + e.line);\r
        }\r
+       \r
+       clearUpdateTimer();\r
+       setUpdateTimer();\r
 }\r
 \r
 function toggleVisibility(elementId)\r
@@ -1089,6 +1213,10 @@ function showAbout()
        document.getElementById("name").innerHTML = "Coming Next " + version;\r
 }\r
 \r
+function showHelp() {\r
+       widget.openURL('http://comingnext.sf.net/help');\r
+}\r
+\r
 function updateFullscreen()\r
 {\r
 }\r
@@ -1099,13 +1227,16 @@ function showFullscreen()
        hideViews();\r
        document.getElementById("fullscreenView").style.display = "block";\r
        document.getElementById('body').className = "backgroundFullscreen";\r
-       document.onclick = launchCalendar;\r
+       if (!errorOccured)\r
+               document.onclick = launchCalendar;\r
        createMenu();\r
        updateData();\r
 }\r
 \r
 function getBackgroundImage()\r
 {\r
+       if (errorOccured)\r
+               return '';\r
        var bgImage;\r
        if (config['backgroundImageLocation'].Value == config['backgroundImageLocation'].ValidValues[0]) // internal\r
                bgImage = 'background_' + orientation + '.png';\r
@@ -1251,7 +1382,8 @@ function listCalendars()
 }\r
 \r
 // Copies all objects and their properties to an array. Data is copied so nothing gets lost when the reference is removed\r
-function listToArray(list)\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
@@ -1261,6 +1393,10 @@ function listToArray(list)
                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
@@ -1330,13 +1466,53 @@ function sortCalendarEntries(a, b)
                        }\r
                }\r
        }\r
+       // NOTE: events my have no date information at all. In that case, we list events without date first\r
+       else if (atime && !btime) {\r
+               return 1;\r
+       }\r
+       else if (!atime && btime) {\r
+               return -1;\r
+       }\r
+       else if (!atime && !btime) {\r
+               // sort by type\r
+               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
 </script>\r
 \r
 <style type="text/css">\r
+a { color:#aaccff }\r
 table { margin:0px; padding:0px; border-spacing:0px; }\r
 td { padding:0px 5px 0px 0px; white-space:nowrap; overflow:hidden; }\r
 hr { color:#ffffff; background-color:#ffffff; height:1px; text-align:left; border-style:none; }\r
@@ -1345,7 +1521,7 @@ hr { color:#ffffff; background-color:#ffffff; height:1px; text-align:left; borde
 .textInput { width:90%; }\r
 .credits { margin-left:40px; text-indent: -20px; margin-bottom:0px; }\r
 #homescreenView { width: 315px; height:91px; overflow:hidden; }\r
-#calendarList { position:absolute; left:10px; top:4px; width:295px; height:75px; overflow:hidden; }\r
+#calendarList { position:absolute; left:5px; top:4px; width:295px; height:75px; overflow:hidden; }\r
 #name { text-align:center; }\r
 #appicon { display: block; margin-left: auto; margin-right: auto; margin-top: 10px; }\r
 #smallappicon { width:22px; height:22px; margin-right:10px; float:left; }\r
@@ -1380,8 +1556,10 @@ hr { color:#ffffff; background-color:#ffffff; height:1px; text-align:left; borde
                <p class="credits">Christophe Milsent (translation support & french translation)</p>\r
                <p class="credits">Flavio Nathan (portuguese-brazilian translation)</p>\r
                <p class="credits">Tokeda (russian translation)</p>\r
+               <p class="credits">Marcella Ferrari (italian translation)</p>\r
+               <p class="credits">Venos (italian translation)</p>\r
        <p>This software is open source and licensed under the GPLv3.</p>\r
-       <p>Visit sourceforge.net/projects/comingnext for free updates.</p>\r
+       <p>Visit <a onclick="widget.openURL('http://comingnext.sf.net/'); return false;" href="http://comingnext.sf.net/">comingnext.sf.net</a> for free updates.</p>\r
        <hr />\r
 </div>\r
 <div id="updateView" style="display:none">\r