Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
27 jpm 1
/*
2
 * Ext JS Library 2.0.2
3
 * Copyright(c) 2006-2008, Ext JS, LLC.
4
 * licensing@extjs.com
5
 *
6
 * http://extjs.com/license
7
 */
8
 
9
/**
10
 * @class Ext.form.FormPanel
11
 * @extends Ext.Panel
12
 * Standard form container.
13
 * <p><b>Although they are not listed, this class also accepts all the config options required to configure its internal {@link Ext.form.BasicForm}</b></p>
14
 * <br><br>
15
 * FormPanel uses a {@link Ext.layout.FormLayout} internally, and that is required for fields and labels to work correctly
16
 * within the FormPanel's layout.  To nest additional layout styles within a FormPanel, you should nest additional Panels
17
 * or other containers that can provide additional layout functionality. <b>You should not override FormPanel's layout.</b>
18
 * <br><br>
19
 * By default, Ext Forms are submitted through Ajax, using {@link Ext.form.Action}.
20
 * To enable normal browser submission of the Ext Form contained in this FormPanel,
21
 * override the Form's onSubmit, and submit methods:<br><br><pre><code>
22
    var myForm = new Ext.form.FormPanel({
23
        onSubmit: Ext.emptyFn,
24
        submit: function() {
25
            this.getForm().getEl().dom.submit();
26
        }
27
    });</code></pre><br>
28
 * @constructor
29
 * @param {Object} config Configuration options
30
 */
31
Ext.FormPanel = Ext.extend(Ext.Panel, {
32
	/**
33
	 * @cfg {String} formId (optional) The id of the FORM tag (defaults to an auto-generated id).
34
	 */
35
    /**
36
     * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
37
     */
38
    /**
39
     * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
40
     */
41
    /**
42
     * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
43
     */
44
    buttonAlign:'center',
45
 
46
    /**
47
     * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
48
     */
49
    minButtonWidth:75,
50
 
51
    /**
52
     * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
53
     * This property cascades to child containers if not set.
54
     */
55
    labelAlign:'left',
56
 
57
    /**
58
     * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
59
     * fires a looping event with that state. This is required to bind buttons to the valid
60
     * state using the config value formBind:true on the button.
61
     */
62
    monitorValid : false,
63
 
64
    /**
65
     * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
66
     */
67
    monitorPoll : 200,
68
 
69
    /**
70
     * @cfg {String} layout @hide
71
     */
72
    layout: 'form',
73
 
74
    // private
75
    initComponent :function(){
76
        this.form = this.createForm();
77
 
78
        Ext.FormPanel.superclass.initComponent.call(this);
79
 
80
        this.addEvents(
81
            /**
82
             * @event clientvalidation
83
             * If the monitorValid config option is true, this event fires repetitively to notify of valid state
84
             * @param {Ext.form.FormPanel} this
85
             * @param {Boolean} valid true if the form has passed client-side validation
86
             */
87
            'clientvalidation'
88
        );
89
 
90
        this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']);
91
    },
92
 
93
    // private
94
    createForm: function(){
95
        delete this.initialConfig.listeners;
96
        return new Ext.form.BasicForm(null, this.initialConfig);
97
    },
98
 
99
    // private
100
    initFields : function(){
101
        var f = this.form;
102
        var formPanel = this;
103
        var fn = function(c){
104
            if(c.doLayout && c != formPanel){
105
                Ext.applyIf(c, {
106
                    labelAlign: c.ownerCt.labelAlign,
107
                    labelWidth: c.ownerCt.labelWidth,
108
                    itemCls: c.ownerCt.itemCls
109
                });
110
                if(c.items){
111
                    c.items.each(fn);
112
                }
113
            }else if(c.isFormField){
114
                f.add(c);
115
            }
116
        }
117
        this.items.each(fn);
118
    },
119
 
120
    // private
121
    getLayoutTarget : function(){
122
        return this.form.el;
123
    },
124
 
125
    /**
126
     * Provides access to the {@link Ext.form.BasicForm Form} which this Panel contains.
127
     * @return {Ext.form.BasicForm} The {@link Ext.form.BasicForm Form} which this Panel contains.
128
     */
129
    getForm : function(){
130
        return this.form;
131
    },
132
 
133
    // private
134
    onRender : function(ct, position){
135
        this.initFields();
136
 
137
        Ext.FormPanel.superclass.onRender.call(this, ct, position);
138
        var o = {
139
            tag: 'form',
140
            method : this.method || 'POST',
141
            id : this.formId || Ext.id()
142
        };
143
        if(this.fileUpload) {
144
            o.enctype = 'multipart/form-data';
145
        }
146
        this.form.initEl(this.body.createChild(o));
147
    },
148
 
149
    // private
150
    beforeDestroy: function(){
151
        Ext.FormPanel.superclass.beforeDestroy.call(this);
152
        Ext.destroy(this.form);
153
    },
154
 
155
    // private
156
    initEvents : function(){
157
        Ext.FormPanel.superclass.initEvents.call(this);
158
		this.items.on('remove', this.onRemove, this);
159
		this.items.on('add', this.onAdd, this);
160
        if(this.monitorValid){ // initialize after render
161
            this.startMonitoring();
162
        }
163
    },
164
 
165
    // private
166
	onAdd : function(ct, c) {
167
		if (c.isFormField) {
168
			this.form.add(c);
169
		}
170
	},
171
 
172
	// private
173
	onRemove : function(c) {
174
		if (c.isFormField) {
175
			Ext.destroy(c.container.up('.x-form-item'));
176
			this.form.remove(c);
177
		}
178
	},
179
 
180
    /**
181
     * Starts monitoring of the valid state of this form. Usually this is done by passing the config
182
     * option "monitorValid"
183
     */
184
    startMonitoring : function(){
185
        if(!this.bound){
186
            this.bound = true;
187
            Ext.TaskMgr.start({
188
                run : this.bindHandler,
189
                interval : this.monitorPoll || 200,
190
                scope: this
191
            });
192
        }
193
    },
194
 
195
    /**
196
     * Stops monitoring of the valid state of this form
197
     */
198
    stopMonitoring : function(){
199
        this.bound = false;
200
    },
201
 
202
    /**
203
     * This is a proxy for the underlying BasicForm's {@link Ext.form.BasicForm#load} call.
204
     * @param {Object} options The options to pass to the action (see {@link Ext.form.BasicForm#doAction} for details)
205
     */
206
    load : function(){
207
        this.form.load.apply(this.form, arguments);
208
    },
209
 
210
    // private
211
    onDisable : function(){
212
        Ext.FormPanel.superclass.onDisable.call(this);
213
        if(this.form){
214
            this.form.items.each(function(){
215
                 this.disable();
216
            });
217
        }
218
    },
219
 
220
    // private
221
    onEnable : function(){
222
        Ext.FormPanel.superclass.onEnable.call(this);
223
        if(this.form){
224
            this.form.items.each(function(){
225
                 this.enable();
226
            });
227
        }
228
    },
229
 
230
    // private
231
    bindHandler : function(){
232
        if(!this.bound){
233
            return false; // stops binding
234
        }
235
        var valid = true;
236
        this.form.items.each(function(f){
237
            if(!f.isValid(true)){
238
                valid = false;
239
                return false;
240
            }
241
        });
242
        if(this.buttons){
243
            for(var i = 0, len = this.buttons.length; i < len; i++){
244
                var btn = this.buttons[i];
245
                if(btn.formBind === true && btn.disabled === valid){
246
                    btn.setDisabled(!valid);
247
                }
248
            }
249
        }
250
        this.fireEvent('clientvalidation', this, valid);
251
    }
252
});
253
Ext.reg('form', Ext.FormPanel);
254
 
255
Ext.form.FormPanel = Ext.FormPanel;
256