Sha256: 0c9289e1980d1e32d54cd585ca4d47f9ee8f88cf6fadec3c1a04d8f8a9cca105

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

module ExpressAdmin
  module Components
    module Navigation
      class CommandButton < ExpressTemplates::Components::Configurable
        include ExpressTemplates::Components::Capabilities::Resourceful


        has_argument :id, "The command name.  Invoked as an action on the resource.", as: :command, type: :symbol
        has_option :disabled, "Disables the button", type: :boolean
        has_option :confirm, "Prompt with the question specified."
        has_option :resource_name, "The name of the resource for this command.  Eg. 'person' for like_person_path()"

        before_build -> {
          config[:command] = config[:command].debang
          add_class(config[:command])
        }

        contains -> {
          button_to command_title, action, button_to_options
        }

        def resource_name
          config[:resource_name] || parent_command_button_list.resource_name
        end

        def button_to_options
          {remote: true, disabled: config[:disabled], confirm: config[:confirm], form_class: 'js-command-button', data: { command: command_title }}
        end

        def action
          helpers.send "#{config[:command]}_#{resource_path_helper}", resource.to_param
        end

        def parent_command_button_list
          @parent_button_list ||= parent
          until @parent_button_list.nil? || @parent_button_list.kind_of?(CommandButtonList)
            @parent_button_list = @parent_button_list.parent
          end
          return @parent_button_list
        end

        private

        def command_title
          config[:command].to_s.titleize
        end
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
express_admin-1.7.11 app/components/express_admin/command_button.rb
express_admin-1.7.10 app/components/express_admin/command_button.rb
express_admin-1.7.9 app/components/express_admin/command_button.rb
express_admin-1.7.8 app/components/express_admin/command_button.rb
express_admin-1.7.7 app/components/express_admin/command_button.rb