//>>built
define("dgrid/extensions/DnD",["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/Deferred","dojo/aspect","dojo/on","dojo/topic","dojo/has","dojo/dnd/Source","dojo/dnd/Manager","dojo/_base/NodeList","put-selector/put","dojo/has!touch?../util/touch","dojo/has!touch?./_DnD-touch-autoscroll","xstyle/css!dojo/resources/dnd.css"],function(_1,_2,_3,_4,_5,on,_6,_7,_8,_9,_a,_b,_c){var _d=_1(_8,{grid:null,getObject:function(_e){var _f=this.grid;return _f.store.get(_e.id.slice(_f.id.length+5));},_legalMouseDown:function(evt){var _10=this.inherited(arguments);return _10&&evt.target!=this.grid.bodyNode;},onDrop:function(_11,_12,_13){var _14=this,_15=this._targetAnchor=this.targetAnchor,_16=this.grid,_17=_16.store;if(!this.before&&_15){_15=_15.nextSibling;}_15=_15&&_16.row(_15);_4.when(_15&&_17.get(_15.id),function(_18){if(_14!=_11){_14.onDropExternal(_11,_12,_13,_18);}else{_14.onDropInternal(_12,_13,_18);}});},onDropInternal:function(_19,_1a,_1b){var _1c=this.grid.store,_1d=this,_1e=this.grid,_1f=_1d._targetAnchor,_20;if(_1f){_20=this.before?_1f.previousSibling:_1f.nextSibling;}if(!_1a&&(_20===_19[0]||(!_1b&&_1e.down(_1e.row(_19[0])).element==_19[0]))){return;}_19.forEach(function(_21){_4.when(_1d.getObject(_21),function(_22){_1c[_1a&&_1c.copy?"copy":"put"](_22,{before:_1b});});});},onDropExternal:function(_23,_24,_25,_26){var _27=this.grid.store,_28=_23.grid;_24.forEach(function(_29,i){_4.when(_23.getObject(_29),function(_2a){if(!_25){if(_28){_4.when(_28.store.getIdentity(_2a),function(id){!i&&_23.selectNone();_23.delItem(_29.id);_28.store.remove(id);});}else{_23.deleteSelectedNodes();}}_27[_27.copy?"copy":"put"](_2a,{before:_26});});});},onDndStart:function(_2b,_2c,_2d){this.inherited(arguments);if(_2b==this){if(this.grid.cancelTouchScroll){this.grid.cancelTouchScroll();}_9.manager().avatar.node.style.width=this.grid.domNode.offsetWidth/2+"px";}},onMouseDown:function(evt){if(_7("touch")&&this.isDragging&&_c.countCurrentTouches(evt,this.grid.touchNode)>1){_6.publish("/dnd/cancel");_9.manager().stopDrag();}else{this.inherited(arguments);}},onMouseMove:function(evt){if(!_7("touch")||_c.countCurrentTouches(evt,this.grid.touchNode)===1){this.inherited(arguments);}},checkAcceptance:function(_2e,_2f){return _2e.getObject&&_8.prototype.checkAcceptance.apply(this,arguments);},getSelectedNodes:function(){if(!this.grid.selection){return this.inherited(arguments);}var t=new _a(),id;for(id in this.grid.selection){t.push(this._selectedNodes[id]);}return t;}});var DnD=_1("dgrid.extensions.DnD",null,{dndSourceType:"dgrid-row",dndParams:null,dndConstructor:_d,postMixInProperties:function(){this.inherited(arguments);this.dndParams=_2.mixin({accept:[this.dndSourceType]},this.dndParams);},postCreate:function(){this.inherited(arguments);this.dndSource=new (this.dndConstructor||_d)(this.bodyNode,_2.mixin(this.dndParams,{grid:this,dropParent:this.contentNode}));var _30,_31,_32;if(this.selection){_30=this.dndSource._selectedNodes={};_31=function(row){_30[row.id]=row.element;};_32=function(row){delete _30[row.id];};this.on("dgrid-select",function(_33){_3.forEach(_33.rows,_31);});this.on("dgrid-deselect",function(_34){_3.forEach(_34.rows,_32);});}_5.after(this,"destroy",function(){delete this.dndSource._selectedNodes;_30=null;this.dndSource.destroy();},true);},insertRow:function(_35){var row=this.inherited(arguments),_36=typeof this.getObjectDndType=="function"?this.getObjectDndType(_35):[this.dndSourceType];_b(row,".dojoDndItem");this.dndSource.setItem(row.id,{data:_35,type:_36 instanceof Array?_36:[_36]});return row;}});DnD.GridSource=_d;return DnD;});