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.

150 lines
4.8 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. /**
  9. * Handler specified for the 'Available' column renderer
  10. * @param {Object} value
  11. */
  12. function formatDate(value){
  13. return value ? value.dateFormat('M d, Y') : '';
  14. }
  15. // shorthand alias
  16. var fm = Ext.form;
  17. // the column model has information about grid columns
  18. // dataIndex maps the column to the specific data field in
  19. // the data store (created below)
  20. var cm = new Ext.grid.ColumnModel({
  21. // specify any defaults for each column
  22. defaults: {
  23. sortable: true // columns are not sortable by default
  24. },
  25. columns: [{
  26. id: 'common',
  27. header: 'Common Name',
  28. dataIndex: 'common',
  29. width: 220,
  30. // use shorthand alias defined above
  31. editor: new fm.TextField({
  32. allowBlank: false
  33. })
  34. }, {
  35. header: 'Light',
  36. dataIndex: 'light',
  37. width: 130,
  38. editor: new fm.ComboBox({
  39. typeAhead: true,
  40. triggerAction: 'all',
  41. // transform the data already specified in html
  42. transform: 'light',
  43. lazyRender: true,
  44. listClass: 'x-combo-list-small'
  45. })
  46. }, {
  47. header: 'Price',
  48. dataIndex: 'price',
  49. width: 70,
  50. align: 'right',
  51. renderer: 'usMoney',
  52. editor: new fm.NumberField({
  53. allowBlank: false,
  54. allowNegative: false,
  55. maxValue: 100000
  56. })
  57. }, {
  58. header: 'Available',
  59. dataIndex: 'availDate',
  60. width: 95,
  61. renderer: formatDate,
  62. editor: new fm.DateField({
  63. format: 'm/d/y',
  64. minValue: '01/01/06',
  65. disabledDays: [0, 6],
  66. disabledDaysText: 'Plants are not available on the weekends'
  67. })
  68. }, {
  69. xtype: 'checkcolumn',
  70. header: 'Indoor?',
  71. dataIndex: 'indoor',
  72. width: 55
  73. }]
  74. });
  75. // create the Data Store
  76. var store = new Ext.data.Store({
  77. // destroy the store if the grid is destroyed
  78. autoDestroy: true,
  79. // load remote data using HTTP
  80. url: 'plants.xml',
  81. // specify a XmlReader (coincides with the XML format of the returned data)
  82. reader: new Ext.data.XmlReader({
  83. // records will have a 'plant' tag
  84. record: 'plant',
  85. // use an Array of field definition objects to implicitly create a Record constructor
  86. fields: [
  87. // the 'name' below matches the tag name to read, except 'availDate'
  88. // which is mapped to the tag 'availability'
  89. {name: 'common', type: 'string'},
  90. {name: 'botanical', type: 'string'},
  91. {name: 'light'},
  92. {name: 'price', type: 'float'},
  93. // dates can be automatically converted by specifying dateFormat
  94. {name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
  95. {name: 'indoor', type: 'bool'}
  96. ]
  97. }),
  98. sortInfo: {field:'common', direction:'ASC'}
  99. });
  100. // create the editor grid
  101. var grid = new Ext.grid.EditorGridPanel({
  102. store: store,
  103. cm: cm,
  104. renderTo: 'editor-grid',
  105. width: 600,
  106. height: 300,
  107. autoExpandColumn: 'common', // column with this id will be expanded
  108. title: 'Edit Plants?',
  109. frame: true,
  110. clicksToEdit: 1,
  111. tbar: [{
  112. text: 'Add Plant',
  113. handler : function(){
  114. // access the Record constructor through the grid's store
  115. var Plant = grid.getStore().recordType;
  116. var p = new Plant({
  117. common: 'New Plant 1',
  118. light: 'Mostly Shade',
  119. price: 0,
  120. availDate: (new Date()).clearTime(),
  121. indoor: false
  122. });
  123. grid.stopEditing();
  124. store.insert(0, p);
  125. grid.startEditing(0, 0);
  126. }
  127. }]
  128. });
  129. // manually trigger the data store load
  130. store.load({
  131. // store loading is asynchronous, use a load listener or callback to handle results
  132. callback: function(){
  133. Ext.Msg.show({
  134. title: 'Store Load Callback',
  135. msg: 'store was loaded, data available for processing',
  136. modal: false,
  137. icon: Ext.Msg.INFO,
  138. buttons: Ext.Msg.OK
  139. });
  140. }
  141. });
  142. });