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



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

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

#batch_action_path(params = {}) ⇒ Object

Path to the batch action itself



55
56
57
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 55

def batch_action_path(params = {})
  [route_collection_path(params), "batch_action"].join("/")
end

#batch_actionsArray



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

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



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

def batch_actions=(bool)
  @batch_actions_enabled = bool
end

#batch_actions_enabled?Boolean



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

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



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

def clear_batch_actions!
  @batch_actions = {}
end

#initializeObject



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

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

#remove_batch_action(sym) ⇒ Object

Remove a batch action



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

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