From e04c57f1234925ba9acd681e2d944060a843975a Mon Sep 17 00:00:00 2001 From: senator Date: Fri, 15 Apr 2011 14:28:16 -0400 Subject: [PATCH] Match Set Tree editor improvements/cleanup 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. comment cleanup, etc --- .../js/dojo/openils/vandelay/TreeDndSource.js | 25 +++++++++++++------ .../web/js/ui/default/vandelay/match_set.js | 21 +++++++--------- 2 files changed, 27 insertions(+), 19 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, diff --git a/Open-ILS/web/js/ui/default/vandelay/match_set.js b/Open-ILS/web/js/ui/default/vandelay/match_set.js index 990f21dd78..4c32278eb2 100644 --- a/Open-ILS/web/js/ui/default/vandelay/match_set.js +++ b/Open-ILS/web/js/ui/default/vandelay/match_set.js @@ -222,8 +222,6 @@ function NodeEditor() { this._init.apply(this, arguments); } -/* XXX replace later with code that will suit this function's purpose - * as well as that of update_draggable. */ function render_vmsp_label(point) { /* quick and dirty */ if (point.bool_op()) { @@ -294,7 +292,6 @@ function new_match_set_tree() { * */ function dojoize_match_set_tree(point, refgen) { - /* XXX TODO test with deeper trees! */ var root = false; if (!refgen) { if (!point) { @@ -329,7 +326,7 @@ function dojoize_match_set_tree(point, refgen) { return results; } -function render_match_set_description(match_set) { +function render_vms_metadata(match_set) { dojo.byId("vms-name").innerHTML = match_set.name(); dojo.byId("vms-owner").innerHTML = aou.findOrgUnit(match_set.owner()).name(); @@ -351,14 +348,11 @@ function my_init() { return; } - var match_set = pcrud.retrieve("vms", CGI.param("match_set")); - render_match_set_description(match_set); + render_vms_metadata(pcrud.retrieve("vms", CGI.param("match_set"))); - /* XXX No-one should have hundreds of these or anything, but theoretically + /* No-one should have hundreds of these or anything, but theoretically * this could be problematic with a big enough list of crad objects. */ - _crads = pcrud.retrieveAll( - "crad", {"order_by": {"crad": "label"}} - ); + _crads = pcrud.retrieveAll("crad", {"order_by": {"crad": "label"}}); var match_set_tree = fieldmapper.standardRequest( ["open-ils.vandelay", "open-ils.vandelay.match_set.get_tree"], @@ -395,12 +389,15 @@ function my_init() { dojo.connect( src, "onDndDrop", null, function(source, nodes, copy, target) { - /* XXX because of the... interesting... characteristics of DnD + /* Because of the... interesting... characteristics of DnD * design in dojo/dijit (at least as of 1.3), this callback will * fire both for our working node dndSource and for the tree! */ if (source == this) - node_editor.clear(); /* because otherwise this acts like a copy! */ + node_editor.clear(); /* ... because otherwise this acts like a + copy operation no matter what the user + does, even though we really want a + "move." */ } ); progress_dialog.hide(); -- 2.43.2