Sha256: a5b4bf285d8a40795f9ecdca4f46ed44219e5ffa79e8497b5013dd3b0043d349

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

module ExpressAdmin
  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 config[:command].to_s.titleize, 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]}
    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


  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
express_admin-1.6.3 app/components/express_admin/command_button.rb
express_admin-1.6.2 app/components/express_admin/command_button.rb
express_admin-1.6.1 app/components/express_admin/command_button.rb
express_admin-1.6.0 app/components/express_admin/command_button.rb