3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.app.PortalDropZone
17 * @extends Ext.dd.DropTarget
18 * Internal class that manages drag/drop for {@link Ext.app.PortalPanel}.
20 Ext.define('Ext.app.PortalDropZone', {
21 extend: 'Ext.dd.DropTarget',
23 constructor: function(portal, cfg) {
25 Ext.dd.ScrollManager.register(portal.body);
26 Ext.app.PortalDropZone.superclass.constructor.call(this, portal.body, cfg);
27 portal.body.ddScrollConfig = this.ddScrollConfig;
37 createEvent: function(dd, e, data, col, c, pos) {
47 status: this.dropAllowed
51 notifyOver: function(dd, e, data) {
58 this.grid = this.getGrid();
61 // handle case scroll where scrollbars appear during drag
62 var cw = portal.body.dom.clientWidth;
64 // set initial client width
66 } else if (this.lastCW != cw) {
67 // client width has changed, so refresh layout & grid calcs
70 this.grid = this.getGrid();
76 cols = this.grid.columnX,
80 for (len; colIndex < len; colIndex++) {
81 colRight = cols[colIndex].x + cols[colIndex].w;
82 if (xy[0] < colRight) {
87 // no match, fix last index
92 // find insert position
93 var overPortlet, pos = 0,
96 overColumn = portal.items.getAt(colIndex),
97 portlets = overColumn.items.items,
100 len = portlets.length;
102 for (len; pos < len; pos++) {
103 overPortlet = portlets[pos];
104 h = overPortlet.el.getHeight();
107 } else if ((overPortlet.el.getY() + (h / 2)) > xy[1]) {
113 pos = (match && overPortlet ? pos : overColumn.items.getCount()) + (overSelf ? -1 : 0);
114 var overEvent = this.createEvent(dd, e, data, colIndex, overColumn, pos);
116 if (portal.fireEvent('validatedrop', overEvent) !== false && portal.fireEvent('beforedragover', overEvent) !== false) {
118 // make sure proxy width is fluid in different width columns
119 proxy.getProxy().setWidth('auto');
122 proxy.moveProxy(overPortlet.el.dom.parentNode, match ? overPortlet.el.dom : null);
124 proxy.moveProxy(overColumn.el.dom, null);
130 p: overSelf || (match && overPortlet) ? pos : false
132 this.scrollPos = portal.body.getScroll();
134 portal.fireEvent('dragover', overEvent);
135 return overEvent.status;
137 return overEvent.status;
142 notifyOut: function() {
146 notifyDrop: function(dd, e, data) {
151 var c = this.lastPos.c,
152 col = this.lastPos.col,
153 pos = this.lastPos.p,
155 dropEvent = this.createEvent(dd, e, data, col, c, pos !== false ? pos : c.items.getCount());
157 if (this.portal.fireEvent('validatedrop', dropEvent) !== false && this.portal.fireEvent('beforedrop', dropEvent) !== false) {
159 // make sure panel is visible prior to inserting so that the layout doesn't ignore it
160 panel.el.dom.style.display = '';
163 c.insert(pos, panel);
169 this.portal.fireEvent('drop', dropEvent);
171 // scroll position is lost on drop, fix it
172 var st = this.scrollPos.top;
174 var d = this.portal.body.dom;
175 setTimeout(function() {
186 // internal cache of body and column coords
187 getGrid: function() {
188 var box = this.portal.body.getBox();
190 this.portal.items.each(function(c) {
199 // unregister the dropzone from ScrollManager
201 Ext.dd.ScrollManager.unregister(this.portal.body);
202 Ext.app.PortalDropZone.superclass.unreg.call(this);