root / trunk / web / dojo / dojox / data / XmlStore.js @ 13
History | View | Annotate | Download (17.7 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.data.XmlStore"]){ |
||
9 | dojo._hasResource["dojox.data.XmlStore"]=true; |
||
10 | dojo.provide("dojox.data.XmlStore");
|
||
11 | dojo.provide("dojox.data.XmlItem");
|
||
12 | dojo.require("dojo.data.util.simpleFetch");
|
||
13 | dojo.require("dojo.data.util.filter");
|
||
14 | dojo.require("dojox.xml.parser");
|
||
15 | dojo.declare("dojox.data.XmlStore",null,{constructor:function(_1){ |
||
16 | if(_1){
|
||
17 | this.url=_1.url;
|
||
18 | this.rootItem=(_1.rootItem||_1.rootitem||this.rootItem); |
||
19 | this.keyAttribute=(_1.keyAttribute||_1.keyattribute||this.keyAttribute); |
||
20 | this._attributeMap=(_1.attributeMap||_1.attributemap);
|
||
21 | this.label=_1.label||this.label; |
||
22 | this.sendQuery=(_1.sendQuery||_1.sendquery||this.sendQuery); |
||
23 | if("urlPreventCache" in _1){ |
||
24 | this.urlPreventCache=_1.urlPreventCache?true:false; |
||
25 | } |
||
26 | } |
||
27 | this._newItems=[];
|
||
28 | this._deletedItems=[];
|
||
29 | this._modifiedItems=[];
|
||
30 | },url:"",rootItem:"",keyAttribute:"",label:"",sendQuery:false,attributeMap:null,urlPreventCache:true,getValue:function(_2,_3,_4){ |
||
31 | var _5=_2.element;
|
||
32 | var i;
|
||
33 | var _6;
|
||
34 | if(_3==="tagName"){ |
||
35 | return _5.nodeName;
|
||
36 | }else{
|
||
37 | if(_3==="childNodes"){ |
||
38 | for(i=0;i<_5.childNodes.length;i++){ |
||
39 | _6=_5.childNodes[i]; |
||
40 | if(_6.nodeType===1){ |
||
41 | return this._getItem(_6); |
||
42 | } |
||
43 | } |
||
44 | return _4;
|
||
45 | }else{
|
||
46 | if(_3==="text()"){ |
||
47 | for(i=0;i<_5.childNodes.length;i++){ |
||
48 | _6=_5.childNodes[i]; |
||
49 | if(_6.nodeType===3||_6.nodeType===4){ |
||
50 | return _6.nodeValue;
|
||
51 | } |
||
52 | } |
||
53 | return _4;
|
||
54 | }else{
|
||
55 | _3=this._getAttribute(_5.nodeName,_3);
|
||
56 | if(_3.charAt(0)==="@"){ |
||
57 | var _7=_3.substring(1); |
||
58 | var _8=_5.getAttribute(_7);
|
||
59 | return (_8)?_8:_4;
|
||
60 | }else{
|
||
61 | for(i=0;i<_5.childNodes.length;i++){ |
||
62 | _6=_5.childNodes[i]; |
||
63 | if(_6.nodeType===1&&_6.nodeName===_3){ |
||
64 | return this._getItem(_6); |
||
65 | } |
||
66 | } |
||
67 | return _4;
|
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | },getValues:function(_9,_a){ |
||
73 | var _b=_9.element;
|
||
74 | var _c=[];
|
||
75 | var i;
|
||
76 | var _d;
|
||
77 | if(_a==="tagName"){ |
||
78 | return [_b.nodeName];
|
||
79 | }else{
|
||
80 | if(_a==="childNodes"){ |
||
81 | for(i=0;i<_b.childNodes.length;i++){ |
||
82 | _d=_b.childNodes[i]; |
||
83 | if(_d.nodeType===1){ |
||
84 | _c.push(this._getItem(_d));
|
||
85 | } |
||
86 | } |
||
87 | return _c;
|
||
88 | }else{
|
||
89 | if(_a==="text()"){ |
||
90 | var ec=_b.childNodes;
|
||
91 | for(i=0;i<ec.length;i++){ |
||
92 | _d=ec[i]; |
||
93 | if(_d.nodeType===3||_d.nodeType===4){ |
||
94 | _c.push(_d.nodeValue); |
||
95 | } |
||
96 | } |
||
97 | return _c;
|
||
98 | }else{
|
||
99 | _a=this._getAttribute(_b.nodeName,_a);
|
||
100 | if(_a.charAt(0)==="@"){ |
||
101 | var _e=_a.substring(1); |
||
102 | var _f=_b.getAttribute(_e);
|
||
103 | return (_f!==undefined)?[_f]:[]; |
||
104 | }else{
|
||
105 | for(i=0;i<_b.childNodes.length;i++){ |
||
106 | _d=_b.childNodes[i]; |
||
107 | if(_d.nodeType===1&&_d.nodeName===_a){ |
||
108 | _c.push(this._getItem(_d));
|
||
109 | } |
||
110 | } |
||
111 | return _c;
|
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | },getAttributes:function(_10){ |
||
117 | var _11=_10.element;
|
||
118 | var _12=[];
|
||
119 | var i;
|
||
120 | _12.push("tagName");
|
||
121 | if(_11.childNodes.length>0){ |
||
122 | var _13={};
|
||
123 | var _14=true; |
||
124 | var _15=false; |
||
125 | for(i=0;i<_11.childNodes.length;i++){ |
||
126 | var _16=_11.childNodes[i];
|
||
127 | if(_16.nodeType===1){ |
||
128 | var _17=_16.nodeName;
|
||
129 | if(!_13[_17]){
|
||
130 | _12.push(_17); |
||
131 | _13[_17]=_17; |
||
132 | } |
||
133 | _14=true;
|
||
134 | }else{
|
||
135 | if(_16.nodeType===3){ |
||
136 | _15=true;
|
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | if(_14){
|
||
141 | _12.push("childNodes");
|
||
142 | } |
||
143 | if(_15){
|
||
144 | _12.push("text()");
|
||
145 | } |
||
146 | } |
||
147 | for(i=0;i<_11.attributes.length;i++){ |
||
148 | _12.push("@"+_11.attributes[i].nodeName);
|
||
149 | } |
||
150 | if(this._attributeMap){ |
||
151 | for(var key in this._attributeMap){ |
||
152 | i=key.indexOf(".");
|
||
153 | if(i>0){ |
||
154 | var _18=key.substring(0,i); |
||
155 | if(_18===_11.nodeName){
|
||
156 | _12.push(key.substring(i+1));
|
||
157 | } |
||
158 | }else{
|
||
159 | _12.push(key); |
||
160 | } |
||
161 | } |
||
162 | } |
||
163 | return _12;
|
||
164 | },hasAttribute:function(_19,_1a){ |
||
165 | return (this.getValue(_19,_1a)!==undefined); |
||
166 | },containsValue:function(_1b,_1c,_1d){ |
||
167 | var _1e=this.getValues(_1b,_1c); |
||
168 | for(var i=0;i<_1e.length;i++){ |
||
169 | if((typeof _1d==="string")){ |
||
170 | if(_1e[i].toString&&_1e[i].toString()===_1d){
|
||
171 | return true; |
||
172 | } |
||
173 | }else{
|
||
174 | if(_1e[i]===_1d){
|
||
175 | return true; |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | return false; |
||
180 | },isItem:function(_1f){ |
||
181 | if(_1f&&_1f.element&&_1f.store&&_1f.store===this){ |
||
182 | return true; |
||
183 | } |
||
184 | return false; |
||
185 | },isItemLoaded:function(_20){ |
||
186 | return this.isItem(_20); |
||
187 | },loadItem:function(_21){ |
||
188 | },getFeatures:function(){ |
||
189 | var _22={"dojo.data.api.Read":true,"dojo.data.api.Write":true}; |
||
190 | if(!this.sendQuery||this.keyAttribute!==""){ |
||
191 | _22["dojo.data.api.Identity"]=true; |
||
192 | } |
||
193 | return _22;
|
||
194 | },getLabel:function(_23){ |
||
195 | if((this.label!=="")&&this.isItem(_23)){ |
||
196 | var _24=this.getValue(_23,this.label); |
||
197 | if(_24){
|
||
198 | return _24.toString();
|
||
199 | } |
||
200 | } |
||
201 | return undefined; |
||
202 | },getLabelAttributes:function(_25){ |
||
203 | if(this.label!==""){ |
||
204 | return [this.label]; |
||
205 | } |
||
206 | return null; |
||
207 | },_fetchItems:function(_26,_27,_28){ |
||
208 | var url=this._getFetchUrl(_26); |
||
209 | if(!url){
|
||
210 | _28(new Error("No URL specified.")); |
||
211 | return;
|
||
212 | } |
||
213 | var _29=(!this.sendQuery?_26:{}); |
||
214 | var _2a=this; |
||
215 | var _2b={url:url,handleAs:"xml",preventCache:_2a.urlPreventCache}; |
||
216 | var _2c=dojo.xhrGet(_2b);
|
||
217 | _2c.addCallback(function(_2d){
|
||
218 | var _2e=_2a._getItems(_2d,_29);
|
||
219 | if(_2e&&_2e.length>0){ |
||
220 | _27(_2e,_26); |
||
221 | }else{
|
||
222 | _27([],_26); |
||
223 | } |
||
224 | }); |
||
225 | _2c.addErrback(function(_2f){
|
||
226 | _28(_2f,_26); |
||
227 | }); |
||
228 | },_getFetchUrl:function(_30){ |
||
229 | if(!this.sendQuery){ |
||
230 | return this.url; |
||
231 | } |
||
232 | var _31=_30.query;
|
||
233 | if(!_31){
|
||
234 | return this.url; |
||
235 | } |
||
236 | if(dojo.isString(_31)){
|
||
237 | return this.url+_31; |
||
238 | } |
||
239 | var _32=""; |
||
240 | for(var _33 in _31){ |
||
241 | var _34=_31[_33];
|
||
242 | if(_34){
|
||
243 | if(_32){
|
||
244 | _32+="&";
|
||
245 | } |
||
246 | _32+=(_33+"="+_34);
|
||
247 | } |
||
248 | } |
||
249 | if(!_32){
|
||
250 | return this.url; |
||
251 | } |
||
252 | var _35=this.url; |
||
253 | if(_35.indexOf("?")<0){ |
||
254 | _35+="?";
|
||
255 | }else{
|
||
256 | _35+="&";
|
||
257 | } |
||
258 | return _35+_32;
|
||
259 | },_getItems:function(_36,_37){ |
||
260 | var _38=null; |
||
261 | if(_37){
|
||
262 | _38=_37.query; |
||
263 | } |
||
264 | var _39=[];
|
||
265 | var _3a=null; |
||
266 | if(this.rootItem!==""){ |
||
267 | _3a=dojo.query(this.rootItem,_36);
|
||
268 | }else{
|
||
269 | _3a=_36.documentElement.childNodes; |
||
270 | } |
||
271 | var _3b=_37.queryOptions?_37.queryOptions.deep:false; |
||
272 | if(_3b){
|
||
273 | _3a=this._flattenNodes(_3a);
|
||
274 | } |
||
275 | for(var i=0;i<_3a.length;i++){ |
||
276 | var _3c=_3a[i];
|
||
277 | if(_3c.nodeType!=1){ |
||
278 | continue;
|
||
279 | } |
||
280 | var _3d=this._getItem(_3c); |
||
281 | if(_38){
|
||
282 | var _3e=_37.queryOptions?_37.queryOptions.ignoreCase:false; |
||
283 | var _3f;
|
||
284 | var _40=false; |
||
285 | var j;
|
||
286 | var _41=true; |
||
287 | var _42={};
|
||
288 | for(var key in _38){ |
||
289 | _3f=_38[key]; |
||
290 | if(typeof _3f==="string"){ |
||
291 | _42[key]=dojo.data.util.filter.patternToRegExp(_3f,_3e); |
||
292 | } |
||
293 | } |
||
294 | for(var _43 in _38){ |
||
295 | _41=false;
|
||
296 | var _44=this.getValues(_3d,_43); |
||
297 | for(j=0;j<_44.length;j++){ |
||
298 | _3f=_44[j]; |
||
299 | if(_3f){
|
||
300 | var _45=_38[_43];
|
||
301 | if((typeof _3f)==="string"&&(_42[_43])){ |
||
302 | if((_3f.match(_42[_43]))!==null){ |
||
303 | _40=true;
|
||
304 | }else{
|
||
305 | _40=false;
|
||
306 | } |
||
307 | }else{
|
||
308 | if((typeof _3f)==="object"){ |
||
309 | if(_3f.toString&&(_42[_43])){
|
||
310 | var _46=_3f.toString();
|
||
311 | if((_46.match(_42[_43]))!==null){ |
||
312 | _40=true;
|
||
313 | }else{
|
||
314 | _40=false;
|
||
315 | } |
||
316 | }else{
|
||
317 | if(_45==="*"||_45===_3f){ |
||
318 | _40=true;
|
||
319 | }else{
|
||
320 | _40=false;
|
||
321 | } |
||
322 | } |
||
323 | } |
||
324 | } |
||
325 | } |
||
326 | if(_40){
|
||
327 | break;
|
||
328 | } |
||
329 | } |
||
330 | if(!_40){
|
||
331 | break;
|
||
332 | } |
||
333 | } |
||
334 | if(_41||_40){
|
||
335 | _39.push(_3d); |
||
336 | } |
||
337 | }else{
|
||
338 | _39.push(_3d); |
||
339 | } |
||
340 | } |
||
341 | dojo.forEach(_39,function(_47){
|
||
342 | if(_47.element.parentNode){
|
||
343 | _47.element.parentNode.removeChild(_47.element); |
||
344 | } |
||
345 | },this);
|
||
346 | return _39;
|
||
347 | },_flattenNodes:function(_48){ |
||
348 | var _49=[];
|
||
349 | if(_48){
|
||
350 | var i;
|
||
351 | for(i=0;i<_48.length;i++){ |
||
352 | var _4a=_48[i];
|
||
353 | _49.push(_4a); |
||
354 | if(_4a.childNodes&&_4a.childNodes.length>0){ |
||
355 | _49=_49.concat(this._flattenNodes(_4a.childNodes));
|
||
356 | } |
||
357 | } |
||
358 | } |
||
359 | return _49;
|
||
360 | },close:function(_4b){ |
||
361 | },newItem:function(_4c,_4d){ |
||
362 | _4c=(_4c||{}); |
||
363 | var _4e=_4c.tagName;
|
||
364 | if(!_4e){
|
||
365 | _4e=this.rootItem;
|
||
366 | if(_4e===""){ |
||
367 | return null; |
||
368 | } |
||
369 | } |
||
370 | var _4f=this._getDocument(); |
||
371 | var _50=_4f.createElement(_4e);
|
||
372 | for(var _51 in _4c){ |
||
373 | var _52;
|
||
374 | if(_51==="tagName"){ |
||
375 | continue;
|
||
376 | }else{
|
||
377 | if(_51==="text()"){ |
||
378 | _52=_4f.createTextNode(_4c[_51]); |
||
379 | _50.appendChild(_52); |
||
380 | }else{
|
||
381 | _51=this._getAttribute(_4e,_51);
|
||
382 | if(_51.charAt(0)==="@"){ |
||
383 | var _53=_51.substring(1); |
||
384 | _50.setAttribute(_53,_4c[_51]); |
||
385 | }else{
|
||
386 | var _54=_4f.createElement(_51);
|
||
387 | _52=_4f.createTextNode(_4c[_51]); |
||
388 | _54.appendChild(_52); |
||
389 | _50.appendChild(_54); |
||
390 | } |
||
391 | } |
||
392 | } |
||
393 | } |
||
394 | var _55=this._getItem(_50); |
||
395 | this._newItems.push(_55);
|
||
396 | var _56=null; |
||
397 | if(_4d&&_4d.parent&&_4d.attribute){
|
||
398 | _56={item:_4d.parent,attribute:_4d.attribute,oldValue:undefined}; |
||
399 | var _57=this.getValues(_4d.parent,_4d.attribute); |
||
400 | if(_57&&_57.length>0){ |
||
401 | var _58=_57.slice(0,_57.length); |
||
402 | if(_57.length===1){ |
||
403 | _56.oldValue=_57[0];
|
||
404 | }else{
|
||
405 | _56.oldValue=_57.slice(0,_57.length);
|
||
406 | } |
||
407 | _58.push(_55); |
||
408 | this.setValues(_4d.parent,_4d.attribute,_58);
|
||
409 | _56.newValue=this.getValues(_4d.parent,_4d.attribute);
|
||
410 | }else{
|
||
411 | this.setValues(_4d.parent,_4d.attribute,_55);
|
||
412 | _56.newValue=_55; |
||
413 | } |
||
414 | } |
||
415 | return _55;
|
||
416 | },deleteItem:function(_59){ |
||
417 | var _5a=_59.element;
|
||
418 | if(_5a.parentNode){
|
||
419 | this._backupItem(_59);
|
||
420 | _5a.parentNode.removeChild(_5a); |
||
421 | return true; |
||
422 | } |
||
423 | this._forgetItem(_59);
|
||
424 | this._deletedItems.push(_59);
|
||
425 | return true; |
||
426 | },setValue:function(_5b,_5c,_5d){ |
||
427 | if(_5c==="tagName"){ |
||
428 | return false; |
||
429 | } |
||
430 | this._backupItem(_5b);
|
||
431 | var _5e=_5b.element;
|
||
432 | var _5f;
|
||
433 | var _60;
|
||
434 | if(_5c==="childNodes"){ |
||
435 | _5f=_5d.element; |
||
436 | _5e.appendChild(_5f); |
||
437 | }else{
|
||
438 | if(_5c==="text()"){ |
||
439 | while(_5e.firstChild){
|
||
440 | _5e.removeChild(_5e.firstChild); |
||
441 | } |
||
442 | _60=this._getDocument(_5e).createTextNode(_5d);
|
||
443 | _5e.appendChild(_60); |
||
444 | }else{
|
||
445 | _5c=this._getAttribute(_5e.nodeName,_5c);
|
||
446 | if(_5c.charAt(0)==="@"){ |
||
447 | var _61=_5c.substring(1); |
||
448 | _5e.setAttribute(_61,_5d); |
||
449 | }else{
|
||
450 | for(var i=0;i<_5e.childNodes.length;i++){ |
||
451 | var _62=_5e.childNodes[i];
|
||
452 | if(_62.nodeType===1&&_62.nodeName===_5c){ |
||
453 | _5f=_62; |
||
454 | break;
|
||
455 | } |
||
456 | } |
||
457 | var _63=this._getDocument(_5e); |
||
458 | if(_5f){
|
||
459 | while(_5f.firstChild){
|
||
460 | _5f.removeChild(_5f.firstChild); |
||
461 | } |
||
462 | }else{
|
||
463 | _5f=_63.createElement(_5c); |
||
464 | _5e.appendChild(_5f); |
||
465 | } |
||
466 | _60=_63.createTextNode(_5d); |
||
467 | _5f.appendChild(_60); |
||
468 | } |
||
469 | } |
||
470 | } |
||
471 | return true; |
||
472 | },setValues:function(_64,_65,_66){ |
||
473 | if(_65==="tagName"){ |
||
474 | return false; |
||
475 | } |
||
476 | this._backupItem(_64);
|
||
477 | var _67=_64.element;
|
||
478 | var i;
|
||
479 | var _68;
|
||
480 | var _69;
|
||
481 | if(_65==="childNodes"){ |
||
482 | while(_67.firstChild){
|
||
483 | _67.removeChild(_67.firstChild); |
||
484 | } |
||
485 | for(i=0;i<_66.length;i++){ |
||
486 | _68=_66[i].element; |
||
487 | _67.appendChild(_68); |
||
488 | } |
||
489 | }else{
|
||
490 | if(_65==="text()"){ |
||
491 | while(_67.firstChild){
|
||
492 | _67.removeChild(_67.firstChild); |
||
493 | } |
||
494 | var _6a=""; |
||
495 | for(i=0;i<_66.length;i++){ |
||
496 | _6a+=_66[i]; |
||
497 | } |
||
498 | _69=this._getDocument(_67).createTextNode(_6a);
|
||
499 | _67.appendChild(_69); |
||
500 | }else{
|
||
501 | _65=this._getAttribute(_67.nodeName,_65);
|
||
502 | if(_65.charAt(0)==="@"){ |
||
503 | var _6b=_65.substring(1); |
||
504 | _67.setAttribute(_6b,_66[0]);
|
||
505 | }else{
|
||
506 | for(i=_67.childNodes.length-1;i>=0;i--){ |
||
507 | var _6c=_67.childNodes[i];
|
||
508 | if(_6c.nodeType===1&&_6c.nodeName===_65){ |
||
509 | _67.removeChild(_6c); |
||
510 | } |
||
511 | } |
||
512 | var _6d=this._getDocument(_67); |
||
513 | for(i=0;i<_66.length;i++){ |
||
514 | _68=_6d.createElement(_65); |
||
515 | _69=_6d.createTextNode(_66[i]); |
||
516 | _68.appendChild(_69); |
||
517 | _67.appendChild(_68); |
||
518 | } |
||
519 | } |
||
520 | } |
||
521 | } |
||
522 | return true; |
||
523 | },unsetAttribute:function(_6e,_6f){ |
||
524 | if(_6f==="tagName"){ |
||
525 | return false; |
||
526 | } |
||
527 | this._backupItem(_6e);
|
||
528 | var _70=_6e.element;
|
||
529 | if(_6f==="childNodes"||_6f==="text()"){ |
||
530 | while(_70.firstChild){
|
||
531 | _70.removeChild(_70.firstChild); |
||
532 | } |
||
533 | }else{
|
||
534 | _6f=this._getAttribute(_70.nodeName,_6f);
|
||
535 | if(_6f.charAt(0)==="@"){ |
||
536 | var _71=_6f.substring(1); |
||
537 | _70.removeAttribute(_71); |
||
538 | }else{
|
||
539 | for(var i=_70.childNodes.length-1;i>=0;i--){ |
||
540 | var _72=_70.childNodes[i];
|
||
541 | if(_72.nodeType===1&&_72.nodeName===_6f){ |
||
542 | _70.removeChild(_72); |
||
543 | } |
||
544 | } |
||
545 | } |
||
546 | } |
||
547 | return true; |
||
548 | },save:function(_73){ |
||
549 | if(!_73){
|
||
550 | _73={}; |
||
551 | } |
||
552 | var i;
|
||
553 | for(i=0;i<this._modifiedItems.length;i++){ |
||
554 | this._saveItem(this._modifiedItems[i],_73,"PUT"); |
||
555 | } |
||
556 | for(i=0;i<this._newItems.length;i++){ |
||
557 | var _74=this._newItems[i]; |
||
558 | if(_74.element.parentNode){
|
||
559 | this._newItems.splice(i,1); |
||
560 | i--; |
||
561 | continue;
|
||
562 | } |
||
563 | this._saveItem(this._newItems[i],_73,"POST"); |
||
564 | } |
||
565 | for(i=0;i<this._deletedItems.length;i++){ |
||
566 | this._saveItem(this._deletedItems[i],_73,"DELETE"); |
||
567 | } |
||
568 | },revert:function(){ |
||
569 | this._newItems=[];
|
||
570 | this._restoreItems(this._deletedItems); |
||
571 | this._deletedItems=[];
|
||
572 | this._restoreItems(this._modifiedItems); |
||
573 | this._modifiedItems=[];
|
||
574 | return true; |
||
575 | },isDirty:function(_75){ |
||
576 | if(_75){
|
||
577 | var _76=this._getRootElement(_75.element); |
||
578 | return (this._getItemIndex(this._newItems,_76)>=0||this._getItemIndex(this._deletedItems,_76)>=0||this._getItemIndex(this._modifiedItems,_76)>=0); |
||
579 | }else{
|
||
580 | return (this._newItems.length>0||this._deletedItems.length>0||this._modifiedItems.length>0); |
||
581 | } |
||
582 | },_saveItem:function(_77,_78,_79){ |
||
583 | var url;
|
||
584 | var _7a;
|
||
585 | if(_79==="PUT"){ |
||
586 | url=this._getPutUrl(_77);
|
||
587 | }else{
|
||
588 | if(_79==="DELETE"){ |
||
589 | url=this._getDeleteUrl(_77);
|
||
590 | }else{
|
||
591 | url=this._getPostUrl(_77);
|
||
592 | } |
||
593 | } |
||
594 | if(!url){
|
||
595 | if(_78.onError){
|
||
596 | _7a=_78.scope||dojo.global; |
||
597 | _78.onError.call(_7a,new Error("No URL for saving content: "+this._getPostContent(_77))); |
||
598 | } |
||
599 | return;
|
||
600 | } |
||
601 | var _7b={url:url,method:(_79||"POST"),contentType:"text/xml",handleAs:"xml"}; |
||
602 | var _7c;
|
||
603 | if(_79==="PUT"){ |
||
604 | _7b.putData=this._getPutContent(_77);
|
||
605 | _7c=dojo.rawXhrPut(_7b); |
||
606 | }else{
|
||
607 | if(_79==="DELETE"){ |
||
608 | _7c=dojo.xhrDelete(_7b); |
||
609 | }else{
|
||
610 | _7b.postData=this._getPostContent(_77);
|
||
611 | _7c=dojo.rawXhrPost(_7b); |
||
612 | } |
||
613 | } |
||
614 | _7a=(_78.scope||dojo.global); |
||
615 | var _7d=this; |
||
616 | _7c.addCallback(function(_7e){
|
||
617 | _7d._forgetItem(_77); |
||
618 | if(_78.onComplete){
|
||
619 | _78.onComplete.call(_7a); |
||
620 | } |
||
621 | }); |
||
622 | _7c.addErrback(function(_7f){
|
||
623 | if(_78.onError){
|
||
624 | _78.onError.call(_7a,_7f); |
||
625 | } |
||
626 | }); |
||
627 | },_getPostUrl:function(_80){ |
||
628 | return this.url; |
||
629 | },_getPutUrl:function(_81){ |
||
630 | return this.url; |
||
631 | },_getDeleteUrl:function(_82){ |
||
632 | var url=this.url; |
||
633 | if(_82&&this.keyAttribute!==""){ |
||
634 | var _83=this.getValue(_82,this.keyAttribute); |
||
635 | if(_83){
|
||
636 | var key=this.keyAttribute.charAt(0)==="@"?this.keyAttribute.substring(1):this.keyAttribute; |
||
637 | url+=url.indexOf("?")<0?"?":"&"; |
||
638 | url+=key+"="+_83;
|
||
639 | } |
||
640 | } |
||
641 | return url;
|
||
642 | },_getPostContent:function(_84){ |
||
643 | var _85=_84.element;
|
||
644 | var _86="<?xml version=\"1.0\"?>"; |
||
645 | return _86+dojox.xml.parser.innerXML(_85);
|
||
646 | },_getPutContent:function(_87){ |
||
647 | var _88=_87.element;
|
||
648 | var _89="<?xml version=\"1.0\"?>"; |
||
649 | return _89+dojox.xml.parser.innerXML(_88);
|
||
650 | },_getAttribute:function(_8a,_8b){ |
||
651 | if(this._attributeMap){ |
||
652 | var key=_8a+"."+_8b; |
||
653 | var _8c=this._attributeMap[key]; |
||
654 | if(_8c){
|
||
655 | _8b=_8c; |
||
656 | }else{
|
||
657 | _8c=this._attributeMap[_8b];
|
||
658 | if(_8c){
|
||
659 | _8b=_8c; |
||
660 | } |
||
661 | } |
||
662 | } |
||
663 | return _8b;
|
||
664 | },_getItem:function(_8d){ |
||
665 | try{
|
||
666 | var q=null; |
||
667 | if(this.keyAttribute===""){ |
||
668 | q=this._getXPath(_8d);
|
||
669 | } |
||
670 | return new dojox.data.XmlItem(_8d,this,q); |
||
671 | } |
||
672 | catch(e){
|
||
673 | } |
||
674 | return null; |
||
675 | },_getItemIndex:function(_8e,_8f){ |
||
676 | for(var i=0;i<_8e.length;i++){ |
||
677 | if(_8e[i].element===_8f){
|
||
678 | return i;
|
||
679 | } |
||
680 | } |
||
681 | return -1; |
||
682 | },_backupItem:function(_90){ |
||
683 | var _91=this._getRootElement(_90.element); |
||
684 | if(this._getItemIndex(this._newItems,_91)>=0||this._getItemIndex(this._modifiedItems,_91)>=0){ |
||
685 | return;
|
||
686 | } |
||
687 | if(_91!=_90.element){
|
||
688 | _90=this._getItem(_91);
|
||
689 | } |
||
690 | _90._backup=_91.cloneNode(true);
|
||
691 | this._modifiedItems.push(_90);
|
||
692 | },_restoreItems:function(_92){ |
||
693 | dojo.forEach(_92,function(_93){
|
||
694 | if(_93._backup){
|
||
695 | _93.element=_93._backup; |
||
696 | _93._backup=null;
|
||
697 | } |
||
698 | },this);
|
||
699 | },_forgetItem:function(_94){ |
||
700 | var _95=_94.element;
|
||
701 | var _96=this._getItemIndex(this._newItems,_95); |
||
702 | if(_96>=0){ |
||
703 | this._newItems.splice(_96,1); |
||
704 | } |
||
705 | _96=this._getItemIndex(this._deletedItems,_95); |
||
706 | if(_96>=0){ |
||
707 | this._deletedItems.splice(_96,1); |
||
708 | } |
||
709 | _96=this._getItemIndex(this._modifiedItems,_95); |
||
710 | if(_96>=0){ |
||
711 | this._modifiedItems.splice(_96,1); |
||
712 | } |
||
713 | },_getDocument:function(_97){ |
||
714 | if(_97){
|
||
715 | return _97.ownerDocument;
|
||
716 | }else{
|
||
717 | if(!this._document){ |
||
718 | return dojox.xml.parser.parse();
|
||
719 | } |
||
720 | } |
||
721 | return null; |
||
722 | },_getRootElement:function(_98){ |
||
723 | while(_98.parentNode){
|
||
724 | _98=_98.parentNode; |
||
725 | } |
||
726 | return _98;
|
||
727 | },_getXPath:function(_99){ |
||
728 | var _9a=null; |
||
729 | if(!this.sendQuery){ |
||
730 | var _9b=_99;
|
||
731 | _9a="";
|
||
732 | while(_9b&&_9b!=_99.ownerDocument){
|
||
733 | var pos=0; |
||
734 | var _9c=_9b;
|
||
735 | var _9d=_9b.nodeName;
|
||
736 | while(_9c){
|
||
737 | _9c=_9c.previousSibling; |
||
738 | if(_9c&&_9c.nodeName===_9d){
|
||
739 | pos++; |
||
740 | } |
||
741 | } |
||
742 | var _9e="/"+_9d+"["+pos+"]"; |
||
743 | if(_9a){
|
||
744 | _9a=_9e+_9a; |
||
745 | }else{
|
||
746 | _9a=_9e; |
||
747 | } |
||
748 | _9b=_9b.parentNode; |
||
749 | } |
||
750 | } |
||
751 | return _9a;
|
||
752 | },getIdentity:function(_9f){ |
||
753 | if(!this.isItem(_9f)){ |
||
754 | throw new Error("dojox.data.XmlStore: Object supplied to getIdentity is not an item"); |
||
755 | }else{
|
||
756 | var id=null; |
||
757 | if(this.sendQuery&&this.keyAttribute!==""){ |
||
758 | id=this.getValue(_9f,this.keyAttribute).toString(); |
||
759 | }else{
|
||
760 | if(!this.serverQuery){ |
||
761 | if(this.keyAttribute!==""){ |
||
762 | id=this.getValue(_9f,this.keyAttribute).toString(); |
||
763 | }else{
|
||
764 | id=_9f.q; |
||
765 | } |
||
766 | } |
||
767 | } |
||
768 | return id;
|
||
769 | } |
||
770 | },getIdentityAttributes:function(_a0){ |
||
771 | if(!this.isItem(_a0)){ |
||
772 | throw new Error("dojox.data.XmlStore: Object supplied to getIdentity is not an item"); |
||
773 | }else{
|
||
774 | if(this.keyAttribute!==""){ |
||
775 | return [this.keyAttribute]; |
||
776 | }else{
|
||
777 | return null; |
||
778 | } |
||
779 | } |
||
780 | },fetchItemByIdentity:function(_a1){ |
||
781 | var _a2=null; |
||
782 | var _a3=null; |
||
783 | var _a4=this; |
||
784 | var url=null; |
||
785 | var _a5=null; |
||
786 | var _a6=null; |
||
787 | if(!_a4.sendQuery){
|
||
788 | _a2=function(_a7){ |
||
789 | if(_a7){
|
||
790 | if(_a4.keyAttribute!==""){ |
||
791 | var _a8={};
|
||
792 | _a8.query={}; |
||
793 | _a8.query[_a4.keyAttribute]=_a1.identity; |
||
794 | _a8.queryOptions={deep:true}; |
||
795 | var _a9=_a4._getItems(_a7,_a8);
|
||
796 | _a3=_a1.scope||dojo.global; |
||
797 | if(_a9.length===1){ |
||
798 | if(_a1.onItem){
|
||
799 | _a1.onItem.call(_a3,_a9[0]);
|
||
800 | } |
||
801 | }else{
|
||
802 | if(_a9.length===0){ |
||
803 | if(_a1.onItem){
|
||
804 | _a1.onItem.call(_a3,null);
|
||
805 | } |
||
806 | }else{
|
||
807 | if(_a1.onError){
|
||
808 | _a1.onError.call(_a3,new Error("Items array size for identity lookup greater than 1, invalid keyAttribute.")); |
||
809 | } |
||
810 | } |
||
811 | } |
||
812 | }else{
|
||
813 | var _aa=_a1.identity.split("/"); |
||
814 | var i;
|
||
815 | var _ab=_a7;
|
||
816 | for(i=0;i<_aa.length;i++){ |
||
817 | if(_aa[i]&&_aa[i]!==""){ |
||
818 | var _ac=_aa[i];
|
||
819 | _ac=_ac.substring(0,_ac.length-1); |
||
820 | var _ad=_ac.split("["); |
||
821 | var tag=_ad[0]; |
||
822 | var _ae=parseInt(_ad[1],10); |
||
823 | var pos=0; |
||
824 | if(_ab){
|
||
825 | var _af=_ab.childNodes;
|
||
826 | if(_af){
|
||
827 | var j;
|
||
828 | var _b0=null; |
||
829 | for(j=0;j<_af.length;j++){ |
||
830 | var _b1=_af[j];
|
||
831 | if(_b1.nodeName===tag){
|
||
832 | if(pos<_ae){
|
||
833 | pos++; |
||
834 | }else{
|
||
835 | _b0=_b1; |
||
836 | break;
|
||
837 | } |
||
838 | } |
||
839 | } |
||
840 | if(_b0){
|
||
841 | _ab=_b0; |
||
842 | }else{
|
||
843 | _ab=null;
|
||
844 | } |
||
845 | }else{
|
||
846 | _ab=null;
|
||
847 | } |
||
848 | }else{
|
||
849 | break;
|
||
850 | } |
||
851 | } |
||
852 | } |
||
853 | var _b2=null; |
||
854 | if(_ab){
|
||
855 | _b2=_a4._getItem(_ab); |
||
856 | if(_b2.element.parentNode){
|
||
857 | _b2.element.parentNode.removeChild(_b2.element); |
||
858 | } |
||
859 | } |
||
860 | if(_a1.onItem){
|
||
861 | _a3=_a1.scope||dojo.global; |
||
862 | _a1.onItem.call(_a3,_b2); |
||
863 | } |
||
864 | } |
||
865 | } |
||
866 | }; |
||
867 | url=this._getFetchUrl(null); |
||
868 | _a5={url:url,handleAs:"xml",preventCache:_a4.urlPreventCache}; |
||
869 | _a6=dojo.xhrGet(_a5); |
||
870 | _a6.addCallback(_a2); |
||
871 | if(_a1.onError){
|
||
872 | _a6.addErrback(function(_b3){
|
||
873 | var s=_a1.scope||dojo.global;
|
||
874 | _a1.onError.call(s,_b3); |
||
875 | }); |
||
876 | } |
||
877 | }else{
|
||
878 | if(_a4.keyAttribute!==""){ |
||
879 | var _b4={query:{}}; |
||
880 | _b4.query[_a4.keyAttribute]=_a1.identity; |
||
881 | url=this._getFetchUrl(_b4);
|
||
882 | _a2=function(_b5){ |
||
883 | var _b6=null; |
||
884 | if(_b5){
|
||
885 | var _b7=_a4._getItems(_b5,{});
|
||
886 | if(_b7.length===1){ |
||
887 | _b6=_b7[0];
|
||
888 | }else{
|
||
889 | if(_a1.onError){
|
||
890 | var _b8=_a1.scope||dojo.global;
|
||
891 | _a1.onError.call(_b8,new Error("More than one item was returned from the server for the denoted identity")); |
||
892 | } |
||
893 | } |
||
894 | } |
||
895 | if(_a1.onItem){
|
||
896 | _b8=_a1.scope||dojo.global; |
||
897 | _a1.onItem.call(_b8,_b6); |
||
898 | } |
||
899 | }; |
||
900 | _a5={url:url,handleAs:"xml",preventCache:_a4.urlPreventCache}; |
||
901 | _a6=dojo.xhrGet(_a5); |
||
902 | _a6.addCallback(_a2); |
||
903 | if(_a1.onError){
|
||
904 | _a6.addErrback(function(_b9){
|
||
905 | var s=_a1.scope||dojo.global;
|
||
906 | _a1.onError.call(s,_b9); |
||
907 | }); |
||
908 | } |
||
909 | }else{
|
||
910 | if(_a1.onError){
|
||
911 | var s=_a1.scope||dojo.global;
|
||
912 | _a1.onError.call(s,new Error("XmlStore is not told that the server to provides identity support. No keyAttribute specified.")); |
||
913 | } |
||
914 | } |
||
915 | } |
||
916 | }}); |
||
917 | dojo.declare("dojox.data.XmlItem",null,{constructor:function(_ba,_bb,_bc){ |
||
918 | this.element=_ba;
|
||
919 | this.store=_bb;
|
||
920 | this.q=_bc;
|
||
921 | },toString:function(){ |
||
922 | var str=""; |
||
923 | if(this.element){ |
||
924 | for(var i=0;i<this.element.childNodes.length;i++){ |
||
925 | var _bd=this.element.childNodes[i]; |
||
926 | if(_bd.nodeType===3||_bd.nodeType===4){ |
||
927 | str+=_bd.nodeValue; |
||
928 | } |
||
929 | } |
||
930 | } |
||
931 | return str;
|
||
932 | }}); |
||
933 | dojo.extend(dojox.data.XmlStore,dojo.data.util.simpleFetch); |
||
934 | } |