-<html>\r
-<head>\r
- <title>The source code</title>\r
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
-</head>\r
-<body onload="prettyPrint();">\r
- <pre class="prettyprint lang-js"><div id="cls-Ext.Action"></div>/**\r
- * @class Ext.Action\r
- * <p>An Action is a piece of reusable functionality that can be abstracted out of any particular component so that it\r
- * can be usefully shared among multiple components. Actions let you share handlers, configuration options and UI\r
- * updates across any components that support the Action interface (primarily {@link Ext.Toolbar}, {@link Ext.Button}\r
- * and {@link Ext.menu.Menu} components).</p>\r
- * <p>Aside from supporting the config object interface, any component that needs to use Actions must also support\r
- * the following method list, as these will be called as needed by the Action class: setText(string), setIconCls(string),\r
- * setDisabled(boolean), setVisible(boolean) and setHandler(function).</p>\r
- * Example usage:<br>\r
- * <pre><code>\r
-// Define the shared action. Each component below will have the same\r
-// display text and icon, and will display the same message on click.\r
-var action = new Ext.Action({\r
- {@link #text}: 'Do something',\r
- {@link #handler}: function(){\r
- Ext.Msg.alert('Click', 'You did something.');\r
- },\r
- {@link #iconCls}: 'do-something',\r
- {@link #itemId}: 'myAction'\r
-});\r
+<html>
+<head>
+ <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>
+</head>
+<body onload="prettyPrint();">
+ <pre class="prettyprint lang-js">/*!
+ * Ext JS Library 3.0.3
+ * Copyright(c) 2006-2009 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+<div id="cls-Ext.form.Action"></div>/**\r
+ * @class Ext.form.Action\r
+ * <p>The subclasses of this class provide actions to perform upon {@link Ext.form.BasicForm Form}s.</p>\r
+ * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when\r
+ * the Form needs to perform an action such as submit or load. The Configuration options\r
+ * listed for this class are set through the Form's action methods: {@link Ext.form.BasicForm#submit submit},\r
+ * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}</p>\r
+ * <p>The instance of Action which performed the action is passed to the success\r
+ * and failure callbacks of the Form's action methods ({@link Ext.form.BasicForm#submit submit},\r
+ * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}),\r
+ * and to the {@link Ext.form.BasicForm#actioncomplete actioncomplete} and\r
+ * {@link Ext.form.BasicForm#actionfailed actionfailed} event handlers.</p>\r
+ */\r
+Ext.form.Action = function(form, options){\r
+ this.form = form;\r
+ this.options = options || {};\r
+};\r
\r
-var panel = new Ext.Panel({\r
- title: 'Actions',\r
- width: 500,\r
- height: 300,\r
- tbar: [\r
- // Add the action directly to a toolbar as a menu button\r
- action,\r
- {\r
- text: 'Action Menu',\r
- // Add the action to a menu as a text item\r
- menu: [action]\r
- }\r
- ],\r
- items: [\r
- // Add the action to the panel body as a standard button\r
- new Ext.Button(action)\r
- ],\r
- renderTo: Ext.getBody()\r
-});\r
+<div id="prop-Ext.form.Action-CLIENT_INVALID"></div>/**\r
+ * Failure type returned when client side validation of the Form fails\r
+ * thus aborting a submit action. Client side validation is performed unless\r
+ * {@link #clientValidation} is explicitly set to <tt>false</tt>.\r
+ * @type {String}\r
+ * @static\r
+ */\r
+Ext.form.Action.CLIENT_INVALID = 'client';\r
+<div id="prop-Ext.form.Action-SERVER_INVALID"></div>/**\r
+ * <p>Failure type returned when server side processing fails and the {@link #result}'s\r
+ * <tt style="font-weight:bold">success</tt> property is set to <tt>false</tt>.</p>\r
+ * <p>In the case of a form submission, field-specific error messages may be returned in the\r
+ * {@link #result}'s <tt style="font-weight:bold">errors</tt> property.</p>\r
+ * @type {String}\r
+ * @static\r
+ */\r
+Ext.form.Action.SERVER_INVALID = 'server';\r
+<div id="prop-Ext.form.Action-CONNECT_FAILURE"></div>/**\r
+ * Failure type returned when a communication error happens when attempting\r
+ * to send a request to the remote server. The {@link #response} may be examined to\r
+ * provide further information.\r
+ * @type {String}\r
+ * @static\r
+ */\r
+Ext.form.Action.CONNECT_FAILURE = 'connect';\r
+<div id="prop-Ext.form.Action-LOAD_FAILURE"></div>/**\r
+ * Failure type returned when the response's <tt style="font-weight:bold">success</tt>\r
+ * property is set to <tt>false</tt>, or no field values are returned in the response's\r
+ * <tt style="font-weight:bold">data</tt> property.\r
+ * @type {String}\r
+ * @static\r
+ */\r
+Ext.form.Action.LOAD_FAILURE = 'load';\r
\r
-// Change the text for all components using the action\r
-action.setText('Something else');\r
+Ext.form.Action.prototype = {\r
+<div id="cfg-Ext.form.Action-url"></div>/**\r
+ * @cfg {String} url The URL that the Action is to invoke.\r
+ */\r
+<div id="cfg-Ext.form.Action-reset"></div>/**\r
+ * @cfg {Boolean} reset When set to <tt><b>true</b></tt>, causes the Form to be\r
+ * {@link Ext.form.BasicForm.reset reset} on Action success. If specified, this happens\r
+ * <b>before</b> the {@link #success} callback is called and before the Form's\r
+ * {@link Ext.form.BasicForm.actioncomplete actioncomplete} event fires.\r
+ */\r
+<div id="cfg-Ext.form.Action-method"></div>/**\r
+ * @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the\r
+ * {@link Ext.form.BasicForm}'s method, or if that is not specified, the underlying DOM form's method.\r
+ */\r
+<div id="cfg-Ext.form.Action-params"></div>/**\r
+ * @cfg {Mixed} params <p>Extra parameter values to pass. These are added to the Form's\r
+ * {@link Ext.form.BasicForm#baseParams} and passed to the specified URL along with the Form's\r
+ * input fields.</p>\r
+ * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>\r
+ */\r
+<div id="cfg-Ext.form.Action-timeout"></div>/**\r
+ * @cfg {Number} timeout The number of seconds to wait for a server response before\r
+ * failing with the {@link #failureType} as {@link #Action.CONNECT_FAILURE}. If not specified,\r
+ * defaults to the configured <tt>{@link Ext.form.BasicForm#timeout timeout}</tt> of the\r
+ * {@link Ext.form.BasicForm form}.\r
+ */\r
+<div id="cfg-Ext.form.Action-success"></div>/**\r
+ * @cfg {Function} success The function to call when a valid success return packet is recieved.\r
+ * The function is passed the following parameters:<ul class="mdetail-params">\r
+ * <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>\r
+ * <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. The {@link #result}\r
+ * property of this object may be examined to perform custom postprocessing.</div></li>\r
+ * </ul>\r
+ */\r
+<div id="cfg-Ext.form.Action-failure"></div>/**\r
+ * @cfg {Function} failure The function to call when a failure packet was recieved, or when an\r
+ * error ocurred in the Ajax communication.\r
+ * The function is passed the following parameters:<ul class="mdetail-params">\r
+ * <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>\r
+ * <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. If an Ajax\r
+ * error ocurred, the failure type will be in {@link #failureType}. The {@link #result}\r
+ * property of this object may be examined to perform custom postprocessing.</div></li>\r
+ * </ul>\r
+ */\r
+<div id="cfg-Ext.form.Action-scope"></div>/**\r
+ * @cfg {Object} scope The scope in which to call the callback functions (The <tt>this</tt> reference\r
+ * for the callback functions).\r
+ */\r
+<div id="cfg-Ext.form.Action-waitMsg"></div>/**\r
+ * @cfg {String} waitMsg The message to be displayed by a call to {@link Ext.MessageBox#wait}\r
+ * during the time the action is being processed.\r
+ */\r
+<div id="cfg-Ext.form.Action-waitTitle"></div>/**\r
+ * @cfg {String} waitTitle The title to be displayed by a call to {@link Ext.MessageBox#wait}\r
+ * during the time the action is being processed.\r
+ */\r
\r
-// Reference an action through a container using the itemId\r
-var btn = panel.getComponent('myAction');\r
-var aRef = btn.baseAction;\r
-aRef.setText('New text');\r
-</code></pre>\r
- * @constructor\r
- * @param {Object} config The configuration options\r
+<div id="prop-Ext.form.Action-type"></div>/**\r
+ * The type of action this Action instance performs.\r
+ * Currently only "submit" and "load" are supported.\r
+ * @type {String}\r
+ */\r
+ type : 'default',\r
+<div id="prop-Ext.form.Action-failureType"></div>/**\r
+ * The type of failure detected will be one of these: {@link #CLIENT_INVALID},\r
+ * {@link #SERVER_INVALID}, {@link #CONNECT_FAILURE}, or {@link #LOAD_FAILURE}. Usage:\r
+ * <pre><code>\r
+var fp = new Ext.form.FormPanel({\r
+...\r
+buttons: [{\r
+ text: 'Save',\r
+ formBind: true,\r
+ handler: function(){\r
+ if(fp.getForm().isValid()){\r
+ fp.getForm().submit({\r
+ url: 'form-submit.php',\r
+ waitMsg: 'Submitting your data...',\r
+ success: function(form, action){\r
+ // server responded with success = true\r
+ var result = action.{@link #result};\r
+ },\r
+ failure: function(form, action){\r
+ if (action.{@link #failureType} === Ext.form.Action.{@link #CONNECT_FAILURE}) {\r
+ Ext.Msg.alert('Error',\r
+ 'Status:'+action.{@link #response}.status+': '+\r
+ action.{@link #response}.statusText);\r
+ }\r
+ if (action.failureType === Ext.form.Action.{@link #SERVER_INVALID}){\r
+ // server responded with success = false\r
+ Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);\r
+ }\r
+ }\r
+ });\r
+ }\r
+ }\r
+},{\r
+ text: 'Reset',\r
+ handler: function(){\r
+ fp.getForm().reset();\r
+ }\r
+}]\r
+ * </code></pre>\r
+ * @property failureType\r
+ * @type {String}\r
+ */\r
+ <div id="prop-Ext.form.Action-response"></div>/**\r
+ * The XMLHttpRequest object used to perform the action.\r
+ * @property response\r
+ * @type {Object}\r
+ */\r
+ <div id="prop-Ext.form.Action-result"></div>/**\r
+ * The decoded response object containing a boolean <tt style="font-weight:bold">success</tt> property and\r
+ * other, action-specific properties.\r
+ * @property result\r
+ * @type {Object}\r
*/\r
-Ext.Action = function(config){\r
- this.initialConfig = config;\r
- this.itemId = config.itemId = (config.itemId || config.id || Ext.id());\r
- this.items = [];\r
-}\r
\r
-Ext.Action.prototype = {\r
- <div id="cfg-Ext.Action-text"></div>/**\r
- * @cfg {String} text The text to set for all components using this action (defaults to '').\r
- */\r
- <div id="cfg-Ext.Action-iconCls"></div>/**\r
- * @cfg {String} iconCls\r
- * The CSS class selector that specifies a background image to be used as the header icon for\r
- * all components using this action (defaults to '').\r
- * <p>An example of specifying a custom icon class would be something like:\r
- * </p><pre><code>\r
-// specify the property in the config for the class:\r
- ...\r
- iconCls: 'do-something'\r
-\r
-// css class that specifies background image to be used as the icon image:\r
-.do-something { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }\r
-</code></pre>\r
- */\r
- <div id="cfg-Ext.Action-disabled"></div>/**\r
- * @cfg {Boolean} disabled True to disable all components using this action, false to enable them (defaults to false).\r
- */\r
- <div id="cfg-Ext.Action-hidden"></div>/**\r
- * @cfg {Boolean} hidden True to hide all components using this action, false to show them (defaults to false).\r
- */\r
- <div id="cfg-Ext.Action-handler"></div>/**\r
- * @cfg {Function} handler The function that will be invoked by each component tied to this action\r
- * when the component's primary event is triggered (defaults to undefined).\r
- */\r
- <div id="cfg-Ext.Action-itemId"></div>/**\r
- * @cfg {String} itemId\r
- * See {@link Ext.Component}.{@link Ext.Component#itemId itemId}.\r
- */\r
- <div id="cfg-Ext.Action-scope"></div>/**\r
- * @cfg {Object} scope The scope in which the {@link #handler} function will execute.\r
- */\r
+ // interface method\r
+ run : function(options){\r
\r
- // private\r
- isAction : true,\r
+ },\r
+\r
+ // interface method\r
+ success : function(response){\r
\r
- <div id="method-Ext.Action-setText"></div>/**\r
- * Sets the text to be displayed by all components using this action.\r
- * @param {String} text The text to display\r
- */\r
- setText : function(text){\r
- this.initialConfig.text = text;\r
- this.callEach('setText', [text]);\r
},\r
\r
- <div id="method-Ext.Action-getText"></div>/**\r
- * Gets the text currently displayed by all components using this action.\r
- */\r
- getText : function(){\r
- return this.initialConfig.text;\r
+ // interface method\r
+ handleResponse : function(response){\r
+\r
},\r
\r
- <div id="method-Ext.Action-setIconClass"></div>/**\r
- * Sets the icon CSS class for all components using this action. The class should supply\r
- * a background image that will be used as the icon image.\r
- * @param {String} cls The CSS class supplying the icon image\r
- */\r
- setIconClass : function(cls){\r
- this.initialConfig.iconCls = cls;\r
- this.callEach('setIconClass', [cls]);\r
+ // default connection failure\r
+ failure : function(response){\r
+ this.response = response;\r
+ this.failureType = Ext.form.Action.CONNECT_FAILURE;\r
+ this.form.afterAction(this, false);\r
},\r
\r
- <div id="method-Ext.Action-getIconClass"></div>/**\r
- * Gets the icon CSS class currently used by all components using this action.\r
- */\r
- getIconClass : function(){\r
- return this.initialConfig.iconCls;\r
+ // private\r
+ // shared code among all Actions to validate that there was a response\r
+ // with either responseText or responseXml\r
+ processResponse : function(response){\r
+ this.response = response;\r
+ if(!response.responseText && !response.responseXML){\r
+ return true;\r
+ }\r
+ this.result = this.handleResponse(response);\r
+ return this.result;\r
},\r
\r
- <div id="method-Ext.Action-setDisabled"></div>/**\r
- * Sets the disabled state of all components using this action. Shortcut method\r
- * for {@link #enable} and {@link #disable}.\r
- * @param {Boolean} disabled True to disable the component, false to enable it\r
- */\r
- setDisabled : function(v){\r
- this.initialConfig.disabled = v;\r
- this.callEach('setDisabled', [v]);\r
+ // utility functions used internally\r
+ getUrl : function(appendParams){\r
+ var url = this.options.url || this.form.url || this.form.el.dom.action;\r
+ if(appendParams){\r
+ var p = this.getParams();\r
+ if(p){\r
+ url = Ext.urlAppend(url, p);\r
+ }\r
+ }\r
+ return url;\r
},\r
\r
- <div id="method-Ext.Action-enable"></div>/**\r
- * Enables all components using this action.\r
- */\r
- enable : function(){\r
- this.setDisabled(false);\r
+ // private\r
+ getMethod : function(){\r
+ return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();\r
},\r
\r
- <div id="method-Ext.Action-disable"></div>/**\r
- * Disables all components using this action.\r
- */\r
- disable : function(){\r
- this.setDisabled(true);\r
+ // private\r
+ getParams : function(){\r
+ var bp = this.form.baseParams;\r
+ var p = this.options.params;\r
+ if(p){\r
+ if(typeof p == "object"){\r
+ p = Ext.urlEncode(Ext.applyIf(p, bp));\r
+ }else if(typeof p == 'string' && bp){\r
+ p += '&' + Ext.urlEncode(bp);\r
+ }\r
+ }else if(bp){\r
+ p = Ext.urlEncode(bp);\r
+ }\r
+ return p;\r
},\r
\r
- <div id="method-Ext.Action-isDisabled"></div>/**\r
- * Returns true if the components using this action are currently disabled, else returns false. \r
+ // private\r
+ createCallback : function(opts){\r
+ var opts = opts || {};\r
+ return {\r
+ success: this.success,\r
+ failure: this.failure,\r
+ scope: this,\r
+ timeout: (opts.timeout*1000) || (this.form.timeout*1000),\r
+ upload: this.form.fileUpload ? this.success : undefined\r
+ };\r
+ }\r
+};\r
+\r
+<div id="cls-Ext.form.Action.Submit"></div>/**\r
+ * @class Ext.form.Action.Submit\r
+ * @extends Ext.form.Action\r
+ * <p>A class which handles submission of data from {@link Ext.form.BasicForm Form}s\r
+ * and processes the returned response.</p>\r
+ * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when\r
+ * {@link Ext.form.BasicForm#submit submit}ting.</p>\r
+ * <p><u><b>Response Packet Criteria</b></u></p>\r
+ * <p>A response packet may contain:\r
+ * <div class="mdetail-params"><ul>\r
+ * <li><b><code>success</code></b> property : Boolean\r
+ * <div class="sub-desc">The <code>success</code> property is required.</div></li>\r
+ * <li><b><code>errors</code></b> property : Object\r
+ * <div class="sub-desc"><div class="sub-desc">The <code>errors</code> property,\r
+ * which is optional, contains error messages for invalid fields.</div></li>\r
+ * </ul></div>\r
+ * <p><u><b>JSON Packets</b></u></p>\r
+ * <p>By default, response packets are assumed to be JSON, so a typical response\r
+ * packet may look like this:</p><pre><code>\r
+{\r
+ success: false,\r
+ errors: {\r
+ clientCode: "Client not found",\r
+ portOfLoading: "This field must not be null"\r
+ }\r
+}</code></pre>\r
+ * <p>Other data may be placed into the response for processing by the {@link Ext.form.BasicForm}'s callback\r
+ * or event handler methods. The object decoded from this JSON is available in the\r
+ * {@link Ext.form.Action#result result} property.</p>\r
+ * <p>Alternatively, if an {@link #errorReader} is specified as an {@link Ext.data.XmlReader XmlReader}:</p><pre><code>\r
+ errorReader: new Ext.data.XmlReader({\r
+ record : 'field',\r
+ success: '@success'\r
+ }, [\r
+ 'id', 'msg'\r
+ ]\r
+ )\r
+</code></pre>\r
+ * <p>then the results may be sent back in XML format:</p><pre><code>\r
+<?xml version="1.0" encoding="UTF-8"?>\r
+<message success="false">\r
+<errors>\r
+ <field>\r
+ <id>clientCode</id>\r
+ <msg><![CDATA[Code not found. <br /><i>This is a test validation message from the server </i>]]></msg>\r
+ </field>\r
+ <field>\r
+ <id>portOfLoading</id>\r
+ <msg><![CDATA[Port not found. <br /><i>This is a test validation message from the server </i>]]></msg>\r
+ </field>\r
+</errors>\r
+</message>\r
+</code></pre>\r
+ * <p>Other elements may be placed into the response XML for processing by the {@link Ext.form.BasicForm}'s callback\r
+ * or event handler methods. The XML document is available in the {@link #errorReader}'s {@link Ext.data.XmlReader#xmlData xmlData} property.</p>\r
+ */\r
+Ext.form.Action.Submit = function(form, options){\r
+ Ext.form.Action.Submit.superclass.constructor.call(this, form, options);\r
+};\r
+\r
+Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {\r
+ <div id="cfg-Ext.form.Action.Submit-errorReader"></div>/**\r
+ * @cfg {Ext.data.DataReader} errorReader <p><b>Optional. JSON is interpreted with\r
+ * no need for an errorReader.</b></p>\r
+ * <p>A Reader which reads a single record from the returned data. The DataReader's\r
+ * <b>success</b> property specifies how submission success is determined. The Record's\r
+ * data provides the error messages to apply to any invalid form Fields.</p>\r
+ */\r
+ <div id="cfg-Ext.form.Action.Submit-clientValidation"></div>/**\r
+ * @cfg {boolean} clientValidation Determines whether a Form's fields are validated\r
+ * in a final call to {@link Ext.form.BasicForm#isValid isValid} prior to submission.\r
+ * Pass <tt>false</tt> in the Form's submit options to prevent this. If not defined, pre-submission field validation\r
+ * is performed.\r
*/\r
- isDisabled : function(){\r
- return this.initialConfig.disabled;\r
+ type : 'submit',\r
+\r
+ // private\r
+ run : function(){\r
+ var o = this.options;\r
+ var method = this.getMethod();\r
+ var isGet = method == 'GET';\r
+ if(o.clientValidation === false || this.form.isValid()){\r
+ Ext.Ajax.request(Ext.apply(this.createCallback(o), {\r
+ form:this.form.el.dom,\r
+ url:this.getUrl(isGet),\r
+ method: method,\r
+ headers: o.headers,\r
+ params:!isGet ? this.getParams() : null,\r
+ isUpload: this.form.fileUpload\r
+ }));\r
+ }else if (o.clientValidation !== false){ // client validation failed\r
+ this.failureType = Ext.form.Action.CLIENT_INVALID;\r
+ this.form.afterAction(this, false);\r
+ }\r
},\r
\r
- <div id="method-Ext.Action-setHidden"></div>/**\r
- * Sets the hidden state of all components using this action. Shortcut method\r
- * for <code>{@link #hide}</code> and <code>{@link #show}</code>.\r
- * @param {Boolean} hidden True to hide the component, false to show it\r
- */\r
- setHidden : function(v){\r
- this.initialConfig.hidden = v;\r
- this.callEach('setVisible', [!v]);\r
+ // private\r
+ success : function(response){\r
+ var result = this.processResponse(response);\r
+ if(result === true || result.success){\r
+ this.form.afterAction(this, true);\r
+ return;\r
+ }\r
+ if(result.errors){\r
+ this.form.markInvalid(result.errors);\r
+ }\r
+ this.failureType = Ext.form.Action.SERVER_INVALID;\r
+ this.form.afterAction(this, false);\r
},\r
\r
- <div id="method-Ext.Action-show"></div>/**\r
- * Shows all components using this action.\r
- */\r
- show : function(){\r
- this.setHidden(false);\r
+ // private\r
+ handleResponse : function(response){\r
+ if(this.form.errorReader){\r
+ var rs = this.form.errorReader.read(response);\r
+ var errors = [];\r
+ if(rs.records){\r
+ for(var i = 0, len = rs.records.length; i < len; i++) {\r
+ var r = rs.records[i];\r
+ errors[i] = r.data;\r
+ }\r
+ }\r
+ if(errors.length < 1){\r
+ errors = null;\r
+ }\r
+ return {\r
+ success : rs.success,\r
+ errors : errors\r
+ };\r
+ }\r
+ return Ext.decode(response.responseText);\r
+ }\r
+});\r
+\r
+\r
+<div id="cls-Ext.form.Action.Load"></div>/**\r
+ * @class Ext.form.Action.Load\r
+ * @extends Ext.form.Action\r
+ * <p>A class which handles loading of data from a server into the Fields of an {@link Ext.form.BasicForm}.</p>\r
+ * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when\r
+ * {@link Ext.form.BasicForm#load load}ing.</p>\r
+ * <p><u><b>Response Packet Criteria</b></u></p>\r
+ * <p>A response packet <b>must</b> contain:\r
+ * <div class="mdetail-params"><ul>\r
+ * <li><b><code>success</code></b> property : Boolean</li>\r
+ * <li><b><code>data</code></b> property : Object</li>\r
+ * <div class="sub-desc">The <code>data</code> property contains the values of Fields to load.\r
+ * The individual value object for each Field is passed to the Field's\r
+ * {@link Ext.form.Field#setValue setValue} method.</div></li>\r
+ * </ul></div>\r
+ * <p><u><b>JSON Packets</b></u></p>\r
+ * <p>By default, response packets are assumed to be JSON, so for the following form load call:<pre><code>\r
+var myFormPanel = new Ext.form.FormPanel({\r
+ title: 'Client and routing info',\r
+ items: [{\r
+ fieldLabel: 'Client',\r
+ name: 'clientName'\r
+ }, {\r
+ fieldLabel: 'Port of loading',\r
+ name: 'portOfLoading'\r
+ }, {\r
+ fieldLabel: 'Port of discharge',\r
+ name: 'portOfDischarge'\r
+ }]\r
+});\r
+myFormPanel.{@link Ext.form.FormPanel#getForm getForm}().{@link Ext.form.BasicForm#load load}({\r
+ url: '/getRoutingInfo.php',\r
+ params: {\r
+ consignmentRef: myConsignmentRef\r
},\r
+ failure: function(form, action) {\r
+ Ext.Msg.alert("Load failed", action.result.errorMessage);\r
+ }\r
+});\r
+</code></pre>\r
+ * a <b>success response</b> packet may look like this:</p><pre><code>\r
+{\r
+ success: true,\r
+ data: {\r
+ clientName: "Fred. Olsen Lines",\r
+ portOfLoading: "FXT",\r
+ portOfDischarge: "OSL"\r
+ }\r
+}</code></pre>\r
+ * while a <b>failure response</b> packet may look like this:</p><pre><code>\r
+{\r
+ success: false,\r
+ errorMessage: "Consignment reference not found"\r
+}</code></pre>\r
+ * <p>Other data may be placed into the response for processing the {@link Ext.form.BasicForm Form}'s\r
+ * callback or event handler methods. The object decoded from this JSON is available in the\r
+ * {@link Ext.form.Action#result result} property.</p>\r
+ */\r
+Ext.form.Action.Load = function(form, options){\r
+ Ext.form.Action.Load.superclass.constructor.call(this, form, options);\r
+ this.reader = this.form.reader;\r
+};\r
\r
- <div id="method-Ext.Action-hide"></div>/**\r
- * Hides all components using this action.\r
- */\r
- hide : function(){\r
- this.setHidden(true);\r
+Ext.extend(Ext.form.Action.Load, Ext.form.Action, {\r
+ // private\r
+ type : 'load',\r
+\r
+ // private\r
+ run : function(){\r
+ Ext.Ajax.request(Ext.apply(\r
+ this.createCallback(this.options), {\r
+ method:this.getMethod(),\r
+ url:this.getUrl(false),\r
+ headers: this.options.headers,\r
+ params:this.getParams()\r
+ }));\r
},\r
\r
- <div id="method-Ext.Action-isHidden"></div>/**\r
- * Returns true if the components using this action are currently hidden, else returns false. \r
- */\r
- isHidden : function(){\r
- return this.initialConfig.hidden;\r
+ // private\r
+ success : function(response){\r
+ var result = this.processResponse(response);\r
+ if(result === true || !result.success || !result.data){\r
+ this.failureType = Ext.form.Action.LOAD_FAILURE;\r
+ this.form.afterAction(this, false);\r
+ return;\r
+ }\r
+ this.form.clearInvalid();\r
+ this.form.setValues(result.data);\r
+ this.form.afterAction(this, true);\r
},\r
\r
- <div id="method-Ext.Action-setHandler"></div>/**\r
- * Sets the function that will be called by each component using this action when its primary event is triggered.\r
- * @param {Function} fn The function that will be invoked by the action's components. The function\r
- * will be called with no arguments.\r
- * @param {Object} scope The scope in which the function will execute\r
- */\r
- setHandler : function(fn, scope){\r
- this.initialConfig.handler = fn;\r
- this.initialConfig.scope = scope;\r
- this.callEach('setHandler', [fn, scope]);\r
+ // private\r
+ handleResponse : function(response){\r
+ if(this.form.reader){\r
+ var rs = this.form.reader.read(response);\r
+ var data = rs.records && rs.records[0] ? rs.records[0].data : null;\r
+ return {\r
+ success : rs.success,\r
+ data : data\r
+ };\r
+ }\r
+ return Ext.decode(response.responseText);\r
+ }\r
+});\r
+\r
+\r
+\r
+<div id="cls-Ext.form.Action.DirectLoad"></div>/**\r
+ * @class Ext.form.Action.DirectLoad\r
+ * @extends Ext.form.Action.Load\r
+ * <p>Provides Ext.direct support for loading form data.</p>\r
+ * <p>This example illustrates usage of Ext.Direct to <b>load</b> a form through Ext.Direct.</p>\r
+ * <pre><code>\r
+var myFormPanel = new Ext.form.FormPanel({\r
+ // configs for FormPanel\r
+ title: 'Basic Information',\r
+ renderTo: document.body,\r
+ width: 300, height: 160,\r
+ padding: 10,\r
+\r
+ // configs apply to child items\r
+ defaults: {anchor: '100%'},\r
+ defaultType: 'textfield',\r
+ items: [{\r
+ fieldLabel: 'Name',\r
+ name: 'name'\r
+ },{\r
+ fieldLabel: 'Email',\r
+ name: 'email'\r
+ },{\r
+ fieldLabel: 'Company',\r
+ name: 'company'\r
+ }],\r
+\r
+ // configs for BasicForm\r
+ api: {\r
+ // The server-side method to call for load() requests\r
+ load: Profile.getBasicInfo,\r
+ // The server-side must mark the submit handler as a 'formHandler'\r
+ submit: Profile.updateBasicInfo\r
},\r
+ // specify the order for the passed params\r
+ paramOrder: ['uid', 'foo']\r
+});\r
\r
- <div id="method-Ext.Action-each"></div>/**\r
- * Executes the specified function once for each component currently tied to this action. The function passed\r
- * in should accept a single argument that will be an object that supports the basic Action config/method interface.\r
- * @param {Function} fn The function to execute for each component\r
- * @param {Object} scope The scope in which the function will execute\r
- */\r
- each : function(fn, scope){\r
- Ext.each(this.items, fn, scope);\r
+// load the form\r
+myFormPanel.getForm().load({\r
+ // pass 2 arguments to server side getBasicInfo method (len=2)\r
+ params: {\r
+ foo: 'bar',\r
+ uid: 34\r
+ }\r
+});\r
+ * </code></pre>\r
+ * The data packet sent to the server will resemble something like:\r
+ * <pre><code>\r
+[\r
+ {\r
+ "action":"Profile","method":"getBasicInfo","type":"rpc","tid":2,\r
+ "data":[34,"bar"] // note the order of the params\r
+ }\r
+]\r
+ * </code></pre>\r
+ * The form will process a data packet returned by the server that is similar\r
+ * to the following format:\r
+ * <pre><code>\r
+[\r
+ {\r
+ "action":"Profile","method":"getBasicInfo","type":"rpc","tid":2,\r
+ "result":{\r
+ "success":true,\r
+ "data":{\r
+ "name":"Fred Flintstone",\r
+ "company":"Slate Rock and Gravel",\r
+ "email":"fred.flintstone@slaterg.com"\r
+ }\r
+ }\r
+ }\r
+]\r
+ * </code></pre>\r
+ */\r
+Ext.form.Action.DirectLoad = Ext.extend(Ext.form.Action.Load, {\r
+ constructor: function(form, opts) {\r
+ Ext.form.Action.DirectLoad.superclass.constructor.call(this, form, opts);\r
},\r
+ type : 'directload',\r
\r
- // private\r
- callEach : function(fnName, args){\r
- var cs = this.items;\r
- for(var i = 0, len = cs.length; i < len; i++){\r
- cs[i][fnName].apply(cs[i], args);\r
+ run : function(){\r
+ var args = this.getParams();\r
+ args.push(this.success, this);\r
+ this.form.api.load.apply(window, args);\r
+ },\r
+\r
+ getParams : function() {\r
+ var buf = [], o = {};\r
+ var bp = this.form.baseParams;\r
+ var p = this.options.params;\r
+ Ext.apply(o, p, bp);\r
+ var paramOrder = this.form.paramOrder;\r
+ if(paramOrder){\r
+ for(var i = 0, len = paramOrder.length; i < len; i++){\r
+ buf.push(o[paramOrder[i]]);\r
+ }\r
+ }else if(this.form.paramsAsHash){\r
+ buf.push(o);\r
}\r
+ return buf;\r
+ },\r
+ // Direct actions have already been processed and therefore\r
+ // we can directly set the result; Direct Actions do not have\r
+ // a this.response property.\r
+ processResponse : function(result) {\r
+ this.result = result;\r
+ return result;\r
},\r
+ \r
+ success : function(response, trans){\r
+ if(trans.type == Ext.Direct.exceptions.SERVER){\r
+ response = {};\r
+ }\r
+ Ext.form.Action.DirectLoad.superclass.success.call(this, response);\r
+ }\r
+});\r
\r
- // private\r
- addComponent : function(comp){\r
- this.items.push(comp);\r
- comp.on('destroy', this.removeComponent, this);\r
+<div id="cls-Ext.form.Action.DirectSubmit"></div>/**\r
+ * @class Ext.form.Action.DirectSubmit\r
+ * @extends Ext.form.Action.Submit\r
+ * <p>Provides Ext.direct support for submitting form data.</p>\r
+ * <p>This example illustrates usage of Ext.Direct to <b>submit</b> a form through Ext.Direct.</p>\r
+ * <pre><code>\r
+var myFormPanel = new Ext.form.FormPanel({\r
+ // configs for FormPanel\r
+ title: 'Basic Information',\r
+ renderTo: document.body,\r
+ width: 300, height: 160,\r
+ padding: 10,\r
+ buttons:[{\r
+ text: 'Submit',\r
+ handler: function(){\r
+ myFormPanel.getForm().submit({\r
+ params: {\r
+ foo: 'bar',\r
+ uid: 34\r
+ }\r
+ });\r
+ }\r
+ }],\r
+\r
+ // configs apply to child items\r
+ defaults: {anchor: '100%'},\r
+ defaultType: 'textfield',\r
+ items: [{\r
+ fieldLabel: 'Name',\r
+ name: 'name'\r
+ },{\r
+ fieldLabel: 'Email',\r
+ name: 'email'\r
+ },{\r
+ fieldLabel: 'Company',\r
+ name: 'company'\r
+ }],\r
+\r
+ // configs for BasicForm\r
+ api: {\r
+ // The server-side method to call for load() requests\r
+ load: Profile.getBasicInfo,\r
+ // The server-side must mark the submit handler as a 'formHandler'\r
+ submit: Profile.updateBasicInfo\r
},\r
+ // specify the order for the passed params\r
+ paramOrder: ['uid', 'foo']\r
+});\r
+ * </code></pre>\r
+ * The data packet sent to the server will resemble something like:\r
+ * <pre><code>\r
+{\r
+ "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",\r
+ "result":{\r
+ "success":true,\r
+ "id":{\r
+ "extAction":"Profile","extMethod":"updateBasicInfo",\r
+ "extType":"rpc","extTID":"6","extUpload":"false",\r
+ "name":"Aaron Conran","email":"aaron@extjs.com","company":"Ext JS, LLC"\r
+ }\r
+ }\r
+}\r
+ * </code></pre>\r
+ * The form will process a data packet returned by the server that is similar\r
+ * to the following:\r
+ * <pre><code>\r
+// sample success packet (batched requests)\r
+[\r
+ {\r
+ "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":3,\r
+ "result":{\r
+ "success":true\r
+ }\r
+ }\r
+]\r
\r
- // private\r
- removeComponent : function(comp){\r
- this.items.remove(comp);\r
+// sample failure packet (one request)\r
+{\r
+ "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",\r
+ "result":{\r
+ "errors":{\r
+ "email":"already taken"\r
+ },\r
+ "success":false,\r
+ "foo":"bar"\r
+ }\r
+}\r
+ * </code></pre>\r
+ * Also see the discussion in {@link Ext.form.Action.DirectLoad}.\r
+ */\r
+Ext.form.Action.DirectSubmit = Ext.extend(Ext.form.Action.Submit, {\r
+ constructor : function(form, opts) {\r
+ Ext.form.Action.DirectSubmit.superclass.constructor.call(this, form, opts);\r
+ },\r
+ type : 'directsubmit',\r
+ // override of Submit\r
+ run : function(){\r
+ var o = this.options;\r
+ if(o.clientValidation === false || this.form.isValid()){\r
+ // tag on any additional params to be posted in the\r
+ // form scope\r
+ this.success.params = this.getParams();\r
+ this.form.api.submit(this.form.el.dom, this.success, this);\r
+ }else if (o.clientValidation !== false){ // client validation failed\r
+ this.failureType = Ext.form.Action.CLIENT_INVALID;\r
+ this.form.afterAction(this, false);\r
+ }\r
},\r
\r
- <div id="method-Ext.Action-execute"></div>/**\r
- * Executes this action manually using the handler function specified in the original config object\r
- * or the handler function set with <code>{@link #setHandler}</code>. Any arguments passed to this\r
- * function will be passed on to the handler function.\r
- * @param {Mixed} arg1 (optional) Variable number of arguments passed to the handler function\r
- * @param {Mixed} arg2 (optional)\r
- * @param {Mixed} etc... (optional)\r
- */\r
- execute : function(){\r
- this.initialConfig.handler.apply(this.initialConfig.scope || window, arguments);\r
+ getParams : function() {\r
+ var o = {};\r
+ var bp = this.form.baseParams;\r
+ var p = this.options.params;\r
+ Ext.apply(o, p, bp);\r
+ return o;\r
+ },\r
+ // Direct actions have already been processed and therefore\r
+ // we can directly set the result; Direct Actions do not have\r
+ // a this.response property.\r
+ processResponse : function(result) {\r
+ this.result = result;\r
+ return result;\r
+ },\r
+ \r
+ success : function(response, trans){\r
+ if(trans.type == Ext.Direct.exceptions.SERVER){\r
+ response = {};\r
+ }\r
+ Ext.form.Action.DirectSubmit.superclass.success.call(this, response);\r
}\r
-};
-</pre> \r
-</body>\r
+});\r
+\r
+Ext.form.Action.ACTION_TYPES = {\r
+ 'load' : Ext.form.Action.Load,\r
+ 'submit' : Ext.form.Action.Submit,\r
+ 'directload' : Ext.form.Action.DirectLoad,\r
+ 'directsubmit' : Ext.form.Action.DirectSubmit\r
+};\r
+</pre>
+</body>
</html>
\ No newline at end of file