').html( __("Number of checkouts by item type") ))
.append(ul)
.insertBefore(oSettings.nTableWrapper)
},
}, columns_settings_issues_table);
if ( $("#issues-table").length ) {
$("#issues-table_processing").position({
of: $( "#issues-table" ),
collision: "none"
});
}
}
// Don't load relatives' issues table unless it is clicked on
var relativesIssuesTable;
$("#relatives-issues-tab").click( function() {
if ( ! relativesIssuesTable ) {
relativesIssuesTable = $("#relatives-issues-table").dataTable($.extend(true, {}, dataTablesDefaults, {
"bAutoWidth": false,
"sDom": "rt",
"aaSorting": [],
"aoColumns": [
{
"mDataProp": "date_due",
"bVisible": false,
},
{
"iDataSort": 0, // Sort on hidden unformatted date due column
"mDataProp": function( oObj ) {
var today = new Date();
var due = new Date( oObj.date_due );
if ( today > due ) {
return "" + oObj.date_due_formatted + "";
} else {
return oObj.date_due_formatted;
}
}
},
{
"mDataProp": 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;
},
"sType": "anti-the"
},
{
"mDataProp": function ( oObj ) {
return oObj.recordtype_description.escapeHtml();
}
},
{
"mDataProp": function ( oObj ) {
return oObj.itemtype_description.escapeHtml();
}
},
{
"mDataProp": function ( oObj ) {
return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
}
},
{
"mDataProp": function ( oObj ) {
return ( oObj.location ? oObj.location.escapeHtml() : '' );
}
},
{
"mDataProp": "issuedate",
"bVisible": false,
},
{
"iDataSort": 7, // Sort on hidden unformatted issuedate column
"mDataProp": "issuedate_formatted",
},
{
"mDataProp": function ( oObj ) {
return ( oObj.branchname ? oObj.branchname.escapeHtml() : '' );
}
},
{
"mDataProp": function ( oObj ) {
return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
}
},
{
"mDataProp": function ( oObj ) {
return ( oObj.copynumber ? oObj.copynumber.escapeHtml() : '' );
}
},
{
"mDataProp": function ( oObj ) {
if ( ! oObj.charge ) oObj.charge = 0;
return parseFloat(oObj.charge).toFixed(2);
}
},
{
"mDataProp": function ( oObj ) {
if ( ! oObj.fine ) oObj.fine = 0;
return parseFloat(oObj.fine).toFixed(2);
}
},
{
"mDataProp": function ( oObj ) {
if ( ! oObj.price ) oObj.price = 0;
return parseFloat(oObj.price).toFixed(2);
}
},
{
"mDataProp": function( oObj ) {
return ""
+ ( oObj.borrower.firstname ? oObj.borrower.firstname.escapeHtml() : "" )
+ " " +
( oObj.borrower.surname ? oObj.borrower.surname.escapeHtml() : "" )
+ " (" + ( oObj.borrower.cardnumber ? oObj.borrower.cardnumber.escapeHtml() : "" ) + ")"
}
},
],
"bPaginate": false,
"bProcessing": true,
"bServerSide": 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)
} );
},
}));
}
});
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);
}
// Handle return claims
$(document).on("click", '.claim-returned-btn', function(e){
e.preventDefault();
itemnumber = $(this).data('itemnumber');
$('#claims-returned-itemnumber').val(itemnumber);
$('#claims-returned-notes').val("");
$('#claims-returned-charge-lost-fee').attr('checked', false)
$('#claims-returned-modal').modal()
});
$(document).on("click", '#claims-returned-modal-btn-submit', function(e){
let itemnumber = $('#claims-returned-itemnumber').val();
let notes = $('#claims-returned-notes').val();
let fee = $('#claims-returned-charge-lost-fee').attr('checked') ? true : false;
$('#claims-returned-modal').modal('hide')
$('.claim-returned-btn[data-itemnumber="' + itemnumber + '"]').replaceWith('';
$(id).parent().parent().addClass('ok');
} else {
content = __("Unable to claim as returned");
$(id).parent().parent().addClass('warn');
}
$(id).replaceWith( content );
refreshReturnClaimsTable();
issuesTable.api().ajax.reload();
}, "json")
});
// Don't load return claims table unless it is clicked on
var returnClaimsTable;
$("#return-claims-tab").click( function() {
refreshReturnClaimsTable();
});
function refreshReturnClaimsTable(){
loadReturnClaimsTable();
$("#return-claims-table").DataTable().ajax.reload();
}
function loadReturnClaimsTable() {
if ( ! returnClaimsTable ) {
returnClaimsTable = $("#return-claims-table").dataTable({
"bAutoWidth": false,
"sDom": "rt",
"aaSorting": [],
"aoColumns": [
{
"mDataProp": "id",
"bVisible": false,
},
{
"mDataProp": 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;
}
},
{
"sClass": "return-claim-notes-td",
"mDataProp": function ( oObj ) {
return '' + oObj.notes + ''
+ '';
}
},
{
"mDataProp": function ( oObj ) {
let created_on = new Date( oObj.created_on );
return created_on.toLocaleDateString();
}
},
{
"mDataProp": function ( oObj ) {
if ( oObj.updated_on ) {
let updated_on = new Date( oObj.updated_on );
return updated_on.toLocaleDateString();
} else {
return "";
}
}
},
{
"mDataProp": 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;
}
},
{
"mDataProp": function ( oObj ) {
let delete_html = oObj.resolved_on
? ' ' + __("Delete") + ''
: "";
let resolve_html = ! oObj.resolution
? ' ' + __("Resolve") + ''
: "";
return ''
+ ' '
+ ' '
+ '
';
}
},
],
"bPaginate": false,
"bProcessing": true,
"bServerSide": 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)
} );
},
});
}
}
$('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();
}
});
}
});
// Handle return claim resolution
$('body').on('click', '.return-claim-tools-resolve', function() {
let id = $(this).data('return-claim-id');
let current_lost_status = $(this).data('current-lost-status');
$('#claims-returned-resolved-modal-id').val(id);
$("#new_lost_status").val(current_lost_status);
let selected_option = $("#new_lost_status option:selected");
$(selected_option).text(_("%s (current status)").format($(selected_option).text()));
$('#claims-returned-resolved-modal').modal()
});
$(document).on('click', '#claims-returned-resolved-modal-btn-submit', function(e) {
let resolution = $('#claims-returned-resolved-modal-resolved-code').val();
let new_lost_status = $('#new_lost_status').val();
let id = $('#claims-returned-resolved-modal-id').val();
$('#claims-returned-resolved-modal-btn-submit-spinner').show();
$('#claims-returned-resolved-modal-btn-submit-icon').hide();
params = {
resolution: resolution,
resolved_by: logged_in_user_borrowernumber,
new_lost_status: new_lost_status
};
$.ajax({
url: '/api/v1/return_claims/' + id + '/resolve',
type: 'PUT',
data: JSON.stringify(params),
success: function( data ) {
$('#claims-returned-resolved-modal-btn-submit-spinner').hide();
$('#claims-returned-resolved-modal-btn-submit-icon').show();
$('#claims-returned-resolved-modal').modal('hide')
refreshReturnClaimsTable();
},
contentType: "json"
});
});
});