').html( __("Number of checkouts by item type") ))
.append(ul)
.insertBefore(oSettings.nTableWrapper)
},
}, table_settings_issues_table);
if ( $("#issues-table").length ) {
$("#issues-table_processing").position({
of: $( "#issues-table" ),
collision: "none"
});
}
}
var loadIssuesTableDelayTimeoutId;
var barcodefield = $("#barcode");
$('#issues-table-load-now-button').click(function(){
if ( loadIssuesTableDelayTimeoutId ) clearTimeout(loadIssuesTableDelayTimeoutId);
LoadIssuesTable();
barcodefield.focus();
return false;
});
$(document).ready(function() {
var onHoldDueDateSet = false;
var onHoldChecked = function() {
var isChecked = false;
$('input[data-on-reserve]').each(function() {
if ($(this).is(':checked')) {
isChecked=true;
}
});
return isChecked;
};
var showHideOnHoldRenewal = function() {
// Display the date input
if (onHoldChecked()) {
$('#newonholdduedate').show()
} else {
$('#newonholdduedate').hide();
}
};
// Handle the select all/none links for checkouts table columns
$("#CheckAllRenewals").on("click",function(){
$("#UncheckAllCheckins").click();
$(".renew:visible").prop("checked", true);
CheckRenewCheckinBoxes();
showHideOnHoldRenewal();
return false;
});
$("#UncheckAllRenewals").on("click",function(){
$(".renew:visible").prop("checked", false);
CheckRenewCheckinBoxes();
showHideOnHoldRenewal();
return false;
});
$("#CheckAllCheckins").on("click",function(){
$("#UncheckAllRenewals").click();
$(".checkin:visible").prop("checked", true);
CheckRenewCheckinBoxes();
return false;
});
$("#UncheckAllCheckins").on("click",function(){
$(".checkin:visible").prop("checked", false);
CheckRenewCheckinBoxes();
return false;
});
$("#newduedate").on("change", function() {
if (!onHoldDueDateSet) {
$('#newonholdduedate input').val($('#newduedate').val());
}
});
$("#newonholdduedate").on("change", function() {
onHoldDueDateSet = true;
});
// Don't allow both return and renew checkboxes to be checked
$(document).on("change", '.renew', function(){
if ( $(this).is(":checked") ) {
$( "#checkin_" + $(this).val() ).prop("checked", false);
}
CheckRenewCheckinBoxes();
});
$(document).on("change", '.checkin', function(){
if ( $(this).is(":checked") ) {
$( "#renew_" + $(this).val() ).prop("checked", false);
}
CheckRenewCheckinBoxes();
});
// Display on hold due dates input when an on hold item is
// selected
$(document).on('change', '.renew', function(){
showHideOnHoldRenewal();
});
$("#output_format > option:first-child").attr("selected", "selected");
$("select[name='csv_profile_id']").hide();
$(document).on("change", '#issues-table-output-format', function(){
if ( $(this).val() == 'csv' ) {
$("select[name='csv_profile_id']").show();
} else {
$("select[name='csv_profile_id']").hide();
}
});
// Clicking the table cell checks the checkbox inside it
$(document).on("click", 'td', function(e){
if(e.target.tagName.toLowerCase() == 'td'){
$(this).find("input:checkbox:visible").each( function() {
$(this).click();
});
}
});
// Handle renewals and returns
$("#CheckinChecked").on("click",function(e){
e.preventDefault();
let refresh_table = true;
function checkin(item_id){
params = {
item_id,
patron_id: borrowernumber,
library_id: branchcode,
exempt_fine: $("#exemptfine").is(':checked')
};
const client = APIClient.circulation;
return client.checkins.create(params).then(
success => {
id = "#checkin_" + item_id;
content = "";
if ( success.returned ) {
content = __("Checked in");
$(id).parent().parent().addClass('ok');
$('#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");
$(id).parent().parent().addClass('warn');
refresh_table = false;
}
$(id).parent().empty().append(content);
},
error => {
console.warn("Something wrong happened: %s".format(error));
}
)
}
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();
}
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 );
});
CheckRenewCheckinBoxes();
// Prevent form submit
return false;
});
$("#RenewChecked").on("click",function(e){
e.preventDefault();
let refresh_table = true;
function renew(item_id){
var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
$(this).parent().parent().replaceWith("");
var params = {
item_id,
patron_id: borrowernumber,
library_id: branchcode,
override_limit: override_limit
};
if (UnseenRenewals) {
var ren = $("#renew_as_unseen_checkbox");
var renew_unseen = ren.length > 0 && ren.is(':checked') ? 1 : 0;
params.seen = renew_unseen === 1 ? 0 : 1;
}
var dueDate = $("#newduedate").val();
if (dueDate && dueDate.length > 0) {
params.date_due = dueDate
}
const client = APIClient.circulation;
return client.checkouts.renew(params).then(
success => {
var id = "#renew_" + success.itemnumber;
var content = "";
if ( success.renew_okay ) {
content = __("Renewed, due:") + " " + success.date_due;
$('#date_due_' + success.itemnumber).replaceWith( success.date_due );
} else {
content = __("Renew failed:") + " ";
if ( success.error == "no_checkout" ) {
content += __("not checked out");
} else if ( success.error == "too_many" ) {
content += __("too many renewals");
} else if ( success.error == "too_unseen" ) {
content += __("too many consecutive renewals without being seen by the library");
} else if ( success.error == "on_reserve" ) {
content += __("on hold");
} else if ( success.error == "restriction" ) {
content += __("Not allowed: patron restricted");
} else if ( success.error == "overdue" ) {
content += __("Not allowed: overdue");
} else if ( success.error == 'no_open_days' ) {
content += __('Unable to find an open day');
} else if ( success.error ) {
content += success.error;
} else {
content += __("reason unknown");
}
refresh_table = false;
}
$(id).replaceWith( content );
},
error => {
console.warn("Something wrong happened: %s".format(error));
}
);
}
function renew_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) => {
$("#renew_"+id).parent().append("");
$("#renew_"+id).hide();
});
return next();
}
let item_ids = $(".renew:checked:visible").map((i, c) => c.value);
renew_all(item_ids, renew).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;
});
$("#RenewAll").on("click",function(){
$("#CheckAllRenewals").click();
$("#UncheckAllCheckins").click();
showHideOnHoldRenewal();
$("#RenewChecked").click();
$('#RenewChecked').prop('disabled' , true );
// Prevent form submit
return false;
});
var ymd = flatpickr.formatDate(new Date(), "Y-m-d");
$('#issues-table-load-immediately').change(function(){
if ( this.checked && typeof issuesTable === 'undefined') {
$('#issues-table-load-now-button').click();
}
barcodefield.focus();
});
if ( Cookies.get("issues-table-load-immediately-" + script) == "true" ) {
if ( LoadCheckoutsTableDelay ) {
loadIssuesTableDelayTimeoutId = setTimeout( function(){ LoadIssuesTable() }, LoadCheckoutsTableDelay * 1000);
} else {
LoadIssuesTable();
}
$('#issues-table-load-immediately').prop('checked', true);
} else {
$('#issues-table-load-delay').hide();
}
$('#issues-table-load-immediately').on( "change", function(){
Cookies.set("issues-table-load-immediately-" + script, $(this).is(':checked'), { expires: 365, sameSite: 'Lax' });
});
// Don't load relatives' issues table unless it is clicked on
var relativesIssuesTable;
$("#relatives-issues-tab").click( function() {
if ( ! relativesIssuesTable ) {
relativesIssuesTable = KohaTable("relatives-issues-table", {
"autoWidth": false,
"dom": '<"table_controls"B>rt',
"order": [],
"columns": [
{
"data": "date_due",
"visible": false,
},
{
"orderData": 0, // Sort on hidden unformatted date due column
"data": function( oObj ) {
var today = new Date();
var due = new Date( oObj.date_due );
let date_due_formatted = $datetime(oObj.date_due, { as_due_date: true, no_tz_adjust: true });
if ( today > due ) {
return "" + date_due_formatted + "";
} else {
return date_due_formatted;
}
}
},
{
"data": function ( oObj ) {
let title = ""
+ (oObj.title ? oObj.title.escapeHtml() : '' );
$.each(oObj.subtitle, function( index, value ) {
title += " " + value.escapeHtml();
});
title += " " + oObj.part_number + " " + oObj.part_name;
if ( oObj.enumchron ) {
title += " (" + oObj.enumchron.escapeHtml() + ")";
}
title += "";
if ( oObj.author ) {
title += " " + __("by _AUTHOR_").replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
}
if ( oObj.itemnotes ) {
var span_class = "";
if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
span_class = "circ-hlt";
}
title += " - " + oObj.itemnotes.escapeHtml() + ""
}
if ( oObj.itemnotes_nonpublic ) {
var span_class = "";
if ( flatpickr.formatDate( new Date(oObj.issuedate), "Y-m-d" ) == ymd ){
span_class = "circ-hlt";
}
title += " - " + oObj.itemnotes_nonpublic.escapeHtml() + ""
}
var onsite_checkout = '';
if ( oObj.onsite_checkout == 1 ) {
onsite_checkout += " (" + __("On-site checkout") + ")";
}
title += " "
+ ""
+ (oObj.barcode ? oObj.barcode.escapeHtml() : "")
+ ""
+ onsite_checkout;
return title;
},
"type": "anti-the"
},
{
"data": function ( oObj ) {
return oObj.recordtype_description.escapeHtml();
}
},
{
"data": function ( oObj ) {
return oObj.itemtype_description.escapeHtml();
}
},
{
"data": function ( oObj ) {
return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
}
},
{
"data": function ( oObj ) {
return ( oObj.location ? oObj.location.escapeHtml() : '' );
}
},
{
"data": "issuedate",
"visible": false,
},
{
"orderData": 7, // Sort on hidden unformatted issuedate column
"data": function ( oObj ) {
return $datetime(oObj.issuedate, { no_tz_adjust: true });
}
},
{
"data": function ( oObj ) {
return ( oObj.branchname ? oObj.branchname.escapeHtml() : '' );
}
},
{
"data": function ( oObj ) {
return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
}
},
{
"data": function ( oObj ) {
return ( oObj.copynumber ? oObj.copynumber.escapeHtml() : '' );
}
},
{
"data": function ( oObj ) {
if ( ! oObj.charge ) oObj.charge = 0;
return parseFloat(oObj.charge).toFixed(2);
}
},
{
"data": function ( oObj ) {
if ( ! oObj.fine ) oObj.fine = 0;
return parseFloat(oObj.fine).toFixed(2);
}
},
{
"data": function ( oObj ) {
if ( ! oObj.price ) oObj.price = 0;
return parseFloat(oObj.price).toFixed(2);
}
},
{
"data": function( oObj ) {
return ""
+ ( oObj.borrower.firstname ? oObj.borrower.firstname.escapeHtml() : "" )
+ " " +
( oObj.borrower.surname ? oObj.borrower.surname.escapeHtml() : "" )
+ " (" + ( oObj.borrower.cardnumber ? oObj.borrower.cardnumber.escapeHtml() : "" ) + ")"
}
},
],
"paging": false,
"processing": true,
"serverSide": false,
"sAjaxSource": '/cgi-bin/koha/svc/checkouts',
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.each(relatives_borrowernumbers, function( index, value ) {
aoData.push( { "name": "borrowernumber", "value": value } );
});
$.getJSON( sSource, aoData, function (json) {
fnCallback(json)
} );
},
}, table_settings_relatives_issues_table);
}
});
if ( $("#relatives-issues-table").length ) {
$("#relatives-issues-table_processing").position({
of: $( "#relatives-issues-table" ),
collision: "none"
});
}
if ( AllowRenewalLimitOverride || AllowRenewalOnHoldOverride ) {
$( '#override_limit' ).click( function () {
if ( this.checked ) {
if ( AllowRenewalLimitOverride ) {
$( '.renewals-allowed' ).show();
$( '.renewals-disabled' ).hide();
}
if ( AllowRenewalOnHoldOverride ) {
$( '.renewals-allowed-on_reserve' ).show();
}
} else {
$( '.renewals-allowed' ).hide();
$( '.renewals-allowed-on_reserve' ).hide();
$( '.renewals-disabled' ).show();
}
} ).prop('checked', false);
}
// Refresh after return claim
$('body').on('refreshClaimModal', function () {
refreshReturnClaimsTable();
issuesTable.api().ajax.reload();
});
// Don't load return claims table unless its tab is shown
var returnClaimsTable;
$("#return-claims-tab").on('shown.bs.tab', function() {
refreshReturnClaimsTable();
});
function refreshReturnClaimsTable(){
const table = $('#return-claims-table');
if ($.fn.dataTable.isDataTable(table)) {
table.DataTable().ajax.reload();
} else {
loadReturnClaimsTable();
}
}
function loadReturnClaimsTable() {
if ( ! returnClaimsTable ) {
returnClaimsTable = $("#return-claims-table").dataTable({
"autoWidth": false,
"dom": "rt",
"order": [],
"columnDefs": [
{ "orderable": false, "searchable": false, "targets": ['NoSort'] },
{ "type": "anti-the", "targets": ["anti-the"] },
],
"columns": [
{
"data": "id",
"visible": false,
},
{
"data": function (oObj) {
if (oObj.resolution) {
return "is_resolved";
} else {
return "is_unresolved";
}
},
"visible": false,
},
{
"data": function ( oObj ) {
let title = ''
+ oObj.title
+ ( oObj.subtitle ? " " + oObj.subtitle : "" )
+ ( oObj.enumchron || "" )
+ '';
if ( oObj.author ) {
title += ' by ' + oObj.author;
}
title += ' '
+ (oObj.barcode ? oObj.barcode.escapeHtml() : "")
+ '';
return title;
}
},
{
"className": "return-claim-notes-td",
"data": function ( oObj ) {
let notes = '';
if ( oObj.notes ) {
notes += oObj.notes;
}
notes += '';
notes += '';
return notes;
}
},
{
"data": "created_on",
"visible": false,
},
{
"orderData": 4,
"data": function ( oObj ) {
if ( oObj.created_on ) {
return $date(oObj.created_on, { no_tz_adjust: true });;
} else {
return "";
}
}
},
{
"data": "updated_on",
"visible": false,
},
{
"orderData": 6,
"data": function ( oObj ) {
if ( oObj.updated_on ) {
return $date(oObj.updated_on, { no_tz_adjust: true });
} else {
return "";
}
}
},
{
"data": function ( oObj ) {
if ( ! oObj.resolution ) return "";
let desc = '' + oObj.resolution_data.lib + ' (';
if (oObj.resolved_by_data) desc += '' + ( oObj.resolved_by_data.firstname || "" ) + " " + ( oObj.resolved_by_data.surname || "" ) + '';
desc += ', ' + oObj.resolved_on + ')';
return desc;
}
},
{
"data": function ( oObj ) {
let delete_html = oObj.resolved_on
? ' ' + __("Delete") + ''
: "";
let resolve_html = ! oObj.resolution
? ' ' + __("Resolve") + ''
: "";
return ''
+ ' '
+ ' '
+ '
';
}
},
],
"paging": false,
"processing": true,
"serverSide": false,
"sAjaxSource": '/cgi-bin/koha/svc/return_claims',
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
$.getJSON( sSource, aoData, function (json) {
let resolved = json.resolved;
let unresolved = json.unresolved;
if ( resolved > 0 ) {
$('#return-claims-count-resolved').text(resolved)
.removeClass('label-default')
.addClass('label-success');
} else {
$('#return-claims-count-resolved').text(resolved)
.removeClass('label-success')
.addClass('label-default');
}
if ( unresolved > 0 ) {
$('#return-claims-count-unresolved').text(unresolved)
.removeClass('label-default')
.addClass('label-warning');
} else {
$('#return-claims-count-unresolved').text(unresolved)
.removeClass('label-warning')
.addClass('label-default');
}
fnCallback(json)
} );
},
"search": { "search": "is_unresolved" },
"footerCallback": function (row, data, start, end, display) {
var api = this.api();
// Total over all pages
var colData = api.column(1).data();
var is_unresolved = 0;
var is_resolved = 0;
colData.each(function( index, value ){
if( index == "is_unresolved" ){ is_unresolved++; }
if (index == "is_resolved") { is_resolved++; }
});
// Update footer
$("#return-claims-controls").html( showClaimFilter( is_unresolved, is_resolved ) )
}
});
}
}
function showClaimFilter( is_unresolved, is_resolved ){
var showAll, showUnresolved;
var total = Number( is_unresolved ) + Number( is_resolved );
if( total > 0 ){
showAll = __nx("Show 1 claim", "Show all {count} claims", total, { count: total });
} else {
showAll = "";
}
if( is_unresolved > 0 ){
showUnresolved = __nx("Show 1 unresolved claim", "Show {count} unresolved claims", is_unresolved, { count: is_unresolved })
} else {
showUnresolved = "";
}
$("#show_all_claims").html( showAll );
$("#show_unresolved_claims").html( showUnresolved );
}
$('body').on('click', '.return-claim-tools-editnotes', function() {
let id = $(this).data('return-claim-id');
$('#return-claim-notes-static-' + id).parent().dblclick();
});
$('body').on('dblclick', '.return-claim-notes-td', function() {
let elt = $(this).children('.return-claim-notes');
let id = elt.data('return-claim-id');
if ( $('#return-claim-notes-editor-textarea-' + id).length == 0 ) {
let note = elt.text();
let editor =
' '
+ ' '
+ '
'
+ ' ' + __("Update") + ''
+ ' ' + __("Cancel") + ''
+ '';
elt.hide();
$(editor).insertAfter( elt );
}
});
$('body').on('click', '.claim-returned-notes-editor-submit', function(){
let id = $(this).data('return-claim-id');
let notes = $('#return-claim-notes-editor-textarea-' + id).val();
let params = {
notes: notes,
updated_by: logged_in_user_borrowernumber
};
$(this).parent().remove();
$.ajax({
url: '/api/v1/return_claims/' + id + '/notes',
type: 'PUT',
data: JSON.stringify(params),
success: function( data ) {
let notes = $('#return-claim-notes-static-' + id);
notes.text(data.notes);
notes.show();
},
contentType: "json"
});
});
$('body').on('click', '.claim-returned-notes-editor-cancel', function(){
let id = $(this).data('return-claim-id');
$(this).parent().remove();
$('#return-claim-notes-static-' + id).show();
});
// Hanld return claim deletion
$('body').on('click', '.return-claim-tools-delete', function() {
let confirmed = confirm(__("Are you sure you want to delete this return claim?"));
if ( confirmed ) {
let id = $(this).data('return-claim-id');
$.ajax({
url: '/api/v1/return_claims/' + id,
type: 'DELETE',
success: function( data ) {
refreshReturnClaimsTable();
issuesTable.api().ajax.reload();
}
});
}
});
$("#show_all_claims").on("click", function(e){
e.preventDefault();
$(".ctrl_link").removeClass("disabled");
$(this).addClass("disabled");
$("#return-claims-table").DataTable().search("").draw();
});
$("#show_unresolved_claims").on("click", function (e) {
e.preventDefault();
$(".ctrl_link").removeClass("disabled");
$(this).addClass("disabled");
$("#return-claims-table").DataTable().search("is_unresolved").draw();
});
});