From: Jeff Davis Date: Tue, 11 Jul 2017 22:45:48 +0000 (-0700) Subject: LP#1673870: move ebook availability JS to standard location X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=07d942af5cff7a861b6b1f1809cae5a8374e430c;p=evergreen%2Fjoelewis.git LP#1673870: move ebook availability JS to standard location Signed-off-by: Jeff Davis Signed-off-by: Galen Charlton Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/templates/opac/parts/ebook_api/avail_js.tt2 b/Open-ILS/src/templates/opac/parts/ebook_api/avail_js.tt2 deleted file mode 100644 index 216d2da2f3..0000000000 --- a/Open-ILS/src/templates/opac/parts/ebook_api/avail_js.tt2 +++ /dev/null @@ -1,54 +0,0 @@ - diff --git a/Open-ILS/src/templates/opac/parts/ebook_api/base_js.tt2 b/Open-ILS/src/templates/opac/parts/ebook_api/base_js.tt2 index 30ee0f52c6..bcff0915ae 100644 --- a/Open-ILS/src/templates/opac/parts/ebook_api/base_js.tt2 +++ b/Open-ILS/src/templates/opac/parts/ebook_api/base_js.tt2 @@ -89,3 +89,7 @@ dojo.addOnLoad(function() { [%- END %] +[%- IF (ctx.page == 'rresult' OR ctx.page == 'record') %] + +[%- END %] + diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2 index 79db0edef7..01fb9f943d 100644 --- a/Open-ILS/src/templates/opac/parts/js.tt2 +++ b/Open-ILS/src/templates/opac/parts/js.tt2 @@ -123,7 +123,6 @@ [% IF ebook_api.enabled == 'true' %] [% INCLUDE "opac/parts/ebook_api/base_js.tt2" %] - [% INCLUDE "opac/parts/ebook_api/avail_js.tt2" IF (ctx.page == 'rresult' OR ctx.page == 'record') %] [% INCLUDE "opac/parts/ebook_api/login_js.tt2" IF (ctx.page == 'login') %] [% END %] diff --git a/Open-ILS/web/js/ui/default/opac/ebook_api/avail.js b/Open-ILS/web/js/ui/default/opac/ebook_api/avail.js new file mode 100644 index 0000000000..b65bf8773a --- /dev/null +++ b/Open-ILS/web/js/ui/default/opac/ebook_api/avail.js @@ -0,0 +1,52 @@ +dojo.addOnLoad(function() { + + // detect ebooks on current page for each vendor + dojo.forEach(vendor_list, function(v) { + var vendor = new Vendor(v); + var ebook_nodes = dojo.query("." + v + "_avail"); + console.log('found ' + ebook_nodes.length + ' ebooks on this page'); + + // we have ebooks for this vendor, so let's get availability info etc. + if (ebook_nodes.length > 0) { + checkSession(v, function(v,ses) { + ebook_nodes.forEach(function(node) { + var ebook = new Ebook(v, node.getAttribute("id")); + ebook.rec_id = node.parentNode.getAttribute("id"); + vendor.ebooks.push(ebook); + + ebook.getHoldings( function(holdings) { + if (typeof holdings.available !== 'undefined') { + var avail = holdings.available; + if (avail == 1) { + node.innerHTML = 'This title is available online.'; + } else if (avail == 0) { + node.innerHTML = 'This title is not currently available.'; + } else { + console.log(ebook.id + ' has bad availability: ' + avail); + } + } else { + if (holdings.formats.length > 0) { + var formats_ul = dojo.create("ul", null, ebook.rec_id + '_formats'); + dojo.forEach(holdings.formats, function(f) { + dojo.create("li", { innerHTML: f.name }, formats_ul); + }); + var status_node = dojo.byId(ebook.rec_id + '_status'); + var status_str = holdings.copies_available + ' of ' + holdings.copies_owned + ' available'; + status_node.innerHTML = status_str; + dojo.removeClass(ebook.rec_id + '_ebook_holdings', "hidden"); + if (holdings.copies_available > 0) { + dojo.removeClass(ebook.rec_id + '_ebook_checkout', "hidden"); + } else { + dojo.removeClass(ebook.rec_id + '_ebook_place_hold', "hidden"); + } + } + } + // unhide holdings/availability info now that it's populated + removeClass(node.parentNode, "hidden"); + }); + }); + }); + } + }); + +});