Upgrade to ExtJS 4.0.1 - Released 05/18/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     requires: [
10         'Ext.layout.component.Body'
11     ],
12
13     cls: 'x-portal',
14     bodyCls: 'x-portal-body',
15     defaultType: 'portalcolumn',
16     componentLayout: 'body',
17     autoScroll: true,
18
19     initComponent : function() {
20         var me = this;
21
22         // Implement a Container beforeLayout call from the layout to this Container
23         this.layout = {
24             type : 'column'
25         };
26         this.callParent();
27
28         this.addEvents({
29             validatedrop: true,
30             beforedragover: true,
31             dragover: true,
32             beforedrop: true,
33             drop: true
34         });
35         this.on('drop', this.doLayout, this);
36     },
37
38     // Set columnWidth, and set first and last column classes to allow exact CSS targeting.
39     beforeLayout: function() {
40         var items = this.layout.getLayoutItems(),
41             len = items.length,
42             i = 0,
43             item;
44
45         for (; i < len; i++) {
46             item = items[i];
47             item.columnWidth = 1 / len;
48             item.removeCls(['x-portal-column-first', 'x-portal-column-last']);
49         }
50         items[0].addCls('x-portal-column-first');
51         items[len - 1].addCls('x-portal-column-last');
52         return this.callParent(arguments);
53     },
54
55     // private
56     initEvents : function(){
57         this.callParent();
58         this.dd = Ext.create('Ext.app.PortalDropZone', this, this.dropConfig);
59     },
60
61     // private
62     beforeDestroy : function() {
63         if (this.dd) {
64             this.dd.unreg();
65         }
66         Ext.app.PortalPanel.superclass.beforeDestroy.call(this);
67     }
68 });