Bug 36084: svc - checkin
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
d322494ef6
commit
50f383de75
4 changed files with 85 additions and 31 deletions
|
@ -570,34 +570,29 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
// Handle renewals and returns
|
||||
$("#CheckinChecked").on("click",function(){
|
||||
|
||||
$("#CheckinChecked").on("click",function(e){
|
||||
e.preventDefault();
|
||||
let refresh_table = true;
|
||||
$(".checkin:checked:visible").each(function() {
|
||||
itemnumber = $(this).val();
|
||||
|
||||
$(this).replaceWith("<img id='checkin_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
|
||||
|
||||
function checkin(item_id){
|
||||
params = {
|
||||
itemnumber: itemnumber,
|
||||
borrowernumber: borrowernumber,
|
||||
branchcode: branchcode,
|
||||
item_id,
|
||||
patron_id: borrowernumber,
|
||||
library_id: branchcode,
|
||||
exempt_fine: $("#exemptfine").is(':checked')
|
||||
};
|
||||
|
||||
$.post({
|
||||
url: "/cgi-bin/koha/svc/checkin",
|
||||
data: params,
|
||||
success: function( data ) {
|
||||
id = "#checkin_" + data.itemnumber;
|
||||
const client = APIClient.circulation;
|
||||
return client.checkins.create(params).then(
|
||||
success => {
|
||||
id = "#checkin_" + item_id;
|
||||
|
||||
content = "";
|
||||
if ( data.returned ) {
|
||||
if ( success.returned ) {
|
||||
content = __("Checked in");
|
||||
$(id).parent().parent().addClass('ok');
|
||||
$('#date_due_' + data.itemnumber).html( __("Checked in") );
|
||||
if ( data.patronnote != null ) {
|
||||
$('.patron_note_' + data.itemnumber).html( __("Patron note") + ": " + data.patronnote);
|
||||
$('#date_due_' + success.itemnumber).html( __("Checked in") );
|
||||
if ( success.patronnote != null ) {
|
||||
$('.patron_note_' + success.itemnumber).html( __("Patron note") + ": " + success.patronnote);
|
||||
}
|
||||
} else {
|
||||
content = __("Unable to check in");
|
||||
|
@ -605,21 +600,46 @@ $(document).ready(function() {
|
|||
refresh_table = false;
|
||||
}
|
||||
|
||||
$(id).replaceWith( content );
|
||||
$(id).parent().empty().append(content);
|
||||
},
|
||||
dataType: "json",
|
||||
async: false,
|
||||
});
|
||||
});
|
||||
// Refocus on barcode field if it exists
|
||||
if ( $("#barcode").length ) {
|
||||
$("#barcode").focus();
|
||||
error => {
|
||||
console.warn("Something wrong happened: %s".format(error));
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if ( refresh_table ) {
|
||||
RefreshIssuesTable();
|
||||
function checkin_all(item_ids, fn){
|
||||
let i = 0;
|
||||
function next(){
|
||||
if (i < item_ids.length) {
|
||||
return fn(item_ids[i++]).then(function(id) {
|
||||
return next();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(item_ids).each((i, id) => {
|
||||
$("#checkin_"+id).parent().append("<img id='checkin_" + id+ "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
|
||||
$("#checkin_"+id).hide();
|
||||
});
|
||||
|
||||
return next();
|
||||
}
|
||||
$('#RenewChecked, #CheckinChecked').prop('disabled' , true );
|
||||
|
||||
let item_ids = $(".checkin:checked:visible").map((i, c) => c.value);
|
||||
|
||||
checkin_all(item_ids, checkin).then(() => {
|
||||
// Refocus on barcode field if it exists
|
||||
if ( $("#barcode").length ) {
|
||||
$("#barcode").focus();
|
||||
}
|
||||
|
||||
if ( refresh_table ) {
|
||||
RefreshIssuesTable();
|
||||
}
|
||||
$('#RenewChecked, #CheckinChecked').prop('disabled' , true );
|
||||
});
|
||||
|
||||
// Prevent form submit
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import ArticleRequestAPIClient from "./article-request-api-client.js";
|
||||
import AVAPIClient from "./authorised-value-api-client.js";
|
||||
import CirculationAPIClient from "./circulation-api-client.js";
|
||||
import SysprefAPIClient from "./system-preferences-api-client.js";
|
||||
|
||||
export const APIClient = {
|
||||
article_request: new ArticleRequestAPIClient(),
|
||||
authorised_value: new AVAPIClient(),
|
||||
circulation: new CirculationAPIClient(),
|
||||
syspref: new SysprefAPIClient(),
|
||||
};
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import HttpClient from "./http-client.js";
|
||||
|
||||
export class CirculationAPIClient extends HttpClient {
|
||||
constructor() {
|
||||
super({
|
||||
baseURL: "/cgi-bin/koha/svc/",
|
||||
});
|
||||
}
|
||||
|
||||
get checkins() {
|
||||
return {
|
||||
create: checkin =>
|
||||
this.post({
|
||||
endpoint: "checkin",
|
||||
body: "itemnumber=%s&borrowernumber=%s&branchcode=%s&exempt_fine=%s&op=%s".format(
|
||||
checkin.item_id,
|
||||
checkin.patron_id,
|
||||
checkin.library_id,
|
||||
checkin.exempt_fine,
|
||||
"cud-checkin"
|
||||
),
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/x-www-form-urlencoded;charset=utf-8",
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default CirculationAPIClient;
|
|
@ -35,7 +35,8 @@ my ( $auth_status ) =
|
|||
check_cookie_auth( $input->cookie('CGISESSID'),
|
||||
{ circulate => 'circulate_remaining_permissions' } );
|
||||
|
||||
if ( $auth_status ne "ok" ) {
|
||||
my $op = $input->param('op') || q{};
|
||||
if ( $auth_status ne "ok" || $op ne "cud-checkin" ) {
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue