Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / direct / direct-form.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.require([
16     'Ext.direct.*',
17     'Ext.form.*',
18     'Ext.tip.QuickTipManager',
19     'Ext.layout.container.Accordion'
20 ]);
21
22 Ext.onReady(function(){    
23     /*
24      * Notice that Direct requests will batch together if they occur
25      * within the enableBuffer delay period (in milliseconds).
26      * Slow the buffering down from the default of 10ms to 100ms
27      */
28     Ext.app.REMOTING_API.enableBuffer = 100;
29     Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
30     
31     // provide feedback for any errors
32     Ext.tip.QuickTipManager.init();
33     
34     var basicInfo = Ext.create('Ext.form.Panel', {
35         // configs for FormPanel
36         title: 'Basic Information',
37         border: false,
38         bodyPadding: 10,
39         // configs for BasicForm
40         api: {
41             // The server-side method to call for load() requests
42             load: Profile.getBasicInfo,
43             // The server-side must mark the submit handler as a 'formHandler'
44             submit: Profile.updateBasicInfo
45         },
46         // specify the order for the passed params
47         paramOrder: ['uid', 'foo'],
48         dockedItems: [{
49             dock: 'bottom',
50             xtype: 'toolbar',
51             ui: 'footer',
52             style: 'margin: 0 5px 5px 0;',
53             items: ['->', {
54                 text: 'Submit',
55                 handler: function(){
56                     basicInfo.getForm().submit({
57                         params: {
58                             foo: 'bar',
59                             uid: 34
60                         }
61                     });
62                 }      
63             }]
64         }],
65         defaultType: 'textfield',
66         defaults: {
67             anchor: '100%'
68         },
69         items: [{
70             fieldLabel: 'Name',
71             name: 'name'
72         },{
73             fieldLabel: 'Email',
74             msgTarget: 'side',
75             name: 'email'
76         },{
77             fieldLabel: 'Company',
78             name: 'company'
79         }]
80     });
81     
82     var phoneInfo = Ext.create('Ext.form.Panel', {
83         title: 'Phone Numbers',
84         border: false,
85         api: {
86             load: Profile.getPhoneInfo
87         },
88         bodyPadding: 10,
89         paramOrder: ['uid'],
90         defaultType: 'textfield',
91         defaults: {
92             anchor: '100%'
93         },
94         items: [{
95             fieldLabel: 'Office',
96             name: 'office'
97         },{
98             fieldLabel: 'Cell',
99             name: 'cell'
100         },{
101             fieldLabel: 'Home',
102             name: 'home'
103         }]
104     });
105     
106     var locationInfo = Ext.create('Ext.form.Panel', {
107         title: 'Location Information',
108         border: false,
109         bodyPadding: 10,
110         api: {
111             load: Profile.getLocationInfo
112         },
113         paramOrder: ['uid'],
114         defaultType: 'textfield',
115         defaults: {
116             anchor: '100%'
117         },
118         items: [{
119             fieldLabel: 'Street',
120             name: 'street'
121         },{
122             fieldLabel: 'City',
123             name: 'city'
124         },{
125             fieldLabel: 'State',
126             name: 'state'
127         },{
128             fieldLabel: 'Zip',
129             name: 'zip'
130         }]
131     });
132     
133     var accordion = Ext.create('Ext.panel.Panel', {
134         layout: 'accordion',
135         renderTo: Ext.getBody(),
136         title: 'My Profile',
137         width: 300,
138         height: 240,
139         items: [basicInfo, phoneInfo, locationInfo]
140     });
141     
142     // load the forms (notice the load requests will get batched together)
143     basicInfo.getForm().load({
144         // pass 2 arguments to server side getBasicInfo method (len=2)
145         params: {
146             foo: 'bar',
147             uid: 34
148         }
149     });
150
151     phoneInfo.getForm().load({
152         params: {
153             uid: 5
154         }
155     });
156
157     // defer this request just to simulate the request not getting batched
158     // since it exceeds to configured buffer
159     Ext.Function.defer(function(){
160         locationInfo.getForm().load({
161             params: {
162                 uid: 5
163             }
164         });
165     }, 200);
166
167     // rpc call
168     TestAction.doEcho('sample');
169 });
170