X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..f562e4c6e5fac7bcb445985b99acbea4d706e6f0:/docs/source/Action.html?ds=sidebyside diff --git a/docs/source/Action.html b/docs/source/Action.html index 8be40ba5..4784e273 100644 --- a/docs/source/Action.html +++ b/docs/source/Action.html @@ -1,630 +1,288 @@ - -
-/** - * @class Ext.form.Action - *The subclasses of this class provide actions to perform upon {@link Ext.form.BasicForm Form}s.
- *Instances of this class are only created by a {@link Ext.form.BasicForm Form} when - * the Form needs to perform an action such as submit or load. The Configuration options - * listed for this class are set through the Form's action methods: {@link Ext.form.BasicForm#submit submit}, - * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}
- *The instance of Action which performed the action is passed to the success - * and failure callbacks of the Form's action methods ({@link Ext.form.BasicForm#submit submit}, - * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}), - * and to the {@link Ext.form.BasicForm#actioncomplete actioncomplete} and - * {@link Ext.form.BasicForm#actionfailed actionfailed} event handlers.
- */ -Ext.form.Action = function(form, options){ - this.form = form; - this.options = options || {}; -}; + + + + +The source code + + + + + + +/** + * @class Ext.Action + * <p>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.Toolbar}, {@link Ext.button.Button} + * and {@link Ext.menu.Menu} components).</p> + * <p>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.</p> + * <p>Any Component that is to be configured with an Action must also support + * the following methods:<ul> + * <li><code>setText(string)</code></li> + * <li><code>setIconCls(string)</code></li> + * <li><code>setDisabled(boolean)</code></li> + * <li><code>setVisible(boolean)</code></li> + * <li><code>setHandler(function)</code></li></ul></p> + * <p>This allows the Action to control its associated Components.</p> + * Example usage:<br> + * <pre><code> +// 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' +}); -/** - * Failure type returned when client side validation of the Form fails - * thus aborting a submit action. Client side validation is performed unless - * {@link #clientValidation} is explicitly set to false. - * @type {String} - * @static - */ -Ext.form.Action.CLIENT_INVALID = 'client'; -/** - *Failure type returned when server side processing fails and the {@link #result}'s - * success property is set to false.
- *In the case of a form submission, field-specific error messages may be returned in the - * {@link #result}'s errors property.
- * @type {String} - * @static - */ -Ext.form.Action.SERVER_INVALID = 'server'; -/** - * Failure type returned when a communication error happens when attempting - * to send a request to the remote server. The {@link #response} may be examined to - * provide further information. - * @type {String} - * @static - */ -Ext.form.Action.CONNECT_FAILURE = 'connect'; -/** - * Failure type returned when the response's success - * property is set to false, or no field values are returned in the response's - * data property. - * @type {String} - * @static - */ -Ext.form.Action.LOAD_FAILURE = 'load'; +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() +}); -Ext.form.Action.prototype = { -/** - * @cfg {String} url The URL that the Action is to invoke. - */ -/** - * @cfg {Boolean} reset When set to true, causes the Form to be - * {@link Ext.form.BasicForm.reset reset} on Action success. If specified, this happens - * before the {@link #success} callback is called and before the Form's - * {@link Ext.form.BasicForm.actioncomplete actioncomplete} event fires. - */ -/** - * @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the - * {@link Ext.form.BasicForm}'s method, or if that is not specified, the underlying DOM form's method. - */ -/** - * @cfg {Mixed} paramsExtra parameter values to pass. These are added to the Form's - * {@link Ext.form.BasicForm#baseParams} and passed to the specified URL along with the Form's - * input fields.
- *Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.
- */ -/** - * @cfg {Number} timeout The number of seconds to wait for a server response before - * failing with the {@link #failureType} as {@link #Action.CONNECT_FAILURE}. If not specified, - * defaults to the configured {@link Ext.form.BasicForm#timeout timeout} of the - * {@link Ext.form.BasicForm form}. - */ -/** - * @cfg {Function} success The function to call when a valid success return packet is recieved. - * The function is passed the following parameters:
-var fp = new Ext.form.FormPanel({
-...
-buttons: [{
- text: 'Save',
- formBind: true,
- handler: function(){
- if(fp.getForm().isValid()){
- fp.getForm().submit({
- url: 'form-submit.php',
- waitMsg: 'Submitting your data...',
- success: function(form, action){
- // server responded with success = true
- var result = action.{@link #result};
- },
- failure: function(form, action){
- if (action.{@link #failureType} === Ext.form.Action.{@link #CONNECT_FAILURE}) {
- Ext.Msg.alert('Error',
- 'Status:'+action.{@link #response}.status+': '+
- action.{@link #response}.statusText);
- }
- if (action.failureType === Ext.form.Action.{@link #SERVER_INVALID}){
- // server responded with success = false
- Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
- }
- }
- });
- }
- }
-},{
- text: 'Reset',
- handler: function(){
- fp.getForm().reset();
- }
-}]
- *
- * @property failureType
- * @type {String}
- */
- /**
- * The XMLHttpRequest object used to perform the action.
- * @property response
- * @type {Object}
- */
- /**
- * The decoded response object containing a boolean success property and
- * other, action-specific properties.
- * @property result
- * @type {Object}
+// Reference an Action through a container using the itemId
+var btn = panel.getComponent('myAction');
+var aRef = btn.baseAction;
+aRef.setText('New text');
+</code></pre>
*/
+Ext.define('Ext.Action', {
- // interface method
- run : function(options){
+ /* Begin Definitions */
- },
+ /* End Definitions */
- // interface method
- success : function(response){
+ /**
+ * @cfg {String} [text='']
+ * The text to set for all components configured by this Action.
+ */
+ /**
+ * @cfg {String} [iconCls='']
+ * The CSS class selector that specifies a background image to be used as the header icon for
+ * all components configured by this Action.
+ * <p>An example of specifying a custom icon class would be something like:
+ * </p><pre><code>
+// 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; }
+</code></pre>
+ */
+ /**
+ * @cfg {Boolean} [disabled=false]
+ * True to disable all components configured by this Action, false to enable them.
+ */
+ * @cfg {Boolean} [hidden=false]
+ * True to hide all components configured by this Action, false to show them.
+ */
+ /**
+ * @cfg {Function} handler
+ * The function that will be invoked by each component tied to this Action
+ * when the component's primary event is triggered.
+ */
+ /**
+ * @cfg {String} itemId
+ * 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 the browser window.
+ */
+ /**
+ * Creates new Action.
+ * @param {Object} config Config object.
+ */
+ constructor : function(config){
+ this.initialConfig = config;
+ this.itemId = config.itemId = (config.itemId || config.id || Ext.id());
+ this.items = [];
},
- // interface method
- handleResponse : function(response){
+ // private
+ isAction : true,
+ /**
+ * Sets the text to be displayed by all components configured by this Action.
+ * @param {String} text The text to display
+ */
+ setText : function(text){
+ this.initialConfig.text = text;
+ this.callEach('setText', [text]);
},
- // default connection failure
- failure : function(response){
- this.response = response;
- this.failureType = Ext.form.Action.CONNECT_FAILURE;
- this.form.afterAction(this, false);
+ /**
+ * Gets the text currently displayed by all components configured by this Action.
+ */
+ getText : function(){
+ return this.initialConfig.text;
},
- // private
- // shared code among all Actions to validate that there was a response
- // with either responseText or responseXml
- processResponse : function(response){
- this.response = response;
- if(!response.responseText && !response.responseXML){
- return true;
- }
- this.result = this.handleResponse(response);
- return this.result;
+ /**
+ * 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
+ */
+ setIconCls : function(cls){
+ this.initialConfig.iconCls = cls;
+ this.callEach('setIconCls', [cls]);
},
- // utility functions used internally
- getUrl : function(appendParams){
- var url = this.options.url || this.form.url || this.form.el.dom.action;
- if(appendParams){
- var p = this.getParams();
- if(p){
- url = Ext.urlAppend(url, p);
- }
- }
- return url;
+ /**
+ * Gets the icon CSS class currently used by all components configured by this Action.
+ */
+ getIconCls : function(){
+ return this.initialConfig.iconCls;
},
- // private
- getMethod : function(){
- return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
+ /**
+ * 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
+ */
+ setDisabled : function(v){
+ this.initialConfig.disabled = v;
+ this.callEach('setDisabled', [v]);
},
- // private
- getParams : function(){
- var bp = this.form.baseParams;
- var p = this.options.params;
- if(p){
- if(typeof p == "object"){
- p = Ext.urlEncode(Ext.applyIf(p, bp));
- }else if(typeof p == 'string' && bp){
- p += '&' + Ext.urlEncode(bp);
- }
- }else if(bp){
- p = Ext.urlEncode(bp);
- }
- return p;
+ /**
+ * Enables all components configured by this Action.
+ */
+ enable : function(){
+ this.setDisabled(false);
},
- // private
- createCallback : function(opts){
- var opts = opts || {};
- return {
- success: this.success,
- failure: this.failure,
- scope: this,
- timeout: (opts.timeout*1000) || (this.form.timeout*1000),
- upload: this.form.fileUpload ? this.success : undefined
- };
- }
-};
-
-/**
- * @class Ext.form.Action.Submit
- * @extends Ext.form.Action
- * A class which handles submission of data from {@link Ext.form.BasicForm Form}s - * and processes the returned response.
- *Instances of this class are only created by a {@link Ext.form.BasicForm Form} when - * {@link Ext.form.BasicForm#submit submit}ting.
- *Response Packet Criteria
- *A response packet may contain: - *
success
property : Boolean
- * success
property is required.errors
property : Object
- * errors
property,
- * which is optional, contains error messages for invalid fields.JSON Packets
- *By default, response packets are assumed to be JSON, so a typical response - * packet may look like this:
-{
- success: false,
- errors: {
- clientCode: "Client not found",
- portOfLoading: "This field must not be null"
- }
-}
- * Other data may be placed into the response for processing by the {@link Ext.form.BasicForm}'s callback - * or event handler methods. The object decoded from this JSON is available in the - * {@link Ext.form.Action#result result} property.
- *Alternatively, if an {@link #errorReader} is specified as an {@link Ext.data.XmlReader XmlReader}:
- errorReader: new Ext.data.XmlReader({
- record : 'field',
- success: '@success'
- }, [
- 'id', 'msg'
- ]
- )
-
- * then the results may be sent back in XML format:
-<?xml version="1.0" encoding="UTF-8"?>
-<message success="false">
-<errors>
- <field>
- <id>clientCode</id>
- <msg><![CDATA[Code not found. <br /><i>This is a test validation message from the server </i>]]></msg>
- </field>
- <field>
- <id>portOfLoading</id>
- <msg><![CDATA[Port not found. <br /><i>This is a test validation message from the server </i>]]></msg>
- </field>
-</errors>
-</message>
-
- * Other elements may be placed into the response XML for processing by the {@link Ext.form.BasicForm}'s callback - * or event handler methods. The XML document is available in the {@link #errorReader}'s {@link Ext.data.XmlReader#xmlData xmlData} property.
- */ -Ext.form.Action.Submit = function(form, options){ - Ext.form.Action.Submit.superclass.constructor.call(this, form, options); -}; + /** + * Disables all components configured by this Action. + */ + disable : function(){ + this.setDisabled(true); + }, -Ext.extend(Ext.form.Action.Submit, Ext.form.Action, { - /** - * @cfg {Ext.data.DataReader} errorReaderOptional. JSON is interpreted with - * no need for an errorReader.
- *A Reader which reads a single record from the returned data. The DataReader's - * success property specifies how submission success is determined. The Record's - * data provides the error messages to apply to any invalid form Fields.
+ /** + * Returns true if the components using this Action are currently disabled, else returns false. */ - /** - * @cfg {boolean} clientValidation Determines whether a Form's fields are validated - * in a final call to {@link Ext.form.BasicForm#isValid isValid} prior to submission. - * Pass false in the Form's submit options to prevent this. If not defined, pre-submission field validation - * is performed. + isDisabled : function(){ + return this.initialConfig.disabled; + }, + + /** + * Sets the hidden state of all components configured by this Action. Shortcut method + * for <code>{@link #hide}</code> and <code>{@link #show}</code>. + * @param {Boolean} hidden True to hide the component, false to show it */ - type : 'submit', + setHidden : function(v){ + this.initialConfig.hidden = v; + this.callEach('setVisible', [!v]); + }, - // private - run : function(){ - var o = this.options; - var method = this.getMethod(); - var isGet = method == 'GET'; - if(o.clientValidation === false || this.form.isValid()){ - Ext.Ajax.request(Ext.apply(this.createCallback(o), { - form:this.form.el.dom, - url:this.getUrl(isGet), - method: method, - headers: o.headers, - params:!isGet ? this.getParams() : null, - isUpload: this.form.fileUpload - })); - }else if (o.clientValidation !== false){ // client validation failed - this.failureType = Ext.form.Action.CLIENT_INVALID; - this.form.afterAction(this, false); - } + /** + * Shows all components configured by this Action. + */ + show : function(){ + this.setHidden(false); }, - // private - success : function(response){ - var result = this.processResponse(response); - if(result === true || result.success){ - this.form.afterAction(this, true); - return; - } - if(result.errors){ - this.form.markInvalid(result.errors); - this.failureType = Ext.form.Action.SERVER_INVALID; - } - this.form.afterAction(this, false); + /** + * Hides all components configured by this Action. + */ + hide : function(){ + this.setHidden(true); }, - // private - handleResponse : function(response){ - if(this.form.errorReader){ - var rs = this.form.errorReader.read(response); - var errors = []; - if(rs.records){ - for(var i = 0, len = rs.records.length; i < len; i++) { - var r = rs.records[i]; - errors[i] = r.data; - } - } - if(errors.length < 1){ - errors = null; - } - return { - success : rs.success, - errors : errors - }; - } - return Ext.decode(response.responseText); - } -}); + /** + * Returns true if the components configured by this Action are currently hidden, else returns false. + */ + isHidden : function(){ + return this.initialConfig.hidden; + }, + /** + * 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 (<code>this</code> 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]); + }, -/** - * @class Ext.form.Action.Load - * @extends Ext.form.Action - *A class which handles loading of data from a server into the Fields of an {@link Ext.form.BasicForm}.
- *Instances of this class are only created by a {@link Ext.form.BasicForm Form} when - * {@link Ext.form.BasicForm#load load}ing.
- *Response Packet Criteria
- *A response packet must contain: - *
success
property : Booleandata
property : Objectdata
property contains the values of Fields to load.
- * The individual value object for each Field is passed to the Field's
- * {@link Ext.form.Field#setValue setValue} method.JSON Packets
- *By default, response packets are assumed to be JSON, so for the following form load call:
-var myFormPanel = new Ext.form.FormPanel({
- title: 'Client and routing info',
- items: [{
- fieldLabel: 'Client',
- name: 'clientName'
- }, {
- fieldLabel: 'Port of loading',
- name: 'portOfLoading'
- }, {
- fieldLabel: 'Port of discharge',
- name: 'portOfDischarge'
- }]
-});
-myFormPanel.{@link Ext.form.FormPanel#getForm getForm}().{@link Ext.form.BasicForm#load load}({
- url: '/getRoutingInfo.php',
- params: {
- consignmentRef: myConsignmentRef
+ /**
+ * 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 (<code>this</code> reference) in which the function is executed. Defaults to the Component.
+ */
+ each : function(fn, scope){
+ Ext.each(this.items, fn, scope);
},
- failure: function(form, action() {
- Ext.Msg.alert("Load failed", action.result.errorMessage);
- }
-});
-
- * a success response packet may look like this:
-{
- success: true,
- data: {
- clientName: "Fred. Olsen Lines",
- portOfLoading: "FXT",
- portOfDischarge: "OSL"
- }
-}
- * while a failure response packet may look like this:
-{
- success: false,
- errorMessage: "Consignment reference not found"
-}
- * Other data may be placed into the response for processing the {@link Ext.form.BasicForm Form}'s - * callback or event handler methods. The object decoded from this JSON is available in the - * {@link Ext.form.Action#result result} property.
- */ -Ext.form.Action.Load = function(form, options){ - Ext.form.Action.Load.superclass.constructor.call(this, form, options); - this.reader = this.form.reader; -}; -Ext.extend(Ext.form.Action.Load, Ext.form.Action, { // private - type : 'load', + callEach : function(fnName, args){ + var items = this.items, + i = 0, + len = items.length; - // private - run : function(){ - Ext.Ajax.request(Ext.apply( - this.createCallback(this.options), { - method:this.getMethod(), - url:this.getUrl(false), - headers: this.options.headers, - params:this.getParams() - })); + for(; i < len; i++){ + items[i][fnName].apply(items[i], args); + } }, // private - success : function(response){ - var result = this.processResponse(response); - if(result === true || !result.success || !result.data){ - this.failureType = Ext.form.Action.LOAD_FAILURE; - this.form.afterAction(this, false); - return; - } - this.form.clearInvalid(); - this.form.setValues(result.data); - this.form.afterAction(this, true); + addComponent : function(comp){ + this.items.push(comp); + comp.on('destroy', this.removeComponent, this); }, // private - handleResponse : function(response){ - if(this.form.reader){ - var rs = this.form.reader.read(response); - var data = rs.records && rs.records[0] ? rs.records[0].data : null; - return { - success : rs.success, - data : data - }; - } - return Ext.decode(response.responseText); - } -}); - - - -/** - * @class Ext.form.Action.DirectLoad - * @extends Ext.form.Action.Load - * Provides Ext.direct support for loading form data. This example illustrates usage - * of Ext.Direct to load a submit a form through Ext.Direct. - *
-var myFormPanel = new Ext.form.FormPanel({
- // configs for FormPanel
- title: 'Basic Information',
- border: false,
- padding: 10,
- buttons:[{
- text: 'Submit',
- handler: function(){
- basicInfo.getForm().submit({
- params: {
- uid: 5
- }
- });
- }
- }],
-
- // configs apply to child items
- defaults: {anchor: '100%'},
- defaultType: 'textfield',
- items: [
- // form fields go here
- ],
-
- // configs for BasicForm
- api: {
- load: Profile.getBasicInfo,
- // The server-side must mark the submit handler as a 'formHandler'
- submit: Profile.updateBasicInfo
- },
- paramOrder: ['uid']
-});
-
-// load the form
-myFormPanel.getForm().load({
- params: {
- uid: 5
- }
-});
- *
- */
-Ext.form.Action.DirectLoad = Ext.extend(Ext.form.Action.Load, {
- constructor: function(form, opts) {
- Ext.form.Action.DirectLoad.superclass.constructor.call(this, form, opts);
- },
- type: 'directload',
-
- run : function(){
- var args = this.getParams();
- args.push(this.success, this);
- this.form.api.load.apply(window, args);
- },
-
- getParams: function() {
- var buf = [], o = {};
- var bp = this.form.baseParams;
- var p = this.options.params;
- Ext.apply(o, p, bp);
- var paramOrder = this.form.paramOrder;
- if(paramOrder){
- for(var i = 0, len = paramOrder.length; i < len; i++){
- buf.push(o[paramOrder[i]]);
- }
- }else if(this.form.paramsAsHash){
- buf.push(o);
- }
- return buf;
+ removeComponent : function(comp){
+ Ext.Array.remove(this.items, comp);
},
- // Direct actions have already been processed and therefore
- // we can directly set the result; Direct Actions do not have
- // a this.response property.
- processResponse: function(result) {
- this.result = result;
- return result;
- }
-});
-/**
- * @class Ext.form.Action.DirectSubmit
- * @extends Ext.form.Action.Submit
- * Provides Ext.direct support for submitting form data.
- * See {@link Ext.form.Action.DirectLoad}.
- */
-Ext.form.Action.DirectSubmit = Ext.extend(Ext.form.Action.Submit, {
- constructor: function(form, opts) {
- Ext.form.Action.DirectSubmit.superclass.constructor.call(this, form, opts);
- },
- type: 'directsubmit',
- // override of Submit
- run : function(){
- var o = this.options;
- if(o.clientValidation === false || this.form.isValid()){
- // tag on any additional params to be posted in the
- // form scope
- this.success.params = this.getParams();
- this.form.api.submit(this.form.el.dom, this.success, this);
- }else if (o.clientValidation !== false){ // client validation failed
- this.failureType = Ext.form.Action.CLIENT_INVALID;
- this.form.afterAction(this, false);
- }
- },
-
- getParams: function() {
- var o = {};
- var bp = this.form.baseParams;
- var p = this.options.params;
- Ext.apply(o, p, bp);
- return o;
- },
- // Direct actions have already been processed and therefore
- // we can directly set the result; Direct Actions do not have
- // a this.response property.
- processResponse: function(result) {
- this.result = result;
- return result;
+ /**
+ * Executes this Action manually using the handler function specified in the original config object
+ * or the handler function set with <code>{@link #setHandler}</code>. Any arguments passed to this
+ * function will be passed on to the handler function.
+ * @param {Object...} args (optional) Variable number of arguments passed to the handler function
+ */
+ execute : function(){
+ this.initialConfig.handler.apply(this.initialConfig.scope || Ext.global, arguments);
}
});
-
-
-Ext.form.Action.ACTION_TYPES = {
- 'load' : Ext.form.Action.Load,
- 'submit' : Ext.form.Action.Submit,
- 'directload': Ext.form.Action.DirectLoad,
- 'directsubmit': Ext.form.Action.DirectSubmit
-};
-
-
-
\ No newline at end of file
+
+
+