Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/web/ext/src/widgets/form/Action.js @ 81

Revision 76, 26.3 KB checked in by djay, 13 years ago (diff)

Ajout du répertoire web

  • Property svn:executable set to *
Line 
1/*!
2 * Ext JS Library 3.4.0
3 * Copyright(c) 2006-2011 Sencha Inc.
4 * licensing@sencha.com
5 * http://www.sencha.com/license
6 */
7/**
8 * @class Ext.form.Action
9 * <p>The subclasses of this class provide actions to perform upon {@link Ext.form.BasicForm Form}s.</p>
10 * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
11 * the Form needs to perform an action such as submit or load. The Configuration options
12 * listed for this class are set through the Form's action methods: {@link Ext.form.BasicForm#submit submit},
13 * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}</p>
14 * <p>The instance of Action which performed the action is passed to the success
15 * and failure callbacks of the Form's action methods ({@link Ext.form.BasicForm#submit submit},
16 * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}),
17 * and to the {@link Ext.form.BasicForm#actioncomplete actioncomplete} and
18 * {@link Ext.form.BasicForm#actionfailed actionfailed} event handlers.</p>
19 */
20Ext.form.Action = function(form, options){
21    this.form = form;
22    this.options = options || {};
23};
24
25/**
26 * Failure type returned when client side validation of the Form fails
27 * thus aborting a submit action. Client side validation is performed unless
28 * {@link #clientValidation} is explicitly set to <tt>false</tt>.
29 * @type {String}
30 * @static
31 */
32Ext.form.Action.CLIENT_INVALID = 'client';
33/**
34 * <p>Failure type returned when server side processing fails and the {@link #result}'s
35 * <tt style="font-weight:bold">success</tt> property is set to <tt>false</tt>.</p>
36 * <p>In the case of a form submission, field-specific error messages may be returned in the
37 * {@link #result}'s <tt style="font-weight:bold">errors</tt> property.</p>
38 * @type {String}
39 * @static
40 */
41Ext.form.Action.SERVER_INVALID = 'server';
42/**
43 * Failure type returned when a communication error happens when attempting
44 * to send a request to the remote server. The {@link #response} may be examined to
45 * provide further information.
46 * @type {String}
47 * @static
48 */
49Ext.form.Action.CONNECT_FAILURE = 'connect';
50/**
51 * Failure type returned when the response's <tt style="font-weight:bold">success</tt>
52 * property is set to <tt>false</tt>, or no field values are returned in the response's
53 * <tt style="font-weight:bold">data</tt> property.
54 * @type {String}
55 * @static
56 */
57Ext.form.Action.LOAD_FAILURE = 'load';
58
59Ext.form.Action.prototype = {
60/**
61 * @cfg {String} url The URL that the Action is to invoke.
62 */
63/**
64 * @cfg {Boolean} reset When set to <tt><b>true</b></tt>, causes the Form to be
65 * {@link Ext.form.BasicForm.reset reset} on Action success. If specified, this happens
66 * <b>before</b> the {@link #success} callback is called and before the Form's
67 * {@link Ext.form.BasicForm.actioncomplete actioncomplete} event fires.
68 */
69/**
70 * @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the
71 * {@link Ext.form.BasicForm}'s method, or if that is not specified, the underlying DOM form's method.
72 */
73/**
74 * @cfg {Mixed} params <p>Extra parameter values to pass. These are added to the Form's
75 * {@link Ext.form.BasicForm#baseParams} and passed to the specified URL along with the Form's
76 * input fields.</p>
77 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
78 */
79/**
80 * @cfg {Number} timeout The number of seconds to wait for a server response before
81 * failing with the {@link #failureType} as {@link #Action.CONNECT_FAILURE}. If not specified,
82 * defaults to the configured <tt>{@link Ext.form.BasicForm#timeout timeout}</tt> of the
83 * {@link Ext.form.BasicForm form}.
84 */
85/**
86 * @cfg {Function} success The function to call when a valid success return packet is recieved.
87 * The function is passed the following parameters:<ul class="mdetail-params">
88 * <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
89 * <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. The {@link #result}
90 * property of this object may be examined to perform custom postprocessing.</div></li>
91 * </ul>
92 */
93/**
94 * @cfg {Function} failure The function to call when a failure packet was recieved, or when an
95 * error ocurred in the Ajax communication.
96 * The function is passed the following parameters:<ul class="mdetail-params">
97 * <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
98 * <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. If an Ajax
99 * error ocurred, the failure type will be in {@link #failureType}. The {@link #result}
100 * property of this object may be examined to perform custom postprocessing.</div></li>
101 * </ul>
102 */
103/**
104 * @cfg {Object} scope The scope in which to call the callback functions (The <tt>this</tt> reference
105 * for the callback functions).
106 */
107/**
108 * @cfg {String} waitMsg The message to be displayed by a call to {@link Ext.MessageBox#wait}
109 * during the time the action is being processed.
110 */
111/**
112 * @cfg {String} waitTitle The title to be displayed by a call to {@link Ext.MessageBox#wait}
113 * during the time the action is being processed.
114 */
115
116/**
117 * @cfg {Boolean} submitEmptyText If set to <tt>true</tt>, the emptyText value will be sent with the form
118 * when it is submitted.  Defaults to <tt>true</tt>.
119 */
120
121/**
122 * The type of action this Action instance performs.
123 * Currently only "submit" and "load" are supported.
124 * @type {String}
125 */
126    type : 'default',
127/**
128 * The type of failure detected will be one of these: {@link #CLIENT_INVALID},
129 * {@link #SERVER_INVALID}, {@link #CONNECT_FAILURE}, or {@link #LOAD_FAILURE}.  Usage:
130 * <pre><code>
131var fp = new Ext.form.FormPanel({
132...
133buttons: [{
134    text: 'Save',
135    formBind: true,
136    handler: function(){
137        if(fp.getForm().isValid()){
138            fp.getForm().submit({
139                url: 'form-submit.php',
140                waitMsg: 'Submitting your data...',
141                success: function(form, action){
142                    // server responded with success = true
143                    var result = action.{@link #result};
144                },
145                failure: function(form, action){
146                    if (action.{@link #failureType} === Ext.form.Action.{@link #CONNECT_FAILURE}) {
147                        Ext.Msg.alert('Error',
148                            'Status:'+action.{@link #response}.status+': '+
149                            action.{@link #response}.statusText);
150                    }
151                    if (action.failureType === Ext.form.Action.{@link #SERVER_INVALID}){
152                        // server responded with success = false
153                        Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
154                    }
155                }
156            });
157        }
158    }
159},{
160    text: 'Reset',
161    handler: function(){
162        fp.getForm().reset();
163    }
164}]
165 * </code></pre>
166 * @property failureType
167 * @type {String}
168 */
169 /**
170 * The XMLHttpRequest object used to perform the action.
171 * @property response
172 * @type {Object}
173 */
174 /**
175 * The decoded response object containing a boolean <tt style="font-weight:bold">success</tt> property and
176 * other, action-specific properties.
177 * @property result
178 * @type {Object}
179 */
180
181    // interface method
182    run : function(options){
183
184    },
185
186    // interface method
187    success : function(response){
188
189    },
190
191    // interface method
192    handleResponse : function(response){
193
194    },
195
196    // default connection failure
197    failure : function(response){
198        this.response = response;
199        this.failureType = Ext.form.Action.CONNECT_FAILURE;
200        this.form.afterAction(this, false);
201    },
202
203    // private
204    // shared code among all Actions to validate that there was a response
205    // with either responseText or responseXml
206    processResponse : function(response){
207        this.response = response;
208        if(!response.responseText && !response.responseXML){
209            return true;
210        }
211        this.result = this.handleResponse(response);
212        return this.result;
213    },
214   
215    decodeResponse: function(response) {
216        try {
217            return Ext.decode(response.responseText);
218        } catch(e) {
219            return false;
220        } 
221    },
222
223    // utility functions used internally
224    getUrl : function(appendParams){
225        var url = this.options.url || this.form.url || this.form.el.dom.action;
226        if(appendParams){
227            var p = this.getParams();
228            if(p){
229                url = Ext.urlAppend(url, p);
230            }
231        }
232        return url;
233    },
234
235    // private
236    getMethod : function(){
237        return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
238    },
239
240    // private
241    getParams : function(){
242        var bp = this.form.baseParams;
243        var p = this.options.params;
244        if(p){
245            if(typeof p == "object"){
246                p = Ext.urlEncode(Ext.applyIf(p, bp));
247            }else if(typeof p == 'string' && bp){
248                p += '&' + Ext.urlEncode(bp);
249            }
250        }else if(bp){
251            p = Ext.urlEncode(bp);
252        }
253        return p;
254    },
255
256    // private
257    createCallback : function(opts){
258        var opts = opts || {};
259        return {
260            success: this.success,
261            failure: this.failure,
262            scope: this,
263            timeout: (opts.timeout*1000) || (this.form.timeout*1000),
264            upload: this.form.fileUpload ? this.success : undefined
265        };
266    }
267};
268
269/**
270 * @class Ext.form.Action.Submit
271 * @extends Ext.form.Action
272 * <p>A class which handles submission of data from {@link Ext.form.BasicForm Form}s
273 * and processes the returned response.</p>
274 * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
275 * {@link Ext.form.BasicForm#submit submit}ting.</p>
276 * <p><u><b>Response Packet Criteria</b></u></p>
277 * <p>A response packet may contain:
278 * <div class="mdetail-params"><ul>
279 * <li><b><code>success</code></b> property : Boolean
280 * <div class="sub-desc">The <code>success</code> property is required.</div></li>
281 * <li><b><code>errors</code></b> property : Object
282 * <div class="sub-desc"><div class="sub-desc">The <code>errors</code> property,
283 * which is optional, contains error messages for invalid fields.</div></li>
284 * </ul></div>
285 * <p><u><b>JSON Packets</b></u></p>
286 * <p>By default, response packets are assumed to be JSON, so a typical response
287 * packet may look like this:</p><pre><code>
288{
289    success: false,
290    errors: {
291        clientCode: "Client not found",
292        portOfLoading: "This field must not be null"
293    }
294}</code></pre>
295 * <p>Other data may be placed into the response for processing by the {@link Ext.form.BasicForm}'s callback
296 * or event handler methods. The object decoded from this JSON is available in the
297 * {@link Ext.form.Action#result result} property.</p>
298 * <p>Alternatively, if an {@link #errorReader} is specified as an {@link Ext.data.XmlReader XmlReader}:</p><pre><code>
299    errorReader: new Ext.data.XmlReader({
300            record : 'field',
301            success: '@success'
302        }, [
303            'id', 'msg'
304        ]
305    )
306</code></pre>
307 * <p>then the results may be sent back in XML format:</p><pre><code>
308&lt;?xml version="1.0" encoding="UTF-8"?&gt;
309&lt;message success="false"&gt;
310&lt;errors&gt;
311    &lt;field&gt;
312        &lt;id&gt;clientCode&lt;/id&gt;
313        &lt;msg&gt;&lt;![CDATA[Code not found. &lt;br /&gt;&lt;i&gt;This is a test validation message from the server &lt;/i&gt;]]&gt;&lt;/msg&gt;
314    &lt;/field&gt;
315    &lt;field&gt;
316        &lt;id&gt;portOfLoading&lt;/id&gt;
317        &lt;msg&gt;&lt;![CDATA[Port not found. &lt;br /&gt;&lt;i&gt;This is a test validation message from the server &lt;/i&gt;]]&gt;&lt;/msg&gt;
318    &lt;/field&gt;
319&lt;/errors&gt;
320&lt;/message&gt;
321</code></pre>
322 * <p>Other elements may be placed into the response XML for processing by the {@link Ext.form.BasicForm}'s callback
323 * or event handler methods. The XML document is available in the {@link #errorReader}'s {@link Ext.data.XmlReader#xmlData xmlData} property.</p>
324 */
325Ext.form.Action.Submit = function(form, options){
326    Ext.form.Action.Submit.superclass.constructor.call(this, form, options);
327};
328
329Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
330    /**
331     * @cfg {Ext.data.DataReader} errorReader <p><b>Optional. JSON is interpreted with
332     * no need for an errorReader.</b></p>
333     * <p>A Reader which reads a single record from the returned data. The DataReader's
334     * <b>success</b> property specifies how submission success is determined. The Record's
335     * data provides the error messages to apply to any invalid form Fields.</p>
336     */
337    /**
338     * @cfg {boolean} clientValidation Determines whether a Form's fields are validated
339     * in a final call to {@link Ext.form.BasicForm#isValid isValid} prior to submission.
340     * Pass <tt>false</tt> in the Form's submit options to prevent this. If not defined, pre-submission field validation
341     * is performed.
342     */
343    type : 'submit',
344
345    // private
346    run : function(){
347        var o = this.options,
348            method = this.getMethod(),
349            isGet = method == 'GET';
350        if(o.clientValidation === false || this.form.isValid()){
351            if (o.submitEmptyText === false) {
352                var fields = this.form.items,
353                    emptyFields = [],
354                    setupEmptyFields = function(f){
355                        if (f.el.getValue() == f.emptyText) {
356                            emptyFields.push(f);
357                            f.el.dom.value = "";
358                        }
359                        if(f.isComposite && f.rendered){
360                            f.items.each(setupEmptyFields);
361                        }
362                    };
363                   
364                fields.each(setupEmptyFields);
365            }
366            Ext.Ajax.request(Ext.apply(this.createCallback(o), {
367                form:this.form.el.dom,
368                url:this.getUrl(isGet),
369                method: method,
370                headers: o.headers,
371                params:!isGet ? this.getParams() : null,
372                isUpload: this.form.fileUpload
373            }));
374            if (o.submitEmptyText === false) {
375                Ext.each(emptyFields, function(f) {
376                    if (f.applyEmptyText) {
377                        f.applyEmptyText();
378                    }
379                });
380            }
381        }else if (o.clientValidation !== false){ // client validation failed
382            this.failureType = Ext.form.Action.CLIENT_INVALID;
383            this.form.afterAction(this, false);
384        }
385    },
386
387    // private
388    success : function(response){
389        var result = this.processResponse(response);
390        if(result === true || result.success){
391            this.form.afterAction(this, true);
392            return;
393        }
394        if(result.errors){
395            this.form.markInvalid(result.errors);
396        }
397        this.failureType = Ext.form.Action.SERVER_INVALID;
398        this.form.afterAction(this, false);
399    },
400
401    // private
402    handleResponse : function(response){
403        if(this.form.errorReader){
404            var rs = this.form.errorReader.read(response);
405            var errors = [];
406            if(rs.records){
407                for(var i = 0, len = rs.records.length; i < len; i++) {
408                    var r = rs.records[i];
409                    errors[i] = r.data;
410                }
411            }
412            if(errors.length < 1){
413                errors = null;
414            }
415            return {
416                success : rs.success,
417                errors : errors
418            };
419        }
420        return this.decodeResponse(response);
421    }
422});
423
424
425/**
426 * @class Ext.form.Action.Load
427 * @extends Ext.form.Action
428 * <p>A class which handles loading of data from a server into the Fields of an {@link Ext.form.BasicForm}.</p>
429 * <p>Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
430 * {@link Ext.form.BasicForm#load load}ing.</p>
431 * <p><u><b>Response Packet Criteria</b></u></p>
432 * <p>A response packet <b>must</b> contain:
433 * <div class="mdetail-params"><ul>
434 * <li><b><code>success</code></b> property : Boolean</li>
435 * <li><b><code>data</code></b> property : Object</li>
436 * <div class="sub-desc">The <code>data</code> property contains the values of Fields to load.
437 * The individual value object for each Field is passed to the Field's
438 * {@link Ext.form.Field#setValue setValue} method.</div></li>
439 * </ul></div>
440 * <p><u><b>JSON Packets</b></u></p>
441 * <p>By default, response packets are assumed to be JSON, so for the following form load call:<pre><code>
442var myFormPanel = new Ext.form.FormPanel({
443    title: 'Client and routing info',
444    items: [{
445        fieldLabel: 'Client',
446        name: 'clientName'
447    }, {
448        fieldLabel: 'Port of loading',
449        name: 'portOfLoading'
450    }, {
451        fieldLabel: 'Port of discharge',
452        name: 'portOfDischarge'
453    }]
454});
455myFormPanel.{@link Ext.form.FormPanel#getForm getForm}().{@link Ext.form.BasicForm#load load}({
456    url: '/getRoutingInfo.php',
457    params: {
458        consignmentRef: myConsignmentRef
459    },
460    failure: function(form, action) {
461        Ext.Msg.alert("Load failed", action.result.errorMessage);
462    }
463});
464</code></pre>
465 * a <b>success response</b> packet may look like this:</p><pre><code>
466{
467    success: true,
468    data: {
469        clientName: "Fred. Olsen Lines",
470        portOfLoading: "FXT",
471        portOfDischarge: "OSL"
472    }
473}</code></pre>
474 * while a <b>failure response</b> packet may look like this:</p><pre><code>
475{
476    success: false,
477    errorMessage: "Consignment reference not found"
478}</code></pre>
479 * <p>Other data may be placed into the response for processing the {@link Ext.form.BasicForm Form}'s
480 * callback or event handler methods. The object decoded from this JSON is available in the
481 * {@link Ext.form.Action#result result} property.</p>
482 */
483Ext.form.Action.Load = function(form, options){
484    Ext.form.Action.Load.superclass.constructor.call(this, form, options);
485    this.reader = this.form.reader;
486};
487
488Ext.extend(Ext.form.Action.Load, Ext.form.Action, {
489    // private
490    type : 'load',
491
492    // private
493    run : function(){
494        Ext.Ajax.request(Ext.apply(
495                this.createCallback(this.options), {
496                    method:this.getMethod(),
497                    url:this.getUrl(false),
498                    headers: this.options.headers,
499                    params:this.getParams()
500        }));
501    },
502
503    // private
504    success : function(response){
505        var result = this.processResponse(response);
506        if(result === true || !result.success || !result.data){
507            this.failureType = Ext.form.Action.LOAD_FAILURE;
508            this.form.afterAction(this, false);
509            return;
510        }
511        this.form.clearInvalid();
512        this.form.setValues(result.data);
513        this.form.afterAction(this, true);
514    },
515
516    // private
517    handleResponse : function(response){
518        if(this.form.reader){
519            var rs = this.form.reader.read(response);
520            var data = rs.records && rs.records[0] ? rs.records[0].data : null;
521            return {
522                success : rs.success,
523                data : data
524            };
525        }
526        return this.decodeResponse(response);
527    }
528});
529
530
531
532/**
533 * @class Ext.form.Action.DirectLoad
534 * @extends Ext.form.Action.Load
535 * <p>Provides Ext.direct support for loading form data.</p>
536 * <p>This example illustrates usage of Ext.Direct to <b>load</b> a form through Ext.Direct.</p>
537 * <pre><code>
538var myFormPanel = new Ext.form.FormPanel({
539    // configs for FormPanel
540    title: 'Basic Information',
541    renderTo: document.body,
542    width: 300, height: 160,
543    padding: 10,
544
545    // configs apply to child items
546    defaults: {anchor: '100%'},
547    defaultType: 'textfield',
548    items: [{
549        fieldLabel: 'Name',
550        name: 'name'
551    },{
552        fieldLabel: 'Email',
553        name: 'email'
554    },{
555        fieldLabel: 'Company',
556        name: 'company'
557    }],
558
559    // configs for BasicForm
560    api: {
561        // The server-side method to call for load() requests
562        load: Profile.getBasicInfo,
563        // The server-side must mark the submit handler as a 'formHandler'
564        submit: Profile.updateBasicInfo
565    },
566    // specify the order for the passed params
567    paramOrder: ['uid', 'foo']
568});
569
570// load the form
571myFormPanel.getForm().load({
572    // pass 2 arguments to server side getBasicInfo method (len=2)
573    params: {
574        foo: 'bar',
575        uid: 34
576    }
577});
578 * </code></pre>
579 * The data packet sent to the server will resemble something like:
580 * <pre><code>
581[
582    {
583        "action":"Profile","method":"getBasicInfo","type":"rpc","tid":2,
584        "data":[34,"bar"] // note the order of the params
585    }
586]
587 * </code></pre>
588 * The form will process a data packet returned by the server that is similar
589 * to the following format:
590 * <pre><code>
591[
592    {
593        "action":"Profile","method":"getBasicInfo","type":"rpc","tid":2,
594        "result":{
595            "success":true,
596            "data":{
597                "name":"Fred Flintstone",
598                "company":"Slate Rock and Gravel",
599                "email":"fred.flintstone@slaterg.com"
600            }
601        }
602    }
603]
604 * </code></pre>
605 */
606Ext.form.Action.DirectLoad = Ext.extend(Ext.form.Action.Load, {
607    constructor: function(form, opts) {
608        Ext.form.Action.DirectLoad.superclass.constructor.call(this, form, opts);
609    },
610    type : 'directload',
611
612    run : function(){
613        var args = this.getParams();
614        args.push(this.success, this);
615        this.form.api.load.apply(window, args);
616    },
617
618    getParams : function() {
619        var buf = [], o = {};
620        var bp = this.form.baseParams;
621        var p = this.options.params;
622        Ext.apply(o, p, bp);
623        var paramOrder = this.form.paramOrder;
624        if(paramOrder){
625            for(var i = 0, len = paramOrder.length; i < len; i++){
626                buf.push(o[paramOrder[i]]);
627            }
628        }else if(this.form.paramsAsHash){
629            buf.push(o);
630        }
631        return buf;
632    },
633    // Direct actions have already been processed and therefore
634    // we can directly set the result; Direct Actions do not have
635    // a this.response property.
636    processResponse : function(result) {
637        this.result = result;
638        return result;
639    },
640
641    success : function(response, trans){
642        if(trans.type == Ext.Direct.exceptions.SERVER){
643            response = {};
644        }
645        Ext.form.Action.DirectLoad.superclass.success.call(this, response);
646    }
647});
648
649/**
650 * @class Ext.form.Action.DirectSubmit
651 * @extends Ext.form.Action.Submit
652 * <p>Provides Ext.direct support for submitting form data.</p>
653 * <p>This example illustrates usage of Ext.Direct to <b>submit</b> a form through Ext.Direct.</p>
654 * <pre><code>
655var myFormPanel = new Ext.form.FormPanel({
656    // configs for FormPanel
657    title: 'Basic Information',
658    renderTo: document.body,
659    width: 300, height: 160,
660    padding: 10,
661    buttons:[{
662        text: 'Submit',
663        handler: function(){
664            myFormPanel.getForm().submit({
665                params: {
666                    foo: 'bar',
667                    uid: 34
668                }
669            });
670        }
671    }],
672
673    // configs apply to child items
674    defaults: {anchor: '100%'},
675    defaultType: 'textfield',
676    items: [{
677        fieldLabel: 'Name',
678        name: 'name'
679    },{
680        fieldLabel: 'Email',
681        name: 'email'
682    },{
683        fieldLabel: 'Company',
684        name: 'company'
685    }],
686
687    // configs for BasicForm
688    api: {
689        // The server-side method to call for load() requests
690        load: Profile.getBasicInfo,
691        // The server-side must mark the submit handler as a 'formHandler'
692        submit: Profile.updateBasicInfo
693    },
694    // specify the order for the passed params
695    paramOrder: ['uid', 'foo']
696});
697 * </code></pre>
698 * The data packet sent to the server will resemble something like:
699 * <pre><code>
700{
701    "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",
702    "result":{
703        "success":true,
704        "id":{
705            "extAction":"Profile","extMethod":"updateBasicInfo",
706            "extType":"rpc","extTID":"6","extUpload":"false",
707            "name":"Aaron Conran","email":"aaron@extjs.com","company":"Ext JS, LLC"
708        }
709    }
710}
711 * </code></pre>
712 * The form will process a data packet returned by the server that is similar
713 * to the following:
714 * <pre><code>
715// sample success packet (batched requests)
716[
717    {
718        "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":3,
719        "result":{
720            "success":true
721        }
722    }
723]
724
725// sample failure packet (one request)
726{
727        "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",
728        "result":{
729            "errors":{
730                "email":"already taken"
731            },
732            "success":false,
733            "foo":"bar"
734        }
735}
736 * </code></pre>
737 * Also see the discussion in {@link Ext.form.Action.DirectLoad}.
738 */
739Ext.form.Action.DirectSubmit = Ext.extend(Ext.form.Action.Submit, {
740    constructor : function(form, opts) {
741        Ext.form.Action.DirectSubmit.superclass.constructor.call(this, form, opts);
742    },
743    type : 'directsubmit',
744    // override of Submit
745    run : function(){
746        var o = this.options;
747        if(o.clientValidation === false || this.form.isValid()){
748            // tag on any additional params to be posted in the
749            // form scope
750            this.success.params = this.getParams();
751            this.form.api.submit(this.form.el.dom, this.success, this);
752        }else if (o.clientValidation !== false){ // client validation failed
753            this.failureType = Ext.form.Action.CLIENT_INVALID;
754            this.form.afterAction(this, false);
755        }
756    },
757
758    getParams : function() {
759        var o = {};
760        var bp = this.form.baseParams;
761        var p = this.options.params;
762        Ext.apply(o, p, bp);
763        return o;
764    },
765    // Direct actions have already been processed and therefore
766    // we can directly set the result; Direct Actions do not have
767    // a this.response property.
768    processResponse : function(result) {
769        this.result = result;
770        return result;
771    },
772
773    success : function(response, trans){
774        if(trans.type == Ext.Direct.exceptions.SERVER){
775            response = {};
776        }
777        Ext.form.Action.DirectSubmit.superclass.success.call(this, response);
778    }
779});
780
781Ext.form.Action.ACTION_TYPES = {
782    'load' : Ext.form.Action.Load,
783    'submit' : Ext.form.Action.Submit,
784    'directload' : Ext.form.Action.DirectLoad,
785    'directsubmit' : Ext.form.Action.DirectSubmit
786};
Note: See TracBrowser for help on using the repository browser.