diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/Zurich.pm | 14 | ||||
-rw-r--r-- | templates/web/default/around/postcode_form.html | 2 | ||||
-rw-r--r-- | templates/web/emptyhomes/index.html | 2 | ||||
-rw-r--r-- | templates/web/fixmystreet/around/postcode_form.html | 2 | ||||
-rw-r--r-- | templates/web/zurich/around/intro.html | 15 | ||||
-rw-r--r-- | templates/web/zurich/header.html | 6 | ||||
-rw-r--r-- | web/cobrands/barnet/base.scss | 2 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/_base.scss | 2 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/_layout.scss | 2 | ||||
-rw-r--r-- | web/cobrands/stevenage/layout.scss | 2 | ||||
-rw-r--r-- | web/cobrands/zurich/base.scss | 4 | ||||
-rw-r--r-- | web/css/core.scss | 4 |
13 files changed, 70 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 200dbd696..5090ef7ff 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -281,6 +281,33 @@ sub ajax : Path('/ajax') { $c->res->body($body); } + +sub location_autocomplete : Path('/ajax/geocode') { + my ( $self, $c ) = @_; + $c->res->content_type('application/json; charset=utf-8'); + unless ( $c->req->param('term') ) { + $c->res->status(404); + $c->res->body(''); + return; + } + # we want the match even if there's no ambiguity, so recommendation doesn't + # disappear when it's the last choice being offered in the autocomplete. + $c->stash->{allow_single_geocode_match_strings} = 1; + my ( $lat, $long, $suggestions ) = + FixMyStreet::Geocode::lookup( $c->req->param('term'), $c ); + my @addresses; + # $error doubles up to return multiple choices by being an array + if ( ref($suggestions) eq 'ARRAY' ) { + foreach (@$suggestions) { + push @addresses, decode_utf8($_->{address}); + } + } + my $body = JSON->new->utf8(1)->encode( + \@addresses + ); + $c->res->body($body); +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/Geocode/Zurich.pm b/perllib/FixMyStreet/Geocode/Zurich.pm index 5aaca2c8e..0fc84c0ef 100644 --- a/perllib/FixMyStreet/Geocode/Zurich.pm +++ b/perllib/FixMyStreet/Geocode/Zurich.pm @@ -52,8 +52,13 @@ sub setup_soap { # string STRING CONTEXT # Looks up on Zurich web service a user-inputted location. # Returns array of (LAT, LON, ERROR), where ERROR is either undef, a string, or -# an array of matches if there are more than one. The information in the query -# may be used to disambiguate the location in cobranded versions of the site. +# an array of matches if there are more than one. +# If there is no ambiguity, returns only a {lat,long} hash, unless allow_single_match_string is true +# (because the auto-complete use of this (in /around) should send the matched name even though it's not ambiguous). +# +# The information in the query may be used to disambiguate the location in cobranded +# versions of the site. + sub string { my ( $s, $c ) = @_; @@ -98,8 +103,9 @@ sub string { push (@valid_locations, $_); last if lc($_->{text}) eq lc($s); } - - return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1; + if (scalar @valid_locations == 1 && ! $c->stash->{allow_single_geocode_match_strings} ) { + return { latitude => $latitude, longitude => $longitude }; + } return { error => $error }; } diff --git a/templates/web/default/around/postcode_form.html b/templates/web/default/around/postcode_form.html index 935995cfe..f58d7285d 100644 --- a/templates/web/default/around/postcode_form.html +++ b/templates/web/default/around/postcode_form.html @@ -5,7 +5,7 @@ <form action="[% c.uri_for('/around') %]" method="get" name="postcodeForm" id="postcodeForm"> <label for="pc">[% question %]:</label> <span><input type="text" name="pc" value="[% pc | html %]" id="pc" size="10" maxlength="200"> - <input type="submit" value="[% loc('Go') %]" id="submit"> + <input type="submit" value="[% loc('Go') %]" id="sub"> </span> [% IF partial_token %] <input type="hidden" name="partial" value="[% partial_token.token %]"> diff --git a/templates/web/emptyhomes/index.html b/templates/web/emptyhomes/index.html index be6a14b95..9ca771fc0 100644 --- a/templates/web/emptyhomes/index.html +++ b/templates/web/emptyhomes/index.html @@ -44,7 +44,7 @@ The TV series launched a campaign for action and while this is running, our <a h <form action="[% c.uri_for('/around') %]" method="get" name="postcodeForm" id="postcodeForm"> <label for="pc">[% question %]:</label> <span><input type="text" name="pc" value="" id="pc" size="10" maxlength="200"> - <input type="submit" value="[% loc('Go') %]" id="submit"> + <input type="submit" value="[% loc('Go') %]" id="sub"> </span> </form> diff --git a/templates/web/fixmystreet/around/postcode_form.html b/templates/web/fixmystreet/around/postcode_form.html index d48a53183..ed5d700f0 100644 --- a/templates/web/fixmystreet/around/postcode_form.html +++ b/templates/web/fixmystreet/around/postcode_form.html @@ -18,7 +18,7 @@ <label for="pc">[% question %]:</label> <div> <input type="text" name="pc" value="[% pc | html %]" id="pc" size="10" maxlength="200" placeholder="[% tprintf(loc('e.g. ā%sā or ā%sā'), c.cobrand.example_places) %]"> - <input type="submit" value="[% loc('Go') %]" id="submit"> + <input type="submit" value="[% loc('Go') %]" id="sub"> </div> [% IF partial_token %] diff --git a/templates/web/zurich/around/intro.html b/templates/web/zurich/around/intro.html index c113afca7..f7a4904e3 100644 --- a/templates/web/zurich/around/intro.html +++ b/templates/web/zurich/around/intro.html @@ -1 +1,16 @@ <h1>[% loc('Report, view, or discuss local problems') %]</h1> + +<!-- FIXME Better place for this --> +<script> + $(function() { + $( "#pc" ).autocomplete({ + minLength: 3, + select: function(event, ui) { + $(this).val(ui.item.value); + this.form.submit(); + return true; + }, + source: "/ajax/geocode" + }); + }); +</script> diff --git a/templates/web/zurich/header.html b/templates/web/zurich/header.html index 0831b4ea4..1e730267d 100644 --- a/templates/web/zurich/header.html +++ b/templates/web/zurich/header.html @@ -20,11 +20,15 @@ <link rel="stylesheet" href="[% start %][% version('/cobrands/' _ c.cobrand.moniker _ '/layout.css') %]"> <![endif]--> +<!-- CDN for now FIXME --><link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/redmond/jquery-ui.css"> + <script src="[% start %][% version('/js/modernizr.custom.js') %]" charset="utf-8"></script> <script src="[% start %][% version('/cobrands/fixmystreet/position_map.js') %]" charset="utf-8"></script> [% INCLUDE 'common_header_tags.html', js_override = '/cobrands/fixmystreet/fixmystreet.js', site_title = 'FixMyZürich' %] [% extra_js %] - + +<!-- CDN for now FIXME --><script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js" charset="utf-8"></script> + [% INCLUDE 'tracking_code.html' %] </head> diff --git a/web/cobrands/barnet/base.scss b/web/cobrands/barnet/base.scss index 0447c6779..2dd0640a6 100644 --- a/web/cobrands/barnet/base.scss +++ b/web/cobrands/barnet/base.scss @@ -26,7 +26,7 @@ background: url('/cobrands/barnet/img/barnet-skipnav.png') no-repeat; } -#front-main #postcodeForm div input#submit, +#front-main #postcodeForm div input#sub, .green-btn, button.green-btn, input.green-btn, diff --git a/web/cobrands/fixmystreet/_base.scss b/web/cobrands/fixmystreet/_base.scss index 9f6a2fe90..d72910450 100644 --- a/web/cobrands/fixmystreet/_base.scss +++ b/web/cobrands/fixmystreet/_base.scss @@ -1474,7 +1474,7 @@ table.nicetable { background:none; line-height:1.5em; } - input#submit { + input#sub { display:table-cell; border:none; padding:0; diff --git a/web/cobrands/fixmystreet/_layout.scss b/web/cobrands/fixmystreet/_layout.scss index 7a84af521..63d4ef32e 100644 --- a/web/cobrands/fixmystreet/_layout.scss +++ b/web/cobrands/fixmystreet/_layout.scss @@ -884,7 +884,7 @@ body.frontpage { height:2em; width:17em; } - input#submit { + input#sub { display:block; float:right; width:3em; diff --git a/web/cobrands/stevenage/layout.scss b/web/cobrands/stevenage/layout.scss index a94dc2a24..542cffd96 100644 --- a/web/cobrands/stevenage/layout.scss +++ b/web/cobrands/stevenage/layout.scss @@ -211,7 +211,7 @@ body.frontpage { #front-main { #postcodeForm { div { - input#submit { + input#sub { color: #fff; background: $primary; &:hover { diff --git a/web/cobrands/zurich/base.scss b/web/cobrands/zurich/base.scss index 4594f832f..94fa5caf6 100644 --- a/web/cobrands/zurich/base.scss +++ b/web/cobrands/zurich/base.scss @@ -5,3 +5,7 @@ @import "../fixmystreet/_base"; +.ui-menu-item { + list-style-type: none; +} + diff --git a/web/css/core.scss b/web/css/core.scss index c7fac1717..ed47cb01a 100644 --- a/web/css/core.scss +++ b/web/css/core.scss @@ -109,7 +109,7 @@ $map_width: 500px; margin-top: 0; } - #submit { + #sub { font-size: 83%; } } @@ -616,7 +616,7 @@ $map_width: 500px; display: block; font-size: 150%; } - #submit { + #sub { font-size: 100%; } } |