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.

1043 lines
38 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.Window"></div>/**
  16. * @class Ext.Window
  17. * @extends Ext.Panel
  18. * <p>A specialized panel intended for use as an application window. Windows are floated, {@link #resizable}, and
  19. * {@link #draggable} by default. Windows can be {@link #maximizable maximized} to fill the viewport,
  20. * restored to their prior size, and can be {@link #minimize}d.</p>
  21. * <p>Windows can also be linked to a {@link Ext.WindowGroup} or managed by the {@link Ext.WindowMgr} to provide
  22. * grouping, activation, to front, to back and other application-specific behavior.</p>
  23. * <p>By default, Windows will be rendered to document.body. To {@link #constrain} a Window to another element
  24. * specify {@link Ext.Component#renderTo renderTo}.</p>
  25. * <p><b>Note:</b> By default, the <code>{@link #closable close}</code> header tool <i>destroys</i> the Window resulting in
  26. * destruction of any child Components. This makes the Window object, and all its descendants <b>unusable</b>. To enable
  27. * re-use of a Window, use <b><code>{@link #closeAction closeAction: 'hide'}</code></b>.</p>
  28. * @constructor
  29. * @param {Object} config The config object
  30. * @xtype window
  31. */
  32. Ext.Window = Ext.extend(Ext.Panel, {
  33. <div id="cfg-Ext.Window-x"></div>/**
  34. * @cfg {Number} x
  35. * The X position of the left edge of the window on initial showing. Defaults to centering the Window within
  36. * the width of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
  37. */
  38. <div id="cfg-Ext.Window-y"></div>/**
  39. * @cfg {Number} y
  40. * The Y position of the top edge of the window on initial showing. Defaults to centering the Window within
  41. * the height of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
  42. */
  43. <div id="cfg-Ext.Window-modal"></div>/**
  44. * @cfg {Boolean} modal
  45. * True to make the window modal and mask everything behind it when displayed, false to display it without
  46. * restricting access to other UI elements (defaults to false).
  47. */
  48. <div id="cfg-Ext.Window-animateTarget"></div>/**
  49. * @cfg {String/Element} animateTarget
  50. * Id or element from which the window should animate while opening (defaults to null with no animation).
  51. */
  52. <div id="cfg-Ext.Window-resizeHandles"></div>/**
  53. * @cfg {String} resizeHandles
  54. * A valid {@link Ext.Resizable} handles config string (defaults to 'all'). Only applies when resizable = true.
  55. */
  56. <div id="cfg-Ext.Window-manager"></div>/**
  57. * @cfg {Ext.WindowGroup} manager
  58. * A reference to the WindowGroup that should manage this window (defaults to {@link Ext.WindowMgr}).
  59. */
  60. <div id="cfg-Ext.Window-defaultButton"></div>/**
  61. * @cfg {String/Number/Component} defaultButton
  62. * <p>Specifies a Component to receive focus when this Window is focussed.</p>
  63. * <p>This may be one of:</p><div class="mdetail-params"><ul>
  64. * <li>The index of a footer Button.</li>
  65. * <li>The id of a Component.</li>
  66. * <li>A Component.</li>
  67. * </ul></div>
  68. */
  69. <div id="cfg-Ext.Window-onEsc"></div>/**
  70. * @cfg {Function} onEsc
  71. * Allows override of the built-in processing for the escape key. Default action
  72. * is to close the Window (performing whatever action is specified in {@link #closeAction}.
  73. * To prevent the Window closing when the escape key is pressed, specify this as
  74. * Ext.emptyFn (See {@link Ext#emptyFn}).
  75. */
  76. <div id="cfg-Ext.Window-collapsed"></div>/**
  77. * @cfg {Boolean} collapsed
  78. * True to render the window collapsed, false to render it expanded (defaults to false). Note that if
  79. * {@link #expandOnShow} is true (the default) it will override the <tt>collapsed</tt> config and the window
  80. * will always be expanded when shown.
  81. */
  82. <div id="cfg-Ext.Window-maximized"></div>/**
  83. * @cfg {Boolean} maximized
  84. * True to initially display the window in a maximized state. (Defaults to false).
  85. */
  86. <div id="cfg-Ext.Window-baseCls"></div>/**
  87. * @cfg {String} baseCls
  88. * The base CSS class to apply to this panel's element (defaults to 'x-window').
  89. */
  90. baseCls : 'x-window',
  91. <div id="cfg-Ext.Window-resizable"></div>/**
  92. * @cfg {Boolean} resizable
  93. * True to allow user resizing at each edge and corner of the window, false to disable resizing (defaults to true).
  94. */
  95. resizable : true,
  96. <div id="cfg-Ext.Window-draggable"></div>/**
  97. * @cfg {Boolean} draggable
  98. * True to allow the window to be dragged by the header bar, false to disable dragging (defaults to true). Note
  99. * that by default the window will be centered in the viewport, so if dragging is disabled the window may need
  100. * to be positioned programmatically after render (e.g., myWindow.setPosition(100, 100);).
  101. */
  102. draggable : true,
  103. <div id="cfg-Ext.Window-closable"></div>/**
  104. * @cfg {Boolean} closable
  105. * <p>True to display the 'close' tool button and allow the user to close the window, false to
  106. * hide the button and disallow closing the window (defaults to true).</p>
  107. * <p>By default, when close is requested by either clicking the close button in the header
  108. * or pressing ESC when the Window has focus, the {@link #close} method will be called. This
  109. * will <i>{@link Ext.Component#destroy destroy}</i> the Window and its content meaning that
  110. * it may not be reused.</p>
  111. * <p>To make closing a Window <i>hide</i> the Window so that it may be reused, set
  112. * {@link #closeAction} to 'hide'.
  113. */
  114. closable : true,
  115. <div id="cfg-Ext.Window-closeAction"></div>/**
  116. * @cfg {String} closeAction
  117. * <p>The action to take when the close header tool is clicked:
  118. * <div class="mdetail-params"><ul>
  119. * <li><b><code>'{@link #close}'</code></b> : <b>Default</b><div class="sub-desc">
  120. * {@link #close remove} the window from the DOM and {@link Ext.Component#destroy destroy}
  121. * it and all descendant Components. The window will <b>not</b> be available to be
  122. * redisplayed via the {@link #show} method.
  123. * </div></li>
  124. * <li><b><code>'{@link #hide}'</code></b> : <div class="sub-desc">
  125. * {@link #hide} the window by setting visibility to hidden and applying negative offsets.
  126. * The window will be available to be redisplayed via the {@link #show} method.
  127. * </div></li>
  128. * </ul></div>
  129. * <p><b>Note:</b> This setting does not affect the {@link #close} method
  130. * which will always {@link Ext.Component#destroy destroy} the window. To
  131. * programatically <i>hide</i> a window, call {@link #hide}.</p>
  132. */
  133. closeAction : 'close',
  134. <div id="cfg-Ext.Window-constrain"></div>/**
  135. * @cfg {Boolean} constrain
  136. * True to constrain the window within its containing element, false to allow it to fall outside of its
  137. * containing element. By default the window will be rendered to document.body. To render and constrain the
  138. * window within another element specify {@link #renderTo}.
  139. * (defaults to false). Optionally the header only can be constrained using {@link #constrainHeader}.
  140. */
  141. constrain : false,
  142. <div id="cfg-Ext.Window-constrainHeader"></div>/**
  143. * @cfg {Boolean} constrainHeader
  144. * True to constrain the window header within its containing element (allowing the window body to fall outside
  145. * of its containing element) or false to allow the header to fall outside its containing element (defaults to
  146. * false). Optionally the entire window can be constrained using {@link #constrain}.
  147. */
  148. constrainHeader : false,
  149. <div id="cfg-Ext.Window-plain"></div>/**
  150. * @cfg {Boolean} plain
  151. * True to render the window body with a transparent background so that it will blend into the framing
  152. * elements, false to add a lighter background color to visually highlight the body element and separate it
  153. * more distinctly from the surrounding frame (defaults to false).
  154. */
  155. plain : false,
  156. <div id="cfg-Ext.Window-minimizable"></div>/**
  157. * @cfg {Boolean} minimizable
  158. * True to display the 'minimize' tool button and allow the user to minimize the window, false to hide the button
  159. * and disallow minimizing the window (defaults to false). Note that this button provides no implementation --
  160. * the behavior of minimizing a window is implementation-specific, so the minimize event must be handled and a
  161. * custom minimize behavior implemented for this option to be useful.
  162. */
  163. minimizable : false,
  164. <div id="cfg-Ext.Window-maximizable"></div>/**
  165. * @cfg {Boolean} maximizable
  166. * True to display the 'maximize' tool button and allow the user to maximize the window, false to hide the button
  167. * and disallow maximizing the window (defaults to false). Note that when a window is maximized, the tool button
  168. * will automatically change to a 'restore' button with the appropriate behavior already built-in that will
  169. * restore the window to its previous size.
  170. */
  171. maximizable : false,
  172. <div id="cfg-Ext.Window-minHeight"></div>/**
  173. * @cfg {Number} minHeight
  174. * The minimum height in pixels allowed for this window (defaults to 100). Only applies when resizable = true.
  175. */
  176. minHeight : 100,
  177. <div id="cfg-Ext.Window-minWidth"></div>/**
  178. * @cfg {Number} minWidth
  179. * The minimum width in pixels allowed for this window (defaults to 200). Only applies when resizable = true.
  180. */
  181. minWidth : 200,
  182. <div id="cfg-Ext.Window-expandOnShow"></div>/**
  183. * @cfg {Boolean} expandOnShow
  184. * True to always expand the window when it is displayed, false to keep it in its current state (which may be
  185. * {@link #collapsed}) when displayed (defaults to true).
  186. */
  187. expandOnShow : true,
  188. <div id="cfg-Ext.Window-showAnimDuration"></div>/**
  189. * @cfg {Number} showAnimDuration The number of seconds that the window show animation takes if enabled.
  190. * Defaults to 0.25
  191. */
  192. showAnimDuration: 0.25,
  193. <div id="cfg-Ext.Window-hideAnimDuration"></div>/**
  194. * @cfg {Number} hideAnimDuration The number of seconds that the window hide animation takes if enabled.
  195. * Defaults to 0.25
  196. */
  197. hideAnimDuration: 0.25,
  198. // inherited docs, same default
  199. collapsible : false,
  200. <div id="cfg-Ext.Window-initHidden"></div>/**
  201. * @cfg {Boolean} initHidden
  202. * True to hide the window until show() is explicitly called (defaults to true).
  203. * @deprecated
  204. */
  205. initHidden : undefined,
  206. <div id="cfg-Ext.Window-hidden"></div>/**
  207. * @cfg {Boolean} hidden
  208. * Render this component hidden (default is <tt>true</tt>). If <tt>true</tt>, the
  209. * {@link #hide} method will be called internally.
  210. */
  211. hidden : true,
  212. // The following configs are set to provide the basic functionality of a window.
  213. // Changing them would require additional code to handle correctly and should
  214. // usually only be done in subclasses that can provide custom behavior. Changing them
  215. // may have unexpected or undesirable results.
  216. <div id="cfg-Ext.Window-elements"></div>/** @cfg {String} elements @hide */
  217. elements : 'header,body',
  218. <div id="cfg-Ext.Window-frame"></div>/** @cfg {Boolean} frame @hide */
  219. frame : true,
  220. <div id="cfg-Ext.Window-floating"></div>/** @cfg {Boolean} floating @hide */
  221. floating : true,
  222. // private
  223. initComponent : function(){
  224. this.initTools();
  225. Ext.Window.superclass.initComponent.call(this);
  226. this.addEvents(
  227. <div id="event-Ext.Window-activate"></div>/**
  228. * @event activate
  229. * Fires after the window has been visually activated via {@link #setActive}.
  230. * @param {Ext.Window} this
  231. */
  232. <div id="event-Ext.Window-deactivate"></div>/**
  233. * @event deactivate
  234. * Fires after the window has been visually deactivated via {@link #setActive}.
  235. * @param {Ext.Window} this
  236. */
  237. <div id="event-Ext.Window-resize"></div>/**
  238. * @event resize
  239. * Fires after the window has been resized.
  240. * @param {Ext.Window} this
  241. * @param {Number} width The window's new width
  242. * @param {Number} height The window's new height
  243. */
  244. 'resize',
  245. <div id="event-Ext.Window-maximize"></div>/**
  246. * @event maximize
  247. * Fires after the window has been maximized.
  248. * @param {Ext.Window} this
  249. */
  250. 'maximize',
  251. <div id="event-Ext.Window-minimize"></div>/**
  252. * @event minimize
  253. * Fires after the window has been minimized.
  254. * @param {Ext.Window} this
  255. */
  256. 'minimize',
  257. <div id="event-Ext.Window-restore"></div>/**
  258. * @event restore
  259. * Fires after the window has been restored to its original size after being maximized.
  260. * @param {Ext.Window} this
  261. */
  262. 'restore'
  263. );
  264. // for backwards compat, this should be removed at some point
  265. if(Ext.isDefined(this.initHidden)){
  266. this.hidden = this.initHidden;
  267. }
  268. if(this.hidden === false){
  269. this.hidden = true;
  270. this.show();
  271. }
  272. },
  273. // private
  274. getState : function(){
  275. return Ext.apply(Ext.Window.superclass.getState.call(this) || {}, this.getBox(true));
  276. },
  277. // private
  278. onRender : function(ct, position){
  279. Ext.Window.superclass.onRender.call(this, ct, position);
  280. if(this.plain){
  281. this.el.addClass('x-window-plain');
  282. }
  283. // this element allows the Window to be focused for keyboard events
  284. this.focusEl = this.el.createChild({
  285. tag: 'a', href:'#', cls:'x-dlg-focus',
  286. tabIndex:'-1', html: '&#160;'});
  287. this.focusEl.swallowEvent('click', true);
  288. this.proxy = this.el.createProxy('x-window-proxy');
  289. this.proxy.enableDisplayMode('block');
  290. if(this.modal){
  291. this.mask = this.container.createChild({cls:'ext-el-mask'}, this.el.dom);
  292. this.mask.enableDisplayMode('block');
  293. this.mask.hide();
  294. this.mon(this.mask, 'click', this.focus, this);
  295. }
  296. if(this.maximizable){
  297. this.mon(this.header, 'dblclick', this.toggleMaximize, this);
  298. }
  299. },
  300. // private
  301. initEvents : function(){
  302. Ext.Window.superclass.initEvents.call(this);
  303. if(this.animateTarget){
  304. this.setAnimateTarget(this.animateTarget);
  305. }
  306. if(this.resizable){
  307. this.resizer = new Ext.Resizable(this.el, {
  308. minWidth: this.minWidth,
  309. minHeight:this.minHeight,
  310. handles: this.resizeHandles || 'all',
  311. pinned: true,
  312. resizeElement : this.resizerAction,
  313. handleCls: 'x-window-handle'
  314. });
  315. this.resizer.window = this;
  316. this.mon(this.resizer, 'beforeresize', this.beforeResize, this);
  317. }
  318. if(this.draggable){
  319. this.header.addClass('x-window-draggable');
  320. }
  321. this.mon(this.el, 'mousedown', this.toFront, this);
  322. this.manager = this.manager || Ext.WindowMgr;
  323. this.manager.register(this);
  324. if(this.maximized){
  325. this.maximized = false;
  326. this.maximize();
  327. }
  328. if(this.closable){
  329. var km = this.getKeyMap();
  330. km.on(27, this.onEsc, this);
  331. km.disable();
  332. }
  333. },
  334. initDraggable : function(){
  335. <div id="prop-Ext.Window-dd"></div>/**
  336. * <p>If this Window is configured {@link #draggable}, this property will contain
  337. * an instance of {@link Ext.dd.DD} which handles dragging the Window's DOM Element.</p>
  338. * <p>This has implementations of <code>startDrag</code>, <code>onDrag</code> and <code>endDrag</code>
  339. * which perform the dragging action. If extra logic is needed at these points, use
  340. * {@link Function#createInterceptor createInterceptor} or {@link Function#createSequence createSequence} to
  341. * augment the existing implementations.</p>
  342. * @type Ext.dd.DD
  343. * @property dd
  344. */
  345. this.dd = new Ext.Window.DD(this);
  346. },
  347. // private
  348. onEsc : function(k, e){
  349. e.stopEvent();
  350. this[this.closeAction]();
  351. },
  352. // private
  353. beforeDestroy : function(){
  354. if(this.rendered){
  355. this.hide();
  356. this.clearAnchor();
  357. Ext.destroy(
  358. this.focusEl,
  359. this.resizer,
  360. this.dd,
  361. this.proxy,
  362. this.mask
  363. );
  364. }
  365. Ext.Window.superclass.beforeDestroy.call(this);
  366. },
  367. // private
  368. onDestroy : function(){
  369. if(this.manager){
  370. this.manager.unregister(this);
  371. }
  372. Ext.Window.superclass.onDestroy.call(this);
  373. },
  374. // private
  375. initTools : function(){
  376. if(this.minimizable){
  377. this.addTool({
  378. id: 'minimize',
  379. handler: this.minimize.createDelegate(this, [])
  380. });
  381. }
  382. if(this.maximizable){
  383. this.addTool({
  384. id: 'maximize',
  385. handler: this.maximize.createDelegate(this, [])
  386. });
  387. this.addTool({
  388. id: 'restore',
  389. handler: this.restore.createDelegate(this, []),
  390. hidden:true
  391. });
  392. }
  393. if(this.closable){
  394. this.addTool({
  395. id: 'close',
  396. handler: this[this.closeAction].createDelegate(this, [])
  397. });
  398. }
  399. },
  400. // private
  401. resizerAction : function(){
  402. var box = this.proxy.getBox();
  403. this.proxy.hide();
  404. this.window.handleResize(box);
  405. return box;
  406. },
  407. // private
  408. beforeResize : function(){
  409. this.resizer.minHeight = Math.max(this.minHeight, this.getFrameHeight() + 40); // 40 is a magic minimum content size?
  410. this.resizer.minWidth = Math.max(this.minWidth, this.getFrameWidth() + 40);
  411. this.resizeBox = this.el.getBox();
  412. },
  413. // private
  414. updateHandles : function(){
  415. if(Ext.isIE && this.resizer){
  416. this.resizer.syncHandleHeight();
  417. this.el.repaint();
  418. }
  419. },
  420. // private
  421. handleResize : function(box){
  422. var rz = this.resizeBox;
  423. if(rz.x != box.x || rz.y != box.y){
  424. this.updateBox(box);
  425. }else{
  426. this.setSize(box);
  427. if (Ext.isIE6 && Ext.isStrict) {
  428. this.doLayout();
  429. }
  430. }
  431. this.focus();
  432. this.updateHandles();
  433. this.saveState();
  434. },
  435. <div id="method-Ext.Window-focus"></div>/**
  436. * Focuses the window. If a defaultButton is set, it will receive focus, otherwise the
  437. * window itself will receive focus.
  438. */
  439. focus : function(){
  440. var f = this.focusEl,
  441. db = this.defaultButton,
  442. t = typeof db,
  443. el,
  444. ct;
  445. if(Ext.isDefined(db)){
  446. if(Ext.isNumber(db) && this.fbar){
  447. f = this.fbar.items.get(db);
  448. }else if(Ext.isString(db)){
  449. f = Ext.getCmp(db);
  450. }else{
  451. f = db;
  452. }
  453. el = f.getEl();
  454. ct = Ext.getDom(this.container);
  455. if (el && ct) {
  456. if (ct != document.body && !Ext.lib.Region.getRegion(ct).contains(Ext.lib.Region.getRegion(el.dom))){
  457. return;
  458. }
  459. }
  460. }
  461. f = f || this.focusEl;
  462. f.focus.defer(10, f);
  463. },
  464. <div id="method-Ext.Window-setAnimateTarget"></div>/**
  465. * Sets the target element from which the window should animate while opening.
  466. * @param {String/Element} el The target element or id
  467. */
  468. setAnimateTarget : function(el){
  469. el = Ext.get(el);
  470. this.animateTarget = el;
  471. },
  472. // private
  473. beforeShow : function(){
  474. delete this.el.lastXY;
  475. delete this.el.lastLT;
  476. if(this.x === undefined || this.y === undefined){
  477. var xy = this.el.getAlignToXY(this.container, 'c-c');
  478. var pos = this.el.translatePoints(xy[0], xy[1]);
  479. this.x = this.x === undefined? pos.left : this.x;
  480. this.y = this.y === undefined? pos.top : this.y;
  481. }
  482. this.el.setLeftTop(this.x, this.y);
  483. if(this.expandOnShow){
  484. this.expand(false);
  485. }
  486. if(this.modal){
  487. Ext.getBody().addClass('x-body-masked');
  488. this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
  489. this.mask.show();
  490. }
  491. },
  492. <div id="method-Ext.Window-show"></div>/**
  493. * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
  494. * @param {String/Element} animateTarget (optional) The target element or id from which the window should
  495. * animate while opening (defaults to null with no animation)
  496. * @param {Function} callback (optional) A callback function to call after the window is displayed
  497. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
  498. * @return {Ext.Window} this
  499. */
  500. show : function(animateTarget, cb, scope){
  501. if(!this.rendered){
  502. this.render(Ext.getBody());
  503. }
  504. if(this.hidden === false){
  505. this.toFront();
  506. return this;
  507. }
  508. if(this.fireEvent('beforeshow', this) === false){
  509. return this;
  510. }
  511. if(cb){
  512. this.on('show', cb, scope, {single:true});
  513. }
  514. this.hidden = false;
  515. if(Ext.isDefined(animateTarget)){
  516. this.setAnimateTarget(animateTarget);
  517. }
  518. this.beforeShow();
  519. if(this.animateTarget){
  520. this.animShow();
  521. }else{
  522. this.afterShow();
  523. }
  524. return this;
  525. },
  526. // private
  527. afterShow : function(isAnim){
  528. if (this.isDestroyed){
  529. return false;
  530. }
  531. this.proxy.hide();
  532. this.el.setStyle('display', 'block');
  533. this.el.show();
  534. if(this.maximized){
  535. this.fitContainer();
  536. }
  537. if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
  538. this.cascade(this.setAutoScroll);
  539. }
  540. if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
  541. Ext.EventManager.onWindowResize(this.onWindowResize, this);
  542. }
  543. this.doConstrain();
  544. this.doLayout();
  545. if(this.keyMap){
  546. this.keyMap.enable();
  547. }
  548. this.toFront();
  549. this.updateHandles();
  550. if(isAnim && (Ext.isIE || Ext.isWebKit)){
  551. var sz = this.getSize();
  552. this.onResize(sz.width, sz.height);
  553. }
  554. this.onShow();
  555. this.fireEvent('show', this);
  556. },
  557. // private
  558. animShow : function(){
  559. this.proxy.show();
  560. this.proxy.setBox(this.animateTarget.getBox());
  561. this.proxy.setOpacity(0);
  562. var b = this.getBox();
  563. this.el.setStyle('display', 'none');
  564. this.proxy.shift(Ext.apply(b, {
  565. callback: this.afterShow.createDelegate(this, [true], false),
  566. scope: this,
  567. easing: 'easeNone',
  568. duration: this.showAnimDuration,
  569. opacity: 0.5
  570. }));
  571. },
  572. <div id="method-Ext.Window-hide"></div>/**
  573. * Hides the window, setting it to invisible and applying negative offsets.
  574. * @param {String/Element} animateTarget (optional) The target element or id to which the window should
  575. * animate while hiding (defaults to null with no animation)
  576. * @param {Function} callback (optional) A callback function to call after the window is hidden
  577. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
  578. * @return {Ext.Window} this
  579. */
  580. hide : function(animateTarget, cb, scope){
  581. if(this.hidden || this.fireEvent('beforehide', this) === false){
  582. return this;
  583. }
  584. if(cb){
  585. this.on('hide', cb, scope, {single:true});
  586. }
  587. this.hidden = true;
  588. if(animateTarget !== undefined){
  589. this.setAnimateTarget(animateTarget);
  590. }
  591. if(this.modal){
  592. this.mask.hide();
  593. Ext.getBody().removeClass('x-body-masked');
  594. }
  595. if(this.animateTarget){
  596. this.animHide();
  597. }else{
  598. this.el.hide();
  599. this.afterHide();
  600. }
  601. return this;
  602. },
  603. // private
  604. afterHide : function(){
  605. this.proxy.hide();
  606. if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
  607. Ext.EventManager.removeResizeListener(this.onWindowResize, this);
  608. }
  609. if(this.keyMap){
  610. this.keyMap.disable();
  611. }
  612. this.onHide();
  613. this.fireEvent('hide', this);
  614. },
  615. // private
  616. animHide : function(){
  617. this.proxy.setOpacity(0.5);
  618. this.proxy.show();
  619. var tb = this.getBox(false);
  620. this.proxy.setBox(tb);
  621. this.el.hide();
  622. this.proxy.shift(Ext.apply(this.animateTarget.getBox(), {
  623. callback: this.afterHide,
  624. scope: this,
  625. duration: this.hideAnimDuration,
  626. easing: 'easeNone',
  627. opacity: 0
  628. }));
  629. },
  630. <div id="prop-Ext.Window-onShow"></div>/**
  631. * Method that is called immediately before the <code>show</code> event is fired.
  632. * Defaults to <code>Ext.emptyFn</code>.
  633. */
  634. onShow : Ext.emptyFn,
  635. <div id="prop-Ext.Window-onHide"></div>/**
  636. * Method that is called immediately before the <code>hide</code> event is fired.
  637. * Defaults to <code>Ext.emptyFn</code>.
  638. */
  639. onHide : Ext.emptyFn,
  640. // private
  641. onWindowResize : function(){
  642. if(this.maximized){
  643. this.fitContainer();
  644. }
  645. if(this.modal){
  646. this.mask.setSize('100%', '100%');
  647. var force = this.mask.dom.offsetHeight;
  648. this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
  649. }
  650. this.doConstrain();
  651. },
  652. // private
  653. doConstrain : function(){
  654. if(this.constrain || this.constrainHeader){
  655. var offsets;
  656. if(this.constrain){
  657. offsets = {
  658. right:this.el.shadowOffset,
  659. left:this.el.shadowOffset,
  660. bottom:this.el.shadowOffset
  661. };
  662. }else {
  663. var s = this.getSize();
  664. offsets = {
  665. right:-(s.width - 100),
  666. bottom:-(s.height - 25)
  667. };
  668. }
  669. var xy = this.el.getConstrainToXY(this.container, true, offsets);
  670. if(xy){
  671. this.setPosition(xy[0], xy[1]);
  672. }
  673. }
  674. },
  675. // private - used for dragging
  676. ghost : function(cls){
  677. var ghost = this.createGhost(cls);
  678. var box = this.getBox(true);
  679. ghost.setLeftTop(box.x, box.y);
  680. ghost.setWidth(box.width);
  681. this.el.hide();
  682. this.activeGhost = ghost;
  683. return ghost;
  684. },
  685. // private
  686. unghost : function(show, matchPosition){
  687. if(!this.activeGhost) {
  688. return;
  689. }
  690. if(show !== false){
  691. this.el.show();
  692. this.focus.defer(10, this);
  693. if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
  694. this.cascade(this.setAutoScroll);
  695. }
  696. }
  697. if(matchPosition !== false){
  698. this.setPosition(this.activeGhost.getLeft(true), this.activeGhost.getTop(true));
  699. }
  700. this.activeGhost.hide();
  701. this.activeGhost.remove();
  702. delete this.activeGhost;
  703. },
  704. <div id="method-Ext.Window-minimize"></div>/**
  705. * Placeholder method for minimizing the window. By default, this method simply fires the {@link #minimize} event
  706. * since the behavior of minimizing a window is application-specific. To implement custom minimize behavior,
  707. * either the minimize event can be handled or this method can be overridden.
  708. * @return {Ext.Window} this
  709. */
  710. minimize : function(){
  711. this.fireEvent('minimize', this);
  712. return this;
  713. },
  714. <div id="method-Ext.Window-close"></div>/**
  715. * <p>Closes the Window, removes it from the DOM, {@link Ext.Component#destroy destroy}s
  716. * the Window object and all its descendant Components. The {@link Ext.Panel#beforeclose beforeclose}
  717. * event is fired before the close happens and will cancel the close action if it returns false.<p>
  718. * <p><b>Note:</b> This method is not affected by the {@link #closeAction} setting which
  719. * only affects the action triggered when clicking the {@link #closable 'close' tool in the header}.
  720. * To hide the Window without destroying it, call {@link #hide}.</p>
  721. */
  722. close : function(){
  723. if(this.fireEvent('beforeclose', this) !== false){
  724. if(this.hidden){
  725. this.doClose();
  726. }else{
  727. this.hide(null, this.doClose, this);
  728. }
  729. }
  730. },
  731. // private
  732. doClose : function(){
  733. this.fireEvent('close', this);
  734. this.destroy();
  735. },
  736. <div id="method-Ext.Window-maximize"></div>/**
  737. * Fits the window within its current container and automatically replaces
  738. * the {@link #maximizable 'maximize' tool button} with the 'restore' tool button.
  739. * Also see {@link #toggleMaximize}.
  740. * @return {Ext.Window} this
  741. */
  742. maximize : function(){
  743. if(!this.maximized){
  744. this.expand(false);
  745. this.restoreSize = this.getSize();
  746. this.restorePos = this.getPosition(true);
  747. if (this.maximizable){
  748. this.tools.maximize.hide();
  749. this.tools.restore.show();
  750. }
  751. this.maximized = true;
  752. this.el.disableShadow();
  753. if(this.dd){
  754. this.dd.lock();
  755. }
  756. if(this.collapsible){
  757. this.tools.toggle.hide();
  758. }
  759. this.el.addClass('x-window-maximized');
  760. this.container.addClass('x-window-maximized-ct');
  761. this.setPosition(0, 0);
  762. this.fitContainer();
  763. this.fireEvent('maximize', this);
  764. }
  765. return this;
  766. },
  767. <div id="method-Ext.Window-restore"></div>/**
  768. * Restores a {@link #maximizable maximized} window back to its original
  769. * size and position prior to being maximized and also replaces
  770. * the 'restore' tool button with the 'maximize' tool button.
  771. * Also see {@link #toggleMaximize}.
  772. * @return {Ext.Window} this
  773. */
  774. restore : function(){
  775. if(this.maximized){
  776. var t = this.tools;
  777. this.el.removeClass('x-window-maximized');
  778. if(t.restore){
  779. t.restore.hide();
  780. }
  781. if(t.maximize){
  782. t.maximize.show();
  783. }
  784. this.setPosition(this.restorePos[0], this.restorePos[1]);
  785. this.setSize(this.restoreSize.width, this.restoreSize.height);
  786. delete this.restorePos;
  787. delete this.restoreSize;
  788. this.maximized = false;
  789. this.el.enableShadow(true);
  790. if(this.dd){
  791. this.dd.unlock();
  792. }
  793. if(this.collapsible && t.toggle){
  794. t.toggle.show();
  795. }
  796. this.container.removeClass('x-window-maximized-ct');
  797. this.doConstrain();
  798. this.fireEvent('restore', this);
  799. }
  800. return this;
  801. },
  802. <div id="method-Ext.Window-toggleMaximize"></div>/**
  803. * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized
  804. * state of the window.
  805. * @return {Ext.Window} this
  806. */
  807. toggleMaximize : function(){
  808. return this[this.maximized ? 'restore' : 'maximize']();
  809. },
  810. // private
  811. fitContainer : function(){
  812. var vs = this.container.getViewSize(false);
  813. this.setSize(vs.width, vs.height);
  814. },
  815. // private
  816. // z-index is managed by the WindowManager and may be overwritten at any time
  817. setZIndex : function(index){
  818. if(this.modal){
  819. this.mask.setStyle('z-index', index);
  820. }
  821. this.el.setZIndex(++index);
  822. index += 5;
  823. if(this.resizer){
  824. this.resizer.proxy.setStyle('z-index', ++index);
  825. }
  826. this.lastZIndex = index;
  827. },
  828. <div id="method-Ext.Window-alignTo"></div>/**
  829. * Aligns the window to the specified element
  830. * @param {Mixed} element The element to align to.
  831. * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.Element#alignTo} for more details).
  832. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  833. * @return {Ext.Window} this
  834. */
  835. alignTo : function(element, position, offsets){
  836. var xy = this.el.getAlignToXY(element, position, offsets);
  837. this.setPagePosition(xy[0], xy[1]);
  838. return this;
  839. },
  840. <div id="method-Ext.Window-anchorTo"></div>/**
  841. * Anchors this window to another element and realigns it when the window is resized or scrolled.
  842. * @param {Mixed} element The element to align to.
  843. * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details)
  844. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  845. * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
  846. * is a number, it is used as the buffer delay (defaults to 50ms).
  847. * @return {Ext.Window} this
  848. */
  849. anchorTo : function(el, alignment, offsets, monitorScroll){
  850. this.clearAnchor();
  851. this.anchorTarget = {
  852. el: el,
  853. alignment: alignment,
  854. offsets: offsets
  855. };
  856. Ext.EventManager.onWindowResize(this.doAnchor, this);
  857. var tm = typeof monitorScroll;
  858. if(tm != 'undefined'){
  859. Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
  860. {buffer: tm == 'number' ? monitorScroll : 50});
  861. }
  862. return this.doAnchor();
  863. },
  864. /**
  865. * Performs the anchor, using the saved anchorTarget property.
  866. * @return {Ext.Window} this
  867. * @private
  868. */
  869. doAnchor : function(){
  870. var o = this.anchorTarget;
  871. this.alignTo(o.el, o.alignment, o.offsets);
  872. return this;
  873. },
  874. <div id="method-Ext.Window-clearAnchor"></div>/**
  875. * Removes any existing anchor from this window. See {@link #anchorTo}.
  876. * @return {Ext.Window} this
  877. */
  878. clearAnchor : function(){
  879. if(this.anchorTarget){
  880. Ext.EventManager.removeResizeListener(this.doAnchor, this);
  881. Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
  882. delete this.anchorTarget;
  883. }
  884. return this;
  885. },
  886. <div id="method-Ext.Window-toFront"></div>/**
  887. * Brings this window to the front of any other visible windows
  888. * @param {Boolean} e (optional) Specify <tt>false</tt> to prevent the window from being focused.
  889. * @return {Ext.Window} this
  890. */
  891. toFront : function(e){
  892. if(this.manager.bringToFront(this)){
  893. if(!e || !e.getTarget().focus){
  894. this.focus();
  895. }
  896. }
  897. return this;
  898. },
  899. <div id="method-Ext.Window-setActive"></div>/**
  900. * Makes this the active window by showing its shadow, or deactivates it by hiding its shadow. This method also
  901. * fires the {@link #activate} or {@link #deactivate} event depending on which action occurred. This method is
  902. * called internally by {@link Ext.WindowMgr}.
  903. * @param {Boolean} active True to activate the window, false to deactivate it (defaults to false)
  904. */
  905. setActive : function(active){
  906. if(active){
  907. if(!this.maximized){
  908. this.el.enableShadow(true);
  909. }
  910. this.fireEvent('activate', this);
  911. }else{
  912. this.el.disableShadow();
  913. this.fireEvent('deactivate', this);
  914. }
  915. },
  916. <div id="method-Ext.Window-toBack"></div>/**
  917. * Sends this window to the back of (lower z-index than) any other visible windows
  918. * @return {Ext.Window} this
  919. */
  920. toBack : function(){
  921. this.manager.sendToBack(this);
  922. return this;
  923. },
  924. <div id="method-Ext.Window-center"></div>/**
  925. * Centers this window in the viewport
  926. * @return {Ext.Window} this
  927. */
  928. center : function(){
  929. var xy = this.el.getAlignToXY(this.container, 'c-c');
  930. this.setPagePosition(xy[0], xy[1]);
  931. return this;
  932. }
  933. <div id="cfg-Ext.Window-autoWidth"></div>/**
  934. * @cfg {Boolean} autoWidth @hide
  935. **/
  936. });
  937. Ext.reg('window', Ext.Window);
  938. // private - custom Window DD implementation
  939. Ext.Window.DD = Ext.extend(Ext.dd.DD, {
  940. constructor : function(win){
  941. this.win = win;
  942. Ext.Window.DD.superclass.constructor.call(this, win.el.id, 'WindowDD-'+win.id);
  943. this.setHandleElId(win.header.id);
  944. this.scroll = false;
  945. },
  946. moveOnly:true,
  947. headerOffsets:[100, 25],
  948. startDrag : function(){
  949. var w = this.win;
  950. this.proxy = w.ghost(w.initialConfig.cls);
  951. if(w.constrain !== false){
  952. var so = w.el.shadowOffset;
  953. this.constrainTo(w.container, {right: so, left: so, bottom: so});
  954. }else if(w.constrainHeader !== false){
  955. var s = this.proxy.getSize();
  956. this.constrainTo(w.container, {right: -(s.width-this.headerOffsets[0]), bottom: -(s.height-this.headerOffsets[1])});
  957. }
  958. },
  959. b4Drag : Ext.emptyFn,
  960. onDrag : function(e){
  961. this.alignElWithMouse(this.proxy, e.getPageX(), e.getPageY());
  962. },
  963. endDrag : function(e){
  964. this.win.unghost();
  965. this.win.saveState();
  966. }
  967. });
  968. </pre>
  969. </body>
  970. </html>