Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / src / widgets / Panel.js
1 /*!
2  * Ext JS Library 3.3.1
3  * Copyright(c) 2006-2010 Sencha Inc.
4  * licensing@sencha.com
5  * http://www.sencha.com/license
6  */
7 /**
8  * @class Ext.Panel
9  * @extends Ext.Container
10  * <p>Panel is a container that has specific functionality and structural components that make
11  * it the perfect building block for application-oriented user interfaces.</p>
12  * <p>Panels are, by virtue of their inheritance from {@link Ext.Container}, capable
13  * of being configured with a {@link Ext.Container#layout layout}, and containing child Components.</p>
14  * <p>When either specifying child {@link Ext.Component#items items} of a Panel, or dynamically {@link Ext.Container#add adding} Components
15  * to a Panel, remember to consider how you wish the Panel to arrange those child elements, and whether
16  * those child elements need to be sized using one of Ext's built-in <code><b>{@link Ext.Container#layout layout}</b></code> schemes. By
17  * default, Panels use the {@link Ext.layout.ContainerLayout ContainerLayout} scheme. This simply renders
18  * child components, appending them one after the other inside the Container, and <b>does not apply any sizing</b>
19  * at all.</p>
20  * <p>A Panel may also contain {@link #bbar bottom} and {@link #tbar top} toolbars, along with separate
21  * {@link #header}, {@link #footer} and {@link #body} sections (see {@link #frame} for additional
22  * information).</p>
23  * <p>Panel also provides built-in {@link #collapsible expandable and collapsible behavior}, along with
24  * a variety of {@link #tools prebuilt tool buttons} that can be wired up to provide other customized
25  * behavior.  Panels can be easily dropped into any {@link Ext.Container Container} or layout, and the
26  * layout and rendering pipeline is {@link Ext.Container#add completely managed by the framework}.</p>
27  * @constructor
28  * @param {Object} config The config object
29  * @xtype panel
30  */
31 Ext.Panel = Ext.extend(Ext.Container, {
32     /**
33      * The Panel's header {@link Ext.Element Element}. Read-only.
34      * <p>This Element is used to house the {@link #title} and {@link #tools}</p>
35      * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
36      * @type Ext.Element
37      * @property header
38      */
39     /**
40      * The Panel's body {@link Ext.Element Element} which may be used to contain HTML content.
41      * The content may be specified in the {@link #html} config, or it may be loaded using the
42      * {@link autoLoad} config, or through the Panel's {@link #getUpdater Updater}. Read-only.
43      * <p>If this is used to load visible HTML elements in either way, then
44      * the Panel may not be used as a Layout for hosting nested Panels.</p>
45      * <p>If this Panel is intended to be used as the host of a Layout (See {@link #layout}
46      * then the body Element must not be loaded or changed - it is under the control
47      * of the Panel's Layout.
48      * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
49      * @type Ext.Element
50      * @property body
51      */
52     /**
53      * The Panel's bwrap {@link Ext.Element Element} used to contain other Panel elements
54      * (tbar, body, bbar, footer). See {@link #bodyCfg}. Read-only.
55      * @type Ext.Element
56      * @property bwrap
57      */
58     /**
59      * True if this panel is collapsed. Read-only.
60      * @type Boolean
61      * @property collapsed
62      */
63     /**
64      * @cfg {Object} bodyCfg
65      * <p>A {@link Ext.DomHelper DomHelper} element specification object may be specified for any
66      * Panel Element.</p>
67      * <p>By default, the Default element in the table below will be used for the html markup to
68      * create a child element with the commensurate Default class name (<code>baseCls</code> will be
69      * replaced by <code>{@link #baseCls}</code>):</p>
70      * <pre>
71      * Panel      Default  Default             Custom      Additional       Additional
72      * Element    element  class               element     class            style
73      * ========   ==========================   =========   ==============   ===========
74      * {@link #header}     div      {@link #baseCls}+'-header'   {@link #headerCfg}   headerCssClass   headerStyle
75      * {@link #bwrap}      div      {@link #baseCls}+'-bwrap'     {@link #bwrapCfg}    bwrapCssClass    bwrapStyle
76      * + tbar     div      {@link #baseCls}+'-tbar'       {@link #tbarCfg}     tbarCssClass     tbarStyle
77      * + {@link #body}     div      {@link #baseCls}+'-body'       {@link #bodyCfg}     {@link #bodyCssClass}     {@link #bodyStyle}
78      * + bbar     div      {@link #baseCls}+'-bbar'       {@link #bbarCfg}     bbarCssClass     bbarStyle
79      * + {@link #footer}   div      {@link #baseCls}+'-footer'   {@link #footerCfg}   footerCssClass   footerStyle
80      * </pre>
81      * <p>Configuring a Custom element may be used, for example, to force the {@link #body} Element
82      * to use a different form of markup than is created by default. An example of this might be
83      * to {@link Ext.Element#createChild create a child} Panel containing a custom content, such as
84      * a header, or forcing centering of all Panel content by having the body be a &lt;center&gt;
85      * element:</p>
86      * <pre><code>
87 new Ext.Panel({
88     title: 'Message Title',
89     renderTo: Ext.getBody(),
90     width: 200, height: 130,
91     <b>bodyCfg</b>: {
92         tag: 'center',
93         cls: 'x-panel-body',  // Default class not applied if Custom element specified
94         html: 'Message'
95     },
96     footerCfg: {
97         tag: 'h2',
98         cls: 'x-panel-footer',        // same as the Default class
99         html: 'footer html'
100     },
101     footerCssClass: 'custom-footer', // additional css class, see {@link Ext.element#addClass addClass}
102     footerStyle:    'background-color:red' // see {@link #bodyStyle}
103 });
104      * </code></pre>
105      * <p>The example above also explicitly creates a <code>{@link #footer}</code> with custom markup and
106      * styling applied.</p>
107      */
108     /**
109      * @cfg {Object} headerCfg
110      * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
111      * of this Panel's {@link #header} Element.  See <code>{@link #bodyCfg}</code> also.</p>
112      */
113     /**
114      * @cfg {Object} bwrapCfg
115      * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
116      * of this Panel's {@link #bwrap} Element.  See <code>{@link #bodyCfg}</code> also.</p>
117      */
118     /**
119      * @cfg {Object} tbarCfg
120      * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
121      * of this Panel's {@link #tbar} Element.  See <code>{@link #bodyCfg}</code> also.</p>
122      */
123     /**
124      * @cfg {Object} bbarCfg
125      * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
126      * of this Panel's {@link #bbar} Element.  See <code>{@link #bodyCfg}</code> also.</p>
127      */
128     /**
129      * @cfg {Object} footerCfg
130      * <p>A {@link Ext.DomHelper DomHelper} element specification object specifying the element structure
131      * of this Panel's {@link #footer} Element.  See <code>{@link #bodyCfg}</code> also.</p>
132      */
133     /**
134      * @cfg {Boolean} closable
135      * Panels themselves do not directly support being closed, but some Panel subclasses do (like
136      * {@link Ext.Window}) or a Panel Class within an {@link Ext.TabPanel}.  Specify <code>true</code>
137      * to enable closing in such situations. Defaults to <code>false</code>.
138      */
139     /**
140      * The Panel's footer {@link Ext.Element Element}. Read-only.
141      * <p>This Element is used to house the Panel's <code>{@link #buttons}</code> or <code>{@link #fbar}</code>.</p>
142      * <br><p><b>Note</b>: see the Note for <code>{@link Ext.Component#el el}</code> also.</p>
143      * @type Ext.Element
144      * @property footer
145      */
146     /**
147      * @cfg {Mixed} applyTo
148      * <p>The id of the node, a DOM node or an existing Element corresponding to a DIV that is already present in
149      * the document that specifies some panel-specific structural markup.  When <code>applyTo</code> is used,
150      * constituent parts of the panel can be specified by CSS class name within the main element, and the panel
151      * will automatically create those components from that markup. Any required components not specified in the
152      * markup will be autogenerated if necessary.</p>
153      * <p>The following class names are supported (baseCls will be replaced by {@link #baseCls}):</p>
154      * <ul><li>baseCls + '-header'</li>
155      * <li>baseCls + '-header-text'</li>
156      * <li>baseCls + '-bwrap'</li>
157      * <li>baseCls + '-tbar'</li>
158      * <li>baseCls + '-body'</li>
159      * <li>baseCls + '-bbar'</li>
160      * <li>baseCls + '-footer'</li></ul>
161      * <p>Using this config, a call to render() is not required.  If applyTo is specified, any value passed for
162      * {@link #renderTo} will be ignored and the target element's parent node will automatically be used as the
163      * panel's container.</p>
164      */
165     /**
166      * @cfg {Object/Array} tbar
167      * <p>The top toolbar of the panel. This can be a {@link Ext.Toolbar} object, a toolbar config, or an array of
168      * buttons/button configs to be added to the toolbar.  Note that this is not available as a property after render.
169      * To access the top toolbar after render, use {@link #getTopToolbar}.</p>
170      * <p><b>Note:</b> Although a Toolbar may contain Field components, these will <b>not</b> be updated by a load
171      * of an ancestor FormPanel. A Panel's toolbars are not part of the standard Container->Component hierarchy, and
172      * so are not scanned to collect form items. However, the values <b>will</b> be submitted because form
173      * submission parameters are collected from the DOM tree.</p>
174      */
175     /**
176      * @cfg {Object/Array} bbar
177      * <p>The bottom toolbar of the panel. This can be a {@link Ext.Toolbar} object, a toolbar config, or an array of
178      * buttons/button configs to be added to the toolbar.  Note that this is not available as a property after render.
179      * To access the bottom toolbar after render, use {@link #getBottomToolbar}.</p>
180      * <p><b>Note:</b> Although a Toolbar may contain Field components, these will <b>not</b> be updated by a load
181      * of an ancestor FormPanel. A Panel's toolbars are not part of the standard Container->Component hierarchy, and
182      * so are not scanned to collect form items. However, the values <b>will</b> be submitted because form
183      * submission parameters are collected from the DOM tree.</p>
184      */
185     /** @cfg {Object/Array} fbar
186      * <p>A {@link Ext.Toolbar Toolbar} object, a Toolbar config, or an array of
187      * {@link Ext.Button Button}s/{@link Ext.Button Button} configs, describing a {@link Ext.Toolbar Toolbar} to be rendered into this Panel's footer element.</p>
188      * <p>After render, the <code>fbar</code> property will be an {@link Ext.Toolbar Toolbar} instance.</p>
189      * <p>If <code>{@link #buttons}</code> are specified, they will supersede the <code>fbar</code> configuration property.</p>
190      * The Panel's <code>{@link #buttonAlign}</code> configuration affects the layout of these items, for example:
191      * <pre><code>
192 var w = new Ext.Window({
193     height: 250,
194     width: 500,
195     bbar: new Ext.Toolbar({
196         items: [{
197             text: 'bbar Left'
198         },'->',{
199             text: 'bbar Right'
200         }]
201     }),
202     {@link #buttonAlign}: 'left', // anything but 'center' or 'right' and you can use '-', and '->'
203                                   // to control the alignment of fbar items
204     fbar: [{
205         text: 'fbar Left'
206     },'->',{
207         text: 'fbar Right'
208     }]
209 }).show();
210      * </code></pre>
211      * <p><b>Note:</b> Although a Toolbar may contain Field components, these will <b>not</b> be updated by a load
212      * of an ancestor FormPanel. A Panel's toolbars are not part of the standard Container->Component hierarchy, and
213      * so are not scanned to collect form items. However, the values <b>will</b> be submitted because form
214      * submission parameters are collected from the DOM tree.</p>
215      */
216     /**
217      * @cfg {Boolean} header
218      * <code>true</code> to create the Panel's header element explicitly, <code>false</code> to skip creating
219      * it.  If a <code>{@link #title}</code> is set the header will be created automatically, otherwise it will not.
220      * If a <code>{@link #title}</code> is set but <code>header</code> is explicitly set to <code>false</code>, the header
221      * will not be rendered.
222      */
223     /**
224      * @cfg {Boolean} footer
225      * <code>true</code> to create the footer element explicitly, false to skip creating it. The footer
226      * will be created automatically if <code>{@link #buttons}</code> or a <code>{@link #fbar}</code> have
227      * been configured.  See <code>{@link #bodyCfg}</code> for an example.
228      */
229     /**
230      * @cfg {String} title
231      * The title text to be used as innerHTML (html tags are accepted) to display in the panel
232      * <code>{@link #header}</code> (defaults to ''). When a <code>title</code> is specified the
233      * <code>{@link #header}</code> element will automatically be created and displayed unless
234      * {@link #header} is explicitly set to <code>false</code>.  If you do not want to specify a
235      * <code>title</code> at config time, but you may want one later, you must either specify a non-empty
236      * <code>title</code> (a blank space ' ' will do) or <code>header:true</code> so that the container
237      * element will get created.
238      */
239     /**
240      * @cfg {Array} buttons
241      * <code>buttons</code> will be used as <code>{@link Ext.Container#items items}</code> for the toolbar in
242      * the footer (<code>{@link #fbar}</code>). Typically the value of this configuration property will be
243      * an array of {@link Ext.Button}s or {@link Ext.Button} configuration objects.
244      * If an item is configured with <code>minWidth</code> or the Panel is configured with <code>minButtonWidth</code>,
245      * that width will be applied to the item.
246      */
247     /**
248      * @cfg {Object/String/Function} autoLoad
249      * A valid url spec according to the Updater {@link Ext.Updater#update} method.
250      * If autoLoad is not null, the panel will attempt to load its contents
251      * immediately upon render.<p>
252      * The URL will become the default URL for this panel's {@link #body} element,
253      * so it may be {@link Ext.Element#refresh refresh}ed at any time.</p>
254      */
255     /**
256      * @cfg {Boolean} frame
257      * <code>false</code> by default to render with plain 1px square borders. <code>true</code> to render with
258      * 9 elements, complete with custom rounded corners (also see {@link Ext.Element#boxWrap}).
259      * <p>The template generated for each condition is depicted below:</p><pre><code>
260      *
261 // frame = false
262 &lt;div id="developer-specified-id-goes-here" class="x-panel">
263
264     &lt;div class="x-panel-header">&lt;span class="x-panel-header-text">Title: (frame:false)&lt;/span>&lt;/div>
265
266     &lt;div class="x-panel-bwrap">
267         &lt;div class="x-panel-body">&lt;p>html value goes here&lt;/p>&lt;/div>
268     &lt;/div>
269 &lt;/div>
270
271 // frame = true (create 9 elements)
272 &lt;div id="developer-specified-id-goes-here" class="x-panel">
273     &lt;div class="x-panel-tl">&lt;div class="x-panel-tr">&lt;div class="x-panel-tc">
274         &lt;div class="x-panel-header">&lt;span class="x-panel-header-text">Title: (frame:true)&lt;/span>&lt;/div>
275     &lt;/div>&lt;/div>&lt;/div>
276
277     &lt;div class="x-panel-bwrap">
278         &lt;div class="x-panel-ml">&lt;div class="x-panel-mr">&lt;div class="x-panel-mc">
279             &lt;div class="x-panel-body">&lt;p>html value goes here&lt;/p>&lt;/div>
280         &lt;/div>&lt;/div>&lt;/div>
281
282         &lt;div class="x-panel-bl">&lt;div class="x-panel-br">&lt;div class="x-panel-bc"/>
283         &lt;/div>&lt;/div>&lt;/div>
284 &lt;/div>
285      * </code></pre>
286      */
287     /**
288      * @cfg {Boolean} border
289      * True to display the borders of the panel's body element, false to hide them (defaults to true).  By default,
290      * the border is a 2px wide inset border, but this can be further altered by setting {@link #bodyBorder} to false.
291      */
292     /**
293      * @cfg {Boolean} bodyBorder
294      * True to display an interior border on the body element of the panel, false to hide it (defaults to true).
295      * This only applies when {@link #border} == true.  If border == true and bodyBorder == false, the border will display
296      * as a 1px wide inset border, giving the entire body element an inset appearance.
297      */
298     /**
299      * @cfg {String/Object/Function} bodyCssClass
300      * Additional css class selector to be applied to the {@link #body} element in the format expected by
301      * {@link Ext.Element#addClass} (defaults to null). See {@link #bodyCfg}.
302      */
303     /**
304      * @cfg {String/Object/Function} bodyStyle
305      * Custom CSS styles to be applied to the {@link #body} element in the format expected by
306      * {@link Ext.Element#applyStyles} (defaults to null). See {@link #bodyCfg}.
307      */
308     /**
309      * @cfg {String} iconCls
310      * The CSS class selector that specifies a background image to be used as the header icon (defaults to '').
311      * <p>An example of specifying a custom icon class would be something like:
312      * </p><pre><code>
313 // specify the property in the config for the class:
314      ...
315      iconCls: 'my-icon'
316
317 // css class that specifies background image to be used as the icon image:
318 .my-icon { background-image: url(../images/my-icon.gif) 0 6px no-repeat !important; }
319 </code></pre>
320      */
321     /**
322      * @cfg {Boolean} collapsible
323      * True to make the panel collapsible and have the expand/collapse toggle button automatically rendered into
324      * the header tool button area, false to keep the panel statically sized with no button (defaults to false).
325      */
326     /**
327      * @cfg {Array} tools
328      * An array of tool button configs to be added to the header tool area. When rendered, each tool is
329      * stored as an {@link Ext.Element Element} referenced by a public property called <code><b></b>tools.<i>&lt;tool-type&gt;</i></code>
330      * <p>Each tool config may contain the following properties:
331      * <div class="mdetail-params"><ul>
332      * <li><b>id</b> : String<div class="sub-desc"><b>Required.</b> The type
333      * of tool to create. By default, this assigns a CSS class of the form <code>x-tool-<i>&lt;tool-type&gt;</i></code> to the
334      * resulting tool Element. Ext provides CSS rules, and an icon sprite containing images for the tool types listed below.
335      * The developer may implement custom tools by supplying alternate CSS rules and background images:
336      * <ul>
337      * <div class="x-tool x-tool-toggle" style="float:left; margin-right:5;"> </div><div><code> toggle</code> (Created by default when {@link #collapsible} is <code>true</code>)</div>
338      * <div class="x-tool x-tool-close" style="float:left; margin-right:5;"> </div><div><code> close</code></div>
339      * <div class="x-tool x-tool-minimize" style="float:left; margin-right:5;"> </div><div><code> minimize</code></div>
340      * <div class="x-tool x-tool-maximize" style="float:left; margin-right:5;"> </div><div><code> maximize</code></div>
341      * <div class="x-tool x-tool-restore" style="float:left; margin-right:5;"> </div><div><code> restore</code></div>
342      * <div class="x-tool x-tool-gear" style="float:left; margin-right:5;"> </div><div><code> gear</code></div>
343      * <div class="x-tool x-tool-pin" style="float:left; margin-right:5;"> </div><div><code> pin</code></div>
344      * <div class="x-tool x-tool-unpin" style="float:left; margin-right:5;"> </div><div><code> unpin</code></div>
345      * <div class="x-tool x-tool-right" style="float:left; margin-right:5;"> </div><div><code> right</code></div>
346      * <div class="x-tool x-tool-left" style="float:left; margin-right:5;"> </div><div><code> left</code></div>
347      * <div class="x-tool x-tool-up" style="float:left; margin-right:5;"> </div><div><code> up</code></div>
348      * <div class="x-tool x-tool-down" style="float:left; margin-right:5;"> </div><div><code> down</code></div>
349      * <div class="x-tool x-tool-refresh" style="float:left; margin-right:5;"> </div><div><code> refresh</code></div>
350      * <div class="x-tool x-tool-minus" style="float:left; margin-right:5;"> </div><div><code> minus</code></div>
351      * <div class="x-tool x-tool-plus" style="float:left; margin-right:5;"> </div><div><code> plus</code></div>
352      * <div class="x-tool x-tool-help" style="float:left; margin-right:5;"> </div><div><code> help</code></div>
353      * <div class="x-tool x-tool-search" style="float:left; margin-right:5;"> </div><div><code> search</code></div>
354      * <div class="x-tool x-tool-save" style="float:left; margin-right:5;"> </div><div><code> save</code></div>
355      * <div class="x-tool x-tool-print" style="float:left; margin-right:5;"> </div><div><code> print</code></div>
356      * </ul></div></li>
357      * <li><b>handler</b> : Function<div class="sub-desc"><b>Required.</b> The function to
358      * call when clicked. Arguments passed are:<ul>
359      * <li><b>event</b> : Ext.EventObject<div class="sub-desc">The click event.</div></li>
360      * <li><b>toolEl</b> : Ext.Element<div class="sub-desc">The tool Element.</div></li>
361      * <li><b>panel</b> : Ext.Panel<div class="sub-desc">The host Panel</div></li>
362      * <li><b>tc</b> : Object<div class="sub-desc">The tool configuration object</div></li>
363      * </ul></div></li>
364      * <li><b>stopEvent</b> : Boolean<div class="sub-desc">Defaults to true. Specify as false to allow click event to propagate.</div></li>
365      * <li><b>scope</b> : Object<div class="sub-desc">The scope in which to call the handler.</div></li>
366      * <li><b>qtip</b> : String/Object<div class="sub-desc">A tip string, or
367      * a config argument to {@link Ext.QuickTip#register}</div></li>
368      * <li><b>hidden</b> : Boolean<div class="sub-desc">True to initially render hidden.</div></li>
369      * <li><b>on</b> : Object<div class="sub-desc">A listener config object specifiying
370      * event listeners in the format of an argument to {@link #addListener}</div></li>
371      * </ul></div>
372      * <p>Note that, apart from the toggle tool which is provided when a panel is collapsible, these
373      * tools only provide the visual button. Any required functionality must be provided by adding
374      * handlers that implement the necessary behavior.</p>
375      * <p>Example usage:</p>
376      * <pre><code>
377 tools:[{
378     id:'refresh',
379     qtip: 'Refresh form Data',
380     // hidden:true,
381     handler: function(event, toolEl, panel){
382         // refresh logic
383     }
384 },
385 {
386     id:'help',
387     qtip: 'Get Help',
388     handler: function(event, toolEl, panel){
389         // whatever
390     }
391 }]
392 </code></pre>
393      * <p>For the custom id of <code>'help'</code> define two relevant css classes with a link to
394      * a 15x15 image:</p>
395      * <pre><code>
396 .x-tool-help {background-image: url(images/help.png);}
397 .x-tool-help-over {background-image: url(images/help_over.png);}
398 // if using an image sprite:
399 .x-tool-help {background-image: url(images/help.png) no-repeat 0 0;}
400 .x-tool-help-over {background-position:-15px 0;}
401 </code></pre>
402      */
403     /**
404      * @cfg {Ext.Template/Ext.XTemplate} toolTemplate
405      * <p>A Template used to create {@link #tools} in the {@link #header} Element. Defaults to:</p><pre><code>
406 new Ext.Template('&lt;div class="x-tool x-tool-{id}">&amp;#160;&lt;/div>')</code></pre>
407      * <p>This may may be overridden to provide a custom DOM structure for tools based upon a more
408      * complex XTemplate. The template's data is a single tool configuration object (Not the entire Array)
409      * as specified in {@link #tools}.  In the following example an &lt;a> tag is used to provide a
410      * visual indication when hovering over the tool:</p><pre><code>
411 var win = new Ext.Window({
412     tools: [{
413         id: 'download',
414         href: '/MyPdfDoc.pdf'
415     }],
416     toolTemplate: new Ext.XTemplate(
417         '&lt;tpl if="id==\'download\'">',
418             '&lt;a class="x-tool x-tool-pdf" href="{href}">&lt;/a>',
419         '&lt;/tpl>',
420         '&lt;tpl if="id!=\'download\'">',
421             '&lt;div class="x-tool x-tool-{id}">&amp;#160;&lt;/div>',
422         '&lt;/tpl>'
423     ),
424     width:500,
425     height:300,
426     closeAction:'hide'
427 });</code></pre>
428      * <p>Note that the CSS class 'x-tool-pdf' should have an associated style rule which provides an
429      * appropriate background image, something like:</p>
430     <pre><code>
431     a.x-tool-pdf {background-image: url(../shared/extjs/images/pdf.gif)!important;}
432     </code></pre>
433      */
434     /**
435      * @cfg {Boolean} hideCollapseTool
436      * <code>true</code> to hide the expand/collapse toggle button when <code>{@link #collapsible} == true</code>,
437      * <code>false</code> to display it (defaults to <code>false</code>).
438      */
439     /**
440      * @cfg {Boolean} titleCollapse
441      * <code>true</code> to allow expanding and collapsing the panel (when <code>{@link #collapsible} = true</code>)
442      * by clicking anywhere in the header bar, <code>false</code>) to allow it only by clicking to tool button
443      * (defaults to <code>false</code>)). If this panel is a child item of a border layout also see the
444      * {@link Ext.layout.BorderLayout.Region BorderLayout.Region}
445      * <code>{@link Ext.layout.BorderLayout.Region#floatable floatable}</code> config option.
446      */
447
448     /**
449      * @cfg {Mixed} floating
450      * <p>This property is used to configure the underlying {@link Ext.Layer}. Acceptable values for this
451      * configuration property are:</p><div class="mdetail-params"><ul>
452      * <li><b><code>false</code></b> : <b>Default.</b><div class="sub-desc">Display the panel inline where it is
453      * rendered.</div></li>
454      * <li><b><code>true</code></b> : <div class="sub-desc">Float the panel (absolute position it with automatic
455      * shimming and shadow).<ul>
456      * <div class="sub-desc">Setting floating to true will create an Ext.Layer for this panel and display the
457      * panel at negative offsets so that it is hidden.</div>
458      * <div class="sub-desc">Since the panel will be absolute positioned, the position must be set explicitly
459      * <i>after</i> render (e.g., <code>myPanel.setPosition(100,100);</code>).</div>
460      * <div class="sub-desc"><b>Note</b>: when floating a panel you should always assign a fixed width,
461      * otherwise it will be auto width and will expand to fill to the right edge of the viewport.</div>
462      * </ul></div></li>
463      * <li><b><code>{@link Ext.Layer object}</code></b> : <div class="sub-desc">The specified object will be used
464      * as the configuration object for the {@link Ext.Layer} that will be created.</div></li>
465      * </ul></div>
466      */
467     /**
468      * @cfg {Boolean/String} shadow
469      * <code>true</code> (or a valid Ext.Shadow {@link Ext.Shadow#mode} value) to display a shadow behind the
470      * panel, <code>false</code> to display no shadow (defaults to <code>'sides'</code>).  Note that this option
471      * only applies when <code>{@link #floating} = true</code>.
472      */
473     /**
474      * @cfg {Number} shadowOffset
475      * The number of pixels to offset the shadow if displayed (defaults to <code>4</code>). Note that this
476      * option only applies when <code>{@link #floating} = true</code>.
477      */
478     /**
479      * @cfg {Boolean} shim
480      * <code>false</code> to disable the iframe shim in browsers which need one (defaults to <code>true</code>).
481      * Note that this option only applies when <code>{@link #floating} = true</code>.
482      */
483     /**
484      * @cfg {Object/Array} keys
485      * A {@link Ext.KeyMap} config object (in the format expected by {@link Ext.KeyMap#addBinding}
486      * used to assign custom key handling to this panel (defaults to <code>null</code>).
487      */
488     /**
489      * @cfg {Boolean/Object} draggable
490      * <p><code>true</code> to enable dragging of this Panel (defaults to <code>false</code>).</p>
491      * <p>For custom drag/drop implementations, an <b>Ext.Panel.DD</b> config could also be passed
492      * in this config instead of <code>true</code>. Ext.Panel.DD is an internal, undocumented class which
493      * moves a proxy Element around in place of the Panel's element, but provides no other behaviour
494      * during dragging or on drop. It is a subclass of {@link Ext.dd.DragSource}, so behaviour may be
495      * added by implementing the interface methods of {@link Ext.dd.DragDrop} e.g.:
496      * <pre><code>
497 new Ext.Panel({
498     title: 'Drag me',
499     x: 100,
500     y: 100,
501     renderTo: Ext.getBody(),
502     floating: true,
503     frame: true,
504     width: 400,
505     height: 200,
506     draggable: {
507 //      Config option of Ext.Panel.DD class.
508 //      It&#39;s a floating Panel, so do not show a placeholder proxy in the original position.
509         insertProxy: false,
510
511 //      Called for each mousemove event while dragging the DD object.
512         onDrag : function(e){
513 //          Record the x,y position of the drag proxy so that we can
514 //          position the Panel at end of drag.
515             var pel = this.proxy.getEl();
516             this.x = pel.getLeft(true);
517             this.y = pel.getTop(true);
518
519 //          Keep the Shadow aligned if there is one.
520             var s = this.panel.getEl().shadow;
521             if (s) {
522                 s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
523             }
524         },
525
526 //      Called on the mouseup event.
527         endDrag : function(e){
528             this.panel.setPosition(this.x, this.y);
529         }
530     }
531 }).show();
532 </code></pre>
533      */
534     /**
535      * @cfg {Boolean} disabled
536      * Render this panel disabled (default is <code>false</code>). An important note when using the disabled
537      * config on panels is that IE will often fail to initialize the disabled mask element correectly if
538      * the panel's layout has not yet completed by the time the Panel is disabled during the render process.
539      * If you experience this issue, you may need to instead use the {@link #afterlayout} event to initialize
540      * the disabled state:
541      * <pre><code>
542 new Ext.Panel({
543     ...
544     listeners: {
545         'afterlayout': {
546             fn: function(p){
547                 p.disable();
548             },
549             single: true // important, as many layouts can occur
550         }
551     }
552 });
553 </code></pre>
554      */
555     /**
556      * @cfg {Boolean} autoHeight
557      * <code>true</code> to use height:'auto', <code>false</code> to use fixed height (defaults to <code>false</code>).
558      * <b>Note</b>: Setting <code>autoHeight: true</code> means that the browser will manage the panel's height
559      * based on its contents, and that Ext will not manage it at all. If the panel is within a layout that
560      * manages dimensions (<code>fit</code>, <code>border</code>, etc.) then setting <code>autoHeight: true</code>
561      * can cause issues with scrolling and will not generally work as expected since the panel will take
562      * on the height of its contents rather than the height required by the Ext layout.
563      */
564
565
566     /**
567      * @cfg {String} baseCls
568      * The base CSS class to apply to this panel's element (defaults to <code>'x-panel'</code>).
569      * <p>Another option available by default is to specify <code>'x-plain'</code> which strips all styling
570      * except for required attributes for Ext layouts to function (e.g. overflow:hidden).
571      * See <code>{@link #unstyled}</code> also.</p>
572      */
573     baseCls : 'x-panel',
574     /**
575      * @cfg {String} collapsedCls
576      * A CSS class to add to the panel's element after it has been collapsed (defaults to
577      * <code>'x-panel-collapsed'</code>).
578      */
579     collapsedCls : 'x-panel-collapsed',
580     /**
581      * @cfg {Boolean} maskDisabled
582      * <code>true</code> to mask the panel when it is {@link #disabled}, <code>false</code> to not mask it (defaults
583      * to <code>true</code>).  Either way, the panel will always tell its contained elements to disable themselves
584      * when it is disabled, but masking the panel can provide an additional visual cue that the panel is
585      * disabled.
586      */
587     maskDisabled : true,
588     /**
589      * @cfg {Boolean} animCollapse
590      * <code>true</code> to animate the transition when the panel is collapsed, <code>false</code> to skip the
591      * animation (defaults to <code>true</code> if the {@link Ext.Fx} class is available, otherwise <code>false</code>).
592      */
593     animCollapse : Ext.enableFx,
594     /**
595      * @cfg {Boolean} headerAsText
596      * <code>true</code> to display the panel <code>{@link #title}</code> in the <code>{@link #header}</code>,
597      * <code>false</code> to hide it (defaults to <code>true</code>).
598      */
599     headerAsText : true,
600     /**
601      * @cfg {String} buttonAlign
602      * The alignment of any {@link #buttons} added to this panel.  Valid values are <code>'right'</code>,
603      * <code>'left'</code> and <code>'center'</code> (defaults to <code>'right'</code>).
604      */
605     buttonAlign : 'right',
606     /**
607      * @cfg {Boolean} collapsed
608      * <code>true</code> to render the panel collapsed, <code>false</code> to render it expanded (defaults to
609      * <code>false</code>).
610      */
611     collapsed : false,
612     /**
613      * @cfg {Boolean} collapseFirst
614      * <code>true</code> to make sure the collapse/expand toggle button always renders first (to the left of)
615      * any other tools in the panel's title bar, <code>false</code> to render it last (defaults to <code>true</code>).
616      */
617     collapseFirst : true,
618     /**
619      * @cfg {Number} minButtonWidth
620      * Minimum width in pixels of all {@link #buttons} in this panel (defaults to <code>75</code>)
621      */
622     minButtonWidth : 75,
623     /**
624      * @cfg {Boolean} unstyled
625      * Overrides the <code>{@link #baseCls}</code> setting to <code>{@link #baseCls} = 'x-plain'</code> which renders
626      * the panel unstyled except for required attributes for Ext layouts to function (e.g. overflow:hidden).
627      */
628     /**
629      * @cfg {String} elements
630      * A comma-delimited list of panel elements to initialize when the panel is rendered.  Normally, this list will be
631      * generated automatically based on the items added to the panel at config time, but sometimes it might be useful to
632      * make sure a structural element is rendered even if not specified at config time (for example, you may want
633      * to add a button or toolbar dynamically after the panel has been rendered).  Adding those elements to this
634      * list will allocate the required placeholders in the panel when it is rendered.  Valid values are<div class="mdetail-params"><ul>
635      * <li><code>header</code></li>
636      * <li><code>tbar</code> (top bar)</li>
637      * <li><code>body</code></li>
638      * <li><code>bbar</code> (bottom bar)</li>
639      * <li><code>footer</code></li>
640      * </ul></div>
641      * Defaults to '<code>body</code>'.
642      */
643     elements : 'body',
644     /**
645      * @cfg {Boolean} preventBodyReset
646      * Defaults to <code>false</code>.  When set to <code>true</code>, an extra css class <code>'x-panel-normal'</code>
647      * will be added to the panel's element, effectively applying css styles suggested by the W3C
648      * (see http://www.w3.org/TR/CSS21/sample.html) to the Panel's <b>body</b> element (not the header,
649      * footer, etc.).
650      */
651     preventBodyReset : false,
652
653     /**
654      * @cfg {Number/String} padding
655      * A shortcut for setting a padding style on the body element. The value can either be
656      * a number to be applied to all sides, or a normal css string describing padding.
657      * Defaults to <tt>undefined</tt>.
658      *
659      */
660     padding: undefined,
661
662     /** @cfg {String} resizeEvent
663      * The event to listen to for resizing in layouts. Defaults to <tt>'bodyresize'</tt>.
664      */
665     resizeEvent: 'bodyresize',
666
667     // protected - these could be used to customize the behavior of the window,
668     // but changing them would not be useful without further mofifications and
669     // could lead to unexpected or undesirable results.
670     toolTarget : 'header',
671     collapseEl : 'bwrap',
672     slideAnchor : 't',
673     disabledClass : '',
674
675     // private, notify box this class will handle heights
676     deferHeight : true,
677     // private
678     expandDefaults: {
679         duration : 0.25
680     },
681     // private
682     collapseDefaults : {
683         duration : 0.25
684     },
685
686     // private
687     initComponent : function(){
688         Ext.Panel.superclass.initComponent.call(this);
689
690         this.addEvents(
691             /**
692              * @event bodyresize
693              * Fires after the Panel has been resized.
694              * @param {Ext.Panel} p the Panel which has been resized.
695              * @param {Number} width The Panel body's new width.
696              * @param {Number} height The Panel body's new height.
697              */
698             'bodyresize',
699             /**
700              * @event titlechange
701              * Fires after the Panel title has been {@link #title set} or {@link #setTitle changed}.
702              * @param {Ext.Panel} p the Panel which has had its title changed.
703              * @param {String} The new title.
704              */
705             'titlechange',
706             /**
707              * @event iconchange
708              * Fires after the Panel icon class has been {@link #iconCls set} or {@link #setIconClass changed}.
709              * @param {Ext.Panel} p the Panel which has had its {@link #iconCls icon class} changed.
710              * @param {String} The new icon class.
711              * @param {String} The old icon class.
712              */
713             'iconchange',
714             /**
715              * @event collapse
716              * Fires after the Panel has been collapsed.
717              * @param {Ext.Panel} p the Panel that has been collapsed.
718              */
719             'collapse',
720             /**
721              * @event expand
722              * Fires after the Panel has been expanded.
723              * @param {Ext.Panel} p The Panel that has been expanded.
724              */
725             'expand',
726             /**
727              * @event beforecollapse
728              * Fires before the Panel is collapsed.  A handler can return false to cancel the collapse.
729              * @param {Ext.Panel} p the Panel being collapsed.
730              * @param {Boolean} animate True if the collapse is animated, else false.
731              */
732             'beforecollapse',
733             /**
734              * @event beforeexpand
735              * Fires before the Panel is expanded.  A handler can return false to cancel the expand.
736              * @param {Ext.Panel} p The Panel being expanded.
737              * @param {Boolean} animate True if the expand is animated, else false.
738              */
739             'beforeexpand',
740             /**
741              * @event beforeclose
742              * Fires before the Panel is closed.  Note that Panels do not directly support being closed, but some
743              * Panel subclasses do (like {@link Ext.Window}) or a Panel within a Ext.TabPanel.  This event only
744              * applies to such subclasses.
745              * A handler can return false to cancel the close.
746              * @param {Ext.Panel} p The Panel being closed.
747              */
748             'beforeclose',
749             /**
750              * @event close
751              * Fires after the Panel is closed.  Note that Panels do not directly support being closed, but some
752              * Panel subclasses do (like {@link Ext.Window}) or a Panel within a Ext.TabPanel.
753              * @param {Ext.Panel} p The Panel that has been closed.
754              */
755             'close',
756             /**
757              * @event activate
758              * Fires after the Panel has been visually activated.
759              * Note that Panels do not directly support being activated, but some Panel subclasses
760              * do (like {@link Ext.Window}). Panels which are child Components of a TabPanel fire the
761              * activate and deactivate events under the control of the TabPanel.
762              * @param {Ext.Panel} p The Panel that has been activated.
763              */
764             'activate',
765             /**
766              * @event deactivate
767              * Fires after the Panel has been visually deactivated.
768              * Note that Panels do not directly support being deactivated, but some Panel subclasses
769              * do (like {@link Ext.Window}). Panels which are child Components of a TabPanel fire the
770              * activate and deactivate events under the control of the TabPanel.
771              * @param {Ext.Panel} p The Panel that has been deactivated.
772              */
773             'deactivate'
774         );
775
776         if(this.unstyled){
777             this.baseCls = 'x-plain';
778         }
779
780
781         this.toolbars = [];
782         // shortcuts
783         if(this.tbar){
784             this.elements += ',tbar';
785             this.topToolbar = this.createToolbar(this.tbar);
786             this.tbar = null;
787
788         }
789         if(this.bbar){
790             this.elements += ',bbar';
791             this.bottomToolbar = this.createToolbar(this.bbar);
792             this.bbar = null;
793         }
794
795         if(this.header === true){
796             this.elements += ',header';
797             this.header = null;
798         }else if(this.headerCfg || (this.title && this.header !== false)){
799             this.elements += ',header';
800         }
801
802         if(this.footerCfg || this.footer === true){
803             this.elements += ',footer';
804             this.footer = null;
805         }
806
807         if(this.buttons){
808             this.fbar = this.buttons;
809             this.buttons = null;
810         }
811         if(this.fbar){
812             this.createFbar(this.fbar);
813         }
814         if(this.autoLoad){
815             this.on('render', this.doAutoLoad, this, {delay:10});
816         }
817     },
818
819     // private
820     createFbar : function(fbar){
821         var min = this.minButtonWidth;
822         this.elements += ',footer';
823         this.fbar = this.createToolbar(fbar, {
824             buttonAlign: this.buttonAlign,
825             toolbarCls: 'x-panel-fbar',
826             enableOverflow: false,
827             defaults: function(c){
828                 return {
829                     minWidth: c.minWidth || min
830                 };
831             }
832         });
833         // @compat addButton and buttons could possibly be removed
834         // @target 4.0
835         /**
836          * This Panel's Array of buttons as created from the <code>{@link #buttons}</code>
837          * config property. Read only.
838          * @type Array
839          * @property buttons
840          */
841         this.fbar.items.each(function(c){
842             c.minWidth = c.minWidth || this.minButtonWidth;
843         }, this);
844         this.buttons = this.fbar.items.items;
845     },
846
847     // private
848     createToolbar: function(tb, options){
849         var result;
850         // Convert array to proper toolbar config
851         if(Ext.isArray(tb)){
852             tb = {
853                 items: tb
854             };
855         }
856         result = tb.events ? Ext.apply(tb, options) : this.createComponent(Ext.apply({}, tb, options), 'toolbar');
857         this.toolbars.push(result);
858         return result;
859     },
860
861     // private
862     createElement : function(name, pnode){
863         if(this[name]){
864             pnode.appendChild(this[name].dom);
865             return;
866         }
867
868         if(name === 'bwrap' || this.elements.indexOf(name) != -1){
869             if(this[name+'Cfg']){
870                 this[name] = Ext.fly(pnode).createChild(this[name+'Cfg']);
871             }else{
872                 var el = document.createElement('div');
873                 el.className = this[name+'Cls'];
874                 this[name] = Ext.get(pnode.appendChild(el));
875             }
876             if(this[name+'CssClass']){
877                 this[name].addClass(this[name+'CssClass']);
878             }
879             if(this[name+'Style']){
880                 this[name].applyStyles(this[name+'Style']);
881             }
882         }
883     },
884
885     // private
886     onRender : function(ct, position){
887         Ext.Panel.superclass.onRender.call(this, ct, position);
888         this.createClasses();
889
890         var el = this.el,
891             d = el.dom,
892             bw,
893             ts;
894
895
896         if(this.collapsible && !this.hideCollapseTool){
897             this.tools = this.tools ? this.tools.slice(0) : [];
898             this.tools[this.collapseFirst?'unshift':'push']({
899                 id: 'toggle',
900                 handler : this.toggleCollapse,
901                 scope: this
902             });
903         }
904
905         if(this.tools){
906             ts = this.tools;
907             this.elements += (this.header !== false) ? ',header' : '';
908         }
909         this.tools = {};
910
911         el.addClass(this.baseCls);
912         if(d.firstChild){ // existing markup
913             this.header = el.down('.'+this.headerCls);
914             this.bwrap = el.down('.'+this.bwrapCls);
915             var cp = this.bwrap ? this.bwrap : el;
916             this.tbar = cp.down('.'+this.tbarCls);
917             this.body = cp.down('.'+this.bodyCls);
918             this.bbar = cp.down('.'+this.bbarCls);
919             this.footer = cp.down('.'+this.footerCls);
920             this.fromMarkup = true;
921         }
922         if (this.preventBodyReset === true) {
923             el.addClass('x-panel-reset');
924         }
925         if(this.cls){
926             el.addClass(this.cls);
927         }
928
929         if(this.buttons){
930             this.elements += ',footer';
931         }
932
933         // This block allows for maximum flexibility and performance when using existing markup
934
935         // framing requires special markup
936         if(this.frame){
937             el.insertHtml('afterBegin', String.format(Ext.Element.boxMarkup, this.baseCls));
938
939             this.createElement('header', d.firstChild.firstChild.firstChild);
940             this.createElement('bwrap', d);
941
942             // append the mid and bottom frame to the bwrap
943             bw = this.bwrap.dom;
944             var ml = d.childNodes[1], bl = d.childNodes[2];
945             bw.appendChild(ml);
946             bw.appendChild(bl);
947
948             var mc = bw.firstChild.firstChild.firstChild;
949             this.createElement('tbar', mc);
950             this.createElement('body', mc);
951             this.createElement('bbar', mc);
952             this.createElement('footer', bw.lastChild.firstChild.firstChild);
953
954             if(!this.footer){
955                 this.bwrap.dom.lastChild.className += ' x-panel-nofooter';
956             }
957             /*
958              * Store a reference to this element so:
959              * a) We aren't looking it up all the time
960              * b) The last element is reported incorrectly when using a loadmask
961              */
962             this.ft = Ext.get(this.bwrap.dom.lastChild);
963             this.mc = Ext.get(mc);
964         }else{
965             this.createElement('header', d);
966             this.createElement('bwrap', d);
967
968             // append the mid and bottom frame to the bwrap
969             bw = this.bwrap.dom;
970             this.createElement('tbar', bw);
971             this.createElement('body', bw);
972             this.createElement('bbar', bw);
973             this.createElement('footer', bw);
974
975             if(!this.header){
976                 this.body.addClass(this.bodyCls + '-noheader');
977                 if(this.tbar){
978                     this.tbar.addClass(this.tbarCls + '-noheader');
979                 }
980             }
981         }
982
983         if(Ext.isDefined(this.padding)){
984             this.body.setStyle('padding', this.body.addUnits(this.padding));
985         }
986
987         if(this.border === false){
988             this.el.addClass(this.baseCls + '-noborder');
989             this.body.addClass(this.bodyCls + '-noborder');
990             if(this.header){
991                 this.header.addClass(this.headerCls + '-noborder');
992             }
993             if(this.footer){
994                 this.footer.addClass(this.footerCls + '-noborder');
995             }
996             if(this.tbar){
997                 this.tbar.addClass(this.tbarCls + '-noborder');
998             }
999             if(this.bbar){
1000                 this.bbar.addClass(this.bbarCls + '-noborder');
1001             }
1002         }
1003
1004         if(this.bodyBorder === false){
1005            this.body.addClass(this.bodyCls + '-noborder');
1006         }
1007
1008         this.bwrap.enableDisplayMode('block');
1009
1010         if(this.header){
1011             this.header.unselectable();
1012
1013             // for tools, we need to wrap any existing header markup
1014             if(this.headerAsText){
1015                 this.header.dom.innerHTML =
1016                     '<span class="' + this.headerTextCls + '">'+this.header.dom.innerHTML+'</span>';
1017
1018                 if(this.iconCls){
1019                     this.setIconClass(this.iconCls);
1020                 }
1021             }
1022         }
1023
1024         if(this.floating){
1025             this.makeFloating(this.floating);
1026         }
1027
1028         if(this.collapsible && this.titleCollapse && this.header){
1029             this.mon(this.header, 'click', this.toggleCollapse, this);
1030             this.header.setStyle('cursor', 'pointer');
1031         }
1032         if(ts){
1033             this.addTool.apply(this, ts);
1034         }
1035
1036         // Render Toolbars.
1037         if(this.fbar){
1038             this.footer.addClass('x-panel-btns');
1039             this.fbar.ownerCt = this;
1040             this.fbar.render(this.footer);
1041             this.footer.createChild({cls:'x-clear'});
1042         }
1043         if(this.tbar && this.topToolbar){
1044             this.topToolbar.ownerCt = this;
1045             this.topToolbar.render(this.tbar);
1046         }
1047         if(this.bbar && this.bottomToolbar){
1048             this.bottomToolbar.ownerCt = this;
1049             this.bottomToolbar.render(this.bbar);
1050         }
1051     },
1052
1053     /**
1054      * Sets the CSS class that provides the icon image for this panel.  This method will replace any existing
1055      * icon class if one has already been set and fire the {@link #iconchange} event after completion.
1056      * @param {String} cls The new CSS class name
1057      */
1058     setIconClass : function(cls){
1059         var old = this.iconCls;
1060         this.iconCls = cls;
1061         if(this.rendered && this.header){
1062             if(this.frame){
1063                 this.header.addClass('x-panel-icon');
1064                 this.header.replaceClass(old, this.iconCls);
1065             }else{
1066                 var hd = this.header,
1067                     img = hd.child('img.x-panel-inline-icon');
1068                 if(img){
1069                     Ext.fly(img).replaceClass(old, this.iconCls);
1070                 }else{
1071                     var hdspan = hd.child('span.' + this.headerTextCls);
1072                     if (hdspan) {
1073                         Ext.DomHelper.insertBefore(hdspan.dom, {
1074                             tag:'img', alt: '', src: Ext.BLANK_IMAGE_URL, cls:'x-panel-inline-icon '+this.iconCls
1075                         });
1076                     }
1077                  }
1078             }
1079         }
1080         this.fireEvent('iconchange', this, cls, old);
1081     },
1082
1083     // private
1084     makeFloating : function(cfg){
1085         this.floating = true;
1086         this.el = new Ext.Layer(Ext.apply({}, cfg, {
1087             shadow: Ext.isDefined(this.shadow) ? this.shadow : 'sides',
1088             shadowOffset: this.shadowOffset,
1089             constrain:false,
1090             shim: this.shim === false ? false : undefined
1091         }), this.el);
1092     },
1093
1094     /**
1095      * Returns the {@link Ext.Toolbar toolbar} from the top (<code>{@link #tbar}</code>) section of the panel.
1096      * @return {Ext.Toolbar} The toolbar
1097      */
1098     getTopToolbar : function(){
1099         return this.topToolbar;
1100     },
1101
1102     /**
1103      * Returns the {@link Ext.Toolbar toolbar} from the bottom (<code>{@link #bbar}</code>) section of the panel.
1104      * @return {Ext.Toolbar} The toolbar
1105      */
1106     getBottomToolbar : function(){
1107         return this.bottomToolbar;
1108     },
1109
1110     /**
1111      * Returns the {@link Ext.Toolbar toolbar} from the footer (<code>{@link #fbar}</code>) section of the panel.
1112      * @return {Ext.Toolbar} The toolbar
1113      */
1114     getFooterToolbar : function() {
1115         return this.fbar;
1116     },
1117
1118     /**
1119      * Adds a button to this panel.  Note that this method must be called prior to rendering.  The preferred
1120      * approach is to add buttons via the {@link #buttons} config.
1121      * @param {String/Object} config A valid {@link Ext.Button} config.  A string will become the text for a default
1122      * button config, an object will be treated as a button config object.
1123      * @param {Function} handler The function to be called on button {@link Ext.Button#click}
1124      * @param {Object} scope The scope (<code>this</code> reference) in which the button handler function is executed. Defaults to the Button.
1125      * @return {Ext.Button} The button that was added
1126      */
1127     addButton : function(config, handler, scope){
1128         if(!this.fbar){
1129             this.createFbar([]);
1130         }
1131         if(handler){
1132             if(Ext.isString(config)){
1133                 config = {text: config};
1134             }
1135             config = Ext.apply({
1136                 handler: handler,
1137                 scope: scope
1138             }, config);
1139         }
1140         return this.fbar.add(config);
1141     },
1142
1143     // private
1144     addTool : function(){
1145         if(!this.rendered){
1146             if(!this.tools){
1147                 this.tools = [];
1148             }
1149             Ext.each(arguments, function(arg){
1150                 this.tools.push(arg);
1151             }, this);
1152             return;
1153         }
1154          // nowhere to render tools!
1155         if(!this[this.toolTarget]){
1156             return;
1157         }
1158         if(!this.toolTemplate){
1159             // initialize the global tool template on first use
1160             var tt = new Ext.Template(
1161                  '<div class="x-tool x-tool-{id}">&#160;</div>'
1162             );
1163             tt.disableFormats = true;
1164             tt.compile();
1165             Ext.Panel.prototype.toolTemplate = tt;
1166         }
1167         for(var i = 0, a = arguments, len = a.length; i < len; i++) {
1168             var tc = a[i];
1169             if(!this.tools[tc.id]){
1170                 var overCls = 'x-tool-'+tc.id+'-over';
1171                 var t = this.toolTemplate.insertFirst(this[this.toolTarget], tc, true);
1172                 this.tools[tc.id] = t;
1173                 t.enableDisplayMode('block');
1174                 this.mon(t, 'click',  this.createToolHandler(t, tc, overCls, this));
1175                 if(tc.on){
1176                     this.mon(t, tc.on);
1177                 }
1178                 if(tc.hidden){
1179                     t.hide();
1180                 }
1181                 if(tc.qtip){
1182                     if(Ext.isObject(tc.qtip)){
1183                         Ext.QuickTips.register(Ext.apply({
1184                               target: t.id
1185                         }, tc.qtip));
1186                     } else {
1187                         t.dom.qtip = tc.qtip;
1188                     }
1189                 }
1190                 t.addClassOnOver(overCls);
1191             }
1192         }
1193     },
1194
1195     onLayout : function(shallow, force){
1196         Ext.Panel.superclass.onLayout.apply(this, arguments);
1197         if(this.hasLayout && this.toolbars.length > 0){
1198             Ext.each(this.toolbars, function(tb){
1199                 tb.doLayout(undefined, force);
1200             });
1201             this.syncHeight();
1202         }
1203     },
1204
1205     syncHeight : function(){
1206         var h = this.toolbarHeight,
1207                 bd = this.body,
1208                 lsh = this.lastSize.height,
1209                 sz;
1210
1211         if(this.autoHeight || !Ext.isDefined(lsh) || lsh == 'auto'){
1212             return;
1213         }
1214
1215
1216         if(h != this.getToolbarHeight()){
1217             h = Math.max(0, lsh - this.getFrameHeight());
1218             bd.setHeight(h);
1219             sz = bd.getSize();
1220             this.toolbarHeight = this.getToolbarHeight();
1221             this.onBodyResize(sz.width, sz.height);
1222         }
1223     },
1224
1225     // private
1226     onShow : function(){
1227         if(this.floating){
1228             return this.el.show();
1229         }
1230         Ext.Panel.superclass.onShow.call(this);
1231     },
1232
1233     // private
1234     onHide : function(){
1235         if(this.floating){
1236             return this.el.hide();
1237         }
1238         Ext.Panel.superclass.onHide.call(this);
1239     },
1240
1241     // private
1242     createToolHandler : function(t, tc, overCls, panel){
1243         return function(e){
1244             t.removeClass(overCls);
1245             if(tc.stopEvent !== false){
1246                 e.stopEvent();
1247             }
1248             if(tc.handler){
1249                 tc.handler.call(tc.scope || t, e, t, panel, tc);
1250             }
1251         };
1252     },
1253
1254     // private
1255     afterRender : function(){
1256         if(this.floating && !this.hidden){
1257             this.el.show();
1258         }
1259         if(this.title){
1260             this.setTitle(this.title);
1261         }
1262         Ext.Panel.superclass.afterRender.call(this); // do sizing calcs last
1263         if (this.collapsed) {
1264             this.collapsed = false;
1265             this.collapse(false);
1266         }
1267         this.initEvents();
1268     },
1269
1270     // private
1271     getKeyMap : function(){
1272         if(!this.keyMap){
1273             this.keyMap = new Ext.KeyMap(this.el, this.keys);
1274         }
1275         return this.keyMap;
1276     },
1277
1278     // private
1279     initEvents : function(){
1280         if(this.keys){
1281             this.getKeyMap();
1282         }
1283         if(this.draggable){
1284             this.initDraggable();
1285         }
1286         if(this.toolbars.length > 0){
1287             Ext.each(this.toolbars, function(tb){
1288                 tb.doLayout();
1289                 tb.on({
1290                     scope: this,
1291                     afterlayout: this.syncHeight,
1292                     remove: this.syncHeight
1293                 });
1294             }, this);
1295             this.syncHeight();
1296         }
1297
1298     },
1299
1300     // private
1301     initDraggable : function(){
1302         /**
1303          * <p>If this Panel is configured {@link #draggable}, this property will contain
1304          * an instance of {@link Ext.dd.DragSource} which handles dragging the Panel.</p>
1305          * The developer must provide implementations of the abstract methods of {@link Ext.dd.DragSource}
1306          * in order to supply behaviour for each stage of the drag/drop process. See {@link #draggable}.
1307          * @type Ext.dd.DragSource.
1308          * @property dd
1309          */
1310         this.dd = new Ext.Panel.DD(this, Ext.isBoolean(this.draggable) ? null : this.draggable);
1311     },
1312
1313     // private
1314     beforeEffect : function(anim){
1315         if(this.floating){
1316             this.el.beforeAction();
1317         }
1318         if(anim !== false){
1319             this.el.addClass('x-panel-animated');
1320         }
1321     },
1322
1323     // private
1324     afterEffect : function(anim){
1325         this.syncShadow();
1326         this.el.removeClass('x-panel-animated');
1327     },
1328
1329     // private - wraps up an animation param with internal callbacks
1330     createEffect : function(a, cb, scope){
1331         var o = {
1332             scope:scope,
1333             block:true
1334         };
1335         if(a === true){
1336             o.callback = cb;
1337             return o;
1338         }else if(!a.callback){
1339             o.callback = cb;
1340         }else { // wrap it up
1341             o.callback = function(){
1342                 cb.call(scope);
1343                 Ext.callback(a.callback, a.scope);
1344             };
1345         }
1346         return Ext.applyIf(o, a);
1347     },
1348
1349     /**
1350      * Collapses the panel body so that it becomes hidden.  Fires the {@link #beforecollapse} event which will
1351      * cancel the collapse action if it returns false.
1352      * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
1353      * {@link #animCollapse} panel config)
1354      * @return {Ext.Panel} this
1355      */
1356     collapse : function(animate){
1357         if(this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforecollapse', this, animate) === false){
1358             return;
1359         }
1360         var doAnim = animate === true || (animate !== false && this.animCollapse);
1361         this.beforeEffect(doAnim);
1362         this.onCollapse(doAnim, animate);
1363         return this;
1364     },
1365
1366     // private
1367     onCollapse : function(doAnim, animArg){
1368         if(doAnim){
1369             this[this.collapseEl].slideOut(this.slideAnchor,
1370                     Ext.apply(this.createEffect(animArg||true, this.afterCollapse, this),
1371                         this.collapseDefaults));
1372         }else{
1373             this[this.collapseEl].hide(this.hideMode);
1374             this.afterCollapse(false);
1375         }
1376     },
1377
1378     // private
1379     afterCollapse : function(anim){
1380         this.collapsed = true;
1381         this.el.addClass(this.collapsedCls);
1382         if(anim !== false){
1383             this[this.collapseEl].hide(this.hideMode);
1384         }
1385         this.afterEffect(anim);
1386
1387         // Reset lastSize of all sub-components so they KNOW they are in a collapsed container
1388         this.cascade(function(c) {
1389             if (c.lastSize) {
1390                 c.lastSize = { width: undefined, height: undefined };
1391             }
1392         });
1393         this.fireEvent('collapse', this);
1394     },
1395
1396     /**
1397      * Expands the panel body so that it becomes visible.  Fires the {@link #beforeexpand} event which will
1398      * cancel the expand action if it returns false.
1399      * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
1400      * {@link #animCollapse} panel config)
1401      * @return {Ext.Panel} this
1402      */
1403     expand : function(animate){
1404         if(!this.collapsed || this.el.hasFxBlock() || this.fireEvent('beforeexpand', this, animate) === false){
1405             return;
1406         }
1407         var doAnim = animate === true || (animate !== false && this.animCollapse);
1408         this.el.removeClass(this.collapsedCls);
1409         this.beforeEffect(doAnim);
1410         this.onExpand(doAnim, animate);
1411         return this;
1412     },
1413
1414     // private
1415     onExpand : function(doAnim, animArg){
1416         if(doAnim){
1417             this[this.collapseEl].slideIn(this.slideAnchor,
1418                     Ext.apply(this.createEffect(animArg||true, this.afterExpand, this),
1419                         this.expandDefaults));
1420         }else{
1421             this[this.collapseEl].show(this.hideMode);
1422             this.afterExpand(false);
1423         }
1424     },
1425
1426     // private
1427     afterExpand : function(anim){
1428         this.collapsed = false;
1429         if(anim !== false){
1430             this[this.collapseEl].show(this.hideMode);
1431         }
1432         this.afterEffect(anim);
1433         if (this.deferLayout) {
1434             delete this.deferLayout;
1435             this.doLayout(true);
1436         }
1437         this.fireEvent('expand', this);
1438     },
1439
1440     /**
1441      * Shortcut for performing an {@link #expand} or {@link #collapse} based on the current state of the panel.
1442      * @param {Boolean} animate True to animate the transition, else false (defaults to the value of the
1443      * {@link #animCollapse} panel config)
1444      * @return {Ext.Panel} this
1445      */
1446     toggleCollapse : function(animate){
1447         this[this.collapsed ? 'expand' : 'collapse'](animate);
1448         return this;
1449     },
1450
1451     // private
1452     onDisable : function(){
1453         if(this.rendered && this.maskDisabled){
1454             this.el.mask();
1455         }
1456         Ext.Panel.superclass.onDisable.call(this);
1457     },
1458
1459     // private
1460     onEnable : function(){
1461         if(this.rendered && this.maskDisabled){
1462             this.el.unmask();
1463         }
1464         Ext.Panel.superclass.onEnable.call(this);
1465     },
1466
1467     // private
1468     onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
1469         var w = adjWidth,
1470             h = adjHeight;
1471
1472         if(Ext.isDefined(w) || Ext.isDefined(h)){
1473             if(!this.collapsed){
1474                 // First, set the the Panel's body width.
1475                 // If we have auto-widthed it, get the resulting full offset width so we can size the Toolbars to match
1476                 // The Toolbars must not buffer this resize operation because we need to know their heights.
1477
1478                 if(Ext.isNumber(w)){
1479                     this.body.setWidth(w = this.adjustBodyWidth(w - this.getFrameWidth()));
1480                 } else if (w == 'auto') {
1481                     w = this.body.setWidth('auto').dom.offsetWidth;
1482                 } else {
1483                     w = this.body.dom.offsetWidth;
1484                 }
1485
1486                 if(this.tbar){
1487                     this.tbar.setWidth(w);
1488                     if(this.topToolbar){
1489                         this.topToolbar.setSize(w);
1490                     }
1491                 }
1492                 if(this.bbar){
1493                     this.bbar.setWidth(w);
1494                     if(this.bottomToolbar){
1495                         this.bottomToolbar.setSize(w);
1496                         // The bbar does not move on resize without this.
1497                         if (Ext.isIE) {
1498                             this.bbar.setStyle('position', 'static');
1499                             this.bbar.setStyle('position', '');
1500                         }
1501                     }
1502                 }
1503                 if(this.footer){
1504                     this.footer.setWidth(w);
1505                     if(this.fbar){
1506                         this.fbar.setSize(Ext.isIE ? (w - this.footer.getFrameWidth('lr')) : 'auto');
1507                     }
1508                 }
1509
1510                 // At this point, the Toolbars must be layed out for getFrameHeight to find a result.
1511                 if(Ext.isNumber(h)){
1512                     h = Math.max(0, h - this.getFrameHeight());
1513                     //h = Math.max(0, h - (this.getHeight() - this.body.getHeight()));
1514                     this.body.setHeight(h);
1515                 }else if(h == 'auto'){
1516                     this.body.setHeight(h);
1517                 }
1518
1519                 if(this.disabled && this.el._mask){
1520                     this.el._mask.setSize(this.el.dom.clientWidth, this.el.getHeight());
1521                 }
1522             }else{
1523                 // Adds an event to set the correct height afterExpand.  This accounts for the deferHeight flag in panel
1524                 this.queuedBodySize = {width: w, height: h};
1525                 if(!this.queuedExpand && this.allowQueuedExpand !== false){
1526                     this.queuedExpand = true;
1527                     this.on('expand', function(){
1528                         delete this.queuedExpand;
1529                         this.onResize(this.queuedBodySize.width, this.queuedBodySize.height);
1530                     }, this, {single:true});
1531                 }
1532             }
1533             this.onBodyResize(w, h);
1534         }
1535         this.syncShadow();
1536         Ext.Panel.superclass.onResize.call(this, adjWidth, adjHeight, rawWidth, rawHeight);
1537
1538     },
1539
1540     // private
1541     onBodyResize: function(w, h){
1542         this.fireEvent('bodyresize', this, w, h);
1543     },
1544
1545     // private
1546     getToolbarHeight: function(){
1547         var h = 0;
1548         if(this.rendered){
1549             Ext.each(this.toolbars, function(tb){
1550                 h += tb.getHeight();
1551             }, this);
1552         }
1553         return h;
1554     },
1555
1556     // deprecate
1557     adjustBodyHeight : function(h){
1558         return h;
1559     },
1560
1561     // private
1562     adjustBodyWidth : function(w){
1563         return w;
1564     },
1565
1566     // private
1567     onPosition : function(){
1568         this.syncShadow();
1569     },
1570
1571     /**
1572      * Returns the width in pixels of the framing elements of this panel (not including the body width).  To
1573      * retrieve the body width see {@link #getInnerWidth}.
1574      * @return {Number} The frame width
1575      */
1576     getFrameWidth : function(){
1577         var w = this.el.getFrameWidth('lr') + this.bwrap.getFrameWidth('lr');
1578
1579         if(this.frame){
1580             var l = this.bwrap.dom.firstChild;
1581             w += (Ext.fly(l).getFrameWidth('l') + Ext.fly(l.firstChild).getFrameWidth('r'));
1582             w += this.mc.getFrameWidth('lr');
1583         }
1584         return w;
1585     },
1586
1587     /**
1588      * Returns the height in pixels of the framing elements of this panel (including any top and bottom bars and
1589      * header and footer elements, but not including the body height).  To retrieve the body height see {@link #getInnerHeight}.
1590      * @return {Number} The frame height
1591      */
1592     getFrameHeight : function() {
1593         var h  = this.el.getFrameWidth('tb') + this.bwrap.getFrameWidth('tb');
1594         h += (this.tbar ? this.tbar.getHeight() : 0) +
1595              (this.bbar ? this.bbar.getHeight() : 0);
1596
1597         if(this.frame){
1598             h += this.el.dom.firstChild.offsetHeight + this.ft.dom.offsetHeight + this.mc.getFrameWidth('tb');
1599         }else{
1600             h += (this.header ? this.header.getHeight() : 0) +
1601                 (this.footer ? this.footer.getHeight() : 0);
1602         }
1603         return h;
1604     },
1605
1606     /**
1607      * Returns the width in pixels of the body element (not including the width of any framing elements).
1608      * For the frame width see {@link #getFrameWidth}.
1609      * @return {Number} The body width
1610      */
1611     getInnerWidth : function(){
1612         return this.getSize().width - this.getFrameWidth();
1613     },
1614
1615     /**
1616      * Returns the height in pixels of the body element (not including the height of any framing elements).
1617      * For the frame height see {@link #getFrameHeight}.
1618      * @return {Number} The body height
1619      */
1620     getInnerHeight : function(){
1621         return this.body.getHeight();
1622         /* Deprecate
1623             return this.getSize().height - this.getFrameHeight();
1624         */
1625     },
1626
1627     // private
1628     syncShadow : function(){
1629         if(this.floating){
1630             this.el.sync(true);
1631         }
1632     },
1633
1634     // private
1635     getLayoutTarget : function(){
1636         return this.body;
1637     },
1638
1639     // private
1640     getContentTarget : function(){
1641         return this.body;
1642     },
1643
1644     /**
1645      * <p>Sets the title text for the panel and optionally the {@link #iconCls icon class}.</p>
1646      * <p>In order to be able to set the title, a header element must have been created
1647      * for the Panel. This is triggered either by configuring the Panel with a non-blank <code>{@link #title}</code>,
1648      * or configuring it with <code><b>{@link #header}: true</b></code>.</p>
1649      * @param {String} title The title text to set
1650      * @param {String} iconCls (optional) {@link #iconCls iconCls} A user-defined CSS class that provides the icon image for this panel
1651      */
1652     setTitle : function(title, iconCls){
1653         this.title = title;
1654         if(this.header && this.headerAsText){
1655             this.header.child('span').update(title);
1656         }
1657         if(iconCls){
1658             this.setIconClass(iconCls);
1659         }
1660         this.fireEvent('titlechange', this, title);
1661         return this;
1662     },
1663
1664     /**
1665      * Get the {@link Ext.Updater} for this panel. Enables you to perform Ajax updates of this panel's body.
1666      * @return {Ext.Updater} The Updater
1667      */
1668     getUpdater : function(){
1669         return this.body.getUpdater();
1670     },
1671
1672      /**
1673      * Loads this content panel immediately with content returned from an XHR call.
1674      * @param {Object/String/Function} config A config object containing any of the following options:
1675 <pre><code>
1676 panel.load({
1677     url: 'your-url.php',
1678     params: {param1: 'foo', param2: 'bar'}, // or a URL encoded string
1679     callback: yourFunction,
1680     scope: yourObject, // optional scope for the callback
1681     discardUrl: false,
1682     nocache: false,
1683     text: 'Loading...',
1684     timeout: 30,
1685     scripts: false
1686 });
1687 </code></pre>
1688      * The only required property is url. The optional properties nocache, text and scripts
1689      * are shorthand for disableCaching, indicatorText and loadScripts and are used to set their
1690      * associated property on this panel Updater instance.
1691      * @return {Ext.Panel} this
1692      */
1693     load : function(){
1694         var um = this.body.getUpdater();
1695         um.update.apply(um, arguments);
1696         return this;
1697     },
1698
1699     // private
1700     beforeDestroy : function(){
1701         Ext.Panel.superclass.beforeDestroy.call(this);
1702         if(this.header){
1703             this.header.removeAllListeners();
1704         }
1705         if(this.tools){
1706             for(var k in this.tools){
1707                 Ext.destroy(this.tools[k]);
1708             }
1709         }
1710         if(this.toolbars.length > 0){
1711             Ext.each(this.toolbars, function(tb){
1712                 tb.un('afterlayout', this.syncHeight, this);
1713                 tb.un('remove', this.syncHeight, this);
1714             }, this);
1715         }
1716         if(Ext.isArray(this.buttons)){
1717             while(this.buttons.length) {
1718                 Ext.destroy(this.buttons[0]);
1719             }
1720         }
1721         if(this.rendered){
1722             Ext.destroy(
1723                 this.ft,
1724                 this.header,
1725                 this.footer,
1726                 this.tbar,
1727                 this.bbar,
1728                 this.body,
1729                 this.mc,
1730                 this.bwrap,
1731                 this.dd
1732             );
1733             if (this.fbar) {
1734                 Ext.destroy(
1735                     this.fbar,
1736                     this.fbar.el
1737                 );
1738             }
1739         }
1740         Ext.destroy(this.toolbars);
1741     },
1742
1743     // private
1744     createClasses : function(){
1745         this.headerCls = this.baseCls + '-header';
1746         this.headerTextCls = this.baseCls + '-header-text';
1747         this.bwrapCls = this.baseCls + '-bwrap';
1748         this.tbarCls = this.baseCls + '-tbar';
1749         this.bodyCls = this.baseCls + '-body';
1750         this.bbarCls = this.baseCls + '-bbar';
1751         this.footerCls = this.baseCls + '-footer';
1752     },
1753
1754     // private
1755     createGhost : function(cls, useShim, appendTo){
1756         var el = document.createElement('div');
1757         el.className = 'x-panel-ghost ' + (cls ? cls : '');
1758         if(this.header){
1759             el.appendChild(this.el.dom.firstChild.cloneNode(true));
1760         }
1761         Ext.fly(el.appendChild(document.createElement('ul'))).setHeight(this.bwrap.getHeight());
1762         el.style.width = this.el.dom.offsetWidth + 'px';;
1763         if(!appendTo){
1764             this.container.dom.appendChild(el);
1765         }else{
1766             Ext.getDom(appendTo).appendChild(el);
1767         }
1768         if(useShim !== false && this.el.useShim !== false){
1769             var layer = new Ext.Layer({shadow:false, useDisplay:true, constrain:false}, el);
1770             layer.show();
1771             return layer;
1772         }else{
1773             return new Ext.Element(el);
1774         }
1775     },
1776
1777     // private
1778     doAutoLoad : function(){
1779         var u = this.body.getUpdater();
1780         if(this.renderer){
1781             u.setRenderer(this.renderer);
1782         }
1783         u.update(Ext.isObject(this.autoLoad) ? this.autoLoad : {url: this.autoLoad});
1784     },
1785
1786     /**
1787      * Retrieve a tool by id.
1788      * @param {String} id
1789      * @return {Object} tool
1790      */
1791     getTool : function(id) {
1792         return this.tools[id];
1793     }
1794
1795 /**
1796  * @cfg {String} autoEl @hide
1797  */
1798 });
1799 Ext.reg('panel', Ext.Panel);