engine/app/controllers/admin/base_controller.rb

55 lines
1.4 KiB
Ruby
Raw Normal View History

module Admin
class BaseController < ::ApplicationController
2010-04-24 00:32:36 +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-04-24 00:32:36 +00:00
before_filter :authenticate_account!
before_filter :require_site
before_filter :validate_site_membership
2010-04-24 00:32:36 +00:00
before_filter :set_locale
2010-04-24 00:32:36 +00:00
helper_method :sections
2010-04-24 00:32:36 +00:00
protected
2010-04-24 00:32:36 +00:00
def flash_success!(options = {})
msg = translate_flash_msg(:successful)
(options.has_key?(:now) && options[:now] ? flash.now : flash)[:success] = msg
end
2010-04-25 00:33:38 +00:00
def flash_error!(options = { :now => true })
msg = translate_flash_msg(:failed)
(options.has_key?(:now) && options[:now] ? flash.now : flash)[:error] = msg
end
2010-04-25 00:33:38 +00:00
def translate_flash_msg(kind)
t("#{kind.to_s}_#{action_name}", :scope => [:admin, controller_name.underscore.gsub('/', '.'), :messages])
end
2010-04-25 00:33:38 +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
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
def set_locale
I18n.locale = current_account.locale
end
end
2010-04-24 00:32:36 +00:00
end