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