1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2013 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 ********************************************************************************/
37 Studio2.FieldDD = function(id, sGroup) {
38 Studio2.FieldDD.superclass.constructor.call(this, id, sGroup);
42 YAHOO.extend(Studio2.FieldDD, YAHOO.util.DDProxy, {
44 startDrag: function(x, y) {
45 // make the proxy look like the source element
46 var dragEl = this.getDragEl();
47 var clickEl = this.getEl();
48 dragEl.innerHTML = clickEl.innerHTML;
49 dragEl.className = clickEl.className;
50 Studio2.copyId = null;
51 this.showAnimation = true;
53 if (Studio2.isSpecial(clickEl) && (Studio2.establishLocation(clickEl) == 'toolbox')) {
54 var copy = Studio2.copyElement(clickEl);
55 Studio2.setCopy(copy);
56 clickEl.parentNode.insertBefore(copy,clickEl.nextSibling);
57 YAHOO.util.Dom.setStyle(clickEl, "display", "none"); // don't want it to take up any space
59 YAHOO.util.Dom.setStyle(clickEl, "visibility", "hidden"); // want a empty space as we're dragging it away from this place
61 Studio2.setScrollObj(this);
64 endDrag: function(e) {
65 Studio2.clearScrollObj();
66 ModuleBuilder.state.isDirty=true;
67 var srcEl = this.getEl();
68 var proxy = this.getDragEl();
69 var proxyid = proxy.id;
72 if (YAHOO.util.Dom.get(srcEl)) { // if we have a valid srcEl still...hasn't been deleted earlier
73 // Show the proxy element and animate it to the src element's location
74 YAHOO.util.Dom.setStyle(proxy, "visibility", "");
75 YAHOO.util.Dom.setStyle(srcEl, "display", ""); // display!=none for getXY to work
76 //YAHOO.util.Dom.setStyle(proxy).alignTo(srcEl, 'tl', null, {
77 //callback: function(){
78 YAHOO.util.Dom.setStyle(proxyid, "visibility", "hidden");
79 if(typeof(YAHOO.util.Dom.get(thisid)) != 'undefined' && YAHOO.util.Dom.get(thisid)!=null)
80 YAHOO.util.Dom.setStyle(thisid, "visibility", "");
82 if (Studio2.isSpecial(srcEl) && Studio2.copy()) {
83 Studio2.activateCopy(); // activateCopy makes it active, and removes the flag that says there is a copy
89 onInvalidDrop: function(e) {
90 Studio2.clearScrollObj();
91 var dragEl = this.getDragEl();
92 dragEl.innerHTML = '';
94 YAHOO.util.Dom.setStyle(this.getEl(), "display", "block");
97 onDrag: Studio2.onDrag,
99 onDragDrop: function(e, id) {
100 var srcEl = this.getEl();
101 var destEl = YAHOO.util.Dom.get(id); // where this element is being dropped
103 var srcLocation = Studio2.establishLocation(srcEl);
104 var destLocation = Studio2.establishLocation(destEl);
106 // CASE1: Trying to delete an item from the toolbox or move fields within the toolbox - don't allow
107 if ( ((srcLocation == 'toolbox') && (destLocation == 'delete')) ||
108 ((srcLocation == 'toolbox') && (destLocation == 'toolbox'))) {
109 Studio2.removeCopy();
110 YAHOO.util.Dom.setStyle(srcEl, "display", "block"); // make it visible again - we made special elements invisible in startDrag
113 // CASE2: Delete a panel element
114 // if source was in a panel (not toolbox) and destination is delete then remove this element
115 if ((srcLocation == 'panels') && (destLocation == 'delete')) {
117 if(Studio2.isSpecial(srcEl)) //nsingh- Bug 23057 Disallow deleting a (filler) as it does not make sense to do so.
119 var parent = srcEl.parentNode;
120 var sibling = srcEl.previousSibling;
121 while(sibling != null) {
122 if (sibling.className && (sibling.className.indexOf('le_field') != -1)) {
125 sibling = sibling.previousSibling;
127 if (sibling == null) {
128 sibling = srcEl.nextSibling;
129 while(sibling != null) {
130 if (sibling.className && (sibling.className.indexOf('le_field') != -1)) {
133 sibling = sibling.nextSibling;
136 Studio2.removeElement(srcEl);
137 Studio2.unregisterExpandableField( srcEl );
138 // this.showAnimation = false; // can't show animation as the source no longer exists
139 if (sibling == null) {
140 // If we've just deleted the last field from a panel then we need to tidy up
141 Studio2.tidyFields(parent);
143 Studio2.registerExpandableField(sibling);
148 // CASE3: Simple field swap
149 // Either neither one is special, or they're both special and both in panels
150 if (( ! Studio2.isSpecial(srcEl) && ! Studio2.isSpecial(destEl)) ||
151 ( Studio2.isSpecial(srcEl) && Studio2.isSpecial(destEl) && (srcLocation == 'panels') && (destLocation == 'panels')) ) {
152 Studio2.swapElements(srcEl, destEl);
153 this.runSpecialCode(srcEl, destEl);
158 // CASE4: swapping a special field from the toolbox with a field in a panel
159 if (Studio2.copy() && (destLocation == 'panels')) {
160 // CASE: split a field
161 //Disallow (filler) on (filler)
162 if( Studio2.isSpecial(destEl) ) {Studio2.removeCopy(); return }
164 var destSibling = Studio2.nextField( destEl ) || Studio2.prevField( destEl );
165 if( Studio2.isExpandable( destEl ) && destEl.getAttribute("state") == 'expanded' ){
166 Studio2.removeCopy(); return;
168 if( Studio2.isExpandable( destEl ) && destEl.getAttribute("state") == 'reduced' ){ Studio2.unregisterExpandableField( destEl ); }
169 var copy = Studio2.copyElement(srcEl);
170 Studio2.activateElement(copy);
171 YAHOO.util.Dom.setStyle(copy, "display", "");
172 Studio2.swapElements( Studio2.copy(),destEl );
173 YAHOO.util.Dom.setStyle(srcEl, "display", "");
174 Studio2.registerExpandableField (destSibling );
179 // CASE5: moving a plain field from the panel to a special field in the toolbox - just copy
180 if ( ! Studio2.isSpecial(srcEl) && Studio2.isSpecial(destEl) && (destLocation == 'toolbox')) {
181 // make a copy of the destination
182 if(Studio2.isExpandable (srcEl ) && Studio2.isExpanded( srcEl)) {
183 Studio2.toggleFieldWidth(srcEl.id); //bring back the old filler.
184 Studio2.unregisterExpandableField ( srcEl );
186 //check if srcSibling needs to expand
187 // var srcSibling = ;
189 var copy = Studio2.copyElement(destEl);
190 var destination = document.getElementById('availablefields');
191 destination.appendChild(copy);
192 Studio2.swapElements(copy,srcEl);
193 YAHOO.util.Dom.setStyle(srcEl, "display", "");
194 Studio2.activateElement(copy);
195 //if src is expanded, reduce it then unregister
199 Studio2.registerExpandableField( Studio2.nextField( srcEl ) || Studio2.prevField( srcEl ) );
203 //CASE6: (filler) droppped on a expandable field.
204 if(Studio2.isSpecial(srcEl) && destLocation == srcLocation ){
205 //Disallow Swap if dropping on a expanded field.
206 if( Studio2.isExpandable( destEl ) && Studio2.isExpanded( destEl )) {return; }
207 var srcSibling = Studio2.prevField( srcEl ) || Studio2.nextField( srcEl );
208 var destSibling = Studio2.prevField( destEl ) || Studio2.nextField( destEl );
209 Studio2.swapElements(srcEl, destEl); //don't change order.
210 if ( !Studio2.isExpandable( destSibling ) && Studio2.isExpandable(srcSibling) && Studio2.isReduced(srcSibling) && !(srcSibling.id == destEl.id && srcEl.id == destSibling.id)) {
211 Studio2.unregisterExpandableField( srcSibling );
212 Studio2.registerExpandableField (destSibling );
213 Studio2.unregisterExpandableField( destEl );
215 if ( !Studio2.isExpandable( destEl ) && Studio2.isSpecial( destSibling )) {
216 Studio2.registerExpandableField (destEl );
218 if(!Studio2.isSpecial(destSibling)) {Studio2.registerExpandableField (destSibling )}
221 //CASE 7: A special field swapped with a regular field. Source is not-special, destination is special.
222 if(!Studio2.isSpecial(srcEl) && Studio2.isSpecial(destEl) && destLocation == srcLocation) {
224 if destination's left sibling is expandable.
225 unregister left sibling from expandable.
226 if src field's left sibling is not special
227 register left sibling to expandable.
230 var srcSibling = Studio2.prevField(srcEl) || Studio2.nextField( srcEl ) ;
231 var destSibling = Studio2.prevField(destEl) || Studio2.nextField( destEl );
233 var sameRow = (srcSibling!=null && destSibling!=null) ? (srcSibling.id == destEl.id && destSibling.id == srcEl.id) : false;
235 if (Studio2.isExpandable( srcEl ) && Studio2.isExpanded( srcEl )) {return;} //disallow dropping expanded fields onto fillers.
236 if (Studio2.isExpandable ( srcEl ) && Studio2.isReduced( srcEl ) && !sameRow) {Studio2.unregisterExpandableField( srcEl );}
237 if (Studio2.isExpandable (destSibling) && !sameRow ){Studio2.unregisterExpandableField( destSibling )}
239 if( srcEl.id == destSibling.id && srcSibling.id == destEl.id ) {Studio2.registerExpandableField ( srcEl ) }
240 Studio2.swapElements(srcEl, destEl);
241 if (Studio2.isSpecial(destSibling)) {Studio2.registerExpandableField(srcEl)}
242 Studio2.registerExpandableField( srcSibling );
248 if( !Studio2.isSpecial( srcEl ) && Studio2.isSpecial( destEl) && destLocation == 'panels' && srcLocation =='toolbox'){
249 var destSibling = Studio2.nextField( destEl ) || Studio2.prevField ( destEl );
250 Studio2.unregisterExpandableField( destSibling );
251 Studio2.swapElements( srcEl,destEl );
252 Studio2.removeElement( destEl ) ;
256 Studio2.swapElements( srcEl,destEl );
257 this.runSpecialCode(srcEl,destEl);
258 if ((srcLocation != destLocation)) {
259 if (Studio2.isSpecial(srcEl) && ! Studio2.isSpecial(destEl)) {
260 Studio2.removeElement(srcEl);
261 // this.showAnimation = false;
264 if (Studio2.isSpecial(destEl) && ! Studio2.isSpecial(srcEl)) {
265 Studio2.removeElement(destEl);
266 // this.showAnimation = false;
273 runSpecialCode: function(srcEl, destEl){
274 var srcLeftSibling = Studio2.prevField(srcEl);
275 var srcRightSibling = Studio2.nextField(srcEl);
276 var destRightSibling = Studio2.nextField(destEl);
277 var destLeftSibling = Studio2.prevField(destEl);
280 //For every affected element unexpand if needed.
281 //registration vs Transformation.
283 if ( Studio2.isExpandable (srcEl ) && Studio2.isExpandable( destEl) ){
284 //src is dest now. copy dest's properties to src.
285 Studio2.swapStates( srcEl, destEl );
286 //srcEl.setAttribute("state", destEl.getAttribute("state"));
288 var registerSrc = !Studio2.isExpandable( srcEl );
289 var destExpandable = !Studio2.isSpecial(destEl) && ((null==destRightSibling && null==destLeftSibling)
290 || (null !== destRightSibling) && Studio2.isSpecial(destRightSibling));
292 var srcUnexpandable = !Studio2.isSpecial(srcEl) && ((null!==srcLeftSibling && !Studio2.isSpecial(srcLeftSibling))
293 || ((null !== srcRightSibling) && !Studio2.isSpecial(srcRightSibling)));
294 var destUnexpandable = !Studio2.isSpecial(destEl) && ((null!==destLeftSibling && !Studio2.isSpecial(destLeftSibling))
295 || ((null!== destRightSibling) && !Studio2.isSpecial(destRightSibling)));
299 Studio2.registerExpandableField( srcEl );
302 Studio2.unregisterExpandableField( srcEl );
305 Studio2.registerExpandableField(destEl);
307 if(destUnexpandable){
308 Studio2.unregisterExpandableField( destEl );
310 if(srcLeftSibling!==null && !Studio2.isSpecial(srcLeftSibling) && !Studio2.isSpecial(srcEl))
311 Studio2.unregisterExpandableField( srcLeftSibling );