4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-container-Card'>/**
19 </span> * @class Ext.layout.container.Card
20 * @extends Ext.layout.container.AbstractCard
21 * <p>This layout manages multiple child Components, each fitted to the Container, where only a single child Component can be
22 * visible at any given time. This layout style is most commonly used for wizards, tab implementations, etc.
23 * This class is intended to be extended or created via the layout:'card' {@link Ext.container.Container#layout} config,
24 * and should generally not need to be created directly via the new keyword.</p>
25 * <p>The CardLayout's focal method is {@link #setActiveItem}. Since only one panel is displayed at a time,
26 * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of
27 * the next panel to display. The layout itself does not provide a user interface for handling this navigation,
28 * so that functionality must be provided by the developer.</p>
29 * <p>In the following example, a simplistic wizard setup is demonstrated. A button bar is added
30 * to the footer of the containing panel to provide navigation buttons. The buttons will be handled by a
31 * common navigation routine -- for this example, the implementation of that routine has been ommitted since
32 * it can be any type of custom logic. Note that other uses of a CardLayout (like a tab control) would require a
33 * completely different implementation. For serious implementations, a better approach would be to extend
34 * CardLayout to provide the custom functionality needed.
35 * {@img Ext.layout.container.Card/Ext.layout.container.Card.png Ext.layout.container.Card container layout}
36 * Example usage:</p>
37 * <pre><code>
38 var navHandler = function(direction){
39 // This routine could contain business logic required to manage the navigation steps.
40 // It would call setActiveItem as needed, manage navigation button state, handle any
41 // branching logic that might be required, handle alternate actions like cancellation
42 // or finalization, etc. A complete wizard implementation could get pretty
43 // sophisticated depending on the complexity required, and should probably be
44 // done as a subclass of CardLayout in a real-world implementation.
47 Ext.create('Ext.panel.Panel', {
48 title: 'Example Wizard',
52 activeItem: 0, // make sure the active item is set on the container config!
53 bodyStyle: 'padding:15px',
55 // applied to each contained panel
58 // just an example of one possible navigation scheme, using buttons
63 handler: navHandler(this, [-1]),
66 '->', // greedy spacer so that the buttons are aligned to each side
70 handler: navHandler(this, [1])
72 // the panels (or "cards") within the layout
75 html: '&lt;h1&gt;Welcome to the Wizard!&lt;/h1&gt;&lt;p&gt;Step 1 of 3&lt;/p&gt;'
78 html: '&lt;p&gt;Step 2 of 3&lt;/p&gt;'
81 html: '&lt;h1&gt;Congratulations!&lt;/h1&gt;&lt;p&gt;Step 3 of 3 - Complete&lt;/p&gt;'
83 renderTo: Ext.getBody()
85 </code></pre>
87 Ext.define('Ext.layout.container.Card', {
89 /* Begin Definitions */
91 alias: ['layout.card'],
92 alternateClassName: 'Ext.layout.CardLayout',
94 extend: 'Ext.layout.container.AbstractCard',
98 setActiveItem: function(newCard) {
101 oldCard = me.activeItem,
104 // Block upward layouts until we are done.
105 me.layoutBusy = true;
107 newCard = me.parseActiveItem(newCard);
108 newIndex = owner.items.indexOf(newCard);
110 // If the card is not a child of the owner, then add it
111 if (newIndex == -1) {
112 newIndex = owner.items.items.length;
116 // Is this a valid, different card?
117 if (newCard && oldCard != newCard) {
118 // If the card has not been rendered yet, now is the time to do so.
119 if (!newCard.rendered) {
120 me.renderItem(newCard, me.getRenderTarget(), owner.items.length);
121 me.configureItem(newCard, 0);
124 me.activeItem = newCard;
126 // Fire the beforeactivate and beforedeactivate events on the cards
127 if (newCard.fireEvent('beforeactivate', newCard, oldCard) === false) {
128 me.layoutBusy = false;
131 if (oldCard && oldCard.fireEvent('beforedeactivate', oldCard, newCard) === false) {
132 me.layoutBusy = false;
136 // If the card hasnt been sized yet, do it now
137 if (!me.sizeAllCards) {
138 me.setItemBox(newCard, me.getTargetBox());
141 // onLayout calls setItemBox
146 if (me.hideInactive) {
149 oldCard.fireEvent('deactivate', oldCard, newCard);
152 // Make sure the new card is shown
153 if (newCard.hidden) {
157 newCard.fireEvent('activate', newCard, oldCard);
159 me.layoutBusy = false;
161 if (!me.sizeAllCards) {
162 if (!owner.componentLayout.layoutBusy) {
169 me.layoutBusy = false;