Module: ActiveAdmin::BatchActions::ResourceExtension

Defined in:
lib/active_admin/batch_actions/resource_extension.rb

Instance Method Summary collapse

Instance Method Details

#add_batch_action(sym, title, options = {}, &block) ⇒ Object

Add a new batch item to a resource

> :if is a proc that will be called to determine if the BatchAction should be displayed

> :sort_order is used to sort the batch actions ascending

> :confirm is a string to prompt the user with (or a boolean to use the default message)

> :form is a Hash of form fields you want the user to fill out

Parameters:

  • title (String)
  • options (Hash) (defaults to: {})

38
39
40
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 38

def add_batch_action(sym, title, options = {}, &block)
  @batch_actions[sym] = ActiveAdmin::BatchAction.new(sym, title, options, &block)
end

#batch_actionsArray

Returns The set of batch actions for this resource.

Returns:

  • (Array)

    The set of batch actions for this resource


13
14
15
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 13

def batch_actions
  batch_actions_enabled? ? @batch_actions.values.sort : []
end

#batch_actions=(bool) ⇒ Object

Disable or Enable batch actions for this resource Set to `nil` to inherit the setting from the namespace


26
27
28
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 26

def batch_actions=(bool)
  @batch_actions_enabled = bool
end

#batch_actions_enabled?Boolean

Returns If batch actions are enabled for this resource.

Returns:

  • (Boolean)

    If batch actions are enabled for this resource


18
19
20
21
22
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 18

def batch_actions_enabled?
  # If the resource config has been set, use it. Otherwise
  # return the namespace setting
  @batch_actions_enabled.nil? ? namespace.batch_actions : @batch_actions_enabled
end

#clear_batch_actions!Object

Clears all the existing batch actions for this resource


51
52
53
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 51

def clear_batch_actions!
  @batch_actions = {}
end

#initializeObject


6
7
8
9
10
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 6

def initialize(*)
  super
  @batch_actions = {}
  add_default_batch_action
end

#remove_batch_action(sym) ⇒ ActiveAdmin::BatchAction

Remove a batch action

Parameters:

  • sym (Symbol)

Returns:


46
47
48
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 46

def remove_batch_action(sym)
  @batch_actions.delete(sym.to_sym)
end