//>>built
define("dojox/grid/enhanced/plugins/_RowMapLayer",["dojo/_base/array","dojo/_base/declare","dojo/_base/kernel","dojo/_base/lang","./_StoreLayer"],function(t,u,v,n,w){var x=function(a){a.sort(function(f,e){return f-e});for(var c=[[a[0]]],d=1,b=0;d<a.length;++d)a[d]==a[d-1]+1?c[b].push(a[d]):c[++b]=[a[d]];return c},p=function(a,c){return c?n.hitch(a||v.global,c):function(){}};return u("dojox.grid.enhanced.plugins._RowMapLayer",w._StoreLayer,{tags:["reorder"],constructor:function(a){this._map={};this._revMap=
{};this.grid=a;this._oldOnDelete=a._onDelete;var c=this;a._onDelete=function(d){c._onDelete(d);c._oldOnDelete.call(a,d)};this._oldSort=a.sort;a.sort=function(){c.clearMapping();c._oldSort.apply(a,arguments)}},uninitialize:function(){this.grid._onDelete=this._oldOnDelete;this.grid.sort=this._oldSort},setMapping:function(a){this._store.forEachLayer(function(e){if("rowmap"===e.name())return!1;if(e.onRowMappingChange)e.onRowMappingChange(a);return!0},!1);var c={};for(d in a){var d=parseInt(d,10);var b=
a[d];if("number"==typeof b){if(d in this._revMap){var f=this._revMap[d];delete this._revMap[d]}else f=d;f==b?(delete this._map[f],c[b]="eq"):(this._map[f]=b,c[b]=f)}}for(b in c)"eq"===c[b]?delete this._revMap[parseInt(b,10)]:this._revMap[parseInt(b,10)]=c[b]},clearMapping:function(){this._map={};this._revMap={}},_onDelete:function(a){var c=this.grid._getItemIndex(a,!0);if(c in this._revMap){a=[];var d=this._revMap[c];delete this._map[d];delete this._revMap[c];for(b in this._revMap){var b=parseInt(b,
10);this._revMap[b]>d&&--this._revMap[b]}for(b in this._revMap)b=parseInt(b,10),b>c&&a.push(b);a.sort(function(f,e){return e-f});for(c=a.length-1;0<=c;--c)b=a[c],this._revMap[b-1]=this._revMap[b],delete this._revMap[b];this._map={};for(b in this._revMap)this._map[this._revMap[b]]=b}},_fetch:function(a){var c=0,d=a.start||0;for(b in this._revMap){var b=parseInt(b,10);b>=d&&++c}if(0<c){var f=[],e,g={},h=0<a.count?a.count:-1;if(0<h)for(e=0;e<h;++e)b=d+e,b=b in this._revMap?this._revMap[b]:b,g[b]=e,f.push(b);
else for(e=0;!(b=d+e,b in this._revMap&&(--c,b=this._revMap[b]),g[b]=e,f.push(b),0>=c);++e);this._subFetch(a,this._getRowArrays(f),0,[],g,a.onComplete,d,h);return a}return n.hitch(this._store,this._originFetch)(a)},_getRowArrays:function(a){return x(a)},_subFetch:function(a,c,d,b,f,e,g,h){var k=c[d],l=this,y=a.start=k[0];a.count=k[k.length-1]-k[0]+1;a.onComplete=function(q){t.forEach(q,function(m,z){var r=y+z;r in f&&(b[f[r]]=m)});++d==c.length?0<h?(a.start=g,a.count=h,a.onComplete=e,p(a.scope,e)(b,
a)):(a.start+=q.length,delete a.count,a.onComplete=function(m){b=b.concat(m);a.start=g;a.onComplete=e;p(a.scope,e)(b,a)},l.originFetch(a)):l._subFetch(a,c,d,b,f,e,g,h)};l.originFetch(a)}})});