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.

191 lines
6.3 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.ConfigPanel
  17. * @extends Ext.Panel
  18. * A configuration panel used for modifying the properties of a PivotGrid.
  19. */
  20. pivot.ConfigPanel = Ext.extend(Ext.Panel, {
  21. title: 'Configure',
  22. layout: {
  23. type: 'vbox',
  24. align: 'stretch'
  25. },
  26. /**
  27. * @cfg {Ext.data.Record} record The Ext.data.Record to extract the field list from. Required
  28. */
  29. initComponent: function() {
  30. var fields = this.getRecordFields();
  31. /**
  32. * @property form
  33. * @type Ext.form.FormPanel
  34. * Used to set the measure and aggregation function
  35. */
  36. this.form = new Ext.Container({
  37. layout: 'form',
  38. style: 'padding: 7px',
  39. items: [{
  40. xtype: 'combo',
  41. mode: 'local',
  42. triggerAction: 'all',
  43. forceSelection: true,
  44. editable: false,
  45. anchor: "0",
  46. fieldLabel: 'Measure',
  47. ref: '/measure',
  48. name: 'measure',
  49. displayField: 'name',
  50. valueField: 'name',
  51. value: this.measure || this.measures[0],
  52. store: this.getMeasureStore()
  53. }, { xtype: 'combo',
  54. mode: 'local',
  55. triggerAction: 'all', forceSelection: true, editable: false, anchor: "0", fieldLabel: 'Aggregator', ref: '/aggregator',
  56. name: 'aggregator',
  57. displayField: 'name', valueField: 'value', value: this.aggregator,
  58. store: new Ext.data.JsonStore({
  59. fields : ['name', 'value'],
  60. data : [
  61. {name : 'Sum', value: 'sum'},
  62. {name : 'Count', value: 'count'},
  63. {name : 'Min', value: 'min'},
  64. {name : 'Max', value: 'max'},
  65. {name : 'Average', value: 'avg'}
  66. ]
  67. })
  68. }]
  69. });
  70. /**
  71. * @property leftAxisGrid
  72. * @type pivot.AxisGrid
  73. */
  74. this.leftAxisGrid = new pivot.AxisGrid({
  75. title : 'Left Axis',
  76. fields: fields,
  77. dimensionData: this.leftAxisDimensions || [],
  78. hasWidthField: true
  79. });
  80. /**
  81. * @property topAxisGrid
  82. * @type pivot.AxisGrid
  83. */
  84. this.topAxisGrid = new pivot.AxisGrid({
  85. title : 'Top Axis',
  86. fields: fields,
  87. dimensionData: this.topAxisDimensions || []
  88. });
  89. Ext.applyIf(this, {
  90. items: [
  91. this.form,
  92. this.topAxisGrid,
  93. this.leftAxisGrid
  94. ],
  95. fbar: {
  96. buttonAlign: 'left',
  97. items: [{
  98. icon : '../shared/icons/fam/accept.png',
  99. text : 'Update',
  100. scope : this,
  101. handler: this.updateGrid
  102. }]
  103. }
  104. });
  105. pivot.ConfigPanel.superclass.initComponent.apply(this, arguments);
  106. },
  107. /**
  108. * @private
  109. * Retrieves the configured axis dimensions for the top and left grids and updates the PivotGrid accordingly
  110. */
  111. updateGrid: function() {
  112. var leftDimensions = [],
  113. topDimensions = [],
  114. leftGridItems = this.leftAxisGrid.store.data.items,
  115. topGridItems = this.topAxisGrid.store.data.items,
  116. i;
  117. for (i = 0; i < leftGridItems.length; i++) {
  118. leftDimensions.push({
  119. dataIndex: leftGridItems[i].get('field'),
  120. direction: leftGridItems[i].get('direction'),
  121. width : leftGridItems[i].get('width')
  122. });
  123. }
  124. for (i = 0; i < topGridItems.length; i++) {
  125. topDimensions.push({
  126. dataIndex: topGridItems[i].get('field'),
  127. direction: topGridItems[i].get('direction')
  128. });
  129. }
  130. this.fireEvent('update', {
  131. leftDimensions: leftDimensions,
  132. topDimensions : topDimensions,
  133. aggregator : this.aggregator.getValue(),
  134. measure : this.measure.getValue()
  135. });
  136. },
  137. /**
  138. * Extracts the field names from the configured record
  139. * @return {Array} The set of Record fields
  140. */
  141. getRecordFields: function() {
  142. return Ext.pluck(this.record.prototype.fields.items, 'name');
  143. },
  144. /**
  145. * @private
  146. * @return {Ext.data.Store} The store
  147. */
  148. getMeasureStore: function() {
  149. /**
  150. * @property measureStore
  151. * @type Ext.data.JsonStore
  152. * The store bound to the combo for selecting the field
  153. */
  154. if (this.measureStore == undefined) {
  155. var fields = [],
  156. measures = this.measures,
  157. length = measures.length,
  158. i;
  159. for (i = 0; i < length; i++) {
  160. fields[i] = [measures[i]];
  161. }
  162. this.measureStore = new Ext.data.ArrayStore({
  163. fields: ['name'],
  164. data : fields
  165. });
  166. }
  167. return this.measureStore;
  168. }
  169. });
  170. Ext.reg('pivotconfig', pivot.ConfigPanel);