diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index 582518e208..aaf33b2272 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -8,6 +8,8 @@ class EnterpriseGroup < ActiveRecord::Base validates :address, presence: true, associated: true before_validation :set_undefined_address_fields before_validation :set_unused_address_fields + after_find :unset_undefined_address_fields + after_save :unset_undefined_address_fields validates :name, presence: true validates :description, presence: true @@ -18,7 +20,7 @@ class EnterpriseGroup < ActiveRecord::Base attr_accessible :address_attributes attr_accessible :email, :website, :facebook, :instagram, :linkedin, :twitter - delegate :phone, :to => :address + delegate :phone, :address1, :address2, :city, :zipcode, :state, :country, :to => :address has_attached_file :logo, styles: {medium: "100x100"}, @@ -59,28 +61,12 @@ class EnterpriseGroup < ActiveRecord::Base address.zipcode.present? || address.zipcode = 'undefined' end - def phone - address.andand.phone.andand.sub('undefined', '') - end - - def address1 - address.andand.address1.andand.sub('undefined', '') - end - - def address2 - address.andand.address2.andand.sub('undefined', '') - end - - def city - address.andand.city.andand.sub('undefined', '') - end - - def state - address.andand.state - end - - def zipcode - address.andand.zipcode.andand.sub('undefined', '') + def unset_undefined_address_fields + return unless address.present? + address.phone.sub!(/^undefined$/, '') + address.address1.sub!(/^undefined$/, '') + address.city.sub!(/^undefined$/, '') + address.zipcode.sub!(/^undefined$/, '') end end diff --git a/app/views/admin/enterprise_groups/_inputs.html.haml b/app/views/admin/enterprise_groups/_inputs.html.haml index a9e911700a..02f5aa337c 100644 --- a/app/views/admin/enterprise_groups/_inputs.html.haml +++ b/app/views/admin/enterprise_groups/_inputs.html.haml @@ -63,13 +63,11 @@ .row .alpha.three.columns = af.label :phone - %span.required * .omega.eight.columns = af.text_field :phone, { placeholder: "eg. 98 7654 3210"} .row .three.columns.alpha = af.label :address1 - %span.required * .eight.columns.omega = af.text_field :address1, { placeholder: "eg. 123 High Street"} .row @@ -82,7 +80,6 @@ = af.label :city, 'Suburb' \/ = af.label :zipcode, 'Postcode' - %span.required * .four.columns = af.text_field :city, { placeholder: "eg. Northcote"} .four.columns.omega @@ -92,7 +89,6 @@ = af.label :state_id, 'State' \/ = af.label :country_id, 'Country' - %span.required * .four.columns = af.collection_select :state_id, af.object.country.states, :id, :name, {}, :class => "select2 fullwidth" .four.columns.omega diff --git a/app/views/groups/_contact.html.haml b/app/views/groups/_contact.html.haml index 458aa81dbe..c3da5e26ba 100644 --- a/app/views/groups/_contact.html.haml +++ b/app/views/groups/_contact.html.haml @@ -42,9 +42,10 @@ - if @group.address2.present? %br = @group.address2 - %br - = @group.city - = @group.state - = @group.zipcode + - if @group.city.present? + %br + = @group.city + = @group.state + = @group.zipcode