Add default supplier view and relationship to address.

This commit is contained in:
Andrew Spinks
2012-04-29 16:32:38 +10:00
parent 7ea0f73398
commit e4fd20b807
12 changed files with 99 additions and 46 deletions

View File

@@ -0,0 +1,5 @@
Spree::Product.class_eval do
attr_accessible :supplier_id
belongs_to :supplier
end

View File

@@ -2,16 +2,8 @@ module Spree
class Supplier < ActiveRecord::Base
set_table_name 'suppliers'
belongs_to :address
# has_many :orders
# belongs_to :country
# belongs_to :state
has_many :products
# validates :name, :pickup_address, :country_id, :state_id, :city, :post_code, :presence => true
# after_initialize :initialize_country
# def initialize_country
# self.country = Spree::Country.find_by_id(Spree::Config[:default_country_id])
# end
end
end

View File

@@ -0,0 +1,16 @@
%table{'data-hook' => "suppliers"}
%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' => "email"}
%td Email:
%td= f.text_field :email
%tr{'data-hook' => "website"}
%td Website:
%td= f.text_field :website
%tr{'data-hook' => "twitter"}
%td Twitter:
%td= f.text_field :twitter

View File

@@ -0,0 +1,5 @@
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
= form_for [:admin, @supplier] do |f|
= render :partial => 'form', :locals => { :f => f }
= render :partial => 'spree/admin/shared/edit_resource_links'

View File

@@ -1,37 +0,0 @@
<div class="toolbar" data-hook="toolbar">
<ul class="actions">
<li>
<%= button_link_to "New Supplier", spree.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link' %>
</li>
</ul>
<br class="clear" />
</div>
<table class="index" id='listing_suppliers'>
<thead>
<tr data-hook="suppliers_header">
<th>Name</th>
<th>
Description
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<% @suppliers.each do |supplier| %>
<tr >
<td><%= link_to supplier.name, spree.admin_supplier_path(supplier) %></td>
<td><%=supplier.description %></td>
<td data-hook="admin_supplier_index_row_actions">
<%= link_to_edit supplier, :class => 'edit' %> &nbsp;
<%= link_to_delete supplier %>
</td>
</tr>
<% end %>
<% if @suppliers.empty? %>
<tr><td colspan="2"><%= t(:none) %></td></tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,22 @@
.toolbar{'data-hook' => "suppliers"}
%ul.actions
%li= button_link_to "New Supplier", spree.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link'
%br.clear
%table#listing_suppliers.index
%thead
%tr{'data-hook' => "suppliers_header"}
%th Name
%th Description
%th
%tbody
- @suppliers.each do |supplier|
%tr
%td= link_to supplier.name, spree.admin_supplier_path(supplier)
%td= supplier.description
%td{'data-hook' => "admin_supplier_index_row_actions"}
= link_to_edit supplier, :class => 'edit'
&nbsp;
= link_to_delete supplier
- if @suppliers.empty?
%tr
%td{:colspan => "2"}= t(:none)

View File

@@ -0,0 +1,6 @@
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
= form_for [:admin, @supplier] do |f|
= render :partial => 'form', :locals => { :f => f }
= render :partial => 'spree/admin/shared/new_resource_links'

View File

@@ -0,0 +1,21 @@
%h1 Supplier
%table
%tr
%th Name
%td= @supplier.name
%tr
%th Description
%td= @supplier.description
%tr
%th Email
%td= @supplier.email
%tr
%th Website
%td= @supplier.website
%tr
%th Twitter
%td= @supplier.twitter
%p
= link_to :Edit, spree.edit_admin_supplier_path(@supplier), :class => 'edit_supplier'
= t(:or)
= link_to t(:back), spree.admin_suppliers_path

View File

@@ -0,0 +1,5 @@
class AddSupplierToProduct < ActiveRecord::Migration
def change
add_column :spree_products, :supplier_id, :integer
end
end

View File

@@ -0,0 +1,9 @@
require 'spec_helper'
describe Spree::Product do
describe "associations" do
it { should belong_to(:supplier) }
end
end

View File

@@ -2,8 +2,17 @@ require 'spec_helper'
describe Spree::Supplier do
describe "associations" do
it { should have_many(:products) }
it { should belong_to(:address) }
end
it "should have an address"
it "should add an address on save"
describe 'validations' do
# it{ should validate_presence_of(:comment) }
end
end