root / trunk / web / dojo / dojox / data / CouchDBRestStore.js @ 13
History | View | Annotate | Download (1.58 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.CouchDBRestStore"]){ |
9 |
dojo._hasResource["dojox.data.CouchDBRestStore"]=true; |
10 |
dojo.provide("dojox.data.CouchDBRestStore");
|
11 |
dojo.require("dojox.data.JsonRestStore");
|
12 |
dojo.declare("dojox.data.CouchDBRestStore",dojox.data.JsonRestStore,{save:function(_1){ |
13 |
var _2=this.inherited(arguments); |
14 |
var _3=this.service.servicePath; |
15 |
for(var i=0;i<_2.length;i++){ |
16 |
(function(_4,_5){
|
17 |
_5.addCallback(function(_6){
|
18 |
if(_6){
|
19 |
_4.__id=_3+_6.id; |
20 |
_4._rev=_6.rev; |
21 |
} |
22 |
return _6;
|
23 |
}); |
24 |
})(_2[i].content,_2[i].deferred); |
25 |
} |
26 |
},fetch:function(_7){ |
27 |
_7.query=_7.query||"_all_docs?";
|
28 |
if(_7.start){
|
29 |
_7.query=(_7.query?(_7.query+"&"):"")+"startkey="+_7.start; |
30 |
delete _7.start;
|
31 |
} |
32 |
if(_7.count){
|
33 |
_7.query=(_7.query?(_7.query+"&"):"")+"limit="+_7.count; |
34 |
delete _7.count;
|
35 |
} |
36 |
return this.inherited(arguments); |
37 |
},_processResults:function(_8){ |
38 |
var _9=_8.rows;
|
39 |
if(_9){
|
40 |
var _a=this.service.servicePath; |
41 |
var _b=this; |
42 |
for(var i=0;i<_9.length;i++){ |
43 |
var _c=_9[i].value;
|
44 |
_c.__id=_a+_9[i].id; |
45 |
_c._id=_9[i].id; |
46 |
_c._loadObject=dojox.rpc.JsonRest._loader; |
47 |
_9[i]=_c; |
48 |
} |
49 |
return {totalCount:_8.total_rows,items:_8.rows}; |
50 |
}else{
|
51 |
return {items:_8}; |
52 |
} |
53 |
}}); |
54 |
dojox.data.CouchDBRestStore.getStores=function(_d){ |
55 |
var _e=dojo.xhrGet({url:_d+"_all_dbs",handleAs:"json",sync:true}); |
56 |
var _f={};
|
57 |
_e.addBoth(function(dbs){
|
58 |
for(var i=0;i<dbs.length;i++){ |
59 |
_f[dbs[i]]=new dojox.data.CouchDBRestStore({target:_d+dbs[i],idAttribute:"_id"}); |
60 |
} |
61 |
return _f;
|
62 |
}); |
63 |
return _f;
|
64 |
}; |
65 |
} |