From c78f3ec233c08fa7a3526621f06ea1521a47074c Mon Sep 17 00:00:00 2001 From: senator Date: Fri, 15 Apr 2011 17:49:12 -0400 Subject: [PATCH] UI perfection. it previews. it saves... (or if it would if the ML method were done, but it will be easy now) I just need to move things to the conify path and add staff client menu entries --- .../web/js/dojo/openils/vandelay/TreeDndSource.js | 18 +++++ .../web/js/dojo/openils/vandelay/TreeStoreModel.js | 32 ++++---- .../web/js/dojo/openils/vandelay/nls/match_set.js | 3 +- Open-ILS/web/js/ui/default/vandelay/match_set.js | 85 ++++++++++++++++++++-- .../templates/default/vandelay/match_set_tree.tt2 | 16 +++- 5 files changed, 125 insertions(+), 29 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js b/Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js index 0748a2f488..c0586b5d32 100644 --- a/Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js +++ b/Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js @@ -30,6 +30,22 @@ dojo.declare( window._tree_dnd_controllers = []; window._tree_dnd_controllers.push(this); + + dojo.connect( + this.tree.model.store, "onNew", this, + function() { this.redraw_expression_preview(); } + ); + dojo.connect( + this.tree.model.store, "onDelete", this, + function() { this.redraw_expression_preview(); } + ); + }, + "redraw_expression_preview": function() { + if (typeof(window.redraw_expression_preview) == "function") { + window.redraw_expression_preview(); + } else { + console.log("no redraw_expression_preview function registered"); + } }, "checkItemAcceptance": function(target, source, position) { if (!source._ready || source == this) return; @@ -101,6 +117,8 @@ dojo.declare( ); } + this.redraw_expression_preview(); + /* just because this is at the end of the default implementation: */ this.onDndCancel(); } diff --git a/Open-ILS/web/js/dojo/openils/vandelay/TreeStoreModel.js b/Open-ILS/web/js/dojo/openils/vandelay/TreeStoreModel.js index af26d09a89..e694238740 100644 --- a/Open-ILS/web/js/dojo/openils/vandelay/TreeStoreModel.js +++ b/Open-ILS/web/js/dojo/openils/vandelay/TreeStoreModel.js @@ -10,32 +10,32 @@ dojo.require("openils.Util"); function _simple_item(model, item) { /* Instead of model.getLabel(), could do * model.store.getValue(item, "blah") or something like that ... */ - return { - "label": model.getLabel(item), - "match_point": String(model.store.getValue(item, "match_point")), - "children": {} - }; + var mp = model.store.getValue(item, "match_point"); + mp.children([]); + return mp; } dojo.declare( "openils.vandelay.TreeStoreModel", dijit.tree.TreeStoreModel, { "replace_mode": 0, - "getSimpleTree": function(item, oncomplete, result) { + "get_simple_tree": function(item, oncomplete, result) { var self = this; - if (!result) result = {}; - - var mykey = this.getIdentity(item); - result[mykey] = _simple_item(this, item); - var child_collector = result[mykey].children; + var me; + if (!result) { + me = result = _simple_item(this, item); + } else { + me = _simple_item(this, item); + result.push(me); + } if (this.mayHaveChildren(item)) { this.getChildren( item, function(children) { + var kids_here = []; for (var i = 0; i < children.length; i++) { - self.getSimpleTree( - children[i], null, child_collector - ); + self.get_simple_tree(children[i], null, kids_here); } + me.children(kids_here); if (oncomplete) oncomplete(result); } ); @@ -48,9 +48,5 @@ dojo.declare( else return true; } -// "newItem": function(args, parent) { -// if (!this.mayHaveChildren(parent)) return; -// return this.inherited(arguments); -// } } ); diff --git a/Open-ILS/web/js/dojo/openils/vandelay/nls/match_set.js b/Open-ILS/web/js/dojo/openils/vandelay/nls/match_set.js index ae9277ef41..4d92442db9 100644 --- a/Open-ILS/web/js/dojo/openils/vandelay/nls/match_set.js +++ b/Open-ILS/web/js/dojo/openils/vandelay/nls/match_set.js @@ -7,5 +7,6 @@ "NO_CAN_DO": "An error has occurred. Close this interface and try again.", "OK": "Ok", "POINT_NEEDS_ONE": "A match point must be exactly one of the following: boolean operator, MARC tag/subfield pair, single-value-field.", - "FAULTY_MARC": "A MARC tag must be identified by three digits, and the subfield must be one non-whitespace, non-control character." + "FAULTY_MARC": "A MARC tag must be identified by three digits, and the subfield must be one non-whitespace, non-control character.", + "WORKING_MP_HERE": "Choose from among the three buttons above to add a new match point." } 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 4c32278eb2..2212dcdfe5 100644 --- a/Open-ILS/web/js/ui/default/vandelay/match_set.js +++ b/Open-ILS/web/js/ui/default/vandelay/match_set.js @@ -10,7 +10,7 @@ dojo.require("openils.Util"); dojo.require("openils.PermaCrud"); dojo.require("openils.widget.ProgressDialog"); -var localeStrings, node_editor, _crads, CGI, tree; +var localeStrings, node_editor, _crads, CGI, tree, match_set; function _find_crad_by_name(name) { for (var i = 0; i < _crads.length; i++) { @@ -120,7 +120,10 @@ function NodeEditor() { this.clear = function() { this.dnd_source.selectAll().deleteSelectedNodes(); - dojo.empty(this.node_editor_container); + dojo.create( + "em", {"innerHTML": localeStrings.WORKING_MP_HERE}, + this.node_editor_container, "only" + ); this.dnd_source._ready = false; }; @@ -215,21 +218,28 @@ function NodeEditor() { ); dojo.place(table, this.node_editor_container, "only"); - /* XXX around here attach other data structures to the node */ + this.dnd_source.insertNodes(false, [draggable]); + + /* nice */ + try { dojo.query("select, input", table)[0].focus(); } + catch(E) { console.log(String(E)); } + }; this._init.apply(this, arguments); } -function render_vmsp_label(point) { +function render_vmsp_label(point, minimal) { /* quick and dirty */ if (point.bool_op()) { return (openils.Util.isTrue(point.negate()) ? "N" : "") + point.bool_op(); } else if (point.svf()) { - return (openils.Util.isTrue(point.negate()) ? "NOT " : "") + - point.svf() + " / " + _find_crad_by_name(point.svf()).label(); + return (openils.Util.isTrue(point.negate()) ? "NOT " : "") + ( + minimal ? point.svf() : + (point.svf() + " / " + _find_crad_by_name(point.svf()).label()) + ); } else { return (openils.Util.isTrue(point.negate()) ? "NOT " : "") + point.tag() + " \u2021" + point.subfield(); @@ -333,6 +343,62 @@ function render_vms_metadata(match_set) { dojo.byId("vms-mtype").innerHTML = match_set.mtype(); } +function redraw_expression_preview() { + tree.model.getRoot( + function(root) { + tree.model.get_simple_tree( + root, function(r) { + dojo.attr( + "expr-preview", + "innerHTML", + render_expression_preview(r) + ); + } + ); + } + ); +} + +function render_expression_preview(r) { + if (r.children().length) { + return "(" + r.children().map(render_expression_preview).join( + " " + render_vmsp_label(r) + " " + ) + ")"; + } else if (!r.bool_op()) { + return render_vmsp_label(r, true /* minimal */); + } else { + return "()"; + } +} + +function save_tree() { + progress_dialog.show(true); + + tree.model.getRoot( + function(root) { + tree.model.get_simple_tree( + root, function(r) { + fieldmapper.standardRequest( + ["open-ils.vandelay", + "open-ils.vandelay.match_set.update"],/* XXX TODO */{ + "params": [ + openils.User.authtoken, match_set.id(), r + ], + "async": true, + "oncomplete": function(r) { + progress_dialog.hide(); + /* catch exceptions */ + r = openils.Util.readResponse(r); + + location.href = location.href; + } + } + ); + } + ); + } + ); +} function my_init() { progress_dialog.show(true); @@ -348,7 +414,9 @@ function my_init() { return; } - render_vms_metadata(pcrud.retrieve("vms", CGI.param("match_set"))); + render_vms_metadata( + match_set = pcrud.retrieve("vms", CGI.param("match_set")) + ); /* No-one should have hundreds of these or anything, but theoretically * this could be problematic with a big enough list of crad objects. */ @@ -400,6 +468,9 @@ function my_init() { "move." */ } ); + + redraw_expression_preview(); + node_editor.clear(); progress_dialog.hide(); } diff --git a/Open-ILS/web/templates/default/vandelay/match_set_tree.tt2 b/Open-ILS/web/templates/default/vandelay/match_set_tree.tt2 index 02ac2d492a..1ebf055c5d 100644 --- a/Open-ILS/web/templates/default/vandelay/match_set_tree.tt2 +++ b/Open-ILS/web/templates/default/vandelay/match_set_tree.tt2 @@ -12,7 +12,15 @@ #src-pane { float: left; width: 49%; } #tree-pane { float: right; width: 50%; } #submit-row { clear: both; text-align: center; padding-top: 1.5ex; } - #submit-row hr { margin: 1ex 0; } + #submit-row hr { margin: 1.5ex 0; } + #expr-preview-row { margin: 2ex 0; } + #expr-preview { + font-family: monospace; + font-size: 125%; + font-weight: bold; + background-color: #000066; + color: white; + } .node-editor { margin-bottom: 1.5ex; } .node-editor td { padding: 0.5ex; } li { background-color: #ddd; } @@ -62,8 +70,10 @@
-
+
+ Your Expression: + +
Add new -- 2.11.0