diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-21 19:59:05 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-21 20:21:14 +0100 |
commit | e12e5a7685b4ae5dcfeaf931adde2dbb91ef745f (patch) | |
tree | 733f0a5c2d31a79addc6f03eafb2a581980099dc | |
parent | 1ae102a9f4ebddb4a94b9fd8094ec47c57f7ad00 (diff) |
Store and use initial URL to fix JavaScript bugs.
If you were on a body page, selected a report, then another report, the
"Back to all reports" link then had an incorrect URL. Also, going "Back
to all reports" after one report would fetch an incorrect Ajax query of
reports to show (as the URL had not yet been updated).
Both of these are fixed by storing the URL on page load, and using that
for the "Back to all reports" link and the URL used by the Ajax call.
There is still an issue with the URL shown if you filter, then select a
report, then click "Back to all reports", but the contents are okay.
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 9 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index fea863b14..53954f57a 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -1087,15 +1087,19 @@ fixmystreet.display = { // If this is the first individual report we've loaded, remove the // "all reports" sub_map_links but store them in a global variable // so we can reinsert them when the user returns to the all reports - // view. Also set the Back link to know where to go back to. + // view. if (!fixmystreet.original.sub_map_links) { fixmystreet.original.sub_map_links = $('#sub_map_links').detach(); - $('.js-back-to-report-list').attr('href', location.href); } // With #sub_map_links detached from the DOM, we set up the // individual report's sub_map_links using map_controls(). fixmystreet.set_up.map_controls(); + // Set the Back link to know where to go back to. + // TODO: If you e.g. filter before selecting a report, this URL is + // wrong (but what is shown is correct). + $('.js-back-to-report-list').attr('href', fixmystreet.original.href); + // Problems nearby should act the same as 'Back to all reports' on around, // but on /my and /reports should go to that around page. if (fixmystreet.original.page == 'around') { @@ -1179,6 +1183,7 @@ fixmystreet.display = { $(function() { fixmystreet.original = { + 'href': location.href, 'title': document.title, 'page': fixmystreet.page }; diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 553823818..afe47b4e7 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -435,7 +435,7 @@ var fixmystreet = fixmystreet || {}; if (fixmystreet.page == 'reports' || fixmystreet.page == 'my') { pin_layer_options.strategies = [ new OpenLayers.Strategy.FixMyStreetFixed() ]; pin_layer_options.protocol = new OpenLayers.Protocol.FixMyStreet({ - url: '?ajax=1', + url: fixmystreet.original.href.split('?')[0] + '?ajax=1', format: new OpenLayers.Format.FixMyStreet() }); } |