diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
index 3ab2ec6592..c3584ea7fe 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
@@ -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("");
-
+ 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("");
+ $("#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;
});
diff --git a/koha-tmpl/intranet-tmpl/prog/js/fetch/api-client.js b/koha-tmpl/intranet-tmpl/prog/js/fetch/api-client.js
index b9b739b72a..d44025cec1 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/fetch/api-client.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/fetch/api-client.js
@@ -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(),
};
diff --git a/koha-tmpl/intranet-tmpl/prog/js/fetch/circulation-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/fetch/circulation-api-client.js
new file mode 100644
index 0000000000..4d1a6dbcd5
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/js/fetch/circulation-api-client.js
@@ -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;
diff --git a/svc/checkin b/svc/checkin
index 1c7c4637e8..9ba087bd4d 100755
--- a/svc/checkin
+++ b/svc/checkin
@@ -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;
}