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