the vandelay match set editor now does quality metrics too
authorsenator <lebbeous@esilibrary.com>
Wed, 4 May 2011 21:33:29 +0000 (17:33 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 6 Jul 2011 18:50:52 +0000 (14:50 -0400)
Open-ILS/examples/fm_IDL.xml
Open-ILS/web/js/dojo/openils/vandelay/nls/match_set.js
Open-ILS/web/js/ui/default/conify/global/vandelay/match_set.js
Open-ILS/web/templates/default/conify/global/vandelay/match_set_tree.tt2

index f7ad9e3..97c2865 100644 (file)
@@ -599,10 +599,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
-                               <create permission="ADMIN_IMPORT_MATCH_SET" context_field="owner"/>
-                               <retrieve permission="ADMIN_IMPORT_MATCH_SET" context_field="owner"/>
-                               <update permission="ADMIN_IMPORT_MATCH_SET" context_field="owner"/>
-                               <delete permission="ADMIN_IMPORT_MATCH_SET" context_field="owner"/>
+                               <create permission="ADMIN_IMPORT_MATCH_SET">
+                    <context link="match_set" field="owner"/>
+                               </create>
+                               <retrieve permission="ADMIN_IMPORT_MATCH_SET">
+                    <context link="match_set" field="owner"/>
+                               </retrieve>
+                               <update permission="ADMIN_IMPORT_MATCH_SET">
+                    <context link="match_set" field="owner"/>
+                               </update>
+                               <delete permission="ADMIN_IMPORT_MATCH_SET">
+                    <context link="match_set" field="owner"/>
+                               </delete>
                        </actions>
                </permacrud>
        </class>
index 7e76613..92851d2 100644 (file)
@@ -6,8 +6,10 @@
     "ENTER_REPLACE_MODE": "Enter Replace Mode",
     "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.",
+    "CANCEL": "Cancel",
+    "POINT_NEEDS_ONE": "You have not entered valid data",
     "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.",
+    "WORKING_QM_HERE": "Use buttons above and to the right to add new quality metrics.",
     "SVF": "Record Attribute"
 }
index e07eeca..28f30b5 100644 (file)
@@ -11,7 +11,7 @@ dojo.require("openils.PermaCrud");
 dojo.require("openils.widget.ProgressDialog");
 dojo.require("openils.widget.AutoGrid");
 
-var localeStrings, node_editor, _crads, CGI, tree, match_set;
+var localeStrings, node_editor, qnode_editor, _crads, CGI, tree, match_set;
 
 var NodeEditorAbstract = {
     "_svf_select_template": null,
@@ -25,11 +25,7 @@ var NodeEditorAbstract = {
     },
     "is_sensible": function(thing) {
         var need_one = 0;
-        var list = openils.Util.objectProperties(this._factories_by_type);
-        console.log(list.join(" "));
-        openils.Util.objectProperties(this._factories_by_type).forEach(
-            function(field) { if (thing[field]()) need_one++; }
-        );
+        this.foi.forEach(function(field) { if (thing[field]()) need_one++; });
 
         if (need_one != 1) {
             alert(localeStrings.POINT_NEEDS_ONE);
@@ -56,7 +52,6 @@ var NodeEditorAbstract = {
             this._consistent_controls = [];
             for (var i = 0; i < trs.length; i++)
                 this._consistent_controls[i] = dojo.clone(trs[i]);
-            dojo.empty(trs[0].parentNode);
         }
 
         this._consistent_controls.forEach(
@@ -124,39 +119,53 @@ var NodeEditorAbstract = {
                 }, dojo.create("td", null, rows[1])
             );
             return rows;
+        },
+        "bool_op": function() {
+            var tr = dojo.create("tr");
+            dojo.create(
+                "label",
+                {"for": "operator-select", "innerHTML": "Operator:"},
+                dojo.create("td", null, tr)
+            );
+            var select = dojo.create(
+                "select", {"fmfield": "bool_op", "id": "operator-select"},
+                dojo.create("td", null, tr)
+            );
+            dojo.create("option", {"value": "AND", "innerHTML": "AND"}, select);
+            dojo.create("option", {"value": "OR", "innerHTML": "OR"}, select);
+
+            return [tr];
         }
     }
 };
 
