1 $(document).ready(function() {
2 // Handle the select all/none links for checkouts table columns
3 $("#CheckAllRenewals").on("click",function(){
4 $("#UncheckAllCheckins").click();
5 $(".renew:visible").attr("checked", "checked" );
8 $("#UncheckAllRenewals").on("click",function(){
9 $(".renew:visible").removeAttr("checked");
13 $("#CheckAllCheckins").on("click",function(){
14 $("#UncheckAllRenewals").click();
15 $(".checkin:visible").attr("checked", "checked" );
18 $("#UncheckAllCheckins").on("click",function(){
19 $(".checkin:visible").removeAttr("checked");
23 // Don't allow both return and renew checkboxes to be checked
24 $(document).on("change", '.renew', function(){
25 if ( $(this).is(":checked") ) {
26 $( "#checkin_" + $(this).val() ).removeAttr("checked");
29 $(document).on("change", '.checkin', function(){
30 if ( $(this).is(":checked") ) {
31 $( "#renew_" + $(this).val() ).removeAttr("checked");
35 // Clicking the table cell checks the checkbox inside it
36 $(document).on("click", 'td', function(e){
37 if(e.target.tagName.toLowerCase() == 'td'){
38 $(this).find("input:checkbox:visible").each( function() {
44 // Handle renewals and returns
45 $("#RenewCheckinChecked").on("click",function(){
46 $(".checkin:checked:visible").each(function() {
47 itemnumber = $(this).val();
49 $(this).replaceWith("<img id='checkin_" + itemnumber + "' src='" + interface + "/" + theme + "/img/loading-small.gif' />");
52 itemnumber: itemnumber,
53 borrowernumber: borrowernumber,
54 branchcode: branchcode,
55 exempt_fine: $("#exemptfine").is(':checked')
58 $.post( "/cgi-bin/koha/svc/checkin.pl", params, function( data ) {
59 id = "#checkin_" + data.itemnumber;
62 if ( data.returned ) {
63 content = CIRCULATION_RETURNED;
65 content = CIRCULATION_NOT_RETURNED;
68 $(id).replaceWith( content );
72 $(".renew:checked:visible").each(function() {
73 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
75 var itemnumber = $(this).val();
77 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/loading-small.gif' />");
80 itemnumber: itemnumber,
81 borrowernumber: borrowernumber,
82 branchcode: branchcode,
83 override_limit: override_limit,
84 date_due: $("#newduedate").val()
87 $.post( "/cgi-bin/koha/svc/renew.pl", params, function( data ) {
88 var id = "#renew_" + data.itemnumber;
91 if ( data.renew_okay ) {
92 content = CIRCULATION_RENEWED_DUE + " " + data.date_due;
94 content = CIRCULATION_RENEW_FAILED + " ";
95 if ( data.error == "no_checkout" ) {
96 content += NOT_CHECKED_OUT;
97 } else if ( data.error == "too_many" ) {
98 content += TOO_MANY_RENEWALS;
99 } else if ( data.error == "on_reserve" ) {
100 content += ON_RESERVE;
101 } else if ( data.error ) {
102 content += data.error;
104 content += REASON_UNKNOWN;
108 $(id).replaceWith( content );
112 // Prevent form submit
116 $("#RenewAll").on("click",function(){
117 $("#CheckAllRenewals").click();
118 $("#UncheckAllCheckins").click();
119 $("#RenewCheckinChecked").click();
121 // Prevent form submit
125 var ymd = $.datepicker.formatDate('yy-mm-dd', new Date());
129 issuesTable = $("#issues-table").dataTable({
131 "sDom": "<'row-fluid'<'span6'><'span6'>r>t<'row-fluid'>t",
134 "mDataProp": function( oObj ) {
135 if ( oObj.issued_today ) {
136 return "<strong>" + TODAYS_CHECKOUTS + "</strong>";
138 return "<strong>" + PREVIOUS_CHECKOUTS + "</strong>";
143 "mDataProp": "date_due",
147 "iDataSort": 1, // Sort on hidden unformatted date due column
148 "mDataProp": function( oObj ) {
149 var today = new Date();
150 var due = new Date( oObj.date_due );
152 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
154 return oObj.date_due_formatted;
159 "mDataProp": function ( oObj ) {
160 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
165 $.each(oObj.subtitle, function( index, value ) {
166 title += " " + value.subfield;
169 title += "</a></span>";
172 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
175 if ( oObj.itemnotes ) {
177 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
178 span_class = "circ-hlt";
180 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
184 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
197 { "mDataProp": "itemtype" },
198 { "mDataProp": "issuedate_formatted" },
199 { "mDataProp": "branchname" },
200 { "mDataProp": "itemcallnumber" },
202 "mDataProp": function ( oObj ) {
203 if ( ! oObj.charge ) oObj.charge = 0;
204 return parseFloat(oObj.charge).toFixed(2);
208 "mDataProp": function ( oObj ) {
209 if ( ! oObj.price ) oObj.price = 0;
210 return parseFloat(oObj.price).toFixed(2);
215 "mDataProp": function ( oObj ) {
221 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
223 if ( oObj.can_renew ) {
225 } else if ( oObj.can_renew_error == "on_reserve" ) {
226 content += "<span class='renewals-disabled'>"
227 + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
230 span_style = "display: none";
231 span_class = "renewals-allowed";
232 } else if ( oObj.can_renew_error == "too_many" ) {
233 content += "<span class='renewals-disabled'>"
237 span_style = "display: none";
238 span_class = "renewals-allowed";
239 } else if ( oObj.can_renew_error == "too_soon" ) {
240 content += "<span class='renewals-disabled'>"
241 + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
244 span_style = "display: none";
245 span_class = "renewals-allowed";
247 content += "<span class='renewals-disabled'>"
248 + oObj.can_renew_error
251 span_style = "display: none";
252 span_class = "renewals-allowed";
255 content += "<span class='" + span_class + "' style='" + span_style + "'>"
256 + "<input type='checkbox' class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
259 if ( oObj.renewals_remaining ) {
260 content += "<span class='renewals'>("
261 + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
265 content += "</span>";
273 "mDataProp": function ( oObj ) {
274 if ( oObj.can_renew_error == "on_reserve" ) {
275 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
277 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
282 "bVisible": exports_enabled ? true : false,
284 "mDataProp": function ( oObj ) {
285 return "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
289 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
290 var total_charge = 0;
292 for ( var i=0; i < aaData.length; i++ ) {
293 total_charge += aaData[i]['charge'] * 1;
294 total_price += aaData[i]['price'] * 1;
296 var nCells = nRow.getElementsByTagName('td');
297 nCells[1].innerHTML = total_charge.toFixed(2);
298 nCells[2].innerHTML = total_price.toFixed(2);
302 "bServerSide": false,
303 "sAjaxSource": '/cgi-bin/koha/svc/checkouts.pl',
304 "fnServerData": function ( sSource, aoData, fnCallback ) {
305 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
307 $.getJSON( sSource, aoData, function (json) {
311 "fnInitComplete": function(oSettings) {
312 // Disable rowGrouping plugin after first use
313 // so any sorting on the table doesn't use it
314 var oSettings = issuesTable.fnSettings();
316 for (f = 0; f < oSettings.aoDrawCallback.length; f++) {
317 if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') {
318 oSettings.aoDrawCallback.splice(f, 1);
323 oSettings.aaSortingFixed = null;
327 iGroupingOrderByColumnIndex: 0,
328 sGroupingColumnSortDirection: "desc"
332 if ( $("#issues-table").length ) {
333 $("#issues-table_processing").position({
334 of: $( "#issues-table" ),
339 // Don't load relatives' issues table unless it is clicked on
340 var relativesIssuesTable;
341 $("#relatives-issues-tab").click( function() {
342 if ( ! relativesIssuesTable ) {
343 relativesIssuesTable = $("#relatives-issues-table").dataTable({
345 "sDom": "<'row-fluid'<'span6'><'span6'>r>t<'row-fluid'>t",
349 "mDataProp": "date_due",
353 "iDataSort": 1, // Sort on hidden unformatted date due column
354 "mDataProp": function( oObj ) {
355 var today = new Date();
356 var due = new Date( oObj.date_due );
358 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
360 return oObj.date_due_formatted;
365 "mDataProp": function ( oObj ) {
366 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
371 $.each(oObj.subtitle, function( index, value ) {
372 title += " " + value.subfield;
375 title += "</a></span>";
378 title += " " + BY + " " + oObj.author;
381 if ( oObj.itemnotes ) {
383 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
384 span_class = "circ-hlt";
386 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
390 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
403 { "mDataProp": "itemtype" },
404 { "mDataProp": "issuedate_formatted" },
405 { "mDataProp": "branchname" },
406 { "mDataProp": "itemcallnumber" },
408 "mDataProp": function ( oObj ) {
409 if ( ! oObj.charge ) oObj.charge = 0;
410 return parseFloat(oObj.charge).toFixed(2);
414 "mDataProp": function ( oObj ) {
415 if ( ! oObj.price ) oObj.price = 0;
416 return parseFloat(oObj.price).toFixed(2);
420 "mDataProp": function( oObj ) {
421 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
422 + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")</a>"
428 "bServerSide": false,
429 "sAjaxSource": '/cgi-bin/koha/svc/checkouts.pl',
430 "fnServerData": function ( sSource, aoData, fnCallback ) {
431 $.each(relatives_borrowernumbers, function( index, value ) {
432 aoData.push( { "name": "borrowernumber", "value": value } );
435 $.getJSON( sSource, aoData, function (json) {
443 if ( $("#relatives-issues-table").length ) {
444 $("#relatives-issues-table_processing").position({
445 of: $( "#relatives-issues-table" ),
450 if ( AllowRenewalLimitOverride ) {
451 $( '#override_limit' ).click( function () {
452 if ( this.checked ) {
453 $( '.renewals-allowed' ).show(); $( '.renewals-disabled' ).hide();
455 $( '.renewals-allowed' ).hide(); $( '.renewals-disabled' ).show();
457 } ).attr( 'checked', false );