From 5f6b7e4ae416140a91d40f0066d370a1b7e81181 Mon Sep 17 00:00:00 2001 From: senator Date: Fri, 15 Apr 2011 14:28:16 -0400 Subject: [PATCH] You can now replace the root node of the tree with anything, and the children will be automatically deleted. This makes it easier to create a single-node tree with no operators, if the user should so desire. --- .../web/js/dojo/openils/vandelay/TreeDndSource.js | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js b/Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js index 832ef6f094..0748a2f488 100644 --- a/Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js +++ b/Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js @@ -7,11 +7,14 @@ dojo.require("dijit._tree.dndSource"); */ dojo.declare( "openils.vandelay.TreeDndSource", dijit._tree.dndSource, { - "_is_replaceable": function(spoint, dpoint) { + "_is_replaceable": function(spoint, dpoint, disroot) { /* An OP can replace anything, but non-OPs can only replace other - * non-OPs + * non-OPs, EXCEPT when the dest is the root node (this allows + * for simple "trees" with only a single non-OP node. */ - if (spoint.bool_op()) + if (disroot) + return true; + else if (spoint.bool_op()) return true; else if (!dpoint.bool_op()) return true; @@ -32,13 +35,12 @@ dojo.declare( if (!source._ready || source == this) return; if (this.tree.model.replace_mode) { + var ditem = dijit.getEnclosingWidget(target).item; return ( position == "over" && this._is_replaceable( source.getAllNodes()[0].match_point, - this.tree.model.store.getValue( - dijit.getEnclosingWidget(target).item, - "match_point" - ) + this.tree.model.store.getValue(ditem, "match_point"), + ditem === this.tree.model.root ) ); } else { @@ -82,6 +84,15 @@ dojo.declare( if (k == "id") continue; /* can't use this / don't need it */ store.setValue(item, k, new_params[k]); } + if (this.tree.model.root === item) { /* replacing root node */ + if (!new_params.match_point.bool_op()) { + /* If we're here, we've replaced the root node with + * something that isn't a bool op, so we need to nuke + * any children that the item has. + */ + store.setValue(item, "children", []); + } + } if (typeof(window.render_vmsp_label) == "function") { store.setValue( item, -- 2.11.0