tvheadend/vendor/ext-3.4.1/docs/source/Action.html
Adam Sutton bafcfff42d webui: restructure webui/extjs source files
I want to keep the 3rd-party packages away from the main source
where possible.
2013-06-03 17:11:01 +01:00

265 lines
10 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-Action-method-constructor'><span id='Ext-Action'>/**
</span></span> * @class Ext.Action
* &lt;p&gt;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}
* and {@link Ext.menu.Menu} components).&lt;/p&gt;
* &lt;p&gt;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).&lt;/p&gt;
* Example usage:&lt;br&gt;
* &lt;pre&gt;&lt;code&gt;
// 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',
{@link #handler}: function(){
Ext.Msg.alert('Click', 'You did something.');
},
{@link #iconCls}: 'do-something',
{@link #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');
&lt;/code&gt;&lt;/pre&gt;
* @constructor
* @param {Object} config The configuration options
*/
Ext.Action = Ext.extend(Object, {
<span id='Ext-Action-cfg-text'> /**
</span> * @cfg {String} text The text to set for all components using this action (defaults to '').
*/
<span id='Ext-Action-cfg-iconCls'> /**
</span> * @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 '').
* &lt;p&gt;An example of specifying a custom icon class would be something like:
* &lt;/p&gt;&lt;pre&gt;&lt;code&gt;
// 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; }
&lt;/code&gt;&lt;/pre&gt;
*/
<span id='Ext-Action-cfg-disabled'> /**
</span> * @cfg {Boolean} disabled True to disable all components using this action, false to enable them (defaults to false).
*/
<span id='Ext-Action-cfg-hidden'> /**
</span> * @cfg {Boolean} hidden True to hide all components using this action, false to show them (defaults to false).
*/
<span id='Ext-Action-cfg-handler'> /**
</span> * @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).
*/
<span id='Ext-Action-cfg-itemId'> /**
</span> * @cfg {String} itemId
* See {@link Ext.Component}.{@link Ext.Component#itemId itemId}.
*/
<span id='Ext-Action-cfg-scope'> /**
</span> * @cfg {Object} scope The scope (&lt;tt&gt;&lt;b&gt;this&lt;/b&gt;&lt;/tt&gt; reference) in which the
* &lt;code&gt;{@link #handler}&lt;/code&gt; is executed. Defaults to this Button.
*/
constructor : function(config){
this.initialConfig = config;
this.itemId = config.itemId = (config.itemId || config.id || Ext.id());
this.items = [];
},
<span id='Ext-Action-property-isAction'> // private
</span> isAction : true,
<span id='Ext-Action-method-setText'> /**
</span> * Sets the text to be displayed by all components using this action.
* @param {String} text The text to display
*/
setText : function(text){
this.initialConfig.text = text;
this.callEach('setText', [text]);
},
<span id='Ext-Action-method-getText'> /**
</span> * Gets the text currently displayed by all components using this action.
*/
getText : function(){
return this.initialConfig.text;
},
<span id='Ext-Action-method-setIconClass'> /**
</span> * 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.
* @param {String} cls The CSS class supplying the icon image
*/
setIconClass : function(cls){
this.initialConfig.iconCls = cls;
this.callEach('setIconClass', [cls]);
},
<span id='Ext-Action-method-getIconClass'> /**
</span> * Gets the icon CSS class currently used by all components using this action.
*/
getIconClass : function(){
return this.initialConfig.iconCls;
},
<span id='Ext-Action-method-setDisabled'> /**
</span> * Sets the disabled state of all components using this action. Shortcut method
* for {@link #enable} and {@link #disable}.
* @param {Boolean} disabled True to disable the component, false to enable it
*/
setDisabled : function(v){
this.initialConfig.disabled = v;
this.callEach('setDisabled', [v]);
},
<span id='Ext-Action-method-enable'> /**
</span> * Enables all components using this action.
*/
enable : function(){
this.setDisabled(false);
},
<span id='Ext-Action-method-disable'> /**
</span> * Disables all components using this action.
*/
disable : function(){
this.setDisabled(true);
},
<span id='Ext-Action-method-isDisabled'> /**
</span> * Returns true if the components using this action are currently disabled, else returns false.
*/
isDisabled : function(){
return this.initialConfig.disabled;
},
<span id='Ext-Action-method-setHidden'> /**
</span> * Sets the hidden state of all components using this action. Shortcut method
* for &lt;code&gt;{@link #hide}&lt;/code&gt; and &lt;code&gt;{@link #show}&lt;/code&gt;.
* @param {Boolean} hidden True to hide the component, false to show it
*/
setHidden : function(v){
this.initialConfig.hidden = v;
this.callEach('setVisible', [!v]);
},
<span id='Ext-Action-method-show'> /**
</span> * Shows all components using this action.
*/
show : function(){
this.setHidden(false);
},
<span id='Ext-Action-method-hide'> /**
</span> * Hides all components using this action.
*/
hide : function(){
this.setHidden(true);
},
<span id='Ext-Action-method-isHidden'> /**
</span> * Returns true if the components using this action are currently hidden, else returns false.
*/
isHidden : function(){
return this.initialConfig.hidden;
},
<span id='Ext-Action-method-setHandler'> /**
</span> * Sets the function that will be called by each Component using this action when its primary event is triggered.
* @param {Function} fn The function that will be invoked by the action's components. The function
* will be called with no arguments.
* @param {Object} scope The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to the Component firing the event.
*/
setHandler : function(fn, scope){
this.initialConfig.handler = fn;
this.initialConfig.scope = scope;
this.callEach('setHandler', [fn, scope]);
},
<span id='Ext-Action-method-each'> /**
</span> * 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 (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to the Component.
*/
each : function(fn, scope){
Ext.each(this.items, fn, scope);
},
<span id='Ext-Action-method-callEach'> // private
</span> callEach : function(fnName, args){
var cs = this.items;
for(var i = 0, len = cs.length; i &lt; len; i++){
cs[i][fnName].apply(cs[i], args);
}
},
<span id='Ext-Action-method-addComponent'> // private
</span> addComponent : function(comp){
this.items.push(comp);
comp.on('destroy', this.removeComponent, this);
},
<span id='Ext-Action-method-removeComponent'> // private
</span> removeComponent : function(comp){
this.items.remove(comp);
},
<span id='Ext-Action-method-execute'> /**
</span> * Executes this action manually using the handler function specified in the original config object
* or the handler function set with &lt;code&gt;{@link #setHandler}&lt;/code&gt;. Any arguments passed to this
* function will be passed on to the handler function.
* @param {Mixed...} args Variable number of arguments passed to the handler function
*/
execute : function(){
this.initialConfig.handler.apply(this.initialConfig.scope || window, arguments);
}
});
</pre>
</body>
</html>