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.

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