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.PanelDD = function(id, sGroup) {
39 Studio2.PanelDD.superclass.constructor.call(this, id, sGroup);
41 var el = this.getDragEl();
42 YAHOO.util.Dom.setStyle(el, "opacity", 0.67) // The proxy is slightly transparent
48 YAHOO.extend(Studio2.PanelDD, YAHOO.util.DDProxy, {
50 startDrag: function(x, y) {
51 var Dom = YAHOO.util.Dom;
52 // make the proxy look like the source element
53 var dragEl = this.getDragEl();
54 var clickEl = this.getEl();
55 dragEl.className = clickEl.className;
56 dragEl.innerHTML = "";
57 Studio2.copyChildren(clickEl, dragEl);
58 this.deletePanel = false;
59 Studio2.copyId = null;
60 dragEl.style.width = clickEl.offsetWidth + "px";
61 dragEl.style.height = clickEl.offsetHeight + "px";
63 if (Studio2.establishLocation(clickEl) == 'toolbox') {
64 var copy = Studio2.newPanel();
65 Studio2.setCopy(copy);
66 clickEl.parentNode.insertBefore(copy,clickEl.nextSibling);
67 // must make it visible - the css sets rows outside of panel to invisible
68 Dom.setStyle(copy, 'display','block');
69 Dom.setStyle(clickEl, "display","none");
72 Dom.setStyle(clickEl, "visibility", "hidden");
73 Studio2.setScrollObj(this);
76 endDrag: function(e) {
77 ModuleBuilder.state.isDirty=true;
78 Studio2.clearScrollObj();
81 var srcEl = this.getEl();
82 var proxy = this.getDragEl();
83 var proxyid = proxy.id;
86 if (this.deletePanel) {
87 Studio2.removeElement(srcEl);
88 // If we've just removed the last panel then we need to put an empty panel back in
91 //Check if this is the toolbox panel which must be re-activitated
92 if (Studio2.isSpecial(srcEl))
94 Studio2.setSpecial(Studio2.copy());
95 Studio2.activateCopy();
96 YAHOO.util.Dom.setStyle(Studio2.copy(), "display", "block");
100 // Show the proxy element and animate it to the src element's location
101 YAHOO.util.Dom.setStyle(proxy, "visibility", "");
102 YAHOO.util.Dom.setStyle(srcEl, "display",""); // display!=none for getXY to work
104 //Ext.get(proxy).alignTo(srcEl, 'tl', null, {callback:function(){
105 YAHOO.util.Dom.setStyle(proxyid, "visibility", "hidden");
106 YAHOO.util.Dom.setStyle(thisid, "visibility", "");
110 if (Studio2.isSpecial(srcEl)) {
111 if (Studio2.establishLocation(srcEl) == 'panels') {
112 // dropping on the panels means that the panel is no longer special
113 Studio2.unsetSpecial(srcEl);
114 // add in the template row to the new panel
115 var newRow = Studio2.newRow(false);
116 srcEl.appendChild(newRow);
117 // bug 16470: change the panel title to make it unique
118 var view = document.getElementById('prepareForSave').view.value;
119 var view_module = document.getElementById('prepareForSave').view_module.value
120 var panelLabel = document.getElementById("le_panelid_"+srcEl.id).childNodes[0].nodeValue.toUpperCase() ;
121 var panelLabelNoID = 'lbl_' + view + '_panel';
122 var panelNumber = panelLabel.substring(panelLabelNoID.length) ;
123 var panelDisplay = SUGAR.language.get('ModuleBuilder', 'LBL_NEW_PANEL') + ' ' + panelNumber ;
124 document.getElementById("le_panelname_"+srcEl.id).childNodes[0].nodeValue = panelDisplay ;
125 var params = { module: 'ModuleBuilder' , action: 'saveProperty', view_module: view_module }
126 if (document.getElementById('prepareForSave').view_package)
128 params ['view_package'] = document.getElementById('prepareForSave').view_package.value ;
130 params [ 'label_'+panelLabel ] = panelDisplay ;
131 YAHOO.util.Connect.asyncRequest(
135 SUGAR.util.paramsToUrl(params)
137 Studio2.activateElement(newRow);
138 Studio2.setSpecial(Studio2.copy());
139 Studio2.activateCopy();
140 YAHOO.util.Dom.setStyle(Studio2.copy(), "display", "block");
144 // we have a special panel that hasn't been moved to the panels area - invalid drop, so remove the copy if there is one
145 var copy = document.getElementById(Studio2.copyId);
146 copy.parentNode.removeChild(copy);
147 Studio2.copyID = null;
153 onInvalidDrop: function(e) {
155 var srcEl = this.getEl();
156 var dragEl = this.getDragEl();
157 dragEl.innerHTML = '';
158 Studio2.clearScrollObj();
162 onDragDrop: function(e, id) {
163 // alert("ondragdrop");
165 var srcEl = this.getEl();
166 var destEl = document.getElementById(id); // where this element is being dropped
168 // if source was in a panel (not toolbox) and destination is the delete area then remove this element
169 if ((Studio2.establishLocation(srcEl) == 'panels') && (Studio2.establishLocation(destEl) == 'delete')) {
170 this.deletePanel = true;
171 //Studio2.removeElement(srcEl);
175 onDrag: Studio2.onDrag,
177 onDragOver: function(e, id) {
178 var srcEl = this.getEl();
179 var destEl = YAHOO.util.Dom.get(id);
180 var dragEl = this.getDragEl();
181 var loc = Studio2.establishLocation(destEl);
182 if ((loc == 'panels') && (destEl.className.indexOf('le_panel') != -1)) {
183 YAHOO.util.Dom.setStyle(srcEl, 'visibility','hidden');
184 YAHOO.util.Dom.setStyle(srcEl, 'display','block');
185 var orig_p = srcEl.parentNode;
186 var p = destEl.parentNode;
188 var mid = YAHOO.util.Dom.getY(destEl) + (destEl.offsetHeight / 2);
190 if (YAHOO.util.Dom.getY(dragEl) < mid) {
191 p.insertBefore(srcEl, destEl); // insert above
193 p.insertBefore(srcEl, destEl.nextSibling); // insert below