diff --git a/app/controllers/my_profile/maps_controller.rb b/app/controllers/my_profile/maps_controller.rb index a8ac94a..1d8b5d2 100644 --- a/app/controllers/my_profile/maps_controller.rb +++ b/app/controllers/my_profile/maps_controller.rb @@ -31,23 +31,11 @@ class MapsController < MyProfileController end def search_city - - term = params[:term]; - - regions = NationalRegion.search_city(term + "%", true).map {|r|{ :label => r.city , :category => r.state}} - - render :json => regions - + render :json => MapsHelper.search_city(params[:term]) end def search_state - - term = params[:term]; - - regions = NationalRegion.search_state(term + "%", true).map {|r|{ :label => r.state}} - - render :json => regions - + render :json => MapsHelper.search_state(params[:term]) end end diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 4a64230..73171a0 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -291,6 +291,23 @@ class AccountController < ApplicationController render :text => user_data.to_json, :layout => false, :content_type => "application/javascript" end + def search_cities + if request.xhr? and params[:state_name] and params[:city_name] + render :json => MapsHelper.search_city(params[:city_name], params[:state_name]) + else + render :json => [].to_json + end + end + + def search_state + if request.xhr? and params[:state_name] + render :json => MapsHelper.search_state(params[:state_name]) + else + render :json => [].to_json + end + end + + protected def redirect? diff --git a/app/helpers/maps_helper.rb b/app/helpers/maps_helper.rb new file mode 100644 index 0000000..93d9387 --- /dev/null +++ b/app/helpers/maps_helper.rb @@ -0,0 +1,14 @@ +module MapsHelper + def self.search_city term, state="" + cities = if state.empty? + NationalRegion.search_city(term + "%", true) + else + NationalRegion.search_city(term + "%", true, state) + end + cities.map {|r|{ :label => r.city , :category => r.state}} + end + + def self.search_state term + NationalRegion.search_state(term + "%", true).map {|r|{ :label => r.state}} + end +end diff --git a/app/models/national_region.rb b/app/models/national_region.rb index e06e4ba..6990986 100644 --- a/app/models/national_region.rb +++ b/app/models/national_region.rb @@ -12,7 +12,7 @@ class NationalRegion < ActiveRecord::Base adtional_contions = ""; if like - operator = "like" + operator = "ilike" find_return = :all end @@ -41,7 +41,7 @@ class NationalRegion < ActiveRecord::Base find_return = :first if like - operator = "like" + operator = "ilike" find_return = :all end diff --git a/app/views/profile_editor/_person_form.rhtml b/app/views/profile_editor/_person_form.rhtml index 336ae7a..4c8a2f8 100644 --- a/app/views/profile_editor/_person_form.rhtml +++ b/app/views/profile_editor/_person_form.rhtml @@ -19,8 +19,8 @@ <%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), '
' + pick_date(:profile_data, :birth_date, {:start_year => (Date.today.year - 100), :end_year => (Date.today.year - 5)}) + '
')) %> <%= optional_field(@person, 'nationality', f.text_field(:nationality, :rel => _('Nationality'))) %> <%= optional_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> -<%= optional_field(@person, 'state', f.text_field(:state, :rel => _('State'))) %> -<%= optional_field(@person, 'city', f.text_field(:city, :rel => _('City'))) %> +<%= optional_field(@person, 'state', f.text_field(:state, :id => 'state_field', :rel => _('State'))) %> +<%= optional_field(@person, 'city', f.text_field(:city, :id => 'city_field', :rel => _('City'))) %> <%= optional_field(@person, 'zip_code', labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code, :rel => _('ZIP code')))) %> <%= optional_field(@person, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address, :rel => _('Address')))) %> <%= optional_field(@person, 'address_reference', labelled_form_field(_('Address reference'), text_field(:profile_data, :address_reference, :rel => _('Address reference')))) %> @@ -36,6 +36,7 @@ <% end %> +<%= javascript_include_tag('city_state_validation') %>