Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / portal / classes / PortalPanel.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.PortalPanel
17  * @extends Ext.panel.Panel
18  * A {@link Ext.panel.Panel Panel} class used for providing drag-drop-enabled portal layouts.
19  */
20 Ext.define('Ext.app.PortalPanel', {
21     extend: 'Ext.panel.Panel',
22     alias: 'widget.portalpanel',
23     requires: [
24         'Ext.layout.component.Body'
25     ],
26
27     cls: 'x-portal',
28     bodyCls: 'x-portal-body',
29     defaultType: 'portalcolumn',
30     componentLayout: 'body',
31     autoScroll: true,
32
33     initComponent : function() {
34         var me = this;
35
36         // Implement a Container beforeLayout call from the layout to this Container
37         this.layout = {
38             type : 'column'
39         };
40         this.callParent();
41
42         this.addEvents({
43             validatedrop: true,
44             beforedragover: true,
45             dragover: true,
46             beforedrop: true,
47             drop: true
48         });
49         this.on('drop', this.doLayout, this);
50     },
51
52     // Set columnWidth, and set first and last column classes to allow exact CSS targeting.
53     beforeLayout: function() {
54         var items = this.layout.getLayoutItems(),
55             len = items.length,
56             i = 0,
57             item;
58
59         for (; i < len; i++) {
60             item = items[i];
61             item.columnWidth = 1 / len;
62             item.removeCls(['x-portal-column-first', 'x-portal-column-last']);
63         }
64         items[0].addCls('x-portal-column-first');
65         items[len - 1].addCls('x-portal-column-last');
66         return this.callParent(arguments);
67     },
68
69     // private
70     initEvents : function(){
71         this.callParent();
72         this.dd = Ext.create('Ext.app.PortalDropZone', this, this.dropConfig);
73     },
74
75     // private
76     beforeDestroy : function() {
77         if (this.dd) {
78             this.dd.unreg();
79         }
80         Ext.app.PortalPanel.superclass.beforeDestroy.call(this);
81     }
82 });
83