make sure user can only add reasonbly valid match points to the tree
authorsenator <lebbeous@esilibrary.com>
Fri, 15 Apr 2011 16:28:47 +0000 (12:28 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 6 Jul 2011 18:50:49 +0000 (14:50 -0400)
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 30132e3..ae9277e 100644 (file)
@@ -4,5 +4,8 @@
     "EXACTLY_ONE": "First select exactly one node from the tree on the right side of the screen.",
     "EXIT_REPLACE_MODE": "Exit Replace Mode",
     "ENTER_REPLACE_MODE": "Enter Replace Mode",
-    "NO_CAN_DO": "An error has occurred. Close this interface and try again."
+    "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."
 }
index 20fb624..990f21d 100644 (file)
@@ -124,6 +124,32 @@ function NodeEditor() {
         this.dnd_source._ready = false;
     };
 
+    this.is_sensible = function(mp) {
+        var need_one = 0;
+        ["tag", "svf", "bool_op"].forEach(
+            function(field) { if (mp[field]()) need_one++; }
+        );
+
+        if (need_one != 1) {
+            alert(localeStrings.POINT_NEEDS_ONE);
+            return false;
+        }
+
+        if (mp.tag()) {
+            if (
+                !mp.tag().match(/^\d{3}$/) ||
+                mp.subfield().length != 1 ||
+                !mp.subfield().match(/\S/) ||
+                mp.subfield().charCodeAt(0) < 32
+            ) {
+                alert(localeStrings.FAULTY_MARC);
+                return false;
+            }
+        }
+
+        return true;
+    };
+
     this.build_vmsp = function() {
         var match_point = new vmsp();
         var controls = dojo.query("[fmfield]", this.node_editor_container);
@@ -132,14 +158,18 @@ function NodeEditor() {
             var value = _simple_value_getter(controls[i]);
             match_point[field](value);
         }
-        return match_point;
+
+        if (!this.is_sensible(match_point)) return null;    /* will alert() */
+        else return match_point;
     };
 
     this.update_draggable = function(draggable) {
-        draggable.match_point = this.build_vmsp();
-        dojo.attr(
-            draggable, "innerHTML", render_vmsp_label(draggable.match_point)
-        );
+        var mp;
+
+        if (!(mp = this.build_vmsp())) return;  /* will alert() */
+
+        draggable.match_point = mp;
+        dojo.attr(draggable, "innerHTML", render_vmsp_label(mp));
         this.dnd_source._ready = true;
     };
 
@@ -176,7 +206,7 @@ function NodeEditor() {
 
         dojo.create(
             "input", {
-                "type": "submit", "value": "Ok",
+                "type": "submit", "value": localeStrings.OK,
                 "onclick": function() { self.update_draggable(draggable); }
             }, dojo.create(
                 "td", {"colspan": 2, "align": "center"},
index f8572e9..02ac2d4 100644 (file)
@@ -4,6 +4,7 @@
     h1 { margin: 1ex 0; }
     .outer { clear: both; margin-bottom: 1ex; }
     button { margin: 0 0.5em; }
+    input[type=submit] { padding: 0 0.5em; }
     #tree-here { margin-bottom: 1.5em; }
     #vms-table { padding-bottom: 2ex; }
     #vms-table th { text-align: right; }