TPAC support for AutoSuggest
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 25 Jan 2012 22:38:28 +0000 (17:38 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 26 Jan 2012 19:11:30 +0000 (14:11 -0500)
This means introducing Dojo, optionally, into the TPAC.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Open-ILS/src/templates/opac/parts/base.tt2
Open-ILS/src/templates/opac/parts/header.tt2
Open-ILS/src/templates/opac/parts/js.tt2
Open-ILS/src/templates/opac/parts/qtype_selector.tt2
Open-ILS/src/templates/opac/parts/searchbar.tt2
Open-ILS/web/css/skin/default/opac/style.css
Open-ILS/web/js/dojo/openils/widget/AutoSuggest.js

index b19b8bc..97b6787 100644 (file)
@@ -254,6 +254,7 @@ sub load_common {
     $ctx->{search_ou} = $self->_get_search_lib();
 
     $self->staff_saved_searches_set_expansion_state if $ctx->{is_staff};
+    $self->load_eg_cache_hash;
 
     return Apache2::Const::OK;
 }
index 5ea922f..f10ccb7 100644 (file)
@@ -1,6 +1,7 @@
 package OpenILS::WWW::EGCatLoader;
 use strict; use warnings;
 use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST);
+use File::Spec;
 use OpenSRF::Utils::Logger qw/$logger/;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Utils::Fieldmapper;
@@ -13,7 +14,8 @@ our %cache = ( # cached data
     map => {aou => {}}, # others added dynamically as needed
     list => {},
     search => {},
-    org_settings => {}
+    org_settings => {},
+    eg_cache_hash => undef
 );
 
 sub init_ro_object_cache {
@@ -302,4 +304,40 @@ sub _get_search_lib {
     return $self->ctx->{aou_tree}->()->id;
 }
 
+# This is defensively coded since we don't do much manual reading from the
+# file system in this module.
+sub load_eg_cache_hash {
+    my ($self) = @_;
+
+    # just a context helper
+    $self->ctx->{eg_cache_hash} = sub { return $cache{eg_cache_hash}; };
+
+    # Need to actually load the value? If already done, move on.
+    return if defined $cache{eg_cache_hash};
+
+    # In this way even if we fail, we won't slow things down by ever trying
+    # again within this Apache process' lifetime.
+    $cache{eg_cache_hash} = 0;
+
+    my $path = File::Spec->catfile(
+        $self->apache->document_root, "eg_cache_hash"
+    );
+
+    if (not open FH, "<$path") {
+        $self->apache->log->warn("error opening $path : $!");
+        return;
+    } else {
+        my $buf;
+        my $rv = read FH, $buf, 64;  # defensive
+        close FH;
+
+        if (not defined $rv) {  # error
+            $self->apache->log->warn("error reading $path : $!");
+        } elsif ($rv > 0) {     # no error, something read
+            chomp $buf;
+            $cache{eg_cache_hash} = $buf;
+        }
+    }
+}
+
 1;
index 4af9a87..239ab30 100644 (file)
@@ -9,9 +9,15 @@
         <link rel="stylesheet" type="text/css" href="[% ctx.media_prefix %]/css/skin/default/opac/style.css" />
         <title>[% l('Catalog - [_1]', ctx.page_title) %]</title>
         <link rel="unapi-server" type="application/xml" title="unAPI" href="/opac/extras/unapi" />
+        [% IF want_dojo %]
+        <style type="text/css">
+            @import "[% ctx.media_prefix %]/js/dojo/dojo/resources/dojo.css";
+            @import "[% ctx.media_prefix %]/js/dojo/dijit/themes/tundra/tundra.css";
+        </style>
+        [% END %]
         [% INCLUDE 'opac/parts/goog_analytics.tt2' %]
     </head>
-    <body>
+    <body[% IF want_dojo; ' class="tundra"'; END %]>
         [% content %] 
         [% INCLUDE 'opac/parts/footer.tt2' %]
         [% INCLUDE 'opac/parts/js.tt2' %]
index ce51900..4efaa30 100644 (file)
             cgi.url("-path" => 1, "-query" => 1);
         END;
     END;
+
+    # Whether we want Dojo or not may one day be a wholly distinct
+    # concern from whether we want autosuggest, so let's get used to
+    # defining that separately.
+    want_dojo = 0;
+
+    use_autosuggest = ctx.get_cgf("opac.use_autosuggest");
+
+    IF use_autosuggest.enabled == "t";
+        want_dojo = 1;
+    END;
 %]
