Skip to content

Commit

Permalink
Bug 13419: Add filters on the list table
Browse files Browse the repository at this point in the history
Tested together with patch #1, works as expected
Signed-off-by: Marc Veron <veron@veron.ch>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
  • Loading branch information
joubu authored and tomascohen committed Apr 22, 2015
1 parent 87b6d46 commit fead2a7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
23 changes: 8 additions & 15 deletions C4/Utils/DataTables/VirtualShelves.pm
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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 : "");
Expand Down
3 changes: 3 additions & 0 deletions koha-tmpl/intranet-tmpl/prog/en/js/datatables.js
Expand Up @@ -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)
Expand Down
32 changes: 29 additions & 3 deletions koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
Expand Up @@ -3,6 +3,7 @@
[% INCLUDE 'doc-head-close.inc' %]
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
[% INCLUDE 'datatables.inc' %]
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.columnFilter.js"></script>
[% IF ( viewshelf ) %]
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.fixFloat.js"></script>
Expand All @@ -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',
});
Expand All @@ -52,8 +61,9 @@ $(document).ready(function(){
],
'bAutoWidth': false,
'sPaginationType': 'full_numbers',
'bFilter': false,
"bProcessing": true,
'bFilter': false
"bSortCellsTop": true
}));

dtListResults.fnAddFilters("filter", 750);
Expand Down Expand Up @@ -595,6 +605,22 @@ function placeHold () {
<th>Sort by</th>
<th>Actions</th>
</tr>
<tr class="filters_row">
<th></th>
<th><input class="filter text_filter" id="searchshelfname_filter" placeholder="List name"></th>
<th></th>
<th><input class="filter text_filter" id="searchowner_filter" placeholder="Owner"></th>
<th>
<select class="filter text_filter" id="searchsortby_filter">
<option value=""></option>
<option value="title">Title</option>
<option value="author">Author</option>
<option value="copyrightdate">Copyrightdate</option>
<option value="itemcallnumber">Call number</option>
</select>
</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
Expand Down
Expand Up @@ -8,7 +8,7 @@
"dt_type":
"[% data.type %]",
"dt_shelfname":
"<a href='cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% data.shelfnumber %]'>[% data.shelfname %]</a>",
"<a href='/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=[% data.shelfnumber %]'>[% data.shelfname %]</a>",
"dt_count":
"[% data.count %] item(s)",
"dt_owner":
Expand Down

0 comments on commit fead2a7

Please sign in to comment.