From ec9fc2fce4fef573cc337ff3de9b102d6dad3ded Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 21 Mar 2013 11:31:43 -0400 Subject: [PATCH] Bug 9887 [Revised] Use DataTables on circulation page 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. Revision adds missing include for table footer when there are previous checkouts and removes   from empty table header cells which were messing up auto-detection of numeric data. The global CSS for table borders has been tightened up to improve handling of alternating row colors in DataTables-sorted tables. Signed-off-by: Chris Cormack Signed-off-by: Katrin Fischer All tests and QA script pass. Note: Don't forget it's the checkout tab and to turn on the preference to allow sorting there. Also, while checkouts sorts dates correctly, sorting on the details tabs was not always correct in my tests. Signed-off-by: Jared Camins-Esakov --- circ/circulation.pl | 2 + .../prog/en/css/staff-global.css | 11 +- .../intranet-tmpl/prog/en/js/datatables.js | 25 +++- .../prog/en/modules/circ/circulation.tt | 120 ++++++++++-------- 4 files changed, 101 insertions(+), 57 deletions(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index 9c55595272..b664d4989a 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -466,7 +466,9 @@ sub build_issue_data { $totalprice += $it->{'replacementprice'} || 0; $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/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 76130538a1..fcb47dc390 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -256,15 +256,18 @@ table+table { .highlighted-row { background-color: orange !important } -tr.highlight td, tr.highlight th, tr.odd td { +tr.highlight td, +tr.highlight th, +tr.odd td, +tr.odd.highlight td { background-color : #F3F3F3; - border : 1px solid #DDDDDD; - border-right : 1px solid #DDDDDD; + border : 1px solid #BCBCBC; + border-right : 1px solid #BCBCBC; } tr.even td, tr.even.highlight td { background-color: #FFF; - border-right : 1px solid #DDDDDD; + border-right : 1px solid #BCBCBC; } td.od { diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js index b350211fbe..703944ea75 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 82fcdf8fdb..b7f7c4c0e4 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 %]