diff options
| author | Luc Donnet | 2014-08-06 16:59:20 +0200 | 
|---|---|---|
| committer | Luc Donnet | 2014-08-06 16:59:20 +0200 | 
| commit | cedecf59a5e19ce867e097e1ebb63840b2d59a68 (patch) | |
| tree | a80394cc946a7d500e2896dc152f25cb5ffdd158 | |
| parent | 8ca6a3feee28f3e04cd043a015cf6f30057cf2ac (diff) | |
| download | chouette-core-cedecf59a5e19ce867e097e1ebb63840b2d59a68.tar.bz2 | |
Refactor search form in stop_areas
| -rw-r--r-- | Gemfile | 4 | ||||
| -rw-r--r-- | Gemfile.lock | 12 | ||||
| -rw-r--r-- | app/assets/javascripts/stop_areas.js.coffee | 36 | ||||
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 8 | ||||
| -rw-r--r-- | app/views/stop_areas/index.html.erb | 34 | ||||
| -rw-r--r-- | config/application.rb | 2 | 
6 files changed, 62 insertions, 34 deletions
| @@ -25,6 +25,7 @@ gem 'devise_invitable'  # Map, Geolocalization  gem "map_layers", "0.0.4"  gem "georuby-ext", "0.0.5" +gem 'nominatim'  # User interface  gem 'language_engine', '0.0.5' @@ -111,7 +112,4 @@ group :production do     gem "daemons"  end -gem 'nominatim' -gem 'bootstrap-typeahead-rails' - diff --git a/Gemfile.lock b/Gemfile.lock index bff2041c2..c70c11ef0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,8 +74,6 @@ GEM      bcrypt-ruby (3.0.1-java)      bootstrap-sass (3.1.1.1)        sass (~> 3.2) -    bootstrap-typeahead-rails (0.9.3.3) -      railties (>= 3.0)      bootswatch-rails (3.1.1.1)        railties (>= 3.1)      bouncy-castle-java (1.5.0146.1) @@ -270,10 +268,11 @@ GEM        rdoc (~> 3.4)        thor (>= 0.14.6, < 2.0)      rake (10.3.2) -    ransack (0.7.0) -      actionpack (~> 3.0) -      activerecord (~> 3.0) -      polyamorous (~> 0.5.0) +    ransack (1.2.0) +      actionpack (>= 3.0) +      activerecord (>= 3.0) +      activesupport (>= 3.0) +      i18n      raphael-rails (2.1.2)      rb-fchange (0.0.5)        ffi @@ -385,7 +384,6 @@ DEPENDENCIES    acts_as_list (= 0.1.6)    acts_as_tree-1.8 (= 1.1.0)    bootstrap-sass (~> 3.1.1) -  bootstrap-typeahead-rails    bootswatch-rails    calendar_helper (= 0.2.5)    capistrano diff --git a/app/assets/javascripts/stop_areas.js.coffee b/app/assets/javascripts/stop_areas.js.coffee index 255c4c707..b4148061e 100644 --- a/app/assets/javascripts/stop_areas.js.coffee +++ b/app/assets/javascripts/stop_areas.js.coffee @@ -29,17 +29,27 @@ jQuery ->    $('input#stop_area_projection_x').change(lon_lat_change)    $('input#stop_area_projection_y').change(lon_lat_change) -  # switch visibility of access_links -  switch_generics = (event) ->  -    event.preventDefault() -    $('.stop_areas .generics.content').toggle('slow') -    $('a.generics .switcher').toggle() +  # Autocomplete input to choose postal code in stop_areas index +  # constructs the suggestion engine +  country_codes = new Bloodhound( +    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value') +    queryTokenizer: Bloodhound.tokenizers.whitespace +    local: $.map( JSON.parse($('#country_codes').text()), (country_code) ->   +      value: country_code +    ) +  ) -  $('.stop_areas a.generics').click(switch_generics) - -  switch_details = (event) ->  -    event.preventDefault() -    $('.stop_areas .details.content').toggle('slow') -    $('a.details .switcher').toggle() - -  $('.stop_areas a.details').click(switch_details) +  country_codes.initialize() +  # kicks off the loading/processing of `local` and `prefetch` +  $('#search .typeahead').typeahead( +    { +      hint: true, +      highlight: true, +      minLength: 1 +    }, +    { +      name: 'country_codes', +      displayKey: 'value', +      source: country_codes.ttAdapter(), +    } +  ) diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 57773a8cc..d6d1b8822 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -45,7 +45,7 @@ class StopAreasController < ChouetteController    def index          request.format.kml? ? @per_page = nil : @per_page = 12 - +    @country_codes = referential.stop_areas.collect(&:country_code).compact.uniq      index! do |format|        format.html {          if collection.out_of_bounds? @@ -81,6 +81,12 @@ class StopAreasController < ChouetteController      redirect_to referential_stop_areas_path(@referential)    end +  def country_codes +    respond_to do |format| +      format.json { render :json => referential.stop_areas.collect(&:country_code).compact.uniq.to_json } +    end +  end +    def addresses      Rails.logger.error("SEARCHING FOR ADDRESSES : #{params[:q]}")      @addresses = filtered_addresses diff --git a/app/views/stop_areas/index.html.erb b/app/views/stop_areas/index.html.erb index 1ff6f73d4..f6fb0425f 100644 --- a/app/views/stop_areas/index.html.erb +++ b/app/views/stop_areas/index.html.erb @@ -1,16 +1,30 @@  <%= title_tag t('stop_areas.index.title') %>  -<form class="navbar-form" role="search"> -  <%= search_form_for @q, :url => referential_stop_areas_path(@referential), :html => {:method => :get} do |f| %> -  <div class="form-group"> -    <%= f.label :name_or_country_code_cont, "#{t('.name_or_country_code')} :" %> -    <%= f.text_field :name_or_country_code_cont %> -    <%= f.hidden_field :area_type_eq %> +<div id="country_codes"> +  <%= @country_codes.to_json %> +</div> + +<%= search_form_for @q, :url => referential_stop_areas_path(@referential), :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %> +<div class="panel panel-default"> +  <div class="panel-heading">    +    <div class="input-group col-md-9">    +      <%= f.text_field :name_cont, :placeholder => "#{t('.name')}", :class => 'form-control' %> +      <div class="input-group-btn"> +        <button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button> +      </div> +    </div><!-- /input-group --> +    <a data-toggle="collapse" data-parent="#search" href="#advanced_search"> +      <i class="fa fa-plus"></i> Recherche Avancée +    </a> +  </div> +   +  <div id="advanced_search" class="panel-collapse collapse">           +    <div class="panel-body"> +      <%= f.text_field :country_code_cont, :placeholder => "#{t('.country_code')}", :class => 'form-control typeahead' %> +    </div>    </div> -  <%= f.submit t('actions.search') %> <%= t("or") %> -  <%= link_to t("cancel"), referential_stop_areas_path(@referential) %> -  <% end %> -</form> +</div> +<% end %>  <div class="page_info">    <span class="search"> <%= t("will_paginate.page_entries_info.search") %></span> <%= page_entries_info @stop_areas %> diff --git a/config/application.rb b/config/application.rb index 8032f9e9a..7ce9e9d0a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,5 +1,7 @@  require File.expand_path('../boot', __FILE__) +ENV['RANSACK_FORM_BUILDER'] = '::SimpleForm::FormBuilder' +  require 'rails/all'  if defined?(Bundler) | 
