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