Ticket #5859 (reopened enhancement)
[patch][cla] dnd patch for nested targets
| Reported by: | guest | Owned by: | elazutkin |
|---|---|---|---|
| Priority: | normal | Milestone: | future |
| Component: | DnD | Version: | 1.0 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
A patch to allow nested targets in drag and drop. The nested targets can accept different source types. eg I had a setup where a Page can contain Sections. A Section can contain more Sections or Questions.
Index: dnd/Manager.js =================================================================== --- dnd/Manager.js (revision 12205) +++ dnd/Manager.js (working copy) @@ -14,6 +14,9 @@
this.target = null; this.canDropFlag = false; this.events = [];
+ this.nestedTargets = false; + this.sources = new dojo.NodeList?(); + this.leftSource = false;
},
// avatar's offset from the mouse
@@ -159,6 +162,17 @@
this.updateAvatar(); dojo.removeClass(dojo.body(), "dojoDnd" + (this.copy ? "Move" : "Copy")); dojo.addClass(dojo.body(), "dojoDnd" + (this.copy ? "Copy" : "Move"));
+ }, + registerSource: function(source){ + this.sources.push(source); + }, + sourceById: function(id){ + for (var i = 0; i < this.sources.length; i++){ + if (this.sources[i].node.id == id){ + return this.sources[i]; + } + } + return null;
}
});
Index: dnd/Source.js =================================================================== --- dnd/Source.js (revision 12205) +++ dnd/Source.js (working copy) @@ -78,6 +78,9 @@
dojo.subscribe("/dnd/drop", this, "onDndDrop"), dojo.subscribe("/dnd/cancel", this, "onDndCancel")
];
+ + var m = dojo.dnd.manager(); + m.registerSource(this); //nestedTargets will be set by the client after this so always register the source
},
// methods
@@ -129,6 +132,13 @@
dojo.dnd.Source.superclass.onMouseMove.call(this, e); var m = dojo.dnd.manager(); if(this.isDragging){
+ + if (m.leftSource){ + m.leftSource = false; + m.overSource(this); + return; + } +
// calculate before/after var before = false; if(this.current){
@@ -210,8 +220,27 @@
// source: Object: the source which provides items // nodes: Array: the list of transferred items // copy: Boolean: copy items, if true, move items otherwise
+ + var m = dojo.dnd.manager(); +
do{ //break box
if(this.containerState != "Over"){ break; }
+ + /*If this source, contains any sources itself that have + their "containerState" set to "Over" then break*/ + if (m.nestedTargets){ + var sources = m.sources; + if (dojo.some(sources,function(item){ + return Boolean( + item.node.id != this.node.id + && item.containerState == 'Over' + && dojo.isDescendant(item.node,this.node) + ); + },this)){ + break; + } + } +
var oldCreator = this._normalizedCreator; if(this != source){
// transferring nodes from the source to the target
@@ -314,6 +343,10 @@
}, onOutEvent: function(){
// summary: this function is called once, when mouse is out of our container
+ var m = dojo.dnd.manager(); + if (m.nestedTargets){ + m.leftSource = true; + }
dojo.dnd.Source.superclass.onOutEvent.call(this); dojo.dnd.manager().outSource(this);
},