@@ -, +, @@ detail page has big ones borrowed!) on Open Library and change ISBN on one of your books to test --- koha-tmpl/opac-tmpl/prog/en/js/openlibrary.js | 113 ++++++++++++++++++------- 1 files changed, 83 insertions(+), 30 deletions(-) --- a/koha-tmpl/opac-tmpl/prog/en/js/openlibrary.js +++ a/koha-tmpl/opac-tmpl/prog/en/js/openlibrary.js @@ -2,6 +2,51 @@ if (typeof KOHA == "undefined" || !KOHA) { var KOHA = {}; } +function get_cover(data) { + if (data.cover && data.cover.small) { + return data.cover.small; + } + return "undefined"; +} + +function get_ebook(data) { + var buttons = { + 'full access': + "http://openlibrary.org/images/button-read-open-library.png", + 'lendable': + "http://openlibrary.org/images/button-borrow-open-library.png", + 'checkedout': + "http://openlibrary.org/images/button-checked-out-open-library.png" + }; + + var result = ""; + if (data["ebooks"] != "undefined") { + /* Ebooks are available */ + var ebooks = data["ebooks"]; + for (idx in ebooks) { + var ebook = ebooks[idx]; + if (ebook["availability"] == "full") { + result = '' + ''; + } + if (ebook["availability"] == "borrow") { + if(ebook.checkedout) { + result = '' + ''; + } else { + result = '' + ''; + } + } + } + } + return result; + } + +function keys(d) { + var k = []; + for (var i in d) { + k.push(i); + } + return k; +} /** * A namespace for OpenLibrary related functions. */ @@ -27,44 +72,52 @@ KOHA.OpenLibrary = { scriptElement.setAttribute("id", "jsonScript"); scriptElement.setAttribute("src", "http://openlibrary.org/api/books?bibkeys=" + escape(bibkeys) + - "&callback=KOHA.OpenLibrary.olCallBack"); + "&callback=KOHA.OpenLibrary.olCallBack&jscmd=data"); scriptElement.setAttribute("type", "text/javascript"); document.documentElement.firstChild.appendChild(scriptElement); }, + + /** * Add cover pages