Opened 11 years ago

Closed 4 years ago

#5859 closed enhancement (patchwelcome)

[patch][cla] dnd patch for nested targets

Reported by: Brett Gardner Owned by: Eugene Lazutkin
Priority: low Milestone: 1.13
Component: DnD Version: 1.0
Keywords: needsreview Cc:
Blocked By: Blocking:

Description (last modified by bill)

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);
 	},

Change History (11)

comment:1 Changed 11 years ago by dylan

Milestone: 1.2
Summary: dnd patch for nested targets[patch][needs cla] dnd patch for nested targets

Who is this patch from? Do you have a CLA on file?

comment:2 Changed 11 years ago by guest

I submitted this patch

Brett Gardner brett@…

I submitted a CLA on Feb 25 2008.

comment:3 Changed 11 years ago by bill

Summary: [patch][needs cla] dnd patch for nested targets[patch][cla] dnd patch for nested targets

comment:4 Changed 11 years ago by bill

Resolution: fixed
Status: newclosed

(In [13065]) Fixes #5859, #6186: problems with initial BorderContainer? sizing on IE. Setting the size of a node and then immediately querying the size sometimes doesn't work (plus which it's inefficient). Fixed that for IE although not for other browsers. (IE is a separate code path since it doesn't use t/l/b/r four-corners setting for styling.) !strict

comment:5 Changed 11 years ago by bill

Resolution: fixed
Status: closedreopened

Oops, above checkin fixes #5895, not this bug (#5859)

comment:6 Changed 11 years ago by guest

http://www.dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/dnd-source-dnd-source

i try this patch for my problem, but i have an error :

t has no properties
[Break on this error] return {node: node, data: t.data, type: t.type};

comment:7 Changed 11 years ago by guest

That patch was several iterations ago. My latest patch is here

http://dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-development-discussion/dnd-nested-targets-patch

Note, I applied this patch to the latest from the SVN repo 6 weeks ago so it may need some tweaking again.

comment:8 Changed 11 years ago by Eugene Lazutkin

Milestone: 1.2future

Moving all open ticketd to the future.

comment:9 Changed 7 years ago by ben hockey

Description: modified (diff)
Keywords: needsreview added
Priority: highlow

i'm trying to identify stale tickets. if there is a need to keep this ticket open, please replace the "needsreview" keyword with "reviewed". if there is no need to keep this ticket open then please close it.

comment:10 Changed 7 years ago by bill

Description: modified (diff)
Reporter: changed from guest to Brett Gardner

Unfortunately the link http://dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-development-discussion/dnd-nested-targets-patch doesn't work anymore. Our fault because we erased the forums.

Kris checked in something in [28150] to allow nested div's in sources, so that the draggable items don't need to be direct children of the top level node, but this patch with it's registerSource() method seems different.

Whether or not we want this feature though is another question.

comment:11 Changed 4 years ago by dylan

Milestone: future1.12
Resolution: patchwelcome
Status: reopenedclosed

Given that we addressed most of this 4 years ago, I'm closing as patchwelcome if further additions should be made.

Note: See TracTickets for help on using tickets.