# Class Ext.Action

Package: | Ext
Defined In: | Action.js
Class: | Action
Extends: | Object

An Action is a piece of reusable functionality that can be abstracted out of any particular component so that it can be usefully shared among multiple components. Actions let you share handlers, configuration options and UI updates across any components that support the Action interface (primarily Ext.Toolbar, Ext.Button and Ext.menu.Menu components).

Aside from supporting the config object interface, any component that needs to use Actions must also support the following method list, as these will be called as needed by the Action class: setText(string), setIconCls(string), setDisabled(boolean), setVisible(boolean) and setHandler(function).

Example usage:

    // Define the shared action.  Each component below will have the same

    // display text and icon, and will display the same message on click.

    var action = new Ext.Action({
        text: 'Do something',
        handler: function(){
            Ext.Msg.alert('Click', 'You did something.');
        },
        iconCls: 'do-something',
        itemId: 'myAction'
    });

    var panel = new Ext.Panel({
        title: 'Actions',
        width: 500,
        height: 300,
        tbar: [
            // Add the action directly to a toolbar as a menu button

            action,
            {
                text: 'Action Menu',
                // Add the action to a menu as a text item

                menu: [action]
            }
        ],
        items: [
            // Add the action to the panel body as a standard button

            new Ext.Button(action)
        ],
        renderTo: Ext.getBody()
    });

    // Change the text for all components using the action

    action.setText('Something else');

    // Reference an action through a container using the itemId

    var btn = panel.getComponent('myAction');
    var aRef = btn.baseAction;
    aRef.setText('New text');

## Config Options

Config Options | Defined By
--- | ---
| disabled : Boolean True to disable all components using this action, false to enable them (defaults to false). | Action
| handler : Function The function that will be invoked by each component tied to this action when the component's primary event is trigge... The function that will be invoked by each component tied to this action when the component's primary event is triggered (defaults to undefined). | Action
| hidden : Boolean True to hide all components using this action, false to show them (defaults to false). | Action
| iconCls : String The CSS class selector that specifies a background image to be used as the header icon for all components using this... The CSS class selector that specifies a background image to be used as the header icon for all components using this action (defaults to ''). An example of specifying a custom icon class would be something like:
    // specify the property in the config for the class:

         ...
         iconCls: 'do-something'

    // css class that specifies background image to be used as the icon image:

    .do-something { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }
| Action
| itemId : String See Ext.Component.itemId. | Action
| scope : Object The scope (`this` reference) in which the `handler` is executed. Defaults to this Button. | Action
| text : String The text to set for all components using this action (defaults to ''). | Action

## Public Properties

This class has no public properties.

## Public Methods

Method | Defined By
--- | ---
| Action( `Object config` ) Parameters: `config` : Object The configuration options Returns: void | Action
| disable() : void Disables all components using this action. Disables all components using this action. Parameters: None. Returns: void | Action
| each( `Function fn`, `Object scope` ) : void Executes the specified function once for each Component currently tied to this action. The function passed in shoul... Executes the specified function once for each Component currently tied to this action. The function passed in should accept a single argument that will be an object that supports the basic Action config/method interface. Parameters: `fn` : Function The function to execute for each component `scope` : Object The scope (`this` reference) in which the function is executed. Defaults to the Component. Returns: void | Action
| enable() : void Enables all components using this action. Enables all components using this action. Parameters: None. Returns: void | Action
| execute( [`Mixed arg1`], [`Mixed arg2`], [`Mixed etc...`] ) : void Executes this action manually using the handler function specified in the original config object or the handler func... Executes this action manually using the handler function specified in the original config object or the handler function set with `setHandler`. Any arguments passed to this function will be passed on to the handler function. Parameters: `arg1` : Mixed (optional) Variable number of arguments passed to the handler function `arg2` : Mixed (optional) `etc...` : Mixed (optional) Returns: void | Action
| getIconClass() : void Gets the icon CSS class currently used by all components using this action. Gets the icon CSS class currently used by all components using this action. Parameters: None. Returns: void | Action
| getText() : void Gets the text currently displayed by all components using this action. Gets the text currently displayed by all components using this action. Parameters: None. Returns: void | Action
| hide() : void Hides all components using this action. Hides all components using this action. Parameters: None. Returns: void | Action
| isDisabled() : void Returns true if the components using this action are currently disabled, else returns false. Returns true if the components using this action are currently disabled, else returns false. Parameters: None. Returns: void | Action
| isHidden() : void Returns true if the components using this action are currently hidden, else returns false. Returns true if the components using this action are currently hidden, else returns false. Parameters: None. Returns: void | Action
| setDisabled( `Boolean disabled` ) : void Sets the disabled state of all components using this action. Shortcut method for enable and disable. Sets the disabled state of all components using this action. Shortcut method for enable and disable. Parameters: `disabled` : Boolean True to disable the component, false to enable it Returns: void | Action
| setHandler( `Function fn`, `Object scope` ) : void Sets the function that will be called by each Component using this action when its primary event is triggered. Sets the function that will be called by each Component using this action when its primary event is triggered. Parameters: `fn` : Function The function that will be invoked by the action's components. The function will be called with no arguments. `scope` : Object The scope (`this` reference) in which the function is executed. Defaults to the Component firing the event. Returns: void | Action
| setHidden( `Boolean hidden` ) : void Sets the hidden state of all components using this action. Shortcut method for hide and show. Sets the hidden state of all components using this action. Shortcut method for `hide` and `show`. Parameters: `hidden` : Boolean True to hide the component, false to show it Returns: void | Action
| setIconClass( `String cls` ) : void Sets the icon CSS class for all components using this action. The class should supply a background image that will ... Sets the icon CSS class for all components using this action. The class should supply a background image that will be used as the icon image. Parameters: `cls` : String The CSS class supplying the icon image Returns: void | Action
| setText( `String text` ) : void Sets the text to be displayed by all components using this action. Sets the text to be displayed by all components using this action. Parameters: `text` : String The text to display Returns: void | Action
| show() : void Shows all components using this action. Shows all components using this action. Parameters: None. Returns: void | Action

## Public Events

This class has no public events.