-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'locations_autocomplete' into next-release
- Loading branch information
Showing
24 changed files
with
279 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,43 @@ | ||
class LocationsController < ApplicationController | ||
|
||
def all_admin_codes_options | ||
helper 'autocomplete' | ||
permissions 'profile' | ||
|
||
# def all_admin_codes_options | ||
def country_dropdown_onchange | ||
return unless request.xhr? | ||
# can select 'Country' which isn't really a country, and that should reset the form | ||
if params[:country_code] == "Country" | ||
geo_admin_codes = [] | ||
else | ||
geo_admin_codes = GeoCountry.find_by_id(params[:country_code]).geo_admin_codes | ||
end | ||
geo_admin_codes = (params[:show_admin_codes] and params[:country_code] != 'Country') ? | ||
GeoCountry.find_by_id(params[:country_code]).geo_admin_codes : [] | ||
# do not try to update models unless there is a current profile (ie don't update models when in search) | ||
update_model_with_country(params[:country_code]) if @profile = Profile.find_by_id(params[:profile_id]) | ||
render :update do |page| | ||
page.replace 'state_dropdown', :partial => '/locations/state_dropdown', :locals => {:display=>'inline', :name => params[:select_state_name], :geo_admin_codes => geo_admin_codes} | ||
page.show 'state_dropdown' | ||
# these messy next three lines reload the autocomplete js with the newly selected country | ||
page << "$$('option.newselected').collect(function(el){el.removeClassName('newselected')});" | ||
page << "$('select_country_id').select('[value=\"#{params[:country_code]}\"]')[0].addClassName('newselected');" | ||
page.replace 'autocomplete_js', :partial => '/locations/autocomplete_js' | ||
if params[:show_admin_codes] | ||
page.replace 'state_dropdown', :partial => '/locations/state_dropdown', :locals => {:display=>'inline', :name => params[:select_state_name], :geo_admin_codes => geo_admin_codes} | ||
page.show 'state_dropdown' | ||
end | ||
page.show 'city_text' | ||
page['city_text_field'].value = '' | ||
page['city_id_field'].value = '' | ||
page.show 'submit_loc' if params[:show_submit] == 'true' | ||
#page.show 'submit_loc' if params[:show_submit] == 'true' | ||
end | ||
end | ||
|
||
def city_lookup | ||
city = params[:city] | ||
country_id = params[:country_id] | ||
admin_code_id = params[:admin_code_id] | ||
if params[:city_id_field] =~ /\S+/ | ||
name = params[:city_id_field]+'[city_id]' | ||
else | ||
name = 'city_id' | ||
end | ||
html = '' | ||
if city.empty? | ||
render :update do |page| | ||
page["city_id_field"].value='' | ||
end | ||
return | ||
end | ||
return if country_id.empty? | ||
@places = GeoPlace.with_names_matching(city, country_id, params) | ||
if @places.empty? | ||
render :update do |page| | ||
page.replace_html 'city_results_box', "No cities matching '#{city}' found." | ||
page.show 'city_results_box' | ||
end | ||
elsif @places.size == 1 | ||
return_single_city(@places[0]) | ||
else | ||
render :update do |page| | ||
page.replace_html 'city_results_box', :partial => '/locations/link_to_city_id', :locals => {:name => params[:city_id_name]} | ||
page.show 'city_results_box' | ||
end | ||
def update_city_id | ||
return unless request.xhr? | ||
render :update do |page| | ||
page["city_id_field"].value= params[:city_id] | ||
end | ||
end | ||
|
||
def select_city_id | ||
city_id = params[:city_id] | ||
return_single_city(GeoPlace.find(city_id)) | ||
end | ||
|
||
private | ||
|
||
def return_single_city(geoplace) | ||
html_for_text_box = geoplace.name.capitalize | ||
html = "<input type='hidden' value='#{geoplace.id}' name='#{params[:city_id_name]}' id='city_id_field' />" | ||
render :update do |page| | ||
page["admin_code_#{geoplace.geo_admin_code.id}"].selected = true | ||
page['city_text_field'].value = html_for_text_box | ||
page.replace_html 'city_results', html | ||
page.hide 'city_results_box' | ||
end | ||
def update_model_with_country(id) | ||
return unless may_edit_location_profile?(@profile.entity) | ||
@profile.update_location({:country_id => id}) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.