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.

250 lines
8.7 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. Ext.ns('Ext.ux.grid');
  16. <div id="cls-Ext.ux.grid.RowExpander"></div>/**
  17. * @class Ext.ux.grid.RowExpander
  18. * @extends Ext.util.Observable
  19. * Plugin (ptype = 'rowexpander') that adds the ability to have a Column in a grid which enables
  20. * a second row body which expands/contracts. The expand/contract behavior is configurable to react
  21. * on clicking of the column, double click of the row, and/or hitting enter while a row is selected.
  22. *
  23. * @ptype rowexpander
  24. */
  25. Ext.ux.grid.RowExpander = Ext.extend(Ext.util.Observable, {
  26. <div id="cfg-Ext.ux.grid.RowExpander-expandOnEnter"></div>/**
  27. * @cfg {Boolean} expandOnEnter
  28. * <tt>true</tt> to toggle selected row(s) between expanded/collapsed when the enter
  29. * key is pressed (defaults to <tt>true</tt>).
  30. */
  31. expandOnEnter : true,
  32. <div id="cfg-Ext.ux.grid.RowExpander-expandOnDblClick"></div>/**
  33. * @cfg {Boolean} expandOnDblClick
  34. * <tt>true</tt> to toggle a row between expanded/collapsed when double clicked
  35. * (defaults to <tt>true</tt>).
  36. */
  37. expandOnDblClick : true,
  38. header : '',
  39. width : 20,
  40. sortable : false,
  41. fixed : true,
  42. hideable: false,
  43. menuDisabled : true,
  44. dataIndex : '',
  45. id : 'expander',
  46. lazyRender : true,
  47. enableCaching : true,
  48. constructor: function(config){
  49. Ext.apply(this, config);
  50. this.addEvents({
  51. <div id="event-Ext.ux.grid.RowExpander-beforeexpand"></div>/**
  52. * @event beforeexpand
  53. * Fires before the row expands. Have the listener return false to prevent the row from expanding.
  54. * @param {Object} this RowExpander object.
  55. * @param {Object} Ext.data.Record Record for the selected row.
  56. * @param {Object} body body element for the secondary row.
  57. * @param {Number} rowIndex The current row index.
  58. */
  59. beforeexpand: true,
  60. <div id="event-Ext.ux.grid.RowExpander-expand"></div>/**
  61. * @event expand
  62. * Fires after the row expands.
  63. * @param {Object} this RowExpander object.
  64. * @param {Object} Ext.data.Record Record for the selected row.
  65. * @param {Object} body body element for the secondary row.
  66. * @param {Number} rowIndex The current row index.
  67. */
  68. expand: true,
  69. <div id="event-Ext.ux.grid.RowExpander-beforecollapse"></div>/**
  70. * @event beforecollapse
  71. * Fires before the row collapses. Have the listener return false to prevent the row from collapsing.
  72. * @param {Object} this RowExpander object.
  73. * @param {Object} Ext.data.Record Record for the selected row.
  74. * @param {Object} body body element for the secondary row.
  75. * @param {Number} rowIndex The current row index.
  76. */
  77. beforecollapse: true,
  78. <div id="event-Ext.ux.grid.RowExpander-collapse"></div>/**
  79. * @event collapse
  80. * Fires after the row collapses.
  81. * @param {Object} this RowExpander object.
  82. * @param {Object} Ext.data.Record Record for the selected row.
  83. * @param {Object} body body element for the secondary row.
  84. * @param {Number} rowIndex The current row index.
  85. */
  86. collapse: true
  87. });
  88. Ext.ux.grid.RowExpander.superclass.constructor.call(this);
  89. if(this.tpl){
  90. if(typeof this.tpl == 'string'){
  91. this.tpl = new Ext.Template(this.tpl);
  92. }
  93. this.tpl.compile();
  94. }
  95. this.state = {};
  96. this.bodyContent = {};
  97. },
  98. getRowClass : function(record, rowIndex, p, ds){
  99. p.cols = p.cols-1;
  100. var content = this.bodyContent[record.id];
  101. if(!content && !this.lazyRender){
  102. content = this.getBodyContent(record, rowIndex);
  103. }
  104. if(content){
  105. p.body = content;
  106. }
  107. return this.state[record.id] ? 'x-grid3-row-expanded' : 'x-grid3-row-collapsed';
  108. },
  109. init : function(grid){
  110. this.grid = grid;
  111. var view = grid.getView();
  112. view.getRowClass = this.getRowClass.createDelegate(this);
  113. view.enableRowBody = true;
  114. grid.on('render', this.onRender, this);
  115. grid.on('destroy', this.onDestroy, this);
  116. },
  117. // @private
  118. onRender: function() {
  119. var grid = this.grid;
  120. var mainBody = grid.getView().mainBody;
  121. mainBody.on('mousedown', this.onMouseDown, this, {delegate: '.x-grid3-row-expander'});
  122. if (this.expandOnEnter) {
  123. this.keyNav = new Ext.KeyNav(this.grid.getGridEl(), {
  124. 'enter' : this.onEnter,
  125. scope: this
  126. });
  127. }
  128. if (this.expandOnDblClick) {
  129. grid.on('rowdblclick', this.onRowDblClick, this);
  130. }
  131. },
  132. // @private
  133. onDestroy: function() {
  134. if(this.keyNav){
  135. this.keyNav.disable();
  136. delete this.keyNav;
  137. }
  138. /*
  139. * A majority of the time, the plugin will be destroyed along with the grid,
  140. * which means the mainBody won't be available. On the off chance that the plugin
  141. * isn't destroyed with the grid, take care of removing the listener.
  142. */
  143. var mainBody = this.grid.getView().mainBody;
  144. if(mainBody){
  145. mainBody.un('mousedown', this.onMouseDown, this);
  146. }
  147. },
  148. // @private
  149. onRowDblClick: function(grid, rowIdx, e) {
  150. this.toggleRow(rowIdx);
  151. },
  152. onEnter: function(e) {
  153. var g = this.grid;
  154. var sm = g.getSelectionModel();
  155. var sels = sm.getSelections();
  156. for (var i = 0, len = sels.length; i < len; i++) {
  157. var rowIdx = g.getStore().indexOf(sels[i]);
  158. this.toggleRow(rowIdx);
  159. }
  160. },
  161. getBodyContent : function(record, index){
  162. if(!this.enableCaching){
  163. return this.tpl.apply(record.data);
  164. }
  165. var content = this.bodyContent[record.id];
  166. if(!content){
  167. content = this.tpl.apply(record.data);
  168. this.bodyContent[record.id] = content;
  169. }
  170. return content;
  171. },
  172. onMouseDown : function(e, t){
  173. e.stopEvent();
  174. var row = e.getTarget('.x-grid3-row');
  175. this.toggleRow(row);
  176. },
  177. renderer : function(v, p, record){
  178. p.cellAttr = 'rowspan="2"';
  179. return '<div class="x-grid3-row-expander">&#160;</div>';
  180. },
  181. beforeExpand : function(record, body, rowIndex){
  182. if(this.fireEvent('beforeexpand', this, record, body, rowIndex) !== false){
  183. if(this.tpl && this.lazyRender){
  184. body.innerHTML = this.getBodyContent(record, rowIndex);
  185. }
  186. return true;
  187. }else{
  188. return false;
  189. }
  190. },
  191. toggleRow : function(row){
  192. if(typeof row == 'number'){
  193. row = this.grid.view.getRow(row);
  194. }
  195. this[Ext.fly(row).hasClass('x-grid3-row-collapsed') ? 'expandRow' : 'collapseRow'](row);
  196. },
  197. expandRow : function(row){
  198. if(typeof row == 'number'){
  199. row = this.grid.view.getRow(row);
  200. }
  201. var record = this.grid.store.getAt(row.rowIndex);
  202. var body = Ext.DomQuery.selectNode('tr:nth(2) div.x-grid3-row-body', row);
  203. if(this.beforeExpand(record, body, row.rowIndex)){
  204. this.state[record.id] = true;
  205. Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
  206. this.fireEvent('expand', this, record, body, row.rowIndex);
  207. }
  208. },
  209. collapseRow : function(row){
  210. if(typeof row == 'number'){
  211. row = this.grid.view.getRow(row);
  212. }
  213. var record = this.grid.store.getAt(row.rowIndex);
  214. var body = Ext.fly(row).child('tr:nth(1) div.x-grid3-row-body', true);
  215. if(this.fireEvent('beforecollapse', this, record, body, row.rowIndex) !== false){
  216. this.state[record.id] = false;
  217. Ext.fly(row).replaceClass('x-grid3-row-expanded', 'x-grid3-row-collapsed');
  218. this.fireEvent('collapse', this, record, body, row.rowIndex);
  219. }
  220. }
  221. });
  222. Ext.preg('rowexpander', Ext.ux.grid.RowExpander);
  223. //backwards compat
  224. Ext.grid.RowExpander = Ext.ux.grid.RowExpander;</pre>
  225. </body>
  226. </html>