From cbde9c1c068b0efa71c1afd49c2e50e6361a4e03 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 12 Nov 2012 15:29:28 -0500 Subject: [PATCH] [Signed off] Bug 9061 - DataTables date sort does not work with date in uk format (dd/mm/yyyy) The DataTables plugin doesn't include native support for sorting date in uk/euro format (dd/mm/yyyy). This patch adds a plugin to be optionally included in cases where the Koha dateformat preference is set to "metric." The patron circulation history page is the only page affected by this patch. If it is found to be working well I will submit follow-ups to cover other instances where sorting by date occurs. To test, load the patron circulation history page (members/readingrec.pl) for a patron with a circulation history. Sorting by "date," "checked out on," "date due," and "Return date" should work correctly with under all three dateformat settings. Signed-off-by: Melia Meggs --- .../prog/en/js/datatables.date-euro.js | 44 ++++++++++++++++++++ .../prog/en/modules/members/readingrec.tt | 8 +++- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/datatables.date-euro.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.date-euro.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.date-euro.js new file mode 100644 index 0000000..e744d0b --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.date-euro.js @@ -0,0 +1,44 @@ +/* Adapted from sorting plugin found at http://datatables.net/plug-ins/sorting, + "Date (dd/mm/YYY hh:ii:ss)," by Ronan Guilloux. Original plugin did not + account for variation in input string */ + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "date-euro-pre": function ( a ) { + // function should work with strings like "dd/mm/yyyy hh:mm:ss" or "dd/mm/yyyy" + // function doesn't validate the date, just checks for valid structure + var x; + var dateTimeParts; + var dateParts; + var timeParts; + if ($.trim(a) !== '') { + dateTimeParts = $.trim(a).split(' '); + dateParts = dateTimeParts[0].split('/'); + if( dateParts.length == 3 ){ + // validish date format + if( dateTimeParts.length > 1){ + // there is a time portion + timeParts = dateTimeParts[1].split(':'); + if( timeParts.length > 1 ){ + // validish time portion + x = (dateParts[2] + dateParts[1] + dateParts[0] + timeParts[0] + timeParts[1] + timeParts[2]) * 1; + } + } else { + x = (dateParts[2] + dateParts[1] + dateParts[0]) * 1; + } + } else { + x = 10000000000000; // = l'an 1000 ... + } + } else { + x = 10000000000000; // = l'an 1000 ... + } + return x; + }, + + "date-euro-asc": function ( a, b ) { + return a - b; + }, + + "date-euro-desc": function ( a, b ) { + return b - a; + } +} ); \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt index b7c5f53..1b86667 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt @@ -1,15 +1,19 @@ [% USE KohaDates %] [% INCLUDE 'doc-head-open.inc' %] -Circulation History for [% INCLUDE 'patron-title.inc' %] +Circulation history for [% INCLUDE 'patron-title.inc' %] [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'datatables-strings.inc' %] +[% IF ( dateformat_metric ) %][% END %] -- 1.7.2.5