//>>built define("dojo/_base/kernel dojo/_base/lang dojo/_base/declare dojo/_base/array dojo/_base/connect ../../EnhancedGrid ../_Plugin ./_RowMapLayer".split(" "),function(t,v,w,m,q,y,z,A){t=w("dojox.grid.enhanced.plugins.Rearrange",z,{name:"rearrange",constructor:function(b,a){this.grid=b;this.setArgs(a);a=new A(b);dojox.grid.enhanced.plugins.wrap(b,"_storeLayerFetch",a)},setArgs:function(b){this.args=v.mixin(this.args||{},b||{});this.args.setIdentifierForNewItem=this.args.setIdentifierForNewItem||function(a){return a}}, destroy:function(){this.inherited(arguments);this.grid.unwrap("rowmap")},onSetStore:function(b){this.grid.layer("rowmap").clearMapping()},_hasIdentity:function(b){var a=this.grid,f=a.store,g=a.layout.cells;return f.getFeatures()["dojo.data.api.Identity"]&&m.some(b,function(b){return f.getIdentityAttributes(a._by_idx[b.r].item)==g[b.c].field})?!0:!1},moveColumns:function(b,a){var f=this.grid,g=f.layout,e=g.cells,h,c,d=0,l=!0;h={};var k={};b.sort(function(a,b){return a-b});for(c=0;c=a&&(k[c]=a+b.length-d+p,++p)}d=0;a==e.length&&(--a,l=!1);f._notRefreshSelection=!0;for(c=0;c=a)break;e.push(h)}h=b.slice(d);d=e;if(c=d.length)for(l={},m.forEach(d,function(a){l[a]=!0}),g[d[0]]=a-c,e=0,d=d[e]+1,k=d-1;d=a;--d)l[d]?(--e,g[d]=a+e):(g[d]=k,--k);var n=v.clone(g);f.layer("rowmap").setMapping(g);f.forEachLayer(function(a){return"rowmap"!=a.name()?(a.invalidate(),!0):!1},!1);f.selection.selected= [];f._noInternalMapping=!0;f._refresh();setTimeout(function(){q.publish("dojox/grid/rearrange/move/"+f.id,["row",n,b]);f._noInternalMapping=!1},0)},moveCells:function(b,a){var f=this.grid,g=f.store;if(g.getFeatures()["dojo.data.api.Write"]&&(b.min.row!=a.min.row||b.min.col!=a.min.col)){var e=f.layout.cells,h,c,d,l,k=[],n=[];h=b.min.row;for(d=a.min.row;h<=b.max.row;++h,++d)for(c=b.min.col,l=a.min.col;c<=b.max.col;++c,++l){for(;e[c]&&e[c].hidden;)++c;for(;e[l]&&e[l].hidden;)++l;k.push({r:h,c:c});n.push({r:d, c:l,v:e[c].get(h,f._by_idx[h].item)})}this._hasIdentity(k.concat(n))?console.warn("Can not write to identity!"):(m.forEach(k,function(a){g.setValue(f._by_idx[a.r].item,e[a.c].field,"")}),m.forEach(n,function(a){g.setValue(f._by_idx[a.r].item,e[a.c].field,a.v)}),g.save({onComplete:function(){q.publish("dojox/grid/rearrange/move/"+f.id,["cell",{from:b,to:a}])}}))}},copyCells:function(b,a){var f=this.grid,g=f.store;if(g.getFeatures()["dojo.data.api.Write"]&&(b.min.row!=a.min.row||b.min.col!=a.min.col)){var e= f.layout.cells,h,c,d,l,k=[];h=b.min.row;for(d=a.min.row;h<=b.max.row;++h,++d)for(c=b.min.col,l=a.min.col;c<=b.max.col;++c,++l){for(;e[c]&&e[c].hidden;)++c;for(;e[l]&&e[l].hidden;)++l;k.push({r:d,c:l,v:e[c].get(h,f._by_idx[h].item)})}this._hasIdentity(k)?console.warn("Can not write to identity!"):(m.forEach(k,function(a){g.setValue(f._by_idx[a.r].item,e[a.c].field,a.v)}),g.save({onComplete:function(){setTimeout(function(){q.publish("dojox/grid/rearrange/copy/"+f.id,["cell",{from:b,to:a}])},0)}}))}}, changeCells:function(b,a,f){var g=this.grid,e=g.store;if(e.getFeatures()["dojo.data.api.Write"]){var h=g.layout.cells,c=b.layout.cells,d,l,k,n,p=[];d=a.min.row;for(k=f.min.row;d<=a.max.row;++d,++k)for(l=a.min.col,n=f.min.col;l<=a.max.col;++l,++n){for(;c[l]&&c[l].hidden;)++l;for(;h[n]&&h[n].hidden;)++n;p.push({r:k,c:n,v:c[l].get(d,b._by_idx[d].item)})}this._hasIdentity(p)?console.warn("Can not write to identity!"):(m.forEach(p,function(a){e.setValue(g._by_idx[a.r].item,h[a.c].field,a.v)}),e.save({onComplete:function(){q.publish("dojox/grid/rearrange/change/"+ g.id,["cell",f])}}))}},clearCells:function(b){var a=this.grid,f=a.store;if(f.getFeatures()["dojo.data.api.Write"]){var g=a.layout.cells,e,h,c=[];for(e=b.min.row;e<=b.max.row;++e)for(h=b.min.col;h<=b.max.col;++h){for(;g[h]&&g[h].hidden;)++h;c.push({r:e,c:h})}this._hasIdentity(c)?console.warn("Can not write to identity!"):(m.forEach(c,function(b){f.setValue(a._by_idx[b.r].item,g[b.c].field,"")}),f.save({onComplete:function(){q.publish("dojox/grid/rearrange/change/"+a.id,["cell",b])}}))}},insertRows:function(b, a,f){try{var g=this.grid,e=g.store,h=g.rowCount,c={},d=0,l=[],k,n=0>f,p=this,t=a.length;if(n)f=0;else for(k=f;k=c&&g<=d&&(a=m,l=!0),e>= c&&e<=d&&(f=m,l=!0),!l&&(c>e||d