Sha256: 93ed1341717b14238c457f17a633a396450a42cde0f6fe363ddda5f9a6860ad6

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 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"), 
                      :id => "batch_actions_selector",
                      :button => { :class => "disabled" } do
          batch_actions_to_display.each do |batch_action|
            options = {
              :class => "batch_action",
              "data-action" => batch_action.sym,
              "data-confirm" => batch_action.confirm
            }

            title = I18n.t("active_admin.batch_actions.labels.#{batch_action.sym}", :default => batch_action.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

      # def build_batch_action_button
      #   a :class => 'table_tools_button dropdown_button disabled', :href => "#batch_actions_popover", :id => "batch_actions_button" do
      #     text_node I18n.t("active_admin.batch_actions.button_label")
      #   end
      # end

      # def build_batch_action_popover
      # end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeadmin-0.5.0.pre lib/active_admin/batch_actions/views/batch_action_selector.rb