Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created March 22, 2010 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelinuxlich/340371 to your computer and use it in GitHub Desktop.
Save thelinuxlich/340371 to your computer and use it in GitHub Desktop.
# no ApplicationHelper...
def toolbar(module_name,id,options={})
acesso_geral = current_usuario.send("may_gerenciar_#{module_name}?")
acesso_edit = current_usuario.special_permissions.updatable(module_name).exists?
acesso_read = current_usuario.special_permissions.readable(module_name).exists?
acesso_delete = current_usuario.special_permissions.deletable(module_name).exists?
concat("<span class='toolbar'>")
if(acesso_geral || acesso_edit) && (options[:actions].include?(:edit))
concat(link_toolbar(module_name,id,"edit","Editar"))
end
if(acesso_geral || acesso_read) && (options[:actions].include?(:index))
concat(link_toolbar(module_name,nil,"index","Voltar"))
end
if(acesso_geral || acesso_read) && (options[:actions].include?(:new))
concat(link_toolbar(module_name,nil,"new","Novo"))
end
concat("</span>")
end
private
def link_toolbar(module_name,id,_action,link_name)
classes_link = "ui-state-default dw-clickable ui-corner-br ui-corner-bl"
classes_icon = "dw-icon ui-icon "
case _action
when "edit"
classes_icon << "ui-icon-pencil"
when "index"
classes_icon << "ui-icon-home"
when "new"
classes_icon << "ui-icon-circle-plus"
end
hash_link = {:controller => module_name, :action => _action}
hash_link[:id] = id if id
content_tag(:a, :href => url_for(hash_link),:class => classes_link) do
"<span class='#{classes_icon}'></span>#{link_name}"
end
end
#na view
%div.heading.ui-widget-header.ui-corner-tr.ui-corner-tl.dw-header
= "Carros"
= toolbar "carros", nil,:actions => [:new]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment