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.

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