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 /*Portions Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
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.
45 * @extends YAHOO.util.DDProxy
47 * @param {String} id the id of the linked element
48 * @param {String} sGroup the group of related DragDrop objects
52 function ygDDSlot(id, sGroup) {
55 this.init(id, sGroup);
59 // Change the style of the frame to be a miniature representation of a
61 var s = this.getDragEl().style;
62 s.borderColor = "transparent";
63 s.backgroundColor = "#f6f5e5";
65 s.filter = "alpha(opacity=76)";
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;
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;
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){
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);
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);
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);
98 ygDDSlot.prototype.handleSwap = function(cur, curb,el, elb, record ){
101 jstransaction.record('studioSwap', {'cur': cur.id, 'curb': curb.id, 'el':el.id, 'elb':elb.id});
103 jstransaction.record('studioSwap', {'cur': cur.id, 'curb': null, 'el':el.id, 'elb':null});
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);
111 var temp = slot1.value;
112 slot1.value = slot2.value;
115 YAHOO.util.DDM.swapNode(cur, el);
117 YAHOO.util.DDM.swapNode(curb, elb);
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);
126 if(curb)curb.style.display = 'inline';
127 setMouseOverForField(cur, false);
129 if(parentID2.indexOf('field') == 0){
130 if(elb)elb.style.display = 'none';
131 setMouseOverForField(el, true);
133 if(elb)elb.style.display = 'inline';
134 setMouseOverForField(el, false);
137 ygDDSlot.prototype.onDragDrop = function(e, id) {
139 var cur = this.getEl();
142 if ("string" == typeof id) {
143 curb = YAHOO.util.DDM.getElement(cur.id + "b");
145 curb = YAHOO.util.DDM.getBestMatch(cur.id + "b").getEl();
147 if(id == 's_field_delete'){
148 id = ygDDSlot.prototype.handleDelete(cur, curb);
154 if ("string" == typeof id) {
155 el = YAHOO.util.DDM.getElement(id);
157 el = YAHOO.util.DDM.getBestMatch(id).getEl();
164 if ("string" == typeof id) {
165 elb =YAHOO.util.DDM.getElement(id2);
167 elb =YAHOO.util.DDM.getBestMatch(id2).getEl();
170 ygDDSlot.prototype.handleSwap(cur, curb, el, elb, true)
171 var dragEl = this.getDragEl();
172 dragEl.innerHTML = '';
175 ygDDSlot.prototype.startDrag = function(x, y) {
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";
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;
191 dragEl.style.width = (clickElRegion.right - clickElRegion.left) + 'px';
192 clickEl.style.height = (clickElRegion.bottom - clickElRegion.top) + 'px';
194 //clickEl.innerHTML = ' ';
195 clickEl.style.border = '2px dashed #cccccc';
196 clickEl.style.opacity = .5;
197 clickEl.style.filter = "alpha(opacity=10)";
201 ygDDSlot.prototype.endDrag = function(e) {
202 // disable moving the linked element
203 var clickEl = this.getEl();
204 //clickEl.innerHTML = this.clickContent
207 clickEl.style.height = this.clickHeight;
209 clickEl.style.height = '';
212 clickEl.style.border = this.clickBorder;
214 clickEl.style.border = '';
215 clickEl.style.opacity = 1;
216 clickEl.style.filter = "alpha(opacity=100)";
219 jstransaction.register('studioSwap',ygDDSlot.prototype.undo, ygDDSlot.prototype.redo);