From 2c414ad6d5ece72c98dab52a137edcb54a77f1bd Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 9 Feb 2017 16:19:42 +0100 Subject: [PATCH] Bug 15235: Add column filters to checkouts table This adds a switch that allow to enable/disable column filters on checkouts table (disabled by default) Depends on bug 15219 --- C4/Utils/DataTables.pm | 44 +++++++++------ .../plugins/jquery.dataTables.columnFilter.js | 2 +- koha-tmpl/intranet-tmpl/prog/css/datatables.css | 10 ++++ .../prog/en/includes/checkouts-table.inc | 18 +++++++ .../intranet-tmpl/prog/en/includes/strings.inc | 1 + .../prog/en/modules/circ/circulation.tt | 1 + .../prog/en/modules/members/moremember.tt | 1 + koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 62 ++++++++++++++++++++++ svc/checkouts | 6 +++ 9 files changed, 129 insertions(+), 16 deletions(-) diff --git a/C4/Utils/DataTables.pm b/C4/Utils/DataTables.pm index e6fc1ccbcf..62629c32f2 100644 --- a/C4/Utils/DataTables.pm +++ b/C4/Utils/DataTables.pm @@ -20,6 +20,8 @@ package C4::Utils::DataTables; use Modern::Perl; require Exporter; +use Koha::DateUtils; + use vars qw(@ISA @EXPORT); BEGIN { @@ -138,14 +140,10 @@ sub dt_build_having { my $mDataProp = $param->{'mDataProp_'.$i}; my @filter_fields = $param->{$mDataProp.'_filteron'} ? split(' ', $param->{$mDataProp.'_filteron'}) - : (); - if(@filter_fields > 0) { - foreach my $field (@filter_fields) { - push @gFilters, " $field LIKE ? "; - push @gParams, "%$sSearch%"; - } - } else { - push @gFilters, " $mDataProp LIKE ? "; + : ($mDataProp); + + foreach my $field (@filter_fields) { + push @gFilters, " $field LIKE ? "; push @gParams, "%$sSearch%"; } } @@ -163,17 +161,33 @@ sub dt_build_having { my $mDataProp = $param->{'mDataProp_'.$i}; my @filter_fields = $param->{$mDataProp.'_filteron'} ? split(' ', $param->{$mDataProp.'_filteron'}) - : (); - if(@filter_fields > 0) { - my @localfilters; - foreach my $field (@filter_fields) { + : ($mDataProp); + + my @localfilters; + foreach my $field (@filter_fields) { + if ($sSearch =~ /^(.*)\~(.*)$/) { + my ($from, $to) = ($1, $2); + my @datefilters; + if ($from) { + my $date = dt_from_string($from); + push @datefilters, " $field >= ? "; + push @params, $date->ymd; + } + if ($to) { + my $date = dt_from_string($to); + push @datefilters, " $field <= ? "; + push @params, $date->ymd; + } + if (@datefilters) { + push @localfilters, ' (' . join(' AND ', @datefilters) . ') '; + } + } else { push @localfilters, " $field LIKE ? "; push @params, "%$sSearch%"; } + } + if (@localfilters) { push @filters, " ( ". join(" OR ", @localfilters) ." ) "; - } else { - push @filters, " $mDataProp LIKE ? "; - push @params, "%$sSearch%"; } } $i++; diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.columnFilter.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.columnFilter.js index 89343f576f..342ecd0235 100644 --- a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.columnFilter.js +++ b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.columnFilter.js @@ -250,7 +250,6 @@ //th.html(_fnRangeLabelPart(0)); var sFromId = oTable.attr("id") + '_range_from_' + i; var from = $(''); - from.datepicker(); //th.append(from); //th.append(_fnRangeLabelPart(1)); var sToId = oTable.attr("id") + '_range_to_' + i; @@ -275,6 +274,7 @@ th.wrapInner(''); + from.datepicker(); to.datepicker(); var index = i; aiCustomSearch_Indexes.push(i); diff --git a/koha-tmpl/intranet-tmpl/prog/css/datatables.css b/koha-tmpl/intranet-tmpl/prog/css/datatables.css index 71fdb6b2ec..05f28e31d9 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/datatables.css +++ b/koha-tmpl/intranet-tmpl/prog/css/datatables.css @@ -257,6 +257,16 @@ span.filter_column > input[type="text"] { box-sizing: border-box; } +span.filter_column.filter_date_range { + white-space: nowrap; +} + +span.filter_column > input.date_range_filter { + font-size: 80%; + width: 6em; + padding: 0; +} + /* Row grouping */ td.group, table.group td.group { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc index 66c1ba0040..7f5f644c5a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc @@ -9,6 +9,24 @@
+ + + + + + + + + + + + + + + + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc index 3b58d4e0fa..5401d3379b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc @@ -42,5 +42,6 @@ var RESUME_HOLD_ERROR_NOT_FOUND = _("Unable to resume, hold not found"); var CURRENT = _(" (current) "); var GROUP_TODAYS_CHECKOUTS = _("Group today's checkouts"); + var SHOW_COLUMN_FILTERS = _("Show column filters"); //]]> 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 d354bb3bd0..cd3fccc1e7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -27,6 +27,7 @@ [% INCLUDE 'timepicker.inc' %] + [% INCLUDE 'checkouts.js.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 62e1fa12b4..16457c0441 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -24,6 +24,7 @@ [% INCLUDE 'timepicker.inc' %] + [% INCLUDE 'checkouts.js.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index cddc37aee1..6836dc9391 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -22,6 +22,49 @@ function disableGrouping(datatable) { } } +function enableFiltering(datatable) { + var oSettings = datatable.fnSettings(); + var filters_row = $(oSettings.nTable).find('thead tr.filters_row'); + if (!filters_row.hasClass('columnFilter')) { + datatable.columnFilter({ + sPlaceHolder: "head:after", + bUseColVis: true, + sRangeFormat: "From {from}
to {to}", + aoColumns: [ + null, + null, + { type: "date-range" }, + { type: "text" }, + { type: "text" }, + { type: "text" }, + { type: "text" }, + { type: "date-range" }, + { type: "text" }, + { type: "text" }, + null, + null, + null, + null, + null, + null, + null + ] + }); + filters_row.addClass('columnFilter'); + } + filters_row.show(); +} + +function disableFiltering(datatable) { + var oSettings = datatable.fnSettings(); + var filters_row = $(oSettings.nTable).find('thead tr.filters_row'); + filters_row.find('input[type="text"]') + .val('') // Empty filter text boxes + .trigger('keyup') // Filter (display all rows) + .trigger('blur'); // Reset value to the column name + filters_row.hide(); +} + var renderers = { groupOrder: function (data, type, row) { if ( row.issued_today ) { @@ -556,6 +599,25 @@ $(document).ready(function() { .append('') .appendTo('#issues-table_wrapper .top.pager'); + var filteringSwitch = $('') + .attr('id', 'issues-table-filtering-switch') + .css('vertical-align', 'middle') + .change(function() { + if ($(this).is(':checked')) { + enableFiltering(issuesTable); + } else { + disableFiltering(issuesTable); + } + }); + $('
') + .css('float', 'left') + .css('padding', '0.3em 0.5em') + .css('line-height', '1.9em') + .append(filteringSwitch) + .append(' ') + .append('') + .appendTo('#issues-table_wrapper .top.pager'); + if ( $("#issues-table").length ) { $("#issues-table_processing").position({ of: $( "#issues-table" ), diff --git a/svc/checkouts b/svc/checkouts index c7c8a6a3f6..918d5f097a 100755 --- a/svc/checkouts +++ b/svc/checkouts @@ -51,6 +51,7 @@ my $count = $input->param('iDisplayLength'); my %params = dt_get_params($input); my $orderby = dt_build_orderby(\%params); +my ($having, $having_params) = dt_build_having(\%params); my $todaysIssuesDefaultSortOrder = C4::Context->preference('todaysIssuesDefaultSortOrder'); @@ -127,6 +128,11 @@ if ( @borrowernumber == 1 ) { $sql .= $borrowernumber_sql; push( @parameters, @borrowernumber ); +if (@$having) { + $sql .= ' HAVING ' . join (' AND ', @$having); + push @parameters, @$having_params; +} + $sql .= " $orderby"; if ($count && $count > 0) { -- 2.11.0