Sha256: e0d2db254ec6e344446fa4856d8b8a0b18632b9f56c52e582396ec3383756a11

Contents?: true

Size: 1.77 KB

Versions: 62

Compression:

Stored size: 1.77 KB

Contents

require 'active_admin/views/components/popover'

module ActiveAdmin
  module Views

    # Action List - A button with a drop down menu of links
    #
    # Creating a new action list:
    #
    #     dropdown_menu "Administration" do
    #       item "Edit Details", edit_details_path
    #       item "Edit My Account", edit_my_acccount_path
    #     end
    #
    # This will create a button with the label "Administration" and
    # a drop down once clicked with 2 options.
    #
    class DropdownMenu < ActiveAdmin::Component
      builder_method :dropdown_menu

      # Build a new action list
      #
      # @param [String] name  The name to display in the button
      #
      # @param [Hash] options A set of options that get passed along to
      #                       to the parent dom element.
      def build(name, options = {})
        options = options.dup

        # Easily set options for the button or menu
        button_options  = options.delete(:button) || {}
        menu_options = options.delete(:menu) || {}

        @button  = build_button(name, button_options)
        @menu = build_menu(menu_options)

        super(options)
      end

      def item(*args)
        within @menu do
          li link_to(*args)
        end
      end

      private

      def build_button(name, button_options)
        button_options[:class] ||= ""
        button_options[:class] << " dropdown_menu_button"

        button_options[:href] = "#"

        a name, button_options
      end

      def build_menu(options)
        options[:class] ||= ""
        options[:class] << " dropdown_menu_list"

        menu_list = nil

        div :class => "dropdown_menu_list_wrapper", :style => "display:none;" do
          menu_list = ul(options)
        end

        menu_list
      end

    end

  end
end

Version data entries

62 entries across 62 versions & 4 rubygems

Version Path
activeadmin-0.6.6 lib/active_admin/views/components/dropdown_menu.rb
activeadmin-0.6.5 lib/active_admin/views/components/dropdown_menu.rb
activeadmin-0.6.4 lib/active_admin/views/components/dropdown_menu.rb
yousty-activeadmin-1.0.4.pre lib/active_admin/views/components/dropdown_menu.rb
yousty-activeadmin-1.0.3.pre lib/active_admin/views/components/dropdown_menu.rb
yousty-activeadmin-1.0.2.pre lib/active_admin/views/components/dropdown_menu.rb
activeadmin-0.6.3 lib/active_admin/views/components/dropdown_menu.rb
yousty-activeadmin-1.0.1.pre lib/active_admin/views/components/dropdown_menu.rb
yousty-activeadmin-1.0.0.pre lib/active_admin/views/components/dropdown_menu.rb
activeadmin-0.6.2 lib/active_admin/views/components/dropdown_menu.rb
activeadmin-0.6.1 lib/active_admin/views/components/dropdown_menu.rb
aa-rails4-0.6.0 lib/active_admin/views/components/dropdown_menu.rb
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/views/components/dropdown_menu.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/views/components/dropdown_menu.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/views/components/dropdown_menu.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/views/components/dropdown_menu.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/views/components/dropdown_menu.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/views/components/dropdown_menu.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/views/components/dropdown_menu.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/views/components/dropdown_menu.rb