1
2
3
4
5
6
7
8
9
10
| //>>built
| define(["dojo/_base/declare","dojo/_base/lang","dojo/_base/kernel","dojo/_base/json","../_StoreLayer"],function(g,e,p,l,h){var k=function(a,b){return b?e.hitch(a||p.global,b):function(){}},q=function(a){var b={};if(a&&e.isObject(a))for(var d in a)b[d]=a[d];return b},m=g("dojox.grid.enhanced.plugins.filter._FilterLayerMixin",null,{tags:["sizeChange"],name:function(){return"filter"},onFilterDefined:function(a){},onFiltered:function(a,b){}}),r=g("dojox.grid.enhanced.plugins.filter.ServerSideFilterLayer",
| [h._ServerSideLayer,m],{constructor:function(a){this._onUserCommandLoad=a.setupFilterQuery||this._onUserCommandLoad;this.filterDef(null)},filterDef:function(a){if(a){this._filter=a;var b=a.toObject();this.command("filter",this._isStateful?l.toJson(b):b);this.command("clear",null);this.useCommands(!0);this.onFilterDefined(a)}else null===a&&(this._filter=null,this.command("filter",null),this.command("clear",!0),this.useCommands(!0),this.onFilterDefined(null));return this._filter},onCommandLoad:function(a,
| b){this.inherited(arguments);var d=b.onBegin;if(this._isStateful){var c;if(a){this.command("filter",null);this.command("clear",null);this.useCommands(!1);var f=a.split(",");if(2<=f.length)c=this._filteredSize=parseInt(f[0],10),this.onFiltered(c,parseInt(f[1],10));else return}else c=this._filteredSize;this.enabled()&&(b.onBegin=function(a,e){k(b.scope,d)(c,e)})}else{var e=this;b.onBegin=function(a,c){e._filter||(e._storeSize=a);e.onFiltered(a,e._storeSize||a);c.onBegin=d;k(b.scope,d)(a,c)}}}});g=g("dojox.grid.enhanced.plugins.filter.ClientSideFilterLayer",
| [h._StoreLayer,m],{_storeSize:-1,_fetchAll:!0,constructor:function(a){this.filterDef(null);a=e.isObject(a)?a:{};this.fetchAllOnFirstFilter(a.fetchAll);this._getter=e.isFunction(a.getter)?a.getter:this._defaultGetter},_defaultGetter:function(a,b,d,c){return c.getValue(a,b)},filterDef:function(a){void 0!==a&&(this._filter=a,this.invalidate(),this.onFilterDefined(a));return this._filter},setGetter:function(a){e.isFunction(a)&&(this._getter=a)},fetchAllOnFirstFilter:function(a){void 0!==a&&(this._fetchAll=
| !!a);return this._fetchAll},invalidate:function(){this._items=[];this._nextUnfetchedIdx=0;this._result=[];this._indexMap=[];this._resultStartIdx=0},_fetch:function(a,b){if(!this._filter){var d=a.onBegin,c=this;a.onBegin=function(b,e){k(a.scope,d)(b,e);c.onFiltered(b,b)};this.originFetch(a);return a}try{var f=b?b._nextResultItemIdx:a.start,f=f||0;if(!b){this._result=[];this._resultStartIdx=f;var g;e.isArray(a.sort)&&0<a.sort.length&&(g=l.toJson(a.sort))!=this._lastSortInfo&&(this.invalidate(),this._lastSortInfo=
| g)}var h="number"==typeof a.count?f+a.count-this._result.length:this._items.length;this._result=this._result.length?this._result.concat(this._items.slice(f,h)):this._items.slice(a.start,"number"==typeof a.count?a.start+a.count:this._items.length);this._result.length>=a.count||this._hasReachedStoreEnd()?this._completeQuery(a):(b||(b=q(a),b.onBegin=e.hitch(this,this._onFetchBegin),b.onComplete=e.hitch(this,function(b,c){this._nextUnfetchedIdx+=b.length;this._doFilter(b,c.start,a);this._fetch(a,c)})),
| b.start=this._nextUnfetchedIdx,this._fetchAll&&delete b.count,b._nextResultItemIdx=h<this._items.length?h:this._items.length,this.originFetch(b))}catch(n){if(a.onError)k(a.scope,a.onError)(n,a);else throw n;}return a},_hasReachedStoreEnd:function(){return 0<=this._storeSize&&this._nextUnfetchedIdx>=this._storeSize},_applyFilter:function(a,b){var d=this._getter,c=this._store;try{return!!this._filter.applyRow(a,function(a,e){return d(a,e,b,c)}).getValue()}catch(f){return console.warn("FilterLayer._applyFilter() error: ",
| f),!1}},_doFilter:function(a,b,d){for(var c=0,e=0;c<a.length;++c)this._applyFilter(a[c],b+c)&&(k(d.scope,d.onItem)(a[c],d),e+=this._addCachedItems(a[c],this._items.length),this._indexMap.push(b+c))},_onFetchBegin:function(a,b){this._storeSize=a},_completeQuery:function(a){var b=this._items.length;this._nextUnfetchedIdx<this._storeSize&&b++;k(a.scope,a.onBegin)(b,a);this.onFiltered(this._items.length,this._storeSize);k(a.scope,a.onComplete)(this._result,a)},_addCachedItems:function(a,b){e.isArray(a)||
| (a=[a]);for(var d=0;d<a.length;++d)this._items[b+d]=a[d];return a.length},onRowMappingChange:function(a){if(this._filter){var b=e.clone(a),d={},c;for(c in b)c=parseInt(c,10),a[this._indexMap[c]]=this._indexMap[b[c]],d[this._indexMap[c]]||(d[this._indexMap[c]]=!0),d[c]||(d[c]=!0,delete a[c])}}});return e.mixin({ServerSideFilterLayer:r,ClientSideFilterLayer:g},h)});
|
|