LP#1053397 more MR display / filter bits user/berick/lp1053397-tpac-metarecords
authorBill Erickson <berick@esilibrary.com>
Tue, 28 Jan 2014 20:13:00 +0000 (15:13 -0500)
committerBill Erickson <berick@esilibrary.com>
Tue, 28 Jan 2014 20:13:00 +0000 (15:13 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/parts/result/table.tt2
Open-ILS/src/templates/opac/results.tt2
Open-ILS/web/js/ui/default/opac/simple.js

index cadc189..b02b596 100644 (file)
@@ -308,8 +308,11 @@ sub load_rresults {
     my $ctx = $self->ctx;
     my $e = $self->editor;
 
+    # 1. param->metarecord : view constituent bib records for a metarecord
+    # 2. param->modifier=metabib : perform a metarecord search
+    my $metarecord = $ctx->{metarecord} = $cgi->param('metarecord');
     my @mods = $cgi->param('modifier');
-    my $is_meta = @mods and grep { $_ eq 'metabib' } @mods;
+    my $is_meta = (@mods and grep {$_ eq 'metabib'} @mods and !$metarecord);
     my $id_key = $is_meta ? 'mmr_id' : 'bre_id';
 
     # find the last record in the set, then redirect
@@ -350,7 +353,6 @@ sub load_rresults {
     $ctx->{search_ou} = $self->_get_search_lib();
     $ctx->{pref_ou} = $self->_get_pref_lib() || $ctx->{search_ou};
     my $offset = $page * $limit;
-    my $metarecord = $cgi->param('metarecord');
     my $results; 
     my $tag_circs = $self->tag_circed_items;
     $self->timelog("Got search parameters");
@@ -461,9 +463,23 @@ sub load_rresults {
 
     $self->load_rresults_bookbag_item_notes($rec_ids) if $ctx->{bookbag};
 
+    my $fetch_recs = $rec_ids;
+
+    my $metarecord_master;
+    if ($metarecord) {
+        # when listing the contents of a metarecord, be sure to fetch
+        # the lead record for summary display.  Adding the ID to
+        # $fetch_recs lets us grab the record (if necessary) w/o it
+        # unintentially becoming a member of the result set.
+        my $mr = $e->retrieve_metabib_metarecord($metarecord);
+        push(@$fetch_recs, $mr->master_record)
+            unless grep {$_ eq $mr->master_record} @$fetch_recs;
+        $metarecord_master = $mr->master_record;
+    }
+
     $self->timelog("Calling get_records_and_facets()");
     my ($facets, @data) = $self->get_records_and_facets(
-        $rec_ids, $results->{facet_key}, 
+        $fetch_recs, $results->{facet_key}, 
         {
             flesh => '{holdings_xml,mra,acp,acnp,acns,bmp}',
             site => $site,
@@ -485,10 +501,11 @@ sub load_rresults {
 
     # shove recs into context in search results order
     for my $rec_id (@$rec_ids) {
-        push(
-            @{$ctx->{records}},
-            grep { $_->{$id_key} == $rec_id } @data
-        );
+        my ($rec) = grep { $_->{$id_key} == $rec_id } @data;
+        push(@{$ctx->{records}}, $rec);
+
+        $ctx->{metarecord_master} = $rec
+            if $metarecord_master and $metarecord_master eq $rec_id;
     }
 
     if ($tag_circs) {
index c4e14cf..2bc2c16 100644 (file)
@@ -329,8 +329,8 @@ sub get_records_and_facets {
             }
 
             my $rec_id = $mmr_id ? $mmr_id : $bre_id;
-            $tmp_data{$bre_id} = {
-                id => $rec_id, # for backwards compat
+            $tmp_data{$rec_id} = {
+                id => $rec_id, 
                 bre_id => $bre_id, 
                 mmr_id => $mmr_id,
                 marc_xml => $xml
@@ -341,8 +341,12 @@ sub get_records_and_facets {
                 my $key = 'TPAC_unapi_cache_'.$rec_id.'_'.$unapi_cache_key_suffix;
                 my $cache_data = $unapi_cache->get_cache($key);
                 if ($$cache_data{running}) {
-                    $unapi_cache->put_cache($key, 
-                        {id => $rec_id, marc_xml => $data->{$unapi_type} }, 10);
+                    $unapi_cache->put_cache($key, {
+                        bre_id => $bre_id,
+                        mmr_id => $mmr_id,
+                        id => $rec_id, 
+                        marc_xml => $data->{$unapi_type} 
+                    }, 10);
                 }
             }
 
index 93d3064..5b7a0c5 100644 (file)
@@ -38,7 +38,8 @@
                             # of the type of record. i.e. rec.id = mmr_id ? mmr_id : bre_id
                             IF rec.mmr_id;
                                 # metarecords link to record list page
-                                record_url = mkurl(ctx.opac_root _ '/results', {metarecord => rec.mmr_id});
+                                record_url = mkurl(ctx.opac_root _ '/results', 
+                                    {metarecord => rec.mmr_id}, ['page']);
                                 hold_type = 'M';
                             ELSE;
                                 record_url = mkurl(ctx.opac_root _ '/record/' _ rec.bre_id);
index 5006800..7ea66a0 100644 (file)
     <form action="[% ctx.opac_root %]/results" method="get">
     [% INCLUDE "opac/parts/searchbar.tt2" took_care_of_form=1 %]
     <div class="almost-content-wrapper">
-        <div id="results_header_bar">
+
+        [%# hide the header bar when displaying metarecord constituents 
+          instead of skipping it altogether to allow the search form
+          variables to propagate %]
+        [% IF ctx.metarecord;
+          mr_attrs = {marc_xml => ctx.metarecord_master.marc_xml};
+          PROCESS get_marc_attrs args=mr_attrs %]
+          <div class="results_header_lbl">
+            [% l('Viewing Results for Grouped Record: [_1]', 
+                mr_attrs.title) | html %]
+          </div>
+        [% END %]
+        <div class="results_header_bar[%- IF ctx.metarecord %] hidden[% END -%]">
             <div id="results_header_inner">
                 <div class="results_header_btns">
                     <a href="[% mkurl(ctx.opac_root _ '/home', {$loc_name => loc_value}, 1) %]">[% l('Another Search') %]</a>
 
                     <label class="results_header_lbl">
                         <input type="checkbox" id="limit_to_available" name="modifier" value="available"
-                            onchange="limit_to_avail_onchange(this, true)"
+                            onchange="search_modifier_onchange('available', this, true)"
                             [% CGI.param('modifier').grep('available').size ? ' checked="checked"' : '' %] />
                         [% l('Limit to available items') %]
                     </label>
+                    <label class="results_header_lbl">
+                        <input type="checkbox" name="modifier" value="metabib"
+                            onchange="search_modifier_onchange('metabib', this, true)"
+                            [% CGI.param('modifier').grep('metabib').size ? ' checked="checked"' : '' %] />
+                        [% l('Group Formats and Editions') %]
+                    </label>
                     [% IF CGI.param('detail_record_view') %]
                         <input type="hidden" name="detail_record_view" value="1" />
                     [% END %]
index 6e3d29f..b491586 100644 (file)
@@ -74,10 +74,11 @@ function select_all_checkboxes(name, checked) {
     }
 }
 
-function limit_to_avail_onchange(checkbox, submitOnChange) {
+function search_modifier_onchange(type, checkbox, submitOnChange) {
     if (checkbox.form._adv && !checkbox.checked) {
         var search_box = $('search_box');
-        search_box.value = search_box.value.replace(/#available ?/g, "");
+        var reg = new RegExp('#' + type + ' ?', 'g');
+        search_box.value = search_box.value.replace(reg, "");
     }
 
     if (submitOnChange) {