From 19bd71af6a9be8ea563c91c2fa11d103387fb0e3 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Wed, 26 Jan 2022 12:18:55 +0000 Subject: [PATCH] Bug 29949: Remove use of title-numeric sorting routine from OPAC datatables JS This patch removes the use of a specific "title-numeric" sorting routine from the DataTables configuration of the "Most popular" table. We can use a "data-order" attribute instead. The patch also removes the now unused code from our custom DataTables JS file in both the OPAC and the staff interface (where it was unused). To test, apply the patch and make sure the OpacTopissue system preference is enabled. - In the OPAC, view the "Most popular" page. - Change the filter settings, if necessary, to get multiple results. - In the results table, confirm that sorting by number of checkouts still works correctly. A search of the code for instances of "title-numeric" should return only one in a comment in the official DataTables library. --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 27 ------------------- .../bootstrap/en/modules/opac-topissues.tt | 9 +++---- .../opac-tmpl/bootstrap/js/datatables.js | 27 ------------------- 3 files changed, 4 insertions(+), 59 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index bae315cf04..c95a972328 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -314,33 +314,6 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { } } ); -/* Plugin to allow sorting on numeric data stored in a span's title attribute - * - * Ex: - * [% formatted currency %] - * - * - * In DataTables config: - * "aoColumns": [ - * { "sType": "title-numeric" }, - * ] - * http://datatables.net/plug-ins/sorting#hidden_title - */ -jQuery.extend( jQuery.fn.dataTableExt.oSort, { - "title-numeric-pre": function ( a ) { - var x = a.match(/title="*(-?[0-9\.]+)/)[1]; - return parseFloat( x ); - }, - - "title-numeric-asc": function ( a, b ) { - return ((a < b) ? -1 : ((a > b) ? 1 : 0)); - }, - - "title-numeric-desc": function ( a, b ) { - return ((a < b) ? 1 : ((a > b) ? -1 : 0)); - } -} ); - (function() { /* Plugin to allow text sorting to ignore articles diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt index 8129451dd4..3cdc6a417a 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt @@ -88,7 +88,7 @@ Title [% IF ( ccodesearch ) %]Collection[% ELSE %]Item type[% END %] - Checkouts + Checkouts [% IF Koha.Preference( 'opacuserlogin' ) == 1 %]   [% END %] @@ -118,9 +118,9 @@ [% ItemTypes.GetDescription(result.itemtype) | html %] [% END %] - + Checkouts: - [% result.count | html %] + [% result.count | html %] [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] @@ -153,8 +153,7 @@ "sorting": [[2, "desc"]], "columnDefs": [ { "sortable": false, "searchable": false, 'targets': [ 'NoSort' ] }, - { "type": "anti-the", "targets" : [ "anti-the" ] }, - { "type": "title-numeric", "targets" : [ "title-num"] }, + { "type": "anti-the", "targets" : [ "anti-the" ] } ] })); }); diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js index 5d3a543942..ea0f3773d2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js @@ -70,33 +70,6 @@ $.fn.dataTable.ext.buttons.clearFilter = { } }; -/* Plugin to allow sorting on numeric data stored in a span's title attribute - * - * Ex: - * [% formatted currency %] - * - * - * In DataTables config: - * "aoColumns": [ - * { "sType": "title-numeric" }, - * ] - * http://datatables.net/plug-ins/sorting#hidden_title - */ -jQuery.extend( jQuery.fn.dataTableExt.oSort, { - "title-numeric-pre": function ( a ) { - var x = a.match(/title="*(-?[0-9\.]+)/)[1]; - return parseFloat( x ); - }, - - "title-numeric-asc": function ( a, b ) { - return ((a < b) ? -1 : ((a > b) ? 1 : 0)); - }, - - "title-numeric-desc": function ( a, b ) { - return ((a < b) ? 1 : ((a > b) ? -1 : 0)); - } -} ); - (function() { /* Plugin to allow text sorting to ignore articles -- 2.20.1