X-Git-Url: https://code.delx.au/comingnext/blobdiff_plain/4cf257bd306ac4dc3220530c33874720488c8436..425ada1748988af6de379edb00cca52c2a4eadf2:/comingNext/index.html diff --git a/comingNext/index.html b/comingNext/index.html index e02a484..14da1c3 100644 --- a/comingNext/index.html +++ b/comingNext/index.html @@ -88,6 +88,7 @@ var versionURL = "http://comingnext.sourceforge.net/version.xml"; var calendarService = null; var cacheEntriesHtml = []; var months_translated = []; +var weekdays_translated = []; var orientation = ''; var now = new Date(); var mode = 0; // 0 = homescreen, 1 = fullscreen, 2 = settings, 3 = about, 4 = check for update @@ -104,6 +105,7 @@ var lastReloadTime = null; // last time we fetched calendar data var reloadInterval = 6 * 60 * 60 * 1000; // = 6 hours; time interval for reloading calendar data var errorOccured = false; var entryLists = null; // stores all fetched calendar entries until data is refreshed +var statupSuccessful = false; // indicates if everything started up wihtout errors. If we detect an error after that, it might just be a temporary problem e.g. by a backup process. // vars for daylight saving time var summertime = false; // true, if current date is in summer, false if in winter @@ -240,7 +242,27 @@ function collectLocales() try { var result = calendarService.IDataSource.Add(criteria); if (result.ErrorCode) - error(result.ErrorMessage); + throw(result.ErrorMessage); + } catch (e) { + error("collectLocales: " + e + ', line ' + e.line); + } + } + for (weekday = 0; weekday < 7; weekday++) { + var startDate = new Date(2000, 0, 2 + weekday); // date that we know for sure is a sunday + + var item = new Object(); + item.Type = "DayEvent"; + item.StartTime = startDate; + item.Summary = "__weekday_temp" + weekday; + + var criteria = new Object(); + criteria.Type = "CalendarEntry"; + criteria.Item = item; + + try { + var result = calendarService.IDataSource.Add(criteria); + if (result.ErrorCode) + throw(result.ErrorMessage); } catch (e) { error("collectLocales: " + e + ', line ' + e.line); } @@ -262,7 +284,7 @@ function collectLocales() throw(result.ErrorMessage); var list = result.ReturnValue; } catch(e) { - error(e + ', line ' + e.line); + error("collectLocales: " + e + ', line ' + e.line); return; } var ids = new Array(); @@ -294,7 +316,43 @@ function collectLocales() counter++; } } catch(e) { - error(e + ', line ' + e.line); + error("collectLocales: " + e + ', line ' + e.line); + return; + } + try { + var startTime = new Date(2000,0,2); + var endTime = new Date(2000,0,9); + var listFiltering = { + Type:'CalendarEntry', + Filter:{ + StartRange: startTime, + EndRange: endTime, + SearchText: '__weekday_temp', + Type: 'DayEvent' + } + } + var result = calendarService.IDataSource.GetList(listFiltering); + if (result.ErrorCode) + throw(result.ErrorMessage); + var weekdaylist = result.ReturnValue; + } catch(e) { + error("collectLocales: " + e + ', line ' + e.line); + return; + } + try { + var entry; + var counter2 = 0; + var curWeekday = ""; + + while (weekdaylist && (entry = weekdaylist.getNext()) != undefined) { + curWeekday = (entry.StartTime + '').split(',')[0]; + log(entry.StartTime + ' -> ' + curWeekday + ' ' + counter2); + ids[counter + counter2] = entry.id; + weekdays_translated[counter2] = curWeekday; + counter2++; + } + } catch(e) { + error("collectLocales: " + e + ', line ' + e.line); return; } log(ids); @@ -456,6 +514,14 @@ function parseDate(dateString) return result; } +function getWeekdayLocalized(date) { + var localizedString = date.toLocaleDateString(); + if (localizedString.match(/\d\d\/\d\d\/\d\d/)) { + return weekdays_translated[date.getDay()]; + } else + return localizedString.split(',')[0]; +} + // 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" function formatDate(date, format) { @@ -540,6 +606,16 @@ function updateData() // check if we got additional or less calendars since our last update var newCalendarList = listCalendars(); + if (newCalendarList == null) { + // Something went wrong fetching the calendars list. + // This usually happens when a backup is being made. + // Retry the next time updateData() is called by + // resetting errorOccured + log('updateData(): listCalendars() failed, trying again laster...'); + cacheEntriesHtml = ''; // make sure we replace the currently shown error message on the next update + errorOccured = false; + return; + } if (newCalendarList.length != calendarList.length) { calendarList = newCalendarList; updateCalendarColors(); @@ -776,7 +852,9 @@ function updateData() // some languages have very strange locale date formats, can't parse all those. Also some todos don't have dates at all. entriesHtml += '' + entryDate + ' '; } else { - var weekDay = date.toLocaleDateString().substr(0,config['weekDayLength'].Value); + var weekDay = getWeekdayLocalized(date).substr(0,config['weekDayLength'].Value); + log('date.toLocaleDateString(): ' + date.toLocaleDateString()); + log('weekDay: ' + weekDay); var time = formatTime(date); var dateStr = formatDate(date, entryDate); if (entry.Type == 'ToDo' && overdue && config['markOverdueTodos'].Value) { @@ -914,6 +992,8 @@ function init() window.widget.onshow = handleOnShow; log("init(): finished..."); + if (!errorOccured) + statupSuccessful = true; } function checkOrientation() @@ -1086,9 +1166,14 @@ function getSettingsCalEntryId() Type: 'DayEvent' } } - var result = calendarService.IDataSource.GetList(listFiltering); - if (result.ErrorCode) { - error(result.ErrorMessage); + var result = null; + try { + result = calendarService.IDataSource.GetList(listFiltering); + if (result.ErrorCode) + throw(result.ErrorMessage); + } + catch (e) { + error("getSettingsCalEntryId: GetList() failed: " + e + ', line ' + e.line); return; } var list = result.ReturnValue; @@ -1110,7 +1195,7 @@ function getSettingsCalEntryId() try { var result = calendarService.IDataSource.Add(criteria); if (result.ErrorCode) - error(result.ErrorMessage); + throw(result.ErrorMessage); } catch (e) { error("getSettingsCalEntryId: " + e + ', line ' + e.line); } @@ -1135,9 +1220,14 @@ function loadSettings() LocalId: settingsCalEntryId } } - var result = calendarService.IDataSource.GetList(listFiltering); - if (result.ErrorCode) { - error(result.ErrorMessage); + var result = null; + try { + result = calendarService.IDataSource.GetList(listFiltering); + if (result.ErrorCode) + throw(result.ErrorMessage); + } + catch (e) { + error("loadSettings: GetList() failed: " + e + ', line ' + e.line); return; } var entry = result.ReturnValue.getNext(); @@ -1226,7 +1316,7 @@ function saveSettings() try { var result = calendarService.IDataSource.Add(criteria); if (result.ErrorCode) - error(result.ErrorMessage); + throw(result.ErrorMessage); } catch (e) { error("saveSettings: " + e + ', line ' + e.line); }