1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
require 'rails_admin/config/proxyable'
require 'rails_admin/config/configurable'
require 'rails_admin/config/hideable'
module RailsAdmin
module Config
module Actions
class Base
include RailsAdmin::Config::Proxyable
include RailsAdmin::Config::Configurable
include RailsAdmin::Config::Hideable
register_instance_option :only do
nil
end
register_instance_option :except do
[]
end
# http://getbootstrap.com/2.3.2/base-css.html#icons
register_instance_option :link_icon do
'icon-question-sign'
end
# Should the action be visible
register_instance_option :visible? do
authorized?
end
register_instance_option :enabled? do
bindings[:abstract_model].nil? || (
(only.nil? || [only].flatten.collect(&:to_s).include?(bindings[:abstract_model].to_s)) &&
![except].flatten.collect(&:to_s).include?(bindings[:abstract_model].to_s) &&
!bindings[:abstract_model].config.excluded?
)
end
register_instance_option :authorized? do
enabled? && (
bindings[:controller].try(:authorization_adapter).nil? || bindings[:controller].authorization_adapter.authorized?(authorization_key, bindings[:abstract_model], bindings[:object])
)
end
# Is the action acting on the root level (Example: /admin/contact)
register_instance_option :root? do
false
end
# Is the action on a model scope (Example: /admin/team/export)
register_instance_option :collection? do
false
end
# Is the action on an object scope (Example: /admin/team/1/edit)
register_instance_option :member? do
false
end
# Render via pjax?
register_instance_option :pjax? do
true
end
# This block is evaluated in the context of the controller when action is called
# You can access:
# - @objects if you're on a model scope
# - @abstract_model & @model_config if you're on a model or object scope
# - @object if you're on an object scope
register_instance_option :controller do
proc do
render action: @action.template_name
end
end
# Model scoped actions only. You will need to handle params[:bulk_ids] in controller
register_instance_option :bulkable? do
false
end
# View partial name (called in default :controller block)
register_instance_option :template_name do
key.to_sym
end
# For Cancan and the like
register_instance_option :authorization_key do
key.to_sym
end
# List of methods allowed. Note that you are responsible for correctly handling them in :controller block
register_instance_option :http_methods do
[:get]
end
# Url fragment
register_instance_option :route_fragment do
custom_key.to_s
end
# Controller action name
register_instance_option :action_name do
custom_key.to_sym
end
# I18n key
register_instance_option :i18n_key do
key
end
# User should override only custom_key (action name and route fragment change, allows for duplicate actions)
register_instance_option :custom_key do
key
end
# Breadcrumb parent
register_instance_option :breadcrumb_parent do
case
when root?
[:dashboard]
when collection?
[:index, bindings[:abstract_model]]
when member?
[:show, bindings[:abstract_model], bindings[:object]]
end
end
# Off API.
def key
self.class.key
end
def self.key
name.to_s.demodulize.underscore.to_sym
end
end
end
end
end
|