Bug 25279: (QA follow-up) Original behaviour

This patch does the following things:
- Uses a call to Koha::Cities->search(*)->count to display the same
  message we displayed before when no city was found/defined (datatable
  not rendered at all).
- Restores the main search box functionality, the passed param is used
  to query on the city name with wildcards on both sides, for (a)
  counting results and for (b) apending to the API call with the same
  behaviour.

The only missing bit from QA is HTML/URI escaping values from cells, but
this is going to happen at DT level most sure.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2020-05-05 18:55:49 -03:00 committed by Martin Renvoize
parent 71e3d02ffb
commit 64de96c612
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 42 additions and 20 deletions

View File

@ -27,7 +27,7 @@ use C4::Output;
use Koha::Cities;
my $input = new CGI;
my $searchfield = $input->param('city_name') // q||;
my $city_name = $input->param('city_name') // q||;
my $cityid = $input->param('cityid');
my $op = $input->param('op') || 'list';
my @messages;
@ -84,8 +84,8 @@ if ( $op eq 'add_form' ) {
push @messages, { type => 'message', code => 'success_on_insert' };
}
}
$searchfield = q||;
$op = 'list';
$city_name = q||;
$op = 'list';
} elsif ( $op eq 'delete_confirm' ) {
my $city = Koha::Cities->find($cityid);
$template->param( city => $city, );
@ -101,9 +101,16 @@ if ( $op eq 'add_form' ) {
$op = 'list';
}
if ( $op eq 'list' ) {
my $filter = {};
$filter->{city_name} = { -like => '%'.$city_name.'%' }
if $city_name;
$template->param( cities_count => Koha::Cities->search($filter)->count );
}
$template->param(
cityid => $cityid,
searchfield => $searchfield,
city_name_filter => $city_name,
messages => \@messages,
op => $op,
);

View File

@ -129,22 +129,28 @@
</div>
<h2>Cities</h2>
[% IF searchfield %]
Searching: [% searchfield | html %]
[% IF city_name_filter %]
Searching: [% city_name_filter | html %]
[% END %]
<table id="table_cities">
<thead>
<tr>
<th>City ID</th>
<th>City</th>
<th>State</th>
<th>ZIP/Postal code</th>
<th>Country</th>
<th>Actions</th>
</tr>
</thead>
</table>
[% IF cities_count > 0 %]
<table id="table_cities">
<thead>
<tr>
<th>City ID</th>
<th>City</th>
<th>State</th>
<th>ZIP/Postal code</th>
<th>Country</th>
<th data-class-name="actions">Actions</th>
</tr>
</thead>
</table>
[% ELSE %]
<div class="dialog message">
There are no cities defined. <a href="/cgi-bin/koha/admin/cities.pl?op=add_form">Create a new city</a>.
</div>
[% END %]
[% END %]
</main>
@ -162,12 +168,21 @@
[% INCLUDE 'datatables.inc' %]
<script>
$(document).ready(function() {
var cities_table_url = '/api/v1/cities';
var cities_table_url = '/api/v1/cities?';
[% IF city_name_filter %]
var city_name_filter = {
'name': {
"like": '%[%- city_name_filter | html -%]%'
}
};
cities_table_url += 'q='+ encodeURI(JSON.stringify(city_name_filter));
[% END %]
var cities_table = $("#table_cities").api({
"ajax": {
"url": cities_table_url
},
'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
"order": [[ 1, "asc" ]],
"columns": [
{
"data": "city_id",
@ -197,7 +212,7 @@
{
"data": function( row, type, val, meta ) {
var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/cities.pl?op=add_form&amp;cityid='+ row.city_id +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>';
var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/cities.pl?op=add_form&amp;cityid='+ row.city_id +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
result += '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/cities.pl?op=delete_confirm&amp;cityid='+ row.city_id +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</a>';
return result;