]> git.proxmox.com Git - sencha-touch.git/blob - src/examples/direct/form.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / examples / direct / form.js
1 Ext.application({
2 name : 'Direct',
3
4 requires: [
5 'Ext.form.Panel',
6 'Ext.field.Email',
7 'Ext.Button',
8 'Ext.MessageBox',
9 'Ext.direct.*'
10 ],
11
12 launch: function() {
13 Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
14
15 Ext.Viewport.add({
16 xtype: 'formpanel',
17 scrollable: null,
18 defaultType: 'textfield',
19 paramOrder: ['uid', 'foo'],
20 api: {
21 load: 'Profile.getBasicInfo',
22 submit: 'Profile.updateBasicInfo'
23 },
24 items: [
25 {
26 label: 'Name',
27 name: 'name'
28 },
29 {
30 xtype: 'emailfield',
31 label: 'Email',
32 name: 'email'
33 },
34 {
35 label: 'Company',
36 name: 'company'
37 },
38 {
39 xtype: 'container',
40 defaultType: 'button',
41 layout: {
42 type: 'hbox',
43 align: 'stretch'
44 },
45 items: [
46 {
47 flex: 1,
48 text: 'Load',
49 ui: 'action',
50 handler: function(button) {
51 var form = button.up('formpanel');
52
53 form.load({
54 params: {
55 uid: 5
56 },
57 success: function() {
58 Ext.Msg.alert('Success', 'Form loaded successfully');
59 },
60 failure: function(form, result, response) {
61 var errors = response.errors,
62 ret = [],
63 name, error;
64
65 for (name in errors) {
66 if (errors.hasOwnProperty(name)) {
67 error = errors[name];
68
69 ret.push(name + ': ' + error);
70 }
71 }
72
73 Ext.Msg.alert('Failure', ret.join('<br />'));
74 }
75 });
76 }
77 },
78 {
79 flex: 1,
80 text: 'Submit',
81 ui: 'confirm',
82 handler: function(button) {
83 var form = button.up('formpanel');
84
85 form.submit({
86 success: function() {
87 Ext.Msg.alert('Success', 'Form submit successful');
88 },
89 failure: function(form, result, response) {
90 var errors = response.errors,
91 ret = [],
92 name, error;
93
94 for (name in errors) {
95 if (errors.hasOwnProperty(name)) {
96 error = errors[name];
97
98 ret.push(name + ': ' + error);
99 }
100 }
101
102 Ext.Msg.alert('Failure', ret.join('<br />'));
103 }
104 });
105 }
106 }
107 ]
108 }
109 ]
110 });
111 }
112 });