Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / panel / Proxy.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  * A custom drag proxy implementation specific to {@link Ext.panel.Panel}s. This class
17  * is primarily used internally for the Panel's drag drop implementation, and
18  * should never need to be created directly.
19  * @private
20  */
21 Ext.define('Ext.panel.Proxy', {
22
23     alternateClassName: 'Ext.dd.PanelProxy',
24
25     /**
26      * Creates new panel proxy.
27      * @param {Ext.panel.Panel} panel The {@link Ext.panel.Panel} to proxy for
28      * @param {Object} [config] Config object
29      */
30     constructor: function(panel, config){
31         /**
32          * @property panel
33          * @type Ext.panel.Panel
34          */
35         this.panel = panel;
36         this.id = this.panel.id +'-ddproxy';
37         Ext.apply(this, config);
38     },
39
40     /**
41      * @cfg {Boolean} insertProxy
42      * True to insert a placeholder proxy element while dragging the panel, false to drag with no proxy.
43      * Most Panels are not absolute positioned and therefore we need to reserve this space.
44      */
45     insertProxy: true,
46
47     // private overrides
48     setStatus: Ext.emptyFn,
49     reset: Ext.emptyFn,
50     update: Ext.emptyFn,
51     stop: Ext.emptyFn,
52     sync: Ext.emptyFn,
53
54     /**
55      * Gets the proxy's element
56      * @return {Ext.Element} The proxy's element
57      */
58     getEl: function(){
59         return this.ghost.el;
60     },
61
62     /**
63      * Gets the proxy's ghost Panel
64      * @return {Ext.panel.Panel} The proxy's ghost Panel
65      */
66     getGhost: function(){
67         return this.ghost;
68     },
69
70     /**
71      * Gets the proxy element. This is the element that represents where the
72      * Panel was before we started the drag operation.
73      * @return {Ext.Element} The proxy's element
74      */
75     getProxy: function(){
76         return this.proxy;
77     },
78
79     /**
80      * Hides the proxy
81      */
82     hide : function(){
83         if (this.ghost) {
84             if (this.proxy) {
85                 this.proxy.remove();
86                 delete this.proxy;
87             }
88
89             // Unghost the Panel, do not move the Panel to where the ghost was
90             this.panel.unghost(null, false);
91             delete this.ghost;
92         }
93     },
94
95     /**
96      * Shows the proxy
97      */
98     show: function(){
99         if (!this.ghost) {
100             var panelSize = this.panel.getSize();
101             this.panel.el.setVisibilityMode(Ext.Element.DISPLAY);
102             this.ghost = this.panel.ghost();
103             if (this.insertProxy) {
104                 // bc Panels aren't absolute positioned we need to take up the space
105                 // of where the panel previously was
106                 this.proxy = this.panel.el.insertSibling({cls: Ext.baseCSSPrefix + 'panel-dd-spacer'});
107                 this.proxy.setSize(panelSize);
108             }
109         }
110     },
111
112     // private
113     repair: function(xy, callback, scope) {
114         this.hide();
115         if (typeof callback == "function") {
116             callback.call(scope || this);
117         }
118     },
119
120     /**
121      * Moves the proxy to a different position in the DOM.  This is typically
122      * called while dragging the Panel to keep the proxy sync'd to the Panel's
123      * location.
124      * @param {HTMLElement} parentNode The proxy's parent DOM node
125      * @param {HTMLElement} [before] The sibling node before which the
126      * proxy should be inserted (defaults to the parent's last child if not
127      * specified)
128      */
129     moveProxy : function(parentNode, before){
130         if (this.proxy) {
131             parentNode.insertBefore(this.proxy.dom, before);
132         }
133     }
134 });