Sha256: a017a3768ad183025f3188aa7372a69cd9b42d155c91a47d7e2a06c01bc648fb
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
module Admin module SidebarHelper def build_sidebar resources = ActiveSupport::OrderedHash.new app_name = @resource.typus_application Typus.application(app_name).sort {|a,b| a.constantize.model_name.human <=> b.constantize.model_name.human}.each do |resource| next unless @current_user.resources.include?(resource) klass = resource.constantize resources[resource] = default_actions(klass) + export(klass) + custom_actions(klass) resources[resource].compact! end render "admin/helpers/sidebar/sidebar", :resources => resources end def default_actions(klass) actions = [] if @current_user.can?("create", klass) options = { :controller => klass.to_resource } message = _t("Add new") actions << (link_to_unless_current message, options.merge(:action => "new")) end message = _t("List") options = { :controller => klass.to_resource } actions << (link_to_unless_current message, options) return actions end def custom_actions(klass) options = { :controller => klass.to_resource } klass.typus_actions_on("index").map do |action| if @current_user.can?(action, klass) (link_to_unless_current _t(action.humanize), options.merge(:action => action)) end end end def export(klass) return [] unless params[:action] == "index" klass.typus_export_formats.map do |format| link_to _t("Export as %{format}", :format => format.upcase), params.merge(:format => format) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
typus-1.0.0.pre7 | app/helpers/admin/sidebar_helper.rb |
typus-1.0.0.pre6 | app/helpers/admin/sidebar_helper.rb |