form.html
2.92 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Grids</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css"/>
<!-- GC -->
<script type="text/javascript" src="../../ext-all.js"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
Ext.require('Ext.data.proxy.LocalStorage');
Ext.onReady(function() {
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'first', 'last', 'start', 'bio'],
proxy: {
type: 'localstorage',
id: 'form'
}
});
var record;
var form = Ext.create('Ext.form.Panel', {
height: 400,
width: 600,
bodyPadding: 10,
renderTo: Ext.getBody(),
title: 'Edit User',
defaults: {
anchor: "-20"
},
items: [
{
xtype: 'textfield',
name: 'first',
fieldLabel: 'First Name'
},
{
xtype: 'textfield',
name: 'last',
fieldLabel: 'Last Name'
},
{
xtype: 'datefield',
name: 'startDate',
fieldLabel: 'Start Date'
},
{
xtype: 'htmleditor',
name: 'bio',
fieldLabel: 'Bio',
labelAlign: 'top',
anchor: '-20 -80' //THIS IS UTTERLY UTTERLY WRONG. IT SHOULD BE -20, NOT -80
}
],
buttons: [
{
text: 'Submit',
handler: function() {
if (!record) {
record = new User({id: 1});
}
record.set(form.getValues());
record.save();
}
}
]
});
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
model: 'User',
listeners: {
load: function() {
//FIXME: THIS APPEARS TO BE BEING CALLED TWICE BUT SHOULD ONLY HAVE BEEN CALLED ONCE
record = this.first();
if (record) {
form.loadRecord(record);
}
}
}
});
store.load();
});
</script>
</body>
</html>