]>
Commit | Line | Data |
---|---|---|
947f0963 TL |
1 | /** |
2 | * Provides Ext Direct support for loading form data. | |
3 | * | |
4 | * This example illustrates usage of Ext Direct to load a form. | |
5 | * | |
6 | * var myFormPanel = new Ext.form.Panel({ | |
7 | * // configs for FormPanel | |
8 | * title: 'Basic Information', | |
9 | * renderTo: document.body, | |
10 | * width: 300, height: 160, | |
11 | * padding: 10, | |
12 | * | |
13 | * // configs apply to child items | |
14 | * defaults: {anchor: '100%'}, | |
15 | * defaultType: 'textfield', | |
16 | * items: [{ | |
17 | * fieldLabel: 'Name', | |
18 | * name: 'name' | |
19 | * },{ | |
20 | * fieldLabel: 'Email', | |
21 | * name: 'email' | |
22 | * },{ | |
23 | * fieldLabel: 'Company', | |
24 | * name: 'company' | |
25 | * }], | |
26 | * | |
27 | * // configs for BasicForm | |
28 | * api: { | |
29 | * // The server-side method to call for load() requests | |
30 | * load: 'Profile.getBasicInfo', | |
31 | * // The server-side must mark the submit handler as a 'formHandler' | |
32 | * submit: 'Profile.updateBasicInfo' | |
33 | * }, | |
34 | * // specify the order for the passed params | |
35 | * paramOrder: ['uid', 'foo'] | |
36 | * }); | |
37 | * | |
38 | * // load the form | |
39 | * myFormPanel.getForm().load({ | |
40 | * // pass 2 arguments to server side getBasicInfo method (len=2) | |
41 | * params: { | |
42 | * foo: 'bar', | |
43 | * uid: 34 | |
44 | * } | |
45 | * }); | |
46 | * | |
47 | * Before using DirectLoad action, make sure you set up Ext Direct remoting provider. | |
48 | * See {@link Ext.direct.Manager} for more information. | |
49 | * | |
50 | * For corresponding submit action, see {@link Ext.form.action.DirectSubmit}. | |
51 | */ | |
52 | Ext.define('Ext.form.action.DirectLoad', { | |
53 | extend: 'Ext.form.action.Load', | |
54 | alternateClassName: 'Ext.form.Action.DirectLoad', | |
55 | alias: 'formaction.directload', | |
56 | ||
57 | requires: [ | |
58 | 'Ext.direct.Manager' | |
59 | ], | |
60 | ||
61 | mixins: [ | |
62 | 'Ext.form.action.DirectAction' | |
63 | ], | |
64 | ||
65 | type: 'directload', | |
66 | ||
67 | run: function() { | |
68 | var me = this, | |
69 | form = me.form, | |
70 | metadata = me.metadata || form.metadata, | |
71 | timeout = me.timeout || form.timeout, | |
72 | args, fn; | |
73 | ||
74 | fn = me.resolveMethod('load'); | |
75 | ||
76 | args = fn.directCfg.method.getArgs({ | |
77 | params: me.getParams(), | |
78 | paramOrder: form.paramOrder, | |
79 | paramsAsHash: form.paramsAsHash, | |
80 | options: timeout != null ? { timeout: timeout * 1000 } : null, | |
81 | metadata: metadata, | |
82 | callback: me.onComplete, | |
83 | scope: me | |
84 | }); | |
85 | ||
86 | fn.apply(window, args); | |
87 | }, | |
88 | ||
89 | // Direct actions have already been processed and therefore | |
90 | // we can directly set the result; Direct Actions do not have | |
91 | // a this.response property. | |
92 | processResponse: function(result) { | |
93 | return (this.result = result); | |
94 | }, | |
95 | ||
96 | onComplete: function(data) { | |
97 | if (data) { | |
98 | this.onSuccess(data); | |
99 | } | |
100 | else { | |
101 | this.onFailure(null); | |
102 | } | |
103 | } | |
104 | }); |