Skip to content

Commit

Permalink
Improve admin menu for extension. Allow extensions to create admin tabs.
Browse files Browse the repository at this point in the history
[#332 state:resolved]
  • Loading branch information
cmaujean committed Jun 20, 2009
1 parent 7df7e37 commit 955fa28
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
17 changes: 17 additions & 0 deletions lib/generators/extension/templates/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 955fa28

Please sign in to comment.