Roo/dd/DropTarget.js
[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     
32     this.events = {  
33         /**
34          * @scope Roo.BasicLayoutRegion
35          */
36         
37         /
38         /**
39          * @event invalidated
40          * Fires when the layout for this region is changed.
41          * @param {Roo.LayoutRegion} this
42          */
43         "invalidated" : true,
44         /**
45          * @event visibilitychange
46          * Fires when this region is shown or hidden 
47          * @param {Roo.LayoutRegion} this
48          * @param {Boolean} visibility true or false
49          */
50         "visibilitychange" : true,
51     }
52     Roo.dd.DropTarget.superclass.constructor.call(  this, 
53         this.el.dom, 
54         this.ddGroup || this.group, 
55         {
56             isTarget: true,
57             events : {
58                  /**
59                  * @scope Roo.dd.DropTarget
60                  */
61                  
62                  /**
63                  * @event enter
64                  * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
65                  * target.  This default implementation adds the CSS class specified by overClass (if any) to the drop element
66                  * and returns the dropAllowed config value.  This method should be overridden if drop validation is required.
67                  * 
68                  * IMPORTANT : it should set this.overClass and this.dropAllowed;
69                  * 
70                  * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
71                  * @param {Event} e The event
72                  * @param {Object} data An object containing arbitrary data supplied by the drag source
73                  * @return {String} status The CSS class that communicates the drop status back to the source so that the
74                  * underlying {@link Roo.dd.StatusProxy} can be updated
75                  */
76                 "enter" : true,
77                  /**
78                  * @event over
79                  * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
80                  * target.  This default implementation adds the CSS class specified by overClass (if any) to the drop element
81                  * and returns the dropAllowed config value.  This method should be overridden if drop validation is required.
82                  * 
83                  * IMPORTANT : it should set this.overClass and this.dropAllowed;
84                  * 
85                  * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
86                  * @param {Event} e The event
87                  * @param {Object} data An object containing arbitrary data supplied by the drag source
88                  * @return {String} status The CSS class that communicates the drop status back to the source so that the
89                  * underlying {@link Roo.dd.StatusProxy} can be updated
90                  */
91                 "over" : true,
92                 
93             }
94                 
95         
96         }
97     );
98
99 };
100
101 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
102     /**
103      * @cfg {String} overClass
104      * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
105      */
106     /**
107      * @cfg {String} dropAllowed
108      * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
109      */
110     dropAllowed : "x-dd-drop-ok",
111     /**
112      * @cfg {String} dropNotAllowed
113      * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
114      */
115     dropNotAllowed : "x-dd-drop-nodrop",
116
117     // private
118     isTarget : true,
119
120     // private
121     isNotifyTarget : true,
122
123     /**
124      * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
125      * target.  This default implementation adds the CSS class specified by overClass (if any) to the drop element
126      * and returns the dropAllowed config value.  This method should be overridden if drop validation is required.
127      * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
128      * @param {Event} e The event
129      * @param {Object} data An object containing arbitrary data supplied by the drag source
130      * @return {String} status The CSS class that communicates the drop status back to the source so that the
131      * underlying {@link Roo.dd.StatusProxy} can be updated
132      */
133     notifyEnter : function(dd, e, data){
134         if(this.overClass){
135             this.el.addClass(this.overClass);
136         }
137         return this.dropAllowed;
138     },
139
140     /**
141      * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the target.
142      * This method will be called on every mouse movement while the drag source is over the drop target.
143      * This default implementation simply returns the dropAllowed config value.
144      * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
145      * @param {Event} e The event
146      * @param {Object} data An object containing arbitrary data supplied by the drag source
147      * @return {String} status The CSS class that communicates the drop status back to the source so that the
148      * underlying {@link Roo.dd.StatusProxy} can be updated
149      */
150     notifyOver : function(dd, e, data){
151         return this.dropAllowed;
152     },
153
154     /**
155      * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source has been dragged
156      * out of the target without dropping.  This default implementation simply removes the CSS class specified by
157      * overClass (if any) from the drop element.
158      * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
159      * @param {Event} e The event
160      * @param {Object} data An object containing arbitrary data supplied by the drag source
161      */
162     notifyOut : function(dd, e, data){
163         if(this.overClass){
164             this.el.removeClass(this.overClass);
165         }
166     },
167
168     /**
169      * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the dragged item has
170      * been dropped on it.  This method has no default implementation and returns false, so you must provide an
171      * implementation that does something to process the drop event and returns true so that the drag source's
172      * repair action does not run.
173      * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
174      * @param {Event} e The event
175      * @param {Object} data An object containing arbitrary data supplied by the drag source
176      * @return {Boolean} True if the drop was valid, else false
177      */
178     notifyDrop : function(dd, e, data){
179         return false;
180     }
181 });