aboutsummaryrefslogtreecommitdiffstats
path: root/web/js/map-OpenLayers.js
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-05-18 12:15:55 +0100
committerStruan Donald <struan@exo.org.uk>2012-05-18 12:15:55 +0100
commit69284dad6f9b645eff9abe84b09463c0bf32fc24 (patch)
tree77cd1947f6ffb8435276c64c67028ccd8603cc53 /web/js/map-OpenLayers.js
parentb50e91710b4dc37fb5f9e3ec28233d34c6413c25 (diff)
Work much better if reporting pin is clicked/dragged outside council boundary
Diffstat (limited to 'web/js/map-OpenLayers.js')
-rw-r--r--web/js/map-OpenLayers.js45
1 files changed, 31 insertions, 14 deletions
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index 20c2ea720..4e728e5f8 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() {
@@ -421,7 +447,6 @@ 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
@@ -429,23 +454,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