diff --git a/app/controllers/admin/distributors_controller.rb b/app/controllers/admin/distributors_controller.rb new file mode 100644 index 0000000000..21d561a1ea --- /dev/null +++ b/app/controllers/admin/distributors_controller.rb @@ -0,0 +1,28 @@ +module Admin + class DistributorsController < ResourceController + before_filter :load_distributor_set, :only => :index + before_filter :load_countries, :except => :index + + def bulk_update + @distributor_set = DistributorSet.new(params[:distributor_set]) + if @distributor_set.save + redirect_to main_app.admin_distributors_path, :notice => 'Distributor collection times updated.' + else + render :index + end + end + + private + def load_distributor_set + @distributor_set = DistributorSet.new :distributors => collection + end + + def load_countries + @countries = Spree::Country.order(:name) + end + + def collection + super.order(:name) + end + end +end diff --git a/app/controllers/admin/resource_controller.rb b/app/controllers/admin/resource_controller.rb new file mode 100644 index 0000000000..227c1bea08 --- /dev/null +++ b/app/controllers/admin/resource_controller.rb @@ -0,0 +1,42 @@ +module Admin + class ResourceController < Spree::Admin::ResourceController + def model_class + "#{controller_name.classify}".constantize + end + + + # URL helpers + def new_object_url(options = {}) + if parent_data.present? + main_app.new_polymorphic_url([:admin, parent, model_class], options) + else + main_app.new_polymorphic_url([:admin, model_class], options) + end + end + + def edit_object_url(object, options = {}) + if parent_data.present? + main_app.send "edit_admin_#{model_name}_#{object_name}_url", parent, object, options + else + main_app.send "edit_admin_#{object_name}_url", object, options + end + end + + def object_url(object = nil, options = {}) + target = object ? object : @object + if parent_data.present? + main_app.send "admin_#{model_name}_#{object_name}_url", parent, target, options + else + main_app.send "admin_#{object_name}_url", target, options + end + end + + def collection_url(options = {}) + if parent_data.present? + main_app.polymorphic_url([:admin, parent, model_class], options) + else + main_app.polymorphic_url([:admin, model_class], options) + end + end + end +end diff --git a/app/controllers/admin/suppliers_controller.rb b/app/controllers/admin/suppliers_controller.rb new file mode 100644 index 0000000000..63eb594bf3 --- /dev/null +++ b/app/controllers/admin/suppliers_controller.rb @@ -0,0 +1,16 @@ +module Admin + class SuppliersController < ResourceController + before_filter :load_data, :except => [:index] + + helper 'spree/products' + + private + def load_data + @countries = Spree::Country.order(:name) + end + + def collection + super.order(:name) + end + end +end diff --git a/app/controllers/spree/admin/distributors_controller.rb b/app/controllers/spree/admin/distributors_controller.rb deleted file mode 100644 index 5a99ae99f8..0000000000 --- a/app/controllers/spree/admin/distributors_controller.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Spree - module Admin - class DistributorsController < ResourceController - before_filter :load_distributor_set, :only => :index - before_filter :load_countries, :except => :index - - def bulk_update - @distributor_set = DistributorSet.new(params[:distributor_set]) - if @distributor_set.save - redirect_to admin_distributors_path, :notice => 'Distributor collection times updated.' - else - render :index - end - end - - private - def load_distributor_set - @distributor_set = DistributorSet.new :distributors => collection - end - - def load_countries - @countries = Country.order(:name) - end - - def collection - super.order(:name) - end - end - end -end diff --git a/app/controllers/spree/admin/suppliers_controller.rb b/app/controllers/spree/admin/suppliers_controller.rb deleted file mode 100644 index ae02ca9384..0000000000 --- a/app/controllers/spree/admin/suppliers_controller.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Spree - module Admin - class SuppliersController < ResourceController - before_filter :load_data, :except => [:index] - - private - def load_data - @countries = Country.order(:name) - end - - def collection - super.order(:name) - end - end - end -end diff --git a/app/overrides/distributors_admin_tab.rb b/app/overrides/distributors_admin_tab.rb index ff19b8b1e9..b0b71bfcea 100644 --- a/app/overrides/distributors_admin_tab.rb +++ b/app/overrides/distributors_admin_tab.rb @@ -1,11 +1,11 @@ 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) %>", + :text => "<%= tab(:distributors, :url => main_app.admin_distributors_path) %>", :disabled => false) Deface::Override.new(:virtual_path => "spree/layouts/admin", :name => "suppliers_admin_tabs", :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]", - :text => "<%= tab(:suppliers, :url => spree.admin_suppliers_path) %>", - :disabled => false) \ No newline at end of file + :text => "<%= tab(:suppliers, :url => main_app.admin_suppliers_path) %>", + :disabled => false) diff --git a/app/views/spree/admin/distributors/_form.html.haml b/app/views/admin/distributors/_form.html.haml similarity index 100% rename from app/views/spree/admin/distributors/_form.html.haml rename to app/views/admin/distributors/_form.html.haml diff --git a/app/views/spree/admin/distributors/edit.html.erb b/app/views/admin/distributors/edit.html.erb similarity index 100% rename from app/views/spree/admin/distributors/edit.html.erb rename to app/views/admin/distributors/edit.html.erb diff --git a/app/views/spree/admin/distributors/index.html.erb b/app/views/admin/distributors/index.html.erb similarity index 65% rename from app/views/spree/admin/distributors/index.html.erb rename to app/views/admin/distributors/index.html.erb index 0042604d1f..6259efa15c 100644 --- a/app/views/spree/admin/distributors/index.html.erb +++ b/app/views/admin/distributors/index.html.erb @@ -1,13 +1,13 @@
-<%= form_for @distributor_set, :url => bulk_update_admin_distributors_path do |f| %> +<%= form_for @distributor_set, :url => main_app.bulk_update_admin_distributors_path do |f| %>| <%= link_to distributor.name, spree.admin_distributor_path(distributor) %> | +<%= link_to distributor.name, main_app.admin_distributor_path(distributor) %> | <%= distributor_form.text_field :next_collection_at %> | <%= distributor.description %> | - <%= link_to_edit distributor, :class => 'edit' %> - <%= link_to_delete distributor %> + <%= link_to_edit [main_app, distributor], :class => 'edit' %> + <%= link_to_delete [main_app, distributor] %> |