diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 038fca2..3e599e4 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -138,6 +138,11 @@ class SearchController < ApplicationController [ :events, N_('Events') ] ] + def cities + @cities = City.find(:all, :order => 'name', :conditions => ['parent_id = ? and lat is not null and lng is not null', params[:state_id]]) + render :action => 'cities', :layout => false + end + def complete_region # FIXME this logic should be in the model @regions = Region.find(:all, :conditions => [ '(name like ? or name like ?) and lat is not null and lng is not null', '%' + params[:region][:name] + '%', '%' + params[:region][:name].capitalize + '%' ]) @@ -150,7 +155,7 @@ class SearchController < ApplicationController @product_category = ProductCategory.find(params[:product_category]) if params[:product_category] # FIXME name is not unique - @region = Region.find_by_name(params[:region][:name]) if params[:region] + @region = City.find_by_id(params[:city]) if params[:city] # how many assets we are searching for? number_of_result_assets = @searching.values.select{|v| v}.size @@ -176,7 +181,6 @@ class SearchController < ApplicationController end render :action => 'index' - render :text => 'bla' end alias :assets :index diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6de647f..32018cc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -483,25 +483,6 @@ module ApplicationHelper html.join "\n" end -# def select_city(name, top_level='Nacional') -# city_field_name = "#{object}[#{method}]" -# state_field_name = "#{object}_#{method}_state" -# region_field_name = "#{object}_#{method}_region" -# -# selected_state = nil -# selected_region = nil -# -# regions = Region.find_by_name(top_level).children -# -# select_tag(region_field_name, options_for_select(regions.map {|r| [r.name, r.id] } + ['---','']) + -# select_tag(state_field_name, options_for_select(['---', ''])) + -# select_tag(city_fied_name, options_for_select(['---',''])) + -# -# observe_field(country_field_name, :update => state_field_name, :url => { :controller => 'geography', :action => 'states' }, :with => 'country' ) + -# observe_field(country_field_name, :update => city_field_name, :url => { :controller => 'geography', :action => 'cities_by_country' }, :with => 'country') + -# observe_field(state_field_name, :update => city_field_name, :url => { :controller => 'geography', :action => 'cities' }, :with => 'state_id') -# end - def file_field_or_thumbnail(label, image, i) display_form_field label, ( render :partial => (image && image.valid? ? 'shared/show_thumbnail' : 'shared/change_image'), diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb index aa947a0..be33d60 100644 --- a/app/helpers/forms_helper.rb +++ b/app/helpers/forms_helper.rb @@ -24,7 +24,7 @@ module FormsHelper text_field_tag( name, value, options ) end - def labelled_select( human_name, name, value_method, text_method, selected, collection, options ) + def labelled_select( human_name, name, value_method, text_method, selected, collection, options={} ) options[:id] ||= 'select-' + FormsHelper.next_id_number content_tag('label', human_name, :for => options[:id]) + select_tag( name, options_from_collection_for_select(collection, value_method, text_method, selected), options) @@ -53,6 +53,20 @@ module FormsHelper javascript_tag('new Autocompleter.Local(%s, %s, %s)' % [ id.to_json, "autocomplete-for-#{id}".to_json, choices.to_json ] ) end + def select_city + states = State.find(:all, :order => 'name') + states = [State.new(:name => '---')] + states + cities = [City.new(:name => '---')] + + state_id = 'state-' + FormsHelper.next_id_number + city_id = 'city-' + FormsHelper.next_id_number + + content_tag('div', labelled_select(_('State:'), 'state', :id, :name, nil, states, :id => state_id), :class => 'select_state_for_origin' ) + + content_tag('div', labelled_select(_('City:'), 'city', :id, :name, nil, cities, :id => city_id), :class => 'select_city_for_origin' ) + + + observe_field(state_id, :update => city_id, :url => { :controller => 'search', :action => 'cities' }, :with => 'state_id') + end + protected def self.next_id_number if defined? @@id_num diff --git a/app/models/category.rb b/app/models/category.rb index 5fd5339..0049a6d 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -8,12 +8,6 @@ class Category < ActiveRecord::Base validates_inclusion_of :display_color, :in => [ 1, 2, 3, 4, nil ] validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('%{fn} was already assigned to another category.') - def validate - if self.parent && (self.class != self.parent.class) - self.errors.add(:type, _("%{fn} must be the same as the parents'")) - end - end - # Finds all top level categories for a given environment. def self.top_level_for(environment) self.find(:all, :conditions => ['parent_id is null and environment_id = ?', environment.id ]) diff --git a/app/models/city.rb b/app/models/city.rb new file mode 100644 index 0000000..f490aae --- /dev/null +++ b/app/models/city.rb @@ -0,0 +1,2 @@ +class City < Region +end diff --git a/app/models/state.rb b/app/models/state.rb new file mode 100644 index 0000000..c659537 --- /dev/null +++ b/app/models/state.rb @@ -0,0 +1,2 @@ +class State < Region +end diff --git a/app/views/search/_sellers_form.rhtml b/app/views/search/_sellers_form.rhtml index f78a8c1..5f81181 100644 --- a/app/views/search/_sellers_form.rhtml +++ b/app/views/search/_sellers_form.rhtml @@ -9,14 +9,13 @@ +