X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6:/src/widgets/Action.js..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/src/Action.js diff --git a/src/widgets/Action.js b/src/Action.js similarity index 66% rename from src/widgets/Action.js rename to src/Action.js index 3c57954c..9e1c390f 100644 --- a/src/widgets/Action.js +++ b/src/Action.js @@ -1,21 +1,23 @@ -/*! - * Ext JS Library 3.3.1 - * Copyright(c) 2006-2010 Sencha Inc. - * licensing@sencha.com - * http://www.sencha.com/license - */ /** * @class Ext.Action *
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 {@link Ext.Toolbar}, {@link Ext.Button} + * updates across any components that support the Action interface (primarily {@link Ext.toolbar.Toolbar}, {@link Ext.button.Button} * and {@link 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).
+ *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
+// 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({
{@link #text}: 'Do something',
@@ -26,30 +28,30 @@ var action = new Ext.Action({
{@link #itemId}: 'myAction'
});
-var panel = new Ext.Panel({
+var panel = new Ext.panel.Panel({
title: 'Actions',
width: 500,
height: 300,
tbar: [
- // Add the action directly to a toolbar as a menu button
+ // 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
+ // 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)
+ // 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
+// Change the text for all components using the Action
action.setText('Something else');
-// Reference an action through a container using the itemId
+// Reference an Action through a container using the itemId
var btn = panel.getComponent('myAction');
var aRef = btn.baseAction;
aRef.setText('New text');
@@ -57,14 +59,19 @@ aRef.setText('New text');
* @constructor
* @param {Object} config The configuration options
*/
-Ext.Action = Ext.extend(Object, {
+Ext.define('Ext.Action', {
+
+ /* Begin Definitions */
+
+ /* End Definitions */
+
/**
- * @cfg {String} text The text to set for all components using this action (defaults to '').
+ * @cfg {String} text The text to set for all components configured by this Action (defaults to '').
*/
/**
* @cfg {String} iconCls
* The CSS class selector that specifies a background image to be used as the header icon for
- * all components using this action (defaults to '').
+ * all components configured by 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:
@@ -76,13 +83,13 @@ Ext.Action = Ext.extend(Object, {
*/
/**
- * @cfg {Boolean} disabled True to disable all components using this action, false to enable them (defaults to false).
+ * @cfg {Boolean} disabled True to disable all components configured by this Action, false to enable them (defaults to false).
*/
/**
- * @cfg {Boolean} hidden True to hide all components using this action, false to show them (defaults to false).
+ * @cfg {Boolean} hidden True to hide all components configured by this Action, false to show them (defaults to false).
*/
/**
- * @cfg {Function} handler The function that will be invoked by each component tied to this action
+ * @cfg {Function} handler The function that will be invoked by each component tied to this Action
* when the component's primary event is triggered (defaults to undefined).
*/
/**
@@ -90,8 +97,8 @@ Ext.Action = Ext.extend(Object, {
* See {@link Ext.Component}.{@link Ext.Component#itemId itemId}.
*/
/**
- * @cfg {Object} scope The scope (this reference) in which the
- * {@link #handler}
is executed. Defaults to this Button.
+ * @cfg {Object} scope The scope (this
reference) in which the
+ * {@link #handler}
is executed. Defaults to the browser window.
*/
constructor : function(config){
@@ -99,12 +106,12 @@ Ext.Action = Ext.extend(Object, {
this.itemId = config.itemId = (config.itemId || config.id || Ext.id());
this.items = [];
},
-
+
// private
isAction : true,
/**
- * Sets the text to be displayed by all components using this action.
+ * Sets the text to be displayed by all components configured by this Action.
* @param {String} text The text to display
*/
setText : function(text){
@@ -113,31 +120,31 @@ Ext.Action = Ext.extend(Object, {
},
/**
- * Gets the text currently displayed by all components using this action.
+ * Gets the text currently displayed by all components configured by this Action.
*/
getText : function(){
return this.initialConfig.text;
},
/**
- * Sets the icon CSS class for all components using this action. The class should supply
+ * 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.
* @param {String} cls The CSS class supplying the icon image
*/
- setIconClass : function(cls){
+ setIconCls : function(cls){
this.initialConfig.iconCls = cls;
- this.callEach('setIconClass', [cls]);
+ this.callEach('setIconCls', [cls]);
},
/**
- * Gets the icon CSS class currently used by all components using this action.
+ * Gets the icon CSS class currently used by all components configured by this Action.
*/
- getIconClass : function(){
+ getIconCls : function(){
return this.initialConfig.iconCls;
},
/**
- * Sets the disabled state of all components using this action. Shortcut method
+ * Sets the disabled state of all components configured by this Action. Shortcut method
* for {@link #enable} and {@link #disable}.
* @param {Boolean} disabled True to disable the component, false to enable it
*/
@@ -147,28 +154,28 @@ Ext.Action = Ext.extend(Object, {
},
/**
- * Enables all components using this action.
+ * Enables all components configured by this Action.
*/
enable : function(){
this.setDisabled(false);
},
/**
- * Disables all components using this action.
+ * Disables all components configured by this Action.
*/
disable : function(){
this.setDisabled(true);
},
/**
- * 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.
*/
isDisabled : function(){
return this.initialConfig.disabled;
},
/**
- * Sets the hidden state of all components using this action. Shortcut method
+ * Sets the hidden state of all components configured by this Action. Shortcut method
* for {@link #hide}
and {@link #show}
.
* @param {Boolean} hidden True to hide the component, false to show it
*/
@@ -178,21 +185,21 @@ Ext.Action = Ext.extend(Object, {
},
/**
- * Shows all components using this action.
+ * Shows all components configured by this Action.
*/
show : function(){
this.setHidden(false);
},
/**
- * Hides all components using this action.
+ * Hides all components configured by this Action.
*/
hide : function(){
this.setHidden(true);
},
/**
- * Returns true if the components using this action are currently hidden, else returns false.
+ * Returns true if the components configured by this Action are currently hidden, else returns false.
*/
isHidden : function(){
return this.initialConfig.hidden;
@@ -211,7 +218,7 @@ Ext.Action = Ext.extend(Object, {
},
/**
- * Executes the specified function once for each Component currently tied to this action. The function passed
+ * 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.
* @param {Function} fn The function to execute for each component
* @param {Object} scope The scope (this
reference) in which the function is executed. Defaults to the Component.
@@ -240,7 +247,7 @@ Ext.Action = Ext.extend(Object, {
},
/**
- * Executes this action manually using the handler function specified in the original config object
+ * Executes this Action manually using the handler function specified in the original config object
* or the handler function set with {@link #setHandler}
. Any arguments passed to this
* function will be passed on to the handler function.
* @param {Mixed} arg1 (optional) Variable number of arguments passed to the handler function
@@ -248,6 +255,6 @@ Ext.Action = Ext.extend(Object, {
* @param {Mixed} etc... (optional)
*/
execute : function(){
- this.initialConfig.handler.apply(this.initialConfig.scope || window, arguments);
+ this.initialConfig.handler.apply(this.initialConfig.scope || Ext.global, arguments);
}
});