Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / layout-browser / layout-browser.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.Loader.setConfig({enabled: true});
16
17 Ext.Loader.setPath('Ext.ux', '../ux');
18
19 Ext.require([
20     'Ext.tip.QuickTipManager',
21     'Ext.container.Viewport',
22     'Ext.layout.*',
23     'Ext.form.Panel',
24     'Ext.form.Label',
25     'Ext.grid.*',
26     'Ext.data.*',
27     'Ext.tree.*',
28     'Ext.selection.*',
29     'Ext.tab.Panel',
30     'Ext.ux.layout.Center'  
31 ]);
32
33 //
34 // This is the main layout definition.
35 //
36 Ext.onReady(function(){
37  
38     Ext.tip.QuickTipManager.init();
39
40     // This is an inner body element within the Details panel created to provide a "slide in" effect
41     // on the panel body without affecting the body's box itself.  This element is created on
42     // initial use and cached in this var for subsequent access.
43     var detailEl;
44     
45     // Gets all layouts examples
46     var layoutExamples = [];
47     Ext.Object.each(getBasicLayouts(), function(name, example) {
48         layoutExamples.push(example);
49     });
50     
51     Ext.Object.each(getCombinationLayouts(), function(name, example){
52         layoutExamples.push(example);
53     });
54     
55     Ext.Object.each(getCustomLayouts(), function(name, example){
56         layoutExamples.push(example);
57     });
58     
59     // This is the main content center region that will contain each example layout panel.
60     // It will be implemented as a CardLayout since it will contain multiple panels with
61     // only one being visible at any given time.
62
63     var contentPanel = {
64          id: 'content-panel',
65          region: 'center', // this is what makes this panel into a region within the containing layout
66          layout: 'card',
67          margins: '2 5 5 0',
68          activeItem: 0,
69          border: false,
70          items: layoutExamples
71     };
72      
73     var store = Ext.create('Ext.data.TreeStore', {
74         root: {
75             expanded: true
76         },
77         proxy: {
78             type: 'ajax',
79             url: 'tree-data.json'
80         }
81     });
82     
83     // Go ahead and create the TreePanel now so that we can use it below
84      var treePanel = Ext.create('Ext.tree.Panel', {
85         id: 'tree-panel',
86         title: 'Sample Layouts',
87         region:'north',
88         split: true,
89         height: 360,
90         minSize: 150,
91         rootVisible: false,
92         autoScroll: true,
93         store: store
94     });
95     
96     // Assign the changeLayout function to be called on tree node click.
97     treePanel.getSelectionModel().on('select', function(selModel, record) {
98         if (record.get('leaf')) {
99             Ext.getCmp('content-panel').layout.setActiveItem(record.getId() + '-panel');
100              if (!detailEl) {
101                 var bd = Ext.getCmp('details-panel').body;
102                 bd.update('').setStyle('background','#fff');
103                 detailEl = bd.createChild(); //create default empty div
104             }
105             detailEl.hide().update(Ext.getDom(record.getId() + '-details').innerHTML).slideIn('l', {stopAnimation:true,duration: 200});
106         }
107     });
108     
109     // This is the Details panel that contains the description for each example layout.
110     var detailsPanel = {
111         id: 'details-panel',
112         title: 'Details',
113         region: 'center',
114         bodyStyle: 'padding-bottom:15px;background:#eee;',
115         autoScroll: true,
116         html: '<p class="details-info">When you select a layout from the tree, additional details will display here.</p>'
117     };
118  
119     // Finally, build the main layout once all the pieces are ready.  This is also a good
120     // example of putting together a full-screen BorderLayout within a Viewport.
121     Ext.create('Ext.Viewport', {
122         layout: 'border',
123         title: 'Ext Layout Browser',
124         items: [{
125             xtype: 'box',
126             id: 'header',
127             region: 'north',
128             html: '<h1> Ext.Layout.Browser</h1>',
129             height: 30
130         },{
131             layout: 'border',
132             id: 'layout-browser',
133             region:'west',
134             border: false,
135             split:true,
136             margins: '2 0 5 5',
137             width: 275,
138             minSize: 100,
139             maxSize: 500,
140             items: [treePanel, detailsPanel]
141         }, 
142             contentPanel
143         ],
144         renderTo: Ext.getBody()
145     });
146 });
147