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.

409 lines
13 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. /**
  8. * @class Ext.ux.tree.TreeGrid
  9. * @extends Ext.tree.TreePanel
  10. *
  11. * @xtype treegrid
  12. */
  13. Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, {
  14. rootVisible : false,
  15. useArrows : true,
  16. lines : false,
  17. borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
  18. cls : 'x-treegrid',
  19. columnResize : true,
  20. enableSort : true,
  21. reserveScrollOffset : true,
  22. enableHdMenu : true,
  23. columnsText : 'Columns',
  24. initComponent : function() {
  25. if(!this.root) {
  26. this.root = new Ext.tree.AsyncTreeNode({text: 'Root'});
  27. }
  28. // initialize the loader
  29. var l = this.loader;
  30. if(!l){
  31. l = new Ext.ux.tree.TreeGridLoader({
  32. dataUrl: this.dataUrl,
  33. requestMethod: this.requestMethod,
  34. store: this.store
  35. });
  36. }else if(Ext.isObject(l) && !l.load){
  37. l = new Ext.ux.tree.TreeGridLoader(l);
  38. }
  39. this.loader = l;
  40. Ext.ux.tree.TreeGrid.superclass.initComponent.call(this);
  41. this.initColumns();
  42. if(this.enableSort) {
  43. this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort);
  44. }
  45. if(this.columnResize){
  46. this.colResizer = new Ext.tree.ColumnResizer(this.columnResize);
  47. this.colResizer.init(this);
  48. }
  49. var c = this.columns;
  50. if(!this.internalTpl){
  51. this.internalTpl = new Ext.XTemplate(
  52. '<div class="x-grid3-header">',
  53. '<div class="x-treegrid-header-inner">',
  54. '<div class="x-grid3-header-offset">',
  55. '<table style="table-layout: fixed;" cellspacing="0" cellpadding="0" border="0"><colgroup><tpl for="columns"><col /></tpl></colgroup>',
  56. '<thead><tr class="x-grid3-hd-row">',
  57. '<tpl for="columns">',
  58. '<td class="x-grid3-hd x-grid3-cell x-treegrid-hd" style="text-align: {align};" id="', this.id, '-xlhd-{#}">',
  59. '<div class="x-grid3-hd-inner x-treegrid-hd-inner" unselectable="on">',
  60. this.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
  61. '{header}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
  62. '</div>',
  63. '</td></tpl>',
  64. '</tr></thead>',
  65. '</table>',
  66. '</div></div>',
  67. '</div>',
  68. '<div class="x-treegrid-root-node">',
  69. '<table class="x-treegrid-root-table" cellpadding="0" cellspacing="0" style="table-layout: fixed;"></table>',
  70. '</div>'
  71. );
  72. }
  73. if(!this.colgroupTpl) {
  74. this.colgroupTpl = new Ext.XTemplate(
  75. '<colgroup><tpl for="columns"><col style="width: {width}px"/></tpl></colgroup>'
  76. );
  77. }
  78. },
  79. initColumns : function() {
  80. var cs = this.columns,
  81. len = cs.length,
  82. columns = [],
  83. i, c;
  84. for(i = 0; i < len; i++){
  85. c = cs[i];
  86. if(!c.isColumn) {
  87. c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn';
  88. c = Ext.create(c);
  89. }
  90. c.init(this);
  91. columns.push(c);
  92. if(this.enableSort !== false && c.sortable !== false) {
  93. c.sortable = true;
  94. this.enableSort = true;
  95. }
  96. }
  97. this.columns = columns;
  98. },
  99. onRender : function(){
  100. Ext.tree.TreePanel.superclass.onRender.apply(this, arguments);
  101. this.el.addClass('x-treegrid');
  102. this.outerCt = this.body.createChild({
  103. cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')
  104. });
  105. this.internalTpl.overwrite(this.outerCt, {columns: this.columns});
  106. this.mainHd = Ext.get(this.outerCt.dom.firstChild);
  107. this.innerHd = Ext.get(this.mainHd.dom.firstChild);
  108. this.innerBody = Ext.get(this.outerCt.dom.lastChild);
  109. this.innerCt = Ext.get(this.innerBody.dom.firstChild);
  110. this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
  111. if(this.hideHeaders){
  112. this.el.child('.x-grid3-header').setDisplayed('none');
  113. }
  114. else if(this.enableHdMenu !== false){
  115. this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'});
  116. if(this.enableColumnHide !== false){
  117. this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'});
  118. this.colMenu.on({
  119. scope: this,
  120. beforeshow: this.beforeColMenuShow,
  121. itemclick: this.handleHdMenuClick
  122. });
  123. this.hmenu.add({
  124. itemId:'columns',
  125. hideOnClick: false,
  126. text: this.columnsText,
  127. menu: this.colMenu,
  128. iconCls: 'x-cols-icon'
  129. });
  130. }
  131. this.hmenu.on('itemclick', this.handleHdMenuClick, this);
  132. }
  133. },
  134. setRootNode : function(node){
  135. node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI;
  136. node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node);
  137. if(this.innerCt) {
  138. this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
  139. }
  140. return node;
  141. },
  142. clearInnerCt : function(){
  143. if(Ext.isIE){
  144. var dom = this.innerCt.dom;
  145. while(dom.firstChild){
  146. dom.removeChild(dom.firstChild);
  147. }
  148. }else{
  149. Ext.ux.tree.TreeGrid.superclass.clearInnerCt.call(this);
  150. }
  151. },
  152. initEvents : function() {
  153. Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments);
  154. this.mon(this.innerBody, 'scroll', this.syncScroll, this);
  155. this.mon(this.innerHd, 'click', this.handleHdDown, this);
  156. this.mon(this.mainHd, {
  157. scope: this,
  158. mouseover: this.handleHdOver,
  159. mouseout: this.handleHdOut
  160. });
  161. },
  162. onResize : function(w, h) {
  163. Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments);
  164. var bd = this.innerBody.dom;
  165. var hd = this.innerHd.dom;
  166. if(!bd){
  167. return;
  168. }
  169. if(Ext.isNumber(h)){
  170. bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px';
  171. }
  172. if(Ext.isNumber(w)){
  173. var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
  174. if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){
  175. this.setScrollOffset(sw);
  176. }else{
  177. var me = this;
  178. setTimeout(function(){
  179. me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0);
  180. }, 10);
  181. }
  182. }
  183. },
  184. updateColumnWidths : function() {
  185. var cols = this.columns,
  186. colCount = cols.length,
  187. groups = this.outerCt.query('colgroup'),
  188. groupCount = groups.length,
  189. c, g, i, j;
  190. for(i = 0; i<colCount; i++) {
  191. c = cols[i];
  192. for(j = 0; j<groupCount; j++) {
  193. g = groups[j];
  194. g.childNodes[i].style.width = (c.hidden ? 0 : c.width) + 'px';
  195. }
  196. }
  197. for(i = 0, groups = this.innerHd.query('td'), len = groups.length; i<len; i++) {
  198. c = Ext.fly(groups[i]);
  199. if(cols[i] && cols[i].hidden) {
  200. c.addClass('x-treegrid-hd-hidden');
  201. }
  202. else {
  203. c.removeClass('x-treegrid-hd-hidden');
  204. }
  205. }
  206. var tcw = this.getTotalColumnWidth();
  207. Ext.fly(this.innerHd.dom.firstChild).setWidth(tcw + (this.scrollOffset || 0));
  208. this.outerCt.select('table').setWidth(tcw);
  209. this.syncHeaderScroll();
  210. },
  211. getVisibleColumns : function() {
  212. var columns = [],
  213. cs = this.columns,
  214. len = cs.length,
  215. i;
  216. for(i = 0; i<len; i++) {
  217. if(!cs[i].hidden) {
  218. columns.push(cs[i]);
  219. }
  220. }
  221. return columns;
  222. },
  223. getTotalColumnWidth : function() {
  224. var total = 0;
  225. for(var i = 0, cs = this.getVisibleColumns(), len = cs.length; i<len; i++) {
  226. total += cs[i].width;
  227. }
  228. return total;
  229. },
  230. setScrollOffset : function(scrollOffset) {
  231. this.scrollOffset = scrollOffset;
  232. this.updateColumnWidths();
  233. },
  234. // private
  235. handleHdDown : function(e, t){
  236. var hd = e.getTarget('.x-treegrid-hd');
  237. if(hd && Ext.fly(t).hasClass('x-grid3-hd-btn')){
  238. var ms = this.hmenu.items,
  239. cs = this.columns,
  240. index = this.findHeaderIndex(hd),
  241. c = cs[index],
  242. sort = c.sortable;
  243. e.stopEvent();
  244. Ext.fly(hd).addClass('x-grid3-hd-menu-open');
  245. this.hdCtxIndex = index;
  246. this.fireEvent('headerbuttonclick', ms, c, hd, index);
  247. this.hmenu.on('hide', function(){
  248. Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
  249. }, this, {single:true});
  250. this.hmenu.show(t, 'tl-bl?');
  251. }
  252. else if(hd) {
  253. var index = this.findHeaderIndex(hd);
  254. this.fireEvent('headerclick', this.columns[index], hd, index);
  255. }
  256. },
  257. // private
  258. handleHdOver : function(e, t){
  259. var hd = e.getTarget('.x-treegrid-hd');
  260. if(hd && !this.headersDisabled){
  261. index = this.findHeaderIndex(hd);
  262. this.activeHdRef = t;
  263. this.activeHdIndex = index;
  264. var el = Ext.get(hd);
  265. this.activeHdRegion = el.getRegion();
  266. el.addClass('x-grid3-hd-over');
  267. this.activeHdBtn = el.child('.x-grid3-hd-btn');
  268. if(this.activeHdBtn){
  269. this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
  270. }
  271. }
  272. },
  273. // private
  274. handleHdOut : function(e, t){
  275. var hd = e.getTarget('.x-treegrid-hd');
  276. if(hd && (!Ext.isIE || !e.within(hd, true))){
  277. this.activeHdRef = null;
  278. Ext.fly(hd).removeClass('x-grid3-hd-over');
  279. hd.style.cursor = '';
  280. }
  281. },
  282. findHeaderIndex : function(hd){
  283. hd = hd.dom || hd;
  284. var cs = hd.parentNode.childNodes;
  285. for(var i = 0, c; c = cs[i]; i++){
  286. if(c == hd){
  287. return i;
  288. }
  289. }
  290. return -1;
  291. },
  292. // private
  293. beforeColMenuShow : function(){
  294. var cols = this.columns,
  295. colCount = cols.length,
  296. i, c;
  297. this.colMenu.removeAll();
  298. for(i = 1; i < colCount; i++){
  299. c = cols[i];
  300. if(c.hideable !== false){
  301. this.colMenu.add(new Ext.menu.CheckItem({
  302. itemId: 'col-' + i,
  303. text: c.header,
  304. checked: !c.hidden,
  305. hideOnClick:false,
  306. disabled: c.hideable === false
  307. }));
  308. }
  309. }
  310. },
  311. // private
  312. handleHdMenuClick : function(item){
  313. var index = this.hdCtxIndex,
  314. id = item.getItemId();
  315. if(this.fireEvent('headermenuclick', this.columns[index], id, index) !== false) {
  316. index = id.substr(4);
  317. if(index > 0 && this.columns[index]) {
  318. this.setColumnVisible(index, !item.checked);
  319. }
  320. }
  321. return true;
  322. },
  323. setColumnVisible : function(index, visible) {
  324. this.columns[index].hidden = !visible;
  325. this.updateColumnWidths();
  326. },
  327. /**
  328. * Scrolls the grid to the top
  329. */
  330. scrollToTop : function(){
  331. this.innerBody.dom.scrollTop = 0;
  332. this.innerBody.dom.scrollLeft = 0;
  333. },
  334. // private
  335. syncScroll : function(){
  336. this.syncHeaderScroll();
  337. var mb = this.innerBody.dom;
  338. this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
  339. },
  340. // private
  341. syncHeaderScroll : function(){
  342. var mb = this.innerBody.dom;
  343. this.innerHd.dom.scrollLeft = mb.scrollLeft;
  344. this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
  345. },
  346. registerNode : function(n) {
  347. Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n);
  348. if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) {
  349. n.ui = new Ext.ux.tree.TreeGridNodeUI(n);
  350. }
  351. }
  352. });
  353. Ext.reg('treegrid', Ext.ux.tree.TreeGrid);