2010-07-13 00:46:17 +00:00
|
|
|
require 'locomotive/admin_responder'
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
module Admin
|
2010-07-13 00:46:17 +00:00
|
|
|
# class BaseController < ::ApplicationController
|
|
|
|
class BaseController < InheritedResources::Base
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
include Locomotive::Routing::SiteDispatcher
|
2010-04-24 00:32:36 +00:00
|
|
|
|
2010-06-03 15:32:40 +00:00
|
|
|
layout 'admin/application'
|
2010-06-12 01:13:58 +00:00
|
|
|
|
2010-06-10 22:07:59 +00:00
|
|
|
before_filter :authenticate_admin!
|
2010-05-10 22:39:52 +00:00
|
|
|
|
|
|
|
before_filter :require_site
|
|
|
|
|
|
|
|
before_filter :validate_site_membership
|
2010-04-24 00:32:36 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
before_filter :set_locale
|
2010-04-24 00:32:36 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
helper_method :sections
|
2010-07-13 00:46:17 +00:00
|
|
|
|
2010-06-12 01:13:58 +00:00
|
|
|
# https://rails.lighthouseapp.com/projects/8994/tickets/1905-apphelpers-within-plugin-not-being-mixed-in
|
|
|
|
Dir[File.dirname(__FILE__) + "/../../helpers/**/*_helper.rb"].each do |file|
|
|
|
|
helper "admin/#{File.basename(file, '.rb').gsub(/_helper$/, '')}"
|
|
|
|
end
|
2010-07-13 00:46:17 +00:00
|
|
|
|
|
|
|
self.responder = Locomotive::AdminResponder # custom responder
|
|
|
|
|
|
|
|
defaults :route_prefix => 'admin'
|
|
|
|
|
|
|
|
respond_to :html
|
2010-06-12 01:13:58 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
protected
|
2010-07-13 00:46:17 +00:00
|
|
|
|
|
|
|
def begin_of_association_chain
|
|
|
|
current_site
|
|
|
|
end
|
2010-04-25 00:33:38 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def self.sections(main, sub = nil)
|
|
|
|
before_filter do |c|
|
|
|
|
sub = sub.call(c) if sub.respond_to?(:call)
|
|
|
|
sections = { :main => main, :sub => sub }
|
|
|
|
c.instance_variable_set(:@admin_sections, sections)
|
|
|
|
end
|
|
|
|
end
|
2010-04-24 00:32:36 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def sections(key = nil)
|
|
|
|
if !key.nil? && key.to_sym == :sub
|
|
|
|
@admin_sections[:sub] || self.controller_name.dasherize
|
|
|
|
else
|
|
|
|
@admin_sections[:main]
|
|
|
|
end
|
2010-04-24 00:32:36 +00:00
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def set_locale
|
2010-06-10 22:07:59 +00:00
|
|
|
I18n.locale = current_admin.locale
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-13 00:46:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-04-24 00:32:36 +00:00
|
|
|
end
|