~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/extjs/source/widgets/layout/CardLayout.js

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

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