root / trunk / web / dojo / dojox / data / util / JsonQuery.js
History | View | Annotate | Download (2.28 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.util.JsonQuery"]){ |
| 9 |
dojo._hasResource["dojox.data.util.JsonQuery"]=true; |
| 10 |
dojo.provide("dojox.data.util.JsonQuery");
|
| 11 |
dojo.declare("dojox.data.util.JsonQuery",null,{useFullIdInQueries:false,_toJsonQuery:function(_1,_2){ |
| 12 |
var _3=true; |
| 13 |
var _4=this; |
| 14 |
function _5(_6,_7){ |
| 15 |
var _8=_7.__id;
|
| 16 |
if(_8){
|
| 17 |
var _9={};
|
| 18 |
_9[_4.idAttribute]=_4.useFullIdInQueries?_7.__id:_7[_4.idAttribute]; |
| 19 |
_7=_9; |
| 20 |
} |
| 21 |
for(var i in _7){ |
| 22 |
var _a=_7[i];
|
| 23 |
var _b=_6+(/^[a-zA-Z_][\w_]*$/.test(i)?"."+i:"["+dojo._escapeString(i)+"]"); |
| 24 |
if(_a&&typeof _a=="object"){ |
| 25 |
_5(_b,_a); |
| 26 |
}else{
|
| 27 |
if(_a!="*"){ |
| 28 |
_c+=(_3?"":"&")+_b+((!_8&&typeof _a=="string"&&_1.queryOptions&&_1.queryOptions.ignoreCase)?"~":"=")+(_4.simplifiedQuery?encodeURIComponent(_a):dojo.toJson(_a)); |
| 29 |
_3=false;
|
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
}; |
| 34 |
if(_1.query&&typeof _1.query=="object"){ |
| 35 |
var _c="[?("; |
| 36 |
_5("@",_1.query);
|
| 37 |
if(!_3){
|
| 38 |
_c+=")]";
|
| 39 |
}else{
|
| 40 |
_c="";
|
| 41 |
} |
| 42 |
_1.queryStr=_c.replace(/\\"|"/g,function(t){ |
| 43 |
return t=="\""?"'":t; |
| 44 |
}); |
| 45 |
}else{
|
| 46 |
if(!_1.query||_1.query=="*"){ |
| 47 |
_1.query="";
|
| 48 |
} |
| 49 |
} |
| 50 |
var _d=_1.sort;
|
| 51 |
if(_d){
|
| 52 |
_1.queryStr=_1.queryStr||(typeof _1.query=="string"?_1.query:""); |
| 53 |
_3=true;
|
| 54 |
for(i=0;i<_d.length;i++){ |
| 55 |
_1.queryStr+=(_3?"[":",")+(_d[i].descending?"\\":"/")+"@["+dojo._escapeString(_d[i].attribute)+"]"; |
| 56 |
_3=false;
|
| 57 |
} |
| 58 |
} |
| 59 |
if(_2&&(_1.start||_1.count)){
|
| 60 |
_1.queryStr=(_1.queryStr||(typeof _1.query=="string"?_1.query:""))+"["+(_1.start||"")+":"+(_1.count?(_1.start||0)+_1.count:"")+"]"; |
| 61 |
} |
| 62 |
if(typeof _1.queryStr=="string"){ |
| 63 |
_1.queryStr=_1.queryStr.replace(/\\"|"/g,function(t){ |
| 64 |
return t=="\""?"'":t; |
| 65 |
}); |
| 66 |
return _1.queryStr;
|
| 67 |
} |
| 68 |
return _1.query;
|
| 69 |
},jsonQueryPagination:true,fetch:function(_e){ |
| 70 |
this._toJsonQuery(_e,this.jsonQueryPagination); |
| 71 |
return this.inherited(arguments); |
| 72 |
},isUpdateable:function(){ |
| 73 |
return true; |
| 74 |
},matchesQuery:function(_f,_10){ |
| 75 |
_10._jsonQuery=_10._jsonQuery||dojox.json.query(this._toJsonQuery(_10));
|
| 76 |
return _10._jsonQuery([_f]).length;
|
| 77 |
},clientSideFetch:function(_11,_12){ |
| 78 |
_11._jsonQuery=_11._jsonQuery||dojox.json.query(this._toJsonQuery(_11));
|
| 79 |
return this.clientSidePaging(_11,_11._jsonQuery(_12)); |
| 80 |
},querySuperSet:function(_13,_14){ |
| 81 |
if(!_13.query){
|
| 82 |
return _14.query;
|
| 83 |
} |
| 84 |
return this.inherited(arguments); |
| 85 |
}}); |
| 86 |
} |