2014-04-07 09:26:43 +00:00
|
|
|
module OrbitApp
|
|
|
|
module Module
|
|
|
|
module SideBarRegistration
|
|
|
|
Version = "0.5"
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
#initiate a blank array for generating the side bar
|
|
|
|
cattr_accessor :side_bars
|
|
|
|
self.side_bars = []
|
|
|
|
|
|
|
|
def add(var)
|
|
|
|
self.side_bars << var
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_key(key)
|
|
|
|
self.side_bars.each{|t|
|
|
|
|
return t if t.name.eql?(key)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_all(request,params,user,current_module_app)
|
|
|
|
self.side_bars.collect{|t| t.render(request,params,user,current_module_app)}.join.html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
|
|
|
return self.side_bars
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_get_ordered!
|
|
|
|
self.side_bars.sort! {|x,y| x.get_sidebar_order! <=> y.get_sidebar_order! }
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
extend ClassMethods
|
|
|
|
def self.included(other)
|
|
|
|
other.extend(ClassMethods)
|
|
|
|
end
|
|
|
|
|
|
|
|
class SideBar
|
|
|
|
include SideBarRenderer
|
|
|
|
|
2014-05-01 07:14:16 +00:00
|
|
|
def initialize(name = '', key, get_module_app, &block)
|
2014-04-07 09:26:43 +00:00
|
|
|
@head_label = name
|
2014-04-11 10:44:45 +00:00
|
|
|
@context_links = []
|
2014-04-07 09:26:43 +00:00
|
|
|
@head_link = ""
|
|
|
|
@app_base_path = ''
|
2014-04-09 10:30:13 +00:00
|
|
|
@active_for_controllers = []
|
2014-05-01 07:14:16 +00:00
|
|
|
@available_for = []
|
|
|
|
@active_for_app_auth = []
|
2014-04-07 09:26:43 +00:00
|
|
|
@module_app_key = key
|
|
|
|
@get_module_app = get_module_app
|
|
|
|
@sidebar_order = 0
|
|
|
|
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
|
|
|
SideBarRegistration.add(self)
|
|
|
|
SideBarRegistration.all_get_ordered!
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_sidebar_order!
|
|
|
|
@sidebar_order = (get_module_app.sidebar_order rescue 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_icon_class
|
|
|
|
@icon_class
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_module_app
|
|
|
|
@get_module_app.call
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_module_app_key
|
|
|
|
@module_app_key
|
|
|
|
end
|
|
|
|
|
2014-05-02 10:19:57 +00:00
|
|
|
def get_active_for_controllers
|
|
|
|
@active_for_controllers
|
|
|
|
end
|
|
|
|
|
2014-04-07 09:26:43 +00:00
|
|
|
def head_label_i18n(var,options ={})
|
|
|
|
@head_label = var
|
|
|
|
@icon_class = options[:icon_class]
|
|
|
|
end
|
|
|
|
|
|
|
|
def head_link_path(var)
|
|
|
|
@head_link = var
|
|
|
|
end
|
2014-04-09 10:30:13 +00:00
|
|
|
|
2014-05-01 07:14:16 +00:00
|
|
|
def available_for(var)
|
2014-07-30 13:40:02 +00:00
|
|
|
@available_for = set_avaibility(var || "admin")
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_availability
|
|
|
|
@available_for
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_avaibility(af)
|
|
|
|
temp = []
|
|
|
|
case af
|
|
|
|
when 'users'
|
|
|
|
temp << 'users'
|
|
|
|
temp << 'sub_managers'
|
|
|
|
temp << 'managers'
|
|
|
|
temp << 'admin'
|
|
|
|
when 'sub_managers'
|
|
|
|
temp << 'sub_managers'
|
|
|
|
temp << 'managers'
|
|
|
|
temp << 'admin'
|
|
|
|
when 'managers'
|
|
|
|
temp << 'managers'
|
|
|
|
temp << 'admin'
|
|
|
|
when 'admin'
|
|
|
|
temp << 'admin'
|
|
|
|
end
|
|
|
|
temp
|
2014-05-01 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2014-04-09 10:30:13 +00:00
|
|
|
def active_for_controllers(var)
|
2014-04-11 10:44:45 +00:00
|
|
|
@active_for_controllers = var
|
|
|
|
end
|
|
|
|
|
2014-05-02 10:19:57 +00:00
|
|
|
def get_context_links
|
|
|
|
@context_links
|
|
|
|
end
|
|
|
|
|
2014-04-11 10:44:45 +00:00
|
|
|
def context_link(*var)
|
|
|
|
var[1].merge!({:module_app_key=>@module_app_key,:get_module_app=>@get_module_app}) unless @module_app_key.nil?
|
|
|
|
new_context_link = ContextLink.new(*var)
|
|
|
|
@context_links << new_context_link
|
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
|
|
|
set_controllers_scope
|
|
|
|
# set_default_active_app_auth
|
|
|
|
current_priority = @context_links.count
|
2014-05-01 07:14:16 +00:00
|
|
|
if @authorizable_with_link
|
|
|
|
context_link 'module_authorization',
|
|
|
|
:link_path => "admin_authorizations_path(get_module_app.key)",
|
|
|
|
:priority => current_priority + 2,
|
2014-07-30 13:40:02 +00:00
|
|
|
:available_for => "managers"
|
2014-05-01 07:14:16 +00:00
|
|
|
end
|
2014-04-11 10:44:45 +00:00
|
|
|
@context_links.each do |t|
|
|
|
|
# t.set_module_app = @module_app
|
|
|
|
t.finalize!
|
|
|
|
end
|
2014-04-09 10:30:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def set_controllers_scope
|
|
|
|
var = @active_for_controllers
|
|
|
|
@active_for_controllers = []
|
|
|
|
var[:private].each do |controller|
|
2014-04-11 10:44:45 +00:00
|
|
|
@active_for_controllers << "#{locale}/admin/"+controller
|
2014-04-09 10:30:13 +00:00
|
|
|
end unless var[:private].nil?
|
|
|
|
var[:public].each do |controller|
|
|
|
|
@active_for_controllers << controller
|
|
|
|
end unless var[:public].nil?
|
|
|
|
end
|
2014-04-07 09:26:43 +00:00
|
|
|
end
|
2014-04-11 10:44:45 +00:00
|
|
|
|
|
|
|
class ContextLink
|
|
|
|
include ContextLinkRenderer
|
|
|
|
attr_reader :label_i18n,:available_for,:priority,:path,:active_for_action
|
|
|
|
|
|
|
|
def initialize(label_i18n="NoNameLink",options={})
|
|
|
|
@label_i18n = label_i18n
|
|
|
|
@priority = options[:priority] || 0
|
|
|
|
@path = options[:link_path] || ""
|
2014-05-12 08:18:35 +00:00
|
|
|
@arg = options[:link_arg] || ""
|
2014-07-30 13:40:02 +00:00
|
|
|
@available_for = set_avaibility(options[:available_for] || "admin")
|
2014-04-11 10:44:45 +00:00
|
|
|
@active_for_action = options[:active_for_action] || []
|
2014-05-01 07:14:16 +00:00
|
|
|
@active_for_app_auth = options[:active_for_app_auth] || []
|
2014-04-11 10:44:45 +00:00
|
|
|
@module_app_key = options[:module_app_key]
|
|
|
|
@get_module_app = options[:get_module_app]
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_module_app
|
|
|
|
@get_module_app.call
|
|
|
|
end
|
|
|
|
|
2014-07-30 13:40:02 +00:00
|
|
|
def available_for
|
|
|
|
@available_for
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_avaibility(af)
|
|
|
|
temp = []
|
|
|
|
case af
|
|
|
|
when 'users'
|
|
|
|
temp << 'users'
|
|
|
|
temp << 'sub_managers'
|
|
|
|
temp << 'managers'
|
|
|
|
temp << 'admin'
|
|
|
|
when 'sub_managers'
|
|
|
|
temp << 'sub_managers'
|
|
|
|
temp << 'managers'
|
|
|
|
temp << 'admin'
|
|
|
|
when 'managers'
|
|
|
|
temp << 'managers'
|
|
|
|
temp << 'admin'
|
|
|
|
when 'admin'
|
|
|
|
temp << 'admin'
|
|
|
|
end
|
|
|
|
temp
|
|
|
|
end
|
|
|
|
|
2014-04-11 10:44:45 +00:00
|
|
|
def active?
|
|
|
|
for_action = @active_for_action.blank? ? false : active_for_action?
|
2014-05-01 07:14:16 +00:00
|
|
|
for_app_auth = @active_for_app_auth.blank? ? false : active_for_app_auth?
|
|
|
|
for_action || for_app_auth
|
2014-04-11 10:44:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def active_for_action?
|
|
|
|
@active_for_action[controller] == action
|
|
|
|
end
|
|
|
|
|
2014-05-02 10:19:57 +00:00
|
|
|
def get_active_action
|
|
|
|
@active_for_action
|
|
|
|
end
|
|
|
|
|
2014-04-11 10:44:45 +00:00
|
|
|
def finalize!
|
|
|
|
set_active_actions
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def set_active_actions
|
|
|
|
controller_action_hash = @active_for_action
|
|
|
|
@active_for_action = Hash[controller_action_hash.map{|controller,action| ["#{locale}/admin/"+controller.to_s,action.to_s]}]
|
|
|
|
end
|
|
|
|
end
|
2014-04-07 09:26:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|