Sha256: 74daee8b64e6f2e1dca9fb41f70b9da4add90b13724c12a8664d1fe259b557a2

Contents?: true

Size: 1.83 KB

Versions: 20

Compression:

Stored size: 1.83 KB

Contents

require 'active_admin/component'

module ActiveAdmin
  module BatchActions

    class BatchActionSelector < ActiveAdmin::Component
      builder_method :batch_action_selector

      # Build a new batch actions selector
      #
      # @param [Array] batch_actions An array of batch actions
      def build(batch_actions)
        @batch_actions = Array(batch_actions)
        @drop_down = build_drop_down
      end

      # We don't want to wrap the action list (or any other children) in
      # an unecessary div, so instead we just return the children
      def to_s
        children.to_s
      end

      private

      def build_drop_down
        dropdown_menu I18n.t("active_admin.batch_actions.button_label"),
                      class: "batch_actions_selector dropdown_menu",
                      button: { class: "disabled" } do
          batch_actions_to_display.each do |batch_action|
            confirmation_text = render_or_call_method_or_proc_on(self, batch_action.confirm)

            options = {
              :class         => "batch_action",
              "data-action"  => batch_action.sym,
              "data-confirm" => confirmation_text,
              "data-inputs"  => render_in_context(self, batch_action.inputs).to_json
            }

            default_title = render_or_call_method_or_proc_on(self, batch_action.title)
            title = I18n.t("active_admin.batch_actions.labels.#{batch_action.sym}", default: default_title)
            label = I18n.t("active_admin.batch_actions.action_label", title: title)

            item label, "#", options
          end
        end
      end

      # Return the set of batch actions that should be displayed
      def batch_actions_to_display
        @batch_actions.select do |batch_action|
          call_method_or_proc_on(self, batch_action.display_if_block)
        end
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/batch_actions/views/batch_action_selector.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.17.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.16.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/batch_actions/views/batch_action_selector.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/batch_actions/views/batch_action_selector.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.15.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.14.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.13.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.12.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.11.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.10.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.9.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.8.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
activeadmin-1.0.0.pre2 lib/active_admin/batch_actions/views/batch_action_selector.rb
activeadmin-1.0.0.pre1 lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.7.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.6.pre lib/active_admin/batch_actions/views/batch_action_selector.rb
yousty-activeadmin-1.0.5.pre lib/active_admin/batch_actions/views/batch_action_selector.rb