mockup showing how to accomplish some of the ui/feedtemplate bits
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 12 Dec 2011 17:03:27 +0000 (12:03 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 3 Jan 2012 22:41:42 +0000 (17:41 -0500)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/examples/apache/eg_vhost.conf
Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm [new file with mode: 0644]
Open-ILS/web/js/dojo/openils/BibTemplate.js
Open-ILS/web/opac/skin/default/js/search_bar.js
Open-ILS/web/opac/skin/default/xml/home/homesearch.xml

index cf593ed..3f708b4 100644 (file)
@@ -51,6 +51,14 @@ OSRFGatewayConfig /openils/conf/opensrf_core.xml
     allow from all
 </Location>
 
+# Autosuggest for searches
+<Location /opac/extras/autosuggest>
+    SetHandler perl-script
+    PerlHandler OpenILS::WWW::AutoSuggest
+    PerlSendHeader On
+    Allow from All
+</Location>
+
 # ----------------------------------------------------------------------------------
 # Replace broken cover images with a transparent GIF by default
 # ----------------------------------------------------------------------------------
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AutoSuggest.pm
new file mode 100644 (file)
index 0000000..d1021ac
--- /dev/null
@@ -0,0 +1,67 @@
+package OpenILS::WWW::AutoSuggest;
+
+use strict;
+use warnings;
+
+use Apache2::Log;
+use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
+use APR::Const    -compile => qw(:error SUCCESS);
+use Apache2::RequestRec ();
+use Apache2::RequestIO ();
+use Apache2::RequestUtil;
+use CGI;
+
+my @dict = qw/
+    alpha
+    allstate
+    apple
+    appropriate
+    application
+    arizona
+    bears
+    beta
+    beets
+    gamma
+    gone
+    out
+    tool
+    toad
+    tap
+    sock
+    socket
+    sicken
+    sickening
+    rage
+    right
+    road
+    /;
+
+sub search_dict {
+    my $term = shift;
+    (my $re = $term) =~ s/[^a-z0-9]/\./gi;
+
+    return ($term, grep(/^$re/, @dict));
+}
+
+sub handler {
+    my $r = shift;
+    my $cgi = new CGI;
+
+    my ($term, @matches) = search_dict($cgi->param("query"));
+    my $xml_terms = join("\n", map {
+        qq{<val term="$term" field="123">$_</val>}
+    } @matches);
+    print "Content-type: application/xml; charset=utf-8\n\n";
+
+    print qq{<?xml version="1.0"?>
+<as>
+$xml_terms
+</as>
+    };
+    
+    return Apache2::Const::OK;
+}
+
+1;
+
+# vim: et:ts=4:sw=4
index 8c81447..c130dd1 100644 (file)
@@ -267,16 +267,21 @@ if(!dojo._hasResource["openils.BibTemplate"]) {
             var me = this;
 
             var process_feed = function (xmldoc) {
-               if (parseInt(me.horizon) >= parseInt(me.root.getAttribute('horizon'))) {
+                console.log("in process_feed()");
+                if (parseInt(me.horizon) >= parseInt(me.root.getAttribute('horizon'))) {
                     if (me.empty == true) dojo.empty(me.place);
                     me.root.setAttribute('horizon', this.horizon);
+                    console.log("about to do bibtemplate loop, item_query is " + me.item_query);
                     dojo.query( me.item_query, xmldoc ).forEach(
                         function (item) {
                             var template = me.root.cloneNode(true);
                             dojo.place( template, me.place, me.relativePosition );
+                            console.log("instantiating a bibtemplate");
                             new openils.BibTemplate({ delay : false, xml : item, root : template });
                         }
                     );
+                } else {
+                    console.log("horizon test failed");
                 }
             };
 
index 76d123d..c77caa8 100644 (file)
@@ -13,6 +13,28 @@ G.evt.common.init.push(searchBarInit);
 var newSearchLocation; 
 var newSearchDepth = null;
 
+dojo.require("openils.BibTemplate");
+
+
+var autosuggest_ft;
+
+function autosuggestTest() {
+    if (!autosuggest_ft) {
+        autosuggest_ft = new openils.FeedTemplate({
+            "place": dojo.byId("test1"),
+            "root": dojo.byId("template_root"),
+            "empty": true,
+            "query": "as",
+            "preventCache": true    /* XXX do we want this permanently? */
+        });
+    }
+
+    autosuggest_ft.feed_uri = "http://dev-vm1/opac/extras/autosuggest?query=" +
+        dojo.byId("search_box").value;
+    console.log(autosuggest_ft.feed_uri);
+
+    autosuggest_ft.render();
+}
 
 function searchBarInit() {
 
index 30ca9a3..1db0f33 100644 (file)
 
                        <tr>
                                <td nowrap='nowrap' align='center' class='color_1 border_5'>
-                                       <input id='search_box' style='width: 300px;' type='text' />
-                                       <span style='padding-left: 6px;'>
-                                               <input type='button' style='width: 40px;' id='search_submit' value='Go!' />
-                                       </span>
+                    <div style="width: 340px;">
+                        <input id='search_box' style='width: 300px;' type='text' />
+                        <span style='padding-left: 6px;'>
+                            <input type='button' style='width: 40px;' id='search_submit' value='Go!'  /><a href="javascript:unHideMe($('test1'));">unhide</a><a href="javascript:autosuggestTest();">search</a>
+                        </span>
+                        <br />
+                        <div id="test1" style="text-align:left; float:left; width: 300px; background: #ccc; position:absolute;z-index: 100"><a href="javascript:hideMe($('test1'));">hide</a></div>
+                    </div>
                                </td>
                        </tr>
 
 
 </div>
 
-
-
-
-
+<div class="hide_me">
+    <div id="template_root">
+        <span type='opac/slot-data' query='val[field=123]' join="&lt;br /&gt;">
+            <span class="hide_me" type="opac/slot-format"><![CDATA[
+                var term = BT.textContent(item);
+                var s = '"' + term + '"';
+
+                return "&lt;a href='javascript:alert(" + s + ");'&gt;" + term + "&lt;/a&gt;";
+            ]]></span>
+        </span>
+    </div>
+</div>