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