|
Lines 1-3
Link Here
|
|
|
1 |
/* global MSG_OVERDRIVE_LOGIN MSG_OVERDRIVE_LINK MSG_OVERDRIVE_LOGOUT MSG_OVERDRIVE_CHECKEDOUT_UNTIL MSG_DOWNLOAD MSG_OVERDRIVE_ACCESS_ONLINE MSG_OVERDRIVE_DOWNLOAD_AS MSG_CHECK_IN MSG_CHECK_OUT MSG_CHECKOUTS MSG_HOLDS MSG_ON_HOLD MSG_PLACE_HOLD MSG_CANCEL_HOLD MSG_OVERDRIVE_CANNOT_CHECKOUT MSG_CANCEL_HOLD_CONFIRM MSG_CHECK_IN_CONFIRM MSG_CHECK_OUT_CONFIRM OD_password_required */ |
| 2 |
|
| 1 |
if ( typeof KOHA == "undefined" || !KOHA ) { |
3 |
if ( typeof KOHA == "undefined" || !KOHA ) { |
| 2 |
var KOHA = {}; |
4 |
var KOHA = {}; |
| 3 |
} |
5 |
} |
|
Lines 74-80
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 74 |
if( OD_password_required ) { $("#overdrive-login").modal('show'); } |
76 |
if( OD_password_required ) { $("#overdrive-login").modal('show'); } |
| 75 |
else { login(""); } |
77 |
else { login(""); } |
| 76 |
}) |
78 |
}) |
| 77 |
.text(_("Login to OverDrive account")); |
79 |
.text( MSG_OVERDRIVE_LOGIN ); |
| 78 |
|
80 |
|
| 79 |
var login_div = $('<div class="overdrive-login">').append(login_link); |
81 |
var login_div = $('<div class="overdrive-login">').append(login_link); |
| 80 |
|
82 |
|
|
Lines 87-92
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 87 |
var checkout_popup = null; |
89 |
var checkout_popup = null; |
| 88 |
$( document ).ready(function() { |
90 |
$( document ).ready(function() { |
| 89 |
var p = window.opener; |
91 |
var p = window.opener; |
|
|
92 |
var cb; |
| 90 |
if (p) { |
93 |
if (p) { |
| 91 |
try { cb = p.refresh_overdrive_account_details;} |
94 |
try { cb = p.refresh_overdrive_account_details;} |
| 92 |
catch(err){ return; } //Catch error if opener is not accessible |
95 |
catch(err){ return; } //Catch error if opener is not accessible |
|
Lines 113-119
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 113 |
} |
116 |
} |
| 114 |
|
117 |
|
| 115 |
var overdrive_link = $('<a href="https://www.overdrive.com/account/" target="overdrive-account" class="overdrive-link" style="float:right">') |
118 |
var overdrive_link = $('<a href="https://www.overdrive.com/account/" target="overdrive-account" class="overdrive-link" style="float:right">') |
| 116 |
.text("OverDrive Account Page"); |
119 |
.text( MSG_OVERDRIVE_LINK ); |
| 117 |
$(container).append(overdrive_link); |
120 |
$(container).append(overdrive_link); |
| 118 |
|
121 |
|
| 119 |
var logout_link = $('<a href="#logout" class="overdrive-logout" style="float:left">') |
122 |
var logout_link = $('<a href="#logout" class="overdrive-logout" style="float:left">') |
|
Lines 123-134
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 123 |
logout(function(data) { |
126 |
logout(function(data) { |
| 124 |
display_account(container, data); |
127 |
display_account(container, data); |
| 125 |
}); |
128 |
}); |
| 126 |
}).text(_("Logout from OverDrive account")); |
129 |
}).text( MSG_OVERDRIVE_LOGOUT ); |
| 127 |
$(container).append(logout_link); |
130 |
$(container).append(logout_link); |
| 128 |
$(container).append('<br style="clear:both;"/>'); |
131 |
$(container).append('<br style="clear:both;"/>'); |
| 129 |
|
132 |
|
| 130 |
if (data.checkouts) { |
133 |
if (data.checkouts) { |
| 131 |
var checkouts_div = $('<div class="overdrive-div">').html('<h3>' + _("Checkouts") + '</h3>'); |
134 |
var checkouts_div = $('<div class="overdrive-div">').html('<h3>' + MSG_CHECKOUTS + '</h3>'); |
| 132 |
var checkouts_list = $('<ul class="overdrive-list">'); |
135 |
var checkouts_list = $('<ul class="overdrive-list">'); |
| 133 |
data.checkouts.items.forEach(function(item) { |
136 |
data.checkouts.items.forEach(function(item) { |
| 134 |
item_line(checkouts_list, item); |
137 |
item_line(checkouts_list, item); |
|
Lines 138-144
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 138 |
} |
141 |
} |
| 139 |
|
142 |
|
| 140 |
if (data.holds) { |
143 |
if (data.holds) { |
| 141 |
var holds_div = $('<div class="overdrive-div">').html('<h3>' + _("Holds") + '</h3>'); |
144 |
var holds_div = $('<div class="overdrive-div">').html('<h3>' + MSG_HOLDS + '</h3>'); |
| 142 |
var holds_list = $('<ul class="overdrive-list">'); |
145 |
var holds_list = $('<ul class="overdrive-list">'); |
| 143 |
data.holds.items.forEach(function(item) { |
146 |
data.holds.items.forEach(function(item) { |
| 144 |
item_line(holds_list, item); |
147 |
item_line(holds_list, item); |
|
Lines 209-215
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 209 |
if( $("#overdrive-results-page").length > 0 ){ |
212 |
if( $("#overdrive-results-page").length > 0 ){ |
| 210 |
location.reload(); |
213 |
location.reload(); |
| 211 |
} else { |
214 |
} else { |
| 212 |
KOHA.OverDriveCirculation.display_account_details( $("#opac-user-overdrive") ); |
215 |
KOHA.OverDriveCirculation.display_account_details( $("#opac-user-overdrive") ); |
| 213 |
} |
216 |
} |
| 214 |
} |
217 |
} |
| 215 |
}); |
218 |
}); |
|
Lines 271-283
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 271 |
if (item) { |
274 |
if (item) { |
| 272 |
var expires = new Date(item.expires); |
275 |
var expires = new Date(item.expires); |
| 273 |
$('<span class="overdrive-item-status">') |
276 |
$('<span class="overdrive-item-status">') |
| 274 |
.text(_("Checked out until") + " " + expires.toLocaleString()) |
277 |
.text( MSG_OVERDRIVE_CHECKEDOUT_UNTIL + " " + expires.toLocaleString()) |
| 275 |
.appendTo(el); |
278 |
.appendTo(el); |
| 276 |
$(el).append(" "); |
279 |
$(el).append(" "); |
| 277 |
|
280 |
|
| 278 |
if (item.format) { |
281 |
if (item.format) { |
| 279 |
var download = $('<a href="#">').appendTo(el); |
282 |
var download = $('<a href="#">').appendTo(el); |
| 280 |
decorate_button(download, _("Download") + " " + item.format); |
283 |
decorate_button(download, MSG_DOWNLOAD + " " + item.format); |
| 281 |
svc_ajax('get', {action: "download-url", id: id, format: item.format}, function(data) { |
284 |
svc_ajax('get', {action: "download-url", id: id, format: item.format}, function(data) { |
| 282 |
download.attr("href", data.action); |
285 |
download.attr("href", data.action); |
| 283 |
}); |
286 |
}); |
|
Lines 291-297
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 291 |
|
294 |
|
| 292 |
if (item.formats[f]) { |
295 |
if (item.formats[f]) { |
| 293 |
var access = $('<a target="_blank">').appendTo(el); |
296 |
var access = $('<a target="_blank">').appendTo(el); |
| 294 |
decorate_button(access, _("Access online") + " " + f); |
297 |
decorate_button(access, MSG_OVERDRIVE_ACCESS_ONLINE + " " + f); |
| 295 |
svc_ajax('get', {action: "download-url", id: id, format: f}, function(data) { |
298 |
svc_ajax('get', {action: "download-url", id: id, format: f}, function(data) { |
| 296 |
access.attr("href", data.action); |
299 |
access.attr("href", data.action); |
| 297 |
}); |
300 |
}); |
|
Lines 302-308
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 302 |
} |
305 |
} |
| 303 |
} |
306 |
} |
| 304 |
if (lockable_formats.length > 0 && checkout_popup) { |
307 |
if (lockable_formats.length > 0 && checkout_popup) { |
| 305 |
$(el).append( ajax_button(_("Download as"), function() { |
308 |
$(el).append( ajax_button( MSG_OVERDRIVE_DOWNLOAD_AS, function() { |
| 306 |
checkout_format(el, id, lockable_formats, copies_available); |
309 |
checkout_format(el, id, lockable_formats, copies_available); |
| 307 |
}) ).append(" "); |
310 |
}) ).append(" "); |
| 308 |
} |
311 |
} |
|
Lines 310-317
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 310 |
|
313 |
|
| 311 |
if (item.format) return item; |
314 |
if (item.format) return item; |
| 312 |
|
315 |
|
| 313 |
$(el).append( ajax_button(_("Check in"), function() { |
316 |
$(el).append( ajax_button( MSG_CHECK_IN, function() { |
| 314 |
if( confirm(_("Are you sure you want to return this item?")) ) { |
317 |
if( confirm( MSG_CHECK_IN_CONFIRM ) ) { |
| 315 |
item_action({action: "return", id: id}, el, copies_available + 1); |
318 |
item_action({action: "return", id: id}, el, copies_available + 1); |
| 316 |
} |
319 |
} |
| 317 |
}) ); |
320 |
}) ); |
|
Lines 322-335
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 322 |
item = item_is_on_hold(id); |
325 |
item = item_is_on_hold(id); |
| 323 |
if (item) { |
326 |
if (item) { |
| 324 |
$('<span class="overdrive-status">') |
327 |
$('<span class="overdrive-status">') |
| 325 |
.text(_("On hold")) |
328 |
.text( MSG_ON_HOLD ) |
| 326 |
.appendTo(el); |
329 |
.appendTo(el); |
| 327 |
$(el).append(" "); |
330 |
$(el).append(" "); |
| 328 |
} |
331 |
} |
| 329 |
|
332 |
|
| 330 |
if(copies_available && checkout_popup) { |
333 |
if(copies_available && checkout_popup) { |
| 331 |
$(el).append( ajax_button(_("Check out"), function() { |
334 |
$(el).append( ajax_button( MSG_CHECK_OUT , function() { |
| 332 |
if( confirm(_("Are you sure you want to checkout this item?")) ) { |
335 |
if( confirm( MSG_CHECK_OUT_CONFIRM ) ) { |
| 333 |
svc_ajax('post', {action: "checkout", id: id}, function(data) { |
336 |
svc_ajax('post', {action: "checkout", id: id}, function(data) { |
| 334 |
if (data.checkouts) { |
337 |
if (data.checkouts) { |
| 335 |
details.checkouts = data.checkouts; |
338 |
details.checkouts = data.checkouts; |
|
Lines 358-371
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 358 |
}) ); |
361 |
}) ); |
| 359 |
} |
362 |
} |
| 360 |
else if (!item) { |
363 |
else if (!item) { |
| 361 |
$(el).append( ajax_button(_("Place hold"), function() { |
364 |
$(el).append( ajax_button( MSG_PLACE_HOLD, function() { |
| 362 |
item_action({action: "place-hold", id: id}, el, copies_available); |
365 |
item_action({action: "place-hold", id: id}, el, copies_available); |
| 363 |
}) ); |
366 |
}) ); |
| 364 |
} |
367 |
} |
| 365 |
|
368 |
|
| 366 |
if (item) { |
369 |
if (item) { |
| 367 |
$(el).append( ajax_button(_("Cancel"), function() { |
370 |
$(el).append( ajax_button( MSG_CANCEL_HOLD, function() { |
| 368 |
if( confirm(_("Are you sure you want to cancel this hold?")) ) { |
371 |
if( confirm( MSG_CANCEL_HOLD_CONFIRM ) ) { |
| 369 |
item_action({action: "remove-hold", id: id}, el, copies_available); |
372 |
item_action({action: "remove-hold", id: id}, el, copies_available); |
| 370 |
} |
373 |
} |
| 371 |
}) ); |
374 |
}) ); |
|
Lines 393-399
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 393 |
|
396 |
|
| 394 |
function checkout_format(el, id, formats, copies_available) { |
397 |
function checkout_format(el, id, formats, copies_available) { |
| 395 |
if (formats.length == 0) { |
398 |
if (formats.length == 0) { |
| 396 |
alert(_("Item cannot be checked out - no available formats")); |
399 |
alert( MSG_OVERDRIVE_CANNOT_CHECKOUT ); |
| 397 |
return false; |
400 |
return false; |
| 398 |
} |
401 |
} |
| 399 |
|
402 |
|
|
Lines 423-434
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 423 |
} |
426 |
} |
| 424 |
callback(data); |
427 |
callback(data); |
| 425 |
}); |
428 |
}); |
| 426 |
} |
429 |
}; |
| 427 |
|
430 |
|
| 428 |
this.display_account_details = function( el ) { |
431 |
this.display_account_details = function( el ) { |
| 429 |
window.refresh_overdrive_account_details = function () { |
432 |
window.refresh_overdrive_account_details = function () { |
| 430 |
KOHA.OverDriveCirculation.display_account_details( el ); |
433 |
KOHA.OverDriveCirculation.display_account_details( el ); |
| 431 |
} |
434 |
}; |
| 432 |
$(el).empty().append(error_div); |
435 |
$(el).empty().append(error_div); |
| 433 |
load_account_details(function(data) { |
436 |
load_account_details(function(data) { |
| 434 |
display_account(el, data); |
437 |
display_account(el, data); |
|
Lines 449-452
KOHA.OverDriveCirculation = new function() {
Link Here
|
| 449 |
.append(actions) |
452 |
.append(actions) |
| 450 |
.appendTo(el); |
453 |
.appendTo(el); |
| 451 |
}; |
454 |
}; |
| 452 |
} |
455 |
}; |
| 453 |
- |
|
|