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