From fead2a72b0a6e296e93ab62d3b7d1f336323ee23 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Dec 2014 14:01:54 +0100 Subject: [PATCH] Bug 13419: Add filters on the list table Tested together with patch #1, works as expected Signed-off-by: Marc Veron Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Utils/DataTables/VirtualShelves.pm | 23 +++++-------- .../intranet-tmpl/prog/en/js/datatables.js | 3 ++ .../prog/en/modules/virtualshelves/shelves.tt | 32 +++++++++++++++++-- .../virtualshelves/tables/shelves_results.tt | 2 +- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/C4/Utils/DataTables/VirtualShelves.pm b/C4/Utils/DataTables/VirtualShelves.pm index 1bebee349d..97c5611ee9 100644 --- a/C4/Utils/DataTables/VirtualShelves.pm +++ b/C4/Utils/DataTables/VirtualShelves.pm @@ -62,24 +62,20 @@ sub search { if ( defined $shelfname and $shelfname ne '' ) { push @where_strs, 'shelfname LIKE ?'; - push @args, 'shelfname%'; - } - if ( defined $count and $count ne '' ) { - push @where_strs, 'count = ?'; - push @args, $count; + push @args, "%$shelfname%"; } if ( defined $owner and $owner ne '' ) { - push @where_strs, 'owner LIKE ?'; - push @args, 'owner%'; - # FIXME search borronumber by name?? + #push @where_strs, 'owner LIKE ?'; + #push @args, "$owner%"; # WHERE category=1 AND (vs.owner=? OR sh.borrowernumber=?); + push @where_strs, '( bo.firstname LIKE ? OR bo.surname LIKE ? )'; + push @args, "%$owner%", "%$owner%"; } if ( defined $sortby and $sortby ne '' ) { push @where_strs, 'sortfield = ?'; - push @args, 'sortfield'; + push @args, $sortby; } - push @where_strs, 'category = ?'; push @args, $type; @@ -91,7 +87,7 @@ sub search { my $where; $where = " WHERE " . join (" AND ", @where_strs) if @where_strs; my $orderby = dt_build_orderby($dt_params); - $orderby =~ s|shelfnumber|vs.shelfnumber|; + $orderby =~ s|shelfnumber|vs.shelfnumber| if $orderby; my $limit; # If iDisplayLength == -1, we want to display all shelves @@ -115,10 +111,7 @@ sub search { ($orderby ? $orderby : ""), ($limit ? $limit : "") ); - my $sth = $dbh->prepare($query); - $sth->execute(@args); - - my $shelves = $sth->fetchall_arrayref({}); + my $shelves = $dbh->selectall_arrayref( $query, { Slice => {} }, @args ); # Get the iTotalDisplayRecords DataTable variable $query = "SELECT COUNT(vs.shelfnumber) " . $from_total . ($where ? $where : ""); diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js index b3d97fe372..e42918c4f7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js @@ -130,6 +130,9 @@ jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay }, iDelay); } }); + $(table).find("select."+sClass).on('change', function() { + table.fnFilter($(this).val(), $(this).attr('data-column_num')); + }); } // Useful if you want to filter on dates with 2 inputs (start date and end date) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index 7460d1cdef..a51f6b2226 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -3,6 +3,7 @@ [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'datatables.inc' %] + [% IF ( viewshelf ) %] @@ -24,8 +25,16 @@ $(document).ready(function(){ aoData.push({ 'name': 'type', 'value': type, - }, - { + },{ + 'name': 'shelfname', + 'value': $("#searchshelfname_filter").val(), + },{ + 'name': 'owner', + 'value': $("#searchowner_filter").val(), + },{ + 'name': 'sortby', + 'value': $("#searchsortby_filter").val(), + },{ 'name': 'template_path', 'value': 'virtualshelves/tables/shelves_results.tt', }); @@ -52,8 +61,9 @@ $(document).ready(function(){ ], 'bAutoWidth': false, 'sPaginationType': 'full_numbers', + 'bFilter': false, "bProcessing": true, - 'bFilter': false + "bSortCellsTop": true })); dtListResults.fnAddFilters("filter", 750); @@ -595,6 +605,22 @@ function placeHold () { Sort by Actions + + + + + + + + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt index 65fec87b6b..cfdd67950a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/tables/shelves_results.tt @@ -8,7 +8,7 @@ "dt_type": "[% data.type %]", "dt_shelfname": - "[% data.shelfname %]", + "[% data.shelfname %]", "dt_count": "[% data.count %] item(s)", "dt_owner": -- 2.39.5