Class: ActiveAdmin::BatchAction
- Inherits:
-
Object
- Object
- ActiveAdmin::BatchAction
- Includes:
- Comparable
- Defined in:
- lib/active_admin/batch_actions/resource_extension.rb
Constant Summary collapse
- DEFAULT_CONFIRM_MESSAGE =
proc { I18n.t "active_admin.batch_actions.default_confirmation" }
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#link_html_options ⇒ Object
readonly
Returns the value of attribute link_html_options.
-
#partial ⇒ Object
readonly
Returns the value of attribute partial.
-
#sym ⇒ Object
readonly
Returns the value of attribute sym.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
sort operator.
- #confirm ⇒ Object
-
#display_if_block ⇒ Object
Returns the display if block.
-
#initialize(sym, title, options = {}, &block) ⇒ BatchAction
constructor
Create a Batch Action.
-
#priority ⇒ Object
Used for sorting.
Constructor Details
#initialize(sym, title, options = {}, &block) ⇒ BatchAction
Create a Batch Action
Examples:
BatchAction.new :flag
> Will create an action that appears in the action list popover
BatchAction.new(:flag) { |selection| redirect_to collection_path, notice: "#{selection.length} users flagged" }
> Will create an action that uses a block to process the request (which receives one paramater of the selected objects)
BatchAction.new("Perform Long Operation on") { |selection| }
> You can create batch actions with a title instead of a Symbol
BatchAction.new(:flag, if: proc{ can? :flag, AdminUser }) { |selection| }
> You can provide an ‘:if` proc to choose when the batch action should be displayed
BatchAction.new :flag, confirm: true
> You can pass ‘true` to `:confirm` to use the default confirm message.
BatchAction.new(:flag, confirm: "Are you sure?") { |selection| }
> You can pass a custom confirmation message through ‘:confirm`
BatchAction.new(:flag, partial: "flag_form", link_html_options: { "data-modal-toggle": "flag-form-modal" }) { |selection, inputs| }
> Pass a partial that contains a modal and with a data attribute that opens the modal with the form for the user to fill out.
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 115 def initialize(sym, title, = {}, &block) @sym = sym @title = title @options = @block = block @confirm = [:confirm] @partial = [:partial] @link_html_options = [:link_html_options] || {} @block ||= proc {} end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
86 87 88 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 86 def block @block end |
#link_html_options ⇒ Object (readonly)
Returns the value of attribute link_html_options.
86 87 88 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 86 def @link_html_options end |
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
86 87 88 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 86 def partial @partial end |
#sym ⇒ Object (readonly)
Returns the value of attribute sym.
86 87 88 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 86 def sym @sym end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
86 87 88 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 86 def title @title end |
Instance Method Details
#<=>(other) ⇒ Object
sort operator
146 147 148 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 146 def <=>(other) self.priority <=> other.priority end |
#confirm ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 126 def confirm if @confirm == true DEFAULT_CONFIRM_MESSAGE else @confirm end end |
#display_if_block ⇒ Object
Returns the display if block. If the block was not explicitly defined a default block always returning true will be returned.
136 137 138 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 136 def display_if_block @options[:if] || proc { true } end |
#priority ⇒ Object
Used for sorting
141 142 143 |
# File 'lib/active_admin/batch_actions/resource_extension.rb', line 141 def priority @options[:priority] || 10 end |