PROCESS "opac/parts/misc_util.tt2";
PROCESS "opac/parts/myopac/column_sort_support.tt2";
WRAPPER "opac/parts/myopac/base.tt2";
- myopac_page = "ebook_circs" %]
+ myopac_page = "ebook_circs";
+ IF CGI.param("action") == 'checkout';
+ ebook_circs_title = l('Check Out E-Item');
+ ELSE;
+ ebook_circs_title = l('E-Items Currently Checked Out');
+ END;
+%]
<h3 class="sr-only">[% l('E-Items Currently Checked Out') %]</h3>
<div id='myopac_checked_div'>
<a href="[% mkurl('circs',{},1) %]">[% l("Current Items Checked Out") %]</a>
</div>
<div class="align selected">
- <a href="#">[% l("E-Items Currently Checked Out") %]</a>
+ <a href="[% mkurl('',{},1) %]">[% l("E-Items Currently Checked Out") %]</a>
</div>
<div class="align">
<a href="[% mkurl('circ_history',{},1) %]">[% l("Check Out History") %]</a>
</div>
<div class="header_middle">
- <span class="float-left">[% l('E-Items Currently Checked Out') %]</span>
+ <span class="float-left">[% ebook_circs_title %]</span>
</div>
<div class="clear-both"></div>
<div id="no_ebook_circs" class="warning_box hidden">[% l('You have no e-items checked out.') %]</div>
+ <div id="ebook_checkout_failed" class="warning_box hidden">[% l('E-item could not be checked out.') %]</div>
+ <div id="ebook_checkout_succeeded" class="success hidden">[% l('E-item successfully checked out.') %]</div>
<div id='ebook_circs_main' class="hidden">
<table id="ebook_circs_main_table"
- title="[% l('E-Items Currently Checked Out') %]"
+ title="[% ebook_circs_title %]"
class="table_no_border_space table_no_cell_pad item_list_padding">
<thead>
<tr>
this.vendor = vendor;
this.id = id; // external ID for this title
this.rec_id; // bre.id for this title's MARC record
+ this.title; // title of ebook
+ this.author; // author of ebook
this.avail; // availability info for this title
this.holdings = {}; // holdings info
+ this.conns = {}; // references to Dojo event connection for performing actions with this ebook
+
+}
+
+Ebook.prototype.getDetails = function(callback) {
+ var ses = dojo.cookie(this.vendor);
+ var ebook = this;
+ new OpenSRF.ClientSession('open-ils.ebook_api').request({
+ method: 'open-ils.ebook_api.title.details',
+ params: [ ses, ebook.id ],
+ async: true,
+ oncomplete: function(r) {
+ var resp = r.recv();
+ if (resp) {
+ console.log('title details response: ' + resp.content());
+ ebook.title = resp.content().title;
+ ebook.author = resp.content().author;
+ return callback(ebook);
+ }
+ }
+ }).send();
}
Ebook.prototype.getAvailability = function(callback) {
}).send();
}
+Ebook.prototype.checkout = function(authtoken, patron_id, callback) {
+ var ses = dojo.cookie(this.vendor);
+ var ebook = this;
+ new OpenSRF.ClientSession('open-ils.ebook_api').request({
+ method: 'open-ils.ebook_api.checkout',
+ params: [ authtoken, ses, ebook.id, patron_id ],
+ async: true,
+ oncomplete: function(r) {
+ var resp = r.recv();
+ if (resp) {
+ console.log('checkout response: ' + resp.content());
+ return callback(resp.content());
+ }
+ }
+ }).send();
+}
+
holds_ready: []
};
+// Ebook to perform actions on.
+var active_ebook;
+if (typeof ebook_action.title_id !== 'undefined') {
+ active_ebook = new Ebook(ebook_action.vendor, ebook_action.title_id);
+}
+
dojo.addOnLoad(function() {
dojo.forEach(vendor_list, function(v) {
}
function updateCheckoutView() {
- if (xacts.checkouts.length < 1) {
+ if (typeof ebook_action.type !== 'undefined') {
+ if (ebook_action.type == 'checkout') {
+ getReadyForCheckout();
+ }
+ } else if (xacts.checkouts.length < 1) {
dojo.removeClass('no_ebook_circs', "hidden");
} else {
dojo.forEach(xacts.checkouts, function(x) {
}
}
+// set up page for user to perform a checkout
+function getReadyForCheckout() {
+ if (typeof active_ebook === 'undefined') {
+ console.log('No active ebook specified, cannot prepare for checkout');
+ dojo.removeClass('ebook_checkout_failed', "hidden");
+ } else {
+ active_ebook.getDetails( function(ebook) {
+ dojo.empty('ebook_circs_main_table_body');
+ var tr = dojo.create("tr", null, dojo.byId('ebook_circs_main_table_body'));
+ dojo.create("td", { innerHTML: ebook.title }, tr);
+ dojo.create("td", { innerHTML: ebook.author }, tr);
+ dojo.create("td", null, tr);
+ dojo.create("td", { id: "checkout-button-td" }, tr);
+ var button = dojo.create("input", { id: "checkout-button", type: "button", value: l_strings.checkout }, dojo.byId('checkout-button-td'));
+ ebook.conns.checkout = dojo.connect(button, 'onclick', "doCheckout");
+ dojo.removeClass('ebook_circs_main', "hidden");
+ });
+ }
+}
+
+// check out our active ebook
+function doCheckout() {
+ active_ebook.checkout(authtoken, patron_id, function(resp) {
+ if (resp.due_date) {
+ console.log('Checkout succeeded!');
+ dojo.destroy('checkout-button');
+ dojo.removeClass('ebook_checkout_succeeded', "hidden");
+ // add our successful checkout to top of transaction cache
+ var new_xact = {
+ title_id: active_ebook.id,
+ title: active_ebook.title,
+ author: active_ebook.author,
+ due_date: resp.due_date,
+ download_url: '' // TODO - for OverDrive, user must "lock in" a format first!
+ };
+ xacts.checkouts.unshift(new_xact);
+ // unset variables related to the transaction we have performed,
+ // to avoid any weirdness on page reload
+ ebook_action = {};
+ active_ebook = undefined;
+ // update page to account for successful checkout
+ addTotalsToPage();
+ addTransactionsToPage();
+ // clear transaction cache to force a refresh on next page load
+ dojo.cookie('ebook_xact_cache', '', {path: '/', expires: '-1h'});
+ } else {
+ console.log('Checkout failed: ' + resp.error_msg);
+ dojo.removeClass('ebook_checkout_failed', "hidden");
+ }
+ // When we switch to jQuery, we can use .one() instead of .on(),
+ // obviating the need for an explicit disconnect here.
+ dojo.disconnect(active_ebook.conns.checkout);
+ });
+}
+
// deserialize transactions from cache, returning them as a JS object
function getCachedTransactions() {
console.log('retrieving cached transaction details');