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", 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", 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 ) {
148 "mDataProp": function( oObj ) {
149 if ( oObj.issued_today ) {
150 return "<strong>" + TODAYS_CHECKOUTS + "</strong>";
152 return "<strong>" + PREVIOUS_CHECKOUTS + "</strong>";
157 "mDataProp": "date_due",
161 "iDataSort": 1, // Sort on hidden unformatted date due column
162 "mDataProp": function( oObj ) {
163 if ( oObj.date_due_overdue ) {
164 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
166 return oObj.date_due_formatted;
171 "mDataProp": function ( oObj ) {
172 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
177 $.each(oObj.subtitle, function( index, value ) {
178 title += " " + value.subfield;
181 title += "</a></span>";
184 title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
187 if ( oObj.itemnotes ) {
189 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
190 span_class = "circ-hlt";
192 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
196 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
209 { "mDataProp": "itemtype" },
210 { "mDataProp": "issuedate_formatted" },
211 { "mDataProp": "branchname" },
212 { "mDataProp": "itemcallnumber" },
214 "mDataProp": function ( oObj ) {
215 if ( ! oObj.charge ) oObj.charge = 0;
216 return parseFloat(oObj.charge).toFixed(2);
220 "mDataProp": function ( oObj ) {
221 if ( ! oObj.price ) oObj.price = 0;
222 return parseFloat(oObj.price).toFixed(2);
227 "mDataProp": function ( oObj ) {
233 content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
235 if ( oObj.can_renew ) {
237 } else if ( oObj.can_renew_error == "on_reserve" ) {
238 content += "<span class='renewals-disabled'>"
239 + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
242 span_style = "display: none";
243 span_class = "renewals-allowed";
244 } else if ( oObj.can_renew_error == "too_many" ) {
245 content += "<span class='renewals-disabled'>"
249 span_style = "display: none";
250 span_class = "renewals-allowed";
251 } else if ( oObj.can_renew_error == "too_soon" ) {
252 content += "<span class='renewals-disabled'>"
253 + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
256 span_style = "display: none";
257 span_class = "renewals-allowed";
259 content += "<span class='renewals-disabled'>"
260 + oObj.can_renew_error
263 span_style = "display: none";
264 span_class = "renewals-allowed";
267 content += "<span class='" + span_class + "' style='" + span_style + "'>"
268 + "<input type='checkbox' class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
271 if ( oObj.renewals_remaining ) {
272 content += "<span class='renewals'>("
273 + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
277 content += "</span>";
285 "mDataProp": function ( oObj ) {
286 if ( oObj.can_renew_error == "on_reserve" ) {
287 return "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>";
289 return "<input type='checkbox' class='checkin' id='checkin_" + oObj.itemnumber + "' name='checkin' value='" + oObj.itemnumber +"'></input>";
294 "bVisible": exports_enabled ? true : false,
296 "mDataProp": function ( oObj ) {
297 return "<input type='checkbox' class='export' id='export_" + oObj.biblionumber + "' name='biblionumbers' value='" + oObj.biblionumber + "' />";
301 "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
302 var total_charge = 0;
304 for ( var i=0; i < aaData.length; i++ ) {
305 total_charge += aaData[i]['charge'] * 1;
306 total_price += aaData[i]['price'] * 1;
308 var nCells = nRow.getElementsByTagName('td');
309 nCells[1].innerHTML = total_charge.toFixed(2);
310 nCells[2].innerHTML = total_price.toFixed(2);
314 "bServerSide": false,
315 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
316 "fnServerData": function ( sSource, aoData, fnCallback ) {
317 aoData.push( { "name": "borrowernumber", "value": borrowernumber } );
319 $.getJSON( sSource, aoData, function (json) {
323 "fnInitComplete": function(oSettings) {
324 // Disable rowGrouping plugin after first use
325 // so any sorting on the table doesn't use it
326 var oSettings = issuesTable.fnSettings();
328 for (f = 0; f < oSettings.aoDrawCallback.length; f++) {
329 if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') {
330 oSettings.aoDrawCallback.splice(f, 1);
335 oSettings.aaSortingFixed = null;
339 iGroupingColumnIndex: 1,
340 iGroupingOrderByColumnIndex: 0,
341 sGroupingColumnSortDirection: "asc"
345 if ( $("#issues-table").length ) {
346 $("#issues-table_processing").position({
347 of: $( "#issues-table" ),
352 // Don't load relatives' issues table unless it is clicked on
353 var relativesIssuesTable;
354 $("#relatives-issues-tab").click( function() {
355 if ( ! relativesIssuesTable ) {
356 relativesIssuesTable = $("#relatives-issues-table").dataTable({
358 "sDom": "<'row-fluid'<'span6'><'span6'>r>t<'row-fluid'>t",
362 "mDataProp": "date_due",
366 "iDataSort": 1, // Sort on hidden unformatted date due column
367 "mDataProp": function( oObj ) {
368 var today = new Date();
369 var due = new Date( oObj.date_due );
371 return "<span class='overdue'>" + oObj.date_due_formatted + "</span>";
373 return oObj.date_due_formatted;
378 "mDataProp": function ( oObj ) {
379 title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
384 $.each(oObj.subtitle, function( index, value ) {
385 title += " " + value.subfield;
388 title += "</a></span>";
391 title += " " + BY + " " + oObj.author;
394 if ( oObj.itemnotes ) {
396 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
397 span_class = "circ-hlt";
399 title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
403 + "<a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
416 { "mDataProp": "itemtype" },
417 { "mDataProp": "issuedate_formatted" },
418 { "mDataProp": "branchname" },
419 { "mDataProp": "itemcallnumber" },
421 "mDataProp": function ( oObj ) {
422 if ( ! oObj.charge ) oObj.charge = 0;
423 return parseFloat(oObj.charge).toFixed(2);
427 "mDataProp": function ( oObj ) {
428 if ( ! oObj.price ) oObj.price = 0;
429 return parseFloat(oObj.price).toFixed(2);
433 "mDataProp": function( oObj ) {
434 return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
435 + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")</a>"
441 "bServerSide": false,
442 "sAjaxSource": '/cgi-bin/koha/svc/checkouts',
443 "fnServerData": function ( sSource, aoData, fnCallback ) {
444 $.each(relatives_borrowernumbers, function( index, value ) {
445 aoData.push( { "name": "borrowernumber", "value": value } );
448 $.getJSON( sSource, aoData, function (json) {
456 if ( $("#relatives-issues-table").length ) {
457 $("#relatives-issues-table_processing").position({
458 of: $( "#relatives-issues-table" ),
463 if ( AllowRenewalLimitOverride ) {
464 $( '#override_limit' ).click( function () {
465 if ( this.checked ) {
466 $( '.renewals-allowed' ).show(); $( '.renewals-disabled' ).hide();
468 $( '.renewals-allowed' ).hide(); $( '.renewals-disabled' ).show();
470 } ).attr( 'checked', false );