-function _find_crad_by_name(name) {
-    for (var i = 0; i < _crads.length; i++) {
-        if (_crads[i].name() == name)
-            return _crads[i];
-    }
-    return null;
+function apply_base_class(cls, basecls) {
+    openils.Util.objectProperties(basecls).forEach(
+        function(m) { cls[m] = basecls[m]; }
+    );
 }
 
 function QualityNodeEditor() {
     var self = this;
+    this.foi = ["tag", "svf"]; /* Fields of Interest - starting points for UI */
 
-    this._init = function(dnd_source, qnode_editor_container) {
+    this._init = function(qnode_editor_container) {
         this._consistent_controls_query =
             "[consistent-controls], [quality-controls]";
-        this.dnd_source = dnd_source;
         this.qnode_editor_container = dojo.byId(qnode_editor_container);
+        this.clear();
     };
 
     this.clear = function() {
-        this.dnd_source.selectAll().deleteSelectedNodes();
         dojo.create(
-            "em", {"innerHTML": localeStrings.WORKING_MP_HERE},
+            "em", {"innerHTML": localeStrings.WORKING_QM_HERE},
             this.qnode_editor_container, "only"
         );
-        this.dnd_source._ready = false;
     };
 
     this.build_vmsq = function() {
         var metric = new vmsq();
+        metric.match_set(match_set.id());   /* using global */
         var controls = dojo.query("[fmfield]", this.qnode_editor_container);
         for (var i = 0; i < controls.length; i++) {
             var field = dojo.attr(controls[i], "fmfield");
@@ -171,7 +180,6 @@ function QualityNodeEditor() {
     this.add = function(type) {
         this.clear();
 
-
         /* these are the editing widgets */
         var table = dojo.create("table", {"className": "node-editor"});
 
@@ -180,19 +188,51 @@ function QualityNodeEditor() {
 
         this._add_consistent_controls(table);
 
+        var ok_cxl_td = dojo.create(
+            "td", {"colspan": 2, "align": "center", "className": "space-me"},
+            dojo.create("tr", null, table)
+        );
+
         dojo.create(
             "input", {
                 "type": "submit", "value": localeStrings.OK,
-                "onclick": function() { alert("would update draggable here"/* XXX TODO */); }
-            }, dojo.create(
-                "td", {"colspan": 2, "align": "center"},
-                dojo.create("tr", null, table)
-            )
+                "onclick": function() {
+                    var metric = self.build_vmsq();
+                    if (metric) {
+                        self.clear();
+                        pcrud.create(
+                            metric, {
+                                /* borrowed from openils.widget.AutoGrid */
+                                "oncomplete": function(req, cudResults) {
+                                    var fmObject = cudResults[0];
+                                    if (vmsq_grid.onPostCreate)
+                                        vmsq_grid.onPostCreate(fmObject);
+                                    if (fmObject) {
+                                        vmsq_grid.store.newItem(
+                                            fmObject.toStoreItem()
+                                        );
+                                    }
+                                    setTimeout(function() {
+                                        try {
+                                            vmsq_grid.selection.select(vmsq_grid.rowCount-1);
+                                            vmsq_grid.views.views[0].getCellNode(vmsq_grid.rowCount-1, 1).focus();
+                                        } catch (E) {}
+                                    },200);
+                                }
+                            }
+                        );
+                    }
+                }
+            }, ok_cxl_td
+        );
+        dojo.create(
+            "input", {
+                "type": "reset", "value": localeStrings.CANCEL,
+                "onclick": function() { self.clear(); }
+            }, ok_cxl_td
         );
 
-        dojo.place(table, this.qnode_editor_container, "only");/* XXX put in dialog here */
-
-        //this.dnd_source.insertNodes(false, [draggable]);
+        dojo.place(table, this.qnode_editor_container, "only");
 
         /* nice */
         try { dojo.query("select, input", table)[0].focus(); }
@@ -200,17 +240,17 @@ function QualityNodeEditor() {
 
     };
 
-    openils.Util.objectProperties(NodeEditorAbstract).forEach(
-        function(m) { self[m] = NodeEditorAbstract[m]; }
-    );
+    apply_base_class(self, NodeEditorAbstract);
     this._init.apply(this, arguments);
 }
 
 function NodeEditor() {
     var self = this;
+    this.foi = ["tag", "svf", "bool_op"]; /* Fields of Interest - starting points for UI */
 
     this._init = function(dnd_source, node_editor_container) {
-        this._consistent_controls_query = "[consistent-controls]";
+        this._consistent_controls_query =
+            "[consistent-controls], [point-controls]";
         this.dnd_source = dnd_source;
         this.node_editor_container = dojo.byId(node_editor_container);
     };
@@ -285,29 +325,19 @@ function NodeEditor() {
 
     };
 
-    openils.Util.objectProperties(NodeEditorAbstract).forEach(
-        function(m) { self[m] = NodeEditorAbstract[m]; }
-    );
+    apply_base_class(self, NodeEditorAbstract);
 
-    this._factories_by_type.bool_op = function() {
-        var tr = dojo.create("tr");
-        dojo.create(
-            "label",
-            {"for": "operator-select", "innerHTML": "Operator:"},
-            dojo.create("td", null, tr)
-        );
-        var select = dojo.create(
-            "select", {"fmfield": "bool_op", "id": "operator-select"},
-            dojo.create("td", null, tr)
-        );
-        dojo.create("option", {"value": "AND", "innerHTML": "AND"}, select);
-        dojo.create("option", {"value": "OR", "innerHTML": "OR"}, select);
-
-        return [tr];
-    };
     this._init.apply(this, arguments);
 }
 
+function find_crad_by_name(name) {
+    for (var i = 0; i < _crads.length; i++) {
+        if (_crads[i].name() == name)
+            return _crads[i];
+    }
+    return null;
+}
+
 function render_vmsp_label(point, minimal) {
     /* "minimal" has this implication:
      * for svf, only show the code, not the longer label.
@@ -317,7 +347,7 @@ function render_vmsp_label(point, minimal) {
     } else if (point.svf()) {
         return (openils.Util.isTrue(point.negate()) ? "NOT " : "") + (
             minimal ?  point.svf() :
-                (point.svf() + " / " + _find_crad_by_name(point.svf()).label())
+                (point.svf() + " / " + find_crad_by_name(point.svf()).label())
         );
     } else {
         return (openils.Util.isTrue(point.negate()) ? "NOT " : "") +
@@ -459,7 +489,7 @@ function save_tree() {
                 root, function(r) {
                     fieldmapper.standardRequest(
                         ["open-ils.vandelay",
-                            "open-ils.vandelay.match_set.update"],/* XXX TODO */{
+                            "open-ils.vandelay.match_set.update"], {
                             "params": [
                                 openils.User.authtoken, match_set.id(), r
                             ],
@@ -482,7 +512,7 @@ function save_tree() {
 function init_vmsq_grid() {
     vmsq_grid.loadAll(
         {"order_by": {"vmsq": "quality"}},
-        {"match_set": CGI.param("match_set")}
+        {"match_set": match_set.id()}
     );
 }
 
@@ -538,6 +568,7 @@ function my_init() {
     );
 
     node_editor = new NodeEditor(src, "node-editor-container");
+    qnode_editor = new QualityNodeEditor("qnode-editor-container");
 
     replace_mode(0);
 
index 7a11223..8ad1eea 100644 (file)
@@ -3,6 +3,7 @@
 <style type="text/css">
     h1 { margin: 1ex 0; }
     .outer { clear: both; margin-bottom: 1ex; }
+    .space-me input { margin: 0 1em; }
     button { margin: 0 0.5em; }
     input[type=submit] { padding: 0 0.5em; }
     #tree-here { margin-bottom: 1.5em; }
     give some indication of which match set we're editing the tree for
     -->
 <table class="hidden">
+    <tr quality-controls="1">
+        <td>
+            <label for="value-input">Value:</label>
+        </td>
+        <td>
+            <input id="value-input" type="text" fmfield="value" />
+        </td>
+    </tr>
     <tr consistent-controls="1">
         <td>
             <label for="quality-input"
@@ -60,7 +69,7 @@
                 size="4" maxlength="3" fmfield="quality" />
         </td>
     </tr>
-    <tr consistent-controls="1">
+    <tr point-controls="1">
         <td>
             <label for="negate-input">Negate?</label>
         </td>
             <input id="negate-input" type="checkbox" fmfield="negate" />
         </td>
     </tr>
-    <tr quality-controls="1">
-        <td>
-            <label for="value-input">Value:</label>
-        </td>
-        <td>
-            <input id="value-input" type="text" fmfield="value" />
-        </td>
-    </tr>
 </table>
 <div class="outer">
     <div id="expr-preview-row">
         </div>
     </div>
     <br style="clear: both;" />
+    <table id="qnode-editor-container"></table>
     <table jsId="vmsq_grid"
         dojoType="openils.widget.AutoGrid"
         query="{id: '*'}"