index 35ff2bb..0b34e5a 100644 (file)
     IF CGI.https; url = url.replace('^http:', 'https:'); END; %]
 <script type='text/javascript' id='EIT' src='[% url %]'></script>
 [%- END %]
+[%- IF want_dojo; -%]
+<script type="text/javascript">
+    var locale = "[% ctx.locale %]";
+     var djConfig = {
+         locale: locale.toLowerCase().replace("_", "-"),    /* XXX ? */
+         parseOnLoad: true,
+         isDebug: false
+     }, lang, bidi;
+</script>
+<script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/dojo/dojo.js?[% ctx.eg_cache_hash %]"></script>
+<script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/opensrf/opensrf.js?[% ctx.eg_cache_hash %]"></script>
+<script type="text/javascript" src="[% ctx.media_prefix %]/js/dojo/dojo/openils_dojo.js?[% ctx.eg_cache_hash %]"></script>
+
+[% IF use_autosuggest.enabled == "t"; %]
+<script type="text/javascript">
+dojo.require("fieldmapper.dojoData");
+dojo.require("openils.widget.AutoSuggest");
+</script>
+[% END; # use_autosuggest %]
+
+[%- END; # want_dojo -%]
index 5089606..98567d4 100644 (file)
@@ -6,7 +6,7 @@
     {value => "series", label => l("Series")},
     {value => "id|bibcn", label => l("Bib Call Number")}
 ] %]
-<select name="qtype">
+<select name="qtype"[% IF id; ' id="'; id ; '"' ; END %]>
     [%  query_type = query_type || CGI.param('qtype');
         FOR qt IN query_types -%]
     <option value='[% qt.value | html %]'[%
index 360bd25..8fbe3e3 100644 (file)
             l(' for ');
         %]
         <span class='search_box_wrapper'>
-            <input type="text" id="search_box" name="query" value="[% is_advanced ? ctx.processed_search_query : CGI.param('query') || l("Search Keyword") | html %]"
-                onfocus="if (this.value=='[% l("Search Keyword") %]'){this.value='';this.style.color='#000';}"
-                onblur="if (this.value==''){this.value='[% l("Search Keyword") %]';this.style.color='#999';}"
+            <input
+                [%- IF use_autosuggest.enabled == "t" %]
+                dojoType="openils.widget.AutoSuggest" type_selector="qtype"
+                submitter="this.textbox.form.submit();"
+                [%- IF use_autosuggest.value.search('opac_visible') %]
+                store_args='{"org_unit_getter": function() { return [% ctx.search_ou %]; }}'
+                [%- END -%]
+                [%- END -%] type="text" id="search_box" name="query"
+                value="[% is_advanced ? ctx.processed_search_query : CGI.param('query') | html %]"
                 x-webkit-speech />
         </span>
-        [%- INCLUDE "opac/parts/qtype_selector.tt2";
+        [%- INCLUDE "opac/parts/qtype_selector.tt2" id="qtype";
             l(' in '); PROCESS build_org_selector name='loc' value=ctx.search_ou;
     %]
     <span>
index e54180b..8480d02 100644 (file)
@@ -1374,3 +1374,9 @@ table.bookbag-specific {
 .result-bookbag-description { font-size: 120%; font-style: italic; }
 .result-bookbag-item-note { font-style: italic; }
 .lowhits-bookbag-name { font-weight: bold; }
+.oils_AS { font-weight: bold; color: #c00; }
+.oils_AS_match_term { text-align: left; color: #000; }
+.oils_AS_match_field {
+    font-size: 75%; padding: 0.65em 0;
+    text-align: right; color: #666;
+}
index 48e6603..7f013f0 100644 (file)
@@ -72,6 +72,9 @@ if (!dojo._hasResource["openils.widget.AutoSuggest"]) {
             "postMixInProperties": function() {
                 this.inherited(arguments);
 
+                if (typeof this.submitter == "string")
+                    this.submitter = dojo.hitch(this, this.submitter);
+
                 /* Save the instantiator from needing to specify same thing
                  * twice, even though we need it and the store needs it too.
                  */