Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / dd / StatusProxy.js
index c195379..0ffb6d2 100644 (file)
@@ -1,43 +1,61 @@
-/*!
- * Ext JS Library 3.3.0
- * Copyright(c) 2006-2010 Ext JS, Inc.
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
+/*
+
+This file is part of Ext JS 4
+
+Copyright (c) 2011 Sencha Inc
+
+Contact:  http://www.sencha.com/contact
+
+GNU General Public License Usage
+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.
+
+If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
+
+*/
 /**
  * @class Ext.dd.StatusProxy
  * A specialized drag proxy that supports a drop status icon, {@link Ext.Layer} styles and auto-repair.  This is the
  * default drag proxy used by all Ext.dd components.
- * @constructor
- * @param {Object} config
  */
-Ext.dd.StatusProxy = function(config){
-    Ext.apply(this, config);
-    this.id = this.id || Ext.id();
-    this.el = new Ext.Layer({
-        dh: {
-            id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
-                {tag: "div", cls: "x-dd-drop-icon"},
-                {tag: "div", cls: "x-dd-drag-ghost"}
-            ]
-        }, 
-        shadow: !config || config.shadow !== false
-    });
-    this.ghost = Ext.get(this.el.dom.childNodes[1]);
-    this.dropStatus = this.dropNotAllowed;
-};
-
-Ext.dd.StatusProxy.prototype = {
+Ext.define('Ext.dd.StatusProxy', {
+    animRepair: false,
+
+    /**
+     * Creates new StatusProxy.
+     * @param {Object} config (optional) Config object.
+     */
+    constructor: function(config){
+        Ext.apply(this, config);
+        this.id = this.id || Ext.id();
+        this.proxy = Ext.createWidget('component', {
+            floating: true,
+            stateful: false,
+            id: this.id,
+            html: '<div class="' + Ext.baseCSSPrefix + 'dd-drop-icon"></div>' +
+                  '<div class="' + Ext.baseCSSPrefix + 'dd-drag-ghost"></div>',
+            cls: Ext.baseCSSPrefix + 'dd-drag-proxy ' + this.dropNotAllowed,
+            shadow: !config || config.shadow !== false,
+            renderTo: document.body
+        });
+
+        this.el = this.proxy.el;
+        this.el.show();
+        this.el.setVisibilityMode(Ext.Element.VISIBILITY);
+        this.el.hide();
+
+        this.ghost = Ext.get(this.el.dom.childNodes[1]);
+        this.dropStatus = this.dropNotAllowed;
+    },
     /**
-     * @cfg {String} dropAllowed
-     * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
+     * @cfg {String} [dropAllowed="x-dd-drop-ok"]
+     * The CSS class to apply to the status element when drop is allowed.
      */
-    dropAllowed : "x-dd-drop-ok",
+    dropAllowed : Ext.baseCSSPrefix + 'dd-drop-ok',
     /**
-     * @cfg {String} dropNotAllowed
-     * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
+     * @cfg {String} [dropNotAllowed="x-dd-drop-nodrop"]
+     * The CSS class to apply to the status element when drop is not allowed.
      */
-    dropNotAllowed : "x-dd-drop-nodrop",
+    dropNotAllowed : Ext.baseCSSPrefix + 'dd-drop-nodrop',
 
     /**
      * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
@@ -47,7 +65,7 @@ Ext.dd.StatusProxy.prototype = {
     setStatus : function(cssClass){
         cssClass = cssClass || this.dropNotAllowed;
         if(this.dropStatus != cssClass){
-            this.el.replaceClass(this.dropStatus, cssClass);
+            this.el.replaceCls(this.dropStatus, cssClass);
             this.dropStatus = cssClass;
         }
     },
@@ -57,7 +75,7 @@ Ext.dd.StatusProxy.prototype = {
      * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
      */
     reset : function(clearGhost){
-        this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
+        this.el.dom.className = Ext.baseCSSPrefix + 'dd-drag-proxy ' + this.dropNotAllowed;
         this.dropStatus = this.dropNotAllowed;
         if(clearGhost){
             this.ghost.update("");
@@ -77,7 +95,7 @@ Ext.dd.StatusProxy.prototype = {
             html.style.margin = "0";
             this.ghost.dom.appendChild(html);
         }
-        var el = this.ghost.dom.firstChild; 
+        var el = this.ghost.dom.firstChild;
         if(el){
             Ext.fly(el).setStyle('float', 'none');
         }
@@ -103,9 +121,9 @@ Ext.dd.StatusProxy.prototype = {
      * Hides the proxy
      * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
      */
-    hide : function(clear){
-        this.el.hide();
-        if(clear){
+    hide : function(clear) {
+        this.proxy.hide();
+        if (clear) {
             this.reset(true);
         }
     },
@@ -122,39 +140,43 @@ Ext.dd.StatusProxy.prototype = {
     /**
      * Displays this proxy
      */
-    show : function(){
-        this.el.show();
+    show : function() {
+        this.proxy.show();
+        this.proxy.toFront();
     },
 
     /**
      * Force the Layer to sync its shadow and shim positions to the element
      */
     sync : function(){
-        this.el.sync();
+        this.proxy.el.sync();
     },
 
     /**
      * Causes the proxy to return to its position of origin via an animation.  Should be called after an
      * invalid drop operation by the item being dragged.
-     * @param {Array} xy The XY position of the element ([x, y])
+     * @param {Number[]} xy The XY position of the element ([x, y])
      * @param {Function} callback The function to call after the repair is complete.
      * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
      */
     repair : function(xy, callback, scope){
         this.callback = callback;
         this.scope = scope;
-        if(xy && this.animRepair !== false){
-            this.el.addClass("x-dd-drag-repair");
+        if (xy && this.animRepair !== false) {
+            this.el.addCls(Ext.baseCSSPrefix + 'dd-drag-repair');
             this.el.hideUnders(true);
-            this.anim = this.el.shift({
-                duration: this.repairDuration || .5,
-                easing: 'easeOut',
-                xy: xy,
-                stopFx: true,
+            this.anim = this.el.animate({
+                duration: this.repairDuration || 500,
+                easing: 'ease-out',
+                to: {
+                    x: xy[0],
+                    y: xy[1]
+                },
+                stopAnimation: true,
                 callback: this.afterRepair,
                 scope: this
             });
-        }else{
+        } else {
             this.afterRepair();
         }
     },
@@ -168,8 +190,8 @@ Ext.dd.StatusProxy.prototype = {
         this.callback = null;
         this.scope = null;
     },
-    
+
     destroy: function(){
-        Ext.destroy(this.ghost, this.el);    
+        Ext.destroy(this.ghost, this.proxy, this.el);
     }
-};
\ No newline at end of file
+});