DnD.js 3.8 KB
//>>built
define("dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/aspect dojo/dom-class dojo/on dojo/topic dojo/has dojo/when dojo/dnd/Source dojo/dnd/Manager dojo/_base/NodeList ../Selection dojo/has!touch?../util/touch".split(" "),function(h,m,n,v,p,z,w,q,k,r,t,x,y,u){var l=h(r,{grid:null,getObject:function(a){var b=this.grid;return b._trackError(function(){return b.collection.get(a.id.slice(b.id.length+5))})},_legalMouseDown:function(a){return this.inherited(arguments)&&a.target!==this.grid.bodyNode},
onDrop:function(a,b,d){var g=this,c=this._targetAnchor=this.targetAnchor,e=this.grid,f=e.collection;!this.before&&c&&(c=c.nextSibling);c=c&&e.row(c);k(c&&f.get(c.id),function(e){if(g!==a)g.onDropExternal(a,b,d,e);else g.onDropInternal(b,d,e)})},onDropInternal:function(a,b,d){var g=this.grid,c=g.collection,e=this,f=e._targetAnchor,h;f&&(h=this.before?f.previousSibling:f.nextSibling);f=g.row(a[0]);(b||h!==a[0]&&(d||!f||g.down(f).element!==a[0]))&&a.forEach(function(a){k(e.getObject(a),function(a){var f=
c.getIdentity(a);g._trackError(function(){var h=c.getIdentity(a),k=d?c.getIdentity(d):null;return(h===k?e._getNextItem(d).then(function(a){d=a}):c[b&&c.copy?"copy":"put"](a,{beforeId:k})).then(function(){e._selectedNodes[f]&&(e._selectedNodes[f]=g.row(f).element)})})})})},_getNextItem:function(a){var b=this.grid;return a&&(a=b.row(a),a.element&&(a=b.down(a),a.element))?k(a.data):k(null)},onDropExternal:function(a,b,d,g){var c=this.grid,e=this.grid.collection,f=a.grid;b.forEach(function(b,h){k(a.getObject(b),
function(k){c._trackError(function(){return e[e.copy?"copy":"put"](k,{beforeId:g?e.getIdentity(g):null}).then(function(){if(!d){if(f){var e=f.collection.getIdentity(k);!h&&a.selectNone();a.delItem(b.id);return f.collection.remove(e)}a.deleteSelectedNodes()}})})})})},onDndStart:function(a){this.inherited(arguments);a===this&&(t.manager().avatar.node.style.width=this.grid.domNode.offsetWidth/2+"px")},onMouseDown:function(a){q("touch")&&this.isDragging&&1<u.countCurrentTouches(a,this.grid.touchNode)?
(w.publish("/dnd/cancel"),t.manager().stopDrag()):this.inherited(arguments)},onMouseMove:function(a){(!q("touch")||1>=u.countCurrentTouches(a,this.grid.touchNode))&&this.inherited(arguments)},checkAcceptance:function(a){return a.getObject&&r.prototype.checkAcceptance.apply(this,arguments)},getSelectedNodes:function(){if(!this.grid.selection)return this.inherited(arguments);var a=new x,b;for(b in this.grid.selection)a.push(this._selectedNodes[b]);return a}});h=h(y,{dndSourceType:"dgrid-row",dndParams:null,
dndConstructor:l,postMixInProperties:function(){this.inherited(arguments);this.dndParams=m.mixin({accept:[this.dndSourceType]},this.dndParams)},postCreate:function(){function a(a){c[a.id]=a.element}function b(a){delete c[a.id];p.remove(a.element,"dojoDndItemSelected dojoDndItemAnchor")}this.inherited(arguments);var d=this.dndConstructor||l,g=m.mixin(this.dndParams,{grid:this,dropParent:this.contentNode});"function"===typeof this.expand&&(g.allowNested=!0);this.dndSource=new d(this.bodyNode,g);var c=
this.dndSource._selectedNodes={};this.on("dgrid-select",function(b){n.forEach(b.rows,a)});this.on("dgrid-deselect",function(a){n.forEach(a.rows,b)});v.after(this,"destroy",function(){delete this.dndSource._selectedNodes;c=null;this.dndSource.destroy()},!0)},insertRow:function(a){var b=this.inherited(arguments),d="function"===typeof this.getObjectDndType?this.getObjectDndType(a):[this.dndSourceType];p.add(b,"dojoDndItem");this.dndSource.setItem(b.id,{data:a,type:d instanceof Array?d:[d]});this.selection&&
(d=this.collection.getIdentity(a),d in this.selection&&(this.dndSource._selectedNodes[d]=b));return b},removeRow:function(a){var b=this.row(a);this.selection&&b.id in this.selection&&delete this.dndSource._selectedNodes[b.id];this.dndSource.delItem(b.element.id);this.inherited(arguments)}});h.GridSource=l;return h});