//>>built
define("dojox/grid/enhanced/plugins/Cookie","dojo/_base/declare dojo/_base/array dojo/_base/lang dojo/_base/sniff dojo/_base/html dojo/_base/json dojo/_base/window dojo/_base/unload dojo/cookie ../_Plugin ../../_RowSelector ../../EnhancedGrid ../../cells/_base".split(" "),function(m,g,f,r,x,n,y,z,p,A,B,t){var u=f.getObject("dojox.grid.cells"),v=function(a){var b=[];f.isArray(a)||(a=[a]);g.forEach(a,function(c){f.isArray(c)&&(c={cells:c});c=c.rows||c.cells;f.isArray(c)&&(f.isArray(c[0])||(c=[c]),g.forEach(c,
function(e){f.isArray(e)&&g.forEach(e,function(d){b.push(d)})}))});return b},C=function(a,b){if(f.isArray(a)){var c=b._setStructureAttr;b._setStructureAttr=function(e){if(!b._colWidthLoaded){b._colWidthLoaded=!0;for(var d=v(e),h=d.length-1;0<=h;--h)"number"==typeof a[h]?d[h].width=a[h]+"px":"hidden"==a[h]&&(d[h].hidden=!0)}c.call(b,e);b._setStructureAttr=c}}},D=function(a){return g.map(g.filter(a.layout.cells,function(b){return!(b.isRowSelector||b instanceof u.RowIndex)}),function(b){return b.hidden?
"hidden":x[r("webkit")?"marginBox":"contentBox"](b.getHeaderNode()).w})},H=function(a,b){if(a&&g.every(a,function(d){return f.isArray(d)&&g.every(d,function(h){return f.isArray(h)&&0<h.length})})){var c=b._setStructureAttr,e=function(d){return null!==d&&f.isObject(d)&&("cells"in d||"rows"in d||"type"in d&&!("name"in d||"field"in d||"get"in d))};b._setStructureAttr=function(d){if(!b._colOrderLoaded){b._colOrderLoaded=!0;b._setStructureAttr=c;d=f.clone(d);f.isArray(d)&&!g.some(d,e)?d=[{cells:d}]:e(d)&&
(d=[d]);var h=v(d);g.forEach(f.isArray(d)?d:[d],function(k,E){var w=k;f.isArray(k)?k.splice(0,k.length):(delete k.rows,w=k.cells=[]);g.forEach(a[E],function(F){g.forEach(F,function(G){var l;for(l=0;l<h.length;++l){var q=h[l];if(n.toJson({name:q.name,field:q.field})==n.toJson(G))break}l<h.length&&w.push(q)})})})}c.call(b,d)}}},I=function(a){return g.map(g.filter(a.views.views,function(b){return!(b instanceof B)}),function(b){return g.map(b.structure.cells,function(c){return g.map(g.filter(c,function(e){return!(e.isRowSelector||
e instanceof u.RowIndex)}),function(e){return{name:e.name,field:e.field}})})})},J=function(a,b){try{a&&f.isObject(a)&&b.setSortIndex(a.idx,a.asc)}catch(c){}},K=function(a){return{idx:a.getSortIndex(),asc:a.getSortAsc()}};r("ie")||z.addOnWindowUnload(function(){g.forEach(dijit.findWidgets(y.body()),function(a){a instanceof t&&!a._destroyed&&a.destroyRecursive()})});m=m("dojox.grid.enhanced.plugins.Cookie",A,{name:"cookie",_cookieEnabled:!0,constructor:function(a,b){this.grid=a;b=b&&f.isObject(b)?b:
{};this.cookieProps=b.cookieProps;this._cookieHandlers=[];this._mixinGrid();this.addCookieHandler({name:"columnWidth",onLoad:C,onSave:D});this.addCookieHandler({name:"columnOrder",onLoad:H,onSave:I});this.addCookieHandler({name:"sortOrder",onLoad:J,onSave:K});g.forEach(this._cookieHandlers,function(c){!1===b[c.name]&&(c.enable=!1)},this)},destroy:function(){this._saveCookie();this._cookieHandlers=null;this.inherited(arguments)},_mixinGrid:function(){var a=this.grid;a.addCookieHandler=f.hitch(this,
"addCookieHandler");a.removeCookie=f.hitch(this,"removeCookie");a.setCookieEnabled=f.hitch(this,"setCookieEnabled");a.getCookieEnabled=f.hitch(this,"getCookieEnabled")},_saveCookie:function(){if(this.getCookieEnabled()){var a={},b=this._cookieHandlers,c=this.cookieProps,e=window.location+"/"+this.grid.id;for(c=b.length-1;0<=c;--c)b[c].enabled&&(a[b[c].name]=b[c].onSave(this.grid));c=f.isObject(this.cookieProps)?this.cookieProps:{};p(e,n.toJson(a),c)}else this.removeCookie()},onPreInit:function(){var a=
this.grid,b=this._cookieHandlers,c=p(window.location+"/"+a.id);if(c){c=n.fromJson(c);for(var e=0;e<b.length;++e)if(b[e].name in c&&b[e].enabled)b[e].onLoad(c[b[e].name],a)}this._cookie=c||{};this._cookieStartedup=!0},addCookieHandler:function(a){if(a.name){var b=function(){};a.onLoad=a.onLoad||b;a.onSave=a.onSave||b;"enabled"in a||(a.enabled=!0);for(b=this._cookieHandlers.length-1;0<=b;--b)this._cookieHandlers[b].name==a.name&&this._cookieHandlers.splice(b,1);this._cookieHandlers.push(a);if(this._cookieStartedup&&
a.name in this._cookie)a.onLoad(this._cookie[a.name],this.grid)}},removeCookie:function(){p(window.location+"/"+this.grid.id,null,{expires:-1})},setCookieEnabled:function(a,b){if("string"==typeof a)for(var c=this._cookieHandlers,e=c.length-1;0<=e;--e)c[e].name===a&&(c[e].enabled=!!b);else(this._cookieEnabled=!!a)||this.removeCookie()},getCookieEnabled:function(a){if(f.isString(a)){for(var b=this._cookieHandlers,c=b.length-1;0<=c;--c)if(b[c].name==a)return b[c].enabled;return!1}return this._cookieEnabled}});
t.registerPlugin(m,{preInit:!0});return m});