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.

304 lines
8.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');
  8. Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
  9. tabPosition: 'left',
  10. alternateColor: false,
  11. alternateCls: 'x-grouptabs-panel-alt',
  12. defaultType: 'grouptab',
  13. deferredRender: false,
  14. activeGroup : null,
  15. initComponent: function(){
  16. Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
  17. this.addEvents(
  18. 'beforegroupchange',
  19. 'groupchange'
  20. );
  21. this.elements = 'body,header';
  22. this.stripTarget = 'header';
  23. this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
  24. this.addClass('x-grouptabs-panel');
  25. if (this.tabStyle && this.tabStyle != '') {
  26. this.addClass('x-grouptabs-panel-' + this.tabStyle);
  27. }
  28. if (this.alternateColor) {
  29. this.addClass(this.alternateCls);
  30. }
  31. this.on('beforeadd', function(gtp, item, index){
  32. this.initGroup(item, index);
  33. });
  34. this.items.each(function(item){
  35. item.on('tabchange',function(item){
  36. this.fireEvent('tabchange', this, item.activeTab);
  37. }, this);
  38. },this);
  39. },
  40. initEvents : function() {
  41. this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
  42. },
  43. onRender: function(ct, position){
  44. Ext.TabPanel.superclass.onRender.call(this, ct, position);
  45. if(this.plain){
  46. var pos = this.tabPosition == 'top' ? 'header' : 'footer';
  47. this[pos].addClass('x-tab-panel-'+pos+'-plain');
  48. }
  49. var st = this[this.stripTarget];
  50. this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
  51. tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
  52. var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
  53. this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
  54. this.header.addClass('x-grouptabs-panel-header');
  55. this.bwrap.addClass('x-grouptabs-bwrap');
  56. this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
  57. if (!this.groupTpl) {
  58. var tt = new Ext.Template(
  59. '<li class="{cls}" id="{id}">',
  60. '<a class="x-grouptabs-expand" onclick="return false;"></a>',
  61. '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
  62. '<span>{text}</span></a>',
  63. '</li>'
  64. );
  65. tt.disableFormats = true;
  66. tt.compile();
  67. Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
  68. }
  69. this.items.each(this.initGroup, this);
  70. },
  71. afterRender: function(){
  72. Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
  73. this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
  74. cls: 'x-tab-joint'
  75. });
  76. this.addClass('x-tab-panel-' + this.tabPosition);
  77. this.header.setWidth(this.tabWidth);
  78. if (this.activeGroup !== undefined) {
  79. var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
  80. delete this.activeGroup;
  81. this.setActiveGroup(group);
  82. group.setActiveTab(group.getMainItem());
  83. }
  84. },
  85. getGroupEl : Ext.TabPanel.prototype.getTabEl,
  86. // private
  87. findTargets: function(e){
  88. var item = null,
  89. itemEl = e.getTarget('li', this.strip);
  90. if (itemEl) {
  91. item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
  92. if (item.disabled) {
  93. return {
  94. expand: null,
  95. item: null,
  96. el: null
  97. };
  98. }
  99. }
  100. return {
  101. expand: e.getTarget('.x-grouptabs-expand', this.strip),
  102. isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
  103. item: item,
  104. el: itemEl
  105. };
  106. },
  107. // private
  108. onStripMouseDown: function(e){
  109. if (e.button != 0) {
  110. return;
  111. }
  112. e.preventDefault();
  113. var t = this.findTargets(e);
  114. if (t.expand) {
  115. this.toggleGroup(t.el);
  116. }
  117. else if (t.item) {
  118. if(t.isGroup) {
  119. t.item.setActiveTab(t.item.getMainItem());
  120. }
  121. else {
  122. t.item.ownerCt.setActiveTab(t.item);
  123. }
  124. }
  125. },
  126. expandGroup: function(groupEl){
  127. if(groupEl.isXType) {
  128. groupEl = this.getGroupEl(groupEl);
  129. }
  130. Ext.fly(groupEl).addClass('x-grouptabs-expanded');
  131. this.syncTabJoint();
  132. },
  133. toggleGroup: function(groupEl){
  134. if(groupEl.isXType) {
  135. groupEl = this.getGroupEl(groupEl);
  136. }
  137. Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
  138. this.syncTabJoint();
  139. },
  140. collapseGroup: function(groupEl){
  141. if(groupEl.isXType) {
  142. groupEl = this.getGroupEl(groupEl);
  143. }
  144. Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
  145. this.syncTabJoint();
  146. },
  147. syncTabJoint: function(groupEl){
  148. if (!this.tabJoint) {
  149. return;
  150. }
  151. groupEl = groupEl || this.getGroupEl(this.activeGroup);
  152. if(groupEl) {
  153. this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
  154. var y = Ext.isGecko2 ? 0 : 1;
  155. if (this.tabPosition == 'left'){
  156. this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
  157. }
  158. else {
  159. this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
  160. }
  161. }
  162. else {
  163. this.tabJoint.hide();
  164. }
  165. },
  166. getActiveTab : function() {
  167. if(!this.activeGroup) return null;
  168. return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
  169. },
  170. onResize: function(){
  171. Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
  172. this.syncTabJoint();
  173. },
  174. createCorner: function(el, pos){
  175. return Ext.fly(el).createChild({
  176. cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
  177. });
  178. },
  179. initGroup: function(group, index){
  180. var before = this.strip.dom.childNodes[index],
  181. p = this.getTemplateArgs(group);
  182. if (index === 0) {
  183. p.cls += ' x-tab-first';
  184. }
  185. p.cls += ' x-grouptabs-main';
  186. p.text = group.getMainItem().title;
  187. var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
  188. tl = this.createCorner(el, 'top-' + this.tabPosition),
  189. bl = this.createCorner(el, 'bottom-' + this.tabPosition);
  190. group.tabEl = el;
  191. if (group.expanded) {
  192. this.expandGroup(el);
  193. }
  194. if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
  195. bl.setLeft('-10px');
  196. bl.setBottom('-5px');
  197. tl.setLeft('-10px');
  198. tl.setTop('-5px');
  199. }
  200. this.mon(group, {
  201. scope: this,
  202. changemainitem: this.onGroupChangeMainItem,
  203. beforetabchange: this.onGroupBeforeTabChange
  204. });
  205. },
  206. setActiveGroup : function(group) {
  207. group = this.getComponent(group);
  208. if(!group){
  209. return false;
  210. }
  211. if(!this.rendered){
  212. this.activeGroup = group;
  213. return true;
  214. }
  215. if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
  216. if(this.activeGroup){
  217. this.activeGroup.activeTab = null;
  218. var oldEl = this.getGroupEl(this.activeGroup);
  219. if(oldEl){
  220. Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
  221. }
  222. }
  223. var groupEl = this.getGroupEl(group);
  224. Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
  225. this.activeGroup = group;
  226. this.stack.add(group);
  227. this.layout.setActiveItem(group);
  228. this.syncTabJoint(groupEl);
  229. this.fireEvent('groupchange', this, group);
  230. return true;
  231. }
  232. return false;
  233. },
  234. onGroupBeforeTabChange: function(group, newTab, oldTab){
  235. if(group !== this.activeGroup || newTab !== oldTab) {
  236. this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
  237. }
  238. this.expandGroup(this.getGroupEl(group));
  239. if(group !== this.activeGroup) {
  240. return this.setActiveGroup(group);
  241. }
  242. },
  243. getFrameHeight: function(){
  244. var h = this.el.getFrameWidth('tb');
  245. h += (this.tbar ? this.tbar.getHeight() : 0) +
  246. (this.bbar ? this.bbar.getHeight() : 0);
  247. return h;
  248. },
  249. adjustBodyWidth: function(w){
  250. return w - this.tabWidth;
  251. }
  252. });
  253. Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);