+++ /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.BasicForm\r
- * @extends Ext.util.Observable\r
- * <p>Encapsulates the DOM <form> element at the heart of the {@link Ext.form.FormPanel FormPanel} class, and provides\r
- * input field management, validation, submission, and form loading services.</p>\r
- * <p>By default, Ext Forms are submitted through Ajax, using an instance of {@link Ext.form.Action.Submit}.\r
- * To enable normal browser submission of an Ext Form, use the {@link #standardSubmit} config option.</p>\r
- * <p><h3>File Uploads</h3>{@link #fileUpload File uploads} are not performed using Ajax submission, that\r
- * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard\r
- * manner with the DOM <tt><form></tt> element temporarily modified to have its\r
- * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer\r
- * to a dynamically generated, hidden <tt><iframe></tt> which is inserted into the document\r
- * but removed after the return data has been gathered.</p>\r
- * <p>The server response is parsed by the browser to create the document for the IFRAME. If the\r
- * server is using JSON to send the return object, then the\r
- * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header\r
- * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>\r
- * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode\r
- * "<" as "&lt;", "&" as "&amp;" etc.</p>\r
- * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object\r
- * is created containing a <tt>responseText</tt> property in order to conform to the\r
- * requirements of event handlers and callbacks.</p>\r
- * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>\r
- * and some server technologies (notably JEE) may require some custom processing in order to\r
- * retrieve parameter names and parameter values from the packet content.</p>\r
- * @constructor\r
- * @param {Mixed} el The form element or its id\r
- * @param {Object} config Configuration options\r
- */\r
-Ext.form.BasicForm = function(el, config){\r
- Ext.apply(this, config);\r
- /*\r
- * The Ext.form.Field items in this form.\r
- * @type MixedCollection\r
- */\r
- this.items = new Ext.util.MixedCollection(false, function(o){\r
- return o.id || (o.id = Ext.id());\r
- });\r
- this.addEvents(\r
- /**\r
- * @event beforeaction\r
- * Fires before any action is performed. Return false to cancel the action.\r
- * @param {Form} this\r
- * @param {Action} action The {@link Ext.form.Action} to be performed\r
- */\r
- 'beforeaction',\r
- /**\r
- * @event actionfailed\r
- * Fires when an action fails.\r
- * @param {Form} this\r
- * @param {Action} action The {@link Ext.form.Action} that failed\r
- */\r
- 'actionfailed',\r
- /**\r
- * @event actioncomplete\r
- * Fires when an action is completed.\r
- * @param {Form} this\r
- * @param {Action} action The {@link Ext.form.Action} that completed\r
- */\r
- 'actioncomplete'\r
- );\r
-\r
- if(el){\r
- this.initEl(el);\r
- }\r
- Ext.form.BasicForm.superclass.constructor.call(this);\r
-};\r
-\r
-Ext.extend(Ext.form.BasicForm, Ext.util.Observable, {\r
- /**\r
- * @cfg {String} method\r
- * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.\r
- */\r
- /**\r
- * @cfg {DataReader} reader\r
- * An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read data when executing "load" actions.\r
- * This is optional as there is built-in support for processing JSON.\r
- */\r
- /**\r
- * @cfg {DataReader} errorReader\r
- * <p>An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read field error messages returned from "submit" actions.\r
- * This is completely optional as there is built-in support for processing JSON.</p>\r
- * <p>The Records which provide messages for the invalid Fields must use the Field name (or id) as the Record ID,\r
- * and must contain a field called "msg" which contains the error message.</p>\r
- * <p>The errorReader does not have to be a full-blown implementation of a DataReader. It simply needs to implement a \r
- * <tt>read(xhr)</tt> function which returns an Array of Records in an object with the following structure:<pre><code>\r
-{\r
- records: recordArray\r
-}\r
-</code></pre>\r
- */\r
- /**\r
- * @cfg {String} url\r
- * The URL to use for form actions if one isn't supplied in the action options.\r
- */\r
- /**\r
- * @cfg {Boolean} fileUpload\r
- * Set to true if this form is a file upload.\r
- * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>\r
- * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the\r
- * DOM <tt><form></tt> element temporarily modified to have its\r
- * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer\r
- * to a dynamically generated, hidden <tt><iframe></tt> which is inserted into the document\r
- * but removed after the return data has been gathered.</p>\r
- * <p>The server response is parsed by the browser to create the document for the IFRAME. If the\r
- * server is using JSON to send the return object, then the\r
- * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header\r
- * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>\r
- * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode\r
- * "<" as "&lt;", "&" as "&amp;" etc.</p>\r
- * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object\r
- * is created containing a <tt>responseText</tt> property in order to conform to the\r
- * requirements of event handlers and callbacks.</p>\r
- * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>\r
- * and some server technologies (notably JEE) may require some custom processing in order to\r
- * retrieve parameter names and parameter values from the packet content.</p>\r
- */\r
- /**\r
- * @cfg {Object} baseParams\r
- * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.\r
- */\r
- /**\r
- * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).\r
- */\r
- timeout: 30,\r
-\r
- // private\r
- activeAction : null,\r
-\r
- /**\r
- * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded\r
- * or setValues() data instead of when the form was first created.\r
- */\r
- trackResetOnLoad : false,\r
-\r
- /**\r
- * @cfg {Boolean} standardSubmit If set to true, standard HTML form submits are used instead of XHR (Ajax) style\r
- * form submissions. (defaults to false)<br>\r
- * <p><b>Note:</b> When using standardSubmit, any the options to {@link #submit} are\r
- * ignored because Ext's Ajax infrastracture is bypassed. To pass extra parameters, you will need to create\r
- * hidden fields within the form.</p>\r
- */\r
- /**\r
- * By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific\r
- * element by passing it or its id or mask the form itself by passing in true.\r
- * @type Mixed\r
- * @property waitMsgTarget\r
- */\r
-\r
- // private\r
- initEl : function(el){\r
- this.el = Ext.get(el);\r
- this.id = this.el.id || Ext.id();\r
- if(!this.standardSubmit){\r
- this.el.on('submit', this.onSubmit, this);\r
- }\r
- this.el.addClass('x-form');\r
- },\r
-\r
- /**\r
- * Get the HTML form Element\r
- * @return Ext.Element\r
- */\r
- getEl: function(){\r
- return this.el;\r
- },\r
-\r
- // private\r
- onSubmit : function(e){\r
- e.stopEvent();\r
- },\r
-\r
- // private\r
- destroy: function() {\r
- this.items.each(function(f){\r
- Ext.destroy(f);\r
- });\r
- if(this.el){\r
- this.el.removeAllListeners();\r
- this.el.remove();\r
- }\r
- this.purgeListeners();\r
- },\r
-\r
- /**\r
- * Returns true if client-side validation on the form is successful.\r
- * @return Boolean\r
- */\r
- isValid : function(){\r
- var valid = true;\r
- this.items.each(function(f){\r
- if(!f.validate()){\r
- valid = false;\r
- }\r
- });\r
- return valid;\r
- },\r
-\r
- /**\r
- * Returns true if any fields in this form have changed since their original load.\r
- * @return Boolean\r
- */\r
- isDirty : function(){\r
- var dirty = false;\r
- this.items.each(function(f){\r
- if(f.isDirty()){\r
- dirty = true;\r
- return false;\r
- }\r
- });\r
- return dirty;\r
- },\r
-\r
- /**\r
- * Performs a predefined action ({@link Ext.form.Action.Submit} or\r
- * {@link Ext.form.Action.Load}) or a custom extension of {@link Ext.form.Action} \r
- * to perform application-specific processing.\r
- * @param {String/Object} actionName The name of the predefined action type,\r
- * or instance of {@link Ext.form.Action} to perform.\r
- * @param {Object} options (optional) The options to pass to the {@link Ext.form.Action}. \r
- * All of the config options listed below are supported by both the submit\r
- * and load actions unless otherwise noted (custom actions could also accept\r
- * other config options):<ul>\r
- * <li><b>url</b> : String<p style="margin-left:1em">The url for the action (defaults\r
- * to the form's url.)</p></li>\r
- * <li><b>method</b> : String<p style="margin-left:1em">The form method to use (defaults\r
- * to the form's method, or POST if not defined)</p></li>\r
- * <li><b>params</b> : String/Object<p style="margin-left:1em">The params to pass\r
- * (defaults to the form's baseParams, or none if not defined)</p></li>\r
- * <li><b>headers</b> : Object<p style="margin-left:1em">Request headers to set for the action\r
- * (defaults to the form's default headers)</p></li>\r
- * <li><b>success</b> : Function<p style="margin-left:1em">The callback that will\r
- * be invoked after a successful response. The function is passed the following parameters:<ul>\r
- * <li><code>form</code> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>\r
- * <li><code>action</code> : Ext.form.Action<div class="sub-desc">The {@link Ext.form.Action Action} object which performed the operation. The {@link Ext.form.Action#result result}\r
- * property of this object may be examined to perform custom postprocessing.</div></li>\r
- * </ul></p></li>\r
- * <li><b>failure</b> : Function<p style="margin-left:1em">The callback that will\r
- * be invoked after a failed transaction attempt. The function\r
- * is passed the following parameters:<ul>\r
- * <li><code>form</code> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>\r
- * <li><code>action</code> : Ext.form.Action<div class="sub-desc">The {@link Ext.form.Action Action} object which performed the operation. If an Ajax\r
- * error ocurred, the failure type will be in {@link Ext.form.Action#failureType failureType}. The {@link Ext.form.Action#result result}\r
- * property of this object may be examined to perform custom postprocessing.</div></li>\r
- * </ul></p></li>\r
- * <li><b>scope</b> : Object<p style="margin-left:1em">The scope in which to call the\r
- * callback functions (The <tt>this</tt> reference for the callback functions).</p></li>\r
- * <li><b>clientValidation</b> : Boolean<p style="margin-left:1em">Submit Action only.\r
- * Determines whether a Form's fields are validated in a final call to\r
- * {@link Ext.form.BasicForm#isValid isValid} prior to submission. Set to <tt>false</tt>\r
- * to prevent this. If undefined, pre-submission field validation is performed.</p></li></ul>\r
- * @return {BasicForm} this\r
- */\r
- doAction : function(action, options){\r
- if(typeof action == 'string'){\r
- action = new Ext.form.Action.ACTION_TYPES[action](this, options);\r
- }\r
- if(this.fireEvent('beforeaction', this, action) !== false){\r
- this.beforeAction(action);\r
- action.run.defer(100, action);\r
- }\r
- return this;\r
- },\r
-\r
- /**\r
- * Shortcut to do a submit action.\r
- * @param {Object} options The options to pass to the action (see {@link #doAction} for details).<br>\r
- * <p><b>Note:</b> this is ignored when using the {@link #standardSubmit} option.</p>\r
- * <p>The following code:</p><pre><code>\r
-myFormPanel.getForm().submit({\r
- clientValidation: true,\r
- url: 'updateConsignment.php',\r
- params: {\r
- newStatus: 'delivered'\r
- },\r
- success: function(form, action) {\r
- Ext.Msg.alert("Success", action.result.msg);\r
- },\r
- failure: function(form, action) {\r
- switch (action.failureType) {\r
- case Ext.form.Action.CLIENT_INVALID:\r
- Ext.Msg.alert("Failure", "Form fields may not be submitted with invalid values");\r
- break;\r
- case Ext.form.Action.CONNECT_FAILURE:\r
- Ext.Msg.alert("Failure", "Ajax communication failed");\r
- break;\r
- case Ext.form.Action.SERVER_INVALID:\r
- Ext.Msg.alert("Failure", action.result.msg);\r
- }\r
- }\r
-});\r
-</code></pre>\r
- * would process the following server response for a successful submission:<pre><code>\r
-{\r
- success: true,\r
- msg: 'Consignment updated'\r
-}\r
-</code></pre>\r
- * and the following server response for a failed submission:<pre><code>\r
-{\r
- success: false,\r
- msg: 'You do not have permission to perform this operation'\r
-}\r
-</code></pre>\r
- * @return {BasicForm} this\r
- */\r
- submit : function(options){\r
- if(this.standardSubmit){\r
- var v = this.isValid();\r
- if(v){\r
- this.el.dom.submit();\r
- }\r
- return v;\r
- }\r
- this.doAction('submit', options);\r
- return this;\r
- },\r
-\r
- /**\r
- * Shortcut to do a load action.\r
- * @param {Object} options The options to pass to the action (see {@link #doAction} for details)\r
- * @return {BasicForm} this\r
- */\r
- load : function(options){\r
- this.doAction('load', options);\r
- return this;\r
- },\r
-\r
- /**\r
- * Persists the values in this form into the passed Ext.data.Record object in a beginEdit/endEdit block.\r
- * @param {Record} record The record to edit\r
- * @return {BasicForm} this\r
- */\r
- updateRecord : function(record){\r
- record.beginEdit();\r
- var fs = record.fields;\r
- fs.each(function(f){\r
- var field = this.findField(f.name);\r
- if(field){\r
- record.set(f.name, field.getValue());\r
- }\r
- }, this);\r
- record.endEdit();\r
- return this;\r
- },\r
-\r
- /**\r
- * Loads an Ext.data.Record into this form.\r
- * @param {Record} record The record to load\r
- * @return {BasicForm} this\r
- */\r
- loadRecord : function(record){\r
- this.setValues(record.data);\r
- return this;\r
- },\r
-\r
- // private\r
- beforeAction : function(action){\r
- var o = action.options;\r
- if(o.waitMsg){\r
- if(this.waitMsgTarget === true){\r
- this.el.mask(o.waitMsg, 'x-mask-loading');\r
- }else if(this.waitMsgTarget){\r
- this.waitMsgTarget = Ext.get(this.waitMsgTarget);\r
- this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');\r
- }else{\r
- Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...');\r
- }\r
- }\r
- },\r
-\r
- // private\r
- afterAction : function(action, success){\r
- this.activeAction = null;\r
- var o = action.options;\r
- if(o.waitMsg){\r
- if(this.waitMsgTarget === true){\r
- this.el.unmask();\r
- }else if(this.waitMsgTarget){\r
- this.waitMsgTarget.unmask();\r
- }else{\r
- Ext.MessageBox.updateProgress(1);\r
- Ext.MessageBox.hide();\r
- }\r
- }\r
- if(success){\r
- if(o.reset){\r
- this.reset();\r
- }\r
- Ext.callback(o.success, o.scope, [this, action]);\r
- this.fireEvent('actioncomplete', this, action);\r
- }else{\r
- Ext.callback(o.failure, o.scope, [this, action]);\r
- this.fireEvent('actionfailed', this, action);\r
- }\r
- },\r
-\r
- /**\r
- * Find a Ext.form.Field in this form by id, dataIndex, name or hiddenName.\r
- * @param {String} id The value to search for\r
- * @return Field\r
- */\r
- findField : function(id){\r
- var field = this.items.get(id);\r
- if(!field){\r
- this.items.each(function(f){\r
- if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){\r
- field = f;\r
- return false;\r
- }\r
- });\r
- }\r
- return field || null;\r
- },\r
-\r
-\r
- /**\r
- * Mark fields in this form invalid in bulk.\r
- * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}\r
- * @return {BasicForm} this\r
- */\r
- markInvalid : function(errors){\r
- if(Ext.isArray(errors)){\r
- for(var i = 0, len = errors.length; i < len; i++){\r
- var fieldError = errors[i];\r
- var f = this.findField(fieldError.id);\r
- if(f){\r
- f.markInvalid(fieldError.msg);\r
- }\r
- }\r
- }else{\r
- var field, id;\r
- for(id in errors){\r
- if(typeof errors[id] != 'function' && (field = this.findField(id))){\r
- field.markInvalid(errors[id]);\r
- }\r
- }\r
- }\r
- return this;\r
- },\r
-\r
- /**\r
- * Set values for fields in this form in bulk.\r
- * @param {Array/Object} values Either an array in the form:<br><br><code><pre>\r
-[{id:'clientName', value:'Fred. Olsen Lines'},\r
- {id:'portOfLoading', value:'FXT'},\r
- {id:'portOfDischarge', value:'OSL'} ]</pre></code><br><br>\r
- * or an object hash of the form:<br><br><code><pre>\r
-{\r
- clientName: 'Fred. Olsen Lines',\r
- portOfLoading: 'FXT',\r
- portOfDischarge: 'OSL'\r
-}</pre></code><br>\r
- * @return {BasicForm} this\r
- */\r
- setValues : function(values){\r
- if(Ext.isArray(values)){ // array of objects\r
- for(var i = 0, len = values.length; i < len; i++){\r
- var v = values[i];\r
- var f = this.findField(v.id);\r
- if(f){\r
- f.setValue(v.value);\r
- if(this.trackResetOnLoad){\r
- f.originalValue = f.getValue();\r
- }\r
- }\r
- }\r
- }else{ // object hash\r
- var field, id;\r
- for(id in values){\r
- if(typeof values[id] != 'function' && (field = this.findField(id))){\r
- field.setValue(values[id]);\r
- if(this.trackResetOnLoad){\r
- field.originalValue = field.getValue();\r
- }\r
- }\r
- }\r
- }\r
- return this;\r
- },\r
-\r
- /**\r
- * <p>Returns the fields in this form as an object with key/value pairs as they would be submitted using a standard form submit.\r
- * If multiple fields exist with the same name they are returned as an array.</p>\r
- *\r
- * <p><b>Note:</b> The values are collected from all enabled HTML input elements within the form, <u>not</u> from\r
- * the Ext Field objects. This means that all returned values are Strings (or Arrays of Strings) and that the the\r
- * value can potentionally be the emptyText of a field.</p>\r
- * @param {Boolean} asString (optional) false to return the values as an object (defaults to returning as a string)\r
- * @return {String/Object}\r
- */\r
- getValues : function(asString){\r
- var fs = Ext.lib.Ajax.serializeForm(this.el.dom);\r
- if(asString === true){\r
- return fs;\r
- }\r
- return Ext.urlDecode(fs);\r
- },\r
-\r
- /**\r
- * Clears all invalid messages in this form.\r
- * @return {BasicForm} this\r
- */\r
- clearInvalid : function(){\r
- this.items.each(function(f){\r
- f.clearInvalid();\r
- });\r
- return this;\r
- },\r
-\r
- /**\r
- * Resets this form.\r
- * @return {BasicForm} this\r
- */\r
- reset : function(){\r
- this.items.each(function(f){\r
- f.reset();\r
- });\r
- return this;\r
- },\r
-\r
- /**\r
- * Add Ext.form Components to this form's Collection. This does not result in rendering of\r
- * the passed Component, it just enables the form to validate Fields, and distribute values to\r
- * Fields.\r
- * <p><b>You will not usually call this function. In order to be rendered, a Field must be added\r
- * to a {@link Ext.Container Container}, usually an {@link Ext.form.FormPanel FormPanel}.\r
- * The FormPanel to which the field is added takes care of adding the Field to the BasicForm's\r
- * collection.</b></p>\r
- * @param {Field} field1\r
- * @param {Field} field2 (optional)\r
- * @param {Field} etc (optional)\r
- * @return {BasicForm} this\r
- */\r
- add : function(){\r
- this.items.addAll(Array.prototype.slice.call(arguments, 0));\r
- return this;\r
- },\r
-\r
-\r
- /**\r
- * Removes a field from the items collection (does NOT remove its markup).\r
- * @param {Field} field\r
- * @return {BasicForm} this\r
- */\r
- remove : function(field){\r
- this.items.remove(field);\r
- return this;\r
- },\r
-\r
- /**\r
- * Iterates through the {@link Ext.form.Field Field}s which have been {@link #add add}ed to this BasicForm,\r
- * checks them for an id attribute, and calls {@link Ext.form.Field#applyToMarkup} on the existing dom element with that id.\r
- * @return {BasicForm} this\r
- */\r
- render : function(){\r
- this.items.each(function(f){\r
- if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists\r
- f.applyToMarkup(f.id);\r
- }\r
- });\r
- return this;\r
- },\r
-\r
- /**\r
- * Calls {@link Ext#apply} for all fields in this form with the passed object.\r
- * @param {Object} values\r
- * @return {BasicForm} this\r
- */\r
- applyToFields : function(o){\r
- this.items.each(function(f){\r
- Ext.apply(f, o);\r
- });\r
- return this;\r
- },\r
-\r
- /**\r
- * Calls {@link Ext#applyIf} for all field in this form with the passed object.\r
- * @param {Object} values\r
- * @return {BasicForm} this\r
- */\r
- applyIfToFields : function(o){\r
- this.items.each(function(f){\r
- Ext.applyIf(f, o);\r
- });\r
- return this;\r
- }\r
-});\r
-\r
-// back compat\r
-Ext.BasicForm = Ext.form.BasicForm;
\ No newline at end of file