1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-Action-method-constructor'><span id='Ext-Action'>/**
2 </span></span> * @class Ext.Action
3 * <p>An Action is a piece of reusable functionality that can be abstracted out of any particular component so that it
4 * can be usefully shared among multiple components. Actions let you share handlers, configuration options and UI
5 * updates across any components that support the Action interface (primarily {@link Ext.toolbar.Toolbar}, {@link Ext.button.Button}
6 * and {@link Ext.menu.Menu} components).</p>
7 * <p>Use a single Action instance as the config object for any number of UI Components which share the same configuration. The
8 * Action not only supplies the configuration, but allows all Components based upon it to have a common set of methods
9 * called at once through a single call to the Action.</p>
10 * <p>Any Component that is to be configured with an Action must also support
11 * the following methods:<ul>
12 * <li><code>setText(string)</code></li>
13 * <li><code>setIconCls(string)</code></li>
14 * <li><code>setDisabled(boolean)</code></li>
15 * <li><code>setVisible(boolean)</code></li>
16 * <li><code>setHandler(function)</code></li></ul>.</p>
17 * <p>This allows the Action to control its associated Components.</p>
18 * Example usage:<br>
19 * <pre><code>
20 // Define the shared Action. Each Component below will have the same
21 // display text and icon, and will display the same message on click.
22 var action = new Ext.Action({
23 {@link #text}: 'Do something',
24 {@link #handler}: function(){
25 Ext.Msg.alert('Click', 'You did something.');
27 {@link #iconCls}: 'do-something',
28 {@link #itemId}: 'myAction'
31 var panel = new Ext.panel.Panel({
36 // Add the Action directly to a toolbar as a menu button
40 // Add the Action to a menu as a text item
45 // Add the Action to the panel body as a standard button
46 new Ext.button.Button(action)
48 renderTo: Ext.getBody()
51 // Change the text for all components using the Action
52 action.setText('Something else');
54 // Reference an Action through a container using the itemId
55 var btn = panel.getComponent('myAction');
56 var aRef = btn.baseAction;
57 aRef.setText('New text');
58 </code></pre>
60 * @param {Object} config The configuration options
62 Ext.define('Ext.Action', {
64 /* Begin Definitions */
68 <span id='Ext-Action-cfg-text'> /**
69 </span> * @cfg {String} text The text to set for all components configured by this Action (defaults to '').
71 <span id='Ext-Action-cfg-iconCls'> /**
72 </span> * @cfg {String} iconCls
73 * The CSS class selector that specifies a background image to be used as the header icon for
74 * all components configured by this Action (defaults to '').
75 * <p>An example of specifying a custom icon class would be something like:
76 * </p><pre><code>
77 // specify the property in the config for the class:
79 iconCls: 'do-something'
81 // css class that specifies background image to be used as the icon image:
82 .do-something { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }
83 </code></pre>
85 <span id='Ext-Action-cfg-disabled'> /**
86 </span> * @cfg {Boolean} disabled True to disable all components configured by this Action, false to enable them (defaults to false).
88 <span id='Ext-Action-cfg-hidden'> /**
89 </span> * @cfg {Boolean} hidden True to hide all components configured by this Action, false to show them (defaults to false).
91 <span id='Ext-Action-cfg-handler'> /**
92 </span> * @cfg {Function} handler The function that will be invoked by each component tied to this Action
93 * when the component's primary event is triggered (defaults to undefined).
95 <span id='Ext-Action-cfg-itemId'> /**
96 </span> * @cfg {String} itemId
97 * See {@link Ext.Component}.{@link Ext.Component#itemId itemId}.
99 <span id='Ext-Action-cfg-scope'> /**
100 </span> * @cfg {Object} scope The scope (<code><b>this</b></code> reference) in which the
101 * <code>{@link #handler}</code> is executed. Defaults to the browser window.
104 constructor : function(config){
105 this.initialConfig = config;
106 this.itemId = config.itemId = (config.itemId || config.id || Ext.id());
113 <span id='Ext-Action-method-setText'> /**
114 </span> * Sets the text to be displayed by all components configured by this Action.
115 * @param {String} text The text to display
117 setText : function(text){
118 this.initialConfig.text = text;
119 this.callEach('setText', [text]);
122 <span id='Ext-Action-method-getText'> /**
123 </span> * Gets the text currently displayed by all components configured by this Action.
125 getText : function(){
126 return this.initialConfig.text;
129 <span id='Ext-Action-method-setIconCls'> /**
130 </span> * Sets the icon CSS class for all components configured by this Action. The class should supply
131 * a background image that will be used as the icon image.
132 * @param {String} cls The CSS class supplying the icon image
134 setIconCls : function(cls){
135 this.initialConfig.iconCls = cls;
136 this.callEach('setIconCls', [cls]);
139 <span id='Ext-Action-method-getIconCls'> /**
140 </span> * Gets the icon CSS class currently used by all components configured by this Action.
142 getIconCls : function(){
143 return this.initialConfig.iconCls;
146 <span id='Ext-Action-method-setDisabled'> /**
147 </span> * Sets the disabled state of all components configured by this Action. Shortcut method
148 * for {@link #enable} and {@link #disable}.
149 * @param {Boolean} disabled True to disable the component, false to enable it
151 setDisabled : function(v){
152 this.initialConfig.disabled = v;
153 this.callEach('setDisabled', [v]);
156 <span id='Ext-Action-method-enable'> /**
157 </span> * Enables all components configured by this Action.
160 this.setDisabled(false);
163 <span id='Ext-Action-method-disable'> /**
164 </span> * Disables all components configured by this Action.
166 disable : function(){
167 this.setDisabled(true);
170 <span id='Ext-Action-method-isDisabled'> /**
171 </span> * Returns true if the components using this Action are currently disabled, else returns false.
173 isDisabled : function(){
174 return this.initialConfig.disabled;
177 <span id='Ext-Action-method-setHidden'> /**
178 </span> * Sets the hidden state of all components configured by this Action. Shortcut method
179 * for <code>{@link #hide}</code> and <code>{@link #show}</code>.
180 * @param {Boolean} hidden True to hide the component, false to show it
182 setHidden : function(v){
183 this.initialConfig.hidden = v;
184 this.callEach('setVisible', [!v]);
187 <span id='Ext-Action-method-show'> /**
188 </span> * Shows all components configured by this Action.
191 this.setHidden(false);
194 <span id='Ext-Action-method-hide'> /**
195 </span> * Hides all components configured by this Action.
198 this.setHidden(true);
201 <span id='Ext-Action-method-isHidden'> /**
202 </span> * Returns true if the components configured by this Action are currently hidden, else returns false.
204 isHidden : function(){
205 return this.initialConfig.hidden;
208 <span id='Ext-Action-method-setHandler'> /**
209 </span> * Sets the function that will be called by each Component using this action when its primary event is triggered.
210 * @param {Function} fn The function that will be invoked by the action's components. The function
211 * will be called with no arguments.
212 * @param {Object} scope The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component firing the event.
214 setHandler : function(fn, scope){
215 this.initialConfig.handler = fn;
216 this.initialConfig.scope = scope;
217 this.callEach('setHandler', [fn, scope]);
220 <span id='Ext-Action-method-each'> /**
221 </span> * Executes the specified function once for each Component currently tied to this Action. The function passed
222 * in should accept a single argument that will be an object that supports the basic Action config/method interface.
223 * @param {Function} fn The function to execute for each component
224 * @param {Object} scope The scope (<code>this</code> reference) in which the function is executed. Defaults to the Component.
226 each : function(fn, scope){
227 Ext.each(this.items, fn, scope);
231 callEach : function(fnName, args){
233 for(var i = 0, len = cs.length; i < len; i++){
234 cs[i][fnName].apply(cs[i], args);
239 addComponent : function(comp){
240 this.items.push(comp);
241 comp.on('destroy', this.removeComponent, this);
245 removeComponent : function(comp){
246 this.items.remove(comp);
249 <span id='Ext-Action-method-execute'> /**
250 </span> * Executes this Action manually using the handler function specified in the original config object
251 * or the handler function set with <code>{@link #setHandler}</code>. Any arguments passed to this
252 * function will be passed on to the handler function.
253 * @param {Mixed} arg1 (optional) Variable number of arguments passed to the handler function
254 * @param {Mixed} arg2 (optional)
255 * @param {Mixed} etc... (optional)
257 execute : function(){
258 this.initialConfig.handler.apply(this.initialConfig.scope || Ext.global, arguments);
261 </pre></pre></body></html>