Update admin backend for supplier/distributor address extraction

This commit is contained in:
Rohan Mitchell
2012-06-26 14:54:35 +10:00
parent ba3c02346d
commit 4b9c0f01e2
11 changed files with 124 additions and 215 deletions

View File

@@ -5,12 +5,12 @@ module Spree
private
def load_data
@countries = Country.order(:name)
@countries = Country.order(:name)
end
def collection
super.order(:name)
super.order(:name)
end
end
end
end
end

View File

@@ -1,67 +0,0 @@
<table data-hook="distributors">
<tr data-hook="name">
<td>Name:</td>
<td><%= f.text_field :name %></td>
</tr>
<tr data-hook="description">
<td>Description:</td>
<td><%= f.text_field :description %></td>
</tr>
<tr data-hook="contact">
<td>Contact:</td>
<td><%= f.text_field :contact %></td>
</tr>
<tr data-hook="phone">
<td>Phone:</td>
<td><%= f.text_field :phone %></td>
</tr>
<tr data-hook="email">
<td>Email:</td>
<td><%= f.text_field :email %></td>
</tr>
<tr data-hook="pickup_address">
<td>Address: </td>
<td><%= f.text_field :pickup_address %></td>
</tr>
<tr data-hook="pickup_city">
<td>City:</td>
<td><%= f.text_field :city %></td>
</tr>
<tr data-hook="pickup_post_code">
<td>Post code:</td>
<td><%= f.text_field :post_code %></td>
</tr>
<tr data-hook="pickup_country">
<td>Country: </td>
<td><%= f.collection_select(:country_id, @countries, :id, :name, :include_blank => true) %></td>
</tr>
<tr data-hook="pickup_state">
<td>State: </td>
<td><%= f.collection_select(:state_id, @distributor.country.states, :id, :name, :include_blank => true) %></td>
</tr>
<tr data-hook="pickup_times">
<td>Pickup times:</td>
<td><%= f.text_field :pickup_times %></td>
</tr>
<tr data-hook="url">
<td>URL:</td>
<td><%= f.text_field :url %></td>
</tr>
<tr data-hook="abn">
<td>ABN:</td>
<td><%= f.text_field :abn %></td>
</tr>
<tr data-hook="acn">
<td>ACN:</td>
<td><%= f.text_field :acn %></td>
</tr>
</table>

View File

@@ -0,0 +1,33 @@
%table{"data-hook" => "distributors"}
%tr{"data-hook" => "name"}
%td Name:
%td= f.text_field :name
%tr{"data-hook" => "description"}
%td Description:
%td= f.text_field :description
%tr{"data-hook" => "contact"}
%td Contact:
%td= f.text_field :contact
%tr{"data-hook" => "phone"}
%td Phone:
%td= f.text_field :phone
%tr{"data-hook" => "email"}
%td Email:
%td= f.text_field :email
%tr{"data-hook" => "url"}
%td URL:
%td= f.text_field :url
%tr{"data-hook" => "abn"}
%td ABN:
%td= f.text_field :abn
%tr{"data-hook" => "acn"}
%td ACN:
%td= f.text_field :acn
%fieldset
%legend Pickup details
%table{"data-hook" => "distributors_pickup_details"}
%tr{"data-hook" => "pickup_times"}
%td Pickup times:
%td= f.text_field :pickup_times
= f.fields_for :pickup_address do |pickup_address_form|
= render 'spree/admin/shared/address_form', :form => pickup_address_form

View File

@@ -1,92 +0,0 @@
<h1>Distributor</h1>
<table>
<tr>
<th>Name</th>
<td>
<%= @distributor.name %>
</td>
</tr>
<tr>
<th>Description</th>
<td>
<%= @distributor.description %>
</td>
</tr>
<tr>
<th>Contact person</th>
<td>
<%= @distributor.contact %>
</td>
</tr>
<tr>
<th>Phone number</th>
<td>
<%= @distributor.phone %>
</td>
</tr>
<tr>
<th>Email</th>
<td>
<%= @distributor.email %>
</td>
</tr>
<th>Pickup address</th>
<td>
<%= @distributor.pickup_address %>
</td>
</tr>
<th>Pickup city</th>
<td>
<%= @distributor.city %>
</td>
</tr>
<th>Pickup post code</th>
<td>
<%= @distributor.post_code %>
</td>
</tr>
<th>Pickup country</th>
<td>
<%= @distributor.country.name if @distributor.country %>
</td>
</tr>
<th>Pickup state</th>
<td>
<%= @distributor.state.name if @distributor.state %>
</td>
</tr>
<th>Pickup times</th>
<td>
<%= @distributor.pickup_times %>
</td>
</tr>
<th>ABN</th>
<td>
<%= @distributor.abn %>
</td>
</tr>
<th>ACN</th>
<td>
<%= @distributor.acn %>
</td>
</tr>
<th>URL</th>
<td>
<%= @distributor.url %>
</td>
</tr>
</table>
<p>
<%= link_to :Edit, spree.edit_admin_distributor_path(@distributor), :class => 'edit_distributor' %> <%= t(:or) %>
<%= link_to t(:back), spree.admin_distributors_path %>
</p>

View File

@@ -0,0 +1,36 @@
%h1 Distributor
%table
%tr
%th Name:
%td= @distributor.name
%tr
%th Description:
%td= @distributor.description
%tr
%th Contact person:
%td= @distributor.contact
%tr
%th Phone number:
%td= @distributor.phone
%tr
%th Email:
%td= @distributor.email
%tr
%th Pickup address:
%td= render 'spree/admin/shared/address', :address => @distributor.pickup_address
%tr
%th Pickup times:
%td= @distributor.pickup_times
%tr
%th ABN:
%td= @distributor.abn
%tr
%th ACN:
%td= @distributor.acn
%tr
%th URL:
%td= @distributor.url
%p
= link_to :Edit, spree.edit_admin_distributor_path(@distributor), :class => 'edit_distributor'
= t(:or)
= link_to t(:back), spree.admin_distributors_path

View File

@@ -0,0 +1,4 @@
= address.address1
= ", #{address.address2}" unless address.address2.blank?
%br/
= [address.city, address.state_text, address.zipcode, address.country.name].compact.join ', '

View File

@@ -0,0 +1,18 @@
%tr{"data-hook" => "address1"}
%td Address:
%td= form.text_field :address1
%tr{"data-hook" => "address2"}
%td Address (cont.):
%td= form.text_field :address2
%tr{"data-hook" => "city"}
%td City:
%td= form.text_field :city
%tr{"data-hook" => "zipcode"}
%td Postcode:
%td= form.text_field :zipcode
%tr{"data-hook" => "country"}
%td Country:
%td= form.collection_select(:country_id, available_countries, :id, :name)
%tr{"data-hook" => "state"}
%td State:
%td= form.collection_select(:state_id, form.object.country.states, :id, :name)

View File

@@ -5,21 +5,8 @@
%tr{'data-hook' => "description"}
%td Description:
%td= f.text_field :description
%tr{'data-hook' => "address"}
%td Address:
%td= f.text_field :address
%tr{'data-hook' => "city"}
%td City:
%td= f.text_field :city
%tr{'data-hook' => "post_code"}
%td Post Code:
%td= f.text_field :postcode
%tr{'data-hook' => "country"}
%td Country:
%td= f.collection_select(:country_id, @countries, :id, :name, :include_blank => true)
%tr{'data-hook' => "state"}
%td State:
%td= f.collection_select(:state_id, @supplier.country.states, :id, :name, :include_blank => true)
= f.fields_for :address do |address_form|
= render 'spree/admin/shared/address_form', :form => address_form
%tr{'data-hook' => "email"}
%td Email:
%td= f.text_field :email
@@ -28,4 +15,4 @@
%td= f.text_field :website
%tr{'data-hook' => "twitter"}
%td Twitter:
%td= f.text_field :twitter
%td= f.text_field :twitter

View File

@@ -1,34 +1,22 @@
%h1 Supplier
%table
%tr
%th Name
%th Name:
%td= @supplier.name
%tr
%th Description
%th Description:
%td= @supplier.description
%tr
%th Address
%td= @supplier.address
%th Address:
%td= render 'spree/admin/shared/address', :address => @supplier.address
%tr
%th City:
%td= @supplier.city
%tr
%th Post Code:
%td= @supplier.postcode
%tr
%th Country:
%td= @supplier.country.name if @supplier.country
%tr
%th State:
%td= @supplier.state.name if @supplier.state
%tr
%th Email
%th Email:
%td= @supplier.email
%tr
%th Website
%th Website:
%td= @supplier.website
%tr
%th Twitter
%th Twitter:
%td= @supplier.twitter
%p
= link_to :Edit, spree.edit_admin_supplier_path(@supplier), :class => 'edit_supplier'

View File

@@ -7,11 +7,9 @@ feature %q{
include AuthenticationWorkflow
include WebHelper
background do
end
context "Given I am setting up distributors" do
scenario "I should be able to create a new distributor" do
context "setting up distributors" do
scenario "creating a new distributor" do
login_to_admin_section
click_link 'Distributors'
@@ -21,11 +19,13 @@ feature %q{
fill_in 'distributor_description', :with => 'Connecting farmers and eaters'
fill_in 'distributor_contact', :with => 'Kirsten or Ren'
fill_in 'distributor_phone', :with => '0413 897 321'
fill_in 'distributor_pickup_address', :with => '35 Ballantyne St'
fill_in 'distributor_city', :with => 'Thornbury'
fill_in 'distributor_post_code', :with => '3072'
select('Australia', :from => 'distributor_country_id')
select('Victoria', :from => 'distributor_state_id')
fill_in 'distributor_pickup_address_attributes_address1', :with => '35 Ballantyne St'
fill_in 'distributor_pickup_address_attributes_city', :with => 'Thornbury'
fill_in 'distributor_pickup_address_attributes_zipcode', :with => '3072'
select('Australia', :from => 'distributor_pickup_address_attributes_country_id')
select('Victoria', :from => 'distributor_pickup_address_attributes_state_id')
fill_in 'distributor_pickup_times', :with => 'Thursday, 22nd Feb, 6 - 9 PM. Friday, 23nd Feb, 6 - 9 PM'
fill_in 'distributor_email', :with => 'info@eaterprises.com.au'
fill_in 'distributor_url', :with => 'http://eaterprises.com.au'

View File

@@ -10,27 +10,29 @@ feature %q{
background do
end
context "Given I am setting up suppliers" do
scenario "I should be able to create a new supplier" do
context "setting up suppliers" do
scenario "creating a new supplier" do
login_to_admin_section
click_link 'Suppliers'
click_link 'New Supplier'
fill_in 'supplier_name', :with => 'David arnold'
fill_in 'supplier_name', :with => 'David Arnold'
fill_in 'supplier_description', :with => 'A farmer with a difference'
fill_in 'supplier_address', :with => '35 Byron Ave'
fill_in 'supplier_city', :with => 'Ararat'
fill_in 'supplier_postcode', :with => '1112'
select('Australia', :from => 'supplier_country_id')
select('Victoria', :from => 'supplier_state_id')
fill_in 'supplier_address_attributes_address1', :with => '35 Byron Ave'
fill_in 'supplier_address_attributes_city', :with => 'Ararat'
fill_in 'supplier_address_attributes_zipcode', :with => '1112'
select('Australia', :from => 'supplier_address_attributes_country_id')
select('Victoria', :from => 'supplier_address_attributes_state_id')
fill_in 'supplier_email', :with => 'david@here.com'
fill_in 'supplier_website', :with => 'http://somewhere.com'
fill_in 'supplier_twitter', :with => 'davida'
click_button 'Create'
flash_message.should == 'Supplier "David arnold" has been successfully created!'
flash_message.should == 'Supplier "David Arnold" has been successfully created!'
end
end
end