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.

253 lines
7.4 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.BufferView"></div>/**
  17. * @class Ext.ux.grid.BufferView
  18. * @extends Ext.grid.GridView
  19. * A custom GridView which renders rows on an as-needed basis.
  20. */
  21. Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
  22. <div id="cfg-Ext.ux.grid.BufferView-rowHeight"></div>/**
  23. * @cfg {Number} rowHeight
  24. * The height of a row in the grid.
  25. */
  26. rowHeight: 19,
  27. <div id="cfg-Ext.ux.grid.BufferView-borderHeight"></div>/**
  28. * @cfg {Number} borderHeight
  29. * The combined height of border-top and border-bottom of a row.
  30. */
  31. borderHeight: 2,
  32. <div id="cfg-Ext.ux.grid.BufferView-scrollDelay"></div>/**
  33. * @cfg {Boolean/Number} scrollDelay
  34. * The number of milliseconds before rendering rows out of the visible
  35. * viewing area. Defaults to 100. Rows will render immediately with a config
  36. * of false.
  37. */
  38. scrollDelay: 100,
  39. <div id="cfg-Ext.ux.grid.BufferView-cacheSize"></div>/**
  40. * @cfg {Number} cacheSize
  41. * The number of rows to look forward and backwards from the currently viewable
  42. * area. The cache applies only to rows that have been rendered already.
  43. */
  44. cacheSize: 20,
  45. <div id="cfg-Ext.ux.grid.BufferView-cleanDelay"></div>/**
  46. * @cfg {Number} cleanDelay
  47. * The number of milliseconds to buffer cleaning of extra rows not in the
  48. * cache.
  49. */
  50. cleanDelay: 500,
  51. initTemplates : function(){
  52. Ext.ux.grid.BufferView.superclass.initTemplates.call(this);
  53. var ts = this.templates;
  54. // empty div to act as a place holder for a row
  55. ts.rowHolder = new Ext.Template(
  56. '<div class="x-grid3-row {alt}" style="{tstyle}"></div>'
  57. );
  58. ts.rowHolder.disableFormats = true;
  59. ts.rowHolder.compile();
  60. ts.rowBody = new Ext.Template(
  61. '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
  62. '<tbody><tr>{cells}</tr>',
  63. (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
  64. '</tbody></table>'
  65. );
  66. ts.rowBody.disableFormats = true;
  67. ts.rowBody.compile();
  68. },
  69. getStyleRowHeight : function(){
  70. return Ext.isBorderBox ? (this.rowHeight + this.borderHeight) : this.rowHeight;
  71. },
  72. getCalculatedRowHeight : function(){
  73. return this.rowHeight + this.borderHeight;
  74. },
  75. getVisibleRowCount : function(){
  76. var rh = this.getCalculatedRowHeight(),
  77. visibleHeight = this.scroller.dom.clientHeight;
  78. return (visibleHeight < 1) ? 0 : Math.ceil(visibleHeight / rh);
  79. },
  80. getVisibleRows: function(){
  81. var count = this.getVisibleRowCount(),
  82. sc = this.scroller.dom.scrollTop,
  83. start = (sc === 0 ? 0 : Math.floor(sc/this.getCalculatedRowHeight())-1);
  84. return {
  85. first: Math.max(start, 0),
  86. last: Math.min(start + count + 2, this.ds.getCount()-1)
  87. };
  88. },
  89. doRender : function(cs, rs, ds, startRow, colCount, stripe, onlyBody){
  90. var ts = this.templates,
  91. ct = ts.cell,
  92. rt = ts.row,
  93. rb = ts.rowBody,
  94. last = colCount-1,
  95. rh = this.getStyleRowHeight(),
  96. vr = this.getVisibleRows(),
  97. tstyle = 'width:'+this.getTotalWidth()+';height:'+rh+'px;',
  98. // buffers
  99. buf = [],
  100. cb,
  101. c,
  102. p = {},
  103. rp = {tstyle: tstyle},
  104. r;
  105. for (var j = 0, len = rs.length; j < len; j++) {
  106. r = rs[j]; cb = [];
  107. var rowIndex = (j+startRow),
  108. visible = rowIndex >= vr.first && rowIndex <= vr.last;
  109. if (visible) {
  110. for (var i = 0; i < colCount; i++) {
  111. c = cs[i];
  112. p.id = c.id;
  113. p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
  114. p.attr = p.cellAttr = "";
  115. p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
  116. p.style = c.style;
  117. if (p.value === undefined || p.value === "") {
  118. p.value = "&#160;";
  119. }
  120. if (r.dirty && typeof r.modified[c.name] !== 'undefined') {
  121. p.css += ' x-grid3-dirty-cell';
  122. }
  123. cb[cb.length] = ct.apply(p);
  124. }
  125. }
  126. var alt = [];
  127. if(stripe && ((rowIndex+1) % 2 === 0)){
  128. alt[0] = "x-grid3-row-alt";
  129. }
  130. if(r.dirty){
  131. alt[1] = " x-grid3-dirty-row";
  132. }
  133. rp.cols = colCount;
  134. if(this.getRowClass){
  135. alt[2] = this.getRowClass(r, rowIndex, rp, ds);
  136. }
  137. rp.alt = alt.join(" ");
  138. rp.cells = cb.join("");
  139. buf[buf.length] = !visible ? ts.rowHolder.apply(rp) : (onlyBody ? rb.apply(rp) : rt.apply(rp));
  140. }
  141. return buf.join("");
  142. },
  143. isRowRendered: function(index){
  144. var row = this.getRow(index);
  145. return row && row.childNodes.length > 0;
  146. },
  147. syncScroll: function(){
  148. Ext.ux.grid.BufferView.superclass.syncScroll.apply(this, arguments);
  149. this.update();
  150. },
  151. // a (optionally) buffered method to update contents of gridview
  152. update: function(){
  153. if (this.scrollDelay) {
  154. if (!this.renderTask) {
  155. this.renderTask = new Ext.util.DelayedTask(this.doUpdate, this);
  156. }
  157. this.renderTask.delay(this.scrollDelay);
  158. }else{
  159. this.doUpdate();
  160. }
  161. },
  162. onRemove : function(ds, record, index, isUpdate){
  163. Ext.ux.grid.BufferView.superclass.onRemove.apply(this, arguments);
  164. if(isUpdate !== true){
  165. this.update();
  166. }
  167. },
  168. doUpdate: function(){
  169. if (this.getVisibleRowCount() > 0) {
  170. var g = this.grid,
  171. cm = g.colModel,
  172. ds = g.store,
  173. cs = this.getColumnData(),
  174. vr = this.getVisibleRows(),
  175. row;
  176. for (var i = vr.first; i <= vr.last; i++) {
  177. // if row is NOT rendered and is visible, render it
  178. if(!this.isRowRendered(i) && (row = this.getRow(i))){
  179. var html = this.doRender(cs, [ds.getAt(i)], ds, i, cm.getColumnCount(), g.stripeRows, true);
  180. row.innerHTML = html;
  181. }
  182. }
  183. this.clean();
  184. }
  185. },
  186. // a buffered method to clean rows
  187. clean : function(){
  188. if(!this.cleanTask){
  189. this.cleanTask = new Ext.util.DelayedTask(this.doClean, this);
  190. }
  191. this.cleanTask.delay(this.cleanDelay);
  192. },
  193. doClean: function(){
  194. if (this.getVisibleRowCount() > 0) {
  195. var vr = this.getVisibleRows();
  196. vr.first -= this.cacheSize;
  197. vr.last += this.cacheSize;
  198. var i = 0, rows = this.getRows();
  199. // if first is less than 0, all rows have been rendered
  200. // so lets clean the end...
  201. if(vr.first <= 0){
  202. i = vr.last + 1;
  203. }
  204. for(var len = this.ds.getCount(); i < len; i++){
  205. // if current row is outside of first and last and
  206. // has content, update the innerHTML to nothing
  207. if ((i < vr.first || i > vr.last) && rows[i].innerHTML) {
  208. rows[i].innerHTML = '';
  209. }
  210. }
  211. }
  212. },
  213. removeTask: function(name){
  214. var task = this[name];
  215. if(task && task.cancel){
  216. task.cancel();
  217. this[name] = null;
  218. }
  219. },
  220. destroy : function(){
  221. this.removeTask('cleanTask');
  222. this.removeTask('renderTask');
  223. Ext.ux.grid.BufferView.superclass.destroy.call(this);
  224. },
  225. layout: function(){
  226. Ext.ux.grid.BufferView.superclass.layout.call(this);
  227. this.update();
  228. }
  229. });</pre>
  230. </body>
  231. </html>