Don't make OpenLibrary requests without an ID
authorDan Scott <dan@coffeecode.net>
Thu, 2 Jun 2011 05:42:49 +0000 (01:42 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 21 Jun 2011 19:17:35 +0000 (15:17 -0400)
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>
Open-ILS/web/opac/skin/default/js/result_common.js

index a7e9fd7..00194f1 100644 (file)
@@ -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']) {