]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * This Form demonstrates the fact that by virtue of inheriting from the Ext.Container\r | |
3 | * class, an Ext.form.Panel can contain any Ext.Component. This includes all the\r | |
4 | * subclasses of Ext.Panel, including the GridPanel.\r | |
5 | *\r | |
6 | * The Grid demonstrates the use of creation of derived fields in a Record created using a\r | |
7 | * custom `convert` function, and the use of column renderers.\r | |
8 | *\r | |
9 | * The Form demonstrates the use of radio buttons grouped by name being set by the value\r | |
10 | * of the derived rating field.\r | |
11 | */\r | |
12 | Ext.define('KitchenSink.view.form.FormGrid', {\r | |
13 | extend: 'Ext.form.Panel',\r | |
14 | xtype: 'form-grid',\r | |
15 | \r | |
16 | //<example>\r | |
17 | requires: [\r | |
18 | 'Ext.grid.*',\r | |
19 | 'Ext.form.*',\r | |
20 | 'Ext.layout.container.Column',\r | |
21 | 'KitchenSink.model.Company'\r | |
22 | ],\r | |
23 | \r | |
24 | exampleTitle: 'Dynamic Form interacting with an embedded Grid',\r | |
25 | otherContent: [{\r | |
26 | type: 'Model',\r | |
27 | path: 'classic/samples/model/Company.js'\r | |
28 | }],\r | |
29 | profiles: {\r | |
30 | classic: {\r | |
31 | width: 750,\r | |
32 | gridWidth: 0.6,\r | |
33 | formWidth: 0.4,\r | |
34 | percentChangeColumnWidth: 75,\r | |
35 | lastUpdatedColumnWidth: 85,\r | |
36 | ratingColumnWidth: 30\r | |
37 | },\r | |
38 | neptune: {\r | |
39 | width: 880,\r | |
40 | gridWidth: 0.65,\r | |
41 | formWidth: 0.35,\r | |
42 | percentChangeColumnWidth: 100,\r | |
43 | lastUpdatedColumnWidth: 115,\r | |
44 | ratingColumnWidth: 60\r | |
45 | }\r | |
46 | },\r | |
47 | //</example>\r | |
48 | \r | |
49 | frame: true,\r | |
50 | title: 'Company data',\r | |
51 | bodyPadding: 5,\r | |
52 | layout: 'column',\r | |
53 | \r | |
54 | // In this example, configuration is applied at initComponent time\r | |
55 | // because it depends on profileInfo object that is generated for the\r | |
56 | // FormGrid instance.\r | |
57 | initComponent: function() {\r | |
58 | Ext.apply(this, {\r | |
59 | width: this.profileInfo.width,\r | |
60 | fieldDefaults: {\r | |
61 | labelAlign: 'left',\r | |
62 | labelWidth: 90,\r | |
63 | anchor: '100%',\r | |
64 | msgTarget: 'side'\r | |
65 | },\r | |
66 | \r | |
67 | items: [{\r | |
68 | columnWidth: this.profileInfo.gridWidth,\r | |
69 | xtype: 'gridpanel',\r | |
70 | store: new Ext.data.Store({\r | |
71 | model: KitchenSink.model.Company,\r | |
72 | proxy: {\r | |
73 | type: 'memory',\r | |
74 | reader: {\r | |
75 | type: 'array'\r | |
76 | }\r | |
77 | },\r | |
78 | data: KitchenSink.data.DataSets.company\r | |
79 | }),\r | |
80 | height: 400,\r | |
81 | columns: [{\r | |
82 | text: 'Company',\r | |
83 | flex: 1,\r | |
84 | sortable: true,\r | |
85 | dataIndex: 'name'\r | |
86 | }, {\r | |
87 | text: 'Price',\r | |
88 | width: 75,\r | |
89 | sortable: true,\r | |
90 | dataIndex: 'price'\r | |
91 | }, {\r | |
92 | text: 'Change',\r | |
93 | width: 80,\r | |
94 | sortable: true,\r | |
95 | renderer: this.changeRenderer,\r | |
96 | dataIndex: 'change'\r | |
97 | }, {\r | |
98 | text: '% Change',\r | |
99 | width: this.profileInfo.percentChangeColumnWidth,\r | |
100 | sortable: true,\r | |
101 | renderer: this.pctChangeRenderer,\r | |
102 | dataIndex: 'pctChange'\r | |
103 | }, {\r | |
104 | text: 'Last Updated',\r | |
105 | width: this.profileInfo.lastUpdatedColumnWidth,\r | |
106 | sortable: true,\r | |
107 | formatter: 'date("m/d/Y")',\r | |
108 | dataIndex: 'lastChange'\r | |
109 | }, {\r | |
110 | text: 'Rating',\r | |
111 | width: this.profileInfo.ratingColumnWidth,\r | |
112 | sortable: true,\r | |
113 | renderer: this.renderRating,\r | |
114 | dataIndex: 'rating'\r | |
115 | }],\r | |
116 | listeners: {\r | |
117 | scope: this,\r | |
118 | selectionchange: this.onSelectionChange\r | |
119 | }\r | |
120 | }, {\r | |
121 | columnWidth: this.profileInfo.formWidth,\r | |
122 | margin: '0 0 0 10',\r | |
123 | xtype: 'fieldset',\r | |
124 | title:'Company details',\r | |
125 | layout: 'anchor',\r | |
126 | defaultType: 'textfield',\r | |
127 | items: [{\r | |
128 | fieldLabel: 'Name',\r | |
129 | name: 'name'\r | |
130 | },{\r | |
131 | fieldLabel: 'Price',\r | |
132 | name: 'price'\r | |
133 | },{\r | |
134 | fieldLabel: '% Change',\r | |
135 | name: 'pctChange'\r | |
136 | },{\r | |
137 | xtype: 'datefield',\r | |
138 | fieldLabel: 'Last Updated',\r | |
139 | name: 'lastChange'\r | |
140 | }, {\r | |
141 | xtype: 'radiogroup',\r | |
142 | fieldLabel: 'Rating',\r | |
143 | columns: 3,\r | |
144 | defaults: {\r | |
145 | name: 'rating' //Each radio has the same name so the browser will make sure only one is checked at once\r | |
146 | },\r | |
147 | items: [{\r | |
148 | inputValue: '0',\r | |
149 | boxLabel: 'A'\r | |
150 | }, {\r | |
151 | inputValue: '1',\r | |
152 | boxLabel: 'B'\r | |
153 | }, {\r | |
154 | inputValue: '2',\r | |
155 | boxLabel: 'C'\r | |
156 | }]\r | |
157 | }]\r | |
158 | }]\r | |
159 | });\r | |
160 | this.callParent();\r | |
161 | },\r | |
162 | \r | |
163 | changeRenderer: function(val) {\r | |
164 | if (val > 0) {\r | |
165 | return '<span style="color:green;">' + val + '</span>';\r | |
166 | } else if(val < 0) {\r | |
167 | return '<span style="color:red;">' + val + '</span>';\r | |
168 | }\r | |
169 | return val;\r | |
170 | },\r | |
171 | \r | |
172 | pctChangeRenderer: function(val){\r | |
173 | if (val > 0) {\r | |
174 | return '<span style="color:green;">' + val + '%</span>';\r | |
175 | } else if(val < 0) {\r | |
176 | return '<span style="color:red;">' + val + '%</span>';\r | |
177 | }\r | |
178 | return val;\r | |
179 | },\r | |
180 | \r | |
181 | renderRating: function(val){\r | |
182 | switch (val) {\r | |
183 | case 0:\r | |
184 | return 'A';\r | |
185 | case 1:\r | |
186 | return 'B';\r | |
187 | case 2:\r | |
188 | return 'C';\r | |
189 | }\r | |
190 | },\r | |
191 | \r | |
192 | onSelectionChange: function(model, records) {\r | |
193 | var rec = records[0];\r | |
194 | if (rec) {\r | |
195 | this.getForm().loadRecord(rec);\r | |
196 | }\r | |
197 | }\r | |
198 | });\r |