remotegroupgrid.js 9.2 KB

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