Web UI for ARGUS server
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.

942 lines
34 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. /*!
  16. * Ext JS Library 3.3.0
  17. * Copyright(c) 2006-2010 Ext JS, Inc.
  18. * licensing@extjs.com
  19. * http://www.extjs.com/license
  20. */
  21. Ext.ns('Ext.ux.grid');
  22. Ext.ux.grid.LockingGridView = Ext.extend(Ext.grid.GridView, {
  23. lockText : 'Lock',
  24. unlockText : 'Unlock',
  25. rowBorderWidth : 1,
  26. lockedBorderWidth : 1,
  27. /*
  28. * This option ensures that height between the rows is synchronized
  29. * between the locked and unlocked sides. This option only needs to be used
  30. * when the row heights aren't predictable.
  31. */
  32. syncHeights: false,
  33. initTemplates : function(){
  34. var ts = this.templates || {};
  35. if (!ts.masterTpl) {
  36. ts.masterTpl = new Ext.Template(
  37. '<div class="x-grid3" hidefocus="true">',
  38. '<div class="x-grid3-locked">',
  39. '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{lstyle}">{lockedHeader}</div></div><div class="x-clear"></div></div>',
  40. '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{lstyle}">{lockedBody}</div><div class="x-grid3-scroll-spacer"></div></div>',
  41. '</div>',
  42. '<div class="x-grid3-viewport x-grid3-unlocked">',
  43. '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
  44. '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
  45. '</div>',
  46. '<div class="x-grid3-resize-marker">&#160;</div>',
  47. '<div class="x-grid3-resize-proxy">&#160;</div>',
  48. '</div>'
  49. );
  50. }
  51. this.templates = ts;
  52. Ext.ux.grid.LockingGridView.superclass.initTemplates.call(this);
  53. },
  54. getEditorParent : function(ed){
  55. return this.el.dom;
  56. },
  57. initElements : function(){
  58. var el = Ext.get(this.grid.getGridEl().dom.firstChild),
  59. lockedWrap = el.child('div.x-grid3-locked'),
  60. lockedHd = lockedWrap.child('div.x-grid3-header'),
  61. lockedScroller = lockedWrap.child('div.x-grid3-scroller'),
  62. mainWrap = el.child('div.x-grid3-viewport'),
  63. mainHd = mainWrap.child('div.x-grid3-header'),
  64. scroller = mainWrap.child('div.x-grid3-scroller');
  65. if (this.grid.hideHeaders) {
  66. lockedHd.setDisplayed(false);
  67. mainHd.setDisplayed(false);
  68. }
  69. if(this.forceFit){
  70. scroller.setStyle('overflow-x', 'hidden');
  71. }
  72. Ext.apply(this, {
  73. el : el,
  74. mainWrap: mainWrap,
  75. mainHd : mainHd,
  76. innerHd : mainHd.dom.firstChild,
  77. scroller: scroller,
  78. mainBody: scroller.child('div.x-grid3-body'),
  79. focusEl : scroller.child('a'),
  80. resizeMarker: el.child('div.x-grid3-resize-marker'),
  81. resizeProxy : el.child('div.x-grid3-resize-proxy'),
  82. lockedWrap: lockedWrap,
  83. lockedHd: lockedHd,
  84. lockedScroller: lockedScroller,
  85. lockedBody: lockedScroller.child('div.x-grid3-body'),
  86. lockedInnerHd: lockedHd.child('div.x-grid3-header-inner', true)
  87. });
  88. this.focusEl.swallowEvent('click', true);
  89. },
  90. getLockedRows : function(){
  91. return this.hasRows() ? this.lockedBody.dom.childNodes : [];
  92. },
  93. getLockedRow : function(row){
  94. return this.getLockedRows()[row];
  95. },
  96. getCell : function(row, col){
  97. var lockedLen = this.cm.getLockedCount();
  98. if(col < lockedLen){
  99. return this.getLockedRow(row).getElementsByTagName('td')[col];
  100. }
  101. return Ext.ux.grid.LockingGridView.superclass.getCell.call(this, row, col - lockedLen);
  102. },
  103. getHeaderCell : function(index){
  104. var lockedLen = this.cm.getLockedCount();
  105. if(index < lockedLen){
  106. return this.lockedHd.dom.getElementsByTagName('td')[index];
  107. }
  108. return Ext.ux.grid.LockingGridView.superclass.getHeaderCell.call(this, index - lockedLen);
  109. },
  110. addRowClass : function(row, cls){
  111. var lockedRow = this.getLockedRow(row);
  112. if(lockedRow){
  113. this.fly(lockedRow).addClass(cls);
  114. }
  115. Ext.ux.grid.LockingGridView.superclass.addRowClass.call(this, row, cls);
  116. },
  117. removeRowClass : function(row, cls){
  118. var lockedRow = this.getLockedRow(row);
  119. if(lockedRow){
  120. this.fly(lockedRow).removeClass(cls);
  121. }
  122. Ext.ux.grid.LockingGridView.superclass.removeRowClass.call(this, row, cls);
  123. },
  124. removeRow : function(row) {
  125. Ext.removeNode(this.getLockedRow(row));
  126. Ext.ux.grid.LockingGridView.superclass.removeRow.call(this, row);
  127. },
  128. removeRows : function(firstRow, lastRow){
  129. var lockedBody = this.lockedBody.dom,
  130. rowIndex = firstRow;
  131. for(; rowIndex <= lastRow; rowIndex++){
  132. Ext.removeNode(lockedBody.childNodes[firstRow]);
  133. }
  134. Ext.ux.grid.LockingGridView.superclass.removeRows.call(this, firstRow, lastRow);
  135. },
  136. syncScroll : function(e){
  137. this.lockedScroller.dom.scrollTop = this.scroller.dom.scrollTop;
  138. Ext.ux.grid.LockingGridView.superclass.syncScroll.call(this, e);
  139. },
  140. updateSortIcon : function(col, dir){
  141. var sortClasses = this.sortClasses,
  142. lockedHeaders = this.lockedHd.select('td').removeClass(sortClasses),
  143. headers = this.mainHd.select('td').removeClass(sortClasses),
  144. lockedLen = this.cm.getLockedCount(),
  145. cls = sortClasses[dir == 'DESC' ? 1 : 0];
  146. if(col < lockedLen){
  147. lockedHeaders.item(col).addClass(cls);
  148. }else{
  149. headers.item(col - lockedLen).addClass(cls);
  150. }
  151. },
  152. updateAllColumnWidths : function(){
  153. var tw = this.getTotalWidth(),
  154. clen = this.cm.getColumnCount(),
  155. lw = this.getLockedWidth(),
  156. llen = this.cm.getLockedCount(),
  157. ws = [], len, i;
  158. this.updateLockedWidth();
  159. for(i = 0; i < clen; i++){
  160. ws[i] = this.getColumnWidth(i);
  161. var hd = this.getHeaderCell(i);
  162. hd.style.width = ws[i];
  163. }
  164. var lns = this.getLockedRows(), ns = this.getRows(), row, trow, j;
  165. for(i = 0, len = ns.length; i < len; i++){
  166. row = lns[i];
  167. row.style.width = lw;
  168. if(row.firstChild){
  169. row.firstChild.style.width = lw;
  170. trow = row.firstChild.rows[0];
  171. for (j = 0; j < llen; j++) {
  172. trow.childNodes[j].style.width = ws[j];
  173. }
  174. }
  175. row = ns[i];
  176. row.style.width = tw;
  177. if(row.firstChild){
  178. row.firstChild.style.width = tw;
  179. trow = row.firstChild.rows[0];
  180. for (j = llen; j < clen; j++) {
  181. trow.childNodes[j - llen].style.width = ws[j];
  182. }
  183. }
  184. }
  185. this.onAllColumnWidthsUpdated(ws, tw);
  186. this.syncHeaderHeight();
  187. },
  188. updateColumnWidth : function(col, width){
  189. var w = this.getColumnWidth(col),
  190. llen = this.cm.getLockedCount(),
  191. ns, rw, c, row;
  192. this.updateLockedWidth();
  193. if(col < llen){
  194. ns = this.getLockedRows();
  195. rw = this.getLockedWidth();
  196. c = col;
  197. }else{
  198. ns = this.getRows();
  199. rw = this.getTotalWidth();
  200. c = col - llen;
  201. }
  202. var hd = this.getHeaderCell(col);
  203. hd.style.width = w;
  204. for(var i = 0, len = ns.length; i < len; i++){
  205. row = ns[i];
  206. row.style.width = rw;
  207. if(row.firstChild){
  208. row.firstChild.style.width = rw;
  209. row.firstChild.rows[0].childNodes[c].style.width = w;
  210. }
  211. }
  212. this.onColumnWidthUpdated(col, w, this.getTotalWidth());
  213. this.syncHeaderHeight();
  214. },
  215. updateColumnHidden : function(col, hidden){
  216. var llen = this.cm.getLockedCount(),
  217. ns, rw, c, row,
  218. display = hidden ? 'none' : '';
  219. this.updateLockedWidth();
  220. if(col < llen){
  221. ns = this.getLockedRows();
  222. rw = this.getLockedWidth();
  223. c = col;
  224. }else{
  225. ns = this.getRows();
  226. rw = this.getTotalWidth();
  227. c = col - llen;
  228. }
  229. var hd = this.getHeaderCell(col);
  230. hd.style.display = display;
  231. for(var i = 0, len = ns.length; i < len; i++){
  232. row = ns[i];
  233. row.style.width = rw;
  234. if(row.firstChild){
  235. row.firstChild.style.width = rw;
  236. row.firstChild.rows[0].childNodes[c].style.display = display;
  237. }
  238. }
  239. this.onColumnHiddenUpdated(col, hidden, this.getTotalWidth());
  240. delete this.lastViewWidth;
  241. this.layout();
  242. },
  243. doRender : function(cs, rs, ds, startRow, colCount, stripe){
  244. var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1,
  245. tstyle = 'width:'+this.getTotalWidth()+';',
  246. lstyle = 'width:'+this.getLockedWidth()+';',
  247. buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r;
  248. for(var j = 0, len = rs.length; j < len; j++){
  249. r = rs[j]; cb = []; lcb = [];
  250. var rowIndex = (j+startRow);
  251. for(var i = 0; i < colCount; i++){
  252. c = cs[i];
  253. p.id = c.id;
  254. p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
  255. (this.cm.config[i].cellCls ? ' ' + this.cm.config[i].cellCls : '');
  256. p.attr = p.cellAttr = '';
  257. p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
  258. p.style = c.style;
  259. if(Ext.isEmpty(p.value)){
  260. p.value = '&#160;';
  261. }
  262. if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
  263. p.css += ' x-grid3-dirty-cell';
  264. }
  265. if(c.locked){
  266. lcb[lcb.length] = ct.apply(p);
  267. }else{
  268. cb[cb.length] = ct.apply(p);
  269. }
  270. }
  271. var alt = [];
  272. if(stripe && ((rowIndex+1) % 2 === 0)){
  273. alt[0] = 'x-grid3-row-alt';
  274. }
  275. if(r.dirty){
  276. alt[1] = ' x-grid3-dirty-row';
  277. }
  278. rp.cols = colCount;
  279. if(this.getRowClass){
  280. alt[2] = this.getRowClass(r, rowIndex, rp, ds);
  281. }
  282. rp.alt = alt.join(' ');
  283. rp.cells = cb.join('');
  284. rp.tstyle = tstyle;
  285. buf[buf.length] = rt.apply(rp);
  286. rp.cells = lcb.join('');
  287. rp.tstyle = lstyle;
  288. lbuf[lbuf.length] = rt.apply(rp);
  289. }
  290. return [buf.join(''), lbuf.join('')];
  291. },
  292. processRows : function(startRow, skipStripe){
  293. if(!this.ds || this.ds.getCount() < 1){
  294. return;
  295. }
  296. var rows = this.getRows(),
  297. lrows = this.getLockedRows(),
  298. row, lrow;
  299. skipStripe = skipStripe || !this.grid.stripeRows;
  300. startRow = startRow || 0;
  301. for(var i = 0, len = rows.length; i < len; ++i){
  302. row = rows[i];
  303. lrow = lrows[i];
  304. row.rowIndex = i;
  305. lrow.rowIndex = i;
  306. if(!skipStripe){
  307. row.className = row.className.replace(this.rowClsRe, ' ');
  308. lrow.className = lrow.className.replace(this.rowClsRe, ' ');
  309. if ((i + 1) % 2 === 0){
  310. row.className += ' x-grid3-row-alt';
  311. lrow.className += ' x-grid3-row-alt';
  312. }
  313. }
  314. this.syncRowHeights(row, lrow);
  315. }
  316. if(startRow === 0){
  317. Ext.fly(rows[0]).addClass(this.firstRowCls);
  318. Ext.fly(lrows[0]).addClass(this.firstRowCls);
  319. }
  320. Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
  321. Ext.fly(lrows[lrows.length - 1]).addClass(this.lastRowCls);
  322. },
  323. syncRowHeights: function(row1, row2){
  324. if(this.syncHeights){
  325. var el1 = Ext.get(row1),
  326. el2 = Ext.get(row2),
  327. h1 = el1.getHeight(),
  328. h2 = el2.getHeight();
  329. if(h1 > h2){
  330. el2.setHeight(h1);
  331. }else if(h2 > h1){
  332. el1.setHeight(h2);
  333. }
  334. }
  335. },
  336. afterRender : function(){
  337. if(!this.ds || !this.cm){
  338. return;
  339. }
  340. var bd = this.renderRows() || ['&#160;', '&#160;'];
  341. this.mainBody.dom.innerHTML = bd[0];
  342. this.lockedBody.dom.innerHTML = bd[1];
  343. this.processRows(0, true);
  344. if(this.deferEmptyText !== true){
  345. this.applyEmptyText();
  346. }
  347. this.grid.fireEvent('viewready', this.grid);
  348. },
  349. renderUI : function(){
  350. var templates = this.templates,
  351. header = this.renderHeaders(),
  352. body = templates.body.apply({rows:'&#160;'});
  353. return templates.masterTpl.apply({
  354. body : body,
  355. header: header[0],
  356. ostyle: 'width:' + this.getOffsetWidth() + ';',
  357. bstyle: 'width:' + this.getTotalWidth() + ';',
  358. lockedBody: body,
  359. lockedHeader: header[1],
  360. lstyle: 'width:'+this.getLockedWidth()+';'
  361. });
  362. },
  363. afterRenderUI: function(){
  364. var g = this.grid;
  365. this.initElements();
  366. Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
  367. Ext.fly(this.lockedInnerHd).on('click', this.handleHdDown, this);
  368. this.mainHd.on({
  369. scope: this,
  370. mouseover: this.handleHdOver,
  371. mouseout: this.handleHdOut,
  372. mousemove: this.handleHdMove
  373. });
  374. this.lockedHd.on({
  375. scope: this,
  376. mouseover: this.handleHdOver,
  377. mouseout: this.handleHdOut,
  378. mousemove: this.handleHdMove
  379. });
  380. this.scroller.on('scroll', this.syncScroll, this);
  381. if(g.enableColumnResize !== false){
  382. this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
  383. this.splitZone.setOuterHandleElId(Ext.id(this.lockedHd.dom));
  384. this.splitZone.setOuterHandleElId(Ext.id(this.mainHd.dom));
  385. }
  386. if(g.enableColumnMove){
  387. this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
  388. this.columnDrag.setOuterHandleElId(Ext.id(this.lockedInnerHd));
  389. this.columnDrag.setOuterHandleElId(Ext.id(this.innerHd));
  390. this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
  391. }
  392. if(g.enableHdMenu !== false){
  393. this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
  394. this.hmenu.add(
  395. {itemId: 'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
  396. {itemId: 'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
  397. );
  398. if(this.grid.enableColLock !== false){
  399. this.hmenu.add('-',
  400. {itemId: 'lock', text: this.lockText, cls: 'xg-hmenu-lock'},
  401. {itemId: 'unlock', text: this.unlockText, cls: 'xg-hmenu-unlock'}
  402. );
  403. }
  404. if(g.enableColumnHide !== false){
  405. this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
  406. this.colMenu.on({
  407. scope: this,
  408. beforeshow: this.beforeColMenuShow,
  409. itemclick: this.handleHdMenuClick
  410. });
  411. this.hmenu.add('-', {
  412. itemId:'columns',
  413. hideOnClick: false,
  414. text: this.columnsText,
  415. menu: this.colMenu,
  416. iconCls: 'x-cols-icon'
  417. });
  418. }
  419. this.hmenu.on('itemclick', this.handleHdMenuClick, this);
  420. }
  421. if(g.trackMouseOver){
  422. this.mainBody.on({
  423. scope: this,
  424. mouseover: this.onRowOver,
  425. mouseout: this.onRowOut
  426. });
  427. this.lockedBody.on({
  428. scope: this,
  429. mouseover: this.onRowOver,
  430. mouseout: this.onRowOut
  431. });
  432. }
  433. if(g.enableDragDrop || g.enableDrag){
  434. this.dragZone = new Ext.grid.GridDragZone(g, {
  435. ddGroup : g.ddGroup || 'GridDD'
  436. });
  437. }
  438. this.updateHeaderSortState();
  439. },
  440. layout : function(){
  441. if(!this.mainBody){
  442. return;
  443. }
  444. var g = this.grid;
  445. var c = g.getGridEl();
  446. var csize = c.getSize(true);
  447. var vw = csize.width;
  448. if(!g.hideHeaders && (vw < 20 || csize.height < 20)){
  449. return;
  450. }
  451. this.syncHeaderHeight();
  452. if(g.autoHeight){
  453. this.scroller.dom.style.overflow = 'visible';
  454. this.lockedScroller.dom.style.overflow = 'visible';
  455. if(Ext.isWebKit){
  456. this.scroller.dom.style.position = 'static';
  457. this.lockedScroller.dom.style.position = 'static';
  458. }
  459. }else{
  460. this.el.setSize(csize.width, csize.height);
  461. var hdHeight = this.mainHd.getHeight();
  462. var vh = csize.height - (hdHeight);
  463. }
  464. this.updateLockedWidth();
  465. if(this.forceFit){
  466. if(this.lastViewWidth != vw){
  467. this.fitColumns(false, false);
  468. this.lastViewWidth = vw;
  469. }
  470. }else {
  471. this.autoExpand();
  472. this.syncHeaderScroll();
  473. }
  474. this.onLayout(vw, vh);
  475. },
  476. getOffsetWidth : function() {
  477. return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth() + this.getScrollOffset()) + 'px';
  478. },
  479. renderHeaders : function(){
  480. var cm = this.cm,
  481. ts = this.templates,
  482. ct = ts.hcell,
  483. cb = [], lcb = [],
  484. p = {},
  485. len = cm.getColumnCount(),
  486. last = len - 1;
  487. for(var i = 0; i < len; i++){
  488. p.id = cm.getColumnId(i);
  489. p.value = cm.getColumnHeader(i) || '';
  490. p.style = this.getColumnStyle(i, true);
  491. p.tooltip = this.getColumnTooltip(i);
  492. p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
  493. (cm.config[i].headerCls ? ' ' + cm.config[i].headerCls : '');
  494. if(cm.config[i].align == 'right'){
  495. p.istyle = 'padding-right:16px';
  496. } else {
  497. delete p.istyle;
  498. }
  499. if(cm.isLocked(i)){
  500. lcb[lcb.length] = ct.apply(p);
  501. }else{
  502. cb[cb.length] = ct.apply(p);
  503. }
  504. }
  505. return [ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'}),
  506. ts.header.apply({cells: lcb.join(''), tstyle:'width:'+this.getLockedWidth()+';'})];
  507. },
  508. updateHeaders : function(){
  509. var hd = this.renderHeaders();
  510. this.innerHd.firstChild.innerHTML = hd[0];
  511. this.innerHd.firstChild.style.width = this.getOffsetWidth();
  512. this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
  513. this.lockedInnerHd.firstChild.innerHTML = hd[1];
  514. var lw = this.getLockedWidth();
  515. this.lockedInnerHd.firstChild.style.width = lw;
  516. this.lockedInnerHd.firstChild.firstChild.style.width = lw;
  517. },
  518. getResolvedXY : function(resolved){
  519. if(!resolved){
  520. return null;
  521. }
  522. var c = resolved.cell, r = resolved.row;
  523. return c ? Ext.fly(c).getXY() : [this.scroller.getX(), Ext.fly(r).getY()];
  524. },
  525. syncFocusEl : function(row, col, hscroll){
  526. Ext.ux.grid.LockingGridView.superclass.syncFocusEl.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
  527. },
  528. ensureVisible : function(row, col, hscroll){
  529. return Ext.ux.grid.LockingGridView.superclass.ensureVisible.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
  530. },
  531. insertRows : function(dm, firstRow, lastRow, isUpdate){
  532. var last = dm.getCount() - 1;
  533. if(!isUpdate && firstRow === 0 && lastRow >= last){
  534. this.refresh();
  535. }else{
  536. if(!isUpdate){
  537. this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
  538. }
  539. var html = this.renderRows(firstRow, lastRow),
  540. before = this.getRow(firstRow);
  541. if(before){
  542. if(firstRow === 0){
  543. this.removeRowClass(0, this.firstRowCls);
  544. }
  545. Ext.DomHelper.insertHtml('beforeBegin', before, html[0]);
  546. before = this.getLockedRow(firstRow);
  547. Ext.DomHelper.insertHtml('beforeBegin', before, html[1]);
  548. }else{
  549. this.removeRowClass(last - 1, this.lastRowCls);
  550. Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html[0]);
  551. Ext.DomHelper.insertHtml('beforeEnd', this.lockedBody.dom, html[1]);
  552. }
  553. if(!isUpdate){
  554. this.fireEvent('rowsinserted', this, firstRow, lastRow);
  555. this.processRows(firstRow);
  556. }else if(firstRow === 0 || firstRow >= last){
  557. this.addRowClass(firstRow, firstRow === 0 ? this.firstRowCls : this.lastRowCls);
  558. }
  559. }
  560. this.syncFocusEl(firstRow);
  561. },
  562. getColumnStyle : function(col, isHeader){
  563. var style = !isHeader ? this.cm.config[col].cellStyle || this.cm.config[col].css || '' : this.cm.config[col].headerStyle || '';
  564. style += 'width:'+this.getColumnWidth(col)+';';
  565. if(this.cm.isHidden(col)){
  566. style += 'display:none;';
  567. }
  568. var align = this.cm.config[col].align;
  569. if(align){
  570. style += 'text-align:'+align+';';
  571. }
  572. return style;
  573. },
  574. getLockedWidth : function() {
  575. return this.cm.getTotalLockedWidth() + 'px';
  576. },
  577. getTotalWidth : function() {
  578. return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth()) + 'px';
  579. },
  580. getColumnData : function(){
  581. var cs = [], cm = this.cm, colCount = cm.getColumnCount();
  582. for(var i = 0; i < colCount; i++){
  583. var name = cm.getDataIndex(i);
  584. cs[i] = {
  585. name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
  586. renderer : cm.getRenderer(i),
  587. id : cm.getColumnId(i),
  588. style : this.getColumnStyle(i),
  589. locked : cm.isLocked(i)
  590. };
  591. }
  592. return cs;
  593. },
  594. renderBody : function(){
  595. var markup = this.renderRows() || ['&#160;', '&#160;'];
  596. return [this.templates.body.apply({rows: markup[0]}), this.templates.body.apply({rows: markup[1]})];
  597. },
  598. refreshRow: function(record){
  599. var store = this.ds,
  600. colCount = this.cm.getColumnCount(),
  601. columns = this.getColumnData(),
  602. last = colCount - 1,
  603. cls = ['x-grid3-row'],
  604. rowParams = {
  605. tstyle: String.format("width: {0};", this.getTotalWidth())
  606. },
  607. lockedRowParams = {
  608. tstyle: String.format("width: {0};", this.getLockedWidth())
  609. },
  610. colBuffer = [],
  611. lockedColBuffer = [],
  612. cellTpl = this.templates.cell,
  613. rowIndex,
  614. row,
  615. lockedRow,
  616. column,
  617. meta,
  618. css,
  619. i;
  620. if (Ext.isNumber(record)) {
  621. rowIndex = record;
  622. record = store.getAt(rowIndex);
  623. } else {
  624. rowIndex = store.indexOf(record);
  625. }
  626. if (!record || rowIndex < 0) {
  627. return;
  628. }
  629. for (i = 0; i < colCount; i++) {
  630. column = columns[i];
  631. if (i == 0) {
  632. css = 'x-grid3-cell-first';
  633. } else {
  634. css = (i == last) ? 'x-grid3-cell-last ' : '';
  635. }
  636. meta = {
  637. id: column.id,
  638. style: column.style,
  639. css: css,
  640. attr: "",
  641. cellAttr: ""
  642. };
  643. meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
  644. if (Ext.isEmpty(meta.value)) {
  645. meta.value = ' ';
  646. }
  647. if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
  648. meta.css += ' x-grid3-dirty-cell';
  649. }
  650. if (column.locked) {
  651. lockedColBuffer[i] = cellTpl.apply(meta);
  652. } else {
  653. colBuffer[i] = cellTpl.apply(meta);
  654. }
  655. }
  656. row = this.getRow(rowIndex);
  657. row.className = '';
  658. lockedRow = this.getLockedRow(rowIndex);
  659. lockedRow.className = '';
  660. if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) {
  661. cls.push('x-grid3-row-alt');
  662. }
  663. if (this.getRowClass) {
  664. rowParams.cols = colCount;
  665. cls.push(this.getRowClass(record, rowIndex, rowParams, store));
  666. }
  667. // Unlocked rows
  668. this.fly(row).addClass(cls).setStyle(rowParams.tstyle);
  669. rowParams.cells = colBuffer.join("");
  670. row.innerHTML = this.templates.rowInner.apply(rowParams);
  671. // Locked rows
  672. this.fly(lockedRow).addClass(cls).setStyle(lockedRowParams.tstyle);
  673. lockedRowParams.cells = lockedColBuffer.join("");
  674. lockedRow.innerHTML = this.templates.rowInner.apply(lockedRowParams);
  675. lockedRow.rowIndex = rowIndex;
  676. this.syncRowHeights(row, lockedRow);
  677. this.fireEvent('rowupdated', this, rowIndex, record);
  678. },
  679. refresh : function(headersToo){
  680. this.fireEvent('beforerefresh', this);
  681. this.grid.stopEditing(true);
  682. var result = this.renderBody();
  683. this.mainBody.update(result[0]).setWidth(this.getTotalWidth());
  684. this.lockedBody.update(result[1]).setWidth(this.getLockedWidth());
  685. if(headersToo === true){
  686. this.updateHeaders();
  687. this.updateHeaderSortState();
  688. }
  689. this.processRows(0, true);
  690. this.layout();
  691. this.applyEmptyText();
  692. this.fireEvent('refresh', this);
  693. },
  694. onDenyColumnLock : function(){
  695. },
  696. initData : function(ds, cm){
  697. if(this.cm){
  698. this.cm.un('columnlockchange', this.onColumnLock, this);
  699. }
  700. Ext.ux.grid.LockingGridView.superclass.initData.call(this, ds, cm);
  701. if(this.cm){
  702. this.cm.on('columnlockchange', this.onColumnLock, this);
  703. }
  704. },
  705. onColumnLock : function(){
  706. this.refresh(true);
  707. },
  708. handleHdMenuClick : function(item){
  709. var index = this.hdCtxIndex,
  710. cm = this.cm,
  711. id = item.getItemId(),
  712. llen = cm.getLockedCount();
  713. switch(id){
  714. case 'lock':
  715. if(cm.getColumnCount(true) <= llen + 1){
  716. this.onDenyColumnLock();
  717. return undefined;
  718. }
  719. cm.setLocked(index, true);
  720. if(llen != index){
  721. cm.moveColumn(index, llen);
  722. this.grid.fireEvent('columnmove', index, llen);
  723. }
  724. break;
  725. case 'unlock':
  726. if(llen - 1 != index){
  727. cm.setLocked(index, false, true);
  728. cm.moveColumn(index, llen - 1);
  729. this.grid.fireEvent('columnmove', index, llen - 1);
  730. }else{
  731. cm.setLocked(index, false);
  732. }
  733. break;
  734. default:
  735. return Ext.ux.grid.LockingGridView.superclass.handleHdMenuClick.call(this, item);
  736. }
  737. return true;
  738. },
  739. handleHdDown : function(e, t){
  740. Ext.ux.grid.LockingGridView.superclass.handleHdDown.call(this, e, t);
  741. if(this.grid.enableColLock !== false){
  742. if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
  743. var hd = this.findHeaderCell(t),
  744. index = this.getCellIndex(hd),
  745. ms = this.hmenu.items, cm = this.cm;
  746. ms.get('lock').setDisabled(cm.isLocked(index));
  747. ms.get('unlock').setDisabled(!cm.isLocked(index));
  748. }
  749. }
  750. },
  751. syncHeaderHeight: function(){
  752. var hrow = Ext.fly(this.innerHd).child('tr', true),
  753. lhrow = Ext.fly(this.lockedInnerHd).child('tr', true);
  754. hrow.style.height = 'auto';
  755. lhrow.style.height = 'auto';
  756. var hd = hrow.offsetHeight,
  757. lhd = lhrow.offsetHeight,
  758. height = Math.max(lhd, hd) + 'px';
  759. hrow.style.height = height;
  760. lhrow.style.height = height;
  761. },
  762. updateLockedWidth: function(){
  763. var lw = this.cm.getTotalLockedWidth(),
  764. tw = this.cm.getTotalWidth() - lw,
  765. csize = this.grid.getGridEl().getSize(true),
  766. lp = Ext.isBorderBox ? 0 : this.lockedBorderWidth,
  767. rp = Ext.isBorderBox ? 0 : this.rowBorderWidth,
  768. vw = (csize.width - lw - lp - rp) + 'px',
  769. so = this.getScrollOffset();
  770. if(!this.grid.autoHeight){
  771. var vh = (csize.height - this.mainHd.getHeight()) + 'px';
  772. this.lockedScroller.dom.style.height = vh;
  773. this.scroller.dom.style.height = vh;
  774. }
  775. this.lockedWrap.dom.style.width = (lw + rp) + 'px';
  776. this.scroller.dom.style.width = vw;
  777. this.mainWrap.dom.style.left = (lw + lp + rp) + 'px';
  778. if(this.innerHd){
  779. this.lockedInnerHd.firstChild.style.width = lw + 'px';
  780. this.lockedInnerHd.firstChild.firstChild.style.width = lw + 'px';
  781. this.innerHd.style.width = vw;
  782. this.innerHd.firstChild.style.width = (tw + rp + so) + 'px';
  783. this.innerHd.firstChild.firstChild.style.width = tw + 'px';
  784. }
  785. if(this.mainBody){
  786. this.lockedBody.dom.style.width = (lw + rp) + 'px';
  787. this.mainBody.dom.style.width = (tw + rp) + 'px';
  788. }
  789. }
  790. });
  791. Ext.ux.grid.LockingColumnModel = Ext.extend(Ext.grid.ColumnModel, {
  792. <div id="method-Ext.ux.grid.RowExpander-isLocked"></div>/**
  793. * Returns true if the given column index is currently locked
  794. * @param {Number} colIndex The column index
  795. * @return {Boolean} True if the column is locked
  796. */
  797. isLocked : function(colIndex){
  798. return this.config[colIndex].locked === true;
  799. },
  800. <div id="method-Ext.ux.grid.RowExpander-setLocked"></div>/**
  801. * Locks or unlocks a given column
  802. * @param {Number} colIndex The column index
  803. * @param {Boolean} value True to lock, false to unlock
  804. * @param {Boolean} suppressEvent Pass false to cause the columnlockchange event not to fire
  805. */
  806. setLocked : function(colIndex, value, suppressEvent){
  807. if (this.isLocked(colIndex) == value) {
  808. return;
  809. }
  810. this.config[colIndex].locked = value;
  811. if (!suppressEvent) {
  812. this.fireEvent('columnlockchange', this, colIndex, value);
  813. }
  814. },
  815. <div id="method-Ext.ux.grid.RowExpander-getTotalLockedWidth"></div>/**
  816. * Returns the total width of all locked columns
  817. * @return {Number} The width of all locked columns
  818. */
  819. getTotalLockedWidth : function(){
  820. var totalWidth = 0;
  821. for (var i = 0, len = this.config.length; i < len; i++) {
  822. if (this.isLocked(i) && !this.isHidden(i)) {
  823. totalWidth += this.getColumnWidth(i);
  824. }
  825. }
  826. return totalWidth;
  827. },
  828. <div id="method-Ext.ux.grid.RowExpander-getLockedCount"></div>/**
  829. * Returns the total number of locked columns
  830. * @return {Number} The number of locked columns
  831. */
  832. getLockedCount : function() {
  833. var len = this.config.length;
  834. for (var i = 0; i < len; i++) {
  835. if (!this.isLocked(i)) {
  836. return i;
  837. }
  838. }
  839. //if we get to this point all of the columns are locked so we return the total
  840. return len;
  841. },
  842. <div id="method-Ext.ux.grid.RowExpander-moveColumn"></div>/**
  843. * Moves a column from one position to another
  844. * @param {Number} oldIndex The current column index
  845. * @param {Number} newIndex The destination column index
  846. */
  847. moveColumn : function(oldIndex, newIndex){
  848. var oldLocked = this.isLocked(oldIndex),
  849. newLocked = this.isLocked(newIndex);
  850. if (oldIndex < newIndex && oldLocked && !newLocked) {
  851. this.setLocked(oldIndex, false, true);
  852. } else if (oldIndex > newIndex && !oldLocked && newLocked) {
  853. this.setLocked(oldIndex, true, true);
  854. }
  855. Ext.ux.grid.LockingColumnModel.superclass.moveColumn.apply(this, arguments);
  856. }
  857. });</pre>
  858. </body>
  859. </html>