//>>built
define("dojox/data/ClientFilter",["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/Deferred","dojo/data/util/filter"],function(t,k,p,u,q){var n=function(a,b,c){return function(d){a._updates.push({create:b&&d,remove:c&&d});m.onUpdate()}},m=t("dojox.data.ClientFilter",null,{cacheByDefault:!1,constructor:function(){this.onSet=n(this,!0,!0);this.onNew=n(this,!0,!1);this.onDelete=n(this,!1,!0);this._updates=[];this._fetchCache=[]},clearCache:function(){this._fetchCache=[]},updateResultSet:function(a,
b){if(this.isUpdateable(b)){for(var c=b._version||0;c<this._updates.length;c++){var d=this._updates[c].create,f=this._updates[c].remove;if(f)for(var e=0;e<a.length;e++)if(this.getIdentity(a[e])==this.getIdentity(f)){a.splice(e--,1);var g=!0}d&&this.matchesQuery(d,b)&&-1==p.indexOf(a,d)&&(a.push(d),g=!0)}b.sort&&g&&a.sort(this.makeComparator(b.sort.concat()));a._fullLength=a.length;b.count&&g&&Infinity!==b.count&&a.splice(b.count,a.length);b._version=this._updates.length;return g?2:1}return 0},querySuperSet:function(a,
b){if(a.query==b.query)return{};if(!(b.query instanceof Object)||a.query&&"object"!=typeof a.query)return!1;var c=k.mixin({},b.query),d;for(d in a.query)if(c[d]==a.query[d])delete c[d];else if("string"!=typeof a.query[d]||!q.patternToRegExp(a.query[d]).test(c[d]))return!1;return c},serverVersion:0,cachingFetch:function(a){for(var b=this,c=0;c<this._fetchCache.length;c++){var d=this._fetchCache[c],f=this.querySuperSet(d,a);if(!1!==f){var e=d._loading;e||(e=new u,e.callback(d.cacheResults));e.addCallback(function(h){h=
b.clientSideFetch(k.mixin(k.mixin({},a),{query:f}),h);e.fullLength=h._fullLength;return h});a._version=d._version;break}}if(!e){c=k.mixin({},a);d=(a.queryOptions||0).cache;var g=this._fetchCache;if(void 0===d?this.cacheByDefault:d){if(a.start||a.count)delete c.start,delete c.count,a.clientQuery=k.mixin(a.clientQuery||{},{start:a.start,count:a.count});a=c;g.push(a)}e=a._loading=this._doQuery(a);e.addErrback(function(){g.splice(p.indexOf(g,a),1)})}var l=this.serverVersion;e.addCallback(function(h){delete a._loading;
h&&(a._version="number"==typeof a._version?a._version:l,b.updateResultSet(h,a),a.cacheResults=h,!a.count||h.length<a.count)&&(e.fullLength=(a.start?a.start:0)+h.length);return h});return e},isUpdateable:function(a){return!a.query||"object"==typeof a.query},clientSideFetch:function(a,b){a.queryOptions&&a.queryOptions.results&&(b=a.queryOptions.results);if(a.query)for(var c=[],d=0;d<b.length;d++){var f=b[d];f&&this.matchesQuery(f,a)&&c.push(b[d])}else c=a.sort?b.concat():b;a.sort&&c.sort(this.makeComparator(a.sort.concat()));
return this.clientSidePaging(a,c)},clientSidePaging:function(a,b){var c=a.start||0;c=c||a.count?b.slice(c,c+(a.count||b.length)):b;c._fullLength=b.length;return c},matchesQuery:function(a,b){var c=b.query,d=b.queryOptions&&b.queryOptions.ignoreCase,f;for(f in c){var e=c[f],g=this.getValue(a,f);if("string"==typeof e&&(e.match(/[\*\.]/)||d)?!q.patternToRegExp(e,d).test(g):g!=e)return!1}return!0},makeComparator:function(a){var b=a.shift();if(!b)return function(){return 0};var c=b.attribute,d=!!b.descending,
f=this.makeComparator(a),e=this;return function(g,l){var h=e.getValue(g,c),r=e.getValue(l,c);return h!=r?h<r==d?1:-1:f(g,l)}}});m.onUpdate=function(){};return m});