Web Interface For Lite Argus Control modules
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.

295 lines
8.7 KiB

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