Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / data / SnapLogicStore.js

History | View | Annotate | Download (4.48 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.SnapLogicStore"]){
9
dojo._hasResource["dojox.data.SnapLogicStore"]=true;
10
dojo.provide("dojox.data.SnapLogicStore");
11
dojo.require("dojo.io.script");
12
dojo.require("dojo.data.util.sorter");
13
dojo.declare("dojox.data.SnapLogicStore",null,{Parts:{DATA:"data",COUNT:"count"},url:"",constructor:function(_1){
14
if(_1.url){
15
this.url=_1.url;
16
}
17
this._parameters=_1.parameters;
18
},_assertIsItem:function(_2){
19
if(!this.isItem(_2)){
20
throw new Error("dojox.data.SnapLogicStore: a function was passed an item argument that was not an item");
21
}
22
},_assertIsAttribute:function(_3){
23
if(typeof _3!=="string"){
24
throw new Error("dojox.data.SnapLogicStore: a function was passed an attribute argument that was not an attribute name string");
25
}
26
},getFeatures:function(){
27
return {"dojo.data.api.Read":true};
28
},getValue:function(_4,_5,_6){
29
this._assertIsItem(_4);
30
this._assertIsAttribute(_5);
31
var i=dojo.indexOf(_4.attributes,_5);
32
if(i!==-1){
33
return _4.values[i];
34
}
35
return _6;
36
},getAttributes:function(_7){
37
this._assertIsItem(_7);
38
return _7.attributes;
39
},hasAttribute:function(_8,_9){
40
this._assertIsItem(_8);
41
this._assertIsAttribute(_9);
42
for(var i=0;i<_8.attributes.length;++i){
43
if(_9==_8.attributes[i]){
44
return true;
45
}
46
}
47
return false;
48
},isItemLoaded:function(_a){
49
return this.isItem(_a);
50
},loadItem:function(_b){
51
},getLabel:function(_c){
52
return undefined;
53
},getLabelAttributes:function(_d){
54
return null;
55
},containsValue:function(_e,_f,_10){
56
return this.getValue(_e,_f)===_10;
57
},getValues:function(_11,_12){
58
this._assertIsItem(_11);
59
this._assertIsAttribute(_12);
60
var i=dojo.indexOf(_11.attributes,_12);
61
if(i!==-1){
62
return [_11.values[i]];
63
}
64
return [];
65
},isItem:function(_13){
66
if(_13&&_13._store===this){
67
return true;
68
}
69
return false;
70
},close:function(_14){
71
},_fetchHandler:function(_15){
72
var _16=_15.scope||dojo.global;
73
if(_15.onBegin){
74
_15.onBegin.call(_16,_15._countResponse[0],_15);
75
}
76
if(_15.onItem||_15.onComplete){
77
var _17=_15._dataResponse;
78
if(!_17.length){
79
_15.onError.call(_16,new Error("dojox.data.SnapLogicStore: invalid response of length 0"),_15);
80
return;
81
}else{
82
if(_15.query!="record count"){
83
var _18=_17.shift();
84
var _19=[];
85
for(var i=0;i<_17.length;++i){
86
if(_15._aborted){
87
break;
88
}
89
_19.push({attributes:_18,values:_17[i],_store:this});
90
}
91
if(_15.sort&&!_15._aborted){
92
_19.sort(dojo.data.util.sorter.createSortFunction(_15.sort,self));
93
}
94
}else{
95
_19=[({attributes:["count"],values:_17,_store:this})];
96
}
97
}
98
if(_15.onItem){
99
for(var i=0;i<_19.length;++i){
100
if(_15._aborted){
101
break;
102
}
103
_15.onItem.call(_16,_19[i],_15);
104
}
105
_19=null;
106
}
107
if(_15.onComplete&&!_15._aborted){
108
_15.onComplete.call(_16,_19,_15);
109
}
110
}
111
},_partHandler:function(_1a,_1b,_1c){
112
if(_1c instanceof Error){
113
if(_1b==this.Parts.DATA){
114
_1a._dataHandle=null;
115
}else{
116
_1a._countHandle=null;
117
}
118
_1a._aborted=true;
119
if(_1a.onError){
120
_1a.onError.call(_1a.scope,_1c,_1a);
121
}
122
}else{
123
if(_1a._aborted){
124
return;
125
}
126
if(_1b==this.Parts.DATA){
127
_1a._dataResponse=_1c;
128
}else{
129
_1a._countResponse=_1c;
130
}
131
if((!_1a._dataHandle||_1a._dataResponse!==null)&&(!_1a._countHandle||_1a._countResponse!==null)){
132
this._fetchHandler(_1a);
133
}
134
}
135
},fetch:function(_1d){
136
_1d._countResponse=null;
137
_1d._dataResponse=null;
138
_1d._aborted=false;
139
_1d.abort=function(){
140
if(!_1d._aborted){
141
_1d._aborted=true;
142
if(_1d._dataHandle&&_1d._dataHandle.cancel){
143
_1d._dataHandle.cancel();
144
}
145
if(_1d._countHandle&&_1d._countHandle.cancel){
146
_1d._countHandle.cancel();
147
}
148
}
149
};
150
if(_1d.onItem||_1d.onComplete){
151
var _1e=this._parameters||{};
152
if(_1d.start){
153
if(_1d.start<0){
154
throw new Error("dojox.data.SnapLogicStore: request start value must be 0 or greater");
155
}
156
_1e["sn.start"]=_1d.start+1;
157
}
158
if(_1d.count){
159
if(_1d.count<0){
160
throw new Error("dojox.data.SnapLogicStore: request count value 0 or greater");
161
}
162
_1e["sn.limit"]=_1d.count;
163
}
164
_1e["sn.content_type"]="application/javascript";
165
var _1f=this;
166
var _20=function(_21,_22){
167
if(_21 instanceof Error){
168
_1f._fetchHandler(_21,_1d);
169
}
170
};
171
var _23={url:this.url,content:_1e,timeout:60000,callbackParamName:"sn.stream_header",handle:dojo.hitch(this,"_partHandler",_1d,this.Parts.DATA)};
172
_1d._dataHandle=dojo.io.script.get(_23);
173
}
174
if(_1d.onBegin){
175
var _1e={};
176
_1e["sn.count"]="records";
177
_1e["sn.content_type"]="application/javascript";
178
var _23={url:this.url,content:_1e,timeout:60000,callbackParamName:"sn.stream_header",handle:dojo.hitch(this,"_partHandler",_1d,this.Parts.COUNT)};
179
_1d._countHandle=dojo.io.script.get(_23);
180
}
181
return _1d;
182
}});
183
}