From 3f1ed0ca0656f292ddd63c010e8e95a2b3a7d8ed Mon Sep 17 00:00:00 2001 From: Andrew Spinks Date: Sat, 7 Apr 2012 12:10:44 +1000 Subject: [PATCH] make distributors work in spree admin framework. --- app/controllers/distributors_controller.rb | 45 ---------------- .../spree/admin/distributors_controller.rb | 8 +++ app/models/distributor.rb | 2 - app/models/spree/distributor.rb | 5 ++ app/overrides/distributors_admin_tab.rb | 5 ++ app/overrides/drop_off_point.rb | 4 ++ app/overrides/replace_delivery_addres.rb | 4 ++ app/views/distributors/_form.html.erb | 13 ----- app/views/distributors/edit.html.erb | 2 - app/views/distributors/index.html.erb | 31 ----------- app/views/distributors/new.html.erb | 2 - .../spree/admin/distributors/_form.html.erb | 51 +++++++++++++++++++ .../spree/admin/distributors/edit.html.erb | 6 +++ .../spree/admin/distributors/index.html.erb | 4 +- .../spree/admin/distributors/new.html.erb | 7 +++ .../{ => spree/admin}/distributors/show.html | 4 +- config/routes.rb | 8 ++- 17 files changed, 101 insertions(+), 100 deletions(-) delete mode 100644 app/controllers/distributors_controller.rb create mode 100644 app/controllers/spree/admin/distributors_controller.rb delete mode 100644 app/models/distributor.rb create mode 100644 app/models/spree/distributor.rb create mode 100644 app/overrides/distributors_admin_tab.rb create mode 100644 app/overrides/drop_off_point.rb create mode 100644 app/overrides/replace_delivery_addres.rb delete mode 100644 app/views/distributors/_form.html.erb delete mode 100644 app/views/distributors/edit.html.erb delete mode 100644 app/views/distributors/index.html.erb delete mode 100644 app/views/distributors/new.html.erb create mode 100644 app/views/spree/admin/distributors/_form.html.erb create mode 100644 app/views/spree/admin/distributors/edit.html.erb create mode 100644 app/views/spree/admin/distributors/new.html.erb rename app/views/{ => spree/admin}/distributors/show.html (83%) diff --git a/app/controllers/distributors_controller.rb b/app/controllers/distributors_controller.rb deleted file mode 100644 index 5b95f601ff..0000000000 --- a/app/controllers/distributors_controller.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/app/controllers/spree/admin/distributors_controller.rb b/app/controllers/spree/admin/distributors_controller.rb new file mode 100644 index 0000000000..5445599ae3 --- /dev/null +++ b/app/controllers/spree/admin/distributors_controller.rb @@ -0,0 +1,8 @@ +module Spree + module Admin + class DistributorsController < ResourceController + + + end + end +end \ No newline at end of file diff --git a/app/models/distributor.rb b/app/models/distributor.rb deleted file mode 100644 index 42b3d016d6..0000000000 --- a/app/models/distributor.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Distributor < ActiveRecord::Base -end diff --git a/app/models/spree/distributor.rb b/app/models/spree/distributor.rb new file mode 100644 index 0000000000..d4532040fe --- /dev/null +++ b/app/models/spree/distributor.rb @@ -0,0 +1,5 @@ +module Spree + class Distributor < ActiveRecord::Base + set_table_name 'distributors' + end +end diff --git a/app/overrides/distributors_admin_tab.rb b/app/overrides/distributors_admin_tab.rb new file mode 100644 index 0000000000..66e4946b40 --- /dev/null +++ b/app/overrides/distributors_admin_tab.rb @@ -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) diff --git a/app/overrides/drop_off_point.rb b/app/overrides/drop_off_point.rb new file mode 100644 index 0000000000..25b80c7116 --- /dev/null +++ b/app/overrides/drop_off_point.rb @@ -0,0 +1,4 @@ +Deface::Override.new(:virtual_path => "spree/checkout/_delivery", + :insert_before => "[data-hook='buttons']", + :text => "

TODO: Select a drop off point....

", + :name => "drop_off_point") \ No newline at end of file diff --git a/app/overrides/replace_delivery_addres.rb b/app/overrides/replace_delivery_addres.rb new file mode 100644 index 0000000000..25b80c7116 --- /dev/null +++ b/app/overrides/replace_delivery_addres.rb @@ -0,0 +1,4 @@ +Deface::Override.new(:virtual_path => "spree/checkout/_delivery", + :insert_before => "[data-hook='buttons']", + :text => "

TODO: Select a drop off point....

", + :name => "drop_off_point") \ No newline at end of file diff --git a/app/views/distributors/_form.html.erb b/app/views/distributors/_form.html.erb deleted file mode 100644 index f3fdc1b2c6..0000000000 --- a/app/views/distributors/_form.html.erb +++ /dev/null @@ -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 %> \ No newline at end of file diff --git a/app/views/distributors/edit.html.erb b/app/views/distributors/edit.html.erb deleted file mode 100644 index 02b6a80e2c..0000000000 --- a/app/views/distributors/edit.html.erb +++ /dev/null @@ -1,2 +0,0 @@ - -<%= render :partial => 'form', :locals => { :distributor => @distributor } %> \ No newline at end of file diff --git a/app/views/distributors/index.html.erb b/app/views/distributors/index.html.erb deleted file mode 100644 index d531fe7fc5..0000000000 --- a/app/views/distributors/index.html.erb +++ /dev/null @@ -1,31 +0,0 @@ - -
- -
-
- - - - - - - - - - <% @distributors.each do |distributor| %> - - - - - <% end %> - <% if @distributors.empty? %> - - <% end %> - -
Name - Description -
<%= link_to distributor.name, distributor_path(distributor) %><%=distributor.description %>
<%= t(:none) %>
\ No newline at end of file diff --git a/app/views/distributors/new.html.erb b/app/views/distributors/new.html.erb deleted file mode 100644 index 02b6a80e2c..0000000000 --- a/app/views/distributors/new.html.erb +++ /dev/null @@ -1,2 +0,0 @@ - -<%= render :partial => 'form', :locals => { :distributor => @distributor } %> \ No newline at end of file diff --git a/app/views/spree/admin/distributors/_form.html.erb b/app/views/spree/admin/distributors/_form.html.erb new file mode 100644 index 0000000000..caf069b259 --- /dev/null +++ b/app/views/spree/admin/distributors/_form.html.erb @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name :<%= f.text_field :name %>
Description :<%= f.text_field :description %>
Contact :<%= f.text_field :contact %>
Phone :<%= f.text_field :phone %>
Email :<%= f.text_field :email %>
Address :<%= f.text_field :pickup_address %>
Pickup times :<%= f.text_field :pickup_times %>
URL :<%= f.text_field :url %>
ABN :<%= f.text_field :abn %>
ACN :<%= f.text_field :acn %>
\ No newline at end of file diff --git a/app/views/spree/admin/distributors/edit.html.erb b/app/views/spree/admin/distributors/edit.html.erb new file mode 100644 index 0000000000..a67c215206 --- /dev/null +++ b/app/views/spree/admin/distributors/edit.html.erb @@ -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 %> \ No newline at end of file diff --git a/app/views/spree/admin/distributors/index.html.erb b/app/views/spree/admin/distributors/index.html.erb index 14195a8c80..8c81569f1e 100644 --- a/app/views/spree/admin/distributors/index.html.erb +++ b/app/views/spree/admin/distributors/index.html.erb @@ -2,7 +2,7 @@

@@ -20,7 +20,7 @@ <% @distributors.each do |distributor| %> - <%=distributor.name %> + <%= link_to distributor.name, spree.admin_distributor_path(distributor) %> <%=distributor.description %> <% end %> diff --git a/app/views/spree/admin/distributors/new.html.erb b/app/views/spree/admin/distributors/new.html.erb new file mode 100644 index 0000000000..cd6b15571d --- /dev/null +++ b/app/views/spree/admin/distributors/new.html.erb @@ -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 %> diff --git a/app/views/distributors/show.html b/app/views/spree/admin/distributors/show.html similarity index 83% rename from app/views/distributors/show.html rename to app/views/spree/admin/distributors/show.html index 5019b87958..ece4795681 100644 --- a/app/views/distributors/show.html +++ b/app/views/spree/admin/distributors/show.html @@ -67,6 +67,6 @@

- <%= 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 %>

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 885e098330..2e31e3ab44 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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