3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 Ext.ux.Portal = Ext.extend(Ext.Panel, {
\r
11 defaultType : 'portalcolumn',
\r
13 initComponent : function(){
\r
14 Ext.ux.Portal.superclass.initComponent.call(this);
\r
17 beforedragover:true,
\r
24 initEvents : function(){
\r
25 Ext.ux.Portal.superclass.initEvents.call(this);
\r
26 this.dd = new Ext.ux.Portal.DropZone(this, this.dropConfig);
\r
29 beforeDestroy : function() {
\r
33 Ext.ux.Portal.superclass.beforeDestroy.call(this);
\r
37 Ext.reg('portal', Ext.ux.Portal);
\r
40 Ext.ux.Portal.DropZone = function(portal, cfg){
\r
41 this.portal = portal;
\r
42 Ext.dd.ScrollManager.register(portal.body);
\r
43 Ext.ux.Portal.DropZone.superclass.constructor.call(this, portal.bwrap.dom, cfg);
\r
44 portal.body.ddScrollConfig = this.ddScrollConfig;
\r
47 Ext.extend(Ext.ux.Portal.DropZone, Ext.dd.DropTarget, {
\r
55 createEvent : function(dd, e, data, col, c, pos){
\r
57 portal: this.portal,
\r
65 status: this.dropAllowed
\r
69 notifyOver : function(dd, e, data){
\r
70 var xy = e.getXY(), portal = this.portal, px = dd.proxy;
\r
72 // case column widths
\r
74 this.grid = this.getGrid();
\r
77 // handle case scroll where scrollbars appear during drag
\r
78 var cw = portal.body.dom.clientWidth;
\r
81 }else if(this.lastCW != cw){
\r
84 this.grid = this.getGrid();
\r
88 var col = 0, xs = this.grid.columnX, cmatch = false;
\r
89 for(var len = xs.length; col < len; col++){
\r
90 if(xy[0] < (xs[col].x + xs[col].w)){
\r
95 // no match, fix last index
\r
100 // find insert position
\r
101 var p, match = false, pos = 0,
\r
102 c = portal.items.itemAt(col),
\r
103 items = c.items.items, overSelf = false;
\r
105 for(var len = items.length; pos < len; pos++){
\r
107 var h = p.el.getHeight();
\r
111 else if((p.el.getY()+(h/2)) > xy[1]){
\r
117 pos = (match && p ? pos : c.items.getCount()) + (overSelf ? -1 : 0);
\r
118 var overEvent = this.createEvent(dd, e, data, col, c, pos);
\r
120 if(portal.fireEvent('validatedrop', overEvent) !== false &&
\r
121 portal.fireEvent('beforedragover', overEvent) !== false){
\r
123 // make sure proxy width is fluid
\r
124 px.getProxy().setWidth('auto');
\r
127 px.moveProxy(p.el.dom.parentNode, match ? p.el.dom : null);
\r
129 px.moveProxy(c.el.dom, null);
\r
132 this.lastPos = {c: c, col: col, p: overSelf || (match && p) ? pos : false};
\r
133 this.scrollPos = portal.body.getScroll();
\r
135 portal.fireEvent('dragover', overEvent);
\r
137 return overEvent.status;
\r
139 return overEvent.status;
\r
144 notifyOut : function(){
\r
148 notifyDrop : function(dd, e, data){
\r
153 var c = this.lastPos.c, col = this.lastPos.col, pos = this.lastPos.p;
\r
155 var dropEvent = this.createEvent(dd, e, data, col, c,
\r
156 pos !== false ? pos : c.items.getCount());
\r
158 if(this.portal.fireEvent('validatedrop', dropEvent) !== false &&
\r
159 this.portal.fireEvent('beforedrop', dropEvent) !== false){
\r
161 dd.proxy.getProxy().remove();
\r
162 dd.panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
\r
165 if(c == dd.panel.ownerCt && (c.items.items.indexOf(dd.panel) <= pos)){
\r
168 c.insert(pos, dd.panel);
\r
175 this.portal.fireEvent('drop', dropEvent);
\r
177 // scroll position is lost on drop, fix it
\r
178 var st = this.scrollPos.top;
\r
180 var d = this.portal.body.dom;
\r
181 setTimeout(function(){
\r
187 delete this.lastPos;
\r
190 // internal cache of body and column coords
\r
191 getGrid : function(){
\r
192 var box = this.portal.bwrap.getBox();
\r
194 this.portal.items.each(function(c){
\r
195 box.columnX.push({x: c.el.getX(), w: c.el.getWidth()});
\r
200 // unregister the dropzone from ScrollManager
\r
201 unreg: function() {
\r
202 //Ext.dd.ScrollManager.unregister(this.portal.body);
\r
203 Ext.ux.Portal.DropZone.superclass.unreg.call(this);
\r