diff --git a/app/controllers/admin/enterprise_groups_controller.rb b/app/controllers/admin/enterprise_groups_controller.rb index cc2f3ed1db..7a0763f5a4 100644 --- a/app/controllers/admin/enterprise_groups_controller.rb +++ b/app/controllers/admin/enterprise_groups_controller.rb @@ -1,5 +1,7 @@ module Admin class EnterpriseGroupsController < ResourceController + before_filter :load_countries, :except => :index + def index end @@ -15,8 +17,22 @@ module Admin redirect_to main_app.admin_enterprise_groups_path end + protected + + def build_resource_with_address + enterprise_group = build_resource_without_address + enterprise_group.address = Spree::Address.new + enterprise_group.address.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) + enterprise_group + end + alias_method_chain :build_resource, :address + private + def load_countries + @countries = Spree::Country.order(:name) + end + def collection EnterpriseGroup.by_position end diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index 6e61b1a564..25fcadca5d 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -2,6 +2,10 @@ class EnterpriseGroup < ActiveRecord::Base acts_as_list has_and_belongs_to_many :enterprises + belongs_to :address, :class_name => 'Spree::Address' + accepts_nested_attributes_for :address + validates :address, presence: true, associated: true + before_validation :set_unused_address_fields validates :name, presence: true validates :description, presence: true @@ -28,4 +32,9 @@ class EnterpriseGroup < ActiveRecord::Base scope :by_position, order('position ASC') scope :on_front_page, where(on_front_page: true) + + def set_unused_address_fields + address.firstname = address.lastname = address.phone = 'unused' if address.present? + end + end diff --git a/app/views/admin/enterprise_groups/_inputs.html.haml b/app/views/admin/enterprise_groups/_inputs.html.haml index d3baec4a0c..82fdc3eece 100644 --- a/app/views/admin/enterprise_groups/_inputs.html.haml +++ b/app/views/admin/enterprise_groups/_inputs.html.haml @@ -47,6 +47,37 @@ = image_tag @object.promo_image.url if @object.promo_image.present? = f.file_field :promo_image -%fieldset.alpha.no-border-bottom{ ng: { show: "menu.selected.name=='Contact'" } } - %legend Contact - TODO += f.fields_for :address do |af| + %fieldset.alpha.no-border-bottom{ ng: { show: "menu.selected.name=='Contact'" } } + %legend Contact + .row + .three.columns.alpha + = af.label :address1 + %span.required * + .eight.columns.omega + = af.text_field :address1, { placeholder: "eg. 123 High Street"} + .row + .alpha.three.columns + = af.label :address2 + .eight.columns.omega + = af.text_field :address2 + .row + .three.columns.alpha + = af.label :city, 'Suburb' + \/ + = af.label :zipcode, 'Postcode' + %span.required * + .four.columns + = af.text_field :city, { placeholder: "eg. Northcote"} + .four.columns.omega + = af.text_field :zipcode, { placeholder: "eg. 3070"} + .row + .three.columns.alpha + = 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 + = af.collection_select :country_id, available_countries, :id, :name, {}, :class => "select2 fullwidth" diff --git a/db/migrate/20150115050935_add_addresses_ref_to_enterprise_groups.rb b/db/migrate/20150115050935_add_addresses_ref_to_enterprise_groups.rb new file mode 100644 index 0000000000..8b2ca415b1 --- /dev/null +++ b/db/migrate/20150115050935_add_addresses_ref_to_enterprise_groups.rb @@ -0,0 +1,6 @@ +class AddAddressesRefToEnterpriseGroups < ActiveRecord::Migration + def change + add_column :enterprise_groups, :address_id, :integer + add_foreign_key :enterprise_groups, :spree_addresses, name: "enterprise_groups_address_id_fk", column: "address_id" + end +end diff --git a/db/schema.rb b/db/schema.rb index 3244916b3b..16c616f1a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20141210233407) do +ActiveRecord::Schema.define(:version => 20150115050935) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -197,6 +197,7 @@ ActiveRecord::Schema.define(:version => 20141210233407) do t.string "logo_content_type" t.integer "logo_file_size" t.datetime "logo_updated_at" + t.integer "address_id" end create_table "enterprise_groups_enterprises", :id => false, :force => true do |t| @@ -573,9 +574,9 @@ ActiveRecord::Schema.define(:version => 20141210233407) do t.string "email" t.text "special_instructions" t.integer "distributor_id" - t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" + t.integer "order_cycle_id" t.integer "cart_id" end @@ -1077,6 +1078,8 @@ ActiveRecord::Schema.define(:version => 20141210233407) do add_foreign_key "enterprise_fees", "enterprises", name: "enterprise_fees_enterprise_id_fk" + add_foreign_key "enterprise_groups", "spree_addresses", name: "enterprise_groups_address_id_fk", column: "address_id" + add_foreign_key "enterprise_groups_enterprises", "enterprise_groups", name: "enterprise_groups_enterprises_enterprise_group_id_fk" add_foreign_key "enterprise_groups_enterprises", "enterprises", name: "enterprise_groups_enterprises_enterprise_id_fk"