Commit 04d456dfb262653951e521be315ff6877d26448e
Committed by
Rafael Martins
1 parent
5d43b171
Exists in
master
and in
29 other branches
Sync city/state with Region
Showing
4 changed files
with
42 additions
and
0 deletions
Show diff stats
app/models/community.rb
... | ... | @@ -10,6 +10,9 @@ class Community < Organization |
10 | 10 | settings_items :language |
11 | 11 | settings_items :zip_code, :city, :state, :country |
12 | 12 | |
13 | + extend SetProfileRegionFromCityState::ClassMethods | |
14 | + set_profile_region_from_city_state | |
15 | + | |
13 | 16 | before_create do |community| |
14 | 17 | community.moderated_articles = true if community.environment.enabled?('organizations_are_moderated_by_default') |
15 | 18 | end | ... | ... |
app/models/enterprise.rb
... | ... | @@ -20,6 +20,9 @@ class Enterprise < Organization |
20 | 20 | |
21 | 21 | settings_items :organization_website, :historic_and_current_context, :activities_short_description, :zip_code, :city, :state, :country |
22 | 22 | |
23 | + extend SetProfileRegionFromCityState::ClassMethods | |
24 | + set_profile_region_from_city_state | |
25 | + | |
23 | 26 | before_save do |enterprise| |
24 | 27 | enterprise.organization_website = enterprise.maybe_add_http(enterprise.organization_website) |
25 | 28 | end | ... | ... |
app/models/person.rb
... | ... | @@ -177,6 +177,9 @@ class Person < Profile |
177 | 177 | N_('Contact information'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code') |
178 | 178 | settings_items :photo, :contact_information, :sex, :city, :state, :country, :zip_code |
179 | 179 | |
180 | + extend SetProfileRegionFromCityState::ClassMethods | |
181 | + set_profile_region_from_city_state | |
182 | + | |
180 | 183 | def self.conditions_for_profiles(conditions, person) |
181 | 184 | new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person]) |
182 | 185 | new_conditions << ' AND ' + sanitize_sql(conditions) unless conditions.blank? | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +module SetProfileRegionFromCityState | |
2 | + | |
3 | + module ClassMethods | |
4 | + def set_profile_region_from_city_state | |
5 | + before_save :region_from_city_and_state | |
6 | + | |
7 | + include InstanceMethods | |
8 | + end | |
9 | + end | |
10 | + | |
11 | + module InstanceMethods | |
12 | + | |
13 | + def city=(value) | |
14 | + self.data[:city] = value | |
15 | + @change_region = true | |
16 | + end | |
17 | + | |
18 | + def state=(value) | |
19 | + self.data[:state] = value | |
20 | + @change_region = true | |
21 | + end | |
22 | + | |
23 | + def region_from_city_and_state | |
24 | + if @change_region | |
25 | + s = State.find_by_name self.state | |
26 | + c = s.children.find_by_name self.city | |
27 | + self.region = c | |
28 | + end | |
29 | + end | |
30 | + | |
31 | + end | |
32 | + | |
33 | +end | ... | ... |