Module: ActiveAdminScopedCollectionActions::ResourceExtension
- Defined in:
- lib/active_admin_scoped_collection_actions/resource_extension.rb
Instance Method Summary collapse
- #add_scoped_collection_action(name, options) ⇒ Object
- #add_scoped_collection_actions_sidebar_section ⇒ Object
- #initialize ⇒ Object
- #scoped_collection_actions ⇒ Object
- #scoped_collection_actions_if ⇒ Object
- #scoped_collection_actions_if=(if_proc) ⇒ Object
- #scoped_collection_actions_on_all ⇒ Object
- #scoped_collection_actions_on_all=(bool) ⇒ Object
- #scoped_collection_actions_sidebar_section ⇒ Object
- #scoped_collection_sidebar_condition ⇒ Object
Instance Method Details
#add_scoped_collection_action(name, options) ⇒ Object
21 22 23 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 21 def add_scoped_collection_action(name, ) (@scoped_collection_actions ||= {})[name.to_sym] = end |
#add_scoped_collection_actions_sidebar_section ⇒ Object
25 26 27 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 25 def self. << end |
#initialize ⇒ Object
4 5 6 7 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 4 def initialize(*) super end |
#scoped_collection_actions ⇒ Object
9 10 11 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 9 def scoped_collection_actions @scoped_collection_actions || {} end |
#scoped_collection_actions_if ⇒ Object
33 34 35 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 33 def scoped_collection_actions_if @if_proc end |
#scoped_collection_actions_if=(if_proc) ⇒ Object
29 30 31 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 29 def scoped_collection_actions_if=(if_proc) @if_proc = if_proc end |
#scoped_collection_actions_on_all ⇒ Object
17 18 19 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 17 def scoped_collection_actions_on_all @scoped_collection_actions_unconditionally || false end |
#scoped_collection_actions_on_all=(bool) ⇒ Object
13 14 15 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 13 def scoped_collection_actions_on_all=(bool) @scoped_collection_actions_unconditionally = bool end |
#scoped_collection_actions_sidebar_section ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 51 def ActiveAdmin::SidebarSection.new :collection_actions, only: :index, if: do div I18n.t('active_admin_scoped_collection_actions.sidebar_msg') active_admin_config.scoped_collection_actions.each do |key, ={}| b_title = .fetch(:title, ::ActiveSupport::Inflector.humanize(key)) = {} [:class] = [:class] if [:class].present? # Important: If user did not specify html_class, then use default [:class] = 'scoped_collection_action_button' unless [:class] b_data = { auth_token: form_authenticity_token.to_s } b_data[:batch_action] = key.to_s if [:form].present? b_data[:inputs] = [:form].is_a?(Proc) ? [:form].call : [:form] end b_data[:confirm] = .fetch(:confirm, I18n.t('active_admin_scoped_collection_actions.confirm_action_message')) [:data] = b_data.to_json b_title, end end end |
#scoped_collection_sidebar_condition ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_admin_scoped_collection_actions/resource_extension.rb', line 37 def -> do if active_admin_config.scoped_collection_actions_if.is_a?(Proc) instance_exec &active_admin_config.scoped_collection_actions_if else filtered_scoped = (params[:q] || params[:scope]) on_all = active_admin_config.scoped_collection_actions_on_all has_actions = active_admin_config.scoped_collection_actions.any? batch_actions_enabled = active_admin_config.batch_actions_enabled? ( batch_actions_enabled && has_actions && (filtered_scoped || on_all) ) end end end |