From a186d7746c0d1df6674560b4f7278fc6d63c151d Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 18 Nov 2015 15:52:14 +0100 Subject: [PATCH] Bug 15219: Load checkouts table incrementally Some libraries have patrons with more than 1000 checkouts. Loading all of them at once can be very long, and sometimes can cause timeout errors. This patch prevent that by loading checkouts in the table by batches of 100. This affects patron's checkouts and patron's relatives' checkouts tables on pages circ/circulation.pl and members/moremember.pl. Additionally, this patch: - adds a switch to turn off and on row grouping (today's checkouts vs previous checkouts) (on by default) - adds a global filter text input on all tables - adds "column settings" for relatives' checkouts tables - factorize some code that was duplicated across the two DataTables configurations (mDataProp) --- admin/columns_settings.yml | 61 ++ .../prog/en/includes/checkouts-table-footer.inc | 2 +- .../prog/en/includes/checkouts-table.inc | 1 + .../prog/en/includes/datatables-strings.inc | 1 + .../intranet-tmpl/prog/en/includes/datatables.inc | 20 +- .../intranet-tmpl/prog/en/includes/strings.inc | 1 + koha-tmpl/intranet-tmpl/prog/en/js/checkouts.js | 662 ++++++++++----------- koha-tmpl/intranet-tmpl/prog/en/js/datatables.js | 1 + .../prog/en/modules/circ/circulation.tt | 1 + .../prog/en/modules/members/moremember.tt | 1 + svc/checkouts | 66 +- 11 files changed, 423 insertions(+), 394 deletions(-) diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml index 3849245..baa53e0 100644 --- a/admin/columns_settings.yml +++ b/admin/columns_settings.yml @@ -231,6 +231,34 @@ modules: columnname: export cannot_be_toggled: 1 cannot_be_modified: 1 + relatives-issues-table: + - + columnname: due_date_unformatted + cannot_be_toggled: 1 + cannot_be_modified: 1 + is_hidden: 1 + - + columnname: due_date + - + columnname: title + - + columnname: item_type + - + columnname: location + - + columnname: checkout_on + - + columnname: checkout_from + - + columnname: callno + - + columnname: charge + - + columnname: fine + - + columnname: price + - + columnname: patron reports: lostitems: @@ -273,6 +301,11 @@ modules: cannot_be_modified: 1 is_hidden: 1 - + columnname: group_order + cannot_be_toggled: 1 + cannot_be_modified: 1 + is_hidden: 1 + - columnname: todays_or_previous_checkouts cannot_be_toggled: 1 cannot_be_modified: 1 @@ -314,3 +347,31 @@ modules: columnname: export cannot_be_toggled: 1 cannot_be_modified: 1 + relatives-issues-table: + - + columnname: due_date_unformatted + cannot_be_toggled: 1 + cannot_be_modified: 1 + is_hidden: 1 + - + columnname: due_date + - + columnname: title + - + columnname: item_type + - + columnname: location + - + columnname: checkout_on + - + columnname: checkout_from + - + columnname: callno + - + columnname: charge + - + columnname: fine + - + columnname: price + - + columnname: patron diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc index 0de211f..d15c0cb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc @@ -1,6 +1,6 @@ - Totals: + Totals: [% totaldue %] [% finetotal %] [% totalprice %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc index 0c1a7f1..ce2f0e9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc @@ -11,6 +11,7 @@     +   Due date Due date Title diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc index ead071b..fa156d6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc @@ -6,6 +6,7 @@ var MSG_DT_PREVIOUS = _("Previous"); var MSG_DT_EMPTY_TABLE = _("No data available in table"); var MSG_DT_INFO = _("Showing _START_ to _END_ of _TOTAL_"); + var MSG_DT_INFO_SIMPLE = _("Entries shown: _TOTAL_"); var MSG_DT_INFO_EMPTY = _("No entries to show"); var MSG_DT_INFO_FILTERED = _("(filtered from _MAX_ total entries)"); var MSG_DT_LENGTH_MENU = _("Show _MENU_ entries"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc index 4381b01..8760f54 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc @@ -1,22 +1,4 @@ [% INCLUDE 'format_price.inc' %] - +[% INCLUDE 'datatables-strings.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc index 3226ad3..73a3f60 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc @@ -30,5 +30,6 @@ var NO = _("No"); var YES = _("Yes"); var INHOUSE_USE = _("On-site checkout"); + var GROUP_TODAYS_CHECKOUTS = _("Group today's checkouts"); //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/en/js/checkouts.js index b4b676b..adc8d4a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/checkouts.js @@ -1,3 +1,278 @@ +(function($) { + +var ymd = $.datepicker.formatDate('yy-mm-dd', new Date()); + +function enableGrouping(datatable) { + datatable.rowGrouping({ + iGroupingColumnIndex: 2, + iGroupingOrderByColumnIndex: 1, + sGroupingColumnSortDirection: "asc" + }); +} + +function disableGrouping(datatable) { + var oSettings = datatable.fnSettings(); + for (f = 0; f < oSettings.aoDrawCallback.length; f++) { + if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') { + oSettings.aoDrawCallback.splice(f, 1); + datatable.fnDraw(); + break; + } + } +} + +function loadTableData(datatable, borrowernumbers, offset, count) { + offset = offset ? offset : 0; + count = count ? count : 100; + + var args = { + "borrowernumber": borrowernumbers, + "offset": offset, + "count": count + }; + + $.ajax({ + dataType: "json", + traditional: true, + url: '/cgi-bin/koha/svc/checkouts', + data: args, + success: function(data) { + if (data.length) { + datatable.fnAddData(data); + } + + if (data.length < count) { + var oSettings = datatable.fnSettings(); + oSettings.bDataFullyLoaded = true; + + // We need to redraw to update the info text + datatable.fnDraw(); + } else { + loadTableData(datatable, borrowernumbers, offset + count, count); + } + } + }); +} + +function dtSimpleInfoCallback (oSettings, iStart, iEnd, iMax, iTotal, sPre) { + var sInfo; + var oLanguage = oSettings.oLanguage; + + if (iTotal > 0) { + sInfo = oLanguage.sInfoSimple.replace('_TOTAL_', iTotal); + } else { + sInfo = oLanguage.sInfoEmpty; + } + + if (iMax > iTotal) { + sInfo += ' ' + oLanguage.sInfoFiltered.replace('_MAX_', iMax); + } + + if (!oSettings.bDataFullyLoaded) { + sInfo += ' (' + oLanguage.sLoadingRecords + ')'; + } + + return sInfo; +} + +var mDataProps = { + groupOrder: function( oObj ) { + if ( oObj.issued_today ) { + return "0"; + } else { + return "1"; + } + }, + groupName: function( oObj ) { + if ( oObj.issued_today ) { + return "" + TODAYS_CHECKOUTS + ""; + } else { + return "" + PREVIOUS_CHECKOUTS + ""; + } + }, + dateDueFormatted: function( oObj ) { + var due = oObj.date_due_formatted; + + if ( oObj.date_due_overdue ) { + due = "" + due + ""; + } + + if ( oObj.lost ) { + due += "" + oObj.lost + ""; + } + + if ( oObj.damaged ) { + due += "" + oObj.damaged + ""; + } + + due = "" + due + ""; + + return due; + }, + title: function ( oObj ) { + var title = "" + + oObj.title; + + $.each(oObj.subtitle, function( index, value ) { + title += " " + value.subfield; + }); + + title += ""; + + if ( oObj.author ) { + title += " " + BY.replace( "_AUTHOR_", " " + oObj.author ); + } + + if ( oObj.itemnotes ) { + var span_class = ""; + if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) { + span_class = "circ-hlt"; + } + title += " - " + oObj.itemnotes + "" + } + + var onsite_checkout = ''; + if ( oObj.onsite_checkout == 1 ) { + onsite_checkout += " (" + INHOUSE_USE + ")"; + } + + title += " " + + "" + + oObj.barcode + + "" + + onsite_checkout; + + return title; + }, + charge: function ( oObj ) { + if ( ! oObj.charge ) oObj.charge = 0; + return parseFloat(oObj.charge).toFixed(2); + }, + fine: function ( oObj ) { + if ( ! oObj.fine ) oObj.fine = 0; + return parseFloat(oObj.fine).toFixed(2); + }, + price: function ( oObj ) { + if ( ! oObj.price ) oObj.price = 0; + return parseFloat(oObj.price).toFixed(2); + }, + renew: function ( oObj ) { + var content = ""; + var span_style = ""; + var span_class = ""; + + content += ""; + content += "" + oObj.renewals_count + ""; + + if ( oObj.can_renew ) { + // Do nothing + } else if ( oObj.can_renew_error == "on_reserve" ) { + content += "" + + "" + ON_HOLD + "" + + ""; + + span_style = "display: none"; + span_class = "renewals-allowed"; + } else if ( oObj.can_renew_error == "too_many" ) { + content += "" + + NOT_RENEWABLE + + ""; + + span_style = "display: none"; + span_class = "renewals-allowed"; + } else if ( oObj.can_renew_error == "restriction" ) { + content += "" + + NOT_RENEWABLE_RESTRICTION + + ""; + + span_style = "display: none"; + span_class = "renewals-allowed"; + } else if ( oObj.can_renew_error == "overdue" ) { + content += "" + + NOT_RENEWABLE_OVERDUE + + ""; + + span_style = "display: none"; + span_class = "renewals-allowed"; + } else if ( oObj.can_renew_error == "too_soon" ) { + content += "" + + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date ) + + ""; + + span_style = "display: none"; + span_class = "renewals-allowed"; + } else if ( oObj.can_renew_error == "auto_too_soon" ) { + content += "" + + NOT_RENEWABLE_AUTO_TOO_SOON + + ""; + + span_style = "display: none"; + span_class = "renewals-allowed"; + } else if ( oObj.can_renew_error == "auto_renew" ) { + content += "" + + NOT_RENEWABLE_AUTO_RENEW + + ""; + + span_style = "display: none"; + span_class = "renewals-allowed"; + } else if ( oObj.can_renew_error == "onsite_checkout" ) { + // Don't display something if it's an onsite checkout + } else { + content += "" + + oObj.can_renew_error + + ""; + + span_style = "display: none"; + span_class = "renewals-allowed"; + } + + var can_force_renew = ( oObj.onsite_checkout == 0 ) && ( oObj.can_renew_error != "on_reserve" ); + var can_renew = ( oObj.renewals_remaining > 0 && !oObj.can_renew_error ); + if ( can_renew || can_force_renew ) { + content += "" + + "" + + ""; + + content += "(" + + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed ) + + ")"; + } + + content += ""; + + return content; + }, + checkin: function ( oObj ) { + if ( oObj.can_renew_error == "on_reserve" ) { + return "" + ON_HOLD + ""; + } else { + return ""; + } + }, + export: function ( oObj ) { + var s = ""; + + s += ""; + return s; + }, + patron: function( oObj ) { + return "" + + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")" + } +}; + $(document).ready(function() { $.ajaxSetup ({ cache: false }); @@ -139,8 +414,6 @@ $(document).ready(function() { return false; }); - var ymd = $.datepicker.formatDate('yy-mm-dd', new Date()); - $('#issues-table').hide(); $('#issues-table-actions').hide(); $('#issues-table-load-immediately').change(function(){ @@ -174,92 +447,19 @@ $(document).ready(function() { "sProcessing": MSG_DT_LOADING_RECORDS, }, "bAutoWidth": false, - "sDom": 'C<"clearfix">rt', + "bPaginate": false, + "sDom": 'C<"top pager"if>rt', "aoColumns": [ - { - "mDataProp": function( oObj ) { - return oObj.sort_order; - } - }, - { - "mDataProp": function( oObj ) { - if ( oObj.issued_today ) { - return "" + TODAYS_CHECKOUTS + ""; - } else { - return "" + PREVIOUS_CHECKOUTS + ""; - } - } - }, - { - "mDataProp": "date_due", - "bVisible": false, - }, + { "mDataProp": "sort_order" }, + { "mDataProp": mDataProps.groupOrder }, + { "mDataProp": mDataProps.groupName }, + { "mDataProp": "date_due" }, { "iDataSort": 2, // Sort on hidden unformatted date due column - "mDataProp": function( oObj ) { - var due = oObj.date_due_formatted; - - if ( oObj.date_due_overdue ) { - due = "" + due + ""; - } - - if ( oObj.lost ) { - due += "" + oObj.lost + ""; - } - - if ( oObj.damaged ) { - due += "" + oObj.damaged + ""; - } - - due = "" + due + ""; - - return due; - } + "mDataProp": mDataProps.dateDueFormatted }, { - "mDataProp": function ( oObj ) { - title = "" - + oObj.title; - - $.each(oObj.subtitle, function( index, value ) { - title += " " + value.subfield; - }); - - title += ""; - - if ( oObj.author ) { - title += " " + BY.replace( "_AUTHOR_", " " + oObj.author ); - } - - if ( oObj.itemnotes ) { - var span_class = ""; - if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) { - span_class = "circ-hlt"; - } - title += " - " + oObj.itemnotes + "" - } - - var onsite_checkout = ''; - if ( oObj.onsite_checkout == 1 ) { - onsite_checkout += " (" + INHOUSE_USE + ")"; - } - - title += " " - + "" - + oObj.barcode - + "" - + onsite_checkout; - - return title; - }, + "mDataProp": mDataProps.title, "sType": "anti-the" }, { "mDataProp": "itemtype_description" }, @@ -267,136 +467,21 @@ $(document).ready(function() { { "mDataProp": "issuedate_formatted" }, { "mDataProp": "branchname" }, { "mDataProp": "itemcallnumber" }, - { - "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": mDataProps.charge }, + { "mDataProp": mDataProps.fine }, + { "mDataProp": mDataProps.price }, { "bSortable": false, - "mDataProp": function ( oObj ) { - var content = ""; - var span_style = ""; - var span_class = ""; - - content += ""; - content += "" + oObj.renewals_count + ""; - - if ( oObj.can_renew ) { - // Do nothing - } else if ( oObj.can_renew_error == "on_reserve" ) { - content += "" - + "" + ON_HOLD + "" - + ""; - - span_style = "display: none"; - span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "too_many" ) { - content += "" - + NOT_RENEWABLE - + ""; - - span_style = "display: none"; - span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "restriction" ) { - content += "" - + NOT_RENEWABLE_RESTRICTION - + ""; - - span_style = "display: none"; - span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "overdue" ) { - content += "" - + NOT_RENEWABLE_OVERDUE - + ""; - - span_style = "display: none"; - span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "too_soon" ) { - content += "" - + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date ) - + ""; - - span_style = "display: none"; - span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "auto_too_soon" ) { - content += "" - + NOT_RENEWABLE_AUTO_TOO_SOON - + ""; - - span_style = "display: none"; - span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "auto_renew" ) { - content += "" - + NOT_RENEWABLE_AUTO_RENEW - + ""; - - span_style = "display: none"; - span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "onsite_checkout" ) { - // Don't display something if it's an onsite checkout - } else { - content += "" - + oObj.can_renew_error - + ""; - - span_style = "display: none"; - span_class = "renewals-allowed"; - } - - var can_force_renew = ( oObj.onsite_checkout == 0 ) && ( oObj.can_renew_error != "on_reserve" ); - var can_renew = ( oObj.renewals_remaining > 0 && !oObj.can_renew_error ); - if ( can_renew || can_force_renew ) { - content += "" - + "" - + ""; - - content += "(" - + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed ) - + ")"; - } - - content += ""; - - return content; - } + "mDataProp": mDataProps.renew }, { "bSortable": false, - "mDataProp": function ( oObj ) { - if ( oObj.can_renew_error == "on_reserve" ) { - return "" + ON_HOLD + ""; - } else { - return ""; - } - } + "mDataProp": mDataProps.checkin }, { "bVisible": exports_enabled ? true : false, "bSortable": false, - "mDataProp": function ( oObj ) { - var s = ""; - - s += ""; - return s; - } + "mDataProp": mDataProps.checkin } ], "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) { @@ -412,38 +497,32 @@ $(document).ready(function() { $("#totalfine").html(total_fine.toFixed(2)); $("#totalprice").html(total_price.toFixed(2)); }, - "bPaginate": false, - "bProcessing": true, - "bServerSide": false, - "sAjaxSource": '/cgi-bin/koha/svc/checkouts', - "fnServerData": function ( sSource, aoData, fnCallback ) { - aoData.push( { "name": "borrowernumber", "value": borrowernumber } ); - - $.getJSON( sSource, aoData, function (json) { - fnCallback(json) - } ); - }, - "fnInitComplete": function(oSettings) { - // Disable rowGrouping plugin after first use - // so any sorting on the table doesn't use it - var oSettings = issuesTable.fnSettings(); - - for (f = 0; f < oSettings.aoDrawCallback.length; f++) { - if (oSettings.aoDrawCallback[f].sName == 'fnRowGrouping') { - oSettings.aoDrawCallback.splice(f, 1); - break; - } - } + "fnInfoCallback": dtSimpleInfoCallback + }, columns_settings); + + enableGrouping(issuesTable); + + var groupingSwitch = $('') + .attr('id', 'issues-table-row-grouping-switch') + .attr('checked', 'checked') + .css('vertical-align', 'middle') + .change(function() { + if ($(this).is(':checked')) { + enableGrouping(issuesTable); + } else { + disableGrouping(issuesTable); + } + }); + $('
') + .css('float', 'left') + .css('padding', '0.3em 0.5em') + .css('line-height', '1.9em') + .append(groupingSwitch) + .append(' ') + .append('') + .appendTo('#issues-table_wrapper .top.pager'); - oSettings.aaSortingFixed = null; - }, - }, columns_settings).rowGrouping( - { - iGroupingColumnIndex: 1, - iGroupingOrderByColumnIndex: 0, - sGroupingColumnSortDirection: "asc" - } - ); + loadTableData(issuesTable, borrowernumber); if ( $("#issues-table").length ) { $("#issues-table_processing").position({ @@ -457,71 +536,19 @@ $(document).ready(function() { var relativesIssuesTable; $("#relatives-issues-tab").click( function() { if ( ! relativesIssuesTable ) { - relativesIssuesTable = $("#relatives-issues-table").dataTable({ + relativesIssuesTable = KohaTable("#relatives-issues-table", { "bAutoWidth": false, - "sDom": "rt", + "sDom": 'C<"top pager"if>rt', "aaSorting": [], + "bPaginate": false, "aoColumns": [ - { - "mDataProp": "date_due", - "bVisible": false, - }, + { "mDataProp": "date_due" }, { "iDataSort": 1, // 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": mDataProps.dateDueFormatted }, { - "mDataProp": function ( oObj ) { - title = "" - + oObj.title; - - $.each(oObj.subtitle, function( index, value ) { - title += " " + value.subfield; - }); - - title += ""; - - if ( oObj.author ) { - title += " " + BY.replace( "_AUTHOR_", " " + oObj.author ); - } - - if ( oObj.itemnotes ) { - var span_class = ""; - if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) { - span_class = "circ-hlt"; - } - title += " - " + oObj.itemnotes + "" - } - - var onsite_checkout = ''; - if ( oObj.onsite_checkout == 1 ) { - onsite_checkout += " (" + INHOUSE_USE + ")"; - } - - title += " " - + "" - + oObj.barcode - + "" - + onsite_checkout; - - return title; - }, + "mDataProp": mDataProps.title, "sType": "anti-the" }, { "mDataProp": "itemtype" }, @@ -529,45 +556,14 @@ $(document).ready(function() { { "mDataProp": "issuedate_formatted" }, { "mDataProp": "branchname" }, { "mDataProp": "itemcallnumber" }, - { - "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.surname + " (" + oObj.borrower.cardnumber + ")" - } - }, + { "mDataProp": mDataProps.charge }, + { "mDataProp": mDataProps.fine }, + { "mDataProp": mDataProps.price }, + { "mDataProp": mDataProps.patron } ], - "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) - } ); - }, - }); + "fnInfoCallback": dtSimpleInfoCallback + }, relatives_columns_settings); + loadTableData(relativesIssuesTable, relatives_borrowernumbers); } }); @@ -587,4 +583,6 @@ $(document).ready(function() { } } ).attr( 'checked', false ); } - }); +}); + +})(jQuery); diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js index e42918c..8c93bc4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js @@ -15,6 +15,7 @@ var dataTablesDefaults = { }, "sEmptyTable" : window.MSG_DT_EMPTY_TABLE || "No data available in table", "sInfo" : window.MSG_DT_INFO || "Showing _START_ to _END_ of _TOTAL_ entries", + "sInfoSimple" : window.MSG_DT_INFO_SIMPLE || "Entries shown: _TOTAL_", "sInfoEmpty" : window.MSG_DT_INFO_EMPTY || "No entries to show", "sInfoFiltered" : window.MSG_DT_INFO_FILTERED || "(filtered from _MAX_ total entries)", "sLengthMenu" : window.MSG_DT_LENGTH_MENU || "Show _MENU_ entries", diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 19ba9fa..1c5ceba 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -48,6 +48,7 @@ var MSG_ADD_MESSAGE = _("Add a new message"); var MSG_EXPORT_SELECT_CHECKOUTS = _("You must select checkout(s) to export"); columns_settings = [% ColumnsSettings.GetColumns( 'circ', 'circulation', 'issues-table', 'json' ) %] +relatives_columns_settings = [% ColumnsSettings.GetColumns( 'circ', 'circulation', 'relatives-issues-table', 'json' ) %] [% IF ( borrowernumber ) %] if($.cookie("holdfor") != [% borrowernumber %]){ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 97e547d..b34e666 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -44,6 +44,7 @@ var MSG_ADD_MESSAGE = _("Add a new message"); var MSG_EXPORT_SELECT_CHECKOUTS = _("You must select checkout(s) to export"); columns_settings = [% ColumnsSettings.GetColumns( 'members', 'moremember', 'issues-table', 'json' ) %] +relatives_columns_settings = [% ColumnsSettings.GetColumns( 'members', 'moremember', 'relatives-issues-table', 'json' ) %] $(document).ready(function() { $('#finesholdsissues').tabs({ diff --git a/svc/checkouts b/svc/checkouts index 6ecfd09..cf993ce 100755 --- a/svc/checkouts +++ b/svc/checkouts @@ -42,22 +42,9 @@ if ( $auth_status ne "ok" ) { exit 0; } -my @sort_columns = qw/date_due title itype issuedate branchcode itemcallnumber/; - my @borrowernumber = $input->param('borrowernumber'); -my $offset = $input->param('iDisplayStart'); -my $results_per_page = $input->param('iDisplayLength') || -1; - -my $sorting_column = $input->param('iSortCol_0') || q{}; -$sorting_column = ( $sorting_column && $sort_columns[$sorting_column] ) ? $sort_columns[$sorting_column] : 'issuedate'; - -my $sorting_direction = $input->param('sSortDir_0') || q{}; -$sorting_direction = $sorting_direction eq 'asc' ? 'asc' : 'desc'; - -$results_per_page = undef if ( $results_per_page == -1 ); - -binmode STDOUT, ":encoding(UTF-8)"; -print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); +my $offset = $input->param('offset') || 0; +my $count = $input->param('count') || 10; my @parameters; my $sql = ' @@ -112,7 +99,9 @@ else { } push( @parameters, @borrowernumber ); -$sql .= " ORDER BY $sorting_column $sorting_direction "; +$sql .= " ORDER BY date_due DESC"; +$sql .= " LIMIT ?,?"; +push @parameters, $offset, $count; my $dbh = C4::Context->dbh(); my $sth = $dbh->prepare($sql); @@ -120,8 +109,7 @@ $sth->execute(@parameters); my $item_level_itypes = C4::Context->preference('item-level_itypes'); -my @checkouts_today; -my @checkouts_previous; +my @checkouts; while ( my $c = $sth->fetchrow_hashref() ) { my ($charge) = GetIssuingCharges( $c->{itemnumber}, $c->{borrowernumber} ); my $fine = GetFine( $c->{itemnumber}, $c->{borrowernumber} ); @@ -198,33 +186,27 @@ while ( my $c = $sth->fetchrow_hashref() ) { issued_today => !$c->{not_issued_today}, }; - if ( $c->{not_issued_today} ) { - push( @checkouts_previous, $checkout ); - } - else { - push( @checkouts_today, $checkout ); - } + push @checkouts, $checkout; } +my $todaysIssuesDefaultSortOrder = + C4::Context->preference('todaysIssuesDefaultSortOrder'); +my $previousIssuesDefaultSortOrder = + C4::Context->preference('previousIssuesDefaultSortOrder'); -@checkouts_today = sort { $a->{timestamp} cmp $b->{timestamp} } @checkouts_today; -@checkouts_today = reverse(@checkouts_today) - unless ( C4::Context->preference('todaysIssuesDefaultSortOrder') eq 'desc' ); - -@checkouts_previous = sort { $a->{date_due} cmp $b->{date_due} } @checkouts_previous; -@checkouts_previous = reverse(@checkouts_previous) - if ( C4::Context->preference('previousIssuesDefaultSortOrder') eq 'desc' ); - -my @checkouts = ( @checkouts_today, @checkouts_previous ); - -my $i = 1; -map { $_->{sort_order} = $i++ } @checkouts; +my $i = $offset + 1; +foreach my $c (@checkouts) { + my $sort_order = $i++; + if ($c->{issued_today} && $todaysIssuesDefaultSortOrder eq 'asc') { + $sort_order = - $sort_order; + } elsif (!$c->{issued_today} && $previousIssuesDefaultSortOrder eq 'asc') { + $sort_order = - $sort_order; + } -my $data; -$data->{'iTotalRecords'} = scalar @checkouts; -$data->{'iTotalDisplayRecords'} = scalar @checkouts; -$data->{'sEcho'} = $input->param('sEcho') || undef; -$data->{'aaData'} = \@checkouts; + $c->{sort_order} = $sort_order; +} -print to_json($data); +binmode STDOUT, ":encoding(UTF-8)"; +print $input->header( -type => 'application/json', -charset => 'UTF-8' ); +print to_json(\@checkouts); -- 1.9.1