[Patches] [PATCH] Bug-7161 Open Library - Larger image, Read, borrow and checked-out status

koha-patchbot at kohaaloha.com koha-patchbot at kohaaloha.com
Sun Nov 6 00:00:03 NZDT 2011


From: Amit Gupta <amit.gupta at osslabs.biz>
Date: Sat, 5 Nov 2011 03:36:23 -0400
Subject: [PATCH] Bug-7161 Open Library - Larger image, Read, borrow and checked-out status

To test:
1. go into system administration and search for "cover"
2. change "OpenLibraryCovers" to "add" and all other to "don't show"
3. verify that opac search results have small covers, while
   detail page has big ones
4. (optional) find book which is available for reading (and not
   borrowed!) on Open Library and change ISBN on one of your books
   to test

Signed-off-by: Dobrica Pavlinusic <dpavlin at rot13.org>
---
 koha-tmpl/opac-tmpl/prog/en/js/openlibrary.js |  113 ++++++++++++++++++-------
 1 files changed, 83 insertions(+), 30 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/prog/en/js/openlibrary.js b/koha-tmpl/opac-tmpl/prog/en/js/openlibrary.js
index 1c62e6c..9727d3e 100644
--- a/koha-tmpl/opac-tmpl/prog/en/js/openlibrary.js
+++ b/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 = '<a href="' + ebook["read_url"] + '">' + '<img  src="' + buttons["full access"] + '"/></a>';
+           }
+           if (ebook["availability"] == "borrow") {
+		if(ebook.checkedout) {
+               	    result = '<a href="' + ebook["borrow_url"] + '">' + '<img  src="' + buttons["checkedout"] + '"/></a>';
+		} else { 
+                    result = '<a href="' + ebook["borrow_url"] + '">' + '<img  src="' + buttons["lendable"] + '"/></a>';
+                }
+           }                
+       }
+   }
+   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 <div
      * and link to preview if div id is gbs-thumbnail-preview
      */
     olCallBack: function(booksInfo) {
-       for (id in booksInfo) {
-          var book = booksInfo[id];
-          var isbn = book.bib_key.substring(5);
-          
-          $("."+isbn).each(function() {
-              var a = document.createElement("a");
-              a.href = book.info_url;
-				      if (typeof(book.thumbnail_url) != "undefined") {
-	               	var img = document.createElement("img");
-	                img.src = book.thumbnail_url;
-					        $(this).append(img);
-                  var re = /^openlibrary-thumbnail-preview/;
-                  if ( re.exec($(this).attr("id")) ) {
-                      $(this).append(
-                        '<div style="margin-bottom:5px; margin-top:-5px;font-size:9px">' +
-                        '<a href="' + 
-                        book.info_url + 
-                        '">Preview</a></div>' 
-                      );
-                  }
-		     		} else {
-				    	var message = document.createElement("span");
-					    $(message).attr("class","no-image");
-					    $(message).html(NO_OL_JACKET);
-					    $(this).append(message);
-				    }
-        });
-      }
-    }
+    for (id in booksInfo) {
+       var book = booksInfo[id];
+       var isbn = id.substring(5);
+       $("."+isbn).each(function() {
+           console.log($(this).attr("id"));
+       var is_opacdetail = /openlibrary-thumbnail-preview/.exec($(this).attr("id"));
+	/*console.log([is_opacdetail,this]);
+           var cover = get_cover(book);*/
+	   var ebook = get_ebook(book);
+           var a = document.createElement("a");
+           a.href = booksInfo.url;
+           if (book.cover) {
+               var img = document.createElement("img");
+               if (is_opacdetail) {
+               	img.src = book.cover.medium;
+               	$(this).append(img);
+                $(this).append(
+                       '<div class="results_summary">' + '<a href="' + book.url + '">Preview</a></div>'
+                   );
+                $(this).append(
+                       '<div class="results_summary">' +ebook+'</div>'
+                   );
+               } else {
+			img.src = book.cover.small;
+               		$(this).append(img);
+		}
+           } else {
+               var message =  document.createElement("span");
+               $(message).attr("class","no-image");
+               $(message).html(NO_OL_JACKET);
+               $(this).append(message);
+           }
+       });
+   }
+ }
 };
-- 
1.7.2.5


More information about the Patches mailing list