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;
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, );
$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,
);
</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>
[% 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",
{
"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&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&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&cityid='+ row.city_id +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</a>';
return result;