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