33 lines
960 B
Ruby
33 lines
960 B
Ruby
|
module ContextLinkRenderer
|
||
|
include Renderer
|
||
|
|
||
|
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 = current_user
|
||
|
if display?
|
||
|
content_tag :li, link_to(content_tag(:span, I18n.t(@label_i18n)), eval(@path)), :class => (active? ? 'active' : nil)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
protected
|
||
|
def display?
|
||
|
@available_for.each do |available_for_in_sym|
|
||
|
result = case available_for_in_sym
|
||
|
when :all
|
||
|
true
|
||
|
when :manager
|
||
|
@belong_module_app.is_manager? @current_user
|
||
|
when :sub_manager
|
||
|
@belong_module_app.is_sub_manager? @current_user
|
||
|
else
|
||
|
(eval(available_for_in_sym).include? @current_user rescue false)
|
||
|
end # of case
|
||
|
return true if result || (@current_user.admin? rescue false)
|
||
|
end # of collect
|
||
|
false
|
||
|
end
|
||
|
|
||
|
end
|