Skip to content
Browse files

Improve admin menu for extension. Allow extensions to create admin tabs.

[#332 state:resolved]
  • Loading branch information...
1 parent 7df7e37 commit 955fa28ec44065416633acc87ab912532ffa2010 @cmaujean cmaujean committed Jun 20, 2009
View
11 app/controllers/admin/base_controller.rb
@@ -1,12 +1,21 @@
class Admin::BaseController < Spree::BaseController
helper :search
layout 'admin'
-
+
before_filter :initialize_product_admin_tabs
before_filter :initialize_order_admin_tabs
+ before_filter :initialize_extension_tabs
before_filter :add_shipments_tab
private
+ def add_extension_admin_tab(tab_args)
+ @extension_tabs << tab_args
+ end
+
+ def initialize_extension_tabs
+ @extension_tabs = []
+ end
+
def add_shipments_tab
@order_admin_tabs << {:name => 'Shipments', :url => "admin_order_shipments_url"}
end
View
3 app/views/layouts/admin.html.erb
@@ -37,6 +37,9 @@
<%= tab :reports %>
<%= tab :configurations, :general_settings, :mail_settings, :tax_categories, :zones, :states, :gateway_configurations, :inventory_settings, :taxonomies, :label => 'configuration' %>
<%= tab :users %>
+ <% @extension_tabs.each do |etab| -%>
+ <%= tab etab[0], etab[1] %>
+ <% end -%>
</ul>
<br class="clear" />
</div>
View
17 lib/generators/extension/templates/extension.rb
@@ -13,6 +13,23 @@ class <%= class_name %> < Spree::Extension
# end
def activate
+
+ # Add your extension tab to the admin.
+ # Requires that you have defined an admin controller:
+ # app/controllers/admin/yourextension_controller
+ # and that you mapped your admin in config/routes
+
+ #Admin::BaseController.class_eval do
+ # before_filter :add_yourextension_tab
+ #
+ # def add_yourextension_tab
+ # # add_extension_admin_tab takes an array containing the same arguments expected
+ # # by the tab helper method:
+ # # [ :extension_name, { :label => "Your Extension", :route => "/some/non/standard/route" } ]
+ # add_extension_admin_tab [ :yourextension ]
+ # end
+ #end
+
# make your helper avaliable in all views
# Spree::BaseController.class_eval do
# helper YourHelper

0 comments on commit 955fa28

Please sign in to comment.
Something went wrong with that request. Please try again.