]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Studio/studiodd.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / modules / Studio / studiodd.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
38 /*Portions Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
39
40 /**
41  * @class a ygDDFramed implementation like ygDDMy, but the content channels are
42  * not restricted to one column, and we drag a miniature representation of the
43  * content channel rather than a frame of the channel.
44  *
45  * @extends YAHOO.util.DDProxy
46  * @constructor
47  * @param {String} id the id of the linked element
48  * @param {String} sGroup the group of related DragDrop objects
49  */
50
51
52 function ygDDSlot(id, sGroup) {
53         
54         if (id) {
55                 this.init(id, sGroup);
56                 this.initFrame();
57         }
58
59         // Change the style of the frame to be a miniature representation of a
60         // content channel
61                 var s = this.getDragEl().style;
62         s.borderColor = "transparent";
63         s.backgroundColor = "#f6f5e5";
64         s.opacity = 0.76;
65         s.filter = "alpha(opacity=76)";
66
67         // Specify that we do not want to resize the drag frame... we want to keep
68         // the drag frame the size of our miniature content channel image
69         this.resizeFrame = true;
70         if(id == 's_field_delete'){
71             this.isValidHandle = false;
72         }
73         // Specify that we want the drag frame centered around the cursor rather 
74         // than relative to the click location so that the miniature content
75         // channel appears in the location that was clicked
76         //this.centerFrame = true;
77 }
78
79 ygDDSlot.prototype = new YAHOO.util.DDProxy();
80 ygDDSlot.prototype.handleDelete = function(cur, curb){
81      var parentID = (typeof(cur.parentID) == 'undefined')?cur.id.substr(4,cur.id.length):cur.parentID ;
82      if(parentID.indexOf('field') == 0){
83          return false;
84      }
85      var myfieldcount = field_count_MSI;
86      addNewField('dyn_field_' + field_count_MSI, 'delete', ' ', ' ', 'deleted', 0, 'studio_fields')
87      yahooSlots["dyn_field_" + myfieldcount] = new ygDDSlot("dyn_field_" + myfieldcount, "studio");
88      ygDDSlot.prototype.handleSwap(cur, curb, document.getElementById("dyn_field_" + myfieldcount), document.getElementById("dyn_field_" + myfieldcount+ 'b'), true);
89 }
90
91 ygDDSlot.prototype.undo = function(transaction){
92         ygDDSlot.prototype.handleSwap(document.getElementById(transaction['el']),document.getElementById(transaction['elb']), document.getElementById(transaction['cur']), document.getElementById(transaction['curb']), false);
93 }
94 ygDDSlot.prototype.redo = function(transaction){
95         ygDDSlot.prototype.handleSwap(document.getElementById(transaction['el']),document.getElementById(transaction['elb']), document.getElementById(transaction['cur']), document.getElementById(transaction['curb']), false);
96 }
97
98 ygDDSlot.prototype.handleSwap = function(cur, curb,el, elb, record ){
99     if(record){
100                 if(curb){
101                 jstransaction.record('studioSwap', {'cur': cur.id, 'curb': curb.id, 'el':el.id, 'elb':elb.id});
102         }else{
103                 jstransaction.record('studioSwap', {'cur': cur.id, 'curb': null, 'el':el.id, 'elb':null});
104         }
105     }
106     var parentID1 = (typeof(el.parentID) == 'undefined')?el.id.substr(4,el.id.length):el.parentID ;
107     var parentID2 = (typeof(cur.parentID) == 'undefined')?cur.id.substr(4,cur.id.length):cur.parentID ;
108     var slot1 = YAHOO.util.DDM.getElement("slot_" + parentID1);
109     var slot2 = YAHOO.util.DDM.getElement("slot_" + parentID2);
110
111     var temp = slot1.value;
112         slot1.value = slot2.value;
113         slot2.value = temp;
114         
115         YAHOO.util.DDM.swapNode(cur, el);
116         if(curb){
117                 YAHOO.util.DDM.swapNode(curb, elb);
118         }
119         //swap ids also or else form swaps don't work properly since the actual div is swapped
120         cur.parentID = parentID1;
121         el.parentID = parentID2;
122         if(parentID1.indexOf('field') == 0){
123                 if(curb)curb.style.display = 'none';
124                 setMouseOverForField(cur, true);
125         }else{
126                 if(curb)curb.style.display = 'inline';
127                 setMouseOverForField(cur, false);
128         }
129         if(parentID2.indexOf('field') == 0){
130                 if(elb)elb.style.display = 'none';
131                 setMouseOverForField(el, true);
132         }else{
133                 if(elb)elb.style.display = 'inline';
134                 setMouseOverForField(el, false);
135         }
136 }
137 ygDDSlot.prototype.onDragDrop = function(e, id) {
138    
139         var cur = this.getEl(); 
140         
141         var curb;
142     if ("string" == typeof id) {
143         curb = YAHOO.util.DDM.getElement(cur.id + "b");
144     } else {
145         curb = YAHOO.util.DDM.getBestMatch(cur.id + "b").getEl();
146     } 
147          if(id == 's_field_delete'){
148              id = ygDDSlot.prototype.handleDelete(cur, curb);
149              if(!id)return false;
150          }
151     
152     
153     var el;
154     if ("string" == typeof id) {
155         el = YAHOO.util.DDM.getElement(id);
156     } else {
157         el = YAHOO.util.DDM.getBestMatch(id).getEl();
158     }
159     
160          
161          
162   
163     id2 = el.id + "b";
164     if ("string" == typeof id) {
165         elb =YAHOO.util.DDM.getElement(id2);
166     } else {
167         elb =YAHOO.util.DDM.getBestMatch(id2).getEl();
168     } 
169     
170         ygDDSlot.prototype.handleSwap(cur, curb, el, elb, true)
171         var dragEl = this.getDragEl();
172         dragEl.innerHTML = '';
173 };
174
175 ygDDSlot.prototype.startDrag = function(x, y) {
176
177         var dragEl = this.getDragEl();
178         var clickEl = this.getEl();
179         dragEl.innerHTML = clickEl.innerHTML;
180         dragEl.className = clickEl.className;
181         dragEl.style.color = clickEl.style.color;
182         dragEl.style.border = "2px solid #aaa";
183         
184         // save the style of the object 
185         this.clickContent = clickEl.innerHTML;
186         this.clickBorder = clickEl.style.border;
187         this.clickHeight = clickEl.style.height;
188         clickElRegion = YAHOO.util.Dom.getRegion(clickEl);
189         dragEl.style.height =   clickEl.style.height;
190
191         dragEl.style.width =    (clickElRegion.right - clickElRegion.left) + 'px';
192         clickEl.style.height = (clickElRegion.bottom - clickElRegion.top) + 'px';
193         
194         //clickEl.innerHTML = ' ';
195         clickEl.style.border = '2px dashed #cccccc';
196         clickEl.style.opacity = .5;
197         clickEl.style.filter = "alpha(opacity=10)";
198
199 };
200
201 ygDDSlot.prototype.endDrag = function(e) {
202         // disable moving the linked element
203         var clickEl = this.getEl();
204         //clickEl.innerHTML = this.clickContent
205
206         if(this.clickHeight) 
207             clickEl.style.height = this.clickHeight;
208         else 
209                 clickEl.style.height = '';
210         
211         if(this.clickBorder) 
212             clickEl.style.border = this.clickBorder;
213         else 
214                 clickEl.style.border = '';
215         clickEl.style.opacity = 1;
216         clickEl.style.filter = "alpha(opacity=100)";
217                 
218 };
219 jstransaction.register('studioSwap',ygDDSlot.prototype.undo, ygDDSlot.prototype.redo);