aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Florisson2014-08-20 11:42:51 +0200
committerMarc Florisson2014-08-20 11:42:51 +0200
commit4b18905e6c49747bc412bc4a99e46b08b4417c87 (patch)
treec1edea106035f06ba0dd4ace141fa6a83554c312
parent043b696e181bbdec04aade0f134b38ed2860b4ce (diff)
downloadchouette-core-4b18905e6c49747bc412bc4a99e46b08b4417c87.tar.bz2
fix js for localization by address. Mantis 26825
-rw-r--r--app/views/stop_areas/_form.html.erb67
1 files changed, 49 insertions, 18 deletions
diff --git a/app/views/stop_areas/_form.html.erb b/app/views/stop_areas/_form.html.erb
index a51c11da5..e78eb0942 100644
--- a/app/views/stop_areas/_form.html.erb
+++ b/app/views/stop_areas/_form.html.erb
@@ -1,13 +1,13 @@
<div class="container-fluid">
- <div class="col-md-7">
+ <div class="col-md-7">
<div id="prefetch">
<label><%= t('.geolocalize') %></label>
- <input class="typeahead form-control input-lg" maxlength="255" name="stop_area[address]" type="text" placeholder="<%= t('.address') %>" />
+ <input class="typeahead form-control input-lg" maxlength="255" name="stop_area[address]" type="text" placeholder="<%= t('.address') %>" />
</div>
<%= semantic_form_for [@referential, @stop_area] do |form| %>
- <%= form.inputs do %>
+ <%= form.inputs do %>
<%= form.input :id, :as => :hidden %>
<%= form.input :name %>
<%= form.input :stop_area_type, :as => :select, :input_html => { :disabled => !@stop_area.new_record? }, :collection => Chouette::StopArea.stop_area_types, :include_blank => false, :member_label => Proc.new { |stop_area_type| t("area_types.label.#{stop_area_type}") } %>
@@ -18,7 +18,7 @@
<%= form.input :projection_x %>
<%= form.input :projection_y %>
</div>
- </div>
+ </div>
<% end %>
<div class="panel panel-default">
<div class="panel-heading">WGS84</div>
@@ -26,21 +26,21 @@
<%= form.input :longitude %>
<%= form.input :latitude %>
</div>
- </div>
+ </div>
<%= form.input :registration_number %>
- <%= form.input :street_name %>
- <%= form.input :country_code %>
- <%= form.input :fare_code %>
- <%= form.input :nearest_topic_name %>
- <%= form.input :comment, :as => :text %>
+ <%= form.input :street_name %>
+ <%= form.input :country_code %>
+ <%= form.input :fare_code %>
+ <%= form.input :nearest_topic_name %>
+ <%= form.input :comment, :as => :text %>
<% if !manage_itl %>
<%= form.input :mobility_restricted_suitability,:as => :boolean %>
<%= form.input :stairs_availability,:as => :boolean %>
- <%= form.input :lift_availability,:as => :boolean %>
+ <%= form.input :lift_availability,:as => :boolean %>
<% end %>
- <%= form.input :objectid, :required => !@stop_area.new_record? %>
+ <%= form.input :objectid, :required => !@stop_area.new_record? %>
<% end %>
@@ -59,6 +59,39 @@
</div>
<script>
+ var address_display = function( address ) {
+ var name = "";
+ if ( address.house_number) {
+ name += address.house_number+" ";
+ }
+ name += address.road+", ";
+ if ( address.postalcode) {
+ name += address.postalcode+" ";
+ }
+ if ( address.city) {
+ name += address.city;
+ } else if ( address.county ) {
+ name += address.county;
+ } else if ( address.country ) {
+ name += address.country;
+ }
+
+ return name;
+ };
+ var filtering = function(list) {
+ var selection = $.grep( list, function(item) {
+ return (item.type == "house" || item.type == "residential") && item.address.road ;
+ });
+ return $.map( selection, function( d) {
+ return { postcode: d.address.postcode,
+ road: d.address.road,
+ lon: d.lon, lat: d.lat,
+ city: d.address.city,
+ postcode: d.address.postcode,
+ the_key: address_display( d.address)};
+ });
+ };
+
var addressesEngine = new Bloodhound({
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.id+" : "+d.road);
@@ -68,16 +101,14 @@
},
limit: 10,
remote: {
- url: '<%= referential_addresses_path(@referential, :format => 'json') %>?q=%QUERY',
- filter: function(list) {
- return $.map(list, function(d) { return { postcode: d.postcode, road: d.road, lon: d.lon, lat: d.lat, city: d.city, postcode: d.postcode, the_key: d.house_number+" "+d.road+", "+d.postcode+" "+d.city+", "+d.country }; });
- },
+ url: 'http://nominatim.openstreetmap.org/search?q=%QUERY&format=json&addressdetails=1',
+ filter: filtering,
}
});
-
+
// kicks off the loading/processing of `local` and `prefetch`
var promise = addressesEngine.initialize();
-
+
// passing in `null` for the `options` arguments will result in the default
// options being used
$('#prefetch .typeahead').typeahead(