//>>built
define("dojox/grid/enhanced/plugins/_StoreLayer",["dojo/_base/declare","dojo/_base/array","dojo/_base/lang","dojo/_base/xhr"],function(g,h,f,n){var k=f.getObject("grid.enhanced.plugins",!0,dojox),p=function(a){for(var c=["reorder","sizeChange","normal","presentation"],b=c.length,d=a.length-1;0<=d;--d){var e=h.indexOf(c,a[d]);0<=e&&e<=b&&(b=e)}return b<c.length-1?c.slice(0,b+1):c},q=function(a){var c=this._layers;var b=c.length;if(a){for(--b;0<=b;--b)if(c[b].name()==a){c[b]._unwrap(c[b+1]);break}c.splice(b,
1)}else for(--b;0<=b;--b)c[b]._unwrap();c.length||(delete this._layers,delete this.layer,delete this.unwrap,delete this.forEachLayer);return this},r=function(a){var c,b=this._layers;if("undefined"==typeof a)return b.length;if("number"==typeof a)return b[a];for(c=b.length-1;0<=c;--c)if(b[c].name()==a)return b[c];return null},t=function(a,c){var b=this._layers.length;if(c){var d=0;var e=1}else d=b-1,e=b=-1;for(;d!=b;d+=e)if(!1===a(this._layers[d],d))return d;return b};k.wrap=function(a,c,b,d){a._layers||
(a._layers=[],a.layer=f.hitch(a,r),a.unwrap=f.hitch(a,q),a.forEachLayer=f.hitch(a,t));var e=p(b.tags);h.some(a._layers,function(l,u){if(h.some(l.tags,function(v){return 0<=h.indexOf(e,v)}))return!1;a._layers.splice(u,0,b);b._wrap(a,c,d,l);return!0})||(a._layers.push(b),b._wrap(a,c,d));return a};var m=g("dojox.grid.enhanced.plugins._StoreLayer",null,{tags:["normal"],layerFuncName:"_fetch",constructor:function(){this._originFetch=this._store=null;this.__enabled=!0},initialize:function(a){},uninitialize:function(a){},
invalidate:function(){},_wrap:function(a,c,b,d){this._store=a;this._funcName=c;var e=f.hitch(this,function(){return(this.enabled()?this[b||this.layerFuncName]:this.originFetch).apply(this,arguments)});d?(this._originFetch=d._originFetch,d._originFetch=e):(this._originFetch=a[c]||function(){},a[c]=e);this.initialize(a)},_unwrap:function(a){this.uninitialize(this._store);a?a._originFetch=this._originFetch:this._store[this._funcName]=this._originFetch;this._store=this._originFetch=null},enabled:function(a){"undefined"!=
typeof a&&(this.__enabled=!!a);return this.__enabled},name:function(){if(!this.__name){var a=this.declaredClass.match(/(?:\.(?:_*)([^\.]+)Layer$)|(?:\.([^\.]+)$)/i);this.__name=a?(a[1]||a[2]).toLowerCase():this.declaredClass}return this.__name},originFetch:function(){return f.hitch(this._store,this._originFetch).apply(this,arguments)}});g=g("dojox.grid.enhanced.plugins._ServerSideLayer",m,{constructor:function(a){a=a||{};this._url=a.url||"";this._isStateful=!!a.isStateful;this._onUserCommandLoad=
a.onCommandLoad||function(){};this.__cmds={cmdlayer:this.name(),enable:!0};this.useCommands(this._isStateful)},enabled:function(a){var c=this.inherited(arguments);this.__cmds.enable=this.__enabled;return c},useCommands:function(a){"undefined"!=typeof a&&(this.__cmds.cmdlayer=a&&this._isStateful?this.name():null);return!!this.__cmds.cmdlayer},_fetch:function(a){this.__cmds.cmdlayer?n.post({url:this._url||this._store.url,content:this.__cmds,load:f.hitch(this,function(c){this.onCommandLoad(c,a);this.originFetch(a)}),
error:f.hitch(this,this.onCommandError)}):(this.onCommandLoad("",a),this.originFetch(a));return a},command:function(a,c){var b=this.__cmds;null===c?delete b[a]:"undefined"!==typeof c&&(b[a]=c);return b[a]},onCommandLoad:function(a,c){this._onUserCommandLoad(this.__cmds,c,a)},onCommandError:function(a){throw a;}});return{_StoreLayer:m,_ServerSideLayer:g,wrap:k.wrap}});