diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-04-17 14:25:25 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-04-26 13:39:27 +0100 |
commit | cad3ef53f5cb1b47ff8922aef188a831b4110aab (patch) | |
tree | 6be585d6e91f580786f8533d964bdc134aa592d1 /web | |
parent | 2a7d70db634b1e8a5f32d99c34bf682ca7dc3a42 (diff) |
Work much better if reporting pin is clicked/dragged in/out of council boundary (CM17).
Diffstat (limited to 'web')
-rw-r--r-- | web/js/map-OpenLayers.js | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 1574754c9..87876a723 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -7,6 +7,32 @@ function fixmystreet_update_pin(lonlat) { ); document.getElementById('fixmystreet.latitude').value = lonlat.lat || lonlat.y; document.getElementById('fixmystreet.longitude').value = lonlat.lon || lonlat.x; + + $.getJSON('/report/new/ajax', { + latitude: $('#fixmystreet\\.latitude').val(), + longitude: $('#fixmystreet\\.longitude').val() + }, function(data) { + if (data.error) { + if (!$('#side-form-error').length) { + $('<div id="side-form-error"/>').insertAfter($('#side-form')); + } + $('#side-form-error').html('<h1>Reporting a problem</h1><p>' + data.error + '</p>').show(); + $('#side-form').hide(); + return; + } + $('#side-form, #site-logo').show(); + $('#councils_text').html(data.councils_text); + $('#form_category_row').html(data.category); + if ( data.extra_name_info ) { + // there might be a first name field on some cobrands + var lb = $('#form_first_name').prev() || $('#form_name').prev(); + lb.before(data.extra_name_info); + } + }); + + if (!$('#side-form-error').is(':visible')) { + $('#side-form, #site-logo').show(); + } } function fixmystreet_activate_drag() { @@ -419,7 +445,7 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { fixmystreet.markers.addFeatures( markers ); fixmystreet_activate_drag(); } - fixmystreet_update_pin(lonlat); + // check to see if markers are visible. We click the // link so that it updates the text in case they go // back @@ -427,23 +453,15 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { fixmystreet.state_pins_were_hidden = true; $('#hide_pins_link').click(); } + + // Store pin location in form fields, and check coverage of point + fixmystreet_update_pin(lonlat); + + // Already did this first time map was clicked, so no need to do it again. if (fixmystreet.page == 'new') { return; } - $.getJSON('/report/new/ajax', { - latitude: $('#fixmystreet\\.latitude').val(), - longitude: $('#fixmystreet\\.longitude').val() - }, function(data) { - if (data.error) { - // XXX If they then click back and click somewhere in the area, this error will still show. - $('#side-form').html('<h1>Reporting a problem</h1><p>' + data.error + '</p>'); - return; - } - $('#councils_text').html(data.councils_text); - $('#form_category_row').html(data.category); - }); - $('#side-form, #site-logo').show(); fixmystreet.map.updateSize(); // might have done, and otherwise Firefox gets confused. /* For some reason on IOS5 if you use the jQuery show method it * doesn't display the JS validation error messages unless you do this |