X-Git-Url: https://code.delx.au/comingnext/blobdiff_plain/1667b303bc93cf8cb998525c9e7b0f87f506bed5..9e9817a7da1768159cec7c2393cab305af8ad762:/debug.js diff --git a/debug.js b/debug.js new file mode 100644 index 0000000..173d3c8 --- /dev/null +++ b/debug.js @@ -0,0 +1,320 @@ +var device = { + getServiceObject: function(cal, datasource) + { + return { + IDataSource: + { + GetList: function(criteria) + { + if (criteria.Type == "CalendarEntry") { + var entries = []; + for(var i = 0; i < device.data.default.length; i++) { + var entry = device.data.default[i]; + var searchText = criteria.Filter.SearchText; + var localId = criteria.Filter.LocalId; + var type = criteria.Filter.Type; + var include = true; + var startRange = criteria.Filter.StartRange; + var endRange = criteria.Filter.EndRange; + if (searchText != undefined && entry.Summary != undefined && entry.Summary.indexOf(searchText) == -1) { + include = false; + } + if (localId != undefined && entry.LocalId != undefined && entry.LocalId != localId) { + include = false; + } + if (type != undefined && entry.Type != undefined && type != entry.Type) { + include = false; + } + if (startRange != undefined && entry.StartTime != undefined && this.StringToDate(entry.StartTime) < startRange) { + include = false; + } + if (endRange != undefined && entry.EndTime != undefined && this.StringToDate(entry.EndTime) > endRange) { + include = false; + } + if (include) + entries.push(entry); + } + return { + ErrorCode: 0, + ErrorMessage: "", + ReturnValue: + { + data: entries, + dataPtr: 0, + getNext: function _getNext() + { + if (this.dataPtr < this.data.length) + return this.data[this.dataPtr++]; + else + return undefined; + } + } + }; + } + else if (criteria.Type == "Calendar") { + return { + ErrorCode: 0, + ErrorMessage: "", + ReturnValue: + { + data: [ "default" ], + dataPtr: 0, + getNext: function _getNext() + { + if (this.dataPtr < this.data.length) + return this.data[this.dataPtr++]; + else + return undefined; + } + } + }; + } + return null; + }, + Add: function (criteria) + { + if (criteria.Type == "CalendarEntry") { + var cal = device.data.default; + var itemId = 0; + if (criteria.Item.id == undefined && criteria.Item.LocalId != undefined) + criteria.Item.id = criteria.Item.LocalId; + var overwriteExisting = false; + var existingIndex = -1; + if (criteria.Item.id != undefined || criteria.Item.LocalId != undefined) { + itemId = criteria.Item.id; + for(var i = 0; i < cal.length; i++) { + if (cal[i].id != undefined && cal[i].id == itemId) { + overwriteExisting = true; + existingIndex = i; + break; + } + } + } + else { + for(var i = 0; i < cal.length; i++) { + if (cal[i].id != undefined && cal[i].id == itemId) { + itemId++; + i = 0; + } + } + } + criteria.Item.id = itemId; + criteria.Item.LocalId = itemId; + if (criteria.Item.StartTime != undefined && criteria.Item.StartTime instanceof Date) + criteria.Item.StartTime = this.DateToString(criteria.Item.StartTime); + if (criteria.Item.EndTime != undefined && criteria.Item.EndTime instanceof Date) + criteria.Item.EndTime = this.DateToString(criteria.Item.EndTime); + if (overwriteExisting) + cal[existingIndex] = criteria.Item; + else + cal.push(criteria.Item); + return { + ErrorCode: 0, + ErrorMessage: "" + } + } + else { + return { + ErrorCode: 1, + ErrorMessage: "invalid citeria.Type" + } + } + }, + Delete: function (criteria) + { + var cal = device.data.default; + for(var i = cal.length - 1; i >= 0; i--) { + if (criteria.Data != undefined && criteria.Data.IdList != undefined) { + for(var j = 0; j < criteria.Data.IdList.length; j++) { + if (criteria.Data.IdList[j] == cal[i].id) { + cal.splice(i, 1); + break; + } + } + } + } + return { + ErrorCode: 0, + ErrorMessage: "" + } + }, + RequestNotification: function(criteria, callback) + { + return { + ErrorCode: 0, + ErrorMessage: "" + } + }, + Cancel: function(request) + { + return { + ErrorCode: 0, + ErrorMessage: "" + } + }, + DateToString: function(date) { + // Wednesday, 26 April, 2012 23:… + var weekdays = [ "Sunday", "Monday", "Thuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]; + var months = [ "January", "Februrary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; + var hours = date.getHours(); if (hours < 10) hours = "0" + hours; + var minutes = date.getMinutes(); if (minutes < 10) minutes = "0" + minutes; + var seconds = date.getSeconds(); if (seconds < 10) seconds = "0" + seconds; + return weekdays[date.getDay()] + ", " + date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear() + ", " + hours + ":" + minutes + ":" + seconds; + }, + StringToDate: function(string) { + var parts = string.replace(/,/g,'').replace(/ /g,' ').split(' '); + var months = []; + months["January"] = 0; + months["February"] = 1; + months["March"] = 2; + months["April"] = 3; + months["May"] = 4; + months["June"] = 5; + months["July"] = 6; + months["August"] = 7; + months["September"] = 8; + months["October"] = 9; + months["November"] = 10; + months["December"] = 11; + var weekdays = []; + weekdays["Sunday"] = 0; + weekdays["Monday"] = 1; + weekdays["Thuesday"] = 2; + weekdays["Wednesday"] = 3; + weekdays["Thursday"] = 4; + weekdays["Friday"] = 5; + weekdays["Saturday"] = 6; + var weekday = weekdays[parts[0]]; + var day = Number(parts[1]); + var month = months[parts[2]]; + var year = Number(parts[3]); + var timeParts = parts[4].split(':'); + var hours = Number(timeParts[0]); + var minutes = Number(timeParts[1]); + var seconds = Number(timeParts[2]); + return new Date(year, month, day, hours, minutes, seconds); + }, + } + } + }, + data: + { + default: [ ] + }, +} + +device.data.default = [ + { + id: 0, + LocalId: 0, + Type: "Meeting", + CalendarName: "default", + Summary: "summary", + Location: "location", + Status: undefined, + StartTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 1 * 1)), + EndTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 2)), + InstanceStartTime: undefined, + InstanceEndTime: undefined + }, + { + id: 1, + LocalId: 1, + Type: "DayEvent", + CalendarName: "default", + Summary: "summary2", + Location: "location2", + Status: undefined, + StartTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24)), + EndTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24)), + InstanceStartTime: undefined, + InstanceEndTime: undefined + }, + { + id: 2, + LocalId: 2, + Type: "DayEvent", + CalendarName: "default", + Summary: "summary3", + Location: "location3", + Status: undefined, + StartTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24 * 2)), + EndTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24 * 2)), + InstanceStartTime: undefined, + InstanceEndTime: undefined + }, +]; + +window.menu = { + leftText: "undef", + leftCallback: undefined, + rightText: "undef", + rightCallback: undefined, + menuContent: [], + setLeftSoftkeyLabel: function(text, callback) { + if (text == "" && callback == null) { + text = "Menu"; + callback = this.defaultLeftCallback; + } + this.leftText = text; + this.leftCallback = callback; + this.update(); + }, + setRightSoftkeyLabel: function(text, callback) { + if (text == "" && callback == null) { + text = "Back"; + callback = this.defaultRightCallback; + } + this.rightText = text; + this.rightCallback = callback; + this.update(); + }, + defaultLeftCallback: function() { + }, + defaultRightCallback: function() { + back(); + }, + clear: function() { + this.menuContent = []; + this.update(); + }, + append: function(arg1) { + this.menuContent[this.menuContent.length] = arg1; + this.update(); + }, + update: function() { + var div = document.getElementById("debug"); + if (div == undefined) { + var body = document.getElementsByTagName('body')[0]; + body.innerHTML += '
Debug DIV
'; + div = document.getElementById('debug'); + } + var left = this.leftCallback == this.defaultLeftCallback ? this.menuContent.join('
') : ""; + div.innerHTML = '
' + this.leftText + "
" + left + '
' + this.rightText + '
'; + }, +} +function MenuItem(text, id) { + this.text = text; + this.id = id; +} +MenuItem.prototype.onSelect = undefined; +MenuItem.prototype.text = undefined; +MenuItem.prototype.id = undefined; +MenuItem.prototype.toString = function() { + return '' + this.text + ''; +} + +window.widget = { + onshow: null, + openApplication: function(appString, args) { + //alert("app '" + appString + "' with args '" + args + "' called"); + }, + prepareForTransition: function() { + }, + performTransition: function() { + }, + openURL: function(url) { + window.open(url); + }, +} +