//>>built
define("dojox/data/QueryReadStore",["dojo","dojox","dojo/data/util/sorter","dojo/string"],function(g,p){return g.declare("dojox.data.QueryReadStore",null,{url:"",requestMethod:"get",_className:"dojox.data.QueryReadStore",_items:[],_lastServerQuery:null,_numRows:-1,lastRequestHash:null,doClientPaging:!1,doClientSorting:!1,_itemsByIdentity:null,_identifier:null,_features:{"dojo.data.api.Read":!0,"dojo.data.api.Identity":!0},_labelAttr:"label",constructor:function(a){g.mixin(this,a)},getValue:function(a,
c,d){this._assertIsItem(a);if(!g.isString(c))throw Error(this._className+".getValue(): Invalid attribute, string expected!");return!this.hasAttribute(a,c)&&d?d:a.i[c]},getValues:function(a,c){this._assertIsItem(a);var d=[];this.hasAttribute(a,c)&&d.push(a.i[c]);return d},getAttributes:function(a){this._assertIsItem(a);var c=[],d;for(d in a.i)c.push(d);return c},hasAttribute:function(a,c){return this.isItem(a)&&"undefined"!=typeof a.i[c]},containsValue:function(a,c,d){a=this.getValues(a,c);c=a.length;
for(var b=0;b<c;b++)if(a[b]==d)return!0;return!1},isItem:function(a){return a?"undefined"!=typeof a.r&&a.r==this:!1},isItemLoaded:function(a){return this.isItem(a)},loadItem:function(a){this.isItemLoaded(a.item)},fetch:function(a){a=a||{};a.store||(a.store=this);var c=this;this._fetchItems(a,function(d,b,e){var h=b.abort||null,f=!1,k=b.start?b.start:0;0==c.doClientPaging&&(k=0);var m=b.count?k+b.count:d.length;b.abort=function(){f=!0;h&&h.call(b)};var l=b.scope||g.global;b.store||(b.store=c);b.onBegin&&
b.onBegin.call(l,e,b);b.sort&&c.doClientSorting&&d.sort(g.data.util.sorter.createSortFunction(b.sort,c));if(b.onItem)for(e=k;e<d.length&&e<m;++e){var n=d[e];f||b.onItem.call(l,n,b)}b.onComplete&&!f&&(e=null,b.onItem||(e=d.slice(k,m)),b.onComplete.call(l,e,b))},function(d,b){b.onError&&b.onError.call(b.scope||g.global,d,b)});return a},getFeatures:function(){return this._features},close:function(a){},getLabel:function(a){if(this._labelAttr&&this.isItem(a))return this.getValue(a,this._labelAttr)},getLabelAttributes:function(a){return this._labelAttr?
[this._labelAttr]:null},_xhrFetchHandler:function(a,c,d,b){a=this._filterResponse(a);a.label&&(this._labelAttr=a.label);b=a.numRows||-1;this._items=[];g.forEach(a.items,function(k){this._items.push({i:k,r:this})},this);a=a.identifier;this._itemsByIdentity={};if(a){this._identifier=a;var e;for(e=0;e<this._items.length;++e){var h=this._items[e].i,f=h[a];if(this._itemsByIdentity[f])throw Error(this._className+":  The json data as specified by: ["+this.url+"] is malformed.  Items within the list have identifier: ["+
a+"].  Value collided: ["+f+"]");this._itemsByIdentity[f]=h}}else for(this._identifier=Number,e=0;e<this._items.length;++e)this._items[e].n=e;b=this._numRows=-1===b?this._items.length:b;d(this._items,c,b);this._numRows=b},_fetchItems:function(a,c,d){var b=a.serverQuery||a.query||{};this.doClientPaging||(b.start=a.start||0,a.count&&(b.count=a.count));if(!this.doClientSorting&&a.sort){var e=[];g.forEach(a.sort,function(f){f&&f.attribute&&e.push((f.descending?"-":"")+f.attribute)});b.sort=e.join(",")}if(this.doClientPaging&&
null!==this._lastServerQuery&&g.toJson(b)==g.toJson(this._lastServerQuery))this._numRows=-1===this._numRows?this._items.length:this._numRows,c(this._items,a,this._numRows);else{var h=("post"==this.requestMethod.toLowerCase()?g.xhrPost:g.xhrGet)({url:this.url,handleAs:"json-comment-optional",content:b,failOk:!0});a.abort=function(){h.cancel()};h.addCallback(g.hitch(this,function(f){this._xhrFetchHandler(f,a,c,d)}));h.addErrback(function(f){d(f,a)});this.lastRequestHash=(new Date).getTime()+"-"+String(Math.random()).substring(2);
this._lastServerQuery=g.mixin({},b)}},_filterResponse:function(a){return a},_assertIsItem:function(a){if(!this.isItem(a))throw Error(this._className+": Invalid item argument.");},_assertIsAttribute:function(a){if("string"!==typeof a)throw Error(this._className+": Invalid attribute argument ('"+a+"').");},fetchItemByIdentity:function(a){if(this._itemsByIdentity){var c=this._itemsByIdentity[a.identity];if(void 0!==c){a.onItem&&a.onItem.call(a.scope?a.scope:g.global,{i:c,r:this});return}}this._fetchItems({serverQuery:{id:a.identity}},
function(d,b){var e=a.scope?a.scope:g.global;try{var h=null;d&&1==d.length&&(h=d[0]);a.onItem&&a.onItem.call(e,h)}catch(f){a.onError&&a.onError.call(e,f)}},function(d,b){var e=a.scope?a.scope:g.global;a.onError&&a.onError.call(e,d)})},getIdentity:function(a){var c=null;return c=this._identifier===Number?a.n:a.i[this._identifier]},getIdentityAttributes:function(a){return[this._identifier]}})});