initial import
[roojs1] / Roo / dd / DropTarget.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11
12
13 /**
14  * @class Roo.dd.DropTarget
15  * @extends Roo.dd.DDTarget
16  * A simple class that provides the basic implementation needed to make any element a drop target that can have
17  * draggable items dropped onto it.  The drop has no effect until an implementation of notifyDrop is provided.
18  * @constructor
19  * @param {String/HTMLElement/Element} el The container element
20  * @param {Object} config
21  */
22 Roo.dd.DropTarget = function(el, config){
23     this.el = Roo.get(el);
24     
25     Roo.apply(this, config);
26     
27     if(this.containerScroll){
28         Roo.dd.ScrollManager.register(this.el);
29     }
30     
31     Roo.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, 
32           {isTarget: true});
33
34 };
35
36 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
37     /**
38      * @cfg {String} overClass
39      * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
40      */
41     /**
42      * @cfg {String} dropAllowed
43      * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
44      */
45     dropAllowed : "x-dd-drop-ok",
46     /**
47      * @cfg {String} dropNotAllowed
48      * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
49      */
50     dropNotAllowed : "x-dd-drop-nodrop",
51
52     // private
53     isTarget : true,
54
55     // private
56     isNotifyTarget : true,
57
58     /**
59      * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
60      * target.  This default implementation adds the CSS class specified by overClass (if any) to the drop element
61      * and returns the dropAllowed config value.  This method should be overridden if drop validation is required.
62      * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
63      * @param {Event} e The event
64      * @param {Object} data An object containing arbitrary data supplied by the drag source
65      * @return {String} status The CSS class that communicates the drop status back to the source so that the
66      * underlying {@link Roo.dd.StatusProxy} can be updated
67      */
68     notifyEnter : function(dd, e, data){
69         if(this.overClass){
70             this.el.addClass(this.overClass);
71         }
72         return this.dropAllowed;
73     },
74
75     /**
76      * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the target.
77      * This method will be called on every mouse movement while the drag source is over the drop target.
78      * This default implementation simply returns the dropAllowed config value.
79      * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
80      * @param {Event} e The event
81      * @param {Object} data An object containing arbitrary data supplied by the drag source
82      * @return {String} status The CSS class that communicates the drop status back to the source so that the
83      * underlying {@link Roo.dd.StatusProxy} can be updated
84      */
85     notifyOver : function(dd, e, data){
86         return this.dropAllowed;
87     },
88
89     /**
90      * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source has been dragged
91      * out of the target without dropping.  This default implementation simply removes the CSS class specified by
92      * overClass (if any) from the drop element.
93      * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
94      * @param {Event} e The event
95      * @param {Object} data An object containing arbitrary data supplied by the drag source
96      */
97     notifyOut : function(dd, e, data){
98         if(this.overClass){
99             this.el.removeClass(this.overClass);
100         }
101     },
102
103     /**
104      * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the dragged item has
105      * been dropped on it.  This method has no default implementation and returns false, so you must provide an
106      * implementation that does something to process the drop event and returns true so that the drag source's
107      * repair action does not run.
108      * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
109      * @param {Event} e The event
110      * @param {Object} data An object containing arbitrary data supplied by the drag source
111      * @return {Boolean} True if the drop was valid, else false
112      */
113     notifyDrop : function(dd, e, data){
114         return false;
115     }
116 });