2012-11-20 07:56:52 +00:00
|
|
|
module ContextLinkRenderer
|
|
|
|
include Renderer
|
|
|
|
|
2012-12-03 10:52:36 +00:00
|
|
|
def render(request,params,module_app,user)
|
|
|
|
@module_app = module_app
|
2012-11-20 07:56:52 +00:00
|
|
|
@request = request
|
|
|
|
@params = params
|
2012-12-03 10:52:36 +00:00
|
|
|
@current_user = user
|
2012-11-20 07:56:52 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2012-12-03 10:52:36 +00:00
|
|
|
protected
|
|
|
|
def display?
|
|
|
|
@available_for.each do |available_for_in_sym|
|
|
|
|
result = case available_for_in_sym
|
|
|
|
when :all
|
|
|
|
true
|
|
|
|
when :manager
|
|
|
|
@module_app.is_manager? @current_user
|
|
|
|
when :sub_manager
|
|
|
|
@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?
|
|
|
|
end # of collect
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2012-11-20 07:56:52 +00:00
|
|
|
end
|