Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / CardLayout.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js"><div id="cls-Ext.layout.CardLayout"></div>/**\r
9  * @class Ext.layout.CardLayout\r
10  * @extends Ext.layout.FitLayout\r
11  * <p>This layout manages multiple child Components, each fitted to the Container, where only a single child Component can be\r
12  * visible at any given time.  This layout style is most commonly used for wizards, tab implementations, etc.\r
13  * This class is intended to be extended or created via the layout:'card' {@link Ext.Container#layout} config,\r
14  * and should generally not need to be created directly via the new keyword.</p>\r
15  * <p>The CardLayout's focal method is {@link #setActiveItem}.  Since only one panel is displayed at a time,\r
16  * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of\r
17  * the next panel to display.  The layout itself does not provide a user interface for handling this navigation,\r
18  * so that functionality must be provided by the developer.</p>\r
19  * <p>In the following example, a simplistic wizard setup is demonstrated.  A button bar is added\r
20  * to the footer of the containing panel to provide navigation buttons.  The buttons will be handled by a\r
21  * common navigation routine -- for this example, the implementation of that routine has been ommitted since\r
22  * it can be any type of custom logic.  Note that other uses of a CardLayout (like a tab control) would require a\r
23  * completely different implementation.  For serious implementations, a better approach would be to extend\r
24  * CardLayout to provide the custom functionality needed.  Example usage:</p>\r
25  * <pre><code>\r
26 var navHandler = function(direction){\r
27     // This routine could contain business logic required to manage the navigation steps.\r
28     // It would call setActiveItem as needed, manage navigation button state, handle any\r
29     // branching logic that might be required, handle alternate actions like cancellation\r
30     // or finalization, etc.  A complete wizard implementation could get pretty\r
31     // sophisticated depending on the complexity required, and should probably be\r
32     // done as a subclass of CardLayout in a real-world implementation.\r
33 };\r
34 \r
35 var card = new Ext.Panel({\r
36     title: 'Example Wizard',\r
37     layout:'card',\r
38     activeItem: 0, // make sure the active item is set on the container config!\r
39     bodyStyle: 'padding:15px',\r
40     defaults: {\r
41         // applied to each contained panel\r
42         border:false\r
43     },\r
44     // just an example of one possible navigation scheme, using buttons\r
45     bbar: [\r
46         {\r
47             id: 'move-prev',\r
48             text: 'Back',\r
49             handler: navHandler.createDelegate(this, [-1]),\r
50             disabled: true\r
51         },\r
52         '->', // greedy spacer so that the buttons are aligned to each side\r
53         {\r
54             id: 'move-next',\r
55             text: 'Next',\r
56             handler: navHandler.createDelegate(this, [1])\r
57         }\r
58     ],\r
59     // the panels (or "cards") within the layout\r
60     items: [{\r
61         id: 'card-0',\r
62         html: '&lt;h1&gt;Welcome to the Wizard!&lt;/h1&gt;&lt;p&gt;Step 1 of 3&lt;/p&gt;'\r
63     },{\r
64         id: 'card-1',\r
65         html: '&lt;p&gt;Step 2 of 3&lt;/p&gt;'\r
66     },{\r
67         id: 'card-2',\r
68         html: '&lt;h1&gt;Congratulations!&lt;/h1&gt;&lt;p&gt;Step 3 of 3 - Complete&lt;/p&gt;'\r
69     }]\r
70 });\r
71 </code></pre>\r
72  */\r
73 Ext.layout.CardLayout = Ext.extend(Ext.layout.FitLayout, {\r
74     <div id="cfg-Ext.layout.CardLayout-deferredRender"></div>/**\r
75      * @cfg {Boolean} deferredRender\r
76      * True to render each contained item at the time it becomes active, false to render all contained items\r
77      * as soon as the layout is rendered (defaults to false).  If there is a significant amount of content or\r
78      * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to\r
79      * true might improve performance.\r
80      */\r
81     deferredRender : false,\r
82     \r
83     <div id="cfg-Ext.layout.CardLayout-layoutOnCardChange"></div>/**\r
84      * @cfg {Boolean} layoutOnCardChange\r
85      * True to force a layout of the active item when the active card is changed. Defaults to false.\r
86      */\r
87     layoutOnCardChange : false,\r
88 \r
89     <div id="cfg-Ext.layout.CardLayout-renderHidden"></div>/**\r
90      * @cfg {Boolean} renderHidden @hide\r
91      */\r
92     // private\r
93     renderHidden : true,\r
94     \r
95     constructor: function(config){\r
96         Ext.layout.CardLayout.superclass.constructor.call(this, config);\r
97         this.forceLayout = (this.deferredRender === false);\r
98     },\r
99 \r
100     <div id="method-Ext.layout.CardLayout-setActiveItem"></div>/**\r
101      * Sets the active (visible) item in the layout.\r
102      * @param {String/Number} item The string component id or numeric index of the item to activate\r
103      */\r
104     setActiveItem : function(item){\r
105         item = this.container.getComponent(item);\r
106         if(this.activeItem != item){\r
107             if(this.activeItem){\r
108                 this.activeItem.hide();\r
109             }\r
110             this.activeItem = item;\r
111             item.show();\r
112             this.container.doLayout();\r
113             if(this.layoutOnCardChange && item.doLayout){\r
114                 item.doLayout();\r
115             }\r
116         }\r
117     },\r
118 \r
119     // private\r
120     renderAll : function(ct, target){\r
121         if(this.deferredRender){\r
122             this.renderItem(this.activeItem, undefined, target);\r
123         }else{\r
124             Ext.layout.CardLayout.superclass.renderAll.call(this, ct, target);\r
125         }\r
126     }\r
127 });\r
128 Ext.Container.LAYOUTS['card'] = Ext.layout.CardLayout;</pre>    \r
129 </body>\r
130 </html>