Coded Value Maps Opac Visible/Search Labels
authorThomas Berezansky <tsbere@mvlc.org>
Thu, 29 Mar 2012 19:37:07 +0000 (15:37 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Mon, 9 Apr 2012 01:14:27 +0000 (21:14 -0400)
Add two new fields to Coded Value Maps:

1 - Opac Visible, for "does this show up in opac limiter boxes"
2 - Search Label, for "what does this get called for those boxes"

Intended use cases include:

Re-labeling MARC fields without changing the base MARC information, say
because you don't expect patrons to understand "Projected Medium".

Hiding things that don't apply, say the vast majority of language limiters,
without needing to delete rows.

I also hooked it up in JSPac, because it was easy to do so.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.tpac_value_maps.sql [new file with mode: 0644]
Open-ILS/src/templates/conify/global/config/coded_value_map.tt2
Open-ILS/src/templates/opac/parts/coded_value_selector.tt2
Open-ILS/web/opac/skin/default/js/adv_global.js

index 10b5837..0da0727 100644 (file)
@@ -788,6 +788,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Code" name="code" reporter:datatype="text"  oils_obj:required="true"/>
                        <field reporter:label="Value" name="value" reporter:datatype="text"  oils_obj:required="true"/>
                        <field reporter:label="Description" name="description" reporter:datatype="text"/>
+                       <field reporter:label="OPAC Visible" name="opac_visible" reporter:datatype="bool"/>
+                       <field reporter:label="Search Label" name="search_label" reporter:datatype="text" oils_persist:i18n="true"/>
                </fields>
                <links>
                        <link field="ctype" reltype="has_a" key="name" map="" class="crad"/>
index 3fd9983..6031eac 100644 (file)
@@ -70,12 +70,18 @@ sub init_ro_object_cache {
         # search for objects of class $hint where field=value
         $cache{search}{$hint} = {};
         $ro_object_subs->{$search_key} = sub {
-            my ($field, $val) = @_;
+            my ($field, $val, $filterfield, $filterval) = @_;
             my $method = "search_$eclass";
+            my $cacheval = $val;
+            my $search_obj = {$field => $val};
+            if($filterfield) {
+                $search_obj->{$filterfield} = $filterval;
+                $cacheval .= ':' . $filterfield . ':' . $filterval;
+            }
             $cache{search}{$hint}{$field} = {} unless $cache{search}{$hint}{$field};
-            $cache{search}{$hint}{$field}{$val} = $e->$method({$field => $val}
-                unless $cache{search}{$hint}{$field}{$val};
-            return $cache{search}{$hint}{$field}{$val};
+            $cache{search}{$hint}{$field}{$cacheval} = $e->$method($search_obj
+                unless $cache{search}{$hint}{$field}{$cacheval};
+            return $cache{search}{$hint}{$field}{$cacheval};
         };
     }
 
index 734f3a9..af24ba4 100644 (file)
@@ -737,11 +737,13 @@ CREATE TABLE config.record_attr_index_norm_map (
 );
 
 CREATE TABLE config.coded_value_map (
-    id          SERIAL  PRIMARY KEY,
-    ctype       TEXT    NOT NULL REFERENCES config.record_attr_definition (name) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
-    code        TEXT    NOT NULL,
-    value       TEXT    NOT NULL,
-    description TEXT
+    id              SERIAL  PRIMARY KEY,
+    ctype           TEXT    NOT NULL REFERENCES config.record_attr_definition (name) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+    code            TEXT    NOT NULL,
+    value           TEXT    NOT NULL,
+    description     TEXT,
+    opac_visible    BOOL    NOT NULL DEFAULT TRUE, -- For TPac selectors
+    search_label    TEXT
 );
 
 CREATE VIEW config.language_map AS SELECT code, value FROM config.coded_value_map WHERE ctype = 'item_lang';
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.tpac_value_maps.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.tpac_value_maps.sql
new file mode 100644 (file)
index 0000000..4e409ec
--- /dev/null
@@ -0,0 +1,3 @@
+ALTER TABLE config.coded_value_map
+    ADD COLUMN opac_visible BOOL NOT NULL DEFAULT TRUE,
+    ADD COLUMN search_label TEXT;
index b49804f..7354368 100644 (file)
@@ -17,7 +17,7 @@
     <table  jsId="ccvmGrid"
             autoHeight='true'
             dojoType="openils.widget.AutoGrid"
-            fieldOrder="['ctype', 'code', 'value', 'description']"
+            fieldOrder="['ctype', 'code', 'value', 'description', 'opac_visible', 'search_label']"
             query="{code: '*'}"
             defaultCellWidth='"25%"'
             fmClass='ccvm'
index 0016b7a..acb464e 100644 (file)
@@ -7,7 +7,7 @@
     all_values = [];
     attr_class = '';
     FOR attr_class IN attr;
-        all_values = ctx.search_ccvm('ctype', attr_class);
+        all_values = ctx.search_ccvm('ctype', attr_class, 'opac_visible', 't');
         IF all_values.size > 0; LAST; END;
     END;
     name = name || "fi:" _ attr_class;
@@ -25,7 +25,7 @@
 # leverage TT's array.sort('<hashkey>') behavior
 sorter = [];
 FOR o IN all_values; 
-    sorter.push({code => o.code, value  => o.value}); 
+    sorter.push({code => o.code, value  => (o.search_label ? o.search_label : o.value)}); 
 END;
 FOR o IN sorter.sort('value') %]
     <option value='[% o.code | uri %]'[% values.grep('^' _ o.code _ '$').size ? ' selected="selected"' : '' %]>[% o.value | html %]</option>
index 7422e90..de29876 100644 (file)
@@ -16,7 +16,7 @@ function advgInit() {
 
     var ctypes = ["bib_level", "item_form", "item_type", "audience", "lit_form"];
 
-    var req = new Request('open-ils.fielder:open-ils.fielder.ccvm.atomic', {"cache":1,"query":{"ctype":ctypes}});
+    var req = new Request('open-ils.fielder:open-ils.fielder.ccvm.atomic', {"cache":1,"query":{"ctype":ctypes, "opac_visible":"t"}});
     req.callback(advDrawBibExtras);
     req.request.ctypes = ctypes;
     req.send();
@@ -156,13 +156,13 @@ function advDrawBibExtras(r) {
             var ctypeData = dojo.filter(data, function(item) { return item.ctype == ctype } );
             ctypeData = ctypeData.sort(
                 function(a,b) { /* sort alphabetically */
-                    return (a.value < b.value) ? -1 : 1;
+                    return ((a.search_label ? a.search_label : a.value) < (b.search_label ? b.search_label : b.value)) ? -1 : 1;
                 }
             );
             dojo.forEach(ctypeData,
                 function(thing) {
-                    var opt = insertSelectorVal(sel, -1, thing.value, thing.code);
-                    opt.setAttribute('title', thing.value);
+                    var opt = insertSelectorVal(sel, -1, (thing.search_label ? thing.search_label : thing.value), thing.code);
+                    opt.setAttribute('title', (thing.search_label ? thing.search_label : thing.value));
                 }
             );
         }