]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui/ygDDList.js
Release 6.5.0
[Github/sugarcrm.git] / include / javascript / yui / ygDDList.js
1
2 /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
3
4 /**
5  * @class a YAHOO.util.DDProxy implementation. During the drag over event, the
6  * dragged element is inserted before the dragged-over element.
7  *
8  * @extends YAHOO.util.DDProxy
9  * @constructor
10  * @param {String} id the id of the linked element
11  * @param {String} sGroup the group of related DragDrop objects
12  */
13 function ygDDList(id, sGroup) {
14
15         if (id) {
16                 this.init(id, sGroup);
17                 this.initFrame();
18         }
19
20         var s = this.getDragEl().style;
21         s.borderColor = "transparent";
22         s.backgroundColor = "#f6f5e5";
23         s.opacity = 0.76;
24         s.filter = "alpha(opacity=76)";
25 }
26
27 ygDDList.prototype = new YAHOO.util.DDProxy();
28
29 ygDDList.prototype.borderDiv = null;
30 ygDDList.prototype.originalDisplayProperties = Array();
31
32 // Bug #47097 : Dashlets not displayed after moving them
33 ygDDList.prototype.dashletID = null;
34 ygDDList.prototype.needsReloadAfterDrop = false;
35
36 ygDDList.prototype.startDrag = function(x, y) {
37         //this.logger.debug(this.id + " startDrag");
38
39         var dragEl = this.getDragEl();
40         var clickEl = this.getEl();
41
42     // Bug #47097 : Dashlets not displayed after moving them
43     this.needsReloadAfterDrop = false;
44     var chartContainer = YAHOO.util.Dom.getElementsByClassName('chartContainer', 'div', clickEl);
45     if ( chartContainer.length != 0 ) {
46         // try to find OBJECT tab in canvas if success - SWF used and it needs to be reloaded
47         var cee_canvas = YAHOO.util.Dom.get(this.dashletID+'-canvas');
48         if ( typeof cee_canvas != 'undefined' && cee_canvas ) {
49             // if there is object tag
50             var canvas_objects = YAHOO.util.Dom.getElementsBy(function(el){ return true;}, 'OBJECT', cee_canvas);
51             if ( canvas_objects.length != 0 ) {
52                 this.needsReloadAfterDrop = true;
53             }
54         }
55         chartContainer.innerHTML = '';
56     }
57     
58         dragEl.innerHTML = clickEl.innerHTML;
59         dragElObjects = dragEl.getElementsByTagName('object');
60
61         
62         dragEl.className = clickEl.className;
63         dragEl.style.color = clickEl.style.color;
64         dragEl.style.border = "1px solid #aaa";
65
66         // save the style of the object 
67         clickElRegion = YAHOO.util.Dom.getRegion(clickEl);
68         
69         this.borderDiv = document.createElement('div'); // create a div to display border
70         this.borderDiv.style.height = (clickElRegion.bottom - clickElRegion.top) + 'px';
71         this.borderDiv.style.border = '2px dashed #cccccc';
72         
73         for(i in clickEl.childNodes) { // hide contents of the target elements contents
74                 if(typeof clickEl.childNodes[i].style != 'undefined') {
75                         this.originalDisplayProperties[i] = clickEl.childNodes[i].style.display;
76                         clickEl.childNodes[i].style.display = 'none';
77                 }
78
79         }
80         clickEl.appendChild(this.borderDiv);
81 };
82
83 ygDDList.prototype.endDrag = function(e) {
84         // disable moving the linked element
85         var clickEl = this.getEl();
86
87         clickEl.removeChild(this.borderDiv); // remove border div
88         
89         for(i in clickEl.childNodes) { // show target elements contents
90                 if(typeof clickEl.childNodes[i].style != 'undefined') {
91                         clickEl.childNodes[i].style.display = this.originalDisplayProperties[i];
92                 }
93         }
94         
95         if(this.clickHeight) 
96             clickEl.style.height = this.clickHeight;
97         else 
98                 clickEl.style.height = '';
99         
100         if(this.clickBorder) 
101             clickEl.style.border = this.clickBorder;
102         else 
103                 clickEl.style.border = '';
104                 
105         dragEl = this.getDragEl();
106         dragEl.innerHTML = '';
107
108         this.afterEndDrag(e);
109     
110     // Bug #47097 : Dashlets not displayed after moving them
111     if ( this.needsReloadAfterDrop && this.dashletID ) {
112         SUGAR.mySugar.retrieveDashlet(this.dashletID); //"predefined_chart"
113     }
114 };
115
116 ygDDList.prototype.afterEndDrag = function(e) {
117
118 }
119
120 ygDDList.prototype.onDrag = function(e, id) {
121     
122 };
123
124 ygDDList.prototype.onDragOver = function(e, id) {
125         // this.logger.debug(this.id.toString() + " onDragOver " + id);
126         var el;
127         
128     if ("string" == typeof id) {
129         el = YAHOO.util.DDM.getElement(id);
130     } else { 
131         el = YAHOO.util.DDM.getBestMatch(id).getEl();
132     }
133     
134         dragEl = this.getDragEl();
135         elRegion = YAHOO.util.Dom.getRegion(el);
136             
137 //    this.logger.debug('id: ' + el.id);
138 //    this.logger.debug('size: ' + (elRegion.bottom - elRegion.top));
139 //    this.logger.debug('getPosY: ' + YAHOO.util.DDM.getPosY(el));
140         var mid = YAHOO.util.DDM.getPosY(el) + (Math.floor((elRegion.bottom - elRegion.top) / 2));
141 //    this.logger.debug('mid: ' + mid);
142         
143 //    this.logger.debug(YAHOO.util.DDM.getPosY(dragEl) + " <  " + mid);
144 //    this.logger.debug("Y: " + YAHOO.util.Event.getPageY(e));
145         
146         if (YAHOO.util.DDM.getPosY(dragEl) < mid ) { // insert on top triggering item
147                 var el2 = this.getEl();
148                 var p = el.parentNode;
149                 p.insertBefore(el2, el);
150         }
151         if (YAHOO.util.DDM.getPosY(dragEl) >= mid ) { // insert below triggered item
152                 var el2 = this.getEl();
153                 var p = el.parentNode;
154                 p.insertBefore(el2, el.nextSibling);
155         }
156 };
157
158 ygDDList.prototype.onDragEnter = function(e, id) {
159         // this.logger.debug(this.id.toString() + " onDragEnter " + id);
160         // this.getDragEl().style.border = "1px solid #449629";
161 };
162
163 ygDDList.prototype.onDragOut = function(e, id) {
164     // I need to know when we are over nothing
165         // this.getDragEl().style.border = "1px solid #964428";
166 }
167
168 /////////////////////////////////////////////////////////////////////////////
169
170 function ygDDListBoundary(id, sGroup) {
171         if (id) {
172                 this.init(id, sGroup);
173                 //this.logger = new ygLogger("ygDDListBoundary");
174                 this.isBoundary = true;
175         }
176 }
177
178 ygDDListBoundary.prototype = new YAHOO.util.DDTarget();