[open-ils-commits] [GIT] Evergreen ILS branch rel_2_1 updated. 22f7c28bbfe83b204cbc1107ed7d3bcd3b21ff2d

Evergreen Git git at git.evergreen-ils.org
Thu Nov 17 19:10:06 EST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_2_1 has been updated
       via  22f7c28bbfe83b204cbc1107ed7d3bcd3b21ff2d (commit)
      from  f015e53f90ec0ab52c5d66fac24ad34d592922ee (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 22f7c28bbfe83b204cbc1107ed7d3bcd3b21ff2d
Author: Dan Wells <dbw2 at calvin.edu>
Date:   Thu Nov 17 16:22:58 2011 -0500

    Switch to new Google Books API; make SSL friendly
    
    As implied in the title, this commit does two things.  First, it
    switches to the new Google Books API (which is both imminent and
    also necessary to make SSL calls work).  From what I have read and
    experienced, we do not need an API key to do searches and previews.
    I have also not hit any kind of unauthenticated limit in several
    days of heavy testing, so I would figure we are safe (at this
    point) for normal end-user OPAC browsing.
    
    Second, all Google Book requests are now done over https.  This
    eliminates the majority of mixed content warnings when browsing
    securely, though you still get a warning when you actual do preview
    a book.
    
    In addition to possibly implementing protocol detection (rather
    than doing https all the time as a "lowest" common denominator),
    there are a few minor points where we might consider future changes.
    Those points are commented within the code.
    
    Signed-off-by: Dan Wells <dbw2 at calvin.edu>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/Open-ILS/web/opac/skin/default/js/rdetail.js b/Open-ILS/web/opac/skin/default/js/rdetail.js
index 2d08344..13c5eab 100644
--- a/Open-ILS/web/opac/skin/default/js/rdetail.js
+++ b/Open-ILS/web/opac/skin/default/js/rdetail.js
@@ -1254,7 +1254,7 @@ function rdetailCheckForGBPreview() {
 function searchForGBPreview( isbn ) {
 	dojo.require("dojo.io.script");
 	dojo.io.script.get({"url": "https://www.google.com/jsapi"});
-	dojo.io.script.get({"url": "http://books.google.com/books", "content": { "bibkeys": isbn, "jscmd": "viewapi", "callback": "GBPreviewCallback"}});
+	dojo.io.script.get({"url": "https://www.googleapis.com/books/v1/volumes", "content": { "q": "isbn:" + isbn, "callback": "GBPreviewCallback"}});
 }
 
 /**
@@ -1266,21 +1266,17 @@ function searchForGBPreview( isbn ) {
  * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
  */
 function GBPreviewCallback(GBPBookInfo) {
-	var GBPreviewDiv = document.getElementById("rdetail_preview_div");
-	var GBPBook;
+	if (GBPBookInfo.totalItems < 1) return;
 
-	for ( i in GBPBookInfo ) {
-		GBPBook = GBPBookInfo[i];
-	}
-
-	if ( !GBPBook ) {
+	var accessInfo = GBPBookInfo.items[0].accessInfo;
+	if ( !accessInfo ) {
 		return;
 	}
 
-	if ( GBPBook.preview != "noview" ) {
+	if ( accessInfo.embeddable ) {
 		// Add a button below the book cover image to load the preview.
 		GBPBadge = document.createElement( 'img' );
-		GBPBadge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
+		GBPBadge.src = 'https://www.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
 		GBPBadge.title = $('rdetail_preview_badge').innerHTML;
 		GBPBadge.style.border = 0;
 		GBPBadgelink = document.createElement( 'a' );
diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js
index baf10ef..a35204d 100644
--- a/Open-ILS/web/opac/skin/default/js/result_common.js
+++ b/Open-ILS/web/opac/skin/default/js/result_common.js
@@ -5,7 +5,7 @@ var opac_strings = dojo.i18n.getLocalization("openils.opac", "opac");
 var recordsHandled = 0;
 var recordsCache = [];
 var lowHitCount = 4;
-var isbnList = '';
+var isbnList = [];
 var googleBooksLink = true;
 
 var resultFetchAllRecords = false;
@@ -427,15 +427,37 @@ function buildunAPISpan (span, type, id) {
 }
 
 function unhideGoogleBooksLink (data) {
-    for ( var i in data ) {
-        //if (data[i].preview == 'noview') continue;
+    for (var i = 0; i < data.items.length; i++) {
+        var item = data.items[i];
+
+        var gbspan;
+        for (var j = 0; j < item.volumeInfo.industryIdentifiers.length; j++) {
+            // XXX: As of 11-17-2011, some items do not return their own ISBN
+            // as an identifier, so this code fails.  For example:
+            // https://www.googleapis.com/books/v1/volumes?q=isbn:0743243560&callback=unhideGoogleBooksLink
+            // It seems the only way around this would be doing a separate
+            // search for each result rather than one search for the whole
+            // page.  Informal testing seems to indicate that these books
+            // are generally Google-unfriendly (no previews, not embeddable),
+            // so we will live without them for now.
+            var ident = item.volumeInfo.industryIdentifiers[j].identifier;
+            gbspan = $n(document.documentElement, 'googleBooksLink-' + ident);
+            if (gbspan) break;
+        }
+        if (!gbspan) continue;
 
-        var gbspan = $n(document.documentElement, 'googleBooksLink-' + i);
         var gba = $n(gbspan, "googleBooks-link");
 
         gba.setAttribute(
             'href',
-            data[i].info_url
+            item.volumeInfo.infoLink
+            // XXX: we might consider constructing the above link ourselves,
+            // as the link provided populates the search box with our original
+            // multi-item search.  Something like:
+            // 'http://books.google.com/books?id=' + item.id
+            // Postive: cleaner display
+            // Negative: more fragile (link format subject to change; likely
+            // enough to matter?)
         );
         removeCSSClass( gbspan, 'hide_me' );
     }
@@ -456,13 +478,16 @@ function resultDisplayRecord(rec, pos, is_mr) {
     if (googleBooksLink) {
 	    var gbspan = $n(r, "googleBooksLink");
         if (currentISBN) {
+            // Google never has dashes in the ISBN, records sometimes do;
+            // remove them to match
+            // XXX: consider making part of cleanISBN(), or we can work around
+            // this if we move to one request per record
             gbspan.setAttribute(
                 'name',
-                gbspan.getAttribute('name') + '-' + currentISBN
+                gbspan.getAttribute('name') + '-' + currentISBN.toString().replace(/-/g,"")
             );
 
-            if (isbnList) isbnList += ', ';
-            isbnList += currentISBN;
+            isbnList.push(currentISBN);
         }
     }
 
@@ -684,12 +709,12 @@ function resultBuildFormatIcons( row, rec, is_mr ) {
 }
 
 function fetchGoogleBooksLink () {
-    if (isbnList && googleBooksLink) {
+    if (isbnList.length > 0 && googleBooksLink) {
         var scriptElement = document.createElement("script");
         scriptElement.setAttribute("id", "jsonScript");
         scriptElement.setAttribute("src",
-            "http://books.google.com/books?bibkeys=" + 
-            escape(isbnList) + "&jscmd=viewapi&callback=unhideGoogleBooksLink");
+            "https://www.googleapis.com/books/v1/volumes?q=" + 
+            escape('isbn:' + isbnList.join(' | isbn:')) + "&callback=unhideGoogleBooksLink");
         scriptElement.setAttribute("type", "text/javascript");
         // make the request to Google Book Search
         document.documentElement.firstChild.appendChild(scriptElement);

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/web/opac/skin/default/js/rdetail.js       |   16 +++----
 Open-ILS/web/opac/skin/default/js/result_common.js |   47 +++++++++++++++-----
 2 files changed, 42 insertions(+), 21 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list