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.

449 lines
15 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. <div id="cls-Ext.layout.ToolbarLayout"></div>/**
  16. * @class Ext.layout.ToolbarLayout
  17. * @extends Ext.layout.ContainerLayout
  18. * Layout manager used by Ext.Toolbar. This is highly specialised for use by Toolbars and would not
  19. * usually be used by any other class.
  20. */
  21. Ext.layout.ToolbarLayout = Ext.extend(Ext.layout.ContainerLayout, {
  22. monitorResize : true,
  23. type: 'toolbar',
  24. <div id="prop-Ext.layout.ToolbarLayout-triggerWidth"></div>/**
  25. * @property triggerWidth
  26. * @type Number
  27. * The width allocated for the menu trigger at the extreme right end of the Toolbar
  28. */
  29. triggerWidth: 18,
  30. <div id="prop-Ext.layout.ToolbarLayout-noItemsMenuText"></div>/**
  31. * @property noItemsMenuText
  32. * @type String
  33. * HTML fragment to render into the toolbar overflow menu if there are no items to display
  34. */
  35. noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
  36. /**
  37. * @private
  38. * @property lastOverflow
  39. * @type Boolean
  40. * Used internally to record whether the last layout caused an overflow or not
  41. */
  42. lastOverflow: false,
  43. /**
  44. * @private
  45. * @property tableHTML
  46. * @type String
  47. * String used to build the HTML injected to support the Toolbar's layout. The align property is
  48. * injected into this string inside the td.x-toolbar-left element during onLayout.
  49. */
  50. tableHTML: [
  51. '<table cellspacing="0" class="x-toolbar-ct">',
  52. '<tbody>',
  53. '<tr>',
  54. '<td class="x-toolbar-left" align="{0}">',
  55. '<table cellspacing="0">',
  56. '<tbody>',
  57. '<tr class="x-toolbar-left-row"></tr>',
  58. '</tbody>',
  59. '</table>',
  60. '</td>',
  61. '<td class="x-toolbar-right" align="right">',
  62. '<table cellspacing="0" class="x-toolbar-right-ct">',
  63. '<tbody>',
  64. '<tr>',
  65. '<td>',
  66. '<table cellspacing="0">',
  67. '<tbody>',
  68. '<tr class="x-toolbar-right-row"></tr>',
  69. '</tbody>',
  70. '</table>',
  71. '</td>',
  72. '<td>',
  73. '<table cellspacing="0">',
  74. '<tbody>',
  75. '<tr class="x-toolbar-extras-row"></tr>',
  76. '</tbody>',
  77. '</table>',
  78. '</td>',
  79. '</tr>',
  80. '</tbody>',
  81. '</table>',
  82. '</td>',
  83. '</tr>',
  84. '</tbody>',
  85. '</table>'
  86. ].join(""),
  87. /**
  88. * @private
  89. * Create the wrapping Toolbar HTML and render/move all the items into the correct places
  90. */
  91. onLayout : function(ct, target) {
  92. //render the Toolbar <table> HTML if it's not already present
  93. if (!this.leftTr) {
  94. var align = ct.buttonAlign == 'center' ? 'center' : 'left';
  95. target.addClass('x-toolbar-layout-ct');
  96. target.insertHtml('beforeEnd', String.format(this.tableHTML, align));
  97. this.leftTr = target.child('tr.x-toolbar-left-row', true);
  98. this.rightTr = target.child('tr.x-toolbar-right-row', true);
  99. this.extrasTr = target.child('tr.x-toolbar-extras-row', true);
  100. if (this.hiddenItem == undefined) {
  101. <div id="prop-Ext.layout.ToolbarLayout-hiddenItems"></div>/**
  102. * @property hiddenItems
  103. * @type Array
  104. * Holds all items that are currently hidden due to there not being enough space to render them
  105. * These items will appear on the expand menu.
  106. */
  107. this.hiddenItems = [];
  108. }
  109. }
  110. var side = ct.buttonAlign == 'right' ? this.rightTr : this.leftTr,
  111. items = ct.items.items,
  112. position = 0;
  113. //render each item if not already rendered, place it into the correct (left or right) target
  114. for (var i = 0, len = items.length, c; i < len; i++, position++) {
  115. c = items[i];
  116. if (c.isFill) {
  117. side = this.rightTr;
  118. position = -1;
  119. } else if (!c.rendered) {
  120. c.render(this.insertCell(c, side, position));
  121. this.configureItem(c);
  122. } else {
  123. if (!c.xtbHidden && !this.isValidParent(c, side.childNodes[position])) {
  124. var td = this.insertCell(c, side, position);
  125. td.appendChild(c.getPositionEl().dom);
  126. c.container = Ext.get(td);
  127. }
  128. }
  129. }
  130. //strip extra empty cells
  131. this.cleanup(this.leftTr);
  132. this.cleanup(this.rightTr);
  133. this.cleanup(this.extrasTr);
  134. this.fitToSize(target);
  135. },
  136. /**
  137. * @private
  138. * Removes any empty nodes from the given element
  139. * @param {Ext.Element} el The element to clean up
  140. */
  141. cleanup : function(el) {
  142. var cn = el.childNodes, i, c;
  143. for (i = cn.length-1; i >= 0 && (c = cn[i]); i--) {
  144. if (!c.firstChild) {
  145. el.removeChild(c);
  146. }
  147. }
  148. },
  149. /**
  150. * @private
  151. * Inserts the given Toolbar item into the given element
  152. * @param {Ext.Component} c The component to add
  153. * @param {Ext.Element} target The target to add the component to
  154. * @param {Number} position The position to add the component at
  155. */
  156. insertCell : function(c, target, position) {
  157. var td = document.createElement('td');
  158. td.className = 'x-toolbar-cell';
  159. target.insertBefore(td, target.childNodes[position] || null);
  160. return td;
  161. },
  162. /**
  163. * @private
  164. * Hides an item because it will not fit in the available width. The item will be unhidden again
  165. * if the Toolbar is resized to be large enough to show it
  166. * @param {Ext.Component} item The item to hide
  167. */
  168. hideItem : function(item) {
  169. this.hiddenItems.push(item);
  170. item.xtbHidden = true;
  171. item.xtbWidth = item.getPositionEl().dom.parentNode.offsetWidth;
  172. item.hide();
  173. },
  174. /**
  175. * @private
  176. * Unhides an item that was previously hidden due to there not being enough space left on the Toolbar
  177. * @param {Ext.Component} item The item to show
  178. */
  179. unhideItem : function(item) {
  180. item.show();
  181. item.xtbHidden = false;
  182. this.hiddenItems.remove(item);
  183. },
  184. /**
  185. * @private
  186. * Returns the width of the given toolbar item. If the item is currently hidden because there
  187. * is not enough room to render it, its previous width is returned
  188. * @param {Ext.Component} c The component to measure
  189. * @return {Number} The width of the item
  190. */
  191. getItemWidth : function(c) {
  192. return c.hidden ? (c.xtbWidth || 0) : c.getPositionEl().dom.parentNode.offsetWidth;
  193. },
  194. /**
  195. * @private
  196. * Called at the end of onLayout. At this point the Toolbar has already been resized, so we need
  197. * to fit the items into the available width. We add up the width required by all of the items in
  198. * the toolbar - if we don't have enough space we hide the extra items and render the expand menu
  199. * trigger.
  200. * @param {Ext.Element} target The Element the Toolbar is currently laid out within
  201. */
  202. fitToSize : function(target) {
  203. if (this.container.enableOverflow === false) {
  204. return;
  205. }
  206. var width = target.dom.clientWidth,
  207. tableWidth = target.dom.firstChild.offsetWidth,
  208. clipWidth = width - this.triggerWidth,
  209. lastWidth = this.lastWidth || 0,
  210. hiddenItems = this.hiddenItems,
  211. hasHiddens = hiddenItems.length != 0,
  212. isLarger = width >= lastWidth;
  213. this.lastWidth = width;
  214. if (tableWidth > width || (hasHiddens && isLarger)) {
  215. var items = this.container.items.items,
  216. len = items.length,
  217. loopWidth = 0,
  218. item;
  219. for (var i = 0; i < len; i++) {
  220. item = items[i];
  221. if (!item.isFill) {
  222. loopWidth += this.getItemWidth(item);
  223. if (loopWidth > clipWidth) {
  224. if (!(item.hidden || item.xtbHidden)) {
  225. this.hideItem(item);
  226. }
  227. } else if (item.xtbHidden) {
  228. this.unhideItem(item);
  229. }
  230. }
  231. }
  232. }
  233. //test for number of hidden items again here because they may have changed above
  234. hasHiddens = hiddenItems.length != 0;
  235. if (hasHiddens) {
  236. this.initMore();
  237. if (!this.lastOverflow) {
  238. this.container.fireEvent('overflowchange', this.container, true);
  239. this.lastOverflow = true;
  240. }
  241. } else if (this.more) {
  242. this.clearMenu();
  243. this.more.destroy();
  244. delete this.more;
  245. if (this.lastOverflow) {
  246. this.container.fireEvent('overflowchange', this.container, false);
  247. this.lastOverflow = false;
  248. }
  249. }
  250. },
  251. /**
  252. * @private
  253. * Returns a menu config for a given component. This config is used to create a menu item
  254. * to be added to the expander menu
  255. * @param {Ext.Component} component The component to create the config for
  256. * @param {Boolean} hideOnClick Passed through to the menu item
  257. */
  258. createMenuConfig : function(component, hideOnClick){
  259. var config = Ext.apply({}, component.initialConfig),
  260. group = component.toggleGroup;
  261. Ext.copyTo(config, component, [
  262. 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
  263. ]);
  264. Ext.apply(config, {
  265. text : component.overflowText || component.text,
  266. hideOnClick: hideOnClick
  267. });
  268. if (group || component.enableToggle) {
  269. Ext.apply(config, {
  270. group : group,
  271. checked: component.pressed,
  272. listeners: {
  273. checkchange: function(item, checked){
  274. component.toggle(checked);
  275. }
  276. }
  277. });
  278. }
  279. delete config.ownerCt;
  280. delete config.xtype;
  281. delete config.id;
  282. return config;
  283. },
  284. /**
  285. * @private
  286. * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
  287. * @param {Ext.menu.Menu} menu The menu to add to
  288. * @param {Ext.Component} component The component to add
  289. */
  290. addComponentToMenu : function(menu, component) {
  291. if (component instanceof Ext.Toolbar.Separator) {
  292. menu.add('-');
  293. } else if (Ext.isFunction(component.isXType)) {
  294. if (component.isXType('splitbutton')) {
  295. menu.add(this.createMenuConfig(component, true));
  296. } else if (component.isXType('button')) {
  297. menu.add(this.createMenuConfig(component, !component.menu));
  298. } else if (component.isXType('buttongroup')) {
  299. component.items.each(function(item){
  300. this.addComponentToMenu(menu, item);
  301. }, this);
  302. }
  303. }
  304. },
  305. /**
  306. * @private
  307. * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
  308. * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
  309. */
  310. clearMenu : function(){
  311. var menu = this.moreMenu;
  312. if (menu && menu.items) {
  313. menu.items.each(function(item){
  314. delete item.menu;
  315. });
  316. }
  317. },
  318. /**
  319. * @private
  320. * Called before the expand menu is shown, this rebuilds the menu since it was last shown because
  321. * it is possible that the items hidden due to space limitations on the Toolbar have changed since.
  322. * @param {Ext.menu.Menu} m The menu
  323. */
  324. beforeMoreShow : function(menu) {
  325. var items = this.container.items.items,
  326. len = items.length,
  327. item,
  328. prev;
  329. var needsSep = function(group, item){
  330. return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
  331. };
  332. this.clearMenu();
  333. menu.removeAll();
  334. for (var i = 0; i < len; i++) {
  335. item = items[i];
  336. if (item.xtbHidden) {
  337. if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
  338. menu.add('-');
  339. }
  340. this.addComponentToMenu(menu, item);
  341. prev = item;
  342. }
  343. }
  344. // put something so the menu isn't empty if no compatible items found
  345. if (menu.items.length < 1) {
  346. menu.add(this.noItemsMenuText);
  347. }
  348. },
  349. /**
  350. * @private
  351. * Creates the expand trigger and menu, adding them to the <tr> at the extreme right of the
  352. * Toolbar table
  353. */
  354. initMore : function(){
  355. if (!this.more) {
  356. /**
  357. * @private
  358. * @property moreMenu
  359. * @type Ext.menu.Menu
  360. * The expand menu - holds items for every Toolbar item that cannot be shown
  361. * because the Toolbar is currently not wide enough.
  362. */
  363. this.moreMenu = new Ext.menu.Menu({
  364. ownerCt : this.container,
  365. listeners: {
  366. beforeshow: this.beforeMoreShow,
  367. scope: this
  368. }
  369. });
  370. /**
  371. * @private
  372. * @property more
  373. * @type Ext.Button
  374. * The expand button which triggers the overflow menu to be shown
  375. */
  376. this.more = new Ext.Button({
  377. iconCls: 'x-toolbar-more-icon',
  378. cls : 'x-toolbar-more',
  379. menu : this.moreMenu,
  380. ownerCt: this.container
  381. });
  382. var td = this.insertCell(this.more, this.extrasTr, 100);
  383. this.more.render(td);
  384. }
  385. },
  386. destroy : function(){
  387. Ext.destroy(this.more, this.moreMenu);
  388. delete this.leftTr;
  389. delete this.rightTr;
  390. delete this.extrasTr;
  391. Ext.layout.ToolbarLayout.superclass.destroy.call(this);
  392. }
  393. });
  394. Ext.Container.LAYOUTS.toolbar = Ext.layout.ToolbarLayout;
  395. </pre>
  396. </body>
  397. </html>