/*
* Ext JS Library 2.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.form.BasicForm
* @extends Ext.util.Observable
* Supplies the functionality to do "actions" on forms and initialize Ext.form.Field types on existing markup.
*
* By default, Ext Forms are submitted through Ajax, using {@link Ext.form.Action}.
* To enable normal browser submission of an Ext Form, use the {@link #standardSubmit} config option.
* @constructor
* @param {Mixed} el The form element or its id
* @param {Object} config Configuration options
*/
Ext.form.BasicForm = function(el, config){
Ext.apply(this, config);
/*
* The Ext.form.Field items in this form.
* @type MixedCollection
*/
this.items = new Ext.util.MixedCollection(false, function(o){
return o.id || (o.id = Ext.id());
});
this.addEvents(
/**
* @event beforeaction
* Fires before any action is performed. Return false to cancel the action.
* @param {Form} this
* @param {Action} action The {@link Ext.form.Action} to be performed
*/
'beforeaction',
/**
* @event actionfailed
* Fires when an action fails.
* @param {Form} this
* @param {Action} action The {@link Ext.form.Action} that failed
*/
'actionfailed',
/**
* @event actioncomplete
* Fires when an action is completed.
* @param {Form} this
* @param {Action} action The {@link Ext.form.Action} that completed
*/
'actioncomplete'
);
if(el){
this.initEl(el);
}
Ext.form.BasicForm.superclass.constructor.call(this);
};
Ext.extend(Ext.form.BasicForm, Ext.util.Observable, {
/**
* @cfg {String} method
* The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
*/
/**
* @cfg {DataReader} reader
* An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read data when executing "load" actions.
* This is optional as there is built-in support for processing JSON.
*/
/**
* @cfg {DataReader} errorReader
* An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
* This is completely optional as there is built-in support for processing JSON.
*/
/**
* @cfg {String} url
* The URL to use for form actions if one isn't supplied in the action options.
*/
/**
* @cfg {Boolean} fileUpload
* Set to true if this form is a file upload.
*
File uploads are not performed using normal "Ajax" techniques, that is they are not * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the * DOM <form> element temporarily modified to have its * target set to refer * to a dynamically generated, hidden <iframe> which is inserted into the document * but removed after the return data has been gathered.
*The server response is parsed by the browser to create the document for the IFRAME. If the * server is using JSON to send the return object, then the * Content-Type header * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.
*The response text is retrieved from the document, and a fake XMLHttpRequest object * is created containing a responseText property in order to conform to the * requirements of event handlers and callbacks.
*Be aware that file upload packets are sent with the content type multipart/form * and some server technologies (notably JEE) may require some custom processing in order to * retrieve parameter names and parameter values from the packet content.
*/ /** * @cfg {Object} baseParams * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}. */ /** * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds). */ timeout: 30, // private activeAction : null, /** * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded * or setValues() data instead of when the form was first created. */ trackResetOnLoad : false, /** * @cfg {Boolean} standardSubmit If set to true, standard HTML form submits are used instead of XHR (Ajax) style * form submissions. (defaults to false) */ /** * By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific * element by passing it or its id or mask the form itself by passing in true. * @type Mixed * @property waitMsgTarget */ // private initEl : function(el){ this.el = Ext.get(el); this.id = this.el.id || Ext.id(); if(!this.standardSubmit){ this.el.on('submit', this.onSubmit, this); } this.el.addClass('x-form'); }, /** * Get the HTML form Element * @return Ext.Element */ getEl: function(){ return this.el; }, // private onSubmit : function(e){ e.stopEvent(); }, // private destroy: function() { this.items.each(function(f){ Ext.destroy(f); }); if(this.el){ this.el.removeAllListeners(); this.el.remove(); } this.purgeListeners(); }, /** * Returns true if client-side validation on the form is successful. * @return Boolean */ isValid : function(){ var valid = true; this.items.each(function(f){ if(!f.validate()){ valid = false; } }); return valid; }, /** * Returns true if any fields in this form have changed since their original load. * @return Boolean */ isDirty : function(){ var dirty = false; this.items.each(function(f){ if(f.isDirty()){ dirty = true; return false; } }); return dirty; }, /** * Performs a predefined action ({@link Ext.form.Action.Submit} or * {@link Ext.form.Action.Load}) or a custom extension of {@link Ext.form.Action} * to perform application-specific processing. * @param {String/Object} actionName The name of the predefined action type, * or instance of {@link Ext.form.Action} to perform. * @param {Object} options (optional) The options to pass to the {@link Ext.form.Action}. * All of the config options listed below are supported by both the submit * and load actions unless otherwise noted (custom actions could also accept * other config options):The url for the action (defaults * to the form's url.)
The form method to use (defaults * to the form's method, or POST if not defined)
The params to pass * (defaults to the form's baseParams, or none if not defined)
Request headers to set for the action * (defaults to the form's default headers)
The callback that will * be invoked after a successful response. Note that this is HTTP success * (the transaction was sent and received correctly), but the resulting response data * can still contain data errors. The function is passed the following parameters:
form : Ext.form.BasicFormaction : Ext.form.ActionThe callback that will * be invoked after a failed transaction attempt. Note that this is HTTP failure, * which means a non-successful HTTP code was returned from the server. The function * is passed the following parameters:
form : Ext.form.BasicFormaction : Ext.form.ActionThe scope in which to call the * callback functions (The this reference for the callback functions).
Submit Action only. * Determines whether a Form's fields are validated in a final call to * {@link Ext.form.BasicForm#isValid isValid} prior to submission. Set to false * to prevent this. If undefined, pre-submission field validation is performed.
[{id:'clientName', value:'Fred. Olsen Lines'},
{id:'portOfLoading', value:'FXT'},
{id:'portOfDischarge', value:'OSL'} ]
{
clientName: 'Fred. Olsen Lines',
portOfLoading: 'FXT',
portOfDischarge: 'OSL'
}