From 62ddc37d78e07d3aa55b1003b187179f8eedc22a Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Thu, 2 Jun 2011 01:42:49 -0400 Subject: [PATCH] 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 Signed-off-by: Bill Erickson --- Open-ILS/web/opac/skin/default/js/result_common.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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: * 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']) { -- 2.11.0