It's ugly and hacky, but numeric search fully works (item barcode included)
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 27 Jul 2011 21:31:30 +0000 (17:31 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 27 Jul 2011 21:31:30 +0000 (17:31 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/web/templates/default/opac/parts/advanced/numeric.tt2
Open-ILS/web/templates/default/opac/parts/header.tt2
Open-ILS/web/templates/default/opac/parts/searchbar.tt2
Open-ILS/web/templates/default/opac/results.tt2

index d445250..ea33fa0 100644 (file)
@@ -132,6 +132,9 @@ sub load_rresults {
     my $e = $self->editor;
 
     $ctx->{page} = 'rresult';
+
+    return $self->item_barcode_shortcut if $cgi->param("qtype") eq "item_barcode";
+
     my $page = $cgi->param('page') || 0;
     my $facet = $cgi->param('facet');
     my $limit = $self->_get_search_limit;
@@ -213,4 +216,43 @@ sub load_rresults {
     return Apache2::Const::OK;
 }
 
+# Searching by barcode is a special search that does /not/ respect any other
+# of the usual search parameters, not even the ones for sorting and paging!
+sub item_barcode_shortcut {
+    my ($self) = @_;
+
+    my $method = "open-ils.search.multi_home.bib_ids.by_barcode";
+    if (my $search = create OpenSRF::AppSession("open-ils.search")) {
+        my $rec_ids = $search->request(
+            $method, $self->cgi->param("query")
+        )->gather(1);
+
+        if (ref $rec_ids ne 'ARRAY') {
+            if (defined $U->event_code($rec_ids)) {
+                $self->apache->log->warn(
+                    "$method returned event: " . $U->event_code($rec_ids)
+                );
+            } else {
+                $self->apache->log->warn(
+                    "$method returned something unexpected: $rec_ids"
+                );
+            }
+            return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+        }
+
+        my ($facets, @data) = $self->get_records_and_facets(
+            $rec_ids, undef, {flesh => "{holdings_xml,mra}"}
+        );
+
+        $self->ctx->{records} = [@data];
+        $self->ctx->{search_facets} = {};
+        $self->ctx->{hit_count} = scalar @data;
+        $self->ctx->{page_size} = $self->ctx->{hit_count};
+
+        return Apache2::Const::OK;
+    } {
+        $self->apache->log->warn("couldn't connect to open-ils.search");
+        return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+    }
+}
 1;
index 8835a5c..c2a1d3d 100644 (file)
@@ -1,6 +1,7 @@
 <form id="adv_search_form" action="[% ctx.opac_root %]/results" method="GET">
     <div class="header_middle">[% l("Numeric Search") %]</div>
     <input type="hidden" name="contains" value="contains" />
+    <input type="hidden" name="_special" value="1" />
     <table>
         <tr>
             <td>
@@ -10,7 +11,7 @@
                     <option value="identifier|bib_cn">[% l('Call Number') %]</option>
                     <option value="identifier|lccn">[% l('LCCN') %]</option>
                     <option value="identifier|tcn">[% l('TCN') %]</option>
-                    <option disabled="disabled" value="item_barcode">[% l('Item Barcode') %]</option>[%# XXX have to implement special logic for this later %]
+                    <option value="item_barcode">[% l('Item Barcode') %]</option>
                 </select>
             </td>
             <td>
index 114b4c3..581307d 100644 (file)
@@ -20,6 +20,7 @@
     propagator = '?' _ query_string;
 
     is_advanced = CGI.param("_adv").size;
+    is_special = CGI.param("_special").size;
 %]
 
 
index 433ce68..bf4a26e 100644 (file)
@@ -13,7 +13,7 @@
             </td>
         </tr>
         <tr>
-            [% IF is_advanced %]
+            [% IF is_advanced || is_special %]
             <td colspan="2">
                 <input type="hidden" name="_adv" value="1" />
             [% ELSE %]
@@ -21,7 +21,7 @@
             [% INCLUDE "default/opac/parts/qtype_selector.tt2" %]
             </td>
             [% END %]
-            [% IF ctx.processed_search_query OR NOT is_advanced %]
+            [% IF ctx.processed_search_query OR (NOT is_advanced AND NOT is_special) %]
             <td>
                 <div id="search_box_wrapper">
                     <!-- Note: when common browsers support HTML5 placeholder text, we can remove the JS -->
@@ -45,7 +45,7 @@
             </td>
             [% END %]
         </tr>
-        [% UNLESS is_advanced %]
+        [% UNLESS is_advanced OR is_special %]
         <tr>
             <td>
                 [% INCLUDE "default/opac/parts/coded_value_selector.tt2" attr=["mattype", "item_type"] none_ok=1 %]
@@ -63,7 +63,7 @@
         [% END %]
     </table>
     [% UNLESS took_care_of_form %]</form>[% END %]
-    [% IF is_advanced AND CGI.param('qtype') %]
+    [% IF (is_advanced AND NOT is_special) AND CGI.param('qtype') %]
     <div class="opac-auto-102">
         [ <a href="[% ctx.opac_root %]/advanced?[% query_string %]">[%
             l('Click to Refine Your Original Search')
index d0b6d28..139cf5f 100644 (file)
@@ -4,7 +4,7 @@
     WRAPPER "default/opac/parts/base.tt2";
     INCLUDE "default/opac/parts/topnav.tt2";
 
-    IF is_advanced;
+    IF is_advanced || is_special;
         ctx.page_title = l("Search Results");
     ELSE;
         ctx.page_title = l("Search Results: ") _ CGI.param('query') | html_entity;
@@ -43,7 +43,7 @@
                 </div>
                 [% END %]
                 <div class="results_header_div"></div>
-                [% UNLESS is_advanced %]
+                [% UNLESS is_advanced || is_special %]
                     <div class="results_header_lbl">Sort by</div>
                     [% INCLUDE "default/opac/parts/filtersort.tt2" value=CGI.param('sort') %]
                     <div class="results_header_div"></div>