]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/sugarwidgets/SugarYUIWidgets.js
Release 6.5.0
[Github/sugarcrm.git] / include / javascript / sugarwidgets / SugarYUIWidgets.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 YAHOO.namespace("SUGAR");(function(){var sw=YAHOO.SUGAR,Event=YAHOO.util.Event,Connect=YAHOO.util.Connect,Dom=YAHOO.util.Dom;sw.MessageBox={progressTemplate:"{body}<br><div class='sugar-progress-wrap'><div class='sugar-progress-bar'/></div>",promptTemplate:"{body}:<input id='sugar-message-prompt' class='sugar-message-prompt' name='sugar-message-prompt'></input>",show:function(config){var myConf=sw.MessageBox.config={type:'message',modal:true,width:240,id:'sugarMsgWindow',close:true,title:"Alert",msg:" ",buttons:[]};if(config['type']&&config['type']=="prompt"){myConf['buttons']=[{text:SUGAR.language.get("app_strings","LBL_EMAIL_CANCEL"),handler:YAHOO.SUGAR.MessageBox.hide},{text:SUGAR.language.get("app_strings","LBL_EMAIL_OK"),handler:config['fn']?function(){var returnValue=config['fn'](YAHOO.util.Dom.get("sugar-message-prompt").value);if(typeof(returnValue)=="undefined"||returnValue){YAHOO.SUGAR.MessageBox.hide();}}:YAHOO.SUGAR.MessageBox.hide,isDefault:true}];}else if((config['type']&&config['type']=="alert")){myConf['buttons']=[{text:SUGAR.language.get("app_strings","LBL_EMAIL_OK"),handler:config['fn']?function(){YAHOO.SUGAR.MessageBox.hide();config['fn']();}:YAHOO.SUGAR.MessageBox.hide,isDefault:true}]}else if((config['type']&&config['type']=="confirm")){myConf['buttons']=[{text:SUGAR.language.get("app_strings","LBL_EMAIL_YES"),handler:config['fn']?function(){config['fn']('yes');YAHOO.SUGAR.MessageBox.hide();}:YAHOO.SUGAR.MessageBox.hide,isDefault:true},{text:SUGAR.language.get("app_strings","LBL_EMAIL_NO"),handler:config['fn']?function(){config['fn']('no');YAHOO.SUGAR.MessageBox.hide();}:YAHOO.SUGAR.MessageBox.hide}];}
36 else if((config['type']&&config['type']=="plain")){myConf['buttons']=[];}
37 for(var i in config){myConf[i]=config[i];}
38 if(sw.MessageBox.panel){sw.MessageBox.panel.destroy();}
39 sw.MessageBox.panel=new YAHOO.widget.SimpleDialog(myConf.id,{width:myConf.width+'px',close:myConf.close,modal:myConf.modal,visible:false,fixedcenter:true,constraintoviewport:true,draggable:true,buttons:myConf.buttons});if(myConf.type=="progress"){sw.MessageBox.panel.setBody(sw.MessageBox.progressTemplate.replace(/\{body\}/gi,myConf.msg));}else if(myConf.type=="prompt"){sw.MessageBox.panel.setBody(sw.MessageBox.promptTemplate.replace(/\{body\}/gi,myConf.msg));}else if(myConf.type=="confirm"){sw.MessageBox.panel.setBody(myConf.msg);}else{sw.MessageBox.panel.setBody(myConf.msg);}
40 sw.MessageBox.panel.setHeader(myConf.title);if(myConf.beforeShow){sw.MessageBox.panel.beforeShowEvent.subscribe(function(){myConf.beforeShow();});}
41 if(myConf.beforeHide){sw.MessageBox.panel.beforeHideEvent.subscribe(function(){myConf.beforeHide();});}
42 sw.MessageBox.panel.render(document.body);sw.MessageBox.panel.show();},updateProgress:function(percent,message){if(!sw.MessageBox.config.type=="progress")return;if(typeof message=="string"){sw.MessageBox.panel.setBody(sw.MessageBox.progressTemplate.replace(/\{body\}/gi,message));}
43 var barEl=Dom.getElementsByClassName("sugar-progress-bar",null,YAHOO.SUGAR.MessageBox.panel.element)[0];if(percent>100)
44 percent=100;else if(percent<0)
45 percent=0;barEl.style.width=percent+"%";},hide:function(){if(sw.MessageBox.panel)
46 sw.MessageBox.panel.hide();}};sw.Template=function(content){this._setContent(content);};sw.Template.prototype={regex:/\{([\w\.]*)\}/gim,append:function(target,args){var tEl=Dom.get(target);if(tEl)tEl.innerHTML+=this.exec(args);else if(typeof(console)!="undefined"&&typeof(console.log)=="function")
47 console.log("Warning, unable to find target:"+target);},exec:function(args){var out=this.content;for(var i in this.vars){var val=this._getValue(i,args);var reg=new RegExp("\\{"+i+"\\}","g");out=out.replace(reg,val);}
48 return out;},_setContent:function(content){this.content=content;var lastIndex=-1;var result=this.regex.exec(content);this.vars={};while(result&&result.index>lastIndex){lastIndex=result.index;this.vars[result[1]]=true;result=this.regex.exec(content);}},_getValue:function(v,scope){return function(e){return eval("this."+e);}.call(scope,v);}};sw.SelectionGrid=function(containerEl,columns,dataSource,config){sw.SelectionGrid.superclass.constructor.call(this,containerEl,columns,dataSource,config);this.subscribe("rowMouseoverEvent",this.onEventHighlightRow);this.subscribe("rowMouseoutEvent",this.onEventUnhighlightRow);if(config.forceMulti){this.subscribe("rowClickEvent",function(o){o.event.preventDefault();this.clearTextSelection();o.event=SUGAR.util.clone(o.event);o.event.ctrlKey=o.event.metaKey=true;this.onEventSelectRow(o);});}else{this.subscribe("rowClickEvent",this.onEventSelectRow);}
49 this.selectRow(this.getTrEl(0));this.focus();}
50 YAHOO.extend(sw.SelectionGrid,YAHOO.widget.ScrollingDataTable,{getColumn:function(column){var oColumn=this._oColumnSet.getColumn(column);if(!oColumn){var elCell=this.getTdEl(column);if(elCell&&(!column.tagName||column.tagName.toUpperCase()!="TH")){oColumn=this._oColumnSet.getColumn(elCell.cellIndex);}
51 else{elCell=this.getThEl(column);if(elCell){var allColumns=this._oColumnSet.flat;for(var i=0,len=allColumns.length;i<len;i++){if(allColumns[i].getThEl().id===elCell.id){oColumn=allColumns[i];}}}}}
52 if(!oColumn){YAHOO.log("Could not get Column for column at "+column,"info",this.toString());}
53 return oColumn;}});sw.DragDropTable=function(containerEl,columns,dataSource,config){var DDT=sw.DragDropTable;DDT.superclass.constructor.call(this,containerEl,columns,dataSource,config);this.DDGroup=config.group?config.group:"defGroup";if(typeof DDT.groups[this.DDGroup]=="undefined")
54 DDT.groups[this.DDGroup]=[];DDT.groups[this.DDGroup][DDT.groups[this.DDGroup].length]=this;this.tabledd=new YAHOO.util.DDTarget(containerEl);}
55 sw.DragDropTable.groups={defGroup:[]}
56 YAHOO.extend(sw.DragDropTable,YAHOO.widget.ScrollingDataTable,{_addTrEl:function(oRecord){var elTr=sw.DragDropTable.superclass._addTrEl.call(this,oRecord);if(!this.disableEmptyRows||(oRecord.getData()[this.getColumnSet().keys[0].key]!=false&&oRecord.getData()[this.getColumnSet().keys[0].key]!="")){var _rowDD=new sw.RowDD(this,oRecord,elTr);}
57 return elTr;},getGroup:function(){return sw.DragDropTable.groups[this.DDGroup];}});sw.RowDD=function(oDataTable,oRecord,elTr){if(oDataTable&&oRecord&&elTr){this.ddtable=oDataTable;this.table=oDataTable.getTableEl();this.row=oRecord;this.rowEl=elTr;this.newIndex=null;this.init(elTr);this.initFrame();this.invalidHandleTypes={};}};YAHOO.extend(sw.RowDD,YAHOO.util.DDProxy,{_removeIdRegex:new RegExp("(<.[^\\/<]*)id\\s*=\\s*['|\"]?\w*['|\"]?([^>]*>)","gim"),_resizeProxy:function(){this.constructor.superclass._resizeProxy.apply(this,arguments);var dragEl=this.getDragEl(),el=this.getEl();Dom.setStyle(this.pointer,'height',(this.rowEl.offsetHeight+5)+'px');Dom.setStyle(this.pointer,'display','block');var xy=Dom.getXY(el);Dom.setXY(this.pointer,[xy[0],(xy[1]-5)]);Dom.setStyle(dragEl,'height',this.rowEl.offsetHeight+"px");Dom.setStyle(dragEl,'width',(parseInt(Dom.getStyle(dragEl,'width'),10)+4)+'px');Dom.setXY(this.dragEl,xy);},startDrag:function(x,y){var dragEl=this.getDragEl();var clickEl=this.getEl();Dom.setStyle(clickEl,"opacity","0.25");var tableWrap=false;if(clickEl.tagName.toUpperCase()=="TR")
58 tableWrap=true;dragEl.innerHTML="<table>"+clickEl.innerHTML.replace(this._removeIdRegex,"$1$2")+"</table>";Dom.addClass(dragEl,"yui-dt-liner");Dom.setStyle(dragEl,"height",(clickEl.clientHeight-2)+"px");Dom.setStyle(dragEl,"backgroundColor",Dom.getStyle(clickEl,"backgroundColor"));Dom.setStyle(dragEl,"border","2px solid gray");Dom.setStyle(dragEl,"display","");this.newTable=this.ddtable;},clickValidator:function(e){if(this.row.getData()[0]==" ")
59 return false;var target=Event.getTarget(e);return(this.isValidHandleChild(target)&&(this.id==this.handleElId||this.DDM.handleWasClicked(target,this.id)));},onDragOver:function(ev,id){var groupTables=this.ddtable.getGroup();for(i in groupTables){var targetTable=groupTables[i];if(!targetTable.getContainerEl)
60 continue;if(targetTable.getContainerEl().id==id){if(targetTable!=this.newTable){this.newIndex=targetTable.getRecordSet().getLength()-1;var destEl=Dom.get(targetTable.getLastTrEl());destEl.parentNode.insertBefore(this.getEl(),destEl);}
61 this.newTable=targetTable
62 return true;}}
63 if(this.newTable&&this.newTable.getRecord(id)){var targetRow=this.newTable.getRecord(id);var destEl=Dom.get(id);destEl.parentNode.insertBefore(this.getEl(),destEl);this.newIndex=this.newTable.getRecordIndex(targetRow);}},endDrag:function(){if(this.newTable!=null&&this.newIndex!=null){this.getEl().style.display="none";this.table.appendChild(this.getEl());this.newTable.addRow(this.row.getData(),this.newIndex);try{this.ddtable.deleteRow(this.row);}catch(e){if(typeof(console)!="undefined"&&console.log)
64 {console.log(e);}}
65 this.ddtable.render();}
66 this.newTable=this.newIndex=null
67 var clickEl=this.getEl();Dom.setStyle(clickEl,"opacity","");}});sw.AsyncPanel=function(el,params){if(params)
68 sw.AsyncPanel.superclass.constructor.call(this,el,params);else
69 sw.AsyncPanel.superclass.constructor.call(this,el);}
70 YAHOO.extend(sw.AsyncPanel,YAHOO.widget.Panel,{loadingText:"Loading...",failureText:"Error loading content.",load:function(url,method,callback,postdata){method=method?method:"GET";this.setBody(this.loadingText);if(Connect.url)url=Connect.url+"&"+url;this.callback=callback;Connect.asyncRequest(method,url,{success:this._updateContent,failure:this._loadFailed,scope:this},postdata);},_updateContent:function(o){var w=this.cfg.config.width.value+"px";this.setBody(o.responseText);if(!SUGAR.isIE)
71 this.body.style.width=w
72 if(this.callback!=null)
73 this.callback(o);},_loadFailed:function(o){this.setBody(this.failureText);}});sw.ClosableTab=function(el,parent,conf){this.closeEvent=new YAHOO.util.CustomEvent("close",this);if(conf)
74 sw.ClosableTab.superclass.constructor.call(this,el,conf);else
75 sw.ClosableTab.superclass.constructor.call(this,el);this.setAttributeConfig("TabView",{value:parent});this.get("labelEl").parentNode.href="javascript:void(0);";}
76 YAHOO.extend(sw.ClosableTab,YAHOO.widget.Tab,{close:function(){this.closeEvent.fire();var parent=this.get("TabView");parent.removeTab(this);},initAttributes:function(attr){sw.ClosableTab.superclass.initAttributes.call(this,attr);this.setAttributeConfig("closeMsg",{value:attr.closeMsg||""});this.setAttributeConfig("label",{value:attr.label||this._getLabel(),method:function(value){var labelEl=this.get("labelEl");if(!labelEl){this.set(LABEL_EL,this._createLabelEl());}
77 labelEl.innerHTML=value;var closeButton=document.createElement('a');closeButton.href="javascript:void(0);";Dom.addClass(closeButton,"sugar-tab-close");Event.addListener(closeButton,"click",function(e,tab){if(tab.get("closeMsg")!="")
78 {if(confirm(tab.get("closeMsg"))){tab.close();}}
79 else{tab.close();}},this);labelEl.appendChild(closeButton);}});}});sw.Tree=function(parentEl,baseRequestParams,rootParams){this.baseRequestParams=baseRequestParams;sw.Tree.superclass.constructor.call(this,parentEl);if(rootParams){if(typeof rootParams=="string")
80 this.sendTreeNodeDataRequest(this.getRoot(),rootParams);else
81 this.sendTreeNodeDataRequest(this.getRoot(),"");}}
82 YAHOO.extend(sw.Tree,YAHOO.widget.TreeView,{sendTreeNodeDataRequest:function(parentNode,params){YAHOO.util.Connect.asyncRequest('POST','index.php',{success:this.handleTreeNodeDataRequest,argument:{parentNode:parentNode},scope:this},this.baseRequestParams+params);},handleTreeNodeDataRequest:function(o){var parentNode=o.argument.parentNode;var resp=YAHOO.lang.JSON.parse(o.responseText);if(resp.tree_data.nodes){for(var i=0;i<resp.tree_data.nodes.length;i++){var newChild=this.buildTreeNodeRecursive(resp.tree_data.nodes[i],parentNode);}}
83 parentNode.tree.draw();},buildTreeNodeRecursive:function(nodeData,parentNode){nodeData.label=nodeData.text;var node=new YAHOO.widget.TextNode(nodeData,parentNode,nodeData.expanded);if(typeof(nodeData.children)=='object'){for(var i=0;i<nodeData.children.length;i++){this.buildTreeNodeRecursive(nodeData.children[i],node);}}
84 return node;}});YAHOO.widget.TVSlideIn=function(el,callback){this.el=el;this.callback=callback;this.logger=new YAHOO.widget.LogWriter(this.toString());};YAHOO.widget.TVSlideIn.prototype={animate:function(){var tvanim=this;var s=this.el.style;s.height="";s.display="";s.overflow="hidden";var th=this.el.clientHeight;s.height="0px";var dur=0.4;var a=new YAHOO.util.Anim(this.el,{height:{from:0,to:th,unit:"px"}},dur);a.onComplete.subscribe(function(){tvanim.onComplete();});a.animate();},onComplete:function(){this.el.style.overflow="";this.el.style.height="";this.callback();},toString:function(){return"TVSlideIn";}};YAHOO.widget.TVSlideOut=function(el,callback){this.el=el;this.callback=callback;this.logger=new YAHOO.widget.LogWriter(this.toString());};YAHOO.widget.TVSlideOut.prototype={animate:function(){var tvanim=this;var dur=0.4;var th=this.el.clientHeight;this.el.style.overflow="hidden";var a=new YAHOO.util.Anim(this.el,{height:{from:th,to:0,unit:"px"}},dur);a.onComplete.subscribe(function(){tvanim.onComplete();});a.animate();},onComplete:function(){var s=this.el.style;s.display="none";this.el.style.overflow="";this.el.style.height="";this.callback();},toString:function(){return"TVSlideOut";}};})();(function(){var temp=YAHOO.widget.Record.prototype;YAHOO.widget.Record=function(oLiteral){this._nCount=YAHOO.widget.Record._nCount;YAHOO.widget.Record._nCount++;this._oData={};if(YAHOO.lang.isObject(oLiteral)){for(var sKey in oLiteral){if(YAHOO.lang.hasOwnProperty(oLiteral,sKey)){this._oData[sKey]=oLiteral[sKey];}}}
85 if(SUGAR.reports&&SUGAR.reports.overrideRecord){this._sId=this._oData.module_name+"_"+this._oData.field_name;}else{this._sId=Dom.generateId(null,"yui-rec");}};YAHOO.widget.Record._nCount=0;YAHOO.widget.Record.prototype=temp;})();