From 01bdbabf966deaf3e356c763777052acb629e291 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 21 Mar 2013 11:31:43 -0400 Subject: [PATCH] Bug 9887 - Use DataTables on circulation page Content-Type: text/plain; charset="utf-8" The circulation page, when the UseTablesortForCirc preference is enabled, uses the old tablesorter plugin. It should use DataTables instead. This patch removes references to the tablesorter plugin and makes these changes to enable use of DataTables: - Pass two new unformatted date variables to the template from circulation.pl so that sorting can be performed on this data. - Add DataTables configurations for the table of checkouts and the table of relatives' checkouts. - Add a new plugin to the main DataTables configuration script to allow sorting on data embedded in a 's 'title' attribute. - Add s to each table with a title attribute containing the unformatted date data which DataTables needs to perform correct sorting. This eliminates the need for a special sorting algorithm to accomodate various date and datetime formatting options. - Set a template variable for checking whether circ exports are enabled. This reduces repetition. DataTables configuration changes based on how many columns are present. To test, load the circulation page for patrons who match various conditions: - Having only checkouts from today - Having checkouts from today and previous days - Having checkouts only from previous days - Having relatives who have checkouts (from today, from previous days, from both) Test these situations with UseTablesortForCirc enabled and disabled. Test these situations with circ exports enabled or disabled (with ExportRemoveFields filled or empty, for instance). Sorting should work correctly on all columns with the dateformat preference set to any option. All other circulation functions should work normally. --- circ/circulation.pl | 2 + koha-tmpl/intranet-tmpl/prog/en/js/datatables.js | 25 +++- .../prog/en/modules/circ/circulation.tt | 119 +++++++++++--------- 3 files changed, 93 insertions(+), 53 deletions(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index 24b1576..455f47b 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -464,7 +464,9 @@ sub build_issue_data { $totalprice += $it->{'replacementprice'}; $it->{'itemtype'} = $itemtypeinfo->{'description'}; $it->{'itemtype_image'} = $itemtypeinfo->{'imageurl'}; + $it->{'dd_sort'} = $it->{'date_due'}; $it->{'dd'} = output_pref($it->{'date_due'}); + $it->{'displaydate_sort'} = $it->{'issuedate'}; $it->{'displaydate'} = output_pref($it->{'issuedate'}); #$it->{'od'} = ( $it->{'date_due'} lt $todaysdate ) ? 1 : 0 ; $it->{'od'} = $it->{'overdue'}; diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js index b350211..703944e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js @@ -470,4 +470,27 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { } } ); -}()); \ No newline at end of file +}()); +/* Plugin to allow sorting on data stored in a span's title attribute + * + * Ex: [% formatted_date %] + * + * In DataTables config: + * "aoColumns": [ + * { "sType": "title-string" }, + * ] + * http://datatables.net/plug-ins/sorting#hidden_title_string + */ +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "title-string-pre": function ( a ) { + return a.match(/title="(.*?)"/)[1].toLowerCase(); + }, + + "title-string-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "title-string-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +} ); \ No newline at end of file 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 19b5bd7..cae3759 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -1,4 +1,7 @@ [% USE KohaDates %] +[% IF ( export_remove_fields OR export_with_csv_profile ) %] + [% SET exports_enabled = 1 %] +[% END %] [% USE KohaAuthorisedValues %] [% INCLUDE 'doc-head-open.inc' %] [% SET destination = "circ" %] @@ -9,45 +12,57 @@ [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'calendar.inc' %] -[% IF ( UseTablesortForCirc ) %][% END %] +[% IF ( UseTablesortForCirc ) %] + +[% INCLUDE 'datatables-strings.inc' %] +[% END %]