Bug 36084: svc - overdrive

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Nick Clemens 2024-02-27 19:14:19 +00:00 committed by Jonathan Druart
parent 6323e08ed7
commit 82359cf085
Signed by: jonathan.druart
GPG key ID: A085E712BEF0E0F0
3 changed files with 16 additions and 15 deletions

View file

@ -7,7 +7,7 @@
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="#" method="post" id="overdrive-login-form">
<form action="#" id="overdrive-login-form">
[% INCLUDE 'csrf-token.inc' %]
<div class="modal-body">
<fieldset class="brief">

View file

@ -193,6 +193,7 @@ KOHA.OverDriveCirculation = new function() {
}
function svc_ajax ( method, params, success_callback ) {
params.csrf_token = $('meta[name="csrf-token"]').attr('content');
return $.ajax({
method: method,
dataType: "json",
@ -218,7 +219,7 @@ KOHA.OverDriveCirculation = new function() {
}
function login(p) {
svc_ajax('get', { action: "login", password: p }, function(data) {
svc_ajax('post', { action: "cud-login", password: p }, function(data) {
details = null;
if( data.login_success ){
$(login_div).detach();
@ -232,7 +233,7 @@ KOHA.OverDriveCirculation = new function() {
}
function logout (callback) {
svc_ajax('post', { action: "logout" }, function(data) {
svc_ajax('post', { action: "cud-logout" }, function(data) {
details = null;
callback(data);
});
@ -300,7 +301,7 @@ KOHA.OverDriveCirculation = new function() {
$(el).append( ajax_button( __("Check in"), function() {
if( confirm( __("Are you sure you want to return this item?") ) ) {
item_action({action: "return", id: id}, el, copies_available + 1);
item_action({action: "cud-return", id: id}, el, copies_available + 1);
}
}, "checkin") );
@ -318,7 +319,7 @@ KOHA.OverDriveCirculation = new function() {
if(copies_available && checkout_popup) {
$(el).append( ajax_button( __("Check out") , function() {
if( confirm( __("Are you sure you want to check out this item?") ) ) {
svc_ajax('post', {action: "checkout", id: id}, function(data) {
svc_ajax('post', {action: "cud-checkout", id: id}, function(data) {
if (data.checkouts) {
details.checkouts = data.checkouts;
}
@ -347,14 +348,14 @@ KOHA.OverDriveCirculation = new function() {
}
else if (!item) {
$(el).append( ajax_button( __("Place hold"), function() {
item_action({action: "place-hold", id: id}, el, copies_available);
item_action({action: "cud-place-hold", id: id}, el, copies_available);
}, "placehold") );
}
if (item) {
$(el).append( ajax_button( __("Cancel hold"), function() {
if( confirm( __("Are you sure you want to cancel this hold?") ) ) {
item_action({action: "remove-hold", id: id}, el, copies_available);
item_action({action: "cud-remove-hold", id: id}, el, copies_available);
}
}, "cancelhold") );
}
@ -399,7 +400,7 @@ KOHA.OverDriveCirculation = new function() {
checkout_popup.find(".overdrive-checkout-submit").click(function(e) {
e.preventDefault();
var format = checkout_format_list.find("input[type='radio'][name='checkout-format']:checked").val();
item_action({action: "checkout-format", id: id, format: format}, el, copies_available);
item_action({action: "cud-checkout-format", id: id, format: format}, el, copies_available);
$(this).unbind( e );
checkout_popup.modal("hide");
});

View file

@ -44,7 +44,7 @@ my %data = (
local $@;
eval {
{
$action eq 'login' && do {
$action eq 'cud-login' && do {
my $password = $cgi->param("password") // q{} ;
my $patron = Koha::Patrons->find({ userid => $user });
my $branch_info = $patron ? Koha::Library::OverDriveInfos->find( $patron->branchcode ) : undef;
@ -64,7 +64,7 @@ eval {
if ($od->is_logged_in) {
$data{is_logged_in} = JSON::true;
$action eq 'logout' && do {
$action eq 'cud-logout' && do {
$od->forget();
$data{login_url} = $od->auth_url($page_url);
$data{is_logged_in} = JSON::false;
@ -78,7 +78,7 @@ eval {
last;
};
$action eq 'checkout' && do {
$action eq 'cud-checkout' && do {
my $id = $cgi->param('id')
or response_bad_request("No 'id' specified");
my $format = $cgi->param('format');
@ -88,7 +88,7 @@ eval {
last;
};
$action eq 'checkout-format' && do {
$action eq 'cud-checkout-format' && do {
my $id = $cgi->param('id')
or response_bad_request("No 'id' specified");
my $format = $cgi->param('format')
@ -105,7 +105,7 @@ eval {
last;
};
$action eq 'return' && do {
$action eq 'cud-return' && do {
my $id = $cgi->param('id')
or response_bad_request("No 'id' specified");
local $@;
@ -115,7 +115,7 @@ eval {
last;
};
$action eq 'place-hold' && do {
$action eq 'cud-place-hold' && do {
my $id = $cgi->param('id')
or response_bad_request("No 'id' specified");
$data{action} = $od->place_hold($id);
@ -123,7 +123,7 @@ eval {
last;
};
$action eq 'remove-hold' && do {
$action eq 'cud-remove-hold' && do {
my $id = $cgi->param('id')
or response_bad_request("No 'id' specified");
local $@;