1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 Studio2.RowDD = function(id, sGroup) {
39 Studio2.RowDD.superclass.constructor.call(this, id, sGroup);
41 var el = this.getDragEl();
42 YAHOO.util.Dom.setStyle(el, "opacity", 0.67);
48 YAHOO.extend(Studio2.RowDD, YAHOO.util.DDProxy, {
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;
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');
68 YAHOO.util.Dom.setStyle(clickEl,'visibility','hidden');
69 Studio2.setScrollObj(this);
72 endDrag: function(e) {
73 Studio2.clearScrollObj();
74 ModuleBuilder.state.isDirty=true;
77 var srcEl = this.getEl();
78 var proxy = this.getDragEl();
79 var proxyid = proxy.id;
83 Studio2.removeElement(srcEl);
85 //Check if this is the new row el, which must be re-activitated
86 if (Studio2.isSpecial(srcEl)) {
87 Studio2.setSpecial(Studio2.copy());
88 Studio2.activateCopy();
89 YAHOO.util.Dom.setStyle(Studio2.copy(), "display","block");
92 // Show the proxy element and animate it to the src element's location
93 YAHOO.util.Dom.setStyle(proxy, 'visibility','');
94 YAHOO.util.Dom.setStyle(srcEl, "display","");
95 //Dom.setStyle(proxy, "visibility", "");
96 //Dom.setStyle(srcEl, "display",""); // display!=none for getXY to work
98 /*Ext.get(proxy).alignTo(srcEl, 'tl', null, {
99 callback: function(){*/
100 YAHOO.util.Dom.setStyle(proxyid,"visibility","hidden");
101 YAHOO.util.Dom.setStyle(thisid,"visibility","");
105 if (Studio2.isSpecial(srcEl)) {
106 if (Studio2.establishLocation(srcEl) == 'panels') {
107 // dropping on the panels means that the row is no longer special
108 Studio2.unsetSpecial(srcEl);
109 // now remove the title for this new row - only wanted while we were in the toolbox
110 for (var i=0;i<srcEl.childNodes.length;i++) {
111 if (srcEl.childNodes[i].tagName.toUpperCase() == 'SPAN') {
112 srcEl.removeChild(srcEl.childNodes[i]);
116 Studio2.setSpecial(Studio2.copy());
117 Studio2.activateCopy();
118 YAHOO.util.Dom.setStyle(Studio2.copy(), "display","block");
122 // we have a special row that hasn't been moved to the panels area - invalid drop, so remove the copy if there is one
123 var copy = document.getElementById(Studio2.copyId);
124 copy.parentNode.removeChild(copy);
125 Studio2.copyID = null;
129 // If we've just removed the last row from a panel then we need to remove the panel
130 // Brute force approach as can't easily discover where this row came from
132 var panels = document.getElementById('panels');
134 for (var i=0;i<panels.childNodes.length;i++) {
135 var panel = panels.childNodes[i];
136 if (panel.nodeName == 'DIV') { // a panel
137 Studio2.tidyRows(panel);
143 onInvalidDrop: function(e) {
144 Studio2.clearScrollObj();
145 this.getDragEl().innerHTML = '';
148 onDragDrop: function(e, id) {
149 var srcEl = this.getEl();
150 var destEl = document.getElementById(id); // where this element is being dropped
152 // if source was in a panel (not toolbox) and destination is the delete area then remove this element
153 var srcLoc = Studio2.establishLocation(srcEl);
154 var dstLoc = Studio2.establishLocation(destEl);
155 if ((Studio2.establishLocation(srcEl) == 'panels') && (Studio2.establishLocation(destEl) == 'delete')) {
156 this.deleteRow = true;
160 onDrag: Studio2.onDrag,
162 onDragOver: function(e, id) {
163 var srcEl = this.getEl();
164 var destEl = document.getElementById(id);
165 var srcLoc = Studio2.establishLocation(srcEl);
166 var dstLoc = Studio2.establishLocation(destEl);
168 if ((Studio2.establishLocation(destEl) == 'panels') && (destEl.className.indexOf('le_row') != -1)) {
169 YAHOO.util.Dom.setStyle(srcEl, "visibility","hidden");
170 YAHOO.util.Dom.setStyle(srcEl, "display" ,"block");
171 var orig_p = srcEl.parentNode;
172 var p = destEl.parentNode;
175 p.insertBefore(srcEl, destEl); // insert above
177 p.insertBefore(srcEl, destEl.nextSibling); // insert below