]> code.delx.au - comingnext/blob - debug.js
added hundrets of events to debug mode for testing of huge datasets
[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 device.data.default = [
211 {
212 id: 0,
213 LocalId: 0,
214 Type: "Meeting",
215 CalendarName: "default",
216 Summary: "summary",
217 Location: "location",
218 Status: undefined,
219 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 1 * 1)),
220 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 2)),
221 InstanceStartTime: undefined,
222 InstanceEndTime: undefined
223 },
224 {
225 id: 1,
226 LocalId: 1,
227 Type: "DayEvent",
228 CalendarName: "default",
229 Summary: "summary2",
230 Location: "location2",
231 Status: undefined,
232 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24)),
233 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24)),
234 InstanceStartTime: undefined,
235 InstanceEndTime: undefined
236 },
237 {
238 id: 2,
239 LocalId: 2,
240 Type: "DayEvent",
241 CalendarName: "default",
242 Summary: "summary3",
243 Location: "location3",
244 Status: undefined,
245 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24 * 2)),
246 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24 * 2)),
247 InstanceStartTime: undefined,
248 InstanceEndTime: undefined
249 },
250 {
251 id: 3,
252 LocalId: 3,
253 Type: "DayEvent",
254 CalendarName: "calendar2",
255 Summary: "summary4",
256 Location: "location4",
257 Status: undefined,
258 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24 * 3)),
259 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24 * 3)),
260 InstanceStartTime: undefined,
261 InstanceEndTime: undefined
262 },
263 ];
264
265 {
266 for(var i = 0; i < 100; i++) {
267 var newid = device.data.default.length + 1;
268 var event = {
269 id: newid,
270 LocalId: newid,
271 Type: "DayEvent",
272 CalendarName: "default",
273 Summary: "summary" + newid,
274 Location: "location" + newid,
275 Status: undefined,
276 StartTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24 * device.data.default.length)),
277 EndTime: device.getServiceObject().IDataSource.DateToString(new Date((new Date()).getTime() + 1000 * 60 * 60 * 24 * device.data.default.length)),
278 InstanceStartTime: undefined,
279 InstanceEndTime: undefined
280 }
281 device.data.default[device.data.default.length] = event;
282 }
283 }
284
285 window.menu = {
286 leftText: "undef",
287 leftCallback: undefined,
288 rightText: "undef",
289 rightCallback: undefined,
290 menuContent: [],
291 setLeftSoftkeyLabel: function(text, callback) {
292 if (text == "" && callback == null) {
293 text = "Menu";
294 callback = this.defaultLeftCallback;
295 }
296 this.leftText = text;
297 this.leftCallback = callback;
298 this.update();
299 },
300 setRightSoftkeyLabel: function(text, callback) {
301 if (text == "" && callback == null) {
302 text = "Back";
303 callback = this.defaultRightCallback;
304 }
305 this.rightText = text;
306 this.rightCallback = callback;
307 this.update();
308 },
309 defaultLeftCallback: function() {
310 },
311 defaultRightCallback: function() {
312 back();
313 },
314 clear: function() {
315 this.menuContent = [];
316 this.update();
317 },
318 append: function(arg1) {
319 this.menuContent[this.menuContent.length] = arg1;
320 this.update();
321 },
322 update: function() {
323 var div = document.getElementById("debug");
324 if (div == undefined) {
325 var body = document.getElementsByTagName('body')[0];
326 body.innerHTML += '<div id="debug">Debug DIV</div>';
327 div = document.getElementById('debug');
328 }
329 var left = this.leftCallback == this.defaultLeftCallback ? this.menuContent.join('<br />') : "";
330 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>';
331 },
332 }
333 function MenuItem(text, id) {
334 this.text = text;
335 this.id = id;
336 }
337 MenuItem.prototype.onSelect = undefined;
338 MenuItem.prototype.text = undefined;
339 MenuItem.prototype.id = undefined;
340 MenuItem.prototype.toString = function() {
341 return '<span style="padding-left:10px;" onclick="' + this.onSelect.name + '()">' + this.text + '</span>';
342 }
343
344 window.widget = {
345 onshow: null,
346 openApplication: function(appString, args) {
347 //alert("app '" + appString + "' with args '" + args + "' called");
348 },
349 prepareForTransition: function() {
350 },
351 performTransition: function() {
352 },
353 openURL: function(url) {
354 window.open(url);
355 },
356 }
357