direct-form.js
4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Ext.require([
'Ext.direct.*',
'Ext.form.*',
'Ext.tip.QuickTipManager',
'Ext.layout.container.Accordion'
]);
Ext.onReady(function(){
/*
* Notice that Direct requests will batch together if they occur
* within the enableBuffer delay period (in milliseconds).
* Slow the buffering down from the default of 10ms to 100ms
*/
Ext.app.REMOTING_API.enableBuffer = 100;
Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
// provide feedback for any errors
Ext.tip.QuickTipManager.init();
var basicInfo = Ext.create('Ext.form.Panel', {
// configs for FormPanel
title: 'Basic Information',
border: false,
bodyPadding: 10,
// configs for BasicForm
api: {
// The server-side method to call for load() requests
load: Profile.getBasicInfo,
// The server-side must mark the submit handler as a 'formHandler'
submit: Profile.updateBasicInfo
},
// specify the order for the passed params
paramOrder: ['uid', 'foo'],
dockedItems: [{
dock: 'bottom',
xtype: 'toolbar',
ui: 'footer',
style: 'margin: 0 5px 5px 0;',
items: ['->', {
text: 'Submit',
handler: function(){
basicInfo.getForm().submit({
params: {
foo: 'bar',
uid: 34
}
});
}
}]
}],
defaultType: 'textfield',
defaults: {
anchor: '100%'
},
items: [{
fieldLabel: 'Name',
name: 'name'
},{
fieldLabel: 'Email',
msgTarget: 'side',
name: 'email'
},{
fieldLabel: 'Company',
name: 'company'
}]
});
var phoneInfo = Ext.create('Ext.form.Panel', {
title: 'Phone Numbers',
border: false,
api: {
load: Profile.getPhoneInfo
},
bodyPadding: 10,
paramOrder: ['uid'],
defaultType: 'textfield',
defaults: {
anchor: '100%'
},
items: [{
fieldLabel: 'Office',
name: 'office'
},{
fieldLabel: 'Cell',
name: 'cell'
},{
fieldLabel: 'Home',
name: 'home'
}]
});
var locationInfo = Ext.create('Ext.form.Panel', {
title: 'Location Information',
border: false,
bodyPadding: 10,
api: {
load: Profile.getLocationInfo
},
paramOrder: ['uid'],
defaultType: 'textfield',
defaults: {
anchor: '100%'
},
items: [{
fieldLabel: 'Street',
name: 'street'
},{
fieldLabel: 'City',
name: 'city'
},{
fieldLabel: 'State',
name: 'state'
},{
fieldLabel: 'Zip',
name: 'zip'
}]
});
var accordion = Ext.create('Ext.panel.Panel', {
layout: 'accordion',
renderTo: Ext.getBody(),
title: 'My Profile',
width: 300,
height: 240,
items: [basicInfo, phoneInfo, locationInfo]
});
// load the forms (notice the load requests will get batched together)
basicInfo.getForm().load({
// pass 2 arguments to server side getBasicInfo method (len=2)
params: {
foo: 'bar',
uid: 34
}
});
phoneInfo.getForm().load({
params: {
uid: 5
}
});
// defer this request just to simulate the request not getting batched
// since it exceeds to configured buffer
Ext.Function.defer(function(){
locationInfo.getForm().load({
params: {
uid: 5
}
});
}, 200);
// rpc call
TestAction.doEcho('sample');
});