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.

2023 lines
74 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.Window
  9. * @extends Ext.Panel
  10. * <p>A specialized panel intended for use as an application window. Windows are floated, {@link #resizable}, and
  11. * {@link #draggable} by default. Windows can be {@link #maximizable maximized} to fill the viewport,
  12. * restored to their prior size, and can be {@link #minimize}d.</p>
  13. * <p>Windows can also be linked to a {@link Ext.WindowGroup} or managed by the {@link Ext.WindowMgr} to provide
  14. * grouping, activation, to front, to back and other application-specific behavior.</p>
  15. * <p>By default, Windows will be rendered to document.body. To {@link #constrain} a Window to another element
  16. * specify {@link Ext.Component#renderTo renderTo}.</p>
  17. * <p><b>Note:</b> By default, the <code>{@link #closable close}</code> header tool <i>destroys</i> the Window resulting in
  18. * destruction of any child Components. This makes the Window object, and all its descendants <b>unusable</b>. To enable
  19. * re-use of a Window, use <b><code>{@link #closeAction closeAction: 'hide'}</code></b>.</p>
  20. * @constructor
  21. * @param {Object} config The config object
  22. * @xtype window
  23. */
  24. Ext.Window = Ext.extend(Ext.Panel, {
  25. /**
  26. * @cfg {Number} x
  27. * The X position of the left edge of the window on initial showing. Defaults to centering the Window within
  28. * the width of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
  29. */
  30. /**
  31. * @cfg {Number} y
  32. * The Y position of the top edge of the window on initial showing. Defaults to centering the Window within
  33. * the height of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
  34. */
  35. /**
  36. * @cfg {Boolean} modal
  37. * True to make the window modal and mask everything behind it when displayed, false to display it without
  38. * restricting access to other UI elements (defaults to false).
  39. */
  40. /**
  41. * @cfg {String/Element} animateTarget
  42. * Id or element from which the window should animate while opening (defaults to null with no animation).
  43. */
  44. /**
  45. * @cfg {String} resizeHandles
  46. * A valid {@link Ext.Resizable} handles config string (defaults to 'all'). Only applies when resizable = true.
  47. */
  48. /**
  49. * @cfg {Ext.WindowGroup} manager
  50. * A reference to the WindowGroup that should manage this window (defaults to {@link Ext.WindowMgr}).
  51. */
  52. /**
  53. * @cfg {String/Number/Component} defaultButton
  54. * <p>Specifies a Component to receive focus when this Window is focussed.</p>
  55. * <p>This may be one of:</p><div class="mdetail-params"><ul>
  56. * <li>The index of a footer Button.</li>
  57. * <li>The id of a Component.</li>
  58. * <li>A Component.</li>
  59. * </ul></div>
  60. */
  61. /**
  62. * @cfg {Function} onEsc
  63. * Allows override of the built-in processing for the escape key. Default action
  64. * is to close the Window (performing whatever action is specified in {@link #closeAction}.
  65. * To prevent the Window closing when the escape key is pressed, specify this as
  66. * Ext.emptyFn (See {@link Ext#emptyFn}).
  67. */
  68. /**
  69. * @cfg {Boolean} collapsed
  70. * True to render the window collapsed, false to render it expanded (defaults to false). Note that if
  71. * {@link #expandOnShow} is true (the default) it will override the <tt>collapsed</tt> config and the window
  72. * will always be expanded when shown.
  73. */
  74. /**
  75. * @cfg {Boolean} maximized
  76. * True to initially display the window in a maximized state. (Defaults to false).
  77. */
  78. /**
  79. * @cfg {String} baseCls
  80. * The base CSS class to apply to this panel's element (defaults to 'x-window').
  81. */
  82. baseCls : 'x-window',
  83. /**
  84. * @cfg {Boolean} resizable
  85. * True to allow user resizing at each edge and corner of the window, false to disable resizing (defaults to true).
  86. */
  87. resizable : true,
  88. /**
  89. * @cfg {Boolean} draggable
  90. * True to allow the window to be dragged by the header bar, false to disable dragging (defaults to true). Note
  91. * that by default the window will be centered in the viewport, so if dragging is disabled the window may need
  92. * to be positioned programmatically after render (e.g., myWindow.setPosition(100, 100);).
  93. */
  94. draggable : true,
  95. /**
  96. * @cfg {Boolean} closable
  97. * <p>True to display the 'close' tool button and allow the user to close the window, false to
  98. * hide the button and disallow closing the window (defaults to true).</p>
  99. * <p>By default, when close is requested by either clicking the close button in the header
  100. * or pressing ESC when the Window has focus, the {@link #close} method will be called. This
  101. * will <i>{@link Ext.Component#destroy destroy}</i> the Window and its content meaning that
  102. * it may not be reused.</p>
  103. * <p>To make closing a Window <i>hide</i> the Window so that it may be reused, set
  104. * {@link #closeAction} to 'hide'.
  105. */
  106. closable : true,
  107. /**
  108. * @cfg {String} closeAction
  109. * <p>The action to take when the close header tool is clicked:
  110. * <div class="mdetail-params"><ul>
  111. * <li><b><code>'{@link #close}'</code></b> : <b>Default</b><div class="sub-desc">
  112. * {@link #close remove} the window from the DOM and {@link Ext.Component#destroy destroy}
  113. * it and all descendant Components. The window will <b>not</b> be available to be
  114. * redisplayed via the {@link #show} method.
  115. * </div></li>
  116. * <li><b><code>'{@link #hide}'</code></b> : <div class="sub-desc">
  117. * {@link #hide} the window by setting visibility to hidden and applying negative offsets.
  118. * The window will be available to be redisplayed via the {@link #show} method.
  119. * </div></li>
  120. * </ul></div>
  121. * <p><b>Note:</b> This setting does not affect the {@link #close} method
  122. * which will always {@link Ext.Component#destroy destroy} the window. To
  123. * programatically <i>hide</i> a window, call {@link #hide}.</p>
  124. */
  125. closeAction : 'close',
  126. /**
  127. * @cfg {Boolean} constrain
  128. * True to constrain the window within its containing element, false to allow it to fall outside of its
  129. * containing element. By default the window will be rendered to document.body. To render and constrain the
  130. * window within another element specify {@link #renderTo}.
  131. * (defaults to false). Optionally the header only can be constrained using {@link #constrainHeader}.
  132. */
  133. constrain : false,
  134. /**
  135. * @cfg {Boolean} constrainHeader
  136. * True to constrain the window header within its containing element (allowing the window body to fall outside
  137. * of its containing element) or false to allow the header to fall outside its containing element (defaults to
  138. * false). Optionally the entire window can be constrained using {@link #constrain}.
  139. */
  140. constrainHeader : false,
  141. /**
  142. * @cfg {Boolean} plain
  143. * True to render the window body with a transparent background so that it will blend into the framing
  144. * elements, false to add a lighter background color to visually highlight the body element and separate it
  145. * more distinctly from the surrounding frame (defaults to false).
  146. */
  147. plain : false,
  148. /**
  149. * @cfg {Boolean} minimizable
  150. * True to display the 'minimize' tool button and allow the user to minimize the window, false to hide the button
  151. * and disallow minimizing the window (defaults to false). Note that this button provides no implementation --
  152. * the behavior of minimizing a window is implementation-specific, so the minimize event must be handled and a
  153. * custom minimize behavior implemented for this option to be useful.
  154. */
  155. minimizable : false,
  156. /**
  157. * @cfg {Boolean} maximizable
  158. * True to display the 'maximize' tool button and allow the user to maximize the window, false to hide the button
  159. * and disallow maximizing the window (defaults to false). Note that when a window is maximized, the tool button
  160. * will automatically change to a 'restore' button with the appropriate behavior already built-in that will
  161. * restore the window to its previous size.
  162. */
  163. maximizable : false,
  164. /**
  165. * @cfg {Number} minHeight
  166. * The minimum height in pixels allowed for this window (defaults to 100). Only applies when resizable = true.
  167. */
  168. minHeight : 100,
  169. /**
  170. * @cfg {Number} minWidth
  171. * The minimum width in pixels allowed for this window (defaults to 200). Only applies when resizable = true.
  172. */
  173. minWidth : 200,
  174. /**
  175. * @cfg {Boolean} expandOnShow
  176. * True to always expand the window when it is displayed, false to keep it in its current state (which may be
  177. * {@link #collapsed}) when displayed (defaults to true).
  178. */
  179. expandOnShow : true,
  180. /**
  181. * @cfg {Number} showAnimDuration The number of seconds that the window show animation takes if enabled.
  182. * Defaults to 0.25
  183. */
  184. showAnimDuration: 0.25,
  185. /**
  186. * @cfg {Number} hideAnimDuration The number of seconds that the window hide animation takes if enabled.
  187. * Defaults to 0.25
  188. */
  189. hideAnimDuration: 0.25,
  190. // inherited docs, same default
  191. collapsible : false,
  192. /**
  193. * @cfg {Boolean} initHidden
  194. * True to hide the window until show() is explicitly called (defaults to true).
  195. * @deprecated
  196. */
  197. initHidden : undefined,
  198. /**
  199. * @cfg {Boolean} hidden
  200. * Render this component hidden (default is <tt>true</tt>). If <tt>true</tt>, the
  201. * {@link #hide} method will be called internally.
  202. */
  203. hidden : true,
  204. // The following configs are set to provide the basic functionality of a window.
  205. // Changing them would require additional code to handle correctly and should
  206. // usually only be done in subclasses that can provide custom behavior. Changing them
  207. // may have unexpected or undesirable results.
  208. /** @cfg {String} elements @hide */
  209. elements : 'header,body',
  210. /** @cfg {Boolean} frame @hide */
  211. frame : true,
  212. /** @cfg {Boolean} floating @hide */
  213. floating : true,
  214. // private
  215. initComponent : function(){
  216. this.initTools();
  217. Ext.Window.superclass.initComponent.call(this);
  218. this.addEvents(
  219. /**
  220. * @event activate
  221. * Fires after the window has been visually activated via {@link #setActive}.
  222. * @param {Ext.Window} this
  223. */
  224. /**
  225. * @event deactivate
  226. * Fires after the window has been visually deactivated via {@link #setActive}.
  227. * @param {Ext.Window} this
  228. */
  229. /**
  230. * @event resize
  231. * Fires after the window has been resized.
  232. * @param {Ext.Window} this
  233. * @param {Number} width The window's new width
  234. * @param {Number} height The window's new height
  235. */
  236. 'resize',
  237. /**
  238. * @event maximize
  239. * Fires after the window has been maximized.
  240. * @param {Ext.Window} this
  241. */
  242. 'maximize',
  243. /**
  244. * @event minimize
  245. * Fires after the window has been minimized.
  246. * @param {Ext.Window} this
  247. */
  248. 'minimize',
  249. /**
  250. * @event restore
  251. * Fires after the window has been restored to its original size after being maximized.
  252. * @param {Ext.Window} this
  253. */
  254. 'restore'
  255. );
  256. // for backwards compat, this should be removed at some point
  257. if(Ext.isDefined(this.initHidden)){
  258. this.hidden = this.initHidden;
  259. }
  260. if(this.hidden === false){
  261. this.hidden = true;
  262. this.show();
  263. }
  264. },
  265. // private
  266. getState : function(){
  267. return Ext.apply(Ext.Window.superclass.getState.call(this) || {}, this.getBox(true));
  268. },
  269. // private
  270. onRender : function(ct, position){
  271. Ext.Window.superclass.onRender.call(this, ct, position);
  272. if(this.plain){
  273. this.el.addClass('x-window-plain');
  274. }
  275. // this element allows the Window to be focused for keyboard events
  276. this.focusEl = this.el.createChild({
  277. tag: 'a', href:'#', cls:'x-dlg-focus',
  278. tabIndex:'-1', html: '&#160;'});
  279. this.focusEl.swallowEvent('click', true);
  280. this.proxy = this.el.createProxy('x-window-proxy');
  281. this.proxy.enableDisplayMode('block');
  282. if(this.modal){
  283. this.mask = this.container.createChild({cls:'ext-el-mask'}, this.el.dom);
  284. this.mask.enableDisplayMode('block');
  285. this.mask.hide();
  286. this.mon(this.mask, 'click', this.focus, this);
  287. }
  288. if(this.maximizable){
  289. this.mon(this.header, 'dblclick', this.toggleMaximize, this);
  290. }
  291. },
  292. // private
  293. initEvents : function(){
  294. Ext.Window.superclass.initEvents.call(this);
  295. if(this.animateTarget){
  296. this.setAnimateTarget(this.animateTarget);
  297. }
  298. if(this.resizable){
  299. this.resizer = new Ext.Resizable(this.el, {
  300. minWidth: this.minWidth,
  301. minHeight:this.minHeight,
  302. handles: this.resizeHandles || 'all',
  303. pinned: true,
  304. resizeElement : this.resizerAction,
  305. handleCls: 'x-window-handle'
  306. });
  307. this.resizer.window = this;
  308. this.mon(this.resizer, 'beforeresize', this.beforeResize, this);
  309. }
  310. if(this.draggable){
  311. this.header.addClass('x-window-draggable');
  312. }
  313. this.mon(this.el, 'mousedown', this.toFront, this);
  314. this.manager = this.manager || Ext.WindowMgr;
  315. this.manager.register(this);
  316. if(this.maximized){
  317. this.maximized = false;
  318. this.maximize();
  319. }
  320. if(this.closable){
  321. var km = this.getKeyMap();
  322. km.on(27, this.onEsc, this);
  323. km.disable();
  324. }
  325. },
  326. initDraggable : function(){
  327. /**
  328. * <p>If this Window is configured {@link #draggable}, this property will contain
  329. * an instance of {@link Ext.dd.DD} which handles dragging the Window's DOM Element.</p>
  330. * <p>This has implementations of <code>startDrag</code>, <code>onDrag</code> and <code>endDrag</code>
  331. * which perform the dragging action. If extra logic is needed at these points, use
  332. * {@link Function#createInterceptor createInterceptor} or {@link Function#createSequence createSequence} to
  333. * augment the existing implementations.</p>
  334. * @type Ext.dd.DD
  335. * @property dd
  336. */
  337. this.dd = new Ext.Window.DD(this);
  338. },
  339. // private
  340. onEsc : function(k, e){
  341. e.stopEvent();
  342. this[this.closeAction]();
  343. },
  344. // private
  345. beforeDestroy : function(){
  346. if(this.rendered){
  347. this.hide();
  348. this.clearAnchor();
  349. Ext.destroy(
  350. this.focusEl,
  351. this.resizer,
  352. this.dd,
  353. this.proxy,
  354. this.mask
  355. );
  356. }
  357. Ext.Window.superclass.beforeDestroy.call(this);
  358. },
  359. // private
  360. onDestroy : function(){
  361. if(this.manager){
  362. this.manager.unregister(this);
  363. }
  364. Ext.Window.superclass.onDestroy.call(this);
  365. },
  366. // private
  367. initTools : function(){
  368. if(this.minimizable){
  369. this.addTool({
  370. id: 'minimize',
  371. handler: this.minimize.createDelegate(this, [])
  372. });
  373. }
  374. if(this.maximizable){
  375. this.addTool({
  376. id: 'maximize',
  377. handler: this.maximize.createDelegate(this, [])
  378. });
  379. this.addTool({
  380. id: 'restore',
  381. handler: this.restore.createDelegate(this, []),
  382. hidden:true
  383. });
  384. }
  385. if(this.closable){
  386. this.addTool({
  387. id: 'close',
  388. handler: this[this.closeAction].createDelegate(this, [])
  389. });
  390. }
  391. },
  392. // private
  393. resizerAction : function(){
  394. var box = this.proxy.getBox();
  395. this.proxy.hide();
  396. this.window.handleResize(box);
  397. return box;
  398. },
  399. // private
  400. beforeResize : function(){
  401. this.resizer.minHeight = Math.max(this.minHeight, this.getFrameHeight() + 40); // 40 is a magic minimum content size?
  402. this.resizer.minWidth = Math.max(this.minWidth, this.getFrameWidth() + 40);
  403. this.resizeBox = this.el.getBox();
  404. },
  405. // private
  406. updateHandles : function(){
  407. if(Ext.isIE && this.resizer){
  408. this.resizer.syncHandleHeight();
  409. this.el.repaint();
  410. }
  411. },
  412. // private
  413. handleResize : function(box){
  414. var rz = this.resizeBox;
  415. if(rz.x != box.x || rz.y != box.y){
  416. this.updateBox(box);
  417. }else{
  418. this.setSize(box);
  419. if (Ext.isIE6 && Ext.isStrict) {
  420. this.doLayout();
  421. }
  422. }
  423. this.focus();
  424. this.updateHandles();
  425. this.saveState();
  426. },
  427. /**
  428. * Focuses the window. If a defaultButton is set, it will receive focus, otherwise the
  429. * window itself will receive focus.
  430. */
  431. focus : function(){
  432. var f = this.focusEl,
  433. db = this.defaultButton,
  434. t = typeof db,
  435. el,
  436. ct;
  437. if(Ext.isDefined(db)){
  438. if(Ext.isNumber(db) && this.fbar){
  439. f = this.fbar.items.get(db);
  440. }else if(Ext.isString(db)){
  441. f = Ext.getCmp(db);
  442. }else{
  443. f = db;
  444. }
  445. el = f.getEl();
  446. ct = Ext.getDom(this.container);
  447. if (el && ct) {
  448. if (ct != document.body && !Ext.lib.Region.getRegion(ct).contains(Ext.lib.Region.getRegion(el.dom))){
  449. return;
  450. }
  451. }
  452. }
  453. f = f || this.focusEl;
  454. f.focus.defer(10, f);
  455. },
  456. /**
  457. * Sets the target element from which the window should animate while opening.
  458. * @param {String/Element} el The target element or id
  459. */
  460. setAnimateTarget : function(el){
  461. el = Ext.get(el);
  462. this.animateTarget = el;
  463. },
  464. // private
  465. beforeShow : function(){
  466. delete this.el.lastXY;
  467. delete this.el.lastLT;
  468. if(this.x === undefined || this.y === undefined){
  469. var xy = this.el.getAlignToXY(this.container, 'c-c');
  470. var pos = this.el.translatePoints(xy[0], xy[1]);
  471. this.x = this.x === undefined? pos.left : this.x;
  472. this.y = this.y === undefined? pos.top : this.y;
  473. }
  474. this.el.setLeftTop(this.x, this.y);
  475. if(this.expandOnShow){
  476. this.expand(false);
  477. }
  478. if(this.modal){
  479. Ext.getBody().addClass('x-body-masked');
  480. this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
  481. this.mask.show();
  482. }
  483. },
  484. /**
  485. * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
  486. * @param {String/Element} animateTarget (optional) The target element or id from which the window should
  487. * animate while opening (defaults to null with no animation)
  488. * @param {Function} callback (optional) A callback function to call after the window is displayed
  489. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
  490. * @return {Ext.Window} this
  491. */
  492. show : function(animateTarget, cb, scope){
  493. if(!this.rendered){
  494. this.render(Ext.getBody());
  495. }
  496. if(this.hidden === false){
  497. this.toFront();
  498. return this;
  499. }
  500. if(this.fireEvent('beforeshow', this) === false){
  501. return this;
  502. }
  503. if(cb){
  504. this.on('show', cb, scope, {single:true});
  505. }
  506. this.hidden = false;
  507. if(Ext.isDefined(animateTarget)){
  508. this.setAnimateTarget(animateTarget);
  509. }
  510. this.beforeShow();
  511. if(this.animateTarget){
  512. this.animShow();
  513. }else{
  514. this.afterShow();
  515. }
  516. return this;
  517. },
  518. // private
  519. afterShow : function(isAnim){
  520. if (this.isDestroyed){
  521. return false;
  522. }
  523. this.proxy.hide();
  524. this.el.setStyle('display', 'block');
  525. this.el.show();
  526. if(this.maximized){
  527. this.fitContainer();
  528. }
  529. if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
  530. this.cascade(this.setAutoScroll);
  531. }
  532. if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
  533. Ext.EventManager.onWindowResize(this.onWindowResize, this);
  534. }
  535. this.doConstrain();
  536. this.doLayout();
  537. if(this.keyMap){
  538. this.keyMap.enable();
  539. }
  540. this.toFront();
  541. this.updateHandles();
  542. if(isAnim && (Ext.isIE || Ext.isWebKit)){
  543. var sz = this.getSize();
  544. this.onResize(sz.width, sz.height);
  545. }
  546. this.onShow();
  547. this.fireEvent('show', this);
  548. },
  549. // private
  550. animShow : function(){
  551. this.proxy.show();
  552. this.proxy.setBox(this.animateTarget.getBox());
  553. this.proxy.setOpacity(0);
  554. var b = this.getBox();
  555. this.el.setStyle('display', 'none');
  556. this.proxy.shift(Ext.apply(b, {
  557. callback: this.afterShow.createDelegate(this, [true], false),
  558. scope: this,
  559. easing: 'easeNone',
  560. duration: this.showAnimDuration,
  561. opacity: 0.5
  562. }));
  563. },
  564. /**
  565. * Hides the window, setting it to invisible and applying negative offsets.
  566. * @param {String/Element} animateTarget (optional) The target element or id to which the window should
  567. * animate while hiding (defaults to null with no animation)
  568. * @param {Function} callback (optional) A callback function to call after the window is hidden
  569. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
  570. * @return {Ext.Window} this
  571. */
  572. hide : function(animateTarget, cb, scope){
  573. if(this.hidden || this.fireEvent('beforehide', this) === false){
  574. return this;
  575. }
  576. if(cb){
  577. this.on('hide', cb, scope, {single:true});
  578. }
  579. this.hidden = true;
  580. if(animateTarget !== undefined){
  581. this.setAnimateTarget(animateTarget);
  582. }
  583. if(this.modal){
  584. this.mask.hide();
  585. Ext.getBody().removeClass('x-body-masked');
  586. }
  587. if(this.animateTarget){
  588. this.animHide();
  589. }else{
  590. this.el.hide();
  591. this.afterHide();
  592. }
  593. return this;
  594. },
  595. // private
  596. afterHide : function(){
  597. this.proxy.hide();
  598. if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
  599. Ext.EventManager.removeResizeListener(this.onWindowResize, this);
  600. }
  601. if(this.keyMap){
  602. this.keyMap.disable();
  603. }
  604. this.onHide();
  605. this.fireEvent('hide', this);
  606. },
  607. // private
  608. animHide : function(){
  609. this.proxy.setOpacity(0.5);
  610. this.proxy.show();
  611. var tb = this.getBox(false);
  612. this.proxy.setBox(tb);
  613. this.el.hide();
  614. this.proxy.shift(Ext.apply(this.animateTarget.getBox(), {
  615. callback: this.afterHide,
  616. scope: this,
  617. duration: this.hideAnimDuration,
  618. easing: 'easeNone',
  619. opacity: 0
  620. }));
  621. },
  622. /**
  623. * Method that is called immediately before the <code>show</code> event is fired.
  624. * Defaults to <code>Ext.emptyFn</code>.
  625. */
  626. onShow : Ext.emptyFn,
  627. /**
  628. * Method that is called immediately before the <code>hide</code> event is fired.
  629. * Defaults to <code>Ext.emptyFn</code>.
  630. */
  631. onHide : Ext.emptyFn,
  632. // private
  633. onWindowResize : function(){
  634. if(this.maximized){
  635. this.fitContainer();
  636. }
  637. if(this.modal){
  638. this.mask.setSize('100%', '100%');
  639. var force = this.mask.dom.offsetHeight;
  640. this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
  641. }
  642. this.doConstrain();
  643. },
  644. // private
  645. doConstrain : function(){
  646. if(this.constrain || this.constrainHeader){
  647. var offsets;
  648. if(this.constrain){
  649. offsets = {
  650. right:this.el.shadowOffset,
  651. left:this.el.shadowOffset,
  652. bottom:this.el.shadowOffset
  653. };
  654. }else {
  655. var s = this.getSize();
  656. offsets = {
  657. right:-(s.width - 100),
  658. bottom:-(s.height - 25)
  659. };
  660. }
  661. var xy = this.el.getConstrainToXY(this.container, true, offsets);
  662. if(xy){
  663. this.setPosition(xy[0], xy[1]);
  664. }
  665. }
  666. },
  667. // private - used for dragging
  668. ghost : function(cls){
  669. var ghost = this.createGhost(cls);
  670. var box = this.getBox(true);
  671. ghost.setLeftTop(box.x, box.y);
  672. ghost.setWidth(box.width);
  673. this.el.hide();
  674. this.activeGhost = ghost;
  675. return ghost;
  676. },
  677. // private
  678. unghost : function(show, matchPosition){
  679. if(!this.activeGhost) {
  680. return;
  681. }
  682. if(show !== false){
  683. this.el.show();
  684. this.focus.defer(10, this);
  685. if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
  686. this.cascade(this.setAutoScroll);
  687. }
  688. }
  689. if(matchPosition !== false){
  690. this.setPosition(this.activeGhost.getLeft(true), this.activeGhost.getTop(true));
  691. }
  692. this.activeGhost.hide();
  693. this.activeGhost.remove();
  694. delete this.activeGhost;
  695. },
  696. /**
  697. * Placeholder method for minimizing the window. By default, this method simply fires the {@link #minimize} event
  698. * since the behavior of minimizing a window is application-specific. To implement custom minimize behavior,
  699. * either the minimize event can be handled or this method can be overridden.
  700. * @return {Ext.Window} this
  701. */
  702. minimize : function(){
  703. this.fireEvent('minimize', this);
  704. return this;
  705. },
  706. /**
  707. * <p>Closes the Window, removes it from the DOM, {@link Ext.Component#destroy destroy}s
  708. * the Window object and all its descendant Components. The {@link Ext.Panel#beforeclose beforeclose}
  709. * event is fired before the close happens and will cancel the close action if it returns false.<p>
  710. * <p><b>Note:</b> This method is not affected by the {@link #closeAction} setting which
  711. * only affects the action triggered when clicking the {@link #closable 'close' tool in the header}.
  712. * To hide the Window without destroying it, call {@link #hide}.</p>
  713. */
  714. close : function(){
  715. if(this.fireEvent('beforeclose', this) !== false){
  716. if(this.hidden){
  717. this.doClose();
  718. }else{
  719. this.hide(null, this.doClose, this);
  720. }
  721. }
  722. },
  723. // private
  724. doClose : function(){
  725. this.fireEvent('close', this);
  726. this.destroy();
  727. },
  728. /**
  729. * Fits the window within its current container and automatically replaces
  730. * the {@link #maximizable 'maximize' tool button} with the 'restore' tool button.
  731. * Also see {@link #toggleMaximize}.
  732. * @return {Ext.Window} this
  733. */
  734. maximize : function(){
  735. if(!this.maximized){
  736. this.expand(false);
  737. this.restoreSize = this.getSize();
  738. this.restorePos = this.getPosition(true);
  739. if (this.maximizable){
  740. this.tools.maximize.hide();
  741. this.tools.restore.show();
  742. }
  743. this.maximized = true;
  744. this.el.disableShadow();
  745. if(this.dd){
  746. this.dd.lock();
  747. }
  748. if(this.collapsible){
  749. this.tools.toggle.hide();
  750. }
  751. this.el.addClass('x-window-maximized');
  752. this.container.addClass('x-window-maximized-ct');
  753. this.setPosition(0, 0);
  754. this.fitContainer();
  755. this.fireEvent('maximize', this);
  756. }
  757. return this;
  758. },
  759. /**
  760. * Restores a {@link #maximizable maximized} window back to its original
  761. * size and position prior to being maximized and also replaces
  762. * the 'restore' tool button with the 'maximize' tool button.
  763. * Also see {@link #toggleMaximize}.
  764. * @return {Ext.Window} this
  765. */
  766. restore : function(){
  767. if(this.maximized){
  768. var t = this.tools;
  769. this.el.removeClass('x-window-maximized');
  770. if(t.restore){
  771. t.restore.hide();
  772. }
  773. if(t.maximize){
  774. t.maximize.show();
  775. }
  776. this.setPosition(this.restorePos[0], this.restorePos[1]);
  777. this.setSize(this.restoreSize.width, this.restoreSize.height);
  778. delete this.restorePos;
  779. delete this.restoreSize;
  780. this.maximized = false;
  781. this.el.enableShadow(true);
  782. if(this.dd){
  783. this.dd.unlock();
  784. }
  785. if(this.collapsible && t.toggle){
  786. t.toggle.show();
  787. }
  788. this.container.removeClass('x-window-maximized-ct');
  789. this.doConstrain();
  790. this.fireEvent('restore', this);
  791. }
  792. return this;
  793. },
  794. /**
  795. * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized
  796. * state of the window.
  797. * @return {Ext.Window} this
  798. */
  799. toggleMaximize : function(){
  800. return this[this.maximized ? 'restore' : 'maximize']();
  801. },
  802. // private
  803. fitContainer : function(){
  804. var vs = this.container.getViewSize(false);
  805. this.setSize(vs.width, vs.height);
  806. },
  807. // private
  808. // z-index is managed by the WindowManager and may be overwritten at any time
  809. setZIndex : function(index){
  810. if(this.modal){
  811. this.mask.setStyle('z-index', index);
  812. }
  813. this.el.setZIndex(++index);
  814. index += 5;
  815. if(this.resizer){
  816. this.resizer.proxy.setStyle('z-index', ++index);
  817. }
  818. this.lastZIndex = index;
  819. },
  820. /**
  821. * Aligns the window to the specified element
  822. * @param {Mixed} element The element to align to.
  823. * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.Element#alignTo} for more details).
  824. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  825. * @return {Ext.Window} this
  826. */
  827. alignTo : function(element, position, offsets){
  828. var xy = this.el.getAlignToXY(element, position, offsets);
  829. this.setPagePosition(xy[0], xy[1]);
  830. return this;
  831. },
  832. /**
  833. * Anchors this window to another element and realigns it when the window is resized or scrolled.
  834. * @param {Mixed} element The element to align to.
  835. * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details)
  836. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  837. * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
  838. * is a number, it is used as the buffer delay (defaults to 50ms).
  839. * @return {Ext.Window} this
  840. */
  841. anchorTo : function(el, alignment, offsets, monitorScroll){
  842. this.clearAnchor();
  843. this.anchorTarget = {
  844. el: el,
  845. alignment: alignment,
  846. offsets: offsets
  847. };
  848. Ext.EventManager.onWindowResize(this.doAnchor, this);
  849. var tm = typeof monitorScroll;
  850. if(tm != 'undefined'){
  851. Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
  852. {buffer: tm == 'number' ? monitorScroll : 50});
  853. }
  854. return this.doAnchor();
  855. },
  856. /**
  857. * Performs the anchor, using the saved anchorTarget property.
  858. * @return {Ext.Window} this
  859. * @private
  860. */
  861. doAnchor : function(){
  862. var o = this.anchorTarget;
  863. this.alignTo(o.el, o.alignment, o.offsets);
  864. return this;
  865. },
  866. /**
  867. * Removes any existing anchor from this window. See {@link #anchorTo}.
  868. * @return {Ext.Window} this
  869. */
  870. clearAnchor : function(){
  871. if(this.anchorTarget){
  872. Ext.EventManager.removeResizeListener(this.doAnchor, this);
  873. Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
  874. delete this.anchorTarget;
  875. }
  876. return this;
  877. },
  878. /**
  879. * Brings this window to the front of any other visible windows
  880. * @param {Boolean} e (optional) Specify <tt>false</tt> to prevent the window from being focused.
  881. * @return {Ext.Window} this
  882. */
  883. toFront : function(e){
  884. if(this.manager.bringToFront(this)){
  885. if(!e || !e.getTarget().focus){
  886. this.focus();
  887. }
  888. }
  889. return this;
  890. },
  891. /**
  892. * Makes this the active window by showing its shadow, or deactivates it by hiding its shadow. This method also
  893. * fires the {@link #activate} or {@link #deactivate} event depending on which action occurred. This method is
  894. * called internally by {@link Ext.WindowMgr}.
  895. * @param {Boolean} active True to activate the window, false to deactivate it (defaults to false)
  896. */
  897. setActive : function(active){
  898. if(active){
  899. if(!this.maximized){
  900. this.el.enableShadow(true);
  901. }
  902. this.fireEvent('activate', this);
  903. }else{
  904. this.el.disableShadow();
  905. this.fireEvent('deactivate', this);
  906. }
  907. },
  908. /**
  909. * Sends this window to the back of (lower z-index than) any other visible windows
  910. * @return {Ext.Window} this
  911. */
  912. toBack : function(){
  913. this.manager.sendToBack(this);
  914. return this;
  915. },
  916. /**
  917. * Centers this window in the viewport
  918. * @return {Ext.Window} this
  919. */
  920. center : function(){
  921. var xy = this.el.getAlignToXY(this.container, 'c-c');
  922. this.setPagePosition(xy[0], xy[1]);
  923. return this;
  924. }
  925. /**
  926. * @cfg {Boolean} autoWidth @hide
  927. **/
  928. });
  929. Ext.reg('window', Ext.Window);
  930. // private - custom Window DD implementation
  931. Ext.Window.DD = Ext.extend(Ext.dd.DD, {
  932. constructor : function(win){
  933. this.win = win;
  934. Ext.Window.DD.superclass.constructor.call(this, win.el.id, 'WindowDD-'+win.id);
  935. this.setHandleElId(win.header.id);
  936. this.scroll = false;
  937. },
  938. moveOnly:true,
  939. headerOffsets:[100, 25],
  940. startDrag : function(){
  941. var w = this.win;
  942. this.proxy = w.ghost(w.initialConfig.cls);
  943. if(w.constrain !== false){
  944. var so = w.el.shadowOffset;
  945. this.constrainTo(w.container, {right: so, left: so, bottom: so});
  946. }else if(w.constrainHeader !== false){
  947. var s = this.proxy.getSize();
  948. this.constrainTo(w.container, {right: -(s.width-this.headerOffsets[0]), bottom: -(s.height-this.headerOffsets[1])});
  949. }
  950. },
  951. b4Drag : Ext.emptyFn,
  952. onDrag : function(e){
  953. this.alignElWithMouse(this.proxy, e.getPageX(), e.getPageY());
  954. },
  955. endDrag : function(e){
  956. this.win.unghost();
  957. this.win.saveState();
  958. }
  959. });
  960. /**
  961. * @class Ext.WindowGroup
  962. * An object that manages a group of {@link Ext.Window} instances and provides z-order management
  963. * and window activation behavior.
  964. * @constructor
  965. */
  966. Ext.WindowGroup = function(){
  967. var list = {};
  968. var accessList = [];
  969. var front = null;
  970. // private
  971. var sortWindows = function(d1, d2){
  972. return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
  973. };
  974. // private
  975. var orderWindows = function(){
  976. var a = accessList, len = a.length;
  977. if(len > 0){
  978. a.sort(sortWindows);
  979. var seed = a[0].manager.zseed;
  980. for(var i = 0; i < len; i++){
  981. var win = a[i];
  982. if(win && !win.hidden){
  983. win.setZIndex(seed + (i*10));
  984. }
  985. }
  986. }
  987. activateLast();
  988. };
  989. // private
  990. var setActiveWin = function(win){
  991. if(win != front){
  992. if(front){
  993. front.setActive(false);
  994. }
  995. front = win;
  996. if(win){
  997. win.setActive(true);
  998. }
  999. }
  1000. };
  1001. // private
  1002. var activateLast = function(){
  1003. for(var i = accessList.length-1; i >=0; --i) {
  1004. if(!accessList[i].hidden){
  1005. setActiveWin(accessList[i]);
  1006. return;
  1007. }
  1008. }
  1009. // none to activate
  1010. setActiveWin(null);
  1011. };
  1012. return {
  1013. /**
  1014. * The starting z-index for windows in this WindowGroup (defaults to 9000)
  1015. * @type Number The z-index value
  1016. */
  1017. zseed : 9000,
  1018. /**
  1019. * <p>Registers a {@link Ext.Window Window} with this WindowManager. This should not
  1020. * need to be called under normal circumstances. Windows are automatically registered
  1021. * with a {@link Ext.Window#manager manager} at construction time.</p>
  1022. * <p>Where this may be useful is moving Windows between two WindowManagers. For example,
  1023. * to bring the Ext.MessageBox dialog under the same manager as the Desktop's
  1024. * WindowManager in the desktop sample app:</p><code><pre>
  1025. var msgWin = Ext.MessageBox.getDialog();
  1026. MyDesktop.getDesktop().getManager().register(msgWin);
  1027. </pre></code>
  1028. * @param {Window} win The Window to register.
  1029. */
  1030. register : function(win){
  1031. if(win.manager){
  1032. win.manager.unregister(win);
  1033. }
  1034. win.manager = this;
  1035. list[win.id] = win;
  1036. accessList.push(win);
  1037. win.on('hide', activateLast);
  1038. },
  1039. /**
  1040. * <p>Unregisters a {@link Ext.Window Window} from this WindowManager. This should not
  1041. * need to be called. Windows are automatically unregistered upon destruction.
  1042. * See {@link #register}.</p>
  1043. * @param {Window} win The Window to unregister.
  1044. */
  1045. unregister : function(win){
  1046. delete win.manager;
  1047. delete list[win.id];
  1048. win.un('hide', activateLast);
  1049. accessList.remove(win);
  1050. },
  1051. /**
  1052. * Gets a registered window by id.
  1053. * @param {String/Object} id The id of the window or a {@link Ext.Window} instance
  1054. * @return {Ext.Window}
  1055. */
  1056. get : function(id){
  1057. return typeof id == "object" ? id : list[id];
  1058. },
  1059. /**
  1060. * Brings the specified window to the front of any other active windows in this WindowGroup.
  1061. * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
  1062. * @return {Boolean} True if the dialog was brought to the front, else false
  1063. * if it was already in front
  1064. */
  1065. bringToFront : function(win){
  1066. win = this.get(win);
  1067. if(win != front){
  1068. win._lastAccess = new Date().getTime();
  1069. orderWindows();
  1070. return true;
  1071. }
  1072. return false;
  1073. },
  1074. /**
  1075. * Sends the specified window to the back of other active windows in this WindowGroup.
  1076. * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
  1077. * @return {Ext.Window} The window
  1078. */
  1079. sendToBack : function(win){
  1080. win = this.get(win);
  1081. win._lastAccess = -(new Date().getTime());
  1082. orderWindows();
  1083. return win;
  1084. },
  1085. /**
  1086. * Hides all windows in this WindowGroup.
  1087. */
  1088. hideAll : function(){
  1089. for(var id in list){
  1090. if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
  1091. list[id].hide();
  1092. }
  1093. }
  1094. },
  1095. /**
  1096. * Gets the currently-active window in this WindowGroup.
  1097. * @return {Ext.Window} The active window
  1098. */
  1099. getActive : function(){
  1100. return front;
  1101. },
  1102. /**
  1103. * Returns zero or more windows in this WindowGroup using the custom search function passed to this method.
  1104. * The function should accept a single {@link Ext.Window} reference as its only argument and should
  1105. * return true if the window matches the search criteria, otherwise it should return false.
  1106. * @param {Function} fn The search function
  1107. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Window being tested.
  1108. * that gets passed to the function if not specified)
  1109. * @return {Array} An array of zero or more matching windows
  1110. */
  1111. getBy : function(fn, scope){
  1112. var r = [];
  1113. for(var i = accessList.length-1; i >=0; --i) {
  1114. var win = accessList[i];
  1115. if(fn.call(scope||win, win) !== false){
  1116. r.push(win);
  1117. }
  1118. }
  1119. return r;
  1120. },
  1121. /**
  1122. * Executes the specified function once for every window in this WindowGroup, passing each
  1123. * window as the only parameter. Returning false from the function will stop the iteration.
  1124. * @param {Function} fn The function to execute for each item
  1125. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Window in the iteration.
  1126. */
  1127. each : function(fn, scope){
  1128. for(var id in list){
  1129. if(list[id] && typeof list[id] != "function"){
  1130. if(fn.call(scope || list[id], list[id]) === false){
  1131. return;
  1132. }
  1133. }
  1134. }
  1135. }
  1136. };
  1137. };
  1138. /**
  1139. * @class Ext.WindowMgr
  1140. * @extends Ext.WindowGroup
  1141. * The default global window group that is available automatically. To have more than one group of windows
  1142. * with separate z-order stacks, create additional instances of {@link Ext.WindowGroup} as needed.
  1143. * @singleton
  1144. */
  1145. Ext.WindowMgr = new Ext.WindowGroup();/**
  1146. * @class Ext.MessageBox
  1147. * <p>Utility class for generating different styles of message boxes. The alias Ext.Msg can also be used.<p/>
  1148. * <p>Note that the MessageBox is asynchronous. Unlike a regular JavaScript <code>alert</code> (which will halt
  1149. * browser execution), showing a MessageBox will not cause the code to stop. For this reason, if you have code
  1150. * that should only run <em>after</em> some user feedback from the MessageBox, you must use a callback function
  1151. * (see the <code>function</code> parameter for {@link #show} for more details).</p>
  1152. * <p>Example usage:</p>
  1153. *<pre><code>
  1154. // Basic alert:
  1155. Ext.Msg.alert('Status', 'Changes saved successfully.');
  1156. // Prompt for user data and process the result using a callback:
  1157. Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
  1158. if (btn == 'ok'){
  1159. // process text value and close...
  1160. }
  1161. });
  1162. // Show a dialog using config options:
  1163. Ext.Msg.show({
  1164. title:'Save Changes?',
  1165. msg: 'You are closing a tab that has unsaved changes. Would you like to save your changes?',
  1166. buttons: Ext.Msg.YESNOCANCEL,
  1167. fn: processResult,
  1168. animEl: 'elId',
  1169. icon: Ext.MessageBox.QUESTION
  1170. });
  1171. </code></pre>
  1172. * @singleton
  1173. */
  1174. Ext.MessageBox = function(){
  1175. var dlg, opt, mask, waitTimer,
  1176. bodyEl, msgEl, textboxEl, textareaEl, progressBar, pp, iconEl, spacerEl,
  1177. buttons, activeTextEl, bwidth, bufferIcon = '', iconCls = '',
  1178. buttonNames = ['ok', 'yes', 'no', 'cancel'];
  1179. // private
  1180. var handleButton = function(button){
  1181. buttons[button].blur();
  1182. if(dlg.isVisible()){
  1183. dlg.hide();
  1184. handleHide();
  1185. Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value, opt], 1);
  1186. }
  1187. };
  1188. // private
  1189. var handleHide = function(){
  1190. if(opt && opt.cls){
  1191. dlg.el.removeClass(opt.cls);
  1192. }
  1193. progressBar.reset();
  1194. };
  1195. // private
  1196. var handleEsc = function(d, k, e){
  1197. if(opt && opt.closable !== false){
  1198. dlg.hide();
  1199. handleHide();
  1200. }
  1201. if(e){
  1202. e.stopEvent();
  1203. }
  1204. };
  1205. // private
  1206. var updateButtons = function(b){
  1207. var width = 0,
  1208. cfg;
  1209. if(!b){
  1210. Ext.each(buttonNames, function(name){
  1211. buttons[name].hide();
  1212. });
  1213. return width;
  1214. }
  1215. dlg.footer.dom.style.display = '';
  1216. Ext.iterate(buttons, function(name, btn){
  1217. cfg = b[name];
  1218. if(cfg){
  1219. btn.show();
  1220. btn.setText(Ext.isString(cfg) ? cfg : Ext.MessageBox.buttonText[name]);
  1221. width += btn.getEl().getWidth() + 15;
  1222. }else{
  1223. btn.hide();
  1224. }
  1225. });
  1226. return width;
  1227. };
  1228. return {
  1229. /**
  1230. * Returns a reference to the underlying {@link Ext.Window} element
  1231. * @return {Ext.Window} The window
  1232. */
  1233. getDialog : function(titleText){
  1234. if(!dlg){
  1235. var btns = [];
  1236. buttons = {};
  1237. Ext.each(buttonNames, function(name){
  1238. btns.push(buttons[name] = new Ext.Button({
  1239. text: this.buttonText[name],
  1240. handler: handleButton.createCallback(name),
  1241. hideMode: 'offsets'
  1242. }));
  1243. }, this);
  1244. dlg = new Ext.Window({
  1245. autoCreate : true,
  1246. title:titleText,
  1247. resizable:false,
  1248. constrain:true,
  1249. constrainHeader:true,
  1250. minimizable : false,
  1251. maximizable : false,
  1252. stateful: false,
  1253. modal: true,
  1254. shim:true,
  1255. buttonAlign:"center",
  1256. width:400,
  1257. height:100,
  1258. minHeight: 80,
  1259. plain:true,
  1260. footer:true,
  1261. closable:true,
  1262. close : function(){
  1263. if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
  1264. handleButton("no");
  1265. }else{
  1266. handleButton("cancel");
  1267. }
  1268. },
  1269. fbar: new Ext.Toolbar({
  1270. items: btns,
  1271. enableOverflow: false
  1272. })
  1273. });
  1274. dlg.render(document.body);
  1275. dlg.getEl().addClass('x-window-dlg');
  1276. mask = dlg.mask;
  1277. bodyEl = dlg.body.createChild({
  1278. html:'<div class="ext-mb-icon"></div><div class="ext-mb-content"><span class="ext-mb-text"></span><br /><div class="ext-mb-fix-cursor"><input type="text" class="ext-mb-input" /><textarea class="ext-mb-textarea"></textarea></div></div>'
  1279. });
  1280. iconEl = Ext.get(bodyEl.dom.firstChild);
  1281. var contentEl = bodyEl.dom.childNodes[1];
  1282. msgEl = Ext.get(contentEl.firstChild);
  1283. textboxEl = Ext.get(contentEl.childNodes[2].firstChild);
  1284. textboxEl.enableDisplayMode();
  1285. textboxEl.addKeyListener([10,13], function(){
  1286. if(dlg.isVisible() && opt && opt.buttons){
  1287. if(opt.buttons.ok){
  1288. handleButton("ok");
  1289. }else if(opt.buttons.yes){
  1290. handleButton("yes");
  1291. }
  1292. }
  1293. });
  1294. textareaEl = Ext.get(contentEl.childNodes[2].childNodes[1]);
  1295. textareaEl.enableDisplayMode();
  1296. progressBar = new Ext.ProgressBar({
  1297. renderTo:bodyEl
  1298. });
  1299. bodyEl.createChild({cls:'x-clear'});
  1300. }
  1301. return dlg;
  1302. },
  1303. /**
  1304. * Updates the message box body text
  1305. * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
  1306. * the XHTML-compliant non-breaking space character '&amp;#160;')
  1307. * @return {Ext.MessageBox} this
  1308. */
  1309. updateText : function(text){
  1310. if(!dlg.isVisible() && !opt.width){
  1311. dlg.setSize(this.maxWidth, 100); // resize first so content is never clipped from previous shows
  1312. }
  1313. // Append a space here for sizing. In IE, for some reason, it wraps text incorrectly without one in some cases
  1314. msgEl.update(text ? text + ' ' : '&#160;');
  1315. var iw = iconCls != '' ? (iconEl.getWidth() + iconEl.getMargins('lr')) : 0,
  1316. mw = msgEl.getWidth() + msgEl.getMargins('lr'),
  1317. fw = dlg.getFrameWidth('lr'),
  1318. bw = dlg.body.getFrameWidth('lr'),
  1319. w;
  1320. w = Math.max(Math.min(opt.width || iw+mw+fw+bw, opt.maxWidth || this.maxWidth),
  1321. Math.max(opt.minWidth || this.minWidth, bwidth || 0));
  1322. if(opt.prompt === true){
  1323. activeTextEl.setWidth(w-iw-fw-bw);
  1324. }
  1325. if(opt.progress === true || opt.wait === true){
  1326. progressBar.setSize(w-iw-fw-bw);
  1327. }
  1328. if(Ext.isIE && w == bwidth){
  1329. w += 4; //Add offset when the content width is smaller than the buttons.
  1330. }
  1331. msgEl.update(text || '&#160;');
  1332. dlg.setSize(w, 'auto').center();
  1333. return this;
  1334. },
  1335. /**
  1336. * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
  1337. * initiated via {@link Ext.MessageBox#progress} or {@link Ext.MessageBox#wait},
  1338. * or by calling {@link Ext.MessageBox#show} with progress: true.
  1339. * @param {Number} value Any number between 0 and 1 (e.g., .5, defaults to 0)
  1340. * @param {String} progressText The progress text to display inside the progress bar (defaults to '')
  1341. * @param {String} msg The message box's body text is replaced with the specified string (defaults to undefined
  1342. * so that any existing body text will not get overwritten by default unless a new value is passed in)
  1343. * @return {Ext.MessageBox} this
  1344. */
  1345. updateProgress : function(value, progressText, msg){
  1346. progressBar.updateProgress(value, progressText);
  1347. if(msg){
  1348. this.updateText(msg);
  1349. }
  1350. return this;
  1351. },
  1352. /**
  1353. * Returns true if the message box is currently displayed
  1354. * @return {Boolean} True if the message box is visible, else false
  1355. */
  1356. isVisible : function(){
  1357. return dlg && dlg.isVisible();
  1358. },
  1359. /**
  1360. * Hides the message box if it is displayed
  1361. * @return {Ext.MessageBox} this
  1362. */
  1363. hide : function(){
  1364. var proxy = dlg ? dlg.activeGhost : null;
  1365. if(this.isVisible() || proxy){
  1366. dlg.hide();
  1367. handleHide();
  1368. if (proxy){
  1369. // unghost is a private function, but i saw no better solution
  1370. // to fix the locking problem when dragging while it closes
  1371. dlg.unghost(false, false);
  1372. }
  1373. }
  1374. return this;
  1375. },
  1376. /**
  1377. * Displays a new message box, or reinitializes an existing message box, based on the config options
  1378. * passed in. All display functions (e.g. prompt, alert, etc.) on MessageBox call this function internally,
  1379. * although those calls are basic shortcuts and do not support all of the config options allowed here.
  1380. * @param {Object} config The following config options are supported: <ul>
  1381. * <li><b>animEl</b> : String/Element<div class="sub-desc">An id or Element from which the message box should animate as it
  1382. * opens and closes (defaults to undefined)</div></li>
  1383. * <li><b>buttons</b> : Object/Boolean<div class="sub-desc">A button config object (e.g., Ext.MessageBox.OKCANCEL or {ok:'Foo',
  1384. * cancel:'Bar'}), or false to not show any buttons (defaults to false)</div></li>
  1385. * <li><b>closable</b> : Boolean<div class="sub-desc">False to hide the top-right close button (defaults to true). Note that
  1386. * progress and wait dialogs will ignore this property and always hide the close button as they can only
  1387. * be closed programmatically.</div></li>
  1388. * <li><b>cls</b> : String<div class="sub-desc">A custom CSS class to apply to the message box's container element</div></li>
  1389. * <li><b>defaultTextHeight</b> : Number<div class="sub-desc">The default height in pixels of the message box's multiline textarea
  1390. * if displayed (defaults to 75)</div></li>
  1391. * <li><b>fn</b> : Function<div class="sub-desc">A callback function which is called when the dialog is dismissed either
  1392. * by clicking on the configured buttons, or on the dialog close button, or by pressing
  1393. * the return button to enter input.
  1394. * <p>Progress and wait dialogs will ignore this option since they do not respond to user
  1395. * actions and can only be closed programmatically, so any required function should be called
  1396. * by the same code after it closes the dialog. Parameters passed:<ul>
  1397. * <li><b>buttonId</b> : String<div class="sub-desc">The ID of the button pressed, one of:<div class="sub-desc"><ul>
  1398. * <li><tt>ok</tt></li>
  1399. * <li><tt>yes</tt></li>
  1400. * <li><tt>no</tt></li>
  1401. * <li><tt>cancel</tt></li>
  1402. * </ul></div></div></li>
  1403. * <li><b>text</b> : String<div class="sub-desc">Value of the input field if either <tt><a href="#show-option-prompt" ext:member="show-option-prompt" ext:cls="Ext.MessageBox">prompt</a></tt>
  1404. * or <tt><a href="#show-option-multiline" ext:member="show-option-multiline" ext:cls="Ext.MessageBox">multiline</a></tt> is true</div></li>
  1405. * <li><b>opt</b> : Object<div class="sub-desc">The config object passed to show.</div></li>
  1406. * </ul></p></div></li>
  1407. * <li><b>scope</b> : Object<div class="sub-desc">The scope of the callback function</div></li>
  1408. * <li><b>icon</b> : String<div class="sub-desc">A CSS class that provides a background image to be used as the body icon for the
  1409. * dialog (e.g. Ext.MessageBox.WARNING or 'custom-class') (defaults to '')</div></li>
  1410. * <li><b>iconCls</b> : String<div class="sub-desc">The standard {@link Ext.Window#iconCls} to
  1411. * add an optional header icon (defaults to '')</div></li>
  1412. * <li><b>maxWidth</b> : Number<div class="sub-desc">The maximum width in pixels of the message box (defaults to 600)</div></li>
  1413. * <li><b>minWidth</b> : Number<div class="sub-desc">The minimum width in pixels of the message box (defaults to 100)</div></li>
  1414. * <li><b>modal</b> : Boolean<div class="sub-desc">False to allow user interaction with the page while the message box is
  1415. * displayed (defaults to true)</div></li>
  1416. * <li><b>msg</b> : String<div class="sub-desc">A string that will replace the existing message box body text (defaults to the
  1417. * XHTML-compliant non-breaking space character '&amp;#160;')</div></li>
  1418. * <li><a id="show-option-multiline"></a><b>multiline</b> : Boolean<div class="sub-desc">
  1419. * True to prompt the user to enter multi-line text (defaults to false)</div></li>
  1420. * <li><b>progress</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
  1421. * <li><b>progressText</b> : String<div class="sub-desc">The text to display inside the progress bar if progress = true (defaults to '')</div></li>
  1422. * <li><a id="show-option-prompt"></a><b>prompt</b> : Boolean<div class="sub-desc">True to prompt the user to enter single-line text (defaults to false)</div></li>
  1423. * <li><b>proxyDrag</b> : Boolean<div class="sub-desc">True to display a lightweight proxy while dragging (defaults to false)</div></li>
  1424. * <li><b>title</b> : String<div class="sub-desc">The title text</div></li>
  1425. * <li><b>value</b> : String<div class="sub-desc">The string value to set into the active textbox element if displayed</div></li>
  1426. * <li><b>wait</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
  1427. * <li><b>waitConfig</b> : Object<div class="sub-desc">A {@link Ext.ProgressBar#waitConfig} object (applies only if wait = true)</div></li>
  1428. * <li><b>width</b> : Number<div class="sub-desc">The width of the dialog in pixels</div></li>
  1429. * </ul>
  1430. * Example usage:
  1431. * <pre><code>
  1432. Ext.Msg.show({
  1433. title: 'Address',
  1434. msg: 'Please enter your address:',
  1435. width: 300,
  1436. buttons: Ext.MessageBox.OKCANCEL,
  1437. multiline: true,
  1438. fn: saveAddress,
  1439. animEl: 'addAddressBtn',
  1440. icon: Ext.MessageBox.INFO
  1441. });
  1442. </code></pre>
  1443. * @return {Ext.MessageBox} this
  1444. */
  1445. show : function(options){
  1446. if(this.isVisible()){
  1447. this.hide();
  1448. }
  1449. opt = options;
  1450. var d = this.getDialog(opt.title || "&#160;");
  1451. d.setTitle(opt.title || "&#160;");
  1452. var allowClose = (opt.closable !== false && opt.progress !== true && opt.wait !== true);
  1453. d.tools.close.setDisplayed(allowClose);
  1454. activeTextEl = textboxEl;
  1455. opt.prompt = opt.prompt || (opt.multiline ? true : false);
  1456. if(opt.prompt){
  1457. if(opt.multiline){
  1458. textboxEl.hide();
  1459. textareaEl.show();
  1460. textareaEl.setHeight(Ext.isNumber(opt.multiline) ? opt.multiline : this.defaultTextHeight);
  1461. activeTextEl = textareaEl;
  1462. }else{
  1463. textboxEl.show();
  1464. textareaEl.hide();
  1465. }
  1466. }else{
  1467. textboxEl.hide();
  1468. textareaEl.hide();
  1469. }
  1470. activeTextEl.dom.value = opt.value || "";
  1471. if(opt.prompt){
  1472. d.focusEl = activeTextEl;
  1473. }else{
  1474. var bs = opt.buttons;
  1475. var db = null;
  1476. if(bs && bs.ok){
  1477. db = buttons["ok"];
  1478. }else if(bs && bs.yes){
  1479. db = buttons["yes"];
  1480. }
  1481. if (db){
  1482. d.focusEl = db;
  1483. }
  1484. }
  1485. if(Ext.isDefined(opt.iconCls)){
  1486. d.setIconClass(opt.iconCls);
  1487. }
  1488. this.setIcon(Ext.isDefined(opt.icon) ? opt.icon : bufferIcon);
  1489. bwidth = updateButtons(opt.buttons);
  1490. progressBar.setVisible(opt.progress === true || opt.wait === true);
  1491. this.updateProgress(0, opt.progressText);
  1492. this.updateText(opt.msg);
  1493. if(opt.cls){
  1494. d.el.addClass(opt.cls);
  1495. }
  1496. d.proxyDrag = opt.proxyDrag === true;
  1497. d.modal = opt.modal !== false;
  1498. d.mask = opt.modal !== false ? mask : false;
  1499. if(!d.isVisible()){
  1500. // force it to the end of the z-index stack so it gets a cursor in FF
  1501. document.body.appendChild(dlg.el.dom);
  1502. d.setAnimateTarget(opt.animEl);
  1503. //workaround for window internally enabling keymap in afterShow
  1504. d.on('show', function(){
  1505. if(allowClose === true){
  1506. d.keyMap.enable();
  1507. }else{
  1508. d.keyMap.disable();
  1509. }
  1510. }, this, {single:true});
  1511. d.show(opt.animEl);
  1512. }
  1513. if(opt.wait === true){
  1514. progressBar.wait(opt.waitConfig);
  1515. }
  1516. return this;
  1517. },
  1518. /**
  1519. * Adds the specified icon to the dialog. By default, the class 'ext-mb-icon' is applied for default
  1520. * styling, and the class passed in is expected to supply the background image url. Pass in empty string ('')
  1521. * to clear any existing icon. This method must be called before the MessageBox is shown.
  1522. * The following built-in icon classes are supported, but you can also pass in a custom class name:
  1523. * <pre>
  1524. Ext.MessageBox.INFO
  1525. Ext.MessageBox.WARNING
  1526. Ext.MessageBox.QUESTION
  1527. Ext.MessageBox.ERROR
  1528. *</pre>
  1529. * @param {String} icon A CSS classname specifying the icon's background image url, or empty string to clear the icon
  1530. * @return {Ext.MessageBox} this
  1531. */
  1532. setIcon : function(icon){
  1533. if(!dlg){
  1534. bufferIcon = icon;
  1535. return;
  1536. }
  1537. bufferIcon = undefined;
  1538. if(icon && icon != ''){
  1539. iconEl.removeClass('x-hidden');
  1540. iconEl.replaceClass(iconCls, icon);
  1541. bodyEl.addClass('x-dlg-icon');
  1542. iconCls = icon;
  1543. }else{
  1544. iconEl.replaceClass(iconCls, 'x-hidden');
  1545. bodyEl.removeClass('x-dlg-icon');
  1546. iconCls = '';
  1547. }
  1548. return this;
  1549. },
  1550. /**
  1551. * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
  1552. * the user. You are responsible for updating the progress bar as needed via {@link Ext.MessageBox#updateProgress}
  1553. * and closing the message box when the process is complete.
  1554. * @param {String} title The title bar text
  1555. * @param {String} msg The message box body text
  1556. * @param {String} progressText (optional) The text to display inside the progress bar (defaults to '')
  1557. * @return {Ext.MessageBox} this
  1558. */
  1559. progress : function(title, msg, progressText){
  1560. this.show({
  1561. title : title,
  1562. msg : msg,
  1563. buttons: false,
  1564. progress:true,
  1565. closable:false,
  1566. minWidth: this.minProgressWidth,
  1567. progressText: progressText
  1568. });
  1569. return this;
  1570. },
  1571. /**
  1572. * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
  1573. * interaction while waiting for a long-running process to complete that does not have defined intervals.
  1574. * You are responsible for closing the message box when the process is complete.
  1575. * @param {String} msg The message box body text
  1576. * @param {String} title (optional) The title bar text
  1577. * @param {Object} config (optional) A {@link Ext.ProgressBar#waitConfig} object
  1578. * @return {Ext.MessageBox} this
  1579. */
  1580. wait : function(msg, title, config){
  1581. this.show({
  1582. title : title,
  1583. msg : msg,
  1584. buttons: false,
  1585. closable:false,
  1586. wait:true,
  1587. modal:true,
  1588. minWidth: this.minProgressWidth,
  1589. waitConfig: config
  1590. });
  1591. return this;
  1592. },
  1593. /**
  1594. * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).
  1595. * If a callback function is passed it will be called after the user clicks the button, and the
  1596. * id of the button that was clicked will be passed as the only parameter to the callback
  1597. * (could also be the top-right close button).
  1598. * @param {String} title The title bar text
  1599. * @param {String} msg The message box body text
  1600. * @param {Function} fn (optional) The callback function invoked after the message box is closed
  1601. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
  1602. * @return {Ext.MessageBox} this
  1603. */
  1604. alert : function(title, msg, fn, scope){
  1605. this.show({
  1606. title : title,
  1607. msg : msg,
  1608. buttons: this.OK,
  1609. fn: fn,
  1610. scope : scope,
  1611. minWidth: this.minWidth
  1612. });
  1613. return this;
  1614. },
  1615. /**
  1616. * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).
  1617. * If a callback function is passed it will be called after the user clicks either button,
  1618. * and the id of the button that was clicked will be passed as the only parameter to the callback
  1619. * (could also be the top-right close button).
  1620. * @param {String} title The title bar text
  1621. * @param {String} msg The message box body text
  1622. * @param {Function} fn (optional) The callback function invoked after the message box is closed
  1623. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
  1624. * @return {Ext.MessageBox} this
  1625. */
  1626. confirm : function(title, msg, fn, scope){
  1627. this.show({
  1628. title : title,
  1629. msg : msg,
  1630. buttons: this.YESNO,
  1631. fn: fn,
  1632. scope : scope,
  1633. icon: this.QUESTION,
  1634. minWidth: this.minWidth
  1635. });
  1636. return this;
  1637. },
  1638. /**
  1639. * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
  1640. * The prompt can be a single-line or multi-line textbox. If a callback function is passed it will be called after the user
  1641. * clicks either button, and the id of the button that was clicked (could also be the top-right
  1642. * close button) and the text that was entered will be passed as the two parameters to the callback.
  1643. * @param {String} title The title bar text
  1644. * @param {String} msg The message box body text
  1645. * @param {Function} fn (optional) The callback function invoked after the message box is closed
  1646. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
  1647. * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
  1648. * property, or the height in pixels to create the textbox (defaults to false / single-line)
  1649. * @param {String} value (optional) Default value of the text input element (defaults to '')
  1650. * @return {Ext.MessageBox} this
  1651. */
  1652. prompt : function(title, msg, fn, scope, multiline, value){
  1653. this.show({
  1654. title : title,
  1655. msg : msg,
  1656. buttons: this.OKCANCEL,
  1657. fn: fn,
  1658. minWidth: this.minPromptWidth,
  1659. scope : scope,
  1660. prompt:true,
  1661. multiline: multiline,
  1662. value: value
  1663. });
  1664. return this;
  1665. },
  1666. /**
  1667. * Button config that displays a single OK button
  1668. * @type Object
  1669. */
  1670. OK : {ok:true},
  1671. /**
  1672. * Button config that displays a single Cancel button
  1673. * @type Object
  1674. */
  1675. CANCEL : {cancel:true},
  1676. /**
  1677. * Button config that displays OK and Cancel buttons
  1678. * @type Object
  1679. */
  1680. OKCANCEL : {ok:true, cancel:true},
  1681. /**
  1682. * Button config that displays Yes and No buttons
  1683. * @type Object
  1684. */
  1685. YESNO : {yes:true, no:true},
  1686. /**
  1687. * Button config that displays Yes, No and Cancel buttons
  1688. * @type Object
  1689. */
  1690. YESNOCANCEL : {yes:true, no:true, cancel:true},
  1691. /**
  1692. * The CSS class that provides the INFO icon image
  1693. * @type String
  1694. */
  1695. INFO : 'ext-mb-info',
  1696. /**
  1697. * The CSS class that provides the WARNING icon image
  1698. * @type String
  1699. */
  1700. WARNING : 'ext-mb-warning',
  1701. /**
  1702. * The CSS class that provides the QUESTION icon image
  1703. * @type String
  1704. */
  1705. QUESTION : 'ext-mb-question',
  1706. /**
  1707. * The CSS class that provides the ERROR icon image
  1708. * @type String
  1709. */
  1710. ERROR : 'ext-mb-error',
  1711. /**
  1712. * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
  1713. * @type Number
  1714. */
  1715. defaultTextHeight : 75,
  1716. /**
  1717. * The maximum width in pixels of the message box (defaults to 600)
  1718. * @type Number
  1719. */
  1720. maxWidth : 600,
  1721. /**
  1722. * The minimum width in pixels of the message box (defaults to 100)
  1723. * @type Number
  1724. */
  1725. minWidth : 100,
  1726. /**
  1727. * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
  1728. * for setting a different minimum width than text-only dialogs may need (defaults to 250).
  1729. * @type Number
  1730. */
  1731. minProgressWidth : 250,
  1732. /**
  1733. * The minimum width in pixels of the message box if it is a prompt dialog. This is useful
  1734. * for setting a different minimum width than text-only dialogs may need (defaults to 250).
  1735. * @type Number
  1736. */
  1737. minPromptWidth: 250,
  1738. /**
  1739. * An object containing the default button text strings that can be overriden for localized language support.
  1740. * Supported properties are: ok, cancel, yes and no. Generally you should include a locale-specific
  1741. * resource file for handling language support across the framework.
  1742. * Customize the default text like so: Ext.MessageBox.buttonText.yes = "oui"; //french
  1743. * @type Object
  1744. */
  1745. buttonText : {
  1746. ok : "OK",
  1747. cancel : "Cancel",
  1748. yes : "Yes",
  1749. no : "No"
  1750. }
  1751. };
  1752. }();
  1753. /**
  1754. * Shorthand for {@link Ext.MessageBox}
  1755. */
  1756. Ext.Msg = Ext.MessageBox;/**
  1757. * @class Ext.dd.PanelProxy
  1758. * A custom drag proxy implementation specific to {@link Ext.Panel}s. This class is primarily used internally
  1759. * for the Panel's drag drop implementation, and should never need to be created directly.
  1760. * @constructor
  1761. * @param panel The {@link Ext.Panel} to proxy for
  1762. * @param config Configuration options
  1763. */
  1764. Ext.dd.PanelProxy = Ext.extend(Object, {
  1765. constructor : function(panel, config){
  1766. this.panel = panel;
  1767. this.id = this.panel.id +'-ddproxy';
  1768. Ext.apply(this, config);
  1769. },
  1770. /**
  1771. * @cfg {Boolean} insertProxy True to insert a placeholder proxy element while dragging the panel,
  1772. * false to drag with no proxy (defaults to true).
  1773. */
  1774. insertProxy : true,
  1775. // private overrides
  1776. setStatus : Ext.emptyFn,
  1777. reset : Ext.emptyFn,
  1778. update : Ext.emptyFn,
  1779. stop : Ext.emptyFn,
  1780. sync: Ext.emptyFn,
  1781. /**
  1782. * Gets the proxy's element
  1783. * @return {Element} The proxy's element
  1784. */
  1785. getEl : function(){
  1786. return this.ghost;
  1787. },
  1788. /**
  1789. * Gets the proxy's ghost element
  1790. * @return {Element} The proxy's ghost element
  1791. */
  1792. getGhost : function(){
  1793. return this.ghost;
  1794. },
  1795. /**
  1796. * Gets the proxy's element
  1797. * @return {Element} The proxy's element
  1798. */
  1799. getProxy : function(){
  1800. return this.proxy;
  1801. },
  1802. /**
  1803. * Hides the proxy
  1804. */
  1805. hide : function(){
  1806. if(this.ghost){
  1807. if(this.proxy){
  1808. this.proxy.remove();
  1809. delete this.proxy;
  1810. }
  1811. this.panel.el.dom.style.display = '';
  1812. this.ghost.remove();
  1813. delete this.ghost;
  1814. }
  1815. },
  1816. /**
  1817. * Shows the proxy
  1818. */
  1819. show : function(){
  1820. if(!this.ghost){
  1821. this.ghost = this.panel.createGhost(this.panel.initialConfig.cls, undefined, Ext.getBody());
  1822. this.ghost.setXY(this.panel.el.getXY());
  1823. if(this.insertProxy){
  1824. this.proxy = this.panel.el.insertSibling({cls:'x-panel-dd-spacer'});
  1825. this.proxy.setSize(this.panel.getSize());
  1826. }
  1827. this.panel.el.dom.style.display = 'none';
  1828. }
  1829. },
  1830. // private
  1831. repair : function(xy, callback, scope){
  1832. this.hide();
  1833. if(typeof callback == "function"){
  1834. callback.call(scope || this);
  1835. }
  1836. },
  1837. /**
  1838. * Moves the proxy to a different position in the DOM. This is typically called while dragging the Panel
  1839. * to keep the proxy sync'd to the Panel's location.
  1840. * @param {HTMLElement} parentNode The proxy's parent DOM node
  1841. * @param {HTMLElement} before (optional) The sibling node before which the proxy should be inserted (defaults
  1842. * to the parent's last child if not specified)
  1843. */
  1844. moveProxy : function(parentNode, before){
  1845. if(this.proxy){
  1846. parentNode.insertBefore(this.proxy.dom, before);
  1847. }
  1848. }
  1849. });
  1850. // private - DD implementation for Panels
  1851. Ext.Panel.DD = Ext.extend(Ext.dd.DragSource, {
  1852. constructor : function(panel, cfg){
  1853. this.panel = panel;
  1854. this.dragData = {panel: panel};
  1855. this.proxy = new Ext.dd.PanelProxy(panel, cfg);
  1856. Ext.Panel.DD.superclass.constructor.call(this, panel.el, cfg);
  1857. var h = panel.header,
  1858. el = panel.body;
  1859. if(h){
  1860. this.setHandleElId(h.id);
  1861. el = panel.header;
  1862. }
  1863. el.setStyle('cursor', 'move');
  1864. this.scroll = false;
  1865. },
  1866. showFrame: Ext.emptyFn,
  1867. startDrag: Ext.emptyFn,
  1868. b4StartDrag: function(x, y) {
  1869. this.proxy.show();
  1870. },
  1871. b4MouseDown: function(e) {
  1872. var x = e.getPageX(),
  1873. y = e.getPageY();
  1874. this.autoOffset(x, y);
  1875. },
  1876. onInitDrag : function(x, y){
  1877. this.onStartDrag(x, y);
  1878. return true;
  1879. },
  1880. createFrame : Ext.emptyFn,
  1881. getDragEl : function(e){
  1882. return this.proxy.ghost.dom;
  1883. },
  1884. endDrag : function(e){
  1885. this.proxy.hide();
  1886. this.panel.saveState();
  1887. },
  1888. autoOffset : function(x, y) {
  1889. x -= this.startPageX;
  1890. y -= this.startPageY;
  1891. this.setDelta(x, y);
  1892. }
  1893. });