/********************************************************************************* * SugarCRM Community Edition is a customer relationship management program developed by * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License version 3 as published by the * Free Software Foundation with the addition of the following permission added * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License along with * this program; if not, see http://www.gnu.org/licenses or write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. * * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************/ if(typeof('console') == 'undefined'){ console = { log: function(message) { } } } var _debug_ = false; var _write_ = function( message ){ if(_debug_){ console.log(message);} } Studio2 = { init: function() { var Dom = YAHOO.util.Dom, DDTarget = YAHOO.util.DDTarget, DDM = YAHOO.utilDragDropMgr; Studio2.maxColumns = parseInt(document.getElementById('maxColumns').value); Studio2.setStartId(parseInt(document.getElementById('idCount').value)); Studio2.setStartId(1000); Studio2.fieldwidth = parseInt(document.getElementById('fieldwidth').value); Studio2.panelNumber = parseInt(document.getElementById('nextPanelId').value); Studio2.isIE = SUGAR.isIE; Studio2.expandableFields = []; Studio2.scrollZones = {}; // Activate the layout panels var panels = document.getElementById('panels'); Dom.setStyle(panels, "visibility", "hidden"); //new Studio2.PanelDD(panels.id,'studio2.panels'); // add the main layout area into PANELS to allow for panel drags to empty areas new DDTarget(panels.id, 'studio2.panels'); for (var i=0;i 1) { this.reduceFieldWidth( field ); } _write_("Unregistered:"+field.id); field.removeChild( field.childNodes[1] ); field.removeAttribute("expandable"); field.removeAttribute("state"); } }, isExpandable:function( field ){ return field.getAttribute("expandable")!=null && !this.isSpecial(field);//&& field.getAttribute("expandable") == "true"; }, swapStates:function( src, dest ){ var old_src= {state:src.getAttribute("state"), img: src.childNodes[1].src}; src.setAttribute("state", dest.getAttribute("state")); src.childNodes[1].src = dest.childNodes[1].src; dest.childNodes[1].src = old_src.img; dest.setAttribute("state", old_src.state); }, getImageElement:function(default_toggle){ var img = document.createElement('img'); if(!default_toggle) img.src = 'index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=minus_inline.gif'; else img.src = 'index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=plus_inline.gif'; img.className = 'le_edit'; img.style.paddingRight = 2; img.style.cssFloat = 'left'; img.name = 'expandable_field_icon'; return img; }, toggleFieldWidth:function(id){ var field = YAHOO.util.Dom.get(id); if ( typeof(field) == 'undefined' || field === null ) return; var img = field.childNodes[1]; if( field.getAttribute("state") && field.getAttribute("state")=='reduced' ){ field.parentNode.removeChild( Studio2.nextField(field) || Studio2.prevField(field) ); Studio2.setColumnWidth(id,2); img.src = 'index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=minus_inline.gif'; this.setExpanded( field ); }else if( field.getAttribute("state") && field.getAttribute("state")=='expanded' ){ Studio2.setColumnWidth(id,1); var newField = Studio2.newField(); Studio2.setSpecial(newField); Studio2.activateElement(newField); field.parentNode.appendChild(newField); this.setReduced( field ); img.src='index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=plus_inline.gif'; } }, setExpanded: function( field ){ field.setAttribute("expandable","true"); field.setAttribute("state","expanded"); _write_("Expanded: "+field.id); }, setReduced: function( field ){ field.setAttribute("expandable","true"); field.setAttribute("state","reduced"); _write_("Recued: "+field.id); }, isExpanded: function (field ){ return field.getAttribute('state') == 'expanded'; }, isReduced:function (field ){ return field.getAttribute('state') == 'reduced'; }, registerExpandableField: function( field ) {//field = HTML element if( Studio2.maxColumns < 2 || field == null || typeof(field) == 'undefined' || this.isSpecial (field) ) { return; } if( !this.isExpandable( field ) ) { var next = this.nextField ( field ) ; var prev = this.prevField ( field ) ; var removeMe = next || prev ; if( this.isSpecial( next) || this.isSpecial( prev ) || this.isEmpty( next ) || this.isEmpty( prev ) || removeMe == null ){ //Always Expanded _write_("remove me is :"+removeMe); if (removeMe != null) { field.parentNode.removeChild(removeMe); } var img = this.getImageElement ( false ); img.onclick = function () { Studio2.toggleFieldWidth ( field.id ) }; field.insertBefore ( img, field.childNodes[1] ); this.setColumnWidth( field.id, 2 ); this.setExpanded( field ); _write_("registered field"); } }else{ _write_("Could not Register field:"+field.id); } }, setStartId: function(id) { Studio2.idStack = [id]; }, nextId: function() { if (Studio2.idStack.length == 1) { // if down to our last id, allocate another Studio2.idStack[0]++; Studio2.idStack.push(Studio2.idStack[0]); } return Studio2.idStack.pop(); }, setNextId: function(id) { Studio2.idStack.push(id); }, isSpecial: function(element) { if(element==null || typeof(element) == 'undefined'){return false;}; return YAHOO.util.Dom.hasClass(element,'special'); }, setSpecial: function(el) { YAHOO.util.Dom.addClass(el, 'special'); }, unsetSpecial: function(el) { YAHOO.util.Dom.removeClass(el, 'special'); }, isEmpty: function( element ){ if (element == null || typeof(element) == 'undefined') {return false;}; return YAHOO.util.Dom.hasClass(element, 'le_field special'); }, count: function(element) { var count = 0; for (var j=0;j' + // the displayed label '(filler)'; // the hidden field that identifies this as something to be saved by prepareForSave() return newField; }, newRow: function(titleRequired) { var newRow = document.createElement('div'); if (titleRequired) { var child = document.createElement('span'); child.className = 'panel_name'; child.appendChild(document.createTextNode(SUGAR.language.get('ModuleBuilder', 'LBL_NEW_ROW') ) ); newRow.appendChild(child); } newRow.className='le_row'; newRow.id = Studio2.nextId(); for(var i=0;i1) { Studio2.removeElement(panel); Studio2.tidyPanels(); } else { // add a blank row back in var newRow = Studio2.newRow(false); panel.appendChild(newRow); Studio2.activateElement(newRow); // debugger; } } }, tidyFields: function(row) { if (Studio2.count(row) <= 0) { // no fields left var panel = row.parentNode; Studio2.removeElement(row); Studio2.tidyRows(panel); } }, removeElement: function(element) { Studio2.reclaimIds(element); Studio2.reclaimFields(element); if (element.className.indexOf('le_field') == -1) { // all fields have been moved to availablefields in Studio2.reclaimFields element.parentNode.removeChild(element); } }, swapElements: function(el1,el2) { // TODO: record this swap in TRANSACTION var el1Width = Studio2.getFieldWidth(el1); var el2Width = Studio2.getFieldWidth(el2); YAHOO.util.DragDropMgr.swapNode(el1, el2); Studio2.setFieldWidth(el1,el2Width); Studio2.setFieldWidth(el2,el1Width); }, activateElement: function(element) { if (!document.getElementById(element.id)) { document.body.appendChild(element); } if (element.className.indexOf('le_panel') != -1) { new Studio2.PanelDD(element.id,'studio2.panels'); new YAHOO.util.DDTarget(element.id,'studio2.rows'); // add so a background for row moves } if (element.className.indexOf('le_row') != -1) { new Studio2.RowDD(element.id,'studio2.rows'); } if (element.className.indexOf('le_field') != -1) { new Studio2.FieldDD(element,'studio2.fields'); } for (var i=0;i 0) { var attrs = element.attributes; for(var i=0;i