You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
9.2 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function(){
  16. Ext.QuickTips.init();
  17. var Employee = Ext.data.Record.create([{
  18. name: 'name',
  19. type: 'string'
  20. }, {
  21. name: 'email',
  22. type: 'string'
  23. }, {
  24. name: 'start',
  25. type: 'date',
  26. dateFormat: 'n/j/Y'
  27. },{
  28. name: 'salary',
  29. type: 'float'
  30. },{
  31. name: 'active',
  32. type: 'bool'
  33. }]);
  34. // hideous function to generate employee data
  35. var genData = function(){
  36. var data = [];
  37. var s = new Date(2007, 0, 1);
  38. var now = new Date(), i = -1;
  39. while(s.getTime() < now.getTime()){
  40. var ecount = Ext.ux.getRandomInt(0, 3);
  41. for(var i = 0; i < ecount; i++){
  42. var name = Ext.ux.generateName();
  43. data.push({
  44. start : s.clearTime(true).add(Date.DAY, Ext.ux.getRandomInt(0, 27)),
  45. name : name,
  46. email: name.toLowerCase().replace(' ', '.') + '@exttest.com',
  47. active: true,
  48. salary: Math.floor(Ext.ux.getRandomInt(35000, 85000)/1000)*1000
  49. });
  50. }
  51. s = s.add(Date.MONTH, 1);
  52. }
  53. return data;
  54. }
  55. var store = new Ext.data.GroupingStore({
  56. reader: new Ext.data.JsonReader({fields: Employee}),
  57. data: genData(),
  58. sortInfo: {field: 'start', direction: 'ASC'}
  59. });
  60. var editor = new Ext.ux.grid.RowEditor({
  61. saveText: 'Update'
  62. });
  63. var grid = new Ext.grid.GridPanel({
  64. store: store,
  65. width: 600,
  66. region:'center',
  67. margins: '0 5 5 5',
  68. autoExpandColumn: 'name',
  69. plugins: [editor],
  70. view: new Ext.grid.GroupingView({
  71. markDirty: false
  72. }),
  73. tbar: [{
  74. iconCls: 'icon-user-add',
  75. text: 'Add Employee',
  76. handler: function(){
  77. var e = new Employee({
  78. name: 'New Guy',
  79. email: 'new@exttest.com',
  80. start: (new Date()).clearTime(),
  81. salary: 50000,
  82. active: true
  83. });
  84. editor.stopEditing();
  85. store.insert(0, e);
  86. grid.getView().refresh();
  87. grid.getSelectionModel().selectRow(0);
  88. editor.startEditing(0);
  89. }
  90. },{
  91. ref: '../removeBtn',
  92. iconCls: 'icon-user-delete',
  93. text: 'Remove Employee',
  94. disabled: true,
  95. handler: function(){
  96. editor.stopEditing();
  97. var s = grid.getSelectionModel().getSelections();
  98. for(var i = 0, r; r = s[i]; i++){
  99. store.remove(r);
  100. }
  101. }
  102. }],
  103. columns: [
  104. new Ext.grid.RowNumberer(),
  105. {
  106. id: 'name',
  107. header: 'First Name',
  108. dataIndex: 'name',
  109. width: 220,
  110. sortable: true,
  111. editor: {
  112. xtype: 'textfield',
  113. allowBlank: false
  114. }
  115. },{
  116. header: 'Email',
  117. dataIndex: 'email',
  118. width: 150,
  119. sortable: true,
  120. editor: {
  121. xtype: 'textfield',
  122. allowBlank: false,
  123. vtype: 'email'
  124. }
  125. },{
  126. xtype: 'datecolumn',
  127. header: 'Start Date',
  128. dataIndex: 'start',
  129. format: 'm/d/Y',
  130. width: 100,
  131. sortable: true,
  132. groupRenderer: Ext.util.Format.dateRenderer('M y'),
  133. editor: {
  134. xtype: 'datefield',
  135. allowBlank: false,
  136. minValue: '01/01/2006',
  137. minText: 'Can\'t have a start date before the company existed!',
  138. maxValue: (new Date()).format('m/d/Y')
  139. }
  140. },{
  141. xtype: 'numbercolumn',
  142. header: 'Salary',
  143. dataIndex: 'salary',
  144. format: '$0,0.00',
  145. width: 100,
  146. sortable: true,
  147. editor: {
  148. xtype: 'numberfield',
  149. allowBlank: false,
  150. minValue: 1,
  151. maxValue: 150000
  152. }
  153. },{
  154. xtype: 'booleancolumn',
  155. header: 'Active',
  156. dataIndex: 'active',
  157. align: 'center',
  158. width: 50,
  159. trueText: 'Yes',
  160. falseText: 'No',
  161. editor: {
  162. xtype: 'checkbox'
  163. }
  164. }]
  165. });
  166. var cstore = new Ext.data.JsonStore({
  167. fields:['month', 'employees', 'salary'],
  168. data:[],
  169. refreshData: function(){
  170. var o = {}, data = [];
  171. var s = new Date(2007, 0, 1);
  172. var now = new Date(), i = -1;
  173. while(s.getTime() < now.getTime()){
  174. var m = {
  175. month: s.format('M y'),
  176. employees: 0,
  177. salary: 0,
  178. index: ++i
  179. }
  180. data.push(m);
  181. o[m.month] = m;
  182. s = s.add(Date.MONTH, 1);
  183. }
  184. store.each(function(r){
  185. var m = o[r.data.start.format('M y')];
  186. for(var i = m.index, mo; mo = data[i]; i++){
  187. mo.employees += 10000;
  188. mo.salary += r.data.salary;
  189. }
  190. });
  191. this.loadData(data);
  192. }
  193. });
  194. cstore.refreshData();
  195. store.on('add', cstore.refreshData, cstore);
  196. store.on('remove', cstore.refreshData, cstore);
  197. store.on('update', cstore.refreshData, cstore);
  198. var chart = new Ext.Panel({
  199. width:600,
  200. height:200,
  201. layout:'fit',
  202. margins: '5 5 0',
  203. region: 'north',
  204. split: true,
  205. minHeight: 100,
  206. maxHeight: 500,
  207. items: {
  208. xtype: 'columnchart',
  209. store: cstore,
  210. url:'../../resources/charts.swf',
  211. xField: 'month',
  212. yAxis: new Ext.chart.NumericAxis({
  213. displayName: 'Employees',
  214. labelRenderer : Ext.util.Format.numberRenderer('0,0')
  215. }),
  216. tipRenderer : function(chart, record, index, series){
  217. if(series.yField == 'salary'){
  218. return Ext.util.Format.number(record.data.salary, '$0,0') + ' total salary in ' + record.data.month;
  219. }else{
  220. return Ext.util.Format.number(Math.floor(record.data.employees/10000), '0,0') + ' total employees in ' + record.data.month;
  221. }
  222. },
  223. // style chart so it looks pretty
  224. chartStyle: {
  225. padding: 10,
  226. animationEnabled: true,
  227. font: {
  228. name: 'Tahoma',
  229. color: 0x444444,
  230. size: 11
  231. },
  232. dataTip: {
  233. padding: 5,
  234. border: {
  235. color: 0x99bbe8,
  236. size:1
  237. },
  238. background: {
  239. color: 0xDAE7F6,
  240. alpha: .9
  241. },
  242. font: {
  243. name: 'Tahoma',
  244. color: 0x15428B,
  245. size: 10,
  246. bold: true
  247. }
  248. },
  249. xAxis: {
  250. color: 0x69aBc8,
  251. majorTicks: {color: 0x69aBc8, length: 4},
  252. minorTicks: {color: 0x69aBc8, length: 2},
  253. majorGridLines: {size: 1, color: 0xeeeeee}
  254. },
  255. yAxis: {
  256. color: 0x69aBc8,
  257. majorTicks: {color: 0x69aBc8, length: 4},
  258. minorTicks: {color: 0x69aBc8, length: 2},
  259. majorGridLines: {size: 1, color: 0xdfe8f6}
  260. }
  261. },
  262. series: [{
  263. type: 'column',
  264. displayName: 'Salary',
  265. yField: 'salary',
  266. style: {
  267. image:'../chart/bar.gif',
  268. mode: 'stretch',
  269. color:0x99BBE8
  270. }
  271. }]
  272. }
  273. });
  274. var layout = new Ext.Panel({
  275. title: 'Employee Salary by Month',
  276. layout: 'border',
  277. layoutConfig: {
  278. columns: 1
  279. },
  280. width:600,
  281. height: 600,
  282. items: [chart, grid]
  283. });
  284. layout.render(Ext.getBody());
  285. grid.getSelectionModel().on('selectionchange', function(sm){
  286. grid.removeBtn.setDisabled(sm.getCount() < 1);
  287. });
  288. });