Commit 04d456dfb262653951e521be315ff6877d26448e

Authored by Braulio Bhavamitra
Committed by Rafael Martins
1 parent 5d43b171

Sync city/state with Region

app/models/community.rb
@@ -10,6 +10,9 @@ class Community < Organization @@ -10,6 +10,9 @@ class Community < Organization
10 settings_items :language 10 settings_items :language
11 settings_items :zip_code, :city, :state, :country 11 settings_items :zip_code, :city, :state, :country
12 12
  13 + extend SetProfileRegionFromCityState::ClassMethods
  14 + set_profile_region_from_city_state
  15 +
13 before_create do |community| 16 before_create do |community|
14 community.moderated_articles = true if community.environment.enabled?('organizations_are_moderated_by_default') 17 community.moderated_articles = true if community.environment.enabled?('organizations_are_moderated_by_default')
15 end 18 end
app/models/enterprise.rb
@@ -20,6 +20,9 @@ class Enterprise < Organization @@ -20,6 +20,9 @@ class Enterprise < Organization
20 20
21 settings_items :organization_website, :historic_and_current_context, :activities_short_description, :zip_code, :city, :state, :country 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 before_save do |enterprise| 26 before_save do |enterprise|
24 enterprise.organization_website = enterprise.maybe_add_http(enterprise.organization_website) 27 enterprise.organization_website = enterprise.maybe_add_http(enterprise.organization_website)
25 end 28 end
app/models/person.rb
@@ -177,6 +177,9 @@ class Person < Profile @@ -177,6 +177,9 @@ class Person < Profile
177 N_('Contact information'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code') 177 N_('Contact information'); N_('City'); N_('State'); N_('Country'); N_('Sex'); N_('Zip code')
178 settings_items :photo, :contact_information, :sex, :city, :state, :country, :zip_code 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 def self.conditions_for_profiles(conditions, person) 183 def self.conditions_for_profiles(conditions, person)
181 new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person]) 184 new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person])
182 new_conditions << ' AND ' + sanitize_sql(conditions) unless conditions.blank? 185 new_conditions << ' AND ' + sanitize_sql(conditions) unless conditions.blank?
lib/set_profile_region_from_city_state.rb 0 → 100644
@@ -0,0 +1,33 @@ @@ -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