]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/javascript/studio2ListDD.js
Release 6.4.1
[Github/sugarcrm.git] / modules / ModuleBuilder / javascript / studio2ListDD.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 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  Studio2.ListDD = function(el, sGroup, fromOnly) {
38         if (typeof el == 'number') {
39                 el = el + "";
40         }
41         if (typeof el == 'string')
42                 el = document.getElementById(el);
43         if (el != null) {
44                 var Dom = YAHOO.util.Dom;
45                 Studio2.ListDD.superclass.constructor.call(this, el, sGroup);
46                 this.addInvalidHandleType("input");
47                 this.addInvalidHandleType("a");
48                 var dEl = this.getDragEl()
49                 Dom.setStyle(dEl, "borderColor", "#FF0000");
50                 Dom.setStyle(dEl, "backgroundColor", "#e5e5e5");
51                 Dom.setStyle(dEl, "opacity", 0.76);
52                 Dom.setStyle(dEl, "filter", "alpha(opacity=76)");
53                 this.fromOnly = fromOnly;
54         }
55 };
56
57 YAHOO.extend(Studio2.ListDD, YAHOO.util.DDProxy, {
58         copyStyles : {'opacity':"", 'border':"", 'height':"", 'filter':"", 'zoom':""},
59     startDrag: function(x, y){
60                 //We need to make sure no inline editors are in use, as drag.drop can break them
61                 if (typeof (SimpleList) != "undefined") {
62                         SimpleList.endCurrentDropDownEdit();
63                 }
64                 
65                 var Dom = YAHOO.util.Dom;
66                 var dragEl = this.getDragEl();
67                 var clickEl = this.getEl();
68                 
69                 this.parentID = clickEl.parentNode.id;
70                 this.clickContent = clickEl.innerHTML;
71                 dragEl.innerHTML = clickEl.innerHTML;
72                 
73                 Dom.addClass(dragEl, clickEl.className);
74                 Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));
75                 Dom.setStyle(dragEl, "height", Dom.getStyle(clickEl, "height"));
76                 Dom.setStyle(dragEl, "border", "1px solid #aaa");
77                 
78                 // save the style of the object 
79                 if (this.clickStyle == null) {
80                         this.clickStyle = {};
81                         for (var s in this.copyStyles) {
82                                 this.clickStyle[s] = clickEl.style[s];
83                         }
84                         if (typeof(this.clickStyle['border']) == 'undefined' || this.clickStyle['border'] == "") 
85                                 this.clickStyle['border'] = "1px solid";
86                 }
87                 
88                 Dom.setStyle(clickEl, "opacity", 0.5);
89                 Dom.setStyle(clickEl, "filter", "alpha(opacity=10)");
90                 Dom.setStyle(clickEl, "border", '2px dashed #cccccc');
91         Studio2.setScrollObj(this);
92         },
93         
94         updateTabs: function(){
95                 studiotabs.moduleTabs = [];
96                 for (j = 0; j < studiotabs.slotCount; j++) {
97                 
98                         var ul = document.getElementById('ul' + j);
99                         studiotabs.moduleTabs[j] = [];
100                         items = ul.getElementsByTagName("li");
101                         for (i = 0; i < items.length; i++) {
102                                 if (items.length == 1) {
103                                         items[i].innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_DROP_HERE');
104                                 }
105                                 else if (items[i].innerHTML == SUGAR.language.get('ModuleBuilder', 'LBL_DROP_HERE')) {
106                                         items[i].innerHTML = '';
107                                 }
108                                 studiotabs.moduleTabs[ul.id.substr(2, ul.id.length)][studiotabs.subtabModules[items[i].id]] = true;
109                         }       
110                 }       
111         },
112         
113         endDrag: function(e){
114         Studio2.clearScrollObj();
115                 ModuleBuilder.state.isDirty=true;
116                 var clickEl = this.getEl();
117                 var clickExEl = new YAHOO.util.Element(clickEl);
118                 dragEl = this.getDragEl();
119                 dragEl.innerHTML = "";
120                 clickEl.innerHTML = this.clickContent;
121                 
122                 var p = clickEl.parentNode;
123                 if (p.id == 'trash') {
124                         p.removeChild(clickEl);
125                         this.lastNode = false;
126                         this.updateTabs();
127                         return;
128                 }
129                 
130                 for(var style in this.clickStyle) {
131                         if (typeof(this.clickStyle[style]) != 'undefined')
132                                 clickExEl.setStyle(style, this.clickStyle[style]);
133                         else
134                                 clickExEl.setStyle(style, '');
135                 }
136                 
137                 this.clickStyle = null;
138                 
139                 if (this.lastNode) {
140                         this.lastNode.id = 'addLS' + addListStudioCount;
141                         studiotabs.subtabModules[this.lastNode.id] = this.lastNode.module;
142                         yahooSlots[this.lastNode.id] = new Studio2.ListDD(this.lastNode.id, 'subTabs', false);
143                         addListStudioCount++;
144                         this.lastNode.style.opacity = 1;
145                         this.lastNode.style.filter = "alpha(opacity=100)";
146                 }
147                 this.lastNode = false;
148                 this.updateTabs();
149                 
150                 dragEl.innerHTML = "";
151         },
152
153     onDrag: Studio2.onDrag,
154     
155         onDragOver: function(e, id){
156                 var el;
157                 if (this.lastNode) {
158                         this.lastNode.parentNode.removeChild(this.lastNode);
159                         this.lastNode = false;
160                 }
161                 if (id.substr(0, 7) == 'modSlot') {
162                         return;
163                 }
164                 el = document.getElementById(id);
165                 dragEl = this.getDragEl();
166                 
167                 var mid = YAHOO.util.Dom.getY(el) + (el.clientHeight / 2);
168                 var el2 = this.getEl();
169                 var p = el.parentNode;
170                 if ((this.fromOnly || (el.id != 'trashcan' && el2.parentNode.id != p.id && el2.parentNode.id == this.parentID))) {
171                         if (typeof(studiotabs.moduleTabs[p.id.substr(2, p.id.length)][studiotabs.subtabModules[el2.id]]) != 'undefined') 
172                                 return;
173                 }
174                 
175                 if (this.fromOnly && el.id != 'trashcan') {
176                         el2 = el2.cloneNode(true);
177                         el2.module = studiotabs.subtabModules[el2.id];
178                         el2.id = 'addListStudio' + addListStudioCount;
179                         this.lastNode = el2;
180                         this.lastNode.clickContent = el2.clickContent;
181                         this.lastNode.clickBorder = el2.clickBorder;
182                         this.lastNode.clickHeight = el2.clickHeight
183                 }
184                 
185                 if (YAHOO.util.Dom.getY(dragEl) < mid) { // insert on top triggering item
186                         p.insertBefore(el2, el);
187                 }
188                 else { // insert below triggered item
189                         p.insertBefore(el2, el.nextSibling);
190                 }
191         }
192 });