From 128554e383bafb7f9ac7b0edd3ec17ebb3ff90e0 Mon Sep 17 00:00:00 2001 From: senator Date: Fri, 15 Apr 2011 12:28:47 -0400 Subject: [PATCH] make sure user can only add reasonbly valid match points to the tree --- .../web/js/dojo/openils/vandelay/nls/match_set.js | 5 ++- Open-ILS/web/js/ui/default/vandelay/match_set.js | 42 ++++++++++++++++++---- .../templates/default/vandelay/match_set_tree.tt2 | 1 + 3 files changed, 41 insertions(+), 7 deletions(-) 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 30132e30a1..ae9277ef41 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 @@ -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." } 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 20fb624d08..990f21dd78 100644 --- a/Open-ILS/web/js/ui/default/vandelay/match_set.js +++ b/Open-ILS/web/js/ui/default/vandelay/match_set.js @@ -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"}, 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 f8572e900e..02ac2d492a 100644 --- a/Open-ILS/web/templates/default/vandelay/match_set_tree.tt2 +++ b/Open-ILS/web/templates/default/vandelay/match_set_tree.tt2 @@ -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; } -- 2.11.0