1 $(document).ready(function() {
2 $.ajaxSetup ({ cache: false });
4 var barcodefield = $("#barcode");
6 // Handle the select all/none links for checkouts table columns
7 $("#CheckAllRenewals").on("click",function(){
8 $("#UncheckAllCheckins").click();
9 $(".renew:visible").prop("checked", true);
12 $("#UncheckAllRenewals").on("click",function(){
13 $(".renew:visible").prop("checked", false);
17 $("#CheckAllCheckins").on("click",function(){
18 $("#UncheckAllRenewals").click();
19 $(".checkin:visible").prop("checked", true);
22 $("#UncheckAllCheckins").on("click",function(){
23 $(".checkin:visible").prop("checked", false);
27 // Don't allow both return and renew checkboxes to be checked
28 $(document).on("change", '.renew', function(){
29 if ( $(this).is(":checked") ) {
30 $( "#checkin_" + $(this).val() ).prop("checked", false);
33 $(document).on("change", '.checkin', function(){
34 if ( $(this).is(":checked") ) {
35 $( "#renew_" + $(this).val() ).prop("checked", false);
39 $("#output_format > option:first-child").attr("selected", "selected");
40 $("select[name='csv_profile_id']").hide();
41 $(document).on("change", '#issues-table-output-format', function(){
42 if ( $(this).val() == 'csv' ) {
43 $("select[name='csv_profile_id']").show();
45 $("select[name='csv_profile_id']").hide();
49 // Clicking the table cell checks the checkbox inside it
50 $(document).on("click", 'td', function(e){
51 if(e.target.tagName.toLowerCase() == 'td'){
52 $(this).find("input:checkbox:visible").each( function() {
58 // Handle renewals and returns
59 $("#RenewCheckinChecked").on("click",function(){
60 $(".checkin:checked:visible").each(function() {
61 itemnumber = $(this).val();
63 $(this).replaceWith("<img id='checkin_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
66 itemnumber: itemnumber,
67 borrowernumber: borrowernumber,
68 branchcode: branchcode,
69 exempt_fine: $("#exemptfine").is(':checked')
72 $.post( "/cgi-bin/koha/svc/checkin", params, function( data ) {
73 id = "#checkin_" + data.itemnumber;
76 if ( data.returned ) {
77 content = CIRCULATION_RETURNED;
78 $(id).parent().parent().addClass('ok');
79 $('#date_due_' + data.itemnumber).html(CIRCULATION_RETURNED);
81 content = CIRCULATION_NOT_RETURNED;
82 $(id).parent().parent().addClass('warn');
85 $(id).replaceWith( content );
89 $(".renew:checked:visible").each(function() {
90 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
92 var itemnumber = $(this).val();
94 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
97 itemnumber: itemnumber,
98 borrowernumber: borrowernumber,
99 branchcode: branchcode,
100 override_limit: override_limit,
101 date_due: $("#newduedate").val()
104 $.post( "/cgi-bin/koha/svc/renew", params, function( data ) {
105 var id = "#renew_" + data.itemnumber;
108 if ( data.renew_okay ) {
109 content = CIRCULATION_RENEWED_DUE + " " + data.date_due;
110 $('#date_due_' + data.itemnumber).replaceWith( data.date_due );
112 content = CIRCULATION_RENEW_FAILED + " ";
113 if ( data.error == "no_checkout" ) {
114 content += NOT_CHECKED_OUT;
115 } else if ( data.error == "too_many" ) {
116 content += TOO_MANY_RENEWALS;
117 } else if ( data.error == "on_reserve" ) {
118 content += ON_RESERVE;
119 } else if ( data.error == "restriction" ) {
120 content += NOT_RENEWABLE_RESTRICTION;
121 } else if ( data.error == "overdue" ) {
122 content += NOT_RENEWABLE_OVERDUE;
123 } else if ( data.error ) {
124 content += data.error;
126 content += REASON_UNKNOWN;
130 $(id).replaceWith( content );
134 // Refocus on barcode field if it exists
135 if ( $("#barcode").length ) {
136 $("#barcode").focus();
139 // Prevent form submit
143 $("#RenewAll").on("click",function(){
144 $("#CheckAllRenewals").click();
145 $("#UncheckAllCheckins").click();
146 $("#RenewCheckinChecked").click();
148 // Prevent form submit
152 var ymd = $.datepicker.formatDate('yy-mm-dd', new Date());
154 $('#issues-table').hide();
155 $('#issues-table-actions').hide();
156 $('#issues-table-load-immediately').change(function(){
157 if ( this.checked && typeof issuesTable === 'undefined') {
158 $('#issues-table-load-now-button').click();
160 barcodefield.focus();
162 $('#issues-table-load-now-button').click(function(){
164 barcodefield.focus();
168 if ( $.cookie("issues-table-load-immediately-" + script) == "true" ) {
170 $('#issues-table-load-immediately').prop('checked', true);
172 $('#issues-table-load-immediately').on( "change", function(){
173 $.cookie("issues-table-load-immediately-" + script, $(this).is(':checked'), { expires: 365 });
176 function LoadIssuesTable() {
177 $('#issues-table-loading-message').hide();
178 $('#issues-table').show();
179 $('#issues-table-actions').show();
181 issuesTable = KohaTable("#issues-table", {
183 "sEmptyTable" : MSG_DT_LOADING_RECORDS,
184 "sProcessing": MSG_DT_LOADING_RECORDS,
187 "dom": 'B<"clearfix">rt',
190 "mDataProp": function( oObj ) {
191 return oObj.sort_order;
195 "mDataProp": function( oObj ) {
196 if ( oObj.issued_today ) {
197 return "<strong>" + TODAYS_CHECKOUTS + "</strong>";
199 return "<strong>" + PREVIOUS_CHECKOUTS + "</strong>";
204 "mDataProp": "date_due",
208 "iDataSort": 2, // Sort on hidden unformatted date due column
209 "mDataProp": function( oObj ) {
210 var due = oObj.date_due_formatted;
212 if ( oObj.date_due_overdue ) {
213 due = "<span class='overdue'>" + due + "</span>";
216 due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
219 due += "<span class='lost'>" + oObj.lost + "</span>";
222 if ( oObj.damaged ) {
223 due += "<span class='dmg'>" + oObj.damaged + "</span>";
231 "mDataProp": function ( oObj ) {
232 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
237 $.each(oObj.subtitle, function( index, value ) {
238 title += " " + value.subfield;
241 if ( oObj.enumchron ) {
242 title += " (" + oObj.enumchron + ")";
245 title += "</a></span>";
248 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
251 if ( oObj.itemnotes ) {
252 var span_class = "text-muted";
253 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
256 if ( oObj.itemnotes_nonpublic ) {
257 var span_class = "text-danger";
258 title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic + "</span>"
261 var onsite_checkout = '';
262 if ( oObj.onsite_checkout == 1 ) {
263 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
267 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
282 { "mDataProp": "itemtype_description" },
283 { "mDataProp": "location" },
284 { "mDataProp": "homebranch" },
285 { "mDataProp": "issuedate_formatted" },
286 { "mDataProp": "branchname" },
287 { "mDataProp": "itemcallnumber" },
289 "mDataProp": function ( oObj ) {
290 if ( ! oObj.charge ) oObj.charge = 0;
291 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.charge).toFixed(2) + '<span>';
295 "mDataProp": function ( oObj ) {
296 if ( ! oObj.fine ) oObj.fine = 0;
297 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.fine).toFixed(2) + '<span>';
301 "mDataProp": function ( oObj ) {
302 if ( ! oObj.price ) oObj.price = 0;
303 return '<span style="text-align: right; display: block;">' + parseFloat(oObj.price).toFixed(2) + '<span>';
308 "bVisible": AllowCirculate ? true : false,
309 "mDataProp": function ( oObj ) {
315 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
317 if ( oObj.can_renew ) {
319 } else if ( oObj.can_renew_error == "on_reserve" ) {
320 content += "<span class='renewals-disabled-no-override'>"
321 + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
324 span_style = "display: none";
325 span_class = "renewals-allowed";
326 } else if ( oObj.can_renew_error == "too_many" ) {
327 content += "<span class='renewals-disabled'>"
331 span_style = "display: none";
332 span_class = "renewals-allowed";
333 } else if ( oObj.can_renew_error == "restriction" ) {
334 content += "<span class='renewals-disabled'>"
335 + NOT_RENEWABLE_RESTRICTION
338 span_style = "display: none";
339 span_class = "renewals-allowed";
340 } else if ( oObj.can_renew_error == "overdue" ) {
341 content += "<span class='renewals-disabled'>"
342 + NOT_RENEWABLE_OVERDUE
345 span_style = "display: none";
346 span_class = "renewals-allowed";
347 } else if ( oObj.can_renew_error == "too_soon" ) {
348 content += "<span class='renewals-disabled'>"
349 + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
352 span_style = "display: none";
353 span_class = "renewals-allowed";
354 } else if ( oObj.can_renew_error == "auto_too_soon" ) {
355 content += "<span class='renewals-disabled'>"
356 + NOT_RENEWABLE_AUTO_TOO_SOON
359 span_style = "display: none";
360 span_class = "renewals-allowed";
361 } else if ( oObj.can_renew_error == "auto_too_late" ) {
362 content += "<span class='renewals-disabled'>"
363 + NOT_RENEWABLE_AUTO_TOO_LATE
366 span_style = "display: none";
367 span_class = "renewals-allowed";
368 } else if ( oObj.can_renew_error == "auto_renew" ) {
369 content += "<span class='renewals-disabled'>"
370 + NOT_RENEWABLE_AUTO_RENEW
373 span_style = "display: none";
374 span_class = "renewals-allowed";
375 } else if ( oObj.can_renew_error == "onsite_checkout" ) {
376 // Don't display something if it's an onsite checkout
378 content += "<span class='renewals-disabled'>"
379 + oObj.can_renew_error
382 span_style = "display: none";
383 span_class = "renewals-allowed";
386 var can_force_renew = ( oObj.onsite_checkout == 0 ) && ( oObj.can_renew_error != "on_reserve" );
387 var can_renew = ( oObj.renewals_remaining > 0 && !oObj.can_renew_error );
388 if ( can_renew || can_force_renew ) {
389 content += "<span class='" + span_class + "' style='" + span_style + "'>"
390 + "<input type='checkbox' ";
391 if ( oObj.date_due_overdue && can_renew ) {
392 content += "checked='checked' ";
394 content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
397 content += "<span class='renewals'>("
398 + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
402 content += "</span>";
409 "bVisible": AllowCirculate ? true : false,
410 "mDataProp": function ( oObj ) {
411 if ( oObj.can_renew_error == "on_reserve" ) {
412 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
414 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
419 "bVisible": exports_enabled ? true : false,
421 "mDataProp": function ( oObj ) {
422 var s = "<input type='checkbox' name='itemnumbers' value='" + oObj.itemnumber + "' style='visibility:hidden;' />";
424 s += "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
429 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
430 var total_charge = 0;
433 for ( var i=0; i < aaData.length; i++ ) {
434 total_charge += aaData[i]['charge'] * 1;
435 total_fine += aaData[i]['fine'] * 1;
436 total_price += aaData[i]['price'] * 1;
438 $("#totaldue").html(total_charge.toFixed(2));
439 $("#totalfine").html(total_fine.toFixed(2));
440 $("#totalprice").html(total_price.toFixed(2));
444 "bServerSide": false,
445 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
446 "fnServerData": function ( sSource, aoData, fnCallback ) {
447 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
449 $.getJSON( sSource, aoData, function (json) {
453 "fnInitComplete": function(oSettings) {
454 // Disable rowGrouping plugin after first use
455 // so any sorting on the table doesn't use it
456 var oSettings = issuesTable.fnSettings();
458 for (f = 0; f < oSettings.aoDrawCallback.length; f++) {
459 if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') {
460 oSettings.aoDrawCallback.splice(f, 1);
465 oSettings.aaSortingFixed = null;
467 }, columns_settings).rowGrouping(
469 iGroupingColumnIndex: 1,
470 iGroupingOrderByColumnIndex: 0,
471 sGroupingColumnSortDirection: "asc"
475 if ( $("#issues-table").length ) {
476 $("#issues-table_processing").position({
477 of: $( "#issues-table" ),
483 // Don't load relatives' issues table unless it is clicked on
484 var relativesIssuesTable;
485 $("#relatives-issues-tab").click( function() {
486 if ( ! relativesIssuesTable ) {
487 relativesIssuesTable = $("#relatives-issues-table").dataTable({
493 "mDataProp": "date_due",
497 "iDataSort": 1, // Sort on hidden unformatted date due column
498 "mDataProp": function( oObj ) {
499 var today = new Date();
500 var due = new Date( oObj.date_due );
502 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
504 return oObj.date_due_formatted;
509 "mDataProp": function ( oObj ) {
510 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
515 $.each(oObj.subtitle, function( index, value ) {
516 title += " " + value.subfield;
519 if ( oObj.enumchron ) {
520 title += " (" + oObj.enumchron + ")";
523 title += "</a></span>";
526 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
529 if ( oObj.itemnotes ) {
531 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
532 span_class = "circ-hlt";
534 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
537 if ( oObj.itemnotes_nonpublic ) {
539 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
540 span_class = "circ-hlt";
542 title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic + "</span>"
545 var onsite_checkout = '';
546 if ( oObj.onsite_checkout == 1 ) {
547 onsite_checkout += " <span class='onsite_checkout'>(" + INHOUSE_USE + ")</span>";
551 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
566 { "mDataProp": "itemtype" },
567 { "mDataProp": "location" },
568 { "mDataProp": "issuedate_formatted" },
569 { "mDataProp": "branchname" },
570 { "mDataProp": "itemcallnumber" },
572 "mDataProp": function ( oObj ) {
573 if ( ! oObj.charge ) oObj.charge = 0;
574 return parseFloat(oObj.charge).toFixed(2);
578 "mDataProp": function ( oObj ) {
579 if ( ! oObj.fine ) oObj.fine = 0;
580 return parseFloat(oObj.fine).toFixed(2);
584 "mDataProp": function ( oObj ) {
585 if ( ! oObj.price ) oObj.price = 0;
586 return parseFloat(oObj.price).toFixed(2);
590 "mDataProp": function( oObj ) {
591 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
592 + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")</a>"
598 "bServerSide": false,
599 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
600 "fnServerData": function ( sSource, aoData, fnCallback ) {
601 $.each(relatives_borrowernumbers, function( index, value ) {
602 aoData.push( { "name": "borrowernumber", "value": value } );
605 $.getJSON( sSource, aoData, function (json) {
613 if ( $("#relatives-issues-table").length ) {
614 $("#relatives-issues-table_processing").position({
615 of: $( "#relatives-issues-table" ),
620 if ( AllowRenewalLimitOverride ) {
621 $( '#override_limit' ).click( function () {
622 if ( this.checked ) {
623 $( '.renewals-allowed' ).show(); $( '.renewals-disabled' ).hide();
625 $( '.renewals-allowed' ).hide(); $( '.renewals-disabled' ).show();
627 } ).prop('checked', false);