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.

446 lines
16 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.grid.PivotGridView"></div>/**
  16. * @class Ext.grid.PivotGridView
  17. * @extends Ext.grid.GridView
  18. * Specialised GridView for rendering Pivot Grid components. Config can be passed to the PivotGridView via the PivotGrid constructor's
  19. * viewConfig option:
  20. <pre><code>
  21. new Ext.grid.PivotGrid({
  22. viewConfig: {
  23. title: 'My Pivot Grid',
  24. getCellCls: function(value) {
  25. return value > 10 'red' : 'green';
  26. }
  27. }
  28. });
  29. </code></pre>
  30. * <p>Currently {@link #title} and {@link #getCellCls} are the only configuration options accepted by PivotGridView. All other
  31. * interaction is performed via the {@link Ext.grid.PivotGrid PivotGrid} class.</p>
  32. */
  33. Ext.grid.PivotGridView = Ext.extend(Ext.grid.GridView, {
  34. <div id="prop-Ext.grid.PivotGridView-colHeaderCellCls"></div>/**
  35. * The CSS class added to all group header cells. Defaults to 'grid-hd-group-cell'
  36. * @property colHeaderCellCls
  37. * @type String
  38. */
  39. colHeaderCellCls: 'grid-hd-group-cell',
  40. <div id="cfg-Ext.grid.PivotGridView-title"></div>/**
  41. * @cfg {String} title Optional title to be placed in the top left corner of the PivotGrid. Defaults to an empty string.
  42. */
  43. title: '',
  44. <div id="cfg-Ext.grid.PivotGridView-getCellCls"></div>/**
  45. * @cfg {Function} getCellCls Optional function which should return a CSS class name for each cell value. This is useful when
  46. * color coding cells based on their value. Defaults to undefined.
  47. */
  48. <div id="method-Ext.grid.PivotGridView-getColumnHeaders"></div>/**
  49. * Returns the headers to be rendered at the top of the grid. Should be a 2-dimensional array, where each item specifies the number
  50. * of columns it groups (column in this case refers to normal grid columns). In the example below we have 5 city groups, which are
  51. * each part of a continent supergroup. The colspan for each city group refers to the number of normal grid columns that group spans,
  52. * so in this case the grid would be expected to have a total of 12 columns:
  53. <pre><code>
  54. [
  55. {
  56. items: [
  57. {header: 'England', colspan: 5},
  58. {header: 'USA', colspan: 3}
  59. ]
  60. },
  61. {
  62. items: [
  63. {header: 'London', colspan: 2},
  64. {header: 'Cambridge', colspan: 3},
  65. {header: 'Palo Alto', colspan: 3}
  66. ]
  67. }
  68. ]
  69. </code></pre>
  70. * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country ->
  71. * State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
  72. * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
  73. * be the sum of all child nodes beneath this node.
  74. */
  75. getColumnHeaders: function() {
  76. return this.grid.topAxis.buildHeaders();;
  77. },
  78. <div id="method-Ext.grid.PivotGridView-getRowHeaders"></div>/**
  79. * Returns the headers to be rendered on the left of the grid. Should be a 2-dimensional array, where each item specifies the number
  80. * of rows it groups. In the example below we have 5 city groups, which are each part of a continent supergroup. The rowspan for each
  81. * city group refers to the number of normal grid columns that group spans, so in this case the grid would be expected to have a
  82. * total of 12 rows:
  83. <pre><code>
  84. [
  85. {
  86. width: 90,
  87. items: [
  88. {header: 'England', rowspan: 5},
  89. {header: 'USA', rowspan: 3}
  90. ]
  91. },
  92. {
  93. width: 50,
  94. items: [
  95. {header: 'London', rowspan: 2},
  96. {header: 'Cambridge', rowspan: 3},
  97. {header: 'Palo Alto', rowspan: 3}
  98. ]
  99. }
  100. ]
  101. </code></pre>
  102. * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country ->
  103. * State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
  104. * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
  105. * be the sum of all child nodes beneath this node.
  106. * Each group may specify the width it should be rendered with.
  107. * @return {Array} The row groups
  108. */
  109. getRowHeaders: function() {
  110. return this.grid.leftAxis.buildHeaders();
  111. },
  112. /**
  113. * @private
  114. * Renders rows between start and end indexes
  115. * @param {Number} startRow Index of the first row to render
  116. * @param {Number} endRow Index of the last row to render
  117. */
  118. renderRows : function(startRow, endRow) {
  119. var grid = this.grid,
  120. rows = grid.extractData(),
  121. rowCount = rows.length,
  122. templates = this.templates,
  123. renderer = grid.renderer,
  124. hasRenderer = typeof renderer == 'function',
  125. getCellCls = this.getCellCls,
  126. hasGetCellCls = typeof getCellCls == 'function',
  127. cellTemplate = templates.cell,
  128. rowTemplate = templates.row,
  129. rowBuffer = [],
  130. meta = {},
  131. tstyle = 'width:' + this.getGridInnerWidth() + 'px;',
  132. colBuffer, column, i;
  133. startRow = startRow || 0;
  134. endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1;
  135. for (i = 0; i < rowCount; i++) {
  136. row = rows[i];
  137. colCount = row.length;
  138. colBuffer = [];
  139. rowIndex = startRow + i;
  140. //build up each column's HTML
  141. for (j = 0; j < colCount; j++) {
  142. cell = row[j];
  143. meta.css = j === 0 ? 'x-grid3-cell-first ' : (j == (colCount - 1) ? 'x-grid3-cell-last ' : '');
  144. meta.attr = meta.cellAttr = '';
  145. meta.value = cell;
  146. if (Ext.isEmpty(meta.value)) {
  147. meta.value = '&#160;';
  148. }
  149. if (hasRenderer) {
  150. meta.value = renderer(meta.value);
  151. }
  152. if (hasGetCellCls) {
  153. meta.css += getCellCls(meta.value) + ' ';
  154. }
  155. colBuffer[colBuffer.length] = cellTemplate.apply(meta);
  156. }
  157. rowBuffer[rowBuffer.length] = rowTemplate.apply({
  158. tstyle: tstyle,
  159. cols : colCount,
  160. cells : colBuffer.join(""),
  161. alt : ''
  162. });
  163. }
  164. return rowBuffer.join("");
  165. },
  166. <div id="prop-Ext.grid.PivotGridView-Ext.Template"></div>/**
  167. * The master template to use when rendering the GridView. Has a default template
  168. * @property Ext.Template
  169. * @type masterTpl
  170. */
  171. masterTpl: new Ext.Template(
  172. '<div class="x-grid3 x-pivotgrid" hidefocus="true">',
  173. '<div class="x-grid3-viewport">',
  174. '<div class="x-grid3-header">',
  175. '<div class="x-grid3-header-title"><span>{title}</span></div>',
  176. '<div class="x-grid3-header-inner">',
  177. '<div class="x-grid3-header-offset" style="{ostyle}"></div>',
  178. '</div>',
  179. '<div class="x-clear"></div>',
  180. '</div>',
  181. '<div class="x-grid3-scroller">',
  182. '<div class="x-grid3-row-headers"></div>',
  183. '<div class="x-grid3-body" style="{bstyle}">{body}</div>',
  184. '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>',
  185. '</div>',
  186. '</div>',
  187. '<div class="x-grid3-resize-marker">&#160;</div>',
  188. '<div class="x-grid3-resize-proxy">&#160;</div>',
  189. '</div>'
  190. ),
  191. /**
  192. * @private
  193. * Adds a gcell template to the internal templates object. This is used to render the headers in a multi-level column header.
  194. */
  195. initTemplates: function() {
  196. Ext.grid.PivotGridView.superclass.initTemplates.apply(this, arguments);
  197. var templates = this.templates || {};
  198. if (!templates.gcell) {
  199. templates.gcell = new Ext.XTemplate(
  200. '<td class="x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} ' + this.colHeaderCellCls + '" style="{style}">',
  201. '<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">',
  202. this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', '{value}',
  203. '</div>',
  204. '</td>'
  205. );
  206. }
  207. this.templates = templates;
  208. this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
  209. },
  210. /**
  211. * @private
  212. * Sets up the reference to the row headers element
  213. */
  214. initElements: function() {
  215. Ext.grid.PivotGridView.superclass.initElements.apply(this, arguments);
  216. <div id="prop-Ext.grid.PivotGridView-rowHeadersEl"></div>/**
  217. * @property rowHeadersEl
  218. * @type Ext.Element
  219. * The element containing all row headers
  220. */
  221. this.rowHeadersEl = new Ext.Element(this.scroller.child('div.x-grid3-row-headers'));
  222. <div id="prop-Ext.grid.PivotGridView-headerTitleEl"></div>/**
  223. * @property headerTitleEl
  224. * @type Ext.Element
  225. * The element that contains the optional title (top left section of the pivot grid)
  226. */
  227. this.headerTitleEl = new Ext.Element(this.mainHd.child('div.x-grid3-header-title'));
  228. },
  229. /**
  230. * @private
  231. * Takes row headers into account when calculating total available width
  232. */
  233. getGridInnerWidth: function() {
  234. var previousWidth = Ext.grid.PivotGridView.superclass.getGridInnerWidth.apply(this, arguments);
  235. return previousWidth - this.getTotalRowHeaderWidth();
  236. },
  237. <div id="method-Ext.grid.PivotGridView-getTotalRowHeaderWidth"></div>/**
  238. * Returns the total width of all row headers as specified by {@link #getRowHeaders}
  239. * @return {Number} The total width
  240. */
  241. getTotalRowHeaderWidth: function() {
  242. var headers = this.getRowHeaders(),
  243. length = headers.length,
  244. total = 0,
  245. i;
  246. for (i = 0; i< length; i++) {
  247. total += headers[i].width;
  248. }
  249. return total;
  250. },
  251. /**
  252. * @private
  253. * Returns the total height of all column headers
  254. * @return {Number} The total height
  255. */
  256. getTotalColumnHeaderHeight: function() {
  257. return this.getColumnHeaders().length * 21;
  258. },
  259. /**
  260. * @private
  261. * Slight specialisation of the GridView renderUI - just adds the row headers
  262. */
  263. renderUI : function() {
  264. var templates = this.templates,
  265. innerWidth = this.getGridInnerWidth();
  266. return templates.master.apply({
  267. body : templates.body.apply({rows:'&#160;'}),
  268. ostyle: 'width:' + innerWidth + 'px',
  269. bstyle: 'width:' + innerWidth + 'px'
  270. });
  271. },
  272. /**
  273. * @private
  274. * Make sure that the headers and rows are all sized correctly during layout
  275. */
  276. onLayout: function(width, height) {
  277. Ext.grid.PivotGridView.superclass.onLayout.apply(this, arguments);
  278. var width = this.getGridInnerWidth();
  279. this.resizeColumnHeaders(width);
  280. this.resizeAllRows(width);
  281. },
  282. <div id="method-Ext.grid.PivotGridView-refresh"></div>/**
  283. * Refreshs the grid UI
  284. * @param {Boolean} headersToo (optional) True to also refresh the headers
  285. */
  286. refresh : function(headersToo) {
  287. this.fireEvent('beforerefresh', this);
  288. this.grid.stopEditing(true);
  289. var result = this.renderBody();
  290. this.mainBody.update(result).setWidth(this.getGridInnerWidth());
  291. if (headersToo === true) {
  292. this.updateHeaders();
  293. this.updateHeaderSortState();
  294. }
  295. this.processRows(0, true);
  296. this.layout();
  297. this.applyEmptyText();
  298. this.fireEvent('refresh', this);
  299. },
  300. /**
  301. * @private
  302. * Bypasses GridView's renderHeaders as they are taken care of separately by the PivotAxis instances
  303. */
  304. renderHeaders: Ext.emptyFn,
  305. /**
  306. * @private
  307. * Taken care of by PivotAxis
  308. */
  309. fitColumns: Ext.emptyFn,
  310. /**
  311. * @private
  312. * Called on layout, ensures that the width of each column header is correct. Omitting this can lead to faulty
  313. * layouts when nested in a container.
  314. * @param {Number} width The new width
  315. */
  316. resizeColumnHeaders: function(width) {
  317. var topAxis = this.grid.topAxis;
  318. if (topAxis.rendered) {
  319. topAxis.el.setWidth(width);
  320. }
  321. },
  322. /**
  323. * @private
  324. * Sets the row header div to the correct width. Should be called after rendering and reconfiguration of headers
  325. */
  326. resizeRowHeaders: function() {
  327. var rowHeaderWidth = this.getTotalRowHeaderWidth(),
  328. marginStyle = String.format("margin-left: {0}px;", rowHeaderWidth);
  329. this.rowHeadersEl.setWidth(rowHeaderWidth);
  330. this.mainBody.applyStyles(marginStyle);
  331. Ext.fly(this.innerHd).applyStyles(marginStyle);
  332. this.headerTitleEl.setWidth(rowHeaderWidth);
  333. this.headerTitleEl.setHeight(this.getTotalColumnHeaderHeight());
  334. },
  335. /**
  336. * @private
  337. * Resizes all rendered rows to the given width. Usually called by onLayout
  338. * @param {Number} width The new width
  339. */
  340. resizeAllRows: function(width) {
  341. var rows = this.getRows(),
  342. length = rows.length,
  343. i;
  344. for (i = 0; i < length; i++) {
  345. Ext.fly(rows[i]).setWidth(width);
  346. Ext.fly(rows[i]).child('table').setWidth(width);
  347. }
  348. },
  349. /**
  350. * @private
  351. * Updates the Row Headers, deferring the updating of Column Headers to GridView
  352. */
  353. updateHeaders: function() {
  354. this.renderGroupRowHeaders();
  355. this.renderGroupColumnHeaders();
  356. },
  357. /**
  358. * @private
  359. * Renders all row header groups at all levels based on the structure fetched from {@link #getGroupRowHeaders}
  360. */
  361. renderGroupRowHeaders: function() {
  362. var leftAxis = this.grid.leftAxis;
  363. this.resizeRowHeaders();
  364. leftAxis.rendered = false;
  365. leftAxis.render(this.rowHeadersEl);
  366. this.setTitle(this.title);
  367. },
  368. <div id="method-Ext.grid.PivotGridView-setTitle"></div>/**
  369. * Sets the title text in the top left segment of the PivotGridView
  370. * @param {String} title The title
  371. */
  372. setTitle: function(title) {
  373. this.headerTitleEl.child('span').dom.innerHTML = title;
  374. },
  375. /**
  376. * @private
  377. * Renders all column header groups at all levels based on the structure fetched from {@link #getColumnHeaders}
  378. */
  379. renderGroupColumnHeaders: function() {
  380. var topAxis = this.grid.topAxis;
  381. topAxis.rendered = false;
  382. topAxis.render(this.innerHd.firstChild);
  383. },
  384. /**
  385. * @private
  386. * Overridden to test whether the user is hovering over a group cell, in which case we don't show the menu
  387. */
  388. isMenuDisabled: function(cellIndex, el) {
  389. return true;
  390. }
  391. });</pre>
  392. </body>
  393. </html>