]> git.proxmox.com Git - extjs.git/blame - extjs/build/examples/classic/grid/remotegroupgrid.js
bump version to 7.0.0-4
[extjs.git] / extjs / build / examples / classic / grid / remotegroupgrid.js
CommitLineData
947f0963
TL
1Ext.require([
2 'Ext.ux.ajax.JsonSimlet',
3 'Ext.ux.ajax.SimManager',
4 'Ext.data.*',
5 'Ext.grid.*'
6]);
7Ext.onReady(function() {
8
9 var data = [{
10 "name": "Cheesecake Factory",
11 "cuisine": "American"
12 }, {
13 "name": "Creamery",
14 "cuisine": "American"
15 }, {
16 "name": "Crepevine",
17 "cuisine": "American"
18 }, {
19 "name": "Gordon Biersch",
20 "cuisine": "American"
21 }, {
22 "name": "MacArthur Park",
23 "cuisine": "American"
24 }, {
25 "name": "Old Pro",
26 "cuisine": "American"
27 }, {
28 "name": "Shokolaat",
29 "cuisine": "American"
30 }, {
31 "name": "Slider Bar",
32 "cuisine": "American"
33 }, {
34 "name": "University Cafe",
35 "cuisine": "American"
36 }, {
37 "name": "Madame Tam",
38 "cuisine": "Asian"
39 }, {
40 "name": "House of Bagels",
41 "cuisine": "Bagels"
42 }, {
43 "name": "Nola's",
44 "cuisine": "Cajun"
45 }, {
46 "name": "St Michael's Alley",
47 "cuisine": "Californian"
48 }, {
49 "name": "Coconuts Caribbean Restaurant & Bar",
50 "cuisine": "Caribbean"
51 }, {
52 "name": "Mango Caribbean Cafe",
53 "cuisine": "Caribbean"
54 }, {
55 "name": "Jing Jing",
56 "cuisine": "Chinese"
57 }, {
58 "name": "Mandarin Gourmet",
59 "cuisine": "Chinese"
60 }, {
61 "name": "Tai Pan",
62 "cuisine": "Chinese"
63 }, {
64 "name": "Coupa Cafe",
65 "cuisine": "Coffee"
66 }, {
67 "name": "Lytton Coffee Company",
68 "cuisine": "Coffee"
69 }, {
70 "name": "Peet's Coffee",
71 "cuisine": "Coffee"
72 }, {
73 "name": "Starbucks",
74 "cuisine": "Coffee"
75 }, {
76 "name": "Rose & Crown",
77 "cuisine": "English"
78 }, {
79 "name": "Bistro Maxine",
80 "cuisine": "French"
81 }, {
82 "name": "Cafe Epi",
83 "cuisine": "French"
84 }, {
85 "name": "Darbar Indian Cuisine",
86 "cuisine": "Indian"
87 }, {
88 "name": "Hyderabad House",
89 "cuisine": "Indian"
90 }, {
91 "name": "Janta",
92 "cuisine": "Indian"
93 }, {
94 "name": "Junoon",
95 "cuisine": "Indian"
96 }, {
97 "name": "Mantra",
98 "cuisine": "Indian"
99 }, {
100 "name": "Buca di Beppo",
101 "cuisine": "Italian"
102 }, {
103 "name": "Cafe Renzo",
104 "cuisine": "Italian"
105 }, {
106 "name": "Cafe Renzo",
107 "cuisine": "Italian"
108 }, {
109 "name": "Il Fornaio",
110 "cuisine": "Italian"
111 }, {
112 "name": "La Strada",
113 "cuisine": "Italian"
114 }, {
115 "name": "Osteria",
116 "cuisine": "Italian"
117 }, {
118 "name": "Pasta?",
119 "cuisine": "Italian"
120 }, {
121 "name": "Vero",
122 "cuisine": "Italian"
123 }, {
124 "name": "Baklava",
125 "cuisine": "Mediterranean"
126 }, {
127 "name": "Cafe 220",
128 "cuisine": "Mediterranean"
129 }, {
130 "name": "Cafe Renaissance",
131 "cuisine": "Mediterranean"
132 }, {
133 "name": "Evvia Estiatorio",
134 "cuisine": "Mediterranean"
135 }, {
136 "name": "Gyros-Gyros",
137 "cuisine": "Mediterranean"
138 }, {
139 "name": "Kan Zeman",
140 "cuisine": "Mediterranean"
141 }, {
142 "name": "Lavanda",
143 "cuisine": "Mediterranean"
144 }, {
145 "name": "Reposado",
146 "cuisine": "Mexican"
147 }, {
148 "name": "Sancho's Taquira",
149 "cuisine": "Mexican"
150 }, {
151 "name": "California Pizza Kitchen",
152 "cuisine": "Pizza"
153 }, {
154 "name": "New York Pizza",
155 "cuisine": "Pizza"
156 }, {
157 "name": "Patxi's Pizza",
158 "cuisine": "Pizza"
159 }, {
160 "name": "Pizza My Heart",
161 "cuisine": "Pizza"
162 }, {
163 "name": "Round Table",
164 "cuisine": "Pizza"
165 }, {
166 "name": "Pluto's",
167 "cuisine": "Salad"
168 }, {
169 "name": "Sprout Cafe",
170 "cuisine": "Salad"
171 }, {
172 "name": "The Prolific Oven",
173 "cuisine": "Sandwiches"
174 }, {
175 "name": "Kanpai",
176 "cuisine": "Sushi"
177 }, {
178 "name": "Miyake",
179 "cuisine": "Sushi"
180 }, {
181 "name": "Sushi Tomo",
182 "cuisine": "Sushi"
183 }, {
184 "name": "Joya",
185 "cuisine": "Tapas"
186 }, {
187 "name": "Bangkok Cuisine",
188 "cuisine": "Thai"
189 }, {
190 "name": "Krung Siam",
191 "cuisine": "Thai"
192 }, {
193 "name": "Siam Royal",
194 "cuisine": "Thai"
195 }, {
196 "name": "Thaiphoon",
197 "cuisine": "Thai"
198 }, {
199 "name": "Garden Fresh",
200 "cuisine": "Vegan"
201 }, {
202 "name": "Loving Hut",
203 "cuisine": "Vegan"
204 }, {
205 "name": "Tamarine",
206 "cuisine": "Vietnamese"
207 }, {
208 "name": "Three Seasons",
209 "cuisine": "Vietnamese"
210 }],
211 restaurants, groupingFeature, grid, newRestaurantDialog;
212
213 // wrapped in closure to prevent global vars.
214 Ext.define('Restaurant', {
215 extend: 'Ext.data.Model',
216 fields: ['name', 'cuisine']
217 });
218
219 Ext.ux.ajax.SimManager.init({
220 delay: 30,
221 defaultSimlet: null
222 }).register({
223 'readRestaurants': {
224 data: data,
225 stype: 'json',
226 getData: Ext.Function.createInterceptor(Ext.ux.ajax.JsonSimlet.prototype.getData, function() {
227 delete this.currentOrder;
228 }),
229
230 // JsonSimlet respects limit param. We want to return ALL the data
231 getPage: function(ctx, data) {
232 return data;
233 }
234 }
235 }).register({
236 'createRestaurant': {
237 stype: 'json',
238 getData: function(ctx) {
239 var recData = Ext.JSON.decode(ctx.xhr.body);
240
241 delete recData.id;
242 data.push(recData);
243
244 return [recData];
245 }
246 }
247 });
248
249 restaurants = Ext.create('Ext.data.Store', {
250 model: 'Restaurant',
251 groupField: 'cuisine',
252 remoteGroup: true,
253 sorters: ['name'],
254 proxy: {
255 api: {
256 create: 'createRestaurant',
257 read: 'readRestaurants'
258 },
259 actionMethods: {
260 create: 'GET',
261 read: 'GET'
262 },
263 noCache: false,
264 type: 'ajax',
265 reader: 'json',
266 writer: 'json'
267 },
268 autoLoad: true,
269 autoSync: true,
270 listeners: {
271 // Clear grouping button only valid if the store is grouped
272 groupchange: function() {
273 grid.down('[text=Clear Grouping]').setDisabled(!restaurants.isGrouped());
274 },
275
276 // Upon successful add of a new restaurant, invoke the server to sort and group
277 write: function(s, operation) {
278 if (operation.action === 'create' && operation.success === true) {
279 restaurants.sort();
280 }
281 }
282 }
283 });
284
285 groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
286 groupHeaderTpl: 'Cuisine: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',
287 hideGroupedHeader: true
288 });
289
290 grid = Ext.create('Ext.grid.Panel', {
291 renderTo: Ext.getBody(),
292 collapsible: true,
293 iconCls: 'icon-grid',
294 frame: true,
295 store: restaurants,
296 width: 600,
297 height: 400,
298 title: 'Restaurants',
299 resizable: true,
300 features: [groupingFeature],
301 columns: [{
302 text: 'Name',
303 flex: 1,
304 dataIndex: 'name'
305 }, {
306 text: 'Cuisine',
307 flex: 1,
308 dataIndex: 'cuisine'
309 }],
310 fbar: [{
311 text: 'New Restaurant',
312 handler: function() {
313 newRestaurantDialog.show();
314 }
315 }, '->', {
316 text: 'Clear Grouping',
317 iconCls: 'icon-clear-group',
318 handler: function(b) {
319 groupingFeature.disable();
320 }
321 }]
322 });
323
324 newRestaurantDialog = Ext.create('Ext.window.Window', {
325 closeAction: 'hide',
326 title: 'Add a new restaurant',
327
328 // Make the Window out of a <form> el so that the <button type="submit"> will invoke its handler upon CR
329 autoEl: 'form',
330 width: 400,
331 bodyPadding: 5,
332 layout: 'anchor',
333 defaults: {
334 anchor: '100%'
335 },
336 defaultFocus: '[name=name]',
337 items: [{
338 xtype: 'textfield',
339 fieldLabel: 'Name',
340 name: 'name'
341 }, {
342 xtype: 'textfield',
343 fieldLabel: 'Cuisine',
344 name: 'cuisine'
345 }],
346 buttons: [{
347 text: 'Add',
348 type: 'submit',
349 handler: function() {
350 var newRec = new Restaurant({
351 name: newRestaurantDialog.down('[name=name]').getValue(),
352 cuisine: newRestaurantDialog.down('[name=cuisine]').getValue()
353 });
354
355 restaurants.add(newRec);
356 newRestaurantDialog.hide();
357 newRestaurantDialog.getEl().dom.reset();
358 }
359 }, {
360 text: 'Cancel',
361 handler: function() {
362 newRestaurantDialog.hide();
363 }
364 }]
365 });
366});