Clear Up
SharpKit Reference

Action Class

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.Toolbar, Ext.button.Button and Ext.menu.Menu components).

Use a single Action instance as the config object for any number of UI Components which share the same configuration. The Action not only supplies the configuration, but allows all Components based upon it to have a common set of methods called at once through a single call to the Action.

Any Component that is to be configured with an Action must also support the following methods:

  • setText(string)
  • setIconCls(string)
  • setDisabled(boolean)
  • setVisible(boolean)
  • setHandler(function)

This allows the Action to control its associated Components.

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.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.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');
            

Namespace: Ext

Base Types

Constructors

Name Description
Action(object) Creates new Action.
Action(ActionConfig)
Action()
Action(Object[])

Methods

Name Description
disable() Disables all components configured by this Action.
each(Delegate, object) 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.
enable() Enables all components configured by this Action.
execute(Object[]) 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.
getIconCls() Gets the icon CSS class currently used by all components configured by this Action.
getText() Gets the text currently displayed by all components configured by this Action.
hide() Hides all components configured by this Action.
isDisabled() Returns true if the components using this Action are currently disabled, else returns false.
isHidden() Returns true if the components configured by this Action are currently hidden, else returns false.
setDisabled(bool) Sets the disabled state of all components configured by this Action. Shortcut method for enable and disable.
setHandler(Delegate, object) Sets the function that will be called by each Component using this action when its primary event is triggered.
setHidden(bool) Sets the hidden state of all components configured by this Action. Shortcut method for hide and show.
setIconCls(JsString) Sets the icon CSS class for all components configured by this Action. The class should supply a background image that will be used as the icon image.
setText(JsString) Sets the text to be displayed by all components configured by this Action.
show() Shows all components configured by this Action.

Fields

Name Description
disabled True to disable all components configured by this Action, false to enable them. Defaults to: false
handler The function that will be invoked by each component tied to this Action when the component's primary event is triggered.
hidden True to hide all components configured by this Action, false to show them. Defaults to: false
iconCls The CSS class selector that specifies a background image to be used as the header icon for all components configured by this Action. 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; }
            
Defaults to: ""
itemId See Ext.Component.itemId.
scope The scope (this reference) in which the handler is executed. Defaults to the browser window.
text The text to set for all components configured by this Action. Defaults to: ""
© Copyright 2005-2011 SharpKit. All rights reserved.