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.

174 lines
4.9 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. /**
  8. * @class pivot.AxisGrid
  9. * @extends Ext.grid.EditorGridPanel
  10. * Grid used to control the dimensions in a PivotGrid axis
  11. */
  12. pivot.AxisGrid = Ext.extend(Ext.grid.EditorGridPanel, {
  13. border: false,
  14. style: 'border-top-width: 1px',
  15. flex: 1,
  16. clicksToEdit: 1,
  17. /**
  18. * @cfg {Array} fields The array of field names to control. Required
  19. */
  20. /**
  21. * @cfg {Boolean} hasWidthField True to add a column for 'width' (e.g. for left axes)
  22. */
  23. hasWidthField: false,
  24. /**
  25. * The Record used internally to manage the field name, sort direction and width of each dimension
  26. * @property record
  27. * @type Ext.data.Record
  28. */
  29. record: Ext.data.Record.create([
  30. {name: 'field', type: 'string'},
  31. {name: 'direction', type: 'string'},
  32. {name: 'width', type: 'int'}
  33. ]),
  34. initComponent: function() {
  35. this.store = new Ext.data.Store({
  36. data : this.dimensionData || [],
  37. reader: new Ext.data.JsonReader({}, this.record)
  38. });
  39. var columns = [{
  40. header : 'Dimension',
  41. dataIndex: 'field',
  42. editor : this.buildDimensionEditor(),
  43. width : this.hasWidthField ? 110 : 160
  44. }, {
  45. header : 'Sort Direction',
  46. dataIndex: 'direction',
  47. editor : this.buildDirectionEditor(),
  48. width : 80
  49. }];
  50. if (this.hasWidthField) {
  51. columns.push({
  52. header : 'Width',
  53. dataIndex: 'width',
  54. editor : new Ext.form.NumberField(),
  55. width : 50
  56. });
  57. }
  58. columns.push({
  59. xtype: 'actioncolumn',
  60. width: 30,
  61. icon : '../shared/icons/fam/delete.gif',
  62. scope : this,
  63. handler: this.onRemoveDimension,
  64. tooltip: 'Delete this axis',
  65. editable: false
  66. });
  67. Ext.applyIf(this, {
  68. bbar: [{
  69. text : 'Add Dimension',
  70. icon : '../shared/icons/fam/add.gif',
  71. scope : this,
  72. handler: this.onAddDimension
  73. }],
  74. columns: columns
  75. });
  76. pivot.AxisGrid.superclass.initComponent.apply(this, arguments);
  77. },
  78. /**
  79. * @private
  80. * Adds a new row to the store and auto-focusses its first editor
  81. */
  82. onAddDimension: function() {
  83. this.store.add(new this.record({
  84. field : this.fields[0],
  85. direction: "ASC",
  86. width : 80
  87. }));
  88. this.startEditing(this.store.getCount() - 1, 0);
  89. },
  90. /**
  91. * @private
  92. */
  93. onRemoveDimension: function(grid, rowIndex, colIndex) {
  94. var store = this.store,
  95. record = this.store.getAt(rowIndex);
  96. store.remove(record);
  97. },
  98. /**
  99. * @private
  100. * @return {Ext.form.ComboBox} The editor
  101. */
  102. buildDimensionEditor: function() {
  103. return new Ext.form.ComboBox({
  104. mode : 'local',
  105. store: this.getFieldStore(),
  106. editable : false,
  107. valueField : 'name',
  108. displayField : 'name',
  109. triggerAction : 'all',
  110. forceSelection: true
  111. });
  112. },
  113. /**
  114. * @private
  115. * @return {Ext.data.Store} The store
  116. */
  117. getFieldStore: function() {
  118. /**
  119. * @property fieldStore
  120. * @type Ext.data.JsonStore
  121. * The store bound to the combo for selecting the field
  122. */
  123. if (this.fieldStore == undefined) {
  124. var fields = [],
  125. length = this.fields.length,
  126. i;
  127. for (i = 0; i < length; i++) {
  128. fields[i] = [this.fields[i]];
  129. }
  130. this.fieldStore = new Ext.data.ArrayStore({
  131. fields: ['name'],
  132. data : fields
  133. });
  134. }
  135. return this.fieldStore;
  136. },
  137. /**
  138. * @private
  139. * Creates a local combo with options for ASC and DESC
  140. * @return {Ext.form.ComboBox} The editor
  141. */
  142. buildDirectionEditor: function() {
  143. return new Ext.form.ComboBox({
  144. name : 'name',
  145. mode : 'local',
  146. editable : false,
  147. forceSelection: true,
  148. triggerAction : 'all',
  149. displayField : 'name',
  150. valueField : 'name',
  151. value : 'ASC',
  152. store: new Ext.data.JsonStore({
  153. fields : ['name'],
  154. data : [{name : 'ASC'}, {name : 'DESC'}]
  155. })
  156. });
  157. }
  158. });