sidebar rewrited
This commit is contained in:
1 parent
5f712622ad
commit
53afb6ea0c
14 files changed
+395
-16
No files matched your search
@@ -1,11 +1,12 @@
|
||||
module ContextLinkRenderer
|
||||
include Renderer
|
||||
|
||||
def render(request,params,module_app,user)
|
||||
@module_app = module_app
|
||||
def render(request,params,current_module_app,current_user,belong_module_app)
|
||||
@current_module_app = current_module_app
|
||||
@belong_module_app = belong_module_app
|
||||
@request = request
|
||||
@params = params
|
||||
@current_user = user
|
||||
@current_user = current_user
|
||||
if display?
|
||||
content_tag :li, link_to((I18n.t(@label_i18n) + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, eval(@path)), :class => (active? ? 'active' : nil)
|
||||
end
|
||||
@@ -18,9 +19,9 @@ protected
|
||||
when :all
|
||||
true
|
||||
when :manager
|
||||
@module_app.is_manager? @current_user
|
||||
@belong_module_app.is_manager? @current_user
|
||||
when :sub_manager
|
||||
@module_app.is_sub_manager? @current_user
|
||||
@belong_module_app.is_sub_manager? @current_user
|
||||
else
|
||||
(eval(available_for_in_sym).include? @current_user rescue false)
|
||||
end # of case
|
||||
|
||||
@@ -2,8 +2,9 @@ module SideBarRenderer
|
||||
include Renderer
|
||||
include AdminHelper
|
||||
|
||||
def render(request,params,user,module_app)
|
||||
@module_app = module_app
|
||||
def render(request,params,user,current_module_app)
|
||||
@belong_module_app = get_module_app
|
||||
@current_module_app = current_module_app
|
||||
@request = request
|
||||
@params = params
|
||||
@current_user = user
|
||||
@@ -12,7 +13,7 @@ module SideBarRenderer
|
||||
buf = link_to( content_tag(:i, nil, :class => @icon_class ) + content_tag(:span, I18n.t( @head_label )), eval(@head_link))
|
||||
buf << content_tag( :ul, :class => ("nav nav-list active") )do # visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')||active_for_ob_auths_object("BulletinCategory"))
|
||||
@context_links.sort_by! {| obj | obj.priority}.collect do |link|
|
||||
link.render(request,params,@module_app,@current_user)
|
||||
link.render(request,params,@current_module_app,@current_user,@belong_module_app)
|
||||
end.join.html_safe
|
||||
end
|
||||
end
|
||||
@@ -24,7 +25,7 @@ module SideBarRenderer
|
||||
def display? #控制sidebar 要不要算圖
|
||||
if is_manager? || is_admin? #如果是系統管理員 或 是模組管理員
|
||||
true
|
||||
elsif (@module_app.open rescue false) # 如果app 被設定成 開放
|
||||
elsif (@current_module_app.open rescue false) # 如果app 被設定成 開放
|
||||
true
|
||||
elsif is_member? #如果app 是封閉 那至少需要是 member
|
||||
true
|
||||
|
||||
@@ -39,8 +39,12 @@ module OrbitApp
|
||||
setup_module_app
|
||||
end
|
||||
|
||||
def get_module_app
|
||||
ModuleApp.first(conditions: {:key=>@key,:title=>name})
|
||||
end
|
||||
|
||||
def setup_module_app
|
||||
module_app = ModuleApp.first(conditions: {:key=>@key,:title=>name})
|
||||
module_app = get_module_app
|
||||
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
|
||||
|
||||
begin
|
||||
@@ -90,7 +94,7 @@ module OrbitApp
|
||||
end
|
||||
|
||||
def side_bar(&block)
|
||||
@side_bar = SideBarRegisition::SideBar.new(@name,@key,&block)
|
||||
@side_bar = SideBarRegisition::SideBar.new(@name,@key,method(:get_module_app),&block)
|
||||
end
|
||||
|
||||
def personal_plugin(params)
|
||||
|
||||
@@ -17,6 +17,10 @@ module OrbitApp
|
||||
return nil
|
||||
end
|
||||
|
||||
def render_all(request,params,user,current_module_app)
|
||||
@@side_bars.collect{|t| t.render(request,params,user,current_module_app)}.join.html_safe
|
||||
end
|
||||
|
||||
def all
|
||||
return @@side_bars
|
||||
end
|
||||
@@ -37,7 +41,7 @@ module OrbitApp
|
||||
# def is_manager?
|
||||
# binding.pry
|
||||
# end
|
||||
def initialize(name = '',key,&block)
|
||||
def initialize(name = '',key,get_module_app,&block)
|
||||
@head_label = name
|
||||
@context_links = []
|
||||
@available_for = []
|
||||
@@ -47,12 +51,16 @@ module OrbitApp
|
||||
@head_link = ""
|
||||
@app_base_path = ''
|
||||
@module_app_key = key
|
||||
@get_module_app = get_module_app
|
||||
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
|
||||
# setup_module_app(module_app_key)
|
||||
finalize!
|
||||
SideBarRegisition.add(self)
|
||||
end
|
||||
|
||||
def get_module_app
|
||||
@get_module_app.call
|
||||
end
|
||||
|
||||
def head_label_i18n(var,options ={})
|
||||
@head_label = var
|
||||
@@ -76,7 +84,7 @@ module OrbitApp
|
||||
end
|
||||
|
||||
def context_link(*var)
|
||||
var[1].merge!(:module_app_key=>@module_app_key) unless @module_app_key.nil?
|
||||
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
|
||||
@@ -126,6 +134,11 @@ module OrbitApp
|
||||
@active_for_object_auth = options[:active_for_object_auth] || []
|
||||
@active_for_app_auth = options[:active_for_app_auth] || []
|
||||
@module_app_key = options[:module_app_key]
|
||||
@get_module_app = options[:get_module_app]
|
||||
end
|
||||
|
||||
def get_module_app
|
||||
@get_module_app.call
|
||||
end
|
||||
|
||||
def active?
|
||||
|
||||
Reference in new issue
Block a user