]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/javascript/studio2PanelDD.js
Release 6.2.0
[Github/sugarcrm.git] / modules / ModuleBuilder / javascript / studio2PanelDD.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.PanelDD = function(id, sGroup) {
39         Studio2.PanelDD.superclass.constructor.call(this, id, sGroup);
40
41     var el = this.getDragEl();
42         YAHOO.util.Dom.setStyle(el, "opacity", 0.67) // The proxy is slightly transparent
43     this.goingUp = false;
44     this.lastY = 0;
45 };
46
47         
48 YAHOO.extend(Studio2.PanelDD, 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.className = clickEl.className;
55                 dragEl.innerHTML = "";
56                 Studio2.copyChildren(clickEl, dragEl);
57                 this.deletePanel = false;
58                 Studio2.copyId = null;
59                 dragEl.style.width = clickEl.offsetWidth + "px";
60                 dragEl.style.height = clickEl.offsetHeight + "px";
61
62                 if (Studio2.establishLocation(clickEl) == 'toolbox') {
63                         var copy = Studio2.newPanel();
64                         Studio2.setCopy(copy);
65                         clickEl.parentNode.insertBefore(copy,clickEl.nextSibling);
66                         YAHOO.util.Dom.setStyle(copy, 'display','block'); // must make it visible - the css sets rows outside of panel to invisible
67                         YAHOO.util.Dom.setStyle(clickEl, "display","none");
68                 }
69
70                 YAHOO.util.Dom.setStyle(clickEl, "visibility", "hidden");
71     },
72
73     endDrag: function(e) {
74                 ModuleBuilder.state.isDirty=true;
75 //      alert("endDrag");
76      
77         var srcEl = this.getEl();
78         var proxy = this.getDragEl();      
79         var proxyid = proxy.id;
80         var thisid = this.id;
81         
82         if (this.deletePanel) {
83                         Studio2.removeElement(srcEl);
84                         // If we've just removed the last panel then we need to put an empty panel back in
85                         proxy.innerHTML = '';
86                 Studio2.tidyPanels();
87         } else {
88         
89                 // Show the proxy element and animate it to the src element's location
90                 YAHOO.util.Dom.setStyle(proxy, "visibility", "");
91                 YAHOO.util.Dom.setStyle(srcEl, "display",""); // display!=none for getXY to work
92                 
93                         //Ext.get(proxy).alignTo(srcEl, 'tl', null, {callback:function(){
94                 YAHOO.util.Dom.setStyle(proxyid, "visibility", "hidden");
95                 YAHOO.util.Dom.setStyle(thisid, "visibility", "");
96                 
97         //});
98         
99                         if (Studio2.isSpecial(srcEl)) {
100                                 if (Studio2.establishLocation(srcEl) == 'panels') {
101                                         // dropping on the panels means that the panel is no longer special
102                                         Studio2.unsetSpecial(srcEl);
103                                         // add in the template row to the new panel
104                                         var newRow = Studio2.newRow(false);
105                                         srcEl.appendChild(newRow);
106                                         // bug 16470: change the panel title to make it unique
107                                         var view = document.getElementById('prepareForSave').view.value;
108                                         var view_module = document.getElementById('prepareForSave').view_module.value
109                                         var panelLabel = document.getElementById("le_panelid_"+srcEl.id).childNodes[0].nodeValue.toUpperCase() ;
110                                         var panelLabelNoID = 'lbl_' + view +  '_panel';
111                     var panelNumber = panelLabel.substring(panelLabelNoID.length) ;
112                                         var panelDisplay = SUGAR.language.get('ModuleBuilder', 'LBL_NEW_PANEL') + ' ' + panelNumber ;
113                                         document.getElementById("le_panelname_"+srcEl.id).childNodes[0].nodeValue =  panelDisplay ;
114                                         var params = { module: 'ModuleBuilder' , action: 'saveProperty', view_module: view_module }
115                                         if (document.getElementById('prepareForSave').view_package)
116                                         {
117                                            params ['view_package'] = document.getElementById('prepareForSave').view_package.value ;
118                                         }
119                                         params [ 'label_'+panelLabel ] = panelDisplay ;
120                                         YAHOO.util.Connect.asyncRequest(
121                                                 "POST",
122                                                 'index.php',
123                                                 false,
124                                                 SUGAR.util.paramsToUrl(params)
125                     );
126                                         Studio2.activateElement(newRow);
127                                         Studio2.setSpecial(Studio2.copy());
128                                         Studio2.activateCopy();
129                                         YAHOO.util.Dom.setStyle(Studio2.copy(), "display", "block");
130                                 }
131                                 else
132                                 {
133                                         // we have a special panel that hasn't been moved to the panels area - invalid drop, so remove the copy if there is one
134                                         var copy = document.getElementById(Studio2.copyId);
135                                         copy.parentNode.removeChild(copy);
136                                         Studio2.copyID = null;
137                                 }
138                         }
139                 }
140     },
141
142         onInvalidDrop: function(e) {
143 //              alert("invalid");
144                 var srcEl = this.getEl();
145                 var dragEl = this.getDragEl();
146                 dragEl.innerHTML = '';
147         },
148         
149     onDragDrop: function(e, id) {
150 //              alert("ondragdrop");
151                 
152                 var srcEl = this.getEl();
153                 var destEl = document.getElementById(id); // where this element is being dropped
154                 
155                 // if source was in a panel (not toolbox) and destination is the delete area then remove this element
156                 if ((Studio2.establishLocation(srcEl) == 'panels') && (Studio2.establishLocation(destEl) == 'delete')) {
157                         this.deletePanel = true;
158                         //Studio2.removeElement(srcEl);
159                 }
160     },
161
162     onDrag: function(e) {
163         // Keep track of the direction of the drag for use during onDragOver
164         var y = e.pageY;
165
166         if (y < this.lastY) {
167             this.goingUp = true;
168         } else if (y > this.lastY) {
169             this.goingUp = false;
170         }
171
172         this.lastY = y;
173     },
174
175     onDragOver: function(e, id) {
176         var srcEl = this.getEl();
177                 var destEl = YAHOO.util.Dom.get(id);
178                 var dragEl = this.getDragEl();
179
180         if ((Studio2.establishLocation(destEl) == 'panels') && (destEl.className.indexOf('le_panel') != -1)) {
181                 YAHOO.util.Dom.setStyle(srcEl, 'visibility','hidden');
182                 YAHOO.util.Dom.setStyle(srcEl, 'display','block');
183                 var orig_p = srcEl.parentNode;
184             var p = destEl.parentNode;
185             
186             var mid = YAHOO.util.Dom.getY(destEl) + (destEl.offsetHeight / 2);
187
188             if (YAHOO.util.Dom.getY(dragEl) < mid) {
189                                 p.insertBefore(srcEl, destEl); // insert above
190             } else {
191                 p.insertBefore(srcEl, destEl.nextSibling); // insert below
192             }
193         }
194
195     }
196 });
197
198