]> code.delx.au - comingnext/blob - debug.js
Work around for bug by fixing the current Date rather than amending calendar dates
[comingnext] / debug.js
1 var device = {
2 getServiceObject: function(cal, datasource)
3 {
4 return {
5 IDataSource:
6 {
7 GetList: function(criteria)
8 {
9 if (criteria.Type == "CalendarEntry") {
10 var entries = [];
11 for(var i = 0; i < device.data.default.length; i++) {
12 var entry = device.data.default[i];
13 var searchText = criteria.Filter.SearchText;
14 var localId = criteria.Filter.LocalId;
15 var type = criteria.Filter.Type;
16 var include = true;
17 var startRange = criteria.Filter.StartRange;
18 var endRange = criteria.Filter.EndRange;
19 var calendarName = criteria.Filter.CalendarName;
20 if (searchText != undefined && entry.Summary != undefined && entry.Summary.indexOf(searchText) == -1) {
21 include = false;
22 }
23 if (localId != undefined && entry.LocalId != undefined && entry.LocalId != localId) {
24 include = false;
25 }
26 if (type != undefined && entry.Type != undefined && type != entry.Type) {
27 include = false;
28 }
29 if (startRange != undefined && entry.StartTime != undefined && this.StringToDate(entry.StartTime) < startRange) {
30 include = false;
31 }
32 if (endRange != undefined && entry.EndTime != undefined && this.StringToDate(entry.EndTime) > endRange) {
33 include = false;
34 }
35 if (calendarName != undefined && entry.CalendarName != undefined && entry.CalendarName != calendarName) {
36 include = false;
37 }
38 if (include)
39 entries.push(entry);
40 }
41 return {
42 ErrorCode: 0,
43 ErrorMessage: "",
44 ReturnValue:
45 {
46 data: entries,
47 dataPtr: 0,
48 getNext: function _getNext()
49 {
50 if (this.dataPtr < this.data.length)
51 return this.data[this.dataPtr++];
52 else
53 return undefined;
54 }
55 }
56 };
57 }
58 else if (criteria.Type == "Calendar") {
59 return {
60 ErrorCode: 0,
61 ErrorMessage: "",
62 ReturnValue:
63 {
64 data: [ "default", "calendar2" ],
65 dataPtr: 0,
66 getNext: function _getNext()
67 {
68 if (this.dataPtr < this.data.length)
69 return this.data[this.dataPtr++];
70 else
71 return undefined;
72 }
73 }
74 };
75 }
76 return null;
77 },
78 Add: function (criteria)
79 {
80 if (criteria.Type == "CalendarEntry") {
81 var cal = device.data.default;
82 var itemId = 0;
83 if (criteria.Item.id == undefined && criteria.Item.LocalId != undefined)
84 criteria.Item.id = criteria.Item.LocalId;
85 var overwriteExisting = false;
86 var existingIndex = -1;
87 if (criteria.Item.id != undefined || criteria.Item.LocalId != undefined) {
88 itemId = criteria.Item.id;
89 for(var i = 0; i < cal.length; i++) {
90 if (cal[i].id != undefined && cal[i].id == itemId) {
91 overwriteExisting = true;
92 existingIndex = i;
93 break;
94 }
95 }
96 }
97 else {
98 for(var i = 0; i < cal.length; i++) {
99 if (cal[i].id != undefined && cal[i].id == itemId) {
100 itemId++;
101 i = 0;
102 }
103 }
104 }
105 criteria.Item.id = itemId;
106 criteria.Item.LocalId = itemId;
107 if (criteria.Item.StartTime != undefined && criteria.Item.StartTime instanceof Date)
108 criteria.Item.StartTime = this.DateToString(criteria.Item.StartTime);
109 if (criteria.Item.EndTime != undefined && criteria.Item.EndTime instanceof Date)
110 criteria.Item.EndTime = this.DateToString(criteria.Item.EndTime);
111 if (overwriteExisting)
112 cal[existingIndex] = criteria.Item;
113 else
114 cal.push(criteria.Item);
115 return {
116 ErrorCode: 0,
117 ErrorMessage: ""
118 }
119 }
120 else {
121 return {
122 ErrorCode: 1,
123 ErrorMessage: "invalid citeria.Type"
124 }
125 }
126 },
127 Delete: function (criteria)
128 {
129 var cal = device.data.default;
130 for(var i = cal.length - 1; i >= 0; i--) {
131 if (criteria.Data != undefined && criteria.Data.IdList != undefined) {
132 for(var j = 0; j < criteria.Data.IdList.length; j++) {
133 if (criteria.Data.IdList[j] == cal[i].id) {
134 cal.splice(i, 1);
135 break;
136 }
137 }
138 }
139 }
140 return {
141 ErrorCode: 0,
142 ErrorMessage: ""
143 }
144 },
145 RequestNotification: function(criteria, callback)
146 {
147 return {
148 ErrorCode: 0,
149 ErrorMessage: ""
150 }
151 },
152 Cancel: function(request)
153 {
154 return {
155 ErrorCode: 0,
156 ErrorMessage: ""
157 }
158 },
159 DateToString: function(date) {
160 // Wednesday, 26 April, 2012 23:…
161 var weekdays = [ "Sunday", "Monday", "Thuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
162 var months = [ "January", "Februrary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
163 var hours = date.getHours(); if (hours < 10) hours = "0" + hours;
164 var minutes = date.getMinutes(); if (minutes < 10) minutes = "0" + minutes;
165 var seconds = date.getSeconds(); if (seconds < 10) seconds = "0" + seconds;
166 return weekdays[date.getDay()] + ", " + date.getDate() + " " + months[date.getMonth()] + " " + date.getFullYear() + ", " + hours + ":" + minutes + ":" + seconds;
167 },
168 StringToDate: function(string) {
169 var parts = string.replace(/,/g,'').replace(/ /g,' ').split(' ');
170 var months = [];
171 months["January"] = 0;
172 months["February"] = 1;
173 months["March"] = 2;
174 months["April"] = 3;
175 months["May"] = 4;
176 months["June"] = 5;
177 months["July"] = 6;
178 months["August"] = 7;
179 months["September"] = 8;
180 months["October"] = 9;
181 months["November"] = 10;
182 months["December"] = 11;
183 var weekdays = [];
184 weekdays["Sunday"] = 0;
185 weekdays["Monday"] = 1;
186 weekdays["Thuesday"] = 2;
187 weekdays["Wednesday"] = 3;
188 weekdays["Thursday"] = 4;
189 weekdays["Friday"] = 5;
190 weekdays["Saturday"] = 6;
191 var weekday = weekdays[parts[0]];
192 var day = Number(parts[1]);
193 var month = months[parts[2]];
194 var year = Number(parts[3]);
195 var timeParts = parts[4].split(':');
196 var hours = Number(timeParts[0]);
197 var minutes = Number(timeParts[1]);
198 var seconds = Number(timeParts[2]);
199 return new Date(year, month, day, hours, minutes, seconds);
200 },
201 }
202 }
203 },
204 data:
205 {
206 default: [ ]
207 },
208 }
209
210 var eventsStartDate = new Date(); // new Date("2012-01-01");
211
212 device.data.default = [
213 {
214 id: 0,
215 LocalId: 0,
216 Type: "Meeting",
217 CalendarName: "default",
218 Summary: "summary",
219 Location: "location",
220 Status: undefined,
221 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 1 * 1)),
222 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 2)),
223 InstanceStartTime: undefined,
224 InstanceEndTime: undefined
225 },
226 {
227 id: 1,
228 LocalId: 1,
229 Type: "DayEvent",
230 CalendarName: "default",
231 Summary: "summary2",
232 Location: "location2",
233 Status: undefined,
234 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 24)),
235 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 24)),
236 InstanceStartTime: undefined,
237 InstanceEndTime: undefined
238 },
239 {
240 id: 2,
241 LocalId: 2,
242 Type: "DayEvent",
243 CalendarName: "default",
244 Summary: "summary3",
245 Location: "location3",
246 Status: undefined,
247 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 24 * 2)),
248 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 24 * 2)),
249 InstanceStartTime: undefined,
250 InstanceEndTime: undefined
251 },
252 {
253 id: 3,
254 LocalId: 3,
255 Type: "DayEvent",
256 CalendarName: "calendar2",
257 Summary: "summary4",
258 Location: "location4",
259 Status: undefined,
260 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 24 * 3)),
261 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 24 * 3)),
262 InstanceStartTime: undefined,
263 InstanceEndTime: undefined
264 },
265 ];
266
267 {
268 for(var i = 0; i < 100; i++) {
269 var newid = device.data.default.length + 1;
270 var event = {
271 id: newid,
272 LocalId: newid,
273 Type: "DayEvent",
274 CalendarName: "default",
275 Summary: "summary" + newid,
276 Location: "location" + newid,
277 Status: undefined,
278 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 24 * device.data.default.length)),
279 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((eventsStartDate).getTime() + 1000 * 60 * 60 * 24 * device.data.default.length)),
280 InstanceStartTime: undefined,
281 InstanceEndTime: undefined
282 }
283 device.data.default[device.data.default.length] = event;
284 }
285 }
286
287 window.menu = {
288 leftText: "undef",
289 leftCallback: undefined,
290 rightText: "undef",
291 rightCallback: undefined,
292 menuContent: [],
293 setLeftSoftkeyLabel: function(text, callback) {
294 if (text == "" && callback == null) {
295 text = "Menu";
296 callback = this.defaultLeftCallback;
297 }
298 this.leftText = text;
299 this.leftCallback = callback;
300 this.update();
301 },
302 setRightSoftkeyLabel: function(text, callback) {
303 if (text == "" && callback == null) {
304 text = "Back";
305 callback = this.defaultRightCallback;
306 }
307 this.rightText = text;
308 this.rightCallback = callback;
309 this.update();
310 },
311 defaultLeftCallback: function() {
312 },
313 defaultRightCallback: function() {
314 back();
315 },
316 clear: function() {
317 this.menuContent = [];
318 this.update();
319 },
320 append: function(arg1) {
321 this.menuContent[this.menuContent.length] = arg1;
322 this.update();
323 },
324 update: function() {
325 var div = document.getElementById("debug");
326 if (div == undefined) {
327 var body = document.getElementsByTagName('body')[0];
328 body.innerHTML += '<div id="debug">Debug DIV</div>';
329 div = document.getElementById('debug');
330 }
331 var left = this.leftCallback == this.defaultLeftCallback ? this.menuContent.join('<br />') : "";
332 div.innerHTML = '<div style="background-color:#a00000"><span onclick="window.menu.leftCallback()">' + this.leftText + "</span><br />" + left + '</div> <div style="background-color:#00a000" onclick="window.menu.rightCallback()">' + this.rightText + '</div>';
333 },
334 }
335 function MenuItem(text, id) {
336 this.text = text;
337 this.id = id;
338 }
339 MenuItem.prototype.onSelect = undefined;
340 MenuItem.prototype.text = undefined;
341 MenuItem.prototype.id = undefined;
342 MenuItem.prototype.toString = function() {
343 return '<span style="padding-left:10px;" onclick="' + this.onSelect.name + '()">' + this.text + '</span>';
344 }
345
346 window.widget = {
347 onshow: null,
348 openApplication: function(appString, args) {
349 //alert("app '" + appString + "' with args '" + args + "' called");
350 },
351 prepareForTransition: function() {
352 },
353 performTransition: function() {
354 },
355 openURL: function(url) {
356 window.open(url);
357 },
358 }
359