4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.BasicDialog
14 * @extends Roo.util.Observable
15 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
17 var dlg = new Roo.BasicDialog("my-dlg", {
26 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
27 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
28 dlg.addButton('Cancel', dlg.hide, dlg);
31 <b>A Dialog should always be a direct child of the body element.</b>
32 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
33 * @cfg {String} title Default text to display in the title bar (defaults to null)
34 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
35 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
36 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
37 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
38 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
39 * (defaults to null with no animation)
40 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
41 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
42 * property for valid values (defaults to 'all')
43 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
44 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
45 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
46 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
47 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
48 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
49 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
50 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
51 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
52 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
53 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
54 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
55 * draggable = true (defaults to false)
56 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
57 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
58 * shadow (defaults to false)
59 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
60 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
61 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
62 * @cfg {Array} buttons Array of buttons
63 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
65 * Create a new BasicDialog.
66 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
67 * @param {Object} config Configuration options
69 Roo.BasicDialog = function(el, config){
70 this.el = Roo.get(el);
71 var dh = Roo.DomHelper;
72 if(!this.el && config && config.autoCreate){
73 if(typeof config.autoCreate == "object"){
74 if(!config.autoCreate.id){
75 config.autoCreate.id = el;
77 this.el = dh.append(document.body,
78 config.autoCreate, true);
80 this.el = dh.append(document.body,
81 {tag: "div", id: el, style:'visibility:hidden;'}, true);
85 el.setDisplayed(true);
86 el.hide = this.hideAction;
90 Roo.apply(this, config);
92 this.proxy = el.createProxy("x-dlg-proxy");
93 this.proxy.hide = this.hideAction;
94 this.proxy.setOpacity(.5);
98 el.setWidth(config.width);
101 el.setHeight(config.height);
103 this.size = el.getSize();
104 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
105 this.xy = [config.x,config.y];
107 this.xy = el.getCenterXY(true);
109 /** The header element @type Roo.Element */
110 this.header = el.child("> .x-dlg-hd");
111 /** The body element @type Roo.Element */
112 this.body = el.child("> .x-dlg-bd");
113 /** The footer element @type Roo.Element */
114 this.footer = el.child("> .x-dlg-ft");
117 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
120 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
123 this.header.unselectable();
125 this.header.update(this.title);
127 // this element allows the dialog to be focused for keyboard event
128 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
129 this.focusEl.swallowEvent("click", true);
131 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
133 // wrap the body and footer for special rendering
134 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
136 this.bwrap.dom.appendChild(this.footer.dom);
139 this.bg = this.el.createChild({
140 tag: "div", cls:"x-dlg-bg",
141 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
143 this.centerBg = this.bg.child("div.x-dlg-bg-center");
146 if(this.autoScroll !== false && !this.autoTabs){
147 this.body.setStyle("overflow", "auto");
150 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
152 if(this.closable !== false){
153 this.el.addClass("x-dlg-closable");
154 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
155 this.close.on("click", this.closeClick, this);
156 this.close.addClassOnOver("x-dlg-close-over");
158 if(this.collapsible !== false){
159 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
160 this.collapseBtn.on("click", this.collapseClick, this);
161 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
162 this.header.on("dblclick", this.collapseClick, this);
164 if(this.resizable !== false){
165 this.el.addClass("x-dlg-resizable");
166 this.resizer = new Roo.Resizable(el, {
167 minWidth: this.minWidth || 80,
168 minHeight:this.minHeight || 80,
169 handles: this.resizeHandles || "all",
172 this.resizer.on("beforeresize", this.beforeResize, this);
173 this.resizer.on("resize", this.onResize, this);
175 if(this.draggable !== false){
176 el.addClass("x-dlg-draggable");
177 if (!this.proxyDrag) {
178 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
181 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
183 dd.setHandleElId(this.header.id);
184 dd.endDrag = this.endMove.createDelegate(this);
185 dd.startDrag = this.startMove.createDelegate(this);
186 dd.onDrag = this.onDrag.createDelegate(this);
191 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
192 this.mask.enableDisplayMode("block");
194 this.el.addClass("x-dlg-modal");
197 this.shadow = new Roo.Shadow({
198 mode : typeof this.shadow == "string" ? this.shadow : "sides",
199 offset : this.shadowOffset
202 this.shadowOffset = 0;
204 if(Roo.useShims && this.shim !== false){
205 this.shim = this.el.createShim();
206 this.shim.hide = this.hideAction;
215 var bts= this.buttons;
217 Roo.each(bts, function(b) {
226 * Fires when a key is pressed
227 * @param {Roo.BasicDialog} this
228 * @param {Roo.EventObject} e
233 * Fires when this dialog is moved by the user.
234 * @param {Roo.BasicDialog} this
235 * @param {Number} x The new page X
236 * @param {Number} y The new page Y
241 * Fires when this dialog is resized by the user.
242 * @param {Roo.BasicDialog} this
243 * @param {Number} width The new width
244 * @param {Number} height The new height
249 * Fires before this dialog is hidden.
250 * @param {Roo.BasicDialog} this
255 * Fires when this dialog is hidden.
256 * @param {Roo.BasicDialog} this
261 * Fires before this dialog is shown.
262 * @param {Roo.BasicDialog} this
267 * Fires when this dialog is shown.
268 * @param {Roo.BasicDialog} this
272 el.on("keydown", this.onKeyDown, this);
273 el.on("mousedown", this.toFront, this);
274 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
276 Roo.DialogManager.register(this);
277 Roo.BasicDialog.superclass.constructor.call(this);
280 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
281 shadowOffset: Roo.isIE ? 6 : 5,
286 buttonAlign: "right",
291 * Sets the dialog title text
292 * @param {String} text The title text to display
293 * @return {Roo.BasicDialog} this
295 setTitle : function(text){
296 this.header.update(text);
301 closeClick : function(){
306 collapseClick : function(){
307 this[this.collapsed ? "expand" : "collapse"]();
311 * Collapses the dialog to its minimized state (only the title bar is visible).
312 * Equivalent to the user clicking the collapse dialog button.
314 collapse : function(){
316 this.collapsed = true;
317 this.el.addClass("x-dlg-collapsed");
318 this.restoreHeight = this.el.getHeight();
319 this.resizeTo(this.el.getWidth(), this.header.getHeight());
324 * Expands a collapsed dialog back to its normal state. Equivalent to the user
325 * clicking the expand dialog button.
329 this.collapsed = false;
330 this.el.removeClass("x-dlg-collapsed");
331 this.resizeTo(this.el.getWidth(), this.restoreHeight);
336 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
337 * @return {Roo.TabPanel} The tabs component
339 initTabs : function(){
340 var tabs = this.getTabs();
341 while(tabs.getTab(0)){
344 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
346 tabs.addTab(Roo.id(dom), dom.title);
354 beforeResize : function(){
355 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
359 onResize : function(){
361 this.syncBodyHeight();
364 this.fireEvent("resize", this, this.size.width, this.size.height);
368 onKeyDown : function(e){
369 if(this.isVisible()){
370 this.fireEvent("keydown", this, e);
375 * Resizes the dialog.
376 * @param {Number} width
377 * @param {Number} height
378 * @return {Roo.BasicDialog} this
380 resizeTo : function(width, height){
381 this.el.setSize(width, height);
382 this.size = {width: width, height: height};
383 this.syncBodyHeight();
384 if(this.fixedcenter){
387 if(this.isVisible()){
391 this.fireEvent("resize", this, width, height);
397 * Resizes the dialog to fit the specified content size.
398 * @param {Number} width
399 * @param {Number} height
400 * @return {Roo.BasicDialog} this
402 setContentSize : function(w, h){
403 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
404 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
405 //if(!this.el.isBorderBox()){
406 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
407 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
410 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
411 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
418 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
419 * executed in response to a particular key being pressed while the dialog is active.
420 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
421 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
422 * @param {Function} fn The function to call
423 * @param {Object} scope (optional) The scope of the function
424 * @return {Roo.BasicDialog} this
426 addKeyListener : function(key, fn, scope){
427 var keyCode, shift, ctrl, alt;
428 if(typeof key == "object" && !(key instanceof Array)){
429 keyCode = key["key"];
430 shift = key["shift"];
436 var handler = function(dlg, e){
437 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
439 if(keyCode instanceof Array){
440 for(var i = 0, len = keyCode.length; i < len; i++){
442 fn.call(scope || window, dlg, k, e);
448 fn.call(scope || window, dlg, k, e);
453 this.on("keydown", handler);
458 * Returns the TabPanel component (creates it if it doesn't exist).
459 * Note: If you wish to simply check for the existence of tabs without creating them,
460 * check for a null 'tabs' property.
461 * @return {Roo.TabPanel} The tabs component
463 getTabs : function(){
465 this.el.addClass("x-dlg-auto-tabs");
466 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
467 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
473 * Adds a button to the footer section of the dialog.
474 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
475 * object or a valid Roo.DomHelper element config
476 * @param {Function} handler The function called when the button is clicked
477 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
478 * @return {Roo.Button} The new button
480 addButton : function(config, handler, scope){
481 var dh = Roo.DomHelper;
483 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
485 if(!this.btnContainer){
486 var tb = this.footer.createChild({
488 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
489 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
491 this.btnContainer = tb.firstChild.firstChild.firstChild;
496 minWidth: this.minButtonWidth,
499 if(typeof config == "string"){
500 bconfig.text = config;
503 bconfig.dhconfig = config;
505 Roo.apply(bconfig, config);
509 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
510 bconfig.position = Math.max(0, bconfig.position);
511 fc = this.btnContainer.childNodes[bconfig.position];
514 var btn = new Roo.Button(
516 this.btnContainer.insertBefore(document.createElement("td"),fc)
517 : this.btnContainer.appendChild(document.createElement("td")),
518 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
521 this.syncBodyHeight();
524 * Array of all the buttons that have been added to this dialog via addButton
529 this.buttons.push(btn);
534 * Sets the default button to be focused when the dialog is displayed.
535 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
536 * @return {Roo.BasicDialog} this
538 setDefaultButton : function(btn){
539 this.defaultButton = btn;
544 getHeaderFooterHeight : function(safe){
547 height += this.header.getHeight();
550 var fm = this.footer.getMargins();
551 height += (this.footer.getHeight()+fm.top+fm.bottom);
553 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
554 height += this.centerBg.getPadding("tb");
559 syncBodyHeight : function(){
560 var bd = this.body, cb = this.centerBg, bw = this.bwrap;
561 var height = this.size.height - this.getHeaderFooterHeight(false);
562 bd.setHeight(height-bd.getMargins("tb"));
563 var hh = this.header.getHeight();
564 var h = this.size.height-hh;
566 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
567 bw.setHeight(h-cb.getPadding("tb"));
568 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
569 bd.setWidth(bw.getWidth(true));
571 this.tabs.syncHeight();
573 this.tabs.el.repaint();
579 * Restores the previous state of the dialog if Roo.state is configured.
580 * @return {Roo.BasicDialog} this
582 restoreState : function(){
583 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
584 if(box && box.width){
585 this.xy = [box.x, box.y];
586 this.resizeTo(box.width, box.height);
592 beforeShow : function(){
594 if(this.fixedcenter){
595 this.xy = this.el.getCenterXY(true);
598 Roo.get(document.body).addClass("x-body-masked");
599 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
606 animShow : function(){
607 var b = Roo.get(this.animateTarget).getBox();
608 this.proxy.setSize(b.width, b.height);
609 this.proxy.setLocation(b.x, b.y);
611 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
612 true, .35, this.showEl.createDelegate(this));
617 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
618 * @return {Roo.BasicDialog} this
620 show : function(animateTarget){
621 if (this.fireEvent("beforeshow", this) === false){
624 if(this.syncHeightBeforeShow){
625 this.syncBodyHeight();
626 }else if(this.firstShow){
627 this.firstShow = false;
628 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
630 this.animateTarget = animateTarget || this.animateTarget;
631 if(!this.el.isVisible()){
633 if(this.animateTarget && Roo.get(this.animateTarget)){
645 this.el.setXY(this.xy);
647 this.adjustAssets(true);
650 // IE peekaboo bug - fix found by Dave Fenwick
654 this.fireEvent("show", this);
658 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
659 * dialog itself will receive focus.
662 if(this.defaultButton){
663 this.defaultButton.focus();
665 this.focusEl.focus();
670 constrainXY : function(){
671 if(this.constraintoviewport !== false){
674 var s = this.container.getSize();
675 this.viewSize = [s.width, s.height];
677 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
680 var s = Roo.get(this.container||document).getScroll();
682 var x = this.xy[0], y = this.xy[1];
683 var w = this.size.width, h = this.size.height;
684 var vw = this.viewSize[0], vh = this.viewSize[1];
685 // only move it if it needs it
687 // first validate right/bottom
688 if(x + w > vw+s.left){
692 if(y + h > vh+s.top){
696 // then make sure top/left isn't negative
708 if(this.isVisible()){
709 this.el.setLocation(x, y);
719 this.xy = this.el.getXY();
725 adjustAssets : function(doShow){
726 var x = this.xy[0], y = this.xy[1];
727 var w = this.size.width, h = this.size.height;
730 this.shadow.show(this.el);
736 if(this.shadow && this.shadow.isVisible()){
737 this.shadow.show(this.el);
739 if(this.shim && this.shim.isVisible()){
740 this.shim.setBounds(x, y, w, h);
745 adjustViewport : function(w, h){
747 w = Roo.lib.Dom.getViewWidth();
748 h = Roo.lib.Dom.getViewHeight();
751 this.viewSize = [w, h];
752 if(this.modal && this.mask.isVisible()){
753 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
754 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
756 if(this.isVisible()){
762 * Destroys this dialog and all its supporting elements (including any tabs, shim,
763 * shadow, proxy, mask, etc.) Also removes all event listeners.
764 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
766 destroy : function(removeEl){
767 if(this.isVisible()){
768 this.animateTarget = null;
771 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
773 this.tabs.destroy(removeEl);
786 for(var i = 0, len = this.buttons.length; i < len; i++){
787 this.buttons[i].destroy();
790 this.el.removeAllListeners();
791 if(removeEl === true){
795 Roo.DialogManager.unregister(this);
799 startMove : function(){
803 if(this.constraintoviewport !== false){
804 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
809 endMove : function(){
811 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
813 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
819 this.fireEvent("move", this, this.xy[0], this.xy[1]);
823 * Brings this dialog to the front of any other visible dialogs
824 * @return {Roo.BasicDialog} this
826 toFront : function(){
827 Roo.DialogManager.bringToFront(this);
832 * Sends this dialog to the back (under) of any other visible dialogs
833 * @return {Roo.BasicDialog} this
836 Roo.DialogManager.sendToBack(this);
841 * Centers this dialog in the viewport
842 * @return {Roo.BasicDialog} this
845 var xy = this.el.getCenterXY(true);
846 this.moveTo(xy[0], xy[1]);
851 * Moves the dialog's top-left corner to the specified point
854 * @return {Roo.BasicDialog} this
856 moveTo : function(x, y){
858 if(this.isVisible()){
859 this.el.setXY(this.xy);
866 * Aligns the dialog to the specified element
867 * @param {String/HTMLElement/Roo.Element} element The element to align to.
868 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
869 * @param {Array} offsets (optional) Offset the positioning by [x, y]
870 * @return {Roo.BasicDialog} this
872 alignTo : function(element, position, offsets){
873 this.xy = this.el.getAlignToXY(element, position, offsets);
874 if(this.isVisible()){
875 this.el.setXY(this.xy);
882 * Anchors an element to another element and realigns it when the window is resized.
883 * @param {String/HTMLElement/Roo.Element} element The element to align to.
884 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
885 * @param {Array} offsets (optional) Offset the positioning by [x, y]
886 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
887 * is a number, it is used as the buffer delay (defaults to 50ms).
888 * @return {Roo.BasicDialog} this
890 anchorTo : function(el, alignment, offsets, monitorScroll){
891 var action = function(){
892 this.alignTo(el, alignment, offsets);
894 Roo.EventManager.onWindowResize(action, this);
895 var tm = typeof monitorScroll;
896 if(tm != 'undefined'){
897 Roo.EventManager.on(window, 'scroll', action, this,
898 {buffer: tm == 'number' ? monitorScroll : 50});
905 * Returns true if the dialog is visible
908 isVisible : function(){
909 return this.el.isVisible();
913 animHide : function(callback){
914 var b = Roo.get(this.animateTarget).getBox();
916 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
918 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
919 this.hideEl.createDelegate(this, [callback]));
924 * @param {Function} callback (optional) Function to call when the dialog is hidden
925 * @return {Roo.BasicDialog} this
927 hide : function(callback){
928 if (this.fireEvent("beforehide", this) === false){
937 // sometimes animateTarget seems to get set.. causing problems...
938 // this just double checks..
939 if(this.animateTarget && Roo.get(this.animateTarget)) {
940 this.animHide(callback);
943 this.hideEl(callback);
949 hideEl : function(callback){
953 Roo.get(document.body).removeClass("x-body-masked");
955 this.fireEvent("hide", this);
956 if(typeof callback == "function"){
962 hideAction : function(){
963 this.setLeft("-10000px");
964 this.setTop("-10000px");
965 this.setStyle("visibility", "hidden");
969 refreshSize : function(){
970 this.size = this.el.getSize();
971 this.xy = this.el.getXY();
972 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
976 // z-index is managed by the DialogManager and may be overwritten at any time
977 setZIndex : function(index){
979 this.mask.setStyle("z-index", index);
982 this.shim.setStyle("z-index", ++index);
985 this.shadow.setZIndex(++index);
987 this.el.setStyle("z-index", ++index);
989 this.proxy.setStyle("z-index", ++index);
992 this.resizer.proxy.setStyle("z-index", ++index);
995 this.lastZIndex = index;
999 * Returns the element for this dialog
1000 * @return {Roo.Element} The underlying dialog Element
1008 * @class Roo.DialogManager
1009 * Provides global access to BasicDialogs that have been created and
1010 * support for z-indexing (layering) multiple open dialogs.
1012 Roo.DialogManager = function(){
1014 var accessList = [];
1018 var sortDialogs = function(d1, d2){
1019 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
1023 var orderDialogs = function(){
1024 accessList.sort(sortDialogs);
1025 var seed = Roo.DialogManager.zseed;
1026 for(var i = 0, len = accessList.length; i < len; i++){
1027 var dlg = accessList[i];
1029 dlg.setZIndex(seed + (i*10));
1036 * The starting z-index for BasicDialogs (defaults to 9000)
1037 * @type Number The z-index value
1042 register : function(dlg){
1044 accessList.push(dlg);
1048 unregister : function(dlg){
1049 delete list[dlg.id];
1052 if(!accessList.indexOf){
1053 for( i = 0, len = accessList.length; i < len; i++){
1054 if(accessList[i] == dlg){
1055 accessList.splice(i, 1);
1060 i = accessList.indexOf(dlg);
1062 accessList.splice(i, 1);
1068 * Gets a registered dialog by id
1069 * @param {String/Object} id The id of the dialog or a dialog
1070 * @return {Roo.BasicDialog} this
1073 return typeof id == "object" ? id : list[id];
1077 * Brings the specified dialog to the front
1078 * @param {String/Object} dlg The id of the dialog or a dialog
1079 * @return {Roo.BasicDialog} this
1081 bringToFront : function(dlg){
1082 dlg = this.get(dlg);
1085 dlg._lastAccess = new Date().getTime();
1092 * Sends the specified dialog to the back
1093 * @param {String/Object} dlg The id of the dialog or a dialog
1094 * @return {Roo.BasicDialog} this
1096 sendToBack : function(dlg){
1097 dlg = this.get(dlg);
1098 dlg._lastAccess = -(new Date().getTime());
1106 hideAll : function(){
1107 for(var id in list){
1108 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
1117 * @class Roo.LayoutDialog
1118 * @extends Roo.BasicDialog
1119 * Dialog which provides adjustments for working with a layout in a Dialog.
1120 * Add your necessary layout config options to the dialog's config.<br>
1121 * Example usage (including a nested layout):
1124 dialog = new Roo.LayoutDialog("download-dlg", {
1133 // layout config merges with the dialog config
1136 alwaysShowTabs: true
1139 dialog.addKeyListener(27, dialog.hide, dialog);
1140 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
1141 dialog.addButton("Build It!", this.getDownload, this);
1143 // we can even add nested layouts
1144 var innerLayout = new Roo.BorderLayout("dl-inner", {
1154 innerLayout.beginUpdate();
1155 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
1156 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
1157 innerLayout.endUpdate(true);
1159 var layout = dialog.getLayout();
1160 layout.beginUpdate();
1161 layout.add("center", new Roo.ContentPanel("standard-panel",
1162 {title: "Download the Source", fitToFrame:true}));
1163 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
1164 {title: "Build your own roo.js"}));
1165 layout.getRegion("center").showPanel(sp);
1170 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
1171 * @param {Object} config configuration options
1173 Roo.LayoutDialog = function(el, cfg){
1176 if (typeof(cfg) == 'undefined') {
1177 config = Roo.apply({}, el);
1178 // not sure why we use documentElement here.. - it should always be body.
1179 // IE7 borks horribly if we use documentElement.
1180 // webkit also does not like documentElement - it creates a body element...
1181 el = Roo.get( document.body || document.documentElement ).createChild();
1182 //config.autoCreate = true;
1186 config.autoTabs = false;
1187 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
1188 this.body.setStyle({overflow:"hidden", position:"relative"});
1189 this.layout = new Roo.BorderLayout(this.body.dom, config);
1190 this.layout.monitorWindowResize = false;
1191 this.el.addClass("x-dlg-auto-layout");
1192 // fix case when center region overwrites center function
1193 this.center = Roo.BasicDialog.prototype.center;
1194 this.on("show", this.layout.layout, this.layout, true);
1196 var xitems = config.items;
1197 delete config.items;
1198 Roo.each(xitems, this.addxtype, this);
1203 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
1205 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
1208 endUpdate : function(){
1209 this.layout.endUpdate();
1213 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
1216 beginUpdate : function(){
1217 this.layout.beginUpdate();
1221 * Get the BorderLayout for this dialog
1222 * @return {Roo.BorderLayout}
1224 getLayout : function(){
1228 showEl : function(){
1229 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
1231 this.layout.layout();
1236 // Use the syncHeightBeforeShow config option to control this automatically
1237 syncBodyHeight : function(){
1238 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
1239 if(this.layout){this.layout.layout();}
1243 * Add an xtype element (actually adds to the layout.)
1244 * @return {Object} xdata xtype object data.
1247 addxtype : function(c) {
1248 return this.layout.addxtype(c);