mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
make distributors work in spree admin framework.
This commit is contained in:
@@ -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
|
||||
8
app/controllers/spree/admin/distributors_controller.rb
Normal file
8
app/controllers/spree/admin/distributors_controller.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module Spree
|
||||
module Admin
|
||||
class DistributorsController < ResourceController
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
class Distributor < ActiveRecord::Base
|
||||
end
|
||||
5
app/models/spree/distributor.rb
Normal file
5
app/models/spree/distributor.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Spree
|
||||
class Distributor < ActiveRecord::Base
|
||||
set_table_name 'distributors'
|
||||
end
|
||||
end
|
||||
5
app/overrides/distributors_admin_tab.rb
Normal file
5
app/overrides/distributors_admin_tab.rb
Normal 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)
|
||||
4
app/overrides/drop_off_point.rb
Normal file
4
app/overrides/drop_off_point.rb
Normal 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")
|
||||
4
app/overrides/replace_delivery_addres.rb
Normal file
4
app/overrides/replace_delivery_addres.rb
Normal 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")
|
||||
@@ -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 %>
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
<%= render :partial => 'form', :locals => { :distributor => @distributor } %>
|
||||
@@ -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>
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
<%= render :partial => 'form', :locals => { :distributor => @distributor } %>
|
||||
51
app/views/spree/admin/distributors/_form.html.erb
Normal file
51
app/views/spree/admin/distributors/_form.html.erb
Normal 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>
|
||||
6
app/views/spree/admin/distributors/edit.html.erb
Normal file
6
app/views/spree/admin/distributors/edit.html.erb
Normal 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 %>
|
||||
@@ -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 %>
|
||||
|
||||
7
app/views/spree/admin/distributors/new.html.erb
Normal file
7
app/views/spree/admin/distributors/new.html.erb
Normal 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 %>
|
||||
@@ -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>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user