3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.layout.CardLayout"></div>/**
\r
10 * @class Ext.layout.CardLayout
\r
11 * @extends Ext.layout.FitLayout
\r
12 * <p>This layout manages multiple child Components, each fitted to the Container, where only a single child Component can be
\r
13 * visible at any given time. This layout style is most commonly used for wizards, tab implementations, etc.
\r
14 * This class is intended to be extended or created via the layout:'card' {@link Ext.Container#layout} config,
\r
15 * and should generally not need to be created directly via the new keyword.</p>
\r
16 * <p>The CardLayout's focal method is {@link #setActiveItem}. Since only one panel is displayed at a time,
\r
17 * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of
\r
18 * the next panel to display. The layout itself does not provide a user interface for handling this navigation,
\r
19 * so that functionality must be provided by the developer.</p>
\r
20 * <p>In the following example, a simplistic wizard setup is demonstrated. A button bar is added
\r
21 * to the footer of the containing panel to provide navigation buttons. The buttons will be handled by a
\r
22 * common navigation routine -- for this example, the implementation of that routine has been ommitted since
\r
23 * it can be any type of custom logic. Note that other uses of a CardLayout (like a tab control) would require a
\r
24 * completely different implementation. For serious implementations, a better approach would be to extend
\r
25 * CardLayout to provide the custom functionality needed. Example usage:</p>
\r
27 var navHandler = function(direction){
\r
28 // This routine could contain business logic required to manage the navigation steps.
\r
29 // It would call setActiveItem as needed, manage navigation button state, handle any
\r
30 // branching logic that might be required, handle alternate actions like cancellation
\r
31 // or finalization, etc. A complete wizard implementation could get pretty
\r
32 // sophisticated depending on the complexity required, and should probably be
\r
33 // done as a subclass of CardLayout in a real-world implementation.
\r
36 var card = new Ext.Panel({
\r
37 title: 'Example Wizard',
\r
39 activeItem: 0, // make sure the active item is set on the container config!
\r
40 bodyStyle: 'padding:15px',
\r
42 // applied to each contained panel
\r
45 // just an example of one possible navigation scheme, using buttons
\r
50 handler: navHandler.createDelegate(this, [-1]),
\r
53 '->', // greedy spacer so that the buttons are aligned to each side
\r
57 handler: navHandler.createDelegate(this, [1])
\r
60 // the panels (or "cards") within the layout
\r
63 html: '<h1>Welcome to the Wizard!</h1><p>Step 1 of 3</p>'
\r
66 html: '<p>Step 2 of 3</p>'
\r
69 html: '<h1>Congratulations!</h1><p>Step 3 of 3 - Complete</p>'
\r
74 Ext.layout.CardLayout = Ext.extend(Ext.layout.FitLayout, {
\r
75 <div id="cfg-Ext.layout.CardLayout-deferredRender"></div>/**
\r
76 * @cfg {Boolean} deferredRender
\r
77 * True to render each contained item at the time it becomes active, false to render all contained items
\r
78 * as soon as the layout is rendered (defaults to false). If there is a significant amount of content or
\r
79 * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to
\r
80 * true might improve performance.
\r
82 deferredRender : false,
\r
84 <div id="cfg-Ext.layout.CardLayout-layoutOnCardChange"></div>/**
\r
85 * @cfg {Boolean} layoutOnCardChange
\r
86 * True to force a layout of the active item when the active card is changed. Defaults to false.
\r
88 layoutOnCardChange : false,
\r
90 <div id="cfg-Ext.layout.CardLayout-renderHidden"></div>/**
\r
91 * @cfg {Boolean} renderHidden @hide
\r
94 renderHidden : true,
\r
98 constructor: function(config){
\r
99 Ext.layout.CardLayout.superclass.constructor.call(this, config);
\r
102 <div id="method-Ext.layout.CardLayout-setActiveItem"></div>/**
\r
103 * Sets the active (visible) item in the layout.
\r
104 * @param {String/Number} item The string component id or numeric index of the item to activate
\r
106 setActiveItem : function(item){
\r
107 var ai = this.activeItem,
\r
108 ct = this.container;
\r
109 item = ct.getComponent(item);
\r
111 // Is this a valid, different card?
\r
112 if(item && ai != item){
\r
114 // Changing cards, hide the current one
\r
117 if (ai.hidden !== true) {
\r
120 ai.fireEvent('deactivate', ai);
\r
122 // Change activeItem reference
\r
123 this.activeItem = item;
\r
125 // The container is about to get a recursive layout, remove any deferLayout reference
\r
126 // because it will trigger a redundant layout.
\r
127 delete item.deferLayout;
\r
129 // Show the new component
\r
137 item.fireEvent('activate', item);
\r
142 renderAll : function(ct, target){
\r
143 if(this.deferredRender){
\r
144 this.renderItem(this.activeItem, undefined, target);
\r
146 Ext.layout.CardLayout.superclass.renderAll.call(this, ct, target);
\r
150 Ext.Container.LAYOUTS['card'] = Ext.layout.CardLayout;</pre>
\r