2012-11-20 07:56:52 +00:00
|
|
|
module ContextLinkRenderer
|
|
|
|
include Renderer
|
|
|
|
|
2012-12-05 10:35:58 +00:00
|
|
|
def render(request,params,current_module_app,current_user,belong_module_app)
|
|
|
|
@current_module_app = current_module_app
|
|
|
|
@belong_module_app = belong_module_app
|
2012-11-20 07:56:52 +00:00
|
|
|
@request = request
|
|
|
|
@params = params
|
2012-12-05 10:35:58 +00:00
|
|
|
@current_user = current_user
|
2012-11-20 07:56:52 +00:00
|
|
|
if display?
|
2013-07-02 08:46:44 +00:00
|
|
|
content_tag :li, link_to(content_tag(:span, I18n.t(@label_i18n)), eval(@path)), :class => (active? ? 'active' : nil)
|
2012-11-20 07:56:52 +00:00
|
|
|
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
|
2012-12-05 10:35:58 +00:00
|
|
|
@belong_module_app.is_manager? @current_user
|
2012-12-03 10:52:36 +00:00
|
|
|
when :sub_manager
|
2012-12-05 10:35:58 +00:00
|
|
|
@belong_module_app.is_sub_manager? @current_user
|
2012-12-03 10:52:36 +00:00
|
|
|
else
|
|
|
|
(eval(available_for_in_sym).include? @current_user rescue false)
|
|
|
|
end # of case
|
2012-12-07 04:40:47 +00:00
|
|
|
return true if result || (@current_user.admin? rescue false)
|
2012-12-03 10:52:36 +00:00
|
|
|
end # of collect
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2012-11-20 07:56:52 +00:00
|
|
|
end
|