aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-10-18 16:22:08 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-10-18 16:22:08 +0100
commit3a2b49ebcb8c65d73108930f421142f2536cb893 (patch)
tree0112c0481384bd8fdc4e3b74efc1c6fd991e40b6
parentfc507074651b9f70dab1eeed4772f678a21fe272 (diff)
Update pagination when status/categories changed.
-rw-r--r--perllib/FixMyStreet/App.pm12
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm10
-rw-r--r--templates/web/base/my/my.html2
-rw-r--r--templates/web/base/my/planned.html2
-rw-r--r--templates/web/base/pagination.html4
-rwxr-xr-xtemplates/web/base/reports/body.html4
-rw-r--r--web/js/map-OpenLayers.js4
7 files changed, 33 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index ab5e62233..7809b5f12 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -346,13 +346,21 @@ sub send_email {
$uri = $c->uri_with( ... );
-Simply forwards on to $c->req->uri_with - this is a common typo I make!
+Forwards on to $c->req->uri_with, but also deletes keys that have a "" value
+(as undefined is passed as that from a template).
=cut
sub uri_with {
my $c = shift;
- return $c->req->uri_with(@_);
+ my $uri = $c->req->uri_with(@_);
+ my $args = $_[0];
+ my %params = %{$uri->query_form_hash};
+ foreach my $key (keys %$args) {
+ delete $params{$key} if $args->{$key} eq "";
+ }
+ $uri->query_form(\%params);
+ return $uri;
}
=head2 uri_for
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 79e11af9c..f05096525 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -521,7 +521,15 @@ sub ajax : Private {
my $list_html = $c->render_fragment($template);
- my $json = { pins => \@pins };
+ my $pagination = $c->render_fragment('pagination.html', {
+ pager => $c->stash->{problems_pager} || $c->stash->{pager},
+ param => 'p',
+ });
+
+ my $json = {
+ pins => \@pins,
+ pagination => $pagination,
+ };
$json->{reports_list} = $list_html if $list_html;
my $body = encode_json($json);
$c->res->body($body);
diff --git a/templates/web/base/my/my.html b/templates/web/base/my/my.html
index 8924736eb..a61a8ea44 100644
--- a/templates/web/base/my/my.html
+++ b/templates/web/base/my/my.html
@@ -38,7 +38,9 @@
<section class="full-width">
[% INCLUDE "reports/_list-filters.html", use_form_wrapper = 1 %]
+<div class="js-pagination">
[% INCLUDE 'pagination.html', pager = problems_pager, param = 'p' %]
+</div>
<div id="js-reports-list">
[% INCLUDE 'my/_problem-list.html' %]
</div>
diff --git a/templates/web/base/my/planned.html b/templates/web/base/my/planned.html
index eab84bb9b..eb67247c4 100644
--- a/templates/web/base/my/planned.html
+++ b/templates/web/base/my/planned.html
@@ -23,7 +23,9 @@
<section class="full-width">
[% INCLUDE "reports/_list-filters.html", use_form_wrapper = 1 %]
+<div class="js-pagination">
[% INCLUDE 'pagination.html', pager = problems_pager, param = 'p' %]
+</div>
[% INCLUDE 'my/_problem-list.html' %]
</section>
diff --git a/templates/web/base/pagination.html b/templates/web/base/pagination.html
index f0c51bb10..448186838 100644
--- a/templates/web/base/pagination.html
+++ b/templates/web/base/pagination.html
@@ -1,13 +1,13 @@
[% IF pager.last_page > 1 %]
<p class="pagination">
[% IF pager.previous_page %]
- <a class="prev" href="[% c.req.uri_with({ $param => pager.previous_page }) %][% '#' _ hash IF hash %]">[% loc('Previous') %]</a>
+ <a class="prev" href="[% c.uri_with({ $param => pager.previous_page, ajax => undefined }) %][% '#' _ hash IF hash %]">[% loc('Previous') %]</a>
[% END %]
[% tprintf( loc('%d to %d of %d'), pager.first, pager.last, pager.total_entries ) %]
[% IF pager.next_page %]
- <a class="next" href="[% c.req.uri_with({ $param => pager.next_page }) %][% '#' _ hash IF hash %]">[% loc('Next') %]</a>
+ <a class="next" href="[% c.uri_with({ $param => pager.next_page, ajax => undefined }) %][% '#' _ hash IF hash %]">[% loc('Next') %]</a>
[% END %]
</p>
[% END %]
diff --git a/templates/web/base/reports/body.html b/templates/web/base/reports/body.html
index 6cad2cd1a..929a4a527 100755
--- a/templates/web/base/reports/body.html
+++ b/templates/web/base/reports/body.html
@@ -62,11 +62,15 @@
<section class="full-width">
[% INCLUDE "reports/_list-filters.html", use_form_wrapper = 1 %]
+<div class="js-pagination">
[% INCLUDE 'pagination.html', param = 'p' %]
+</div>
<div id="js-reports-list">
[% INCLUDE 'reports/_problem-list.html' %]
</div>
+<div class="js-pagination">
[% INCLUDE 'pagination.html', param = 'p' %]
+</div>
</section>
</div>
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index 1ccb7febc..43a0aadbb 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -297,6 +297,7 @@ var fixmystreet = fixmystreet || {};
var qs = parse_query_string();
var filter_categories = replace_query_parameter(qs, 'filter_categories', 'filter_category');
var filter_statuses = replace_query_parameter(qs, 'statuses', 'status');
+ delete qs['p'];
var new_url;
if ($.isEmptyObject(qs)) {
new_url = location.href.replace(location.search, "");
@@ -796,6 +797,9 @@ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, {
if (typeof(obj.reports_list) != 'undefined' && (reports_list = document.getElementById('js-reports-list'))) {
reports_list.innerHTML = obj.reports_list;
}
+ if (typeof(obj.pagination) != 'undefined') {
+ $('.js-pagination').html(obj.pagination);
+ }
return fixmystreet.maps.markers_list( obj.pins, false );
},
CLASS_NAME: "OpenLayers.Format.FixMyStreet"