make distributors work in spree admin framework.

This commit is contained in:
Andrew Spinks
2012-04-07 12:10:44 +10:00
parent 0a6852616d
commit 3f1ed0ca06
17 changed files with 101 additions and 100 deletions

View File

@@ -1,45 +0,0 @@
class DistributorsController < ApplicationController
force_ssl
respond_to :html
helper 'spree/admin/navigation'
layout '/spree/layouts/admin'
def index
@distributors = Distributor.all
respond_with(@distributors)
end
def new
@distributor = Distributor.new
end
def edit
@distributor = Distributor.find(params[:id])
end
def update
@distributor = Distributor.find(params[:id])
if @distributor.update_attributes(params[:distributor])
redirect_to distributors_path
else
render :action => "edit"
end
end
def show
@distributor = Distributor.find(params[:id])
respond_with(@distributor)
end
def create
@distributor = Distributor.new(params[:distributor])
if @distributor.save
redirect_to distributors_path
else
render :action => "new"
end
end
end

View File

@@ -0,0 +1,8 @@
module Spree
module Admin
class DistributorsController < ResourceController
end
end
end

View File

@@ -1,2 +0,0 @@
class Distributor < ActiveRecord::Base
end

View File

@@ -0,0 +1,5 @@
module Spree
class Distributor < ActiveRecord::Base
set_table_name 'distributors'
end
end

View File

@@ -0,0 +1,5 @@
Deface::Override.new(:virtual_path => "spree/layouts/admin",
:name => "distributors_admin_tabs",
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
:text => "<%= tab(:distributors, :url => spree.admin_distributors_path) %>",
:disabled => false)

View File

@@ -0,0 +1,4 @@
Deface::Override.new(:virtual_path => "spree/checkout/_delivery",
:insert_before => "[data-hook='buttons']",
:text => "<p>TODO: Select a drop off point.... </p>",
:name => "drop_off_point")

View File

@@ -0,0 +1,4 @@
Deface::Override.new(:virtual_path => "spree/checkout/_delivery",
:insert_before => "[data-hook='buttons']",
:text => "<p>TODO: Select a drop off point.... </p>",
:name => "drop_off_point")

View File

@@ -1,13 +0,0 @@
<%= simple_form_for distributor do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.input :contact %>
<%= f.input :phone %>
<%= f.input :email %>
<%= f.input :pickup_address %>
<%= f.input :pickup_times %>
<%= f.input :url %>
<%= f.input :abn %>
<%= f.input :acn %>
<%= f.button :submit %>
<% end %>

View File

@@ -1,2 +0,0 @@
<%= render :partial => 'form', :locals => { :distributor => @distributor } %>

View File

@@ -1,31 +0,0 @@
<div class="toolbar" data-hook="toolbar">
<ul class="actions">
<li>
<%= button_link_to "New Distributor", new_distributor_path, :icon => 'add', :id => 'admin_new_distributor_link' %>
</li>
</ul>
<br class="clear" />
</div>
<table class="index" id='listing_distributors'>
<thead>
<tr data-hook="distributors_header">
<th>Name</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<% @distributors.each do |distributor| %>
<tr >
<td><%= link_to distributor.name, distributor_path(distributor) %></td>
<td><%=distributor.description %></td>
</tr>
<% end %>
<% if @distributors.empty? %>
<tr><td colspan="2"><%= t(:none) %></td></tr>
<% end %>
</tbody>
</table>

View File

@@ -1,2 +0,0 @@
<%= render :partial => 'form', :locals => { :distributor => @distributor } %>

View File

@@ -0,0 +1,51 @@
<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_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,6 @@
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @distributor } %>
<%= form_for [:admin, @distributor] do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= render :partial => 'spree/admin/shared/edit_resource_links' %>
<% end %>

View File

@@ -2,7 +2,7 @@
<div class="toolbar" data-hook="toolbar">
<ul class="actions">
<li>
<%= link_to "New Distributor", "new", :icon => 'add', :id => 'admin_new_distributor_link' %>
<%= button_link_to "New Distributor", spree.new_admin_distributor_path, :icon => 'add', :id => 'admin_new_distributor_link' %>
</li>
</ul>
<br class="clear" />
@@ -20,7 +20,7 @@
<tbody>
<% @distributors.each do |distributor| %>
<tr >
<td><%=distributor.name %></td>
<td><%= link_to distributor.name, spree.admin_distributor_path(distributor) %></td>
<td><%=distributor.description %></td>
</tr>
<% end %>

View File

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

View File

@@ -67,6 +67,6 @@
</table>
<p>
<%= link_to :Edit, edit_distributor_path(@distributor), :class => 'edit_distributor' %> <%= t(:or) %>
<%= link_to t(:back), distributors_path %>
<%= 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

@@ -1,5 +1,5 @@
Openfoodweb::Application.routes.draw do
resources :distributors
# resources :distributors
# Mount Spree's routes
mount Spree::Core::Engine, :at => '/'
@@ -61,3 +61,9 @@ Openfoodweb::Application.routes.draw do
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
end
Spree::Core::Engine.routes.prepend do
namespace :admin do
resources :distributors
end
end