1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 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 var yahooSlots = new Array();
39 function addNewRowToView(id){
40 var curRow = document.getElementById(id);
41 var parent = curRow.parentNode;
42 var newRow = document.createElement('tr');
43 var newRow = parent.insertRow(parent.rows.length);
44 var re = /studiorow[0-9]+/g;
45 var cell = newRow.insertCell(0);
47 cell.innerHTML = curRow.cells[0].innerHTML.replace(re, 'studiorow' + slotCount);
48 cell.className = curRow.cells[0].className;
49 for(var j = 1; j < curRow.cells.length ; j++){
50 var cell = newRow.insertCell(j);
51 cell.innerHTML = ' ';
52 cell.className = curRow.cells[j].className;
54 var index = parent.rows.length;
55 for(var i = 0; i < parent.rows.length ; i++){
56 if(parent.rows[i].id == id){
60 newRow.id = 'studiorow' + slotCount;
61 if(typeof(curRow.parentId) == 'undefined'){
64 newRow.parentId = curRow.parentId;
66 if(index < parent.rows.length){
67 parent.insertBefore(newRow, parent.rows[index]);
69 parent.appendChild(newRow);
71 document.getElementById('add_' + newRow.parentId).value = 1 + parseInt(document.getElementById('add_' + newRow.parentId).value);
75 function deleteRowFromView(id, index){
76 var curRow = document.getElementById(id);
77 curRow.parentNode.removeChild(curRow);
78 if(typeof(curRow.parentId) == 'undefined'){
79 document.getElementById('form_' + id).value=-1;
81 document.getElementById('add_' + curRow.parentId).value = parseInt(document.getElementById('add_' + curRow.parentId).value) - 1;
85 function addNewColToView(id, index){
87 var curCol = document.getElementById(id);
88 var index = curCol.cellIndex;
89 var parent = curCol.parentNode;
90 var cell = parent.insertCell(index + 1);
91 if(parent.parentNode.rows[parent.rowIndex + 1])parent.parentNode.rows[parent.rowIndex + 1].insertCell(index + 1)
92 var re = /studiocol[0-9]+/g;
93 cell.innerHTML = '[NEW]';
94 cell.className = curCol.className;
95 if(typeof(curCol.parentId) == 'undefined'){
98 cell.parentId = curCol.parentId;
101 document.getElementById('add_' + cell.parentId).value = 1 + parseInt(document.getElementById('add_' + cell.parentId).value);
105 function deleteColFromView(id, index){
106 var curCol = document.getElementById(id);
107 var row = curCol.parentNode;
108 var index = curCol.cellIndex;
109 if(typeof(row.cells[index + 1].parentId) == 'undefined'){
110 row.deleteCell(index);
111 row.deleteCell(index - 1);
112 if(row.parentNode.rows[row.rowIndex + 1]){
113 row.parentNode.rows[row.rowIndex + 1].deleteCell(index );
114 row.parentNode.rows[row.rowIndex + 1].deleteCell(index - 1);
119 row.deleteCell(index + 1);
120 if(row.parentNode.rows[row.rowIndex + 1])row.parentNode.rows[row.rowIndex + 1].deleteCell(index +1);
123 document.getElementById('add_' + curCol.id).value = parseInt(document.getElementById('add_' + curCol.id).value) - 1;
130 var field_count_MSI = 0;
131 var studioLoaded = false;
132 var dyn_field_count = 0;
133 function addNewFieldType(type){
134 var select = document.getElementById('studio_display_type').options;
135 for(var i = 0; i < select.length; i++){
136 if(select[i].value == type){
140 select[i] = new Option(type, type);
143 function filterStudioFields(type){
144 var table = document.getElementById('studio_fields');
145 for(var i = 0; i < table.rows.length; i++){
146 children = table.rows[i].cells[0].childNodes;
147 for(var j = 0; j < children.length; j++){
149 if(child.nodeName == 'DIV' && typeof(child.fieldType) != 'undefined'){
151 table.rows[i].style.display = '';
152 }else if(type == 'custom'){
154 table.rows[i].style.display = ''
156 table.rows[i].style.display = 'none';
159 if(child.fieldType == type){
160 table.rows[i].style.display = ''
162 table.rows[i].style.display = 'none';
173 function addNewField(id, name, label, html, fieldType,isCustom, table_id, top){
175 html = replaceAll(html, "&qt;", '"');
176 html = replaceAll(html, "&sqt;", "'");
177 var table = document.getElementById(table_id);
180 row = table.insertRow(1);
182 row = table.insertRow(table.rows.length);
185 var cell = row.insertCell(0);
186 var div = document.createElement('div');
187 div.className = 'slot';
188 div.setAttribute('id', id);
189 div.fieldType = fieldType;
190 addNewFieldType(fieldType);
191 div.isCustom = isCustom;
192 div.style.width='100%';
193 var textEl = document.createElement('input');
194 textEl.setAttribute('type', 'hidden')
195 textEl.setAttribute('name', 'slot_field_' + field_count_MSI );
196 textEl.setAttribute('id', 'slot_field_' + field_count_MSI );
197 textEl.setAttribute('value', 'add:' + name );
198 field_list_MSI['form_' + name] = textEl;
199 document.studio.appendChild(textEl);
200 div.innerHTML = label;
201 var cell2 = row.insertCell(1);
202 var div2 = document.createElement('div');
203 setMouseOverForField(div, true);
204 div2.style.display = 'none';
205 div2.setAttribute('id', id + 'b' );
206 html = html.replace(/(<input)([^>]*)/g, '$1 disabled readonly $2');
207 html = html.replace(/(<select)([^>]*)/g, '$1 disabled readonly $2');
208 html = html.replace(/(onclick=')([^']*)/g, '$1'); // to strip {} from after a JS onclick call
209 div2.innerHTML += html;
210 cell.appendChild(div);
211 cell2.appendChild(div2);
214 yahooSlots[id] = new ygDDSlot(id, "studio");
223 function removeFieldFromTable(field, table)
225 var table = document.getElementById(table);
226 var rows = table.rows;
227 for(i = 0 ; i < rows.length; i++){
228 cells = rows[i].cells;
229 for(j = 0; j < cells.length; j++){
230 cell = rows[i].cells[j];
231 children = cell.childNodes;
232 for(k = 0; k < children.length; k++){
234 if(child.nodeType == 1){
236 if(child.getAttribute('id') == 'slot_' + field){
245 function setMouseOverForField(field, on){
248 field.onmouseover = function(){
249 return overlib(document.getElementById(this.id + 'b').innerHTML, FGCLASS, 'olFgClass',
250 CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass');
253 field.onmouseout = function(){
257 field.onmouseover = function(){};
258 field.onmouseout = function(){};
261 var lastIDClick = '';
262 var lastIDClickTime = 0;
264 function wasDoubleClick(id) {
266 var now = d.getTime();
268 if (lastIDClick == id && (now - lastIDClickTime) < dblDelay) {
273 lastIDClickTime = now;
277 function confirmNoSave(){
278 return confirm(SUGAR.language.get('Studio', 'LBL_CONFIRM_UNSAVE'));
280 var labelEdit = false;
281 SUGAR.Studio = function(){
282 this.labelEdit = false;
283 this.lastLabel = false;
285 SUGAR.Studio.prototype.endLabelEdit = function(id){
286 if(id == 'undefined')return;
287 document.getElementById('span' + id).style.display = 'none';
288 jstransaction.record('studioLabelEdit', {'id':id, 'new': document.getElementById(id).value , 'old':document.getElementById('label' + id).innerHTML});
289 document.getElementById('label' + id).innerHTML = document.getElementById(id).value;
290 document.getElementById('label_' + id).value = document.getElementById(id).value;
291 document.getElementById('label' + id).style.display = '';
292 this.labelEdit = false;
293 YAHOO.util.DragDropMgr.unlock();
296 SUGAR.Studio.prototype.undoLabelEdit = function (transaction){
297 var id = transaction['id'];
298 document.getElementById('span' + id).style.display = 'none';
299 document.getElementById('label' + id).innerHTML = transaction['old'];
300 document.getElementById('label_' + id).value = transaction['old'];
302 SUGAR.Studio.prototype.redoLabelEdit= function (transaction){
303 var id = transaction['id'];
304 document.getElementById('span' + id).style.display = 'none';
305 document.getElementById('label' + id).innerHTML = transaction['new'];
306 document.getElementById('label_' + id).value = transaction['new'];
309 SUGAR.Studio.prototype.handleLabelClick = function(id, count){
310 if(this.lastLabel != ''){
311 //endLabelEdit(lastLabel);
313 if(wasDoubleClick(id) || count == 1){
314 document.getElementById('span' + id).style.display = '';
315 document.getElementById(id).focus();
316 document.getElementById(id).select();
317 document.getElementById('label' + id).style.display = 'none';
319 YAHOO.util.DragDropMgr.lock();
325 jstransaction.register('studioLabelEdit', SUGAR.Studio.prototype.undoLabelEdit, SUGAR.Studio.prototype.redoLabelEdit);
328 SUGAR.Studio.prototype.save = function(formName, publish){
329 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
330 var formObject = document.forms[formName];
331 YAHOO.util.Connect.setForm(formObject);
332 var cObj = YAHOO.util.Connect.asyncRequest('POST','index.php',
333 {success: SUGAR.Studio.prototype.saved, failure: SUGAR.Studio.prototype.saved,timeout:5000, argument: publish});
335 SUGAR.Studio.prototype.saved= function(o){
337 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED'));
338 window.setTimeout('ajaxStatus.hideStatus();', 2000);
344 document.location.reload();
347 ajaxStatus.showStatus(SUGAR.language.get('Studio', 'LBL_FAILED_TO_SAVE'));
348 window.setTimeout('ajaxStatus.hideStatus();', 2000);
352 SUGAR.Studio.prototype.publish = function(){
353 ajaxStatus.showStatus(SUGAR.language.get('Studio', 'LBL_PUBLISHING'));
354 var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module=Studio&action=Publish',
355 {success: SUGAR.Studio.prototype.published, failure: SUGAR.Studio.prototype.published}, null);
358 SUGAR.Studio.prototype.published= function(o){
360 ajaxStatus.showStatus(SUGAR.language.get('Studio', 'LBL_PUBLISHED'));
361 window.setTimeout('ajaxStatus.hideStatus();', 2000);
362 document.location.reload();
364 ajaxStatus.showStatus(SUGAR.language.get('Studio', 'LBL_FAILED_PUBLISHED'));
365 window.setTimeout('ajaxStatus.hideStatus();', 2000);
369 var studiopopup = function() {
371 // covers the page w/ white overlay
372 display: function() {
373 if(studiojs.popupVisible)return false;
374 studiojs.popupVisible = true;
375 var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module=Studio&action=wizard&wizard=EditCustomFieldsWizard&option=CreateCustomFields&popup=true',
376 {success: studiopopup.render, failure: studiopopup.render}, null);
383 studiojs.popup.hide();
385 evalScript:function(text){
386 SUGAR.util.evalScript(text);
389 render: function(obj){
392 studiojs.popup = new YAHOO.widget.Dialog("dlg", { effect:{effect:YAHOO.widget.ContainerEffect.SLIDE,duration:.5}, fixedcenter: false, constraintoviewport: false, underlay:"shadow",modal:true, close:true, visible:false, draggable:true, monitorresize:true} );
394 studiojs.popup.setBody(obj.responseText);
395 studiojs.popupAvailable = true;
396 studiojs.popup.render(document.body);
397 studiojs.popup.center();
398 studiojs.popup.beforeHideEvent.fire = function(e){
399 studiojs.popupVisible = false;
401 studiopopup.evalScript(obj.responseText);
411 var studiojs = new SUGAR.Studio();
412 studiojs.popupAvailable = false;
413 studiojs.popupVisible = false;
419 var popupSave = function(o){
420 var errorIndex = o.responseText.indexOf('[ERROR]');
423 var error = o.responseText.substr(errorIndex + 7, o.responseText.length);
424 ajaxStatus.showStatus(error);
425 window.setTimeout('ajaxStatus.hideStatus();', 2000);
428 var typeIndex = o.responseText.indexOf('[TYPE]') ;
429 var labelIndex = o.responseText.indexOf('[LABEL]') ;
430 var dataIndex = o.responseText.indexOf('[DATA]');
431 var errorIndex = o.responseText.indexOf('[ERROR]');
432 var name = o.responseText.substr(6, typeIndex - 6);
433 var type = o.responseText.substr(typeIndex + 6,labelIndex - (typeIndex + 6));
434 var label = o.responseText.substr(labelIndex + 7,dataIndex - (labelIndex + 7));
435 var data = o.responseText.substr(dataIndex + 6, o.responseText.length);
437 addNewField('dyn_field_' + field_count_MSI, name, label, data, type, 1, 'studio_fields', true)
441 function submitCustomFieldForm(isPopup){
443 if(typeof(document.popup_form.presave) != 'undefined'){
444 document.popup_form.presave();
447 if(!check_form('popup_form'))return;
457 YAHOO.util.Connect.setForm('popup_form');
458 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback);
459 studiopopup.destroy();
462 document.popup_form.submit();
466 function deleteCustomFieldForm(isPopup){
470 if(confirm("WARNING\nDeleting a custom field will delete all data related to that custom field. \nYou will still need to remove the field from any layouts you have added it to.")){
471 document.popup_form.option.value = 'DeleteCustomField';
472 document.popup_form.submit();
476 function dropdownChanged(value){
477 if(typeof(app_list_strings[value]) == 'undefined')return;
478 var select = document.getElementById('default_value').options;
482 for(var key in app_list_strings[value]){
483 select[count] = new Option(app_list_strings[value][key], key);
488 function customFieldChanged(){
491 var populateCustomField = function(response){
492 var div = document.getElementById('customfieldbody');
493 if(response.status = 0){
494 div.innerHTML = 'Server Connection Failed';
496 validate['popup_form'] = new Array();
497 inputsWithErrors = new Array();
498 div.innerHTML = response.responseText;
499 studiopopup.evalScript(response.responseText);
500 if(studiojs.popupAvailable){
502 var region = YAHOO.util.Dom.getRegion('custom_field_table') ;
503 studiojs.popup.cfg.setProperty('width', region.right - region.left + 30 + 'px');
504 studiojs.popup.cfg.setProperty('height', region.bottom - region.top + 30 + 'px');
506 studiojs.popup.render(document.body);
507 studiojs.popup.center();
508 studiojs.popup.show();
513 var populateCustomFieldCallback = {
514 success: populateCustomField ,
515 failure: populateCustomField,
519 function changeTypeData(type){
520 document.getElementById('customfieldbody').innerHTML = '<h2>Loading...</h2>';
521 COBJ = YAHOO.util.Connect.asyncRequest('GET','index.php?module=Studio&popup=true&action=index&&ajax=editcustomfield&to_pdf=true&type=' + type,populateCustomFieldCallback,null);
525 function typeChanged(obj)
527 changeTypeData(obj.options[obj.selectedIndex].value);
531 function handle_duplicate(){
532 document.popup_form.action.value = 'EditView';
533 document.popup_form.duplicate.value = 'true';
534 document.popup_form.submit();
537 function forceRange(field, min, max){
538 field.value = parseInt(field.value);
539 if(field.value == 'NaN')field.value = max;
540 if(field.value > max) field.value = max;
541 if(field.value < min) field.value = min;
543 function changeMaxLength(field, length){
544 field.maxLength = parseInt(length);
545 field.value = field.value.substr(0, field.maxLength);