summaryrefslogtreecommitdiff
path: root/frontend/beta/js/YUI-extensions/dd/StatusProxy.js
blob: 97de4d9a97497492289700499c3344358bb8659b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
YAHOO.ext.dd.StatusProxy = function(config){
    YAHOO.ext.util.Config.apply(this, config);
    this.id = this.id || YAHOO.util.Dom.generateId();
    this.el = new YAHOO.ext.Layer({
        dh: {
            id: this.id, tag: 'div', cls: 'ydd-drag-proxy '+this.dropNotAllowed, children: [
                {tag: 'div', cls: 'ydd-drop-icon'},
                {tag: 'div', cls: 'ydd-drag-ghost'}
            ]
        }, 
        shadow: !config || config.shadow !== false
    });
    /*this.el = YAHOO.ext.DomHelper.insertBefore(document.body.firstChild, {
        id: this.id, tag: 'div', cls: 'ydd-drag-proxy '+this.dropNotAllowed, children: [
            {tag: 'div', cls: 'ydd-drop-icon'},
            {tag: 'div', cls: 'ydd-drag-ghost'}
        ]
    }, true);*/
    this.ghost = getEl(this.el.dom.childNodes[1]);
    this.dropStatus = this.dropNotAllowed;
};

YAHOO.ext.dd.StatusProxy.prototype = {
    dropAllowed : 'ydd-drop-ok',
    dropNotAllowed : 'ydd-drop-nodrop',
    /**
     * Updates the DD visual element to allow/not allow a drop
     * @param {String} cssClass The css class for the new drop status indicator image
     */
    setStatus : function(cssClass){
        cssClass = cssClass || this.dropNotAllowed;
        if(this.dropStatus != cssClass){
            this.el.replaceClass(this.dropStatus, cssClass);
            this.dropStatus = cssClass;
        }
    },
    
    reset : function(clearGhost){
        this.el.dom.className = 'ydd-drag-proxy ' + this.dropNotAllowed;
        this.dropStatus = this.dropNotAllowed;
        if(clearGhost){
            this.ghost.update('');
        }
    },
    
    update : function(html){
        if(typeof html == 'string'){
            this.ghost.update(html);
        }else{
            this.ghost.update('');
            html.style.margin = '0';
            this.ghost.dom.appendChild(html);
        }        
    },
    
    getEl : function(){
        return this.el;
    },
    
    getGhost : function(){
        return this.ghost;
    },
    
    hide : function(clear){
        this.el.hide();
        if(clear){
            this.reset(true);
        }
    },
    
    stop : function(){
        if(this.anim && this.anim.isAnimated()){
            this.anim.stop();
        }
    },
    
    show : function(){
        this.el.show();
    },
    
    sync : function(){
        this.el.syncLocalXY();  
    },
    
    repair : function(xy, callback, scope){
        this.callback = callback;
        this.scope = scope;
        if(xy && this.animRepair !== false && YAHOO.util.Anim){
            this.el.addClass('ydd-drag-repair');
            this.el.hideUnders(true);
            if(!this.anim){
                this.anim = new YAHOO.util.Motion(this.el.dom, {}, this.repairDuration || .5, YAHOO.util.Easing.easeOut);
                this.anim.onComplete.subscribe(this.afterRepair, this, true);
            }
            this.anim.attributes = {points: {to:xy}};
            this.anim.animate();
        }else{
            this.afterRepair();
        }
    },
    
    afterRepair : function(){
        this.hide(true);
        if(typeof this.callback == 'function'){
            this.callback.call(this.scope || this);
        }
        this.callback == null;
        this.scope == null;
    }
};