Ticket #7140 (new defect)

Opened 12 months ago

Last modified 5 months ago

Tree: The whole tree structure will break up if we drag-n-drop a parent node onto a child node.

Reported by: binspaul Owned by:
Priority: normal Milestone: 1.4
Component: Dijit Version: 1.1.1
Severity: normal Keywords: Tree, DnD
Cc:

Description

The whole tree hierarchy will break up if we drag-n-drop a parent node onto a child node. It is also present in the example given in the file : '/dojo-release-1.1.1/dijit/tests/tree/test_Tree_DnD.html'. In the Collections tree example given, just drag-n-drop the Fruits node onto the Citrus node. The whole tree structure will break-up producing exception. Ideally, it should not be allowed to drop a node onto its child node.

Attachments

test_Tree_DnD.html (6.3 kB) - added by binspaul 12 months ago.
dojo-release-1.1.1/dijit/tests/tree/test_Tree_DnD.html

Change History

Changed 12 months ago by binspaul

dojo-release-1.1.1/dijit/tests/tree/test_Tree_DnD.html

Changed 12 months ago by bill

  • priority changed from high to normal
  • summary changed from The whole tree structure will break up if we drag-n-drop a parent node onto a child node. to Tree: The whole tree structure will break up if we drag-n-drop a parent node onto a child node.
  • severity changed from critical to normal
  • milestone changed from tbd to 1.3

Hmm, I thought we had another ticket open about this but I can't find it.

Note that this is a little more complicated than the ticket description since you can drag multiple TreeNodes at once.

Changed 7 months ago by bill

  • milestone changed from 1.3 to 1.4

bumping 1.4 tickets to 1.5, and most 1.3 tickets to 1.4

Changed 5 months ago by millennium

Here's the part code I wrote to fix this bug. It's implemented in "checkItemAcceptance". But it isn't that hard to merge into dndSource.

checkItemAcceptance: function(target,source,position) {
  var _checkChildren = function(sourceNode, treeNode) {
  	if (sourceNode.isTreeNode) {	//SomeHow getChildren() gives something else than treeNodes only
    	if (treeNode == sourceNode) {
				return false;
			}
   			
   		var result = true;
 			var children = sourceNode.getChildren();
   		for (var i in children) {
   			if (!_checkChildren(children[i], treeNode)) {
   				result = false;
   				break;
   			}
   		}	
   		return result;
		}
		return true;
  }
    	
  var treeNode = dijit.getEnclosingWidget(target);
  if (position != "over") {
  	treeNode = treeNode.getParent();
  }
  if (treeNode.isTreeNode) {
 		for (var i in source.selection){
			var sourceNode = dijit.getEnclosingWidget(source.selection[i]);
			if (!(sourceNode && _checkChildren(sourceNode, treeNode))) {
				return false;
			}	
		}
		return true;
	}			
	return false;
}

Note that this is a little more complicated than the ticket description since you can drag multiple TreeNodes? at once.

If one of the treeNodes can't be dropt in the specific location, You can't drop your selection in there. (IMHO)

Note: See TracTickets for help on using tickets.