2012-11-20 07:56:52 +00:00
|
|
|
module SideBarRenderer
|
|
|
|
include Renderer
|
|
|
|
include AdminHelper
|
2013-05-02 03:35:48 +00:00
|
|
|
include ActionView::Helpers::TextHelper
|
2012-11-20 07:56:52 +00:00
|
|
|
|
2012-12-05 10:35:58 +00:00
|
|
|
def render(request,params,user,current_module_app)
|
2013-05-02 03:35:48 +00:00
|
|
|
@belong_module_app = get_module_app
|
|
|
|
@current_module_app = current_module_app
|
|
|
|
@request = request
|
|
|
|
@params = params
|
|
|
|
@current_user = user
|
|
|
|
if display?
|
|
|
|
content_tag :div, class: "sub-nav-block" do
|
|
|
|
concat content_tag :h4, I18n.t(@head_label)
|
|
|
|
concat (content_tag :ul, class: "nav nav-list" do
|
|
|
|
@context_links.sort_by {| obj | obj.priority}.map{ |link|
|
|
|
|
link.render(request, params, @current_module_app, @current_user, @belong_module_app)
|
|
|
|
}.join.html_safe
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_head(request, params, user, current_module_app)
|
2012-12-05 10:35:58 +00:00
|
|
|
@belong_module_app = get_module_app
|
|
|
|
@current_module_app = current_module_app
|
2012-11-20 07:56:52 +00:00
|
|
|
@request = request
|
|
|
|
@params = params
|
|
|
|
@current_user = user
|
|
|
|
if display?
|
2013-05-02 03:35:48 +00:00
|
|
|
content_tag :li, class: (module_sidebar_active? ? 'active' : nil) do
|
|
|
|
link_to eval(@head_link) do
|
|
|
|
content_tag :span do
|
|
|
|
content_tag(:i, nil, class: @icon_class)
|
|
|
|
end
|
|
|
|
end
|
2012-11-20 07:56:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def display? #控制sidebar 要不要算圖
|
|
|
|
if is_manager? || is_admin? #如果是系統管理員 或 是模組管理員
|
|
|
|
true
|
2012-12-07 04:40:47 +00:00
|
|
|
elsif (@current_module_app.open rescue true) # 如果app 被設定成 開放
|
2012-11-20 07:56:52 +00:00
|
|
|
true
|
|
|
|
elsif is_member? #如果app 是封閉 那至少需要是 member
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def module_sidebar_active?
|
2013-05-02 03:35:48 +00:00
|
|
|
active_for_controller? or active_for_app_auth? or active_for_ob_auths? or active_for_tag?
|
2012-11-20 07:56:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def active_for_controller?
|
|
|
|
@active_for_controllers.include? controller
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|