Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / examples / portal / classes / PortalPanel.js
1 /**
2  * @class Ext.app.PortalPanel
3  * @extends Ext.Panel
4  * A {@link Ext.Panel Panel} class used for providing drag-drop-enabled portal layouts.
5  */
6 Ext.define('Ext.app.PortalPanel', {
7     extend: 'Ext.panel.Panel',
8     alias: 'widget.portalpanel',
9     cls: 'x-portal',
10     bodyCls: 'x-portal-body',
11     defaultType: 'portalcolumn',
12     componentLayout: 'body',
13     autoScroll: true,
14
15     initComponent : function() {
16         var me = this;
17
18         // Implement a Container beforeLayout call from the layout to this Container
19         this.layout = {
20             type : 'column'
21         };
22         this.callParent();
23
24         this.addEvents({
25             validatedrop: true,
26             beforedragover: true,
27             dragover: true,
28             beforedrop: true,
29             drop: true
30         });
31         this.on('drop', this.doLayout, this);
32     },
33
34     // Set columnWidth, and set first and last column classes to allow exact CSS targeting.
35     beforeLayout: function() {
36         var items = this.layout.getLayoutItems(),
37             len = items.length,
38             i = 0,
39             item;
40
41         for (; i < len; i++) {
42             item = items[i];
43             item.columnWidth = 1 / len;
44             item.removeCls(['x-portal-column-first', 'x-portal-column-last']);
45         }
46         items[0].addCls('x-portal-column-first');
47         items[len - 1].addCls('x-portal-column-last');
48         return this.callParent(arguments);
49     },
50
51     // private
52     initEvents : function(){
53         this.callParent();
54         this.dd = Ext.create('Ext.app.PortalDropZone', this, this.dropConfig);
55     },
56
57     // private
58     beforeDestroy : function() {
59         if (this.dd) {
60             this.dd.unreg();
61         }
62         Ext.app.PortalPanel.superclass.beforeDestroy.call(this);
63     }
64 });