adding google books view to result pages
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 14 Mar 2008 13:00:32 +0000 (13:00 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 14 Mar 2008 13:00:32 +0000 (13:00 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@9008 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/locale/en-US/opac.dtd
Open-ILS/web/opac/skin/default/js/result_common.js
Open-ILS/web/opac/skin/default/xml/result/result_table.xml

index f7c564a..766bd45 100644 (file)
@@ -554,6 +554,7 @@ We recommend that you remove this title from any bookbags it may have been added
 
 <!ENTITY result.table.keyword "View titles for this record">
 <!ENTITY result.table.author "Perform an Author Search">
+<!ENTITY result.googleBooks.browse "Browse in Google Books Search">
 
 <!ENTITY common.call.number.label "Call Number:">
 <!ENTITY common.isbn.label "ISBN:">
index 318cba5..3810402 100644 (file)
@@ -2,6 +2,8 @@
 var recordsHandled = 0;
 var recordsCache = [];
 var lowHitCount = 4;
+var isbnList = '';
+var googleBooks = false;
 
 var resultFetchAllRecords = false;
 var resultCompiledSearch = null;
@@ -394,6 +396,21 @@ function buildunAPISpan (span, type, id) {
        );
 }
 
+function unhideGoogleBooks (data) {
+    for ( var i in data ) {
+        if (data[i].preview == 'noview') continue;
+
+        var gbspan = $n('googleBooks-' + i);
+        var gba = $n("googleBooks-link",gbspan)
+
+        gba..setAttribute(
+            'href',
+            data[i].info_url
+        );
+        removeCSSClass( gbspan, 'hide_me' );
+    }
+}
+
 /* display the record info in the record display table 'pos' is the 
                zero based position the record should have in the display table */
 function resultDisplayRecord(rec, pos, is_mr) {
@@ -403,8 +420,21 @@ function resultDisplayRecord(rec, pos, is_mr) {
        recordsCache.push(rec);
 
        var r = table.rows[pos + 1];
+    var currentISBN = cleanISBN(rec.isbn());
+
+    if (googleBooks) {
+           var gbspan = $n(r, "googleBooks");
+        if (currentISBN) {
+            gbspan.setAttribute(
+                'name',
+                gbspan.getAttribute('name') + '-' + currentISBN
+            );
+
+            if (isbnList) isbnList += ', ';
+            isbnList += currentISBN;
+        }
+    }
 
-       
        try {
                var rank = parseFloat(ranks[pos + getOffset()]);
                rank            = parseInt( rank * 100 );
@@ -414,7 +444,7 @@ function resultDisplayRecord(rec, pos, is_mr) {
        } catch(e){ }
 
        var pic = $n(r, config.names.result.item_jacket);
-       pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
+       pic.setAttribute("src", buildISBNSrc(currentISBN));
 
        var title_link = $n(r, config.names.result.item_title);
        var author_link = $n(r, config.names.result.item_author);
@@ -550,6 +580,18 @@ function resultBuildFormatIcons( row, rec, is_mr ) {
 
 
 function resultPageIsDone(pos) {
+
+    if (isbnList && googleBooks) {
+        var scriptElement = document.createElement("script");
+        scriptElement.setAttribute("id", "jsonScript");
+        scriptElement.setAttribute("src",
+            "http://books.google.com/books?bibkeys=" + 
+            escape(isbnList) + "&jscmd=viewapi&callback=unhideGoogleBooks");
+        scriptElement.setAttribute("type", "text/javascript");
+        // make the request to Google Book Search
+        document.documentElement.firstChild.appendChild(scriptElement);
+    }
+
        return (recordsHandled == getDisplayCount() 
                || recordsHandled + getOffset() == getHitCount());
 }
index cd1137b..ad90031 100644 (file)
                                                                        </span>
 
                                                                        <span class='hide_me' name='place_hold_span'>
-                                                                               <a style='padding-left: 8px; padding-right: 10px;' href='javascript:void(0);' 
+                                                                               <a style='padding-left: 8px;' href='javascript:void(0);' 
                                                                                        class='classic_link' name='place_hold_link'>&opac.holds.placeHold;</a>
                                                                        </span>
 
                                                                        <!-- Empty span used for creating unAPI links -->
-                                                                       <abbr name="unapi" class="unapi-id">
+                                                                       <abbr style='padding-left: 8px;' name="unapi" class="unapi-id">
                                                                                <!-- unAPI URI goes here -->
                                                                        </abbr>
 
+                                                                       <!-- Empty span used for creating unAPI links -->
+                                                                       <span name="googleBooks" class="hide_me">
+                                                                               <a style='padding-left: 8px;' class='classic_link' name="googleBooks-link">&result.googleBooks.browse;</a>
+                                                                       </span>
+
+
                                                                </td>
                                                        </tr>