From: Dan Scott <dan@coffeecode.net>
Date: Thu, 2 Jun 2011 05:42:49 +0000 (-0400)
Subject: Don't make OpenLibrary requests without an ID
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=62ddc37d78e07d3aa55b1003b187179f8eedc22a;p=evergreen%2Fmasslnc.git

Don't make OpenLibrary requests without an ID

It is rather silly to make requests if you have not pulled any IDs out
of the records to pass along to OpenLibrary, so do not do that. Also
refactor and add a bit more defensiveness.

Signed-off-by: Dan Scott <dan@coffeecode.net>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
---

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 a7e9fd776f..00194f1b52 100644
--- a/Open-ILS/web/opac/skin/default/js/result_common.js
+++ b/Open-ILS/web/opac/skin/default/js/result_common.js
@@ -451,24 +451,22 @@ function resultDisplayRecord(rec, pos, is_mr) {
 	var r = table.rows[pos + 1];
     var currentISBN = cleanISBN(rec.isbn());
 
-    if (OpenLibraryLinks) {
-        var olspan = $n(r, 'openLibraryLink');
-        if (currentISBN) {
+    if (currentISBN) {
+        isbnList.push(currentISBN);
+        if (OpenLibraryLinks) {
+            var olspan = $n(r, 'openLibraryLink');
             olspan.setAttribute('name', olspan.getAttribute('name') + 
                 '-' + currentISBN
             );
         }
-    }
 
-    if (googleBooksLink) {
-	    var gbspan = $n(r, "googleBooksLink");
-        if (currentISBN) {
+        if (googleBooksLink) {
+            var gbspan = $n(r, "googleBooksLink");
             gbspan.setAttribute(
                 'name',
                 gbspan.getAttribute('name') + '-' + currentISBN
             );
 
-            isbnList.push(currentISBN);
         }
     }
 
@@ -686,7 +684,7 @@ function resultBuildFormatIcons( row, rec, is_mr ) {
 }
 
 function fetchOpenLibraryLinks() {
-    if (isbnList && OpenLibraryLinks) {
+    if (isbnList.length > 0 && OpenLibraryLinks) {
         /* OpenLibrary supports a number of different identifiers:
          * ISBN: isbn:<isbn>
          * LCCN: lccn:<lccn>
@@ -736,6 +734,11 @@ function renderOpenLibraryLinks(response) {
             }
         });
 
+        /* If there are no books to read or borrow, move on */
+        if (!ol_ebooks[isbn]) {
+            continue;
+        }
+
         /* Now populate the results page with our ebook goodness*/
         /* Go for the jugular - exact match with full access */
         if (ol_ebooks[isbn]['exact_full']) {