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.

2040 lines
75 KiB

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