From c8e49e18623bfdead312c2f72ec6341ae291795e Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 24 Feb 2017 09:51:59 +0100 Subject: [PATCH] Bug 15219: Fix date sorting when server-side processing is disabled Use DataTables 'columns' option instead of 'aoColumns' This allow more control on what data is used for display, sorting, filtering, ... A large part of this patch is about rewording things to better match the DataTables documentation. The real change is that "mRender": renderingFunc becomes "render": { "display": renderingFunc } So the return value of renderingFunc is now only used for display (not for filtering, sorting, ...) --- koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 310 +++++++++++++++------------ 1 file changed, 173 insertions(+), 137 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index 20d229cd5b..cddc37aee1 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -22,203 +22,200 @@ function disableGrouping(datatable) { } } -var mRenders = { - groupOrder: function (oData, sType, oObj) { - if ( oObj.issued_today ) { +var renderers = { + groupOrder: function (data, type, row) { + if ( row.issued_today ) { return "1"; } else { return "0"; } }, - groupName: function (oData, sType, oObj) { - if (oObj.issued_today) { + groupName: function (data, type, row) { + if (row.issued_today) { return "" + TODAYS_CHECKOUTS + ""; } else { return "" + PREVIOUS_CHECKOUTS + ""; } }, - dateDueFormatted: function (oData, sType, oObj) { - var due = oObj.date_due_formatted; + dateDueFormatted: function (data, type, row) { + var due = row.date_due_formatted; - if ( oObj.date_due_overdue ) { + if ( row.date_due_overdue ) { due = "" + due + ""; } - due = "" + due + ""; + due = "" + due + ""; - if ( oObj.lost ) { - due += "" + oObj.lost + ""; + if ( row.lost ) { + due += "" + row.lost + ""; } - if ( oObj.damaged ) { - due += "" + oObj.damaged + ""; + if ( row.damaged ) { + due += "" + row.damaged + ""; } return due; }, - title: function (oData, sType, oObj) { + title: function (data, type, row) { var title = "" - + oObj.title; + + row.title; - $.each(oObj.subtitle, function( index, value ) { + $.each(row.subtitle, function( index, value ) { title += " " + value.subfield; }); - if ( oObj.enumchron ) { - title += " (" + oObj.enumchron + ")"; + if ( row.enumchron ) { + title += " (" + row.enumchron + ")"; } title += ""; - if ( oObj.author ) { - title += " " + BY.replace( "_AUTHOR_", " " + oObj.author ); + if ( row.author ) { + title += " " + BY.replace( "_AUTHOR_", " " + row.author ); } - if ( oObj.itemnotes ) { + if ( row.itemnotes ) { var span_class = "text-muted"; - title += " - " + oObj.itemnotes + "" + title += " - " + row.itemnotes + "" } - if ( oObj.itemnotes_nonpublic ) { + if ( row.itemnotes_nonpublic ) { var span_class = "text-danger"; - if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) { - span_class = "circ-hlt"; - } - title += " - " + oObj.itemnotes_nonpublic + "" + title += " - " + row.itemnotes_nonpublic + "" } var onsite_checkout = ''; - if ( oObj.onsite_checkout == 1 ) { + if ( row.onsite_checkout == 1 ) { onsite_checkout += " (" + INHOUSE_USE + ")"; } title += " " + "" - + oObj.barcode + + row.barcode + "" + onsite_checkout; return title; }, - itemtype: function (oData, sType, oObj) { - return oObj.itemtype_description; + itemtype: function (data, type, row) { + return row.itemtype_description; }, - issuedate: function (oData, sType, oObj) { - return oObj.issuedate_formatted; + issuedate: function (data, type, row) { + return row.issuedate_formatted; }, - branch: function (oData, sType, oObj) { - return oObj.branchname; + branch: function (data, type, row) { + return row.branchname; }, - charge: function (oData, sType, oObj) { - if (!oObj.charge) oObj.charge = 0; - return '' + parseFloat(oObj.charge).toFixed(2) + ''; + charge: function (data, type, row) { + if (!row.charge) row.charge = 0; + return '' + parseFloat(row.charge).toFixed(2) + ''; }, - fine: function (oData, sType, oObj) { - if (!oObj.fine) oObj.fine = 0; - return '' + parseFloat(oObj.fine).toFixed(2) + ''; + fine: function (data, type, row) { + if (!row.fine) row.fine = 0; + return '' + parseFloat(row.fine).toFixed(2) + ''; }, - price: function (oData, sType, oObj) { - if (!oObj.price) oObj.price = 0; - return parseFloat(oObj.price).toFixed(2); + price: function (data, type, row) { + if (!row.price) row.price = 0; + return parseFloat(row.price).toFixed(2); }, - renew: function (oData, sType, oObj) { + renew: function (data, type, row) { var content = ""; var span_style = ""; var span_class = ""; content += ""; - content += "" + oObj.renewals_count + ""; + content += "" + row.renewals_count + ""; - if ( oObj.can_renew ) { + if ( row.can_renew ) { // Do nothing - } else if ( oObj.can_renew_error == "on_reserve" ) { + } else if ( row.can_renew_error == "on_reserve" ) { content += "" - + "" + ON_HOLD + "" + + "" + ON_HOLD + "" + ""; span_style = "display: none"; span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "too_many" ) { + } else if ( row.can_renew_error == "too_many" ) { content += "" + NOT_RENEWABLE + ""; span_style = "display: none"; span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "restriction" ) { + } else if ( row.can_renew_error == "restriction" ) { content += "" + NOT_RENEWABLE_RESTRICTION + ""; span_style = "display: none"; span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "overdue" ) { + } else if ( row.can_renew_error == "overdue" ) { content += "" + NOT_RENEWABLE_OVERDUE + ""; span_style = "display: none"; span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "too_soon" ) { + } else if ( row.can_renew_error == "too_soon" ) { content += "" - + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date ) + + NOT_RENEWABLE_TOO_SOON.format( row.can_renew_date ) + ""; span_style = "display: none"; span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "auto_too_soon" ) { + } else if ( row.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_too_late" ) { + } else if ( row.can_renew_error == "auto_too_late" ) { content += "" + NOT_RENEWABLE_AUTO_TOO_LATE + ""; span_style = "display: none"; span_class = "renewals-allowed"; - } else if ( oObj.can_renew_error == "auto_renew" ) { + } else if ( row.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" ) { + } else if ( row.can_renew_error == "onsite_checkout" ) { // Don't display something if it's an onsite checkout } else { content += "" - + oObj.can_renew_error + + row.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 ); + var can_force_renew = ( row.onsite_checkout == 0 ) && ( row.can_renew_error != "on_reserve" ); + var can_renew = ( row.renewals_remaining > 0 && !row.can_renew_error ); if ( can_renew || can_force_renew ) { content += "" + "" + content += "class='renew' id='renew_" + row.itemnumber + "' name='renew' value='" + row.itemnumber +"'/>" + ""; content += "(" - + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed ) + + RENEWALS_REMAINING.format( row.renewals_remaining, row.renewals_allowed ) + ")"; } @@ -226,22 +223,22 @@ var mRenders = { return content; }, - checkin: function (oData, sType, oObj) { - if (oObj.can_renew_error == "on_reserve") { - return "" + ON_HOLD + ""; + checkin: function (data, type, row) { + if (row.can_renew_error == "on_reserve") { + return "" + ON_HOLD + ""; } else { - return ""; + return ""; } }, - export: function (oData, sType, oObj) { - var s = ""; + export: function (data, type, row) { + var s = ""; - s += ""; + s += ""; return s; }, - patron: function (oData, sType, oObj) { - return "" - + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")" + patron: function (data, type, row) { + return "" + + row.borrower.firstname + " " + row.borrower.surname + " (" + row.borrower.cardnumber + ")" } }; @@ -429,14 +426,14 @@ $(document).ready(function() { "sPaginationType": "four_button", "dom": 'B<"clearfix"><"top pager"ilp>rt', "aaSorting": [], - "aoColumns": [ + "columns": [ { - "mData": "issued_today", - "mRender": mRenders.groupOrder + "data": "issued_today", + "render": renderers.groupOrder }, { - "mData": function (oObj) { - if (oObj.issued_today) { + "data": function (row) { + if (row.issued_today) { return "" + TODAYS_CHECKOUTS + ""; } else { return "" + PREVIOUS_CHECKOUTS + ""; @@ -444,57 +441,82 @@ $(document).ready(function() { } }, { - "mData": "date_due", - "mRender": mRenders.dateDueFormatted + "data": "date_due", + "render": { + "display": renderers.dateDueFormatted + } }, { - "mData": "title", - "mRender": mRenders.title + "data": "title", + "render": { + "display": renderers.title + } }, { - "mData": "itemtype", - "mRender": mRenders.itemtype + "data": "itemtype", + "render": { + "display": renderers.itemtype + } }, - { "mData": "location" }, - { "mData": "homebranch" }, + { "data": "location" }, + { "data": "homebranch" }, { - "mData": "issuedate", - "mRender": mRenders.issuedate + "data": "issuedate", + "render": { + "display": renderers.issuedate + } }, { - "mData": "branchcode", - "mRender": mRenders.branch + "data": "branchcode", + "render": { + "display": renderers.branch + } }, - { "mData": "itemcallnumber" }, + { "data": "itemcallnumber" }, { - "mData": "charge", - "mRender": mRenders.charge, - "bSortable": ServerSideCheckoutsTables ? false : true + "data": "charge", + "render": { + "display": renderers.charge + }, + "orderable": ServerSideCheckoutsTables ? false : true }, { - "mData": "fine", - "mRender": mRenders.fine, - "bSortable": ServerSideCheckoutsTables ? false : true + "data": "fine", + "render": { + "display": renderers.fine + }, + "orderable": ServerSideCheckoutsTables ? false : true }, { - "mData": "replacementprice", - "mRender": mRenders.price, - "bSortable": ServerSideCheckoutsTables ? false : true + "data": "price", + "render": { + "display": renderers.price + }, + "orderable": ServerSideCheckoutsTables ? false : true }, { - "bVisible": AllowCirculate ? true : false, - "mRender": mRenders.renew, - "bSortable": false + "data": null, + "render": { + "display": renderers.renew + }, + "visible": AllowCirculate ? true : false, + "orderable": false }, { - "bVisible": AllowCirculate ? true : false, - "mRender": mRenders.checkin, - "bSortable": false + "data": null, + "render": { + "display": renderers.checkin + }, + "visible": AllowCirculate ? true : false, + "orderable": false }, { - "bVisible": exports_enabled ? true : false, - "bSortable": false, - "mRender": mRenders.export + "data": null, + "render": { + "display": renderers.export + }, + "visible": exports_enabled ? true : false, + "orderable": false } ], "fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) { @@ -561,42 +583,56 @@ $(document).ready(function() { }, "bPaginate": true, "sPaginationType": "four_button", - "aoColumns": [ + "columns": [ { - "mData": "date_due", - "mRender": mRenders.dateDueFormatted + "data": "date_due", + "render": { + "display": renderers.dateDueFormatted + } }, { - "mData": "title", - "mRender": mRenders.title, + "data": "title", + "render": { + "display": renderers.title + } }, - { "mData": "itemtype" }, - { "mData": "location" }, + { "data": "itemtype" }, + { "data": "location" }, { - "mData": "issuedate", - "mRender": mRenders.issuedate + "data": "issuedate", + "render": { + "display": renderers.issuedate + } }, - { "mData": "branchname" }, - { "mData": "itemcallnumber" }, + { "data": "branchname" }, + { "data": "itemcallnumber" }, { - "mData": "charge", - "mRender": mRenders.charge, - "bSortable": ServerSideCheckoutsTables ? false : true + "data": "charge", + "render": { + "display": renderers.charge + }, + "orderable": ServerSideCheckoutsTables ? false : true }, { - "mData": "fine", - "mRender": mRenders.fine, - "bSortable": ServerSideCheckoutsTables ? false : true + "data": "fine", + "render": { + "display": renderers.fine + }, + "orderable": ServerSideCheckoutsTables ? false : true }, { - "mData": "replacementprice", - "mRender": mRenders.price, - "bSortable": ServerSideCheckoutsTables ? false : true + "data": "replacementprice", + "render": { + "display": renderers.price + }, + "orderable": ServerSideCheckoutsTables ? false : true }, { - "mData": "borrowernumber", - "mRender": mRenders.patron, - "bSortable": ServerSideCheckoutsTables ? false : true + "data": "borrowernumber", + "render": { + "display": renderers.patron + }, + "orderable": ServerSideCheckoutsTables ? false : true } ] }, relatives_columns_settings); -- 2.11.0