Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / rpc / Rest.js @ 12

History | View | Annotate | Download (2.3 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.rpc.Rest"]){
9
dojo._hasResource["dojox.rpc.Rest"]=true;
10
dojo.provide("dojox.rpc.Rest");
11
(function(){
12
if(dojox.rpc&&dojox.rpc.transportRegistry){
13
dojox.rpc.transportRegistry.register("REST",function(_1){
14
return _1=="REST";
15
},{getExecutor:function(_2,_3,_4){
16
return new dojox.rpc.Rest(_3.name,(_3.contentType||_4._smd.contentType||"").match(/json|javascript/),null,function(id,_5){
17
var _6=_4._getRequest(_3,[id]);
18
_6.url=_6.target+(_6.data?"?"+_6.data:"");
19
return _6;
20
});
21
}});
22
}
23
var _7;
24
function _8(_9,_a,_b,id){
25
_9.addCallback(function(_c){
26
if(_9.ioArgs.xhr&&_b){
27
_b=_9.ioArgs.xhr.getResponseHeader("Content-Range");
28
_9.fullLength=_b&&(_b=_b.match(/\/(.*)/))&&parseInt(_b[1]);
29
}
30
return _c;
31
});
32
return _9;
33
};
34
_7=dojox.rpc.Rest=function(_d,_e,_f,_10){
35
var _11;
36
_11=function(id,_12){
37
return _7._get(_11,id,_12);
38
};
39
_11.isJson=_e;
40
_11._schema=_f;
41
_11.cache={serialize:_e?((dojox.json&&dojox.json.ref)||dojo).toJson:function(_13){
42
return _13;
43
}};
44
_11._getRequest=_10||function(id,_14){
45
if(dojo.isObject(id)){
46
id=dojo.objectToQuery(id);
47
id=id?"?"+id:"";
48
}
49
if(_14&&_14.sort&&!_14.queryStr){
50
id+=(id?"&":"?")+"sort(";
51
for(var i=0;i<_14.sort.length;i++){
52
var _15=_14.sort[i];
53
id+=(i>0?",":"")+(_15.descending?"-":"+")+encodeURIComponent(_15.attribute);
54
}
55
id+=")";
56
}
57
var _16={url:_d+(id==null?"":id),handleAs:_e?"json":"text",contentType:_e?"application/json":"text/plain",sync:dojox.rpc._sync,headers:{Accept:_e?"application/json,application/javascript":"*/*"}};
58
if(_14&&(_14.start>=0||_14.count>=0)){
59
_16.headers.Range="items="+(_14.start||"0")+"-"+((_14.count&&_14.count!=Infinity&&(_14.count+(_14.start||0)-1))||"");
60
}
61
dojox.rpc._sync=false;
62
return _16;
63
};
64
function _17(_18){
65
_11[_18]=function(id,_19){
66
return _7._change(_18,_11,id,_19);
67
};
68
};
69
_17("put");
70
_17("post");
71
_17("delete");
72
_11.servicePath=_d;
73
return _11;
74
};
75
_7._index={};
76
_7._timeStamps={};
77
_7._change=function(_1a,_1b,id,_1c){
78
var _1d=_1b._getRequest(id);
79
_1d[_1a+"Data"]=_1c;
80
return _8(dojo.xhr(_1a.toUpperCase(),_1d,true),_1b);
81
};
82
_7._get=function(_1e,id,_1f){
83
_1f=_1f||{};
84
return _8(dojo.xhrGet(_1e._getRequest(id,_1f)),_1e,(_1f.start>=0||_1f.count>=0),id);
85
};
86
})();
87
}