Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / data / FileStore.js @ 12

History | View | Annotate | Download (5.51 KB)

1
/*
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.FileStore"]){
9
dojo._hasResource["dojox.data.FileStore"]=true;
10
dojo.provide("dojox.data.FileStore");
11
dojo.declare("dojox.data.FileStore",null,{constructor:function(_1){
12
if(_1&&_1.label){
13
this.label=_1.label;
14
}
15
if(_1&&_1.url){
16
this.url=_1.url;
17
}
18
if(_1&&_1.options){
19
if(dojo.isArray(_1.options)){
20
this.options=_1.options;
21
}else{
22
if(dojo.isString(_1.options)){
23
this.options=_1.options.split(",");
24
}
25
}
26
}
27
if(_1&&_1.pathAsQueryParam){
28
this.pathAsQueryParam=true;
29
}
30
if(_1&&"urlPreventCache" in _1){
31
this.urlPreventCache=_1.urlPreventCache?true:false;
32
}
33
},url:"",_storeRef:"_S",label:"name",_identifier:"path",_attributes:["children","directory","name","path","modified","size","parentDir"],pathSeparator:"/",options:[],failOk:false,urlPreventCache:true,_assertIsItem:function(_2){
34
if(!this.isItem(_2)){
35
throw new Error("dojox.data.FileStore: a function was passed an item argument that was not an item");
36
}
37
},_assertIsAttribute:function(_3){
38
if(typeof _3!=="string"){
39
throw new Error("dojox.data.FileStore: a function was passed an attribute argument that was not an attribute name string");
40
}
41
},pathAsQueryParam:false,getFeatures:function(){
42
return {"dojo.data.api.Read":true,"dojo.data.api.Identity":true};
43
},getValue:function(_4,_5,_6){
44
var _7=this.getValues(_4,_5);
45
if(_7&&_7.length>0){
46
return _7[0];
47
}
48
return _6;
49
},getAttributes:function(_8){
50
return this._attributes;
51
},hasAttribute:function(_9,_a){
52
this._assertIsItem(_9);
53
this._assertIsAttribute(_a);
54
return (_a in _9);
55
},getIdentity:function(_b){
56
return this.getValue(_b,this._identifier);
57
},getIdentityAttributes:function(_c){
58
return [this._identifier];
59
},isItemLoaded:function(_d){
60
var _e=this.isItem(_d);
61
if(_e&&typeof _d._loaded=="boolean"&&!_d._loaded){
62
_e=false;
63
}
64
return _e;
65
},loadItem:function(_f){
66
var _10=_f.item;
67
var _11=this;
68
var _12=_f.scope||dojo.global;
69
var _13={};
70
if(this.options.length>0){
71
_13.options=dojo.toJson(this.options);
72
}
73
if(this.pathAsQueryParam){
74
_13.path=_10.parentPath+this.pathSeparator+_10.name;
75
}
76
var _14={url:this.pathAsQueryParam?this.url:this.url+"/"+_10.parentPath+"/"+_10.name,handleAs:"json-comment-optional",content:_13,preventCache:this.urlPreventCache,failOk:this.failOk};
77
var _15=dojo.xhrGet(_14);
78
_15.addErrback(function(_16){
79
if(_f.onError){
80
_f.onError.call(_12,_16);
81
}
82
});
83
_15.addCallback(function(_17){
84
delete _10.parentPath;
85
delete _10._loaded;
86
dojo.mixin(_10,_17);
87
_11._processItem(_10);
88
if(_f.onItem){
89
_f.onItem.call(_12,_10);
90
}
91
});
92
},getLabel:function(_18){
93
return this.getValue(_18,this.label);
94
},getLabelAttributes:function(_19){
95
return [this.label];
96
},containsValue:function(_1a,_1b,_1c){
97
var _1d=this.getValues(_1a,_1b);
98
for(var i=0;i<_1d.length;i++){
99
if(_1d[i]==_1c){
100
return true;
101
}
102
}
103
return false;
104
},getValues:function(_1e,_1f){
105
this._assertIsItem(_1e);
106
this._assertIsAttribute(_1f);
107
var _20=_1e[_1f];
108
if(typeof _20!=="undefined"&&!dojo.isArray(_20)){
109
_20=[_20];
110
}else{
111
if(typeof _20==="undefined"){
112
_20=[];
113
}
114
}
115
return _20;
116
},isItem:function(_21){
117
if(_21&&_21[this._storeRef]===this){
118
return true;
119
}
120
return false;
121
},close:function(_22){
122
},fetch:function(_23){
123
_23=_23||{};
124
if(!_23.store){
125
_23.store=this;
126
}
127
var _24=this;
128
var _25=_23.scope||dojo.global;
129
var _26={};
130
if(_23.query){
131
_26.query=dojo.toJson(_23.query);
132
}
133
if(_23.sort){
134
_26.sort=dojo.toJson(_23.sort);
135
}
136
if(_23.queryOptions){
137
_26.queryOptions=dojo.toJson(_23.queryOptions);
138
}
139
if(typeof _23.start=="number"){
140
_26.start=""+_23.start;
141
}
142
if(typeof _23.count=="number"){
143
_26.count=""+_23.count;
144
}
145
if(this.options.length>0){
146
_26.options=dojo.toJson(this.options);
147
}
148
var _27={url:this.url,preventCache:this.urlPreventCache,failOk:this.failOk,handleAs:"json-comment-optional",content:_26};
149
var _28=dojo.xhrGet(_27);
150
_28.addCallback(function(_29){
151
_24._processResult(_29,_23);
152
});
153
_28.addErrback(function(_2a){
154
if(_23.onError){
155
_23.onError.call(_25,_2a,_23);
156
}
157
});
158
},fetchItemByIdentity:function(_2b){
159
var _2c=_2b.identity;
160
var _2d=this;
161
var _2e=_2b.scope||dojo.global;
162
var _2f={};
163
if(this.options.length>0){
164
_2f.options=dojo.toJson(this.options);
165
}
166
if(this.pathAsQueryParam){
167
_2f.path=_2c;
168
}
169
var _30={url:this.pathAsQueryParam?this.url:this.url+"/"+_2c,handleAs:"json-comment-optional",content:_2f,preventCache:this.urlPreventCache,failOk:this.failOk};
170
var _31=dojo.xhrGet(_30);
171
_31.addErrback(function(_32){
172
if(_2b.onError){
173
_2b.onError.call(_2e,_32);
174
}
175
});
176
_31.addCallback(function(_33){
177
var _34=_2d._processItem(_33);
178
if(_2b.onItem){
179
_2b.onItem.call(_2e,_34);
180
}
181
});
182
},_processResult:function(_35,_36){
183
var _37=_36.scope||dojo.global;
184
try{
185
if(_35.pathSeparator){
186
this.pathSeparator=_35.pathSeparator;
187
}
188
if(_36.onBegin){
189
_36.onBegin.call(_37,_35.total,_36);
190
}
191
var _38=this._processItemArray(_35.items);
192
if(_36.onItem){
193
var i;
194
for(i=0;i<_38.length;i++){
195
_36.onItem.call(_37,_38[i],_36);
196
}
197
_38=null;
198
}
199
if(_36.onComplete){
200
_36.onComplete.call(_37,_38,_36);
201
}
202
}
203
catch(e){
204
if(_36.onError){
205
_36.onError.call(_37,e,_36);
206
}else{
207
}
208
}
209
},_processItemArray:function(_39){
210
var i;
211
for(i=0;i<_39.length;i++){
212
this._processItem(_39[i]);
213
}
214
return _39;
215
},_processItem:function(_3a){
216
if(!_3a){
217
return null;
218
}
219
_3a[this._storeRef]=this;
220
if(_3a.children&&_3a.directory){
221
if(dojo.isArray(_3a.children)){
222
var _3b=_3a.children;
223
var i;
224
for(i=0;i<_3b.length;i++){
225
var _3c=_3b[i];
226
if(dojo.isObject(_3c)){
227
_3b[i]=this._processItem(_3c);
228
}else{
229
_3b[i]={name:_3c,_loaded:false,parentPath:_3a.path};
230
_3b[i][this._storeRef]=this;
231
}
232
}
233
}else{
234
delete _3a.children;
235
}
236
}
237
return _3a;
238
}});
239
}