Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / portal / portal.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 /**
16  * @class Ext.app.Portal
17  * @extends Object
18  * A sample portal layout application class.
19  */
20 // TODO: Fill in the content panel -- no AccordionLayout at the moment
21 // TODO: Fix container drag/scroll support (waiting on Ext.lib.Anim)
22 // TODO: Fix Ext.Tool scope being set to the panel header
23 // TODO: Drag/drop does not cause a refresh of scroll overflow when needed
24 // TODO: Grid portlet throws errors on destroy (grid bug)
25 // TODO: Z-index issues during drag
26
27 Ext.define('Ext.app.Portal', {
28
29     extend: 'Ext.container.Viewport',
30
31     uses: ['Ext.app.PortalPanel', 'Ext.app.PortalColumn', 'Ext.app.GridPortlet', 'Ext.app.ChartPortlet'],
32
33     getTools: function(){
34         return [{
35             xtype: 'tool',
36             type: 'gear',
37             handler: function(e, target, panelHeader, tool){
38                 var portlet = panelHeader.ownerCt;
39                 portlet.setLoading('Working...');
40                 Ext.defer(function() {
41                     portlet.setLoading(false);
42                 }, 2000);
43             }
44         }];
45     },
46
47     initComponent: function(){
48         var content = '<div class="portlet-content">'+Ext.example.shortBogusMarkup+'</div>';
49
50         Ext.apply(this, {
51             id: 'app-viewport',
52             layout: {
53                 type: 'border',
54                 padding: '0 5 5 5' // pad the layout from the window edges
55             },
56             items: [{
57                 id: 'app-header',
58                 xtype: 'box',
59                 region: 'north',
60                 height: 40,
61                 html: 'Ext Portal'
62             },{
63                 xtype: 'container',
64                 region: 'center',
65                 layout: 'border',
66                 items: [{
67                     id: 'app-options',
68                     title: 'Options',
69                     region: 'west',
70                     animCollapse: true,
71                     width: 200,
72                     minWidth: 150,
73                     maxWidth: 400,
74                     split: true,
75                     collapsible: true,
76                     layout: 'accordion',
77                     layoutConfig:{
78                         animate: true
79                     },
80                     items: [{
81                         html: content,
82                         title:'Navigation',
83                         autoScroll: true,
84                         border: false,
85                         iconCls: 'nav'
86                     },{
87                         title:'Settings',
88                         html: content,
89                         border: false,
90                         autoScroll: true,
91                         iconCls: 'settings'
92                     }]
93                 },{
94                     id: 'app-portal',
95                     xtype: 'portalpanel',
96                     region: 'center',
97                     items: [{
98                         id: 'col-1',
99                         items: [{
100                             id: 'portlet-1',
101                             title: 'Grid Portlet',
102                             tools: this.getTools(),
103                             items: Ext.create('Ext.app.GridPortlet'),
104                             listeners: {
105                                 'close': Ext.bind(this.onPortletClose, this)
106                             }
107                         },{
108                             id: 'portlet-2',
109                             title: 'Portlet 2',
110                             tools: this.getTools(),
111                             html: content,
112                             listeners: {
113                                 'close': Ext.bind(this.onPortletClose, this)
114                             }
115                         }]
116                     },{
117                         id: 'col-2',
118                         items: [{
119                             id: 'portlet-3',
120                             title: 'Portlet 3',
121                             tools: this.getTools(),
122                             html: '<div class="portlet-content">'+Ext.example.bogusMarkup+'</div>',
123                             listeners: {
124                                 'close': Ext.bind(this.onPortletClose, this)
125                             }
126                         }]
127                     },{
128                         id: 'col-3',
129                         items: [{
130                             id: 'portlet-4',
131                             title: 'Stock Portlet',
132                             tools: this.getTools(),
133                             items: Ext.create('Ext.app.ChartPortlet'),
134                             listeners: {
135                                 'close': Ext.bind(this.onPortletClose, this)
136                             }
137                         }]
138                     }]
139                 }]
140             }]
141         });
142         this.callParent(arguments);
143     },
144
145     onPortletClose: function(portlet) {
146         this.showMsg('"' + portlet.title + '" was removed');
147     },
148
149     showMsg: function(msg) {
150         var el = Ext.get('app-msg'),
151             msgId = Ext.id();
152
153         this.msgId = msgId;
154         el.update(msg).show();
155
156         Ext.defer(this.clearMsg, 3000, this, [msgId]);
157     },
158
159     clearMsg: function(msgId) {
160         if (msgId === this.msgId) {
161             Ext.get('app-msg').hide();
162         }
163     }
164 });
165