+++ /dev/null
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\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
-/**\r
- * Failure type returned when client side validation of the Form fails\r
- * thus aborting a submit action.\r
- * @type {String}\r
- * @static\r
- */\r
-Ext.form.Action.CLIENT_INVALID = 'client';\r
-/**\r
- * Failure type returned when server side validation of the Form fails\r
- * indicating that field-specific error messages have been returned in the\r
- * response's <tt style="font-weight:bold">errors</tt> property.\r
- * @type {String}\r
- * @static\r
- */\r
-Ext.form.Action.SERVER_INVALID = 'server';\r
-/**\r
- * Failure type returned when a communication error happens when attempting\r
- * to send a request to the remote server.\r
- * @type {String}\r
- * @static\r
- */\r
-Ext.form.Action.CONNECT_FAILURE = 'connect';\r
-/**\r
- * Failure type returned when 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
-Ext.form.Action.prototype = {\r
-/**\r
- * @cfg {String} url The URL that the Action is to invoke.\r
- */\r
-/**\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
-/**\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
-/**\r
- * @cfg {Mixed} params 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.\r
- */\r
-/**\r
- * @cfg {Number} timeout The number of milliseconds to wait for a server response before\r
- * failing with the {@link #failureType} as {@link #Action.CONNECT_FAILURE}.\r
- */\r
-/**\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
-/**\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
-/**\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
-/**\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
-/**\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
-/**\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
-/**\r
- * The type of failure detected. See {@link link Ext.form.Action#Action.CLIENT_INVALID CLIENT_INVALID},\r
- * {@link link Ext.form.Action#Action.SERVER_INVALID SERVER_INVALID},\r
- * {@link #link Ext.form.ActionAction.CONNECT_FAILURE CONNECT_FAILURE}, {@link Ext.form.Action#Action.LOAD_FAILURE LOAD_FAILURE}\r
- * @property failureType\r
- * @type {String}\r
- *//**\r
- * The XMLHttpRequest object used to perform the action.\r
- * @property response\r
- * @type {Object}\r
- *//**\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
-\r
- // interface method\r
- run : function(options){\r
-\r
- },\r
-\r
- // interface method\r
- success : function(response){\r
-\r
- },\r
-\r
- // interface method\r
- handleResponse : function(response){\r
-\r
- },\r
-\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
- // private\r
- processResponse : function(response){\r
- this.response = response;\r
- if(!response.responseText){\r
- return true;\r
- }\r
- this.result = this.handleResponse(response);\r
- return this.result;\r
- },\r
-\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 += (url.indexOf('?') != -1 ? '&' : '?') + p;\r
- }\r
- }\r
- return url;\r
- },\r
-\r
- // private\r
- getMethod : function(){\r
- return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();\r
- },\r
-\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
- // 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
-/**\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>A response packet must contain a boolean <tt style="font-weight:bold">success</tt> property, and, optionally\r
- * an <tt style="font-weight:bold">errors</tt> property. The <tt style="font-weight:bold">errors</tt> property contains error\r
- * messages for invalid fields.</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 {@link #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
- /**\r
- * @cfg {Ext.data.DataReader} errorReader <b>Optional. JSON is interpreted with no need for an errorReader.</b>\r
- * <p>A Reader which reads a single record from the returned data. The DataReader's <b>success</b> property specifies\r
- * how submission success is determined. The Record's data provides the error messages to apply to any invalid form Fields.</p>.\r
- */\r
- /**\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
- 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
- // 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
- this.failureType = Ext.form.Action.SERVER_INVALID;\r
- }\r
- this.form.afterAction(this, false);\r
- },\r
-\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
-/**\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>A response packet <b>must</b> contain a boolean <tt style="font-weight:bold">success</tt> property, and\r
- * a <tt style="font-weight:bold">data</tt> property. The <tt style="font-weight:bold">data</tt> property\r
- * contains the values of Fields to load. The individual value object for each Field\r
- * is passed to the Field's {@link Ext.form.Field#setValue setValue} method.</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: true,\r
- data: {\r
- clientName: "Fred. Olsen Lines",\r
- portOfLoading: "FXT",\r
- portOfDischarge: "OSL"\r
- }\r
-}</code></pre>\r
- * <p>Other data may be placed into the response for processing the {@link Ext.form.BasicForm Form}'s callback\r
- * or event handler methods. The object decoded from this JSON is available in the {@link #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
-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
- // 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
- // 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
-Ext.form.Action.ACTION_TYPES = {\r
- 'load' : Ext.form.Action.Load,\r
- 'submit' : Ext.form.Action.Submit\r
-};\r