1 $(document).ready(function() {
2 $.ajaxSetup ({ cache: false });
4 // Handle the select all/none links for checkouts table columns
5 $("#CheckAllRenewals").on("click",function(){
6 $("#UncheckAllCheckins").click();
7 $(".renew:visible").attr("checked", "checked" );
10 $("#UncheckAllRenewals").on("click",function(){
11 $(".renew:visible").removeAttr("checked");
15 $("#CheckAllCheckins").on("click",function(){
16 $("#UncheckAllRenewals").click();
17 $(".checkin:visible").attr("checked", "checked" );
20 $("#UncheckAllCheckins").on("click",function(){
21 $(".checkin:visible").removeAttr("checked");
25 // Don't allow both return and renew checkboxes to be checked
26 $(document).on("change", '.renew', function(){
27 if ( $(this).is(":checked") ) {
28 $( "#checkin_" + $(this).val() ).removeAttr("checked");
31 $(document).on("change", '.checkin', function(){
32 if ( $(this).is(":checked") ) {
33 $( "#renew_" + $(this).val() ).removeAttr("checked");
37 // Clicking the table cell checks the checkbox inside it
38 $(document).on("click", 'td', function(e){
39 if(e.target.tagName.toLowerCase() == 'td'){
40 $(this).find("input:checkbox:visible").each( function() {
46 // Handle renewals and returns
47 $("#RenewCheckinChecked").on("click",function(){
48 $(".checkin:checked:visible").each(function() {
49 itemnumber = $(this).val();
51 $(this).replaceWith("<img id='checkin_" + itemnumber + "' src='" + interface + "/" + theme + "/img/loading-small.gif' />");
54 itemnumber: itemnumber,
55 borrowernumber: borrowernumber,
56 branchcode: branchcode,
57 exempt_fine: $("#exemptfine").is(':checked')
60 $.post( "/cgi-bin/koha/svc/checkin.pl", params, function( data ) {
61 id = "#checkin_" + data.itemnumber;
64 if ( data.returned ) {
65 content = CIRCULATION_RETURNED;
67 content = CIRCULATION_NOT_RETURNED;
70 $(id).replaceWith( content );
74 $(".renew:checked:visible").each(function() {
75 var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
77 var itemnumber = $(this).val();
79 $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/loading-small.gif' />");
82 itemnumber: itemnumber,
83 borrowernumber: borrowernumber,
84 branchcode: branchcode,
85 override_limit: override_limit,
86 date_due: $("#newduedate").val()
89 $.post( "/cgi-bin/koha/svc/renew.pl", params, function( data ) {
90 var id = "#renew_" + data.itemnumber;
93 if ( data.renew_okay ) {
94 content = CIRCULATION_RENEWED_DUE + " " + data.date_due;
96 content = CIRCULATION_RENEW_FAILED + " ";
97 if ( data.error == "no_checkout" ) {
98 content += NOT_CHECKED_OUT;
99 } else if ( data.error == "too_many" ) {
100 content += TOO_MANY_RENEWALS;
101 } else if ( data.error == "on_reserve" ) {
102 content += ON_RESERVE;
103 } else if ( data.error ) {
104 content += data.error;
106 content += REASON_UNKNOWN;
110 $(id).replaceWith( content );
114 // Prevent form submit
118 $("#RenewAll").on("click",function(){
119 $("#CheckAllRenewals").click();
120 $("#UncheckAllCheckins").click();
121 $("#RenewCheckinChecked").click();
123 // Prevent form submit
127 var ymd = $.datepicker.formatDate('yy-mm-dd', new Date());
131 issuesTable = $("#issues-table").dataTable({
133 "sEmptyTable" : MSG_DT_LOADING_RECORDS,
136 "sDom": "<'row-fluid'<'span6'><'span6'>r>t<'row-fluid'>t",
139 "mDataProp": function( oObj ) {
140 if ( oObj.issued_today ) {
141 return "<strong>" + TODAYS_CHECKOUTS + "</strong>";
143 return "<strong>" + PREVIOUS_CHECKOUTS + "</strong>";
148 "mDataProp": "date_due",
152 "iDataSort": 1, // Sort on hidden unformatted date due column
153 "mDataProp": function( oObj ) {
154 var today = new Date();
155 var due = new Date( oObj.date_due );
157 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
159 return oObj.date_due_formatted;
164 "mDataProp": function ( oObj ) {
165 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
170 $.each(oObj.subtitle, function( index, value ) {
171 title += " " + value.subfield;
174 title += "</a></span>";
177 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
180 if ( oObj.itemnotes ) {
182 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
183 span_class = "circ-hlt";
185 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
189 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
202 { "mDataProp": "itemtype" },
203 { "mDataProp": "issuedate_formatted" },
204 { "mDataProp": "branchname" },
205 { "mDataProp": "itemcallnumber" },
207 "mDataProp": function ( oObj ) {
208 if ( ! oObj.charge ) oObj.charge = 0;
209 return parseFloat(oObj.charge).toFixed(2);
213 "mDataProp": function ( oObj ) {
214 if ( ! oObj.price ) oObj.price = 0;
215 return parseFloat(oObj.price).toFixed(2);
220 "mDataProp": function ( oObj ) {
226 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
228 if ( oObj.can_renew ) {
230 } else if ( oObj.can_renew_error == "on_reserve" ) {
231 content += "<span class='renewals-disabled'>"
232 + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
235 span_style = "display: none";
236 span_class = "renewals-allowed";
237 } else if ( oObj.can_renew_error == "too_many" ) {
238 content += "<span class='renewals-disabled'>"
242 span_style = "display: none";
243 span_class = "renewals-allowed";
244 } else if ( oObj.can_renew_error == "too_soon" ) {
245 content += "<span class='renewals-disabled'>"
246 + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
249 span_style = "display: none";
250 span_class = "renewals-allowed";
252 content += "<span class='renewals-disabled'>"
253 + oObj.can_renew_error
256 span_style = "display: none";
257 span_class = "renewals-allowed";
260 content += "<span class='" + span_class + "' style='" + span_style + "'>"
261 + "<input type='checkbox' class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
264 if ( oObj.renewals_remaining ) {
265 content += "<span class='renewals'>("
266 + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
270 content += "</span>";
278 "mDataProp": function ( oObj ) {
279 if ( oObj.can_renew_error == "on_reserve" ) {
280 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
282 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
287 "bVisible": exports_enabled ? true : false,
289 "mDataProp": function ( oObj ) {
290 return "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
294 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
295 var total_charge = 0;
297 for ( var i=0; i < aaData.length; i++ ) {
298 total_charge += aaData[i]['charge'] * 1;
299 total_price += aaData[i]['price'] * 1;
301 var nCells = nRow.getElementsByTagName('td');
302 nCells[1].innerHTML = total_charge.toFixed(2);
303 nCells[2].innerHTML = total_price.toFixed(2);
307 "bServerSide": false,
308 "sAjaxSource": '/cgi-bin/koha/svc/checkouts.pl',
309 "fnServerData": function ( sSource, aoData, fnCallback ) {
310 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
312 $.getJSON( sSource, aoData, function (json) {
316 "fnInitComplete": function(oSettings) {
317 // Disable rowGrouping plugin after first use
318 // so any sorting on the table doesn't use it
319 var oSettings = issuesTable.fnSettings();
321 for (f = 0; f < oSettings.aoDrawCallback.length; f++) {
322 if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') {
323 oSettings.aoDrawCallback.splice(f, 1);
328 oSettings.aaSortingFixed = null;
332 iGroupingOrderByColumnIndex: 0,
333 sGroupingColumnSortDirection: "desc"
337 if ( $("#issues-table").length ) {
338 $("#issues-table_processing").position({
339 of: $( "#issues-table" ),
344 // Don't load relatives' issues table unless it is clicked on
345 var relativesIssuesTable;
346 $("#relatives-issues-tab").click( function() {
347 if ( ! relativesIssuesTable ) {
348 relativesIssuesTable = $("#relatives-issues-table").dataTable({
350 "sDom": "<'row-fluid'<'span6'><'span6'>r>t<'row-fluid'>t",
354 "mDataProp": "date_due",
358 "iDataSort": 1, // Sort on hidden unformatted date due column
359 "mDataProp": function( oObj ) {
360 var today = new Date();
361 var due = new Date( oObj.date_due );
363 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
365 return oObj.date_due_formatted;
370 "mDataProp": function ( oObj ) {
371 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
376 $.each(oObj.subtitle, function( index, value ) {
377 title += " " + value.subfield;
380 title += "</a></span>";
383 title += " " + BY + " " + oObj.author;
386 if ( oObj.itemnotes ) {
388 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
389 span_class = "circ-hlt";
391 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
395 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
408 { "mDataProp": "itemtype" },
409 { "mDataProp": "issuedate_formatted" },
410 { "mDataProp": "branchname" },
411 { "mDataProp": "itemcallnumber" },
413 "mDataProp": function ( oObj ) {
414 if ( ! oObj.charge ) oObj.charge = 0;
415 return parseFloat(oObj.charge).toFixed(2);
419 "mDataProp": function ( oObj ) {
420 if ( ! oObj.price ) oObj.price = 0;
421 return parseFloat(oObj.price).toFixed(2);
425 "mDataProp": function( oObj ) {
426 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
427 + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")</a>"
433 "bServerSide": false,
434 "sAjaxSource": '/cgi-bin/koha/svc/checkouts.pl',
435 "fnServerData": function ( sSource, aoData, fnCallback ) {
436 $.each(relatives_borrowernumbers, function( index, value ) {
437 aoData.push( { "name": "borrowernumber", "value": value } );
440 $.getJSON( sSource, aoData, function (json) {
448 if ( $("#relatives-issues-table").length ) {
449 $("#relatives-issues-table_processing").position({
450 of: $( "#relatives-issues-table" ),
455 if ( AllowRenewalLimitOverride ) {
456 $( '#override_limit' ).click( function () {
457 if ( this.checked ) {
458 $( '.renewals-allowed' ).show(); $( '.renewals-disabled' ).hide();
460 $( '.renewals-allowed' ).hide(); $( '.renewals-disabled' ).show();
462 } ).attr( 'checked', false );