diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-04-08 16:37:09 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-04-08 23:38:47 +0100 |
commit | 1fa87a4adb61c3131516e711f3cf3a83941495d5 (patch) | |
tree | fcbf4b8eb1fe8cea0465dcfe0f4181ba08dd80cd /web | |
parent | 75002bb7f3eb82fa1c8002e199e188501d7954a4 (diff) |
[UK] Fix Highways England categories on pin move.
If you clicked on a non-HE location (so showing non-HE categories), then
moved the pin to a HE location, the HE message box would show and update
categories (but there would be no HE ones at the time). The server would
return the new categories (including HE ones), but as the issue location
had now not changed on this second call, the categories would not update
to hide non-HE ones (it would show both HE and non-HE categories).
So, instead of going off a location, check the road name - if it has not
changed, do not recreate the whole HE message box, but do call the right
HE selected/not selected function to update the categories.
Note that this, if "Somewhere else" is selected, then causes an infinite
loop, because the highways_change event triggers a category_change event
which fires the layer's road found function, and then repeat.
The highways_change->category_change event firing, according to the code
comment, is so that asset selection can take place, or to remove stopper
messages being shown. Previously, HE did not have its own categories but
overrode the body to be sent to; HE now does have categories of its own,
so I think this code can be removed.
Diffstat (limited to 'web')
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 11 | ||||
-rw-r--r-- | web/cobrands/highways/assets.js | 35 |
2 files changed, 20 insertions, 26 deletions
diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 0a08c0f69..204ceb85d 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -1198,17 +1198,6 @@ fixmystreet.message_controller = (function() { disable_report_form(stopper.keep_category_extras); } - // make sure we fire the code to check if an asset is selected if - // we change options in the Highways England message - $(fixmystreet).on('report_new:highways_change', function() { - if (fixmystreet.body_overrides.get_only_send() === 'Highways England') { - $('#' + stopperId).remove(); // Get rid of any stopper message - responsibility_off(); // Will also reenable form - } else { - $(fixmystreet).trigger('report_new:category_change'); - } - }); - $(fixmystreet).on('report_new:category_change', check_for_stopper); return { diff --git a/web/cobrands/highways/assets.js b/web/cobrands/highways/assets.js index 1607bc193..666c97e2b 100644 --- a/web/cobrands/highways/assets.js +++ b/web/cobrands/highways/assets.js @@ -54,22 +54,27 @@ fixmystreet.assets.add(defaults, { nearest_radius: 15, actions: { found: function(layer, feature) { - // if we've changed location then we want to reset things otherwise - // this is probably just being called again by a category change - var lat = $('#fixmystreet\\.latitude').val(), - lon = $('#fixmystreet\\.longitude').val(); - if ( fixmystreet.body_overrides.location && - lat == fixmystreet.body_overrides.location.latitude && - lon == fixmystreet.body_overrides.location.longitude ) { + if (fixmystreet.assets.selectedFeature()) { + $('#highways').remove(); return; } - $('#highways').remove(); - if ( !fixmystreet.assets.selectedFeature() ) { - add_highways_warning(feature.attributes.ROA_NUMBER); + var current_road_name = $('#highways strong').first().text(); + var new_road_name = feature.attributes.ROA_NUMBER; + if (current_road_name === new_road_name) { + // this could be because of a category change, or because we've + // received new data from the server (but the pin drop had + // already shown the HE message) + if ($('#js-highways:checked').length) { + he_selected(); + } else { + non_he_selected(); + } + } else { + $('#highways').remove(); + add_highways_warning(new_road_name); } }, not_found: function(layer) { - fixmystreet.body_overrides.location = null; if (fixmystreet.body_overrides.get_only_send() === 'Highways England') { fixmystreet.body_overrides.remove_only_send(); fixmystreet.body_overrides.do_not_send('Highways England'); @@ -82,10 +87,7 @@ fixmystreet.assets.add(defaults, { function regenerate_category(he_flag) { if (!fixmystreet.reporting_data) return; - fixmystreet.body_overrides.location = { - latitude: $('#fixmystreet\\.latitude').val(), - longitude: $('#fixmystreet\\.longitude').val() - }; + var old_category = $("#form_category").val(); // Restart the category dropdown from the original data (not all of it as // we keep subcategories the same) @@ -99,6 +101,9 @@ function regenerate_category(he_flag) { select = select.html(); $('#form_category').html(select); } + if ($("#form_category option[value=\"" + old_category + "\"]").length) { + $("#form_category").val(old_category); + } // Recalculate the category groups var old_category_group = $('#category_group').val() || $('#filter_group').val(); |