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.

360 lines
11 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. <div id="cls-Ext.layout.boxOverflow.Menu"></div>/**
  16. * @class Ext.layout.boxOverflow.Menu
  17. * @extends Ext.layout.boxOverflow.None
  18. * Description
  19. */
  20. Ext.layout.boxOverflow.Menu = Ext.extend(Ext.layout.boxOverflow.None, {
  21. <div id="cfg-Ext.layout.boxOverflow.Menu-null"></div>/**
  22. * @cfg afterCls
  23. * @type String
  24. * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
  25. * which must always be present at the rightmost edge of the Container
  26. */
  27. afterCls: 'x-strip-right',
  28. <div id="prop-Ext.layout.boxOverflow.Menu-noItemsMenuText"></div>/**
  29. * @property noItemsMenuText
  30. * @type String
  31. * HTML fragment to render into the toolbar overflow menu if there are no items to display
  32. */
  33. noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
  34. constructor: function(layout) {
  35. Ext.layout.boxOverflow.Menu.superclass.constructor.apply(this, arguments);
  36. <div id="prop-Ext.layout.boxOverflow.Menu-menuItems"></div>/**
  37. * @property menuItems
  38. * @type Array
  39. * Array of all items that are currently hidden and should go into the dropdown menu
  40. */
  41. this.menuItems = [];
  42. },
  43. /**
  44. * @private
  45. * Creates the beforeCt, innerCt and afterCt elements if they have not already been created
  46. * @param {Ext.Container} container The Container attached to this Layout instance
  47. * @param {Ext.Element} target The target Element
  48. */
  49. createInnerElements: function() {
  50. if (!this.afterCt) {
  51. this.afterCt = this.layout.innerCt.insertSibling({cls: this.afterCls}, 'before');
  52. }
  53. },
  54. /**
  55. * @private
  56. */
  57. clearOverflow: function(calculations, targetSize) {
  58. var newWidth = targetSize.width + (this.afterCt ? this.afterCt.getWidth() : 0),
  59. items = this.menuItems;
  60. this.hideTrigger();
  61. for (var index = 0, length = items.length; index < length; index++) {
  62. items.pop().component.show();
  63. }
  64. return {
  65. targetSize: {
  66. height: targetSize.height,
  67. width : newWidth
  68. }
  69. };
  70. },
  71. /**
  72. * @private
  73. */
  74. showTrigger: function() {
  75. this.createMenu();
  76. this.menuTrigger.show();
  77. },
  78. /**
  79. * @private
  80. */
  81. hideTrigger: function() {
  82. if (this.menuTrigger != undefined) {
  83. this.menuTrigger.hide();
  84. }
  85. },
  86. /**
  87. * @private
  88. * Called before the overflow menu is shown. This constructs the menu's items, caching them for as long as it can.
  89. */
  90. beforeMenuShow: function(menu) {
  91. var items = this.menuItems,
  92. len = items.length,
  93. item,
  94. prev;
  95. var needsSep = function(group, item){
  96. return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
  97. };
  98. this.clearMenu();
  99. menu.removeAll();
  100. for (var i = 0; i < len; i++) {
  101. item = items[i].component;
  102. if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
  103. menu.add('-');
  104. }
  105. this.addComponentToMenu(menu, item);
  106. prev = item;
  107. }
  108. // put something so the menu isn't empty if no compatible items found
  109. if (menu.items.length < 1) {
  110. menu.add(this.noItemsMenuText);
  111. }
  112. },
  113. /**
  114. * @private
  115. * Returns a menu config for a given component. This config is used to create a menu item
  116. * to be added to the expander menu
  117. * @param {Ext.Component} component The component to create the config for
  118. * @param {Boolean} hideOnClick Passed through to the menu item
  119. */
  120. createMenuConfig : function(component, hideOnClick){
  121. var config = Ext.apply({}, component.initialConfig),
  122. group = component.toggleGroup;
  123. Ext.copyTo(config, component, [
  124. 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
  125. ]);
  126. Ext.apply(config, {
  127. text : component.overflowText || component.text,
  128. hideOnClick: hideOnClick
  129. });
  130. if (group || component.enableToggle) {
  131. Ext.apply(config, {
  132. group : group,
  133. checked: component.pressed,
  134. listeners: {
  135. checkchange: function(item, checked){
  136. component.toggle(checked);
  137. }
  138. }
  139. });
  140. }
  141. delete config.ownerCt;
  142. delete config.xtype;
  143. delete config.id;
  144. return config;
  145. },
  146. /**
  147. * @private
  148. * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
  149. * @param {Ext.menu.Menu} menu The menu to add to
  150. * @param {Ext.Component} component The component to add
  151. */
  152. addComponentToMenu : function(menu, component) {
  153. if (component instanceof Ext.Toolbar.Separator) {
  154. menu.add('-');
  155. } else if (Ext.isFunction(component.isXType)) {
  156. if (component.isXType('splitbutton')) {
  157. menu.add(this.createMenuConfig(component, true));
  158. } else if (component.isXType('button')) {
  159. menu.add(this.createMenuConfig(component, !component.menu));
  160. } else if (component.isXType('buttongroup')) {
  161. component.items.each(function(item){
  162. this.addComponentToMenu(menu, item);
  163. }, this);
  164. }
  165. }
  166. },
  167. /**
  168. * @private
  169. * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
  170. * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
  171. */
  172. clearMenu : function(){
  173. var menu = this.moreMenu;
  174. if (menu && menu.items) {
  175. menu.items.each(function(item){
  176. delete item.menu;
  177. });
  178. }
  179. },
  180. /**
  181. * @private
  182. * Creates the overflow trigger and menu used when enableOverflow is set to true and the items
  183. * in the layout are too wide to fit in the space available
  184. */
  185. createMenu: function() {
  186. if (!this.menuTrigger) {
  187. this.createInnerElements();
  188. /**
  189. * @private
  190. * @property menu
  191. * @type Ext.menu.Menu
  192. * The expand menu - holds items for every item that cannot be shown
  193. * because the container is currently not large enough.
  194. */
  195. this.menu = new Ext.menu.Menu({
  196. ownerCt : this.layout.container,
  197. listeners: {
  198. scope: this,
  199. beforeshow: this.beforeMenuShow
  200. }
  201. });
  202. /**
  203. * @private
  204. * @property menuTrigger
  205. * @type Ext.Button
  206. * The expand button which triggers the overflow menu to be shown
  207. */
  208. this.menuTrigger = new Ext.Button({
  209. iconCls : 'x-toolbar-more-icon',
  210. cls : 'x-toolbar-more',
  211. menu : this.menu,
  212. renderTo: this.afterCt
  213. });
  214. }
  215. },
  216. /**
  217. * @private
  218. */
  219. destroy: function() {
  220. Ext.destroy(this.menu, this.menuTrigger);
  221. }
  222. });
  223. Ext.layout.boxOverflow.menu = Ext.layout.boxOverflow.Menu;
  224. <div id="cls-Ext.layout.boxOverflow.HorizontalMenu"></div>/**
  225. * @class Ext.layout.boxOverflow.HorizontalMenu
  226. * @extends Ext.layout.boxOverflow.Menu
  227. * Description
  228. */
  229. Ext.layout.boxOverflow.HorizontalMenu = Ext.extend(Ext.layout.boxOverflow.Menu, {
  230. constructor: function() {
  231. Ext.layout.boxOverflow.HorizontalMenu.superclass.constructor.apply(this, arguments);
  232. var me = this,
  233. layout = me.layout,
  234. origFunction = layout.calculateChildBoxes;
  235. layout.calculateChildBoxes = function(visibleItems, targetSize) {
  236. var calcs = origFunction.apply(layout, arguments),
  237. meta = calcs.meta,
  238. items = me.menuItems;
  239. //calculate the width of the items currently hidden solely because there is not enough space
  240. //to display them
  241. var hiddenWidth = 0;
  242. for (var index = 0, length = items.length; index < length; index++) {
  243. hiddenWidth += items[index].width;
  244. }
  245. meta.minimumWidth += hiddenWidth;
  246. meta.tooNarrow = meta.minimumWidth > targetSize.width;
  247. return calcs;
  248. };
  249. },
  250. handleOverflow: function(calculations, targetSize) {
  251. this.showTrigger();
  252. var newWidth = targetSize.width - this.afterCt.getWidth(),
  253. boxes = calculations.boxes,
  254. usedWidth = 0,
  255. recalculate = false;
  256. //calculate the width of all visible items and any spare width
  257. for (var index = 0, length = boxes.length; index < length; index++) {
  258. usedWidth += boxes[index].width;
  259. }
  260. var spareWidth = newWidth - usedWidth,
  261. showCount = 0;
  262. //see if we can re-show any of the hidden components
  263. for (var index = 0, length = this.menuItems.length; index < length; index++) {
  264. var hidden = this.menuItems[index],
  265. comp = hidden.component,
  266. width = hidden.width;
  267. if (width < spareWidth) {
  268. comp.show();
  269. spareWidth -= width;
  270. showCount ++;
  271. recalculate = true;
  272. } else {
  273. break;
  274. }
  275. }
  276. if (recalculate) {
  277. this.menuItems = this.menuItems.slice(showCount);
  278. } else {
  279. for (var i = boxes.length - 1; i >= 0; i--) {
  280. var item = boxes[i].component,
  281. right = boxes[i].left + boxes[i].width;
  282. if (right >= newWidth) {
  283. this.menuItems.unshift({
  284. component: item,
  285. width : boxes[i].width
  286. });
  287. item.hide();
  288. } else {
  289. break;
  290. }
  291. }
  292. }
  293. if (this.menuItems.length == 0) {
  294. this.hideTrigger();
  295. }
  296. return {
  297. targetSize: {
  298. height: targetSize.height,
  299. width : newWidth
  300. },
  301. recalculate: recalculate
  302. };
  303. }
  304. });
  305. Ext.layout.boxOverflow.menu.hbox = Ext.layout.boxOverflow.HorizontalMenu;</pre>
  306. </body>
  307. </html>