UI perfection. it previews. it saves...
authorsenator <lebbeous@esilibrary.com>
Fri, 15 Apr 2011 21:49:12 +0000 (17:49 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 6 Jul 2011 18:50:49 +0000 (14:50 -0400)
(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

Open-ILS/web/js/dojo/openils/vandelay/TreeDndSource.js
Open-ILS/web/js/dojo/openils/vandelay/TreeStoreModel.js
Open-ILS/web/js/dojo/openils/vandelay/nls/match_set.js
Open-ILS/web/js/ui/default/vandelay/match_set.js
Open-ILS/web/templates/default/vandelay/match_set_tree.tt2

index 0748a2f..c0586b5 100644 (file)
@@ -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();
         }
index af26d09..e694238 100644 (file)
@@ -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);
-//        }
     }
 );
index ae9277e..4d92442 100644 (file)
@@ -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."
 }
index 4c32278..2212dcd 100644 (file)
@@ -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();
 }
 
index 02ac2d4..1ebf055 100644 (file)
     #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; }
     </tr>
 </table>
 <div class="outer">
-    <div><!-- XXX TODO: consider a read-only display here of the query as built
-        so far from the treet --></div>
+    <div id="expr-preview-row">
+        <em>Your Expression:</em>
+        <span id="expr-preview"></span>
+    </div>
     <div id="vmsp-buttons">
         Add new
         <button onclick="node_editor.add('svf');">Single-Value-Field</button>