LP#1673870: move ebook availability JS to standard location
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Tue, 11 Jul 2017 22:45:48 +0000 (15:45 -0700)
committerBill Erickson <berickxx@gmail.com>
Fri, 1 Sep 2017 20:06:50 +0000 (16:06 -0400)
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/opac/parts/ebook_api/avail_js.tt2 [deleted file]
Open-ILS/src/templates/opac/parts/ebook_api/base_js.tt2
Open-ILS/src/templates/opac/parts/js.tt2
Open-ILS/web/js/ui/default/opac/ebook_api/avail.js [new file with mode: 0644]

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 (file)
index 216d2da..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<script type="text/javascript">
-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");
-                    });
-                });
-            });
-        }
-    });
-
-});
-</script>
index 30ee0f5..bcff091 100644 (file)
@@ -89,3 +89,7 @@ dojo.addOnLoad(function() {
 <script type="text/javascript" src="[% ctx.media_prefix %]/js/ui/default/opac/ebook_api/loggedin.js[% ctx.cache_key %]"></script>
 [%- END %]
 
+[%- IF (ctx.page == 'rresult' OR ctx.page == 'record') %]
+<script type="text/javascript" src="[% ctx.media_prefix %]/js/ui/default/opac/ebook_api/avail.js"></script>
+[%- END %]
+
index 79db0ed..01fb9f9 100644 (file)
 
 [% 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 (file)
index 0000000..b65bf87
--- /dev/null
@@ -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");
+                    });
+                });
+            });
+        }
+    });
+
+});