2010-05-10 22:39:52 +00:00
|
|
|
module Admin
|
2010-07-13 00:46:17 +00:00
|
|
|
class BaseController < InheritedResources::Base
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
include Locomotive::Routing::SiteDispatcher
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-09-21 11:16:39 +00:00
|
|
|
layout '/admin/layouts/application'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-05-28 17:52:36 +00:00
|
|
|
before_filter :require_admin
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
before_filter :require_site
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
before_filter :validate_site_membership
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
before_filter :set_locale
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-04-24 23:21:38 +00:00
|
|
|
helper_method :sections, :current_site_url, :site_url, :page_url
|
2010-07-23 20:09:54 +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-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
self.responder = Locomotive::AdminResponder # custom responder
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 23:37:02 +00:00
|
|
|
defaults :route_prefix => 'admin'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
respond_to :html
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
protected
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-05-28 17:52:36 +00:00
|
|
|
def require_admin
|
|
|
|
authenticate_admin!
|
|
|
|
end
|
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
def begin_of_association_chain
|
|
|
|
current_site
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
|
|
|
|
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-07-23 20:09:54 +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
|
2010-07-23 20:09:54 +00:00
|
|
|
else
|
2010-05-10 22:39:52 +00:00
|
|
|
@admin_sections[:main]
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
2010-04-24 00:32:36 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def set_locale
|
2010-10-27 00:11:44 +00:00
|
|
|
I18n.locale = current_admin.locale rescue Locomotive.config.default_locale
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-04-24 23:21:38 +00:00
|
|
|
# ___ site/page urls builder ___
|
|
|
|
|
|
|
|
def current_site_url
|
|
|
|
request.protocol + request.host_with_port
|
|
|
|
end
|
|
|
|
|
|
|
|
def site_url(site, options = {})
|
|
|
|
options = { :fullpath => true, :protocol => true }.merge(options)
|
|
|
|
|
|
|
|
url = "#{site.subdomain}.#{Locomotive.config.domain}"
|
|
|
|
url += ":#{request.port}" if request.port != 80
|
|
|
|
|
|
|
|
url = File.join(url, request.fullpath) if options[:fullpath]
|
|
|
|
url = "http://#{url}" if options[:protocol]
|
|
|
|
url
|
|
|
|
end
|
|
|
|
|
|
|
|
def page_url(page, options = {})
|
|
|
|
if content = options.delete(:content)
|
|
|
|
File.join(current_site_url, page.fullpath.gsub('content_type_template', ''), content._slug)
|
|
|
|
else
|
|
|
|
File.join(current_site_url, page.fullpath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|