GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Adds basic social networking capabilities to your existing application, including users, blogs, photos, clippings, favorites, and more.
Homepage: http://www.communityengine.org
Clone URL: git://github.com/bborn/communityengine.git
applied location chooser patch from simon, fixed a few errors
bborn (author)
Thu Sep 04 11:31:32 -0700 2008
commit  1640d961372d00441f40f5eac133e1198472648f
tree    a8f7e9bf1cf281f780a11232b2bbe113a8a2589a
parent  6eb615836568e9bf94e1ca15618730e30a252038
...
297
298
299
300
301
302
 
 
 
 
 
 
 
303
304
305
306
307
308
309
310
 
 
 
 
 
 
 
 
 
311
312
313
...
348
349
350
351
 
 
 
 
 
 
352
353
354
355
 
356
357
 
358
359
360
...
297
298
299
 
 
 
300
301
302
303
304
305
306
307
 
 
 
 
 
 
 
308
309
310
311
312
313
314
315
316
317
318
319
...
354
355
356
 
357
358
359
360
361
362
363
 
 
 
364
365
 
366
367
368
369
0
@@ -297,17 +297,23 @@ class UsersController < BaseController
0
 
0
   def metro_area_update
0
     return unless request.xhr?
0
- if params[:state_id]
0
- metro_areas = MetroArea.find_all_by_state_id(params[:state_id], :order => "name")
0
- render :partial => 'shared/location_chooser', :locals => {:states => State.find(:all), :metro_areas => metro_areas, :selected_country => Country.get(:us).id, :selected_state => params[:state_id].to_i, :selected_metro_area => nil }
0
+
0
+ country = Country.find(params[:country_id]) unless params[:country_id].blank?
0
+ state = State.find(params[:state_id]) unless params[:state_id].blank?
0
+ states = country ? country.states : []
0
+
0
+ if states.any?
0
+ metro_areas = state ? state.metro_areas.all(:order => "name") : []
0
     else
0
- if params[:country_id].to_i.eql?(Country.get(:us).id)
0
- render :partial => 'shared/location_chooser', :locals => {:states => State.find(:all), :metro_areas => [], :selected_country => params[:country_id].to_i, :selected_state => params[:state_id].to_i, :selected_metro_area => nil }
0
- else
0
- metro_areas = MetroArea.find_all_by_country_id(params[:country_id], :order => "name")
0
- render :partial => 'shared/location_chooser', :locals => {:states => [], :metro_areas => metro_areas, :selected_country => params[:country_id].to_i, :selected_state => nil, :selected_metro_area => nil }
0
- end
0
- end
0
+ metro_areas = country ? country.metro_areas : []
0
+ end
0
+
0
+ render :partial => 'shared/location_chooser', :locals => {
0
+ :states => states,
0
+ :metro_areas => metro_areas,
0
+ :selected_country => params[:country_id].to_i,
0
+ :selected_state => params[:state_id].to_i,
0
+ :selected_metro_area => nil }
0
   end
0
   
0
   def toggle_featured
0
@@ -348,13 +354,16 @@ class UsersController < BaseController
0
   end
0
   
0
   def setup_locations_for(user)
0
- metro_areas = []
0
+ metro_areas = states = []
0
+
0
+ if user.country
0
+ states = user.country.states
0
+ end
0
+
0
     if user.state
0
- metro_areas = @user.state.metro_areas
0
- elsif user.country
0
- metro_areas = user.country.metro_areas
0
+ metro_areas = user.state.metro_areas.all(:order => "name");
0
     end
0
- states = user.country.eql?(Country.get(:us)) ? State.find(:all) : []
0
+
0
     return metro_areas, states
0
   end
0
 
...
13
14
15
 
 
 
 
 
 
 
 
16
...
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -13,4 +13,12 @@ class Country < ActiveRecord::Base
0
     MetroArea.find(:all, :include => :country).collect{ |m| m.country }.sort_by{ |c| c.name }.uniq
0
   end
0
   
0
+ def states
0
+ State.find(:all, :include => :metro_areas, :conditions => ["metro_areas.id in (?)", metro_area_ids ]).uniq
0
+ end
0
+
0
+ def metro_area_ids
0
+ metro_areas.map{|m| m.id }
0
+ end
0
+
0
 end
...
1
2
 
3
4
5
 
 
 
 
 
 
6
7
 
 
 
 
 
 
8
9
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
 
2
3
4
 
5
6
7
8
9
10
11
 
12
13
14
15
16
17
18
 
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
0
@@ -1,10 +1,32 @@
0
 %span#location_chooser
0
- ="Country:".l
0
+ = "Country:".l
0
   %br
0
   = select_tag(:country_id, '<option></option>'+options_from_collection_for_select(Country.find_countries_with_metros, "id", "name", selected_country), {:style => "width:100px"})
0
- = "<br />"+"State:".l+" <br />" + select_tag(:state_id, '<option></option>'+options_from_collection_for_select(State.find(:all), "id", "name", (selected_state rescue nil)), {:style => "width:100px", :disabled => states.empty? } )
0
+
0
+ %br
0
+ = "State:".l
0
+ %br
0
+ = select_tag(:state_id, '<option></option>' + options_from_collection_for_select(states, "id", "name", (selected_state rescue nil)), {:style => "width:100px", :disabled => states.empty? })
0
+
0
   = image_tag 'spinner.gif', :plugin => 'community_engine', :style => 'display:none;'
0
- = "<br />" + "Metro Area:".l + "<br />" + select_tag(:metro_area_id, options_from_collection_for_select(metro_areas, "id", "name", (selected_metro_area rescue nil)), {:style => "width:100px", :disabled => metro_areas.empty? } )
0
+
0
+ %br
0
+ = "Metro Area:".l
0
+ %br
0
+ = select_tag(:metro_area_id, options_from_collection_for_select(metro_areas, "id", "name", (selected_metro_area rescue nil)), {:style => "width:100px", :disabled => metro_areas.empty? })
0
+
0
   = image_tag 'spinner.gif', :plugin => 'community_engine', :style => 'display:none;'
0
-= observe_field "state_id", {:url => {:controller => 'users', :action => 'metro_area_update'}, :with => "state_id", :loading => "$$('span#location_chooser img')[0].show();", 500 => "alert('Sorry, there was an error.'.l); return false", :update => "location_chooser"}
0
-= observe_field "country_id", {:url => {:controller => 'users', :action => 'metro_area_update'}, :with => "country_id", :loading => "$$('span#location_chooser img')[0].show();", 500 => "alert('Sorry, there was an error.'.l); return false", :update => "location_chooser"}
0
+
0
+= observe_field("state_id", {:url => {:controller => 'users', :action => 'metro_area_update'}, |
0
+ :with => "'state_id=' + $('state_id').value + '&country_id=' + $('country_id').value", |
0
+ :loading => "$$('span#location_chooser img')[0].show();", |
0
+ 500 => "alert('Sorry, there was an error.'.l); return false", |
0
+ :update => "location_chooser"}) |
0
+
0
+%span
0
+
0
+= observe_field("country_id", {:url => {:controller => 'users', :action => 'metro_area_update'}, |
0
+ :with => "country_id", |
0
+ :loading => "$$('span#location_chooser img')[0].show();", |
0
+ 500 => "alert('Sorry, there was an error.'.l); return false", |
0
+ :update => "location_chooser"}) |

Comments

    No one has commented yet.