]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/javascript/studio2RowDD.js
Release 6.2.0
[Github/sugarcrm.git] / modules / ModuleBuilder / javascript / studio2RowDD.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37
38 Studio2.RowDD = function(id, sGroup) {
39         Studio2.RowDD.superclass.constructor.call(this, id, sGroup);
40
41     var el = this.getDragEl();
42     YAHOO.util.Dom.setStyle(el, "opacity", 0.67);
43         this.goingUp = false;
44     this.lastY = 0;
45 };
46
47         
48 YAHOO.extend(Studio2.RowDD, YAHOO.util.DDProxy, {
49
50     startDrag: function(x, y) {         
51         // make the proxy look like the source element
52                 var dragEl = this.getDragEl();
53                 var clickEl = this.getEl();
54                 dragEl.innerHTML = "";
55                 Studio2.copyChildren(clickEl, dragEl);
56                 dragEl.className = clickEl.className;
57                 this.deleteRow = false;
58                 Studio2.copyId = null;
59                 
60                 if (Studio2.isSpecial(clickEl)) {
61                         var copy = Studio2.newRow(true);
62                         Studio2.setCopy(copy);
63                         clickEl.parentNode.insertBefore(copy,clickEl.nextSibling);
64                         YAHOO.util.Dom.setStyle(copy, 'display','block');
65                         YAHOO.util.Dom.setStyle(clickEl, 'display','none');
66                 }
67                 
68                 YAHOO.util.Dom.setStyle(clickEl,'visibility','hidden');
69     },
70
71     endDrag: function(e) {
72                 ModuleBuilder.state.isDirty=true;
73  //     alert("endDrag");
74      
75         var srcEl = this.getEl();
76         var proxy = this.getDragEl();      
77         var proxyid = proxy.id;
78         var thisid = this.id;
79         
80         if (this.deleteRow) {
81                         Studio2.removeElement(srcEl);
82                         proxy.innerHTML = '';
83         } else {
84                 // Show the proxy element and animate it to the src element's location
85                 YAHOO.util.Dom.setStyle(proxy, 'visibility','');
86                 YAHOO.util.Dom.setStyle(srcEl, "display","");
87                 //Dom.setStyle(proxy, "visibility", "");
88                 //Dom.setStyle(srcEl, "display",""); // display!=none for getXY to work
89         
90                 /*Ext.get(proxy).alignTo(srcEl, 'tl', null, {
91                                 callback: function(){*/
92                                 YAHOO.util.Dom.setStyle(proxyid,"visibility","hidden");
93                                 YAHOO.util.Dom.setStyle(thisid,"visibility","");
94                                 //}
95                         //});
96                 
97                         if (Studio2.isSpecial(srcEl)) {
98                                 if (Studio2.establishLocation(srcEl) == 'panels') {
99                                         // dropping on the panels means that the row is no longer special
100                                         Studio2.unsetSpecial(srcEl);
101                                         // now remove the title for this new row - only wanted while we were in the toolbox
102                                         for (var i=0;i<srcEl.childNodes.length;i++) {
103                                                 if (srcEl.childNodes[i].tagName.toUpperCase() == 'SPAN') {
104                                                         srcEl.removeChild(srcEl.childNodes[i]);
105                                                         break;
106                                                 }
107                                         }
108                                         Studio2.setSpecial(Studio2.copy());
109                                         Studio2.activateCopy();
110                                         YAHOO.util.Dom.setStyle(Studio2.copy(), "display","block");
111                                 }
112                                 else
113                                 {
114                                         // we have a special row that hasn't been moved to the panels area - invalid drop, so remove the copy if there is one
115                                         var copy = document.getElementById(Studio2.copyId);
116                                         copy.parentNode.removeChild(copy);
117                                         Studio2.copyID = null;
118                                 }
119                         }
120         } 
121         // If we've just removed the last row from a panel then we need to remove the panel
122                 // Brute force approach as can't easily discover where this row came from
123                 
124                 var panels = document.getElementById('panels');
125                 
126                 for (var i=0;i<panels.childNodes.length;i++) {
127                         var panel = panels.childNodes[i];
128                         if (panel.nodeName == 'DIV') { // a panel
129                                 Studio2.tidyRows(panel);
130                 }
131                 }
132
133     },
134
135         onInvalidDrop: function(e) {
136                 this.getDragEl().innerHTML = '';
137         },
138         
139     onDragDrop: function(e, id) {
140                 var srcEl = this.getEl();
141                 var destEl = document.getElementById(id); // where this element is being dropped
142                 
143                 // if source was in a panel (not toolbox) and destination is the delete area then remove this element
144                 var srcLoc = Studio2.establishLocation(srcEl);
145                 var dstLoc = Studio2.establishLocation(destEl);
146                 if ((Studio2.establishLocation(srcEl) == 'panels') && (Studio2.establishLocation(destEl) == 'delete')) {
147                         this.deleteRow = true;
148                 }
149     },
150
151     onDrag: function(e) {
152        // Keep track of the direction of the drag for use during onDragOver
153         var y = e.pageY;
154
155         if (y < this.lastY) {
156             this.goingUp = true;
157         } else if (y > this.lastY) {
158             this.goingUp = false;
159         }
160
161         this.lastY = y;
162     },
163
164     onDragOver: function(e, id) {
165         var srcEl = this.getEl();
166         var destEl = document.getElementById(id);
167         var srcLoc = Studio2.establishLocation(srcEl);
168                 var dstLoc = Studio2.establishLocation(destEl);
169                 if ((Studio2.establishLocation(destEl) == 'panels') && (destEl.className.indexOf('le_row') != -1)) {
170                 
171                 YAHOO.util.Dom.setStyle(srcEl, "visibility","hidden");
172                 YAHOO.util.Dom.setStyle(srcEl, "display"   ,"block");
173                 var orig_p = srcEl.parentNode;
174             var p = destEl.parentNode;
175
176             if (this.goingUp) {
177                                 p.insertBefore(srcEl, destEl); // insert above
178             } else {
179                 p.insertBefore(srcEl, destEl.nextSibling); // insert below
180             }
181         }
182     }
183 });
184
185