if(typeof resp == 'undefined' || resp == null ){ var resp = new Object(); resp.authenticated = true; } resp.baseUrl = null; //set by server side resp.tenantName = null; //set by server side resp.generateRandom=function() { var range = 1000000; var nmbrTry = 0; while(nmbrTry < 1000 ){ nmbrTry++; var result = Math.floor(Math.random()*range); var el = document.getElementById("'"+result+"'"); if(el == null){ return result; } } } resp.WidgetContainer=function(){ this.widgets = new Array(); } resp.WidgetContainer.prototype.getWidget=function(widgetName){ for(var i=0; 0 < this.widgets.length; i++){ if(typeof this.widgets[i] == 'undefined') return null; if(this.widgets[i].frameName == widgetName) return this.widgets[i]; } return null; } if(typeof resp.container == 'undefined' || resp.container == null){ resp.container = new resp.WidgetContainer(); } resp.BaseWidget=function(divId, width, height,frameName){ if(typeof divId == 'undefined') return; this.keepAlive = true; this.widgetFrame = null; this.preSubmitParams = null; // JSON if(divId==null || (document.getElementById(divId)==null)){ this.container=document.createElement('div'); this.container=document.body.appendChild(this.container); } else { this.container = document.getElementById(divId); } if(this.isSecureProtocol()) { // if parent is HTTPS, make child HTTPS resp.baseUrl = resp.baseUrl.replace('http://','https://'); } else { // if parent is HTTP, make child HTTP resp.baseUrl = resp.baseUrl.replace('https://','http://'); } if(this.container != null){ if(resp.authenticated) { this.iframe=this.load(divId, width, height,frameName); resp.container.widgets.push(this); // adding widget to container } } } resp.BaseWidget.prototype.load=function(divId, width, height,frameName){ var tmp = new Date(); this.frameName = frameName + resp.generateRandom() + '_' + tmp.getTime() ; // create loading indicator this.loadingDiv = document.createElement("div"); this.loadingDiv.style.width="500px"; this.loadingDiv.style.textAlign="center"; this.loadingImg = document.createElement("img"); if(typeof cpq == 'object') { this.loadingImg.src = resp.baseUrl+ "/img/cpq/ajax-loader.gif"; } else { this.loadingImg.src = resp.baseUrl+ "/img/ajax-loader.gif"; } this.loadingImg = this.loadingDiv.appendChild(this.loadingImg); this.loadingDiv = this.container.appendChild(this.loadingDiv); this.iframe = document.createElement("iframe"); this.iframe.id = this.frameName; this.iframe.name = this.frameName; this.iframe.style.borderWidth="0px"; this.iframe.style.borderColor="transparent"; this.iframe.frameBorder = "0"; this.iframe.marginHeight="0"; this.iframe.marginWidth="0"; var oThis = this; resp.addEventHandler(oThis.iframe,"load", function(){ oThis.loadingDiv.style.display = "none"; }) if(typeof width != 'undefined' && width != null) { this.iframe.style.width=width+"px"; } if(typeof height != 'undefined' && height != null) { this.iframe.style.height=height+"px"; } return this.iframe; } resp.BaseWidget.prototype.prepareSendCommand=function(){ var tmp = null; var cmdIndex = this.iframe.src.indexOf('#'); if(cmdIndex > 0 ){ tmp = this.iframe.src.substring(0, cmdIndex); } else { tmp = this.iframe.src; } return tmp; } resp.BaseWidget.prototype.reload=function(){ this.iframe.src = this.prepareSendCommand() + '#reload'; } resp.BaseWidget.prototype.hide=function(){ this.iframe.style.width = "0px"; this.iframe.style.height = "0px"; } resp.BaseWidget.prototype.show=function(width, height){ this.iframe.style.width = width+"px"; this.iframe.style.height = height+"px"; } resp.BaseWidget.prototype.sendCrossDomainParams=function(callback){ var addParams = this.buildCrossDomainParams(this.preSubmitParams); var random = resp.generateRandom(); this.iframe.src = this.prepareSendCommand()+'#setParam'+addParams+(callback!=null ? '~'+callback:'') + '|'+random; this.preSubmitParams = null; } resp.BaseWidget.prototype.isSecureProtocol=function(){ if(location.protocol=='https:') return true; return false; } resp.CreateCaseWidget=function(divId, apiKey, standardParams, customParams, width, height){ this.preSubmit = null; resp.BaseWidget.call(this,divId,width, height,"createCaseWidget"); var iframeUrl = resp.baseUrl +"/caseEditPrepare.do?token="+apiKey+ "&widget=true&widgetName="+this.frameName + this.buildUrlParams('presetFields',customParams) + this.buildUrlParams(null, standardParams); if(this.isSecureProtocol()){ // if parent is HTTPS, make child HTTPS iframeUrl = iframeUrl.replace('http://','https://'); iframeUrl = iframeUrl + '&secure=true'; } else { // if parent is HTTP, make child HTTP and add doNotForceHTTPS iframeUrl = iframeUrl.replace('https://','http://'); } if(resp.cpqSSO){ iframeUrl = iframeUrl + '&cpqSSO=true'; } if(resp.tenantName != null){ iframeUrl = iframeUrl + '&tenantName='+resp.tenantName; } // this.container.innerHTML = ""; // this.container.innerHTML = ""; //this.iframe.contentWindow.location.reload(true); this.iframe = this.container.appendChild(this.iframe); this.iframe.src = iframeUrl; //this.iframe.contentWindow.location.href = iframeUrl; } resp.CreateCaseWidget.prototype = new resp.BaseWidget(); resp.CreateCaseWidget.prototype.onSubmit=function(callback){ if(this.preSubmit!=null){ this.preSubmit(); } this.sendCrossDomainParams(callback); } resp.CreateCaseWidget.prototype.reload=function(){ this.iframe.src= this.prepareSendCommand()+'&validWidget=true';// + '#reload'; TODO: - double reload!! } /** * Method called after case has been created and no Case list associated. * This method can be used to create List widget upon Case creation. */ resp.CreateCaseWidget.prototype.afterCaseCreate=function(){ } resp.ListCaseWidget=function(divId, apiKey, standardParams, customParams, width, height){ this.preCommentSubmit = null; resp.BaseWidget.call(this,divId,width, height,"listCaseWidget"); var iframeUrl = resp.baseUrl+"/searchAjax.do?view=3&resetForm=true&widget=true"+this.buildUrlParams('customFields',customParams)+"&token="+apiKey+"&widgetName="+this.frameName + this.buildUrlParams(null, standardParams); if(this.isSecureProtocol()){ // if parent is HTTPS, make child HTTPS iframeUrl = iframeUrl.replace('http://','https://'); iframeUrl = iframeUrl + '&secure=true'; } else { // if parent is HTTP, make child HTTP and add doNotForceHTTPS iframeUrl = iframeUrl.replace('https://','http://'); } if(resp.tenantName != null){ iframeUrl = iframeUrl + '&tenantName='+resp.tenantName; } if(resp.cpqSSO){ iframeUrl = iframeUrl + '&cpqSSO=true'; } this.iframe = this.container.appendChild(this.iframe); this.iframe.src = iframeUrl; } resp.ListCaseWidget.prototype = new resp.BaseWidget(); /** * Executed before comment is submitted to server. * Paras : - commentadditionaldata - used for sending 'CPQ Link' - see cpqComm.js * - commentlinktitle - used as title for above CPQ Link - see cpqComm.js */ resp.ListCaseWidget.prototype.onCommentSubmit=function(callback){ if(this.preCommentSubmit!=null){ this.preCommentSubmit(); } this.sendCrossDomainParams(callback); } resp.ListCaseWidget.prototype.reload=function(){ this.iframe.src= this.prepareSendCommand()+'&validWidget=true';// + '#reload'; TODO: - double reload!! } /** * Building params that will be sent to other domain using receiver.htm. * Acctually this is pair of Custom Field Names (which are actually dom Ids and their values). */ resp.BaseWidget.prototype.buildCrossDomainParams=function(map){ if(map == null) return ''; var url = ''; for(var key in map){ // var updatedKey = key.replace(/ /g,'_'); // because Custom Fields Ids white spaces are replaced with underscores - DOM Spec. Limitation // updatedKey = updatedKey.toLowerCase(); url = url + '*'+key+'*'+map[key]; } return url; } resp.BaseWidget.prototype.buildUrlParams=function(paramListName, map){ if(map == null ) return ''; var url = ''; if(paramListName != null) { // building custom params var i=0; for(var key in map){ url = url +'&'+paramListName+'['+i+'].name='+key; if(paramListName == 'presetFields') { url = url + '&'+paramListName+'['+i+'].simpleValue='+escape(map[key]); //hardcoded } else { url = url + '&'+paramListName+'['+i+'].value='+escape(map[key]); } i++; } } else { //building standard params for(var key in map) { url = url + '&'+key+'='+map[key]; } } return url; } //find cases by custom field resp.ListCaseWidget.expertCaseListParams = {"Duration" : 3}; //find case by Id resp.ListCaseWidget.findCase = {'caseId' : '5555'}; /** * * Resp Cross-Frame Commands */ resp.resize=function(widgetName,width,height,initWidget){ if(widgetName == null) { return; } if (initWidget > 0) { // wait is introduced because rich text editor in widgets loads after resize // function is called and this causes submit button to become invisible setTimeout(function(){ var widget = resp.container.getWidget(widgetName); if(widget == null) return; if(typeof width != 'undefined' || width != null){ widget.iframe.style.width=width+'px'; } if(typeof height != 'undefined' || height != null){ widget.iframe.style.height=height+'px'; } }, 1000); } else { var widget = resp.container.getWidget(widgetName); if(widget == null) return; if(typeof width != 'undefined' || width != null){ widget.iframe.style.width=width+'px'; } if(typeof height != 'undefined' || height != null){ widget.iframe.style.height=height+'px'; } } } resp.reloadAllLists=function(){ var widgets = resp.container.widgets; for(var i=0; i < widgets.length; i++){ if(widgets[i].frameName.indexOf('listCaseWidget') > -1){ widgets[i].reload(); } } } resp.onCommentSubmit=function(callback){ var widgets = resp.container.widgets; for(var i=0; i < widgets.length; i++){ var widget = widgets[i]; if(widget.onCommentSubmit){ widget.onCommentSubmit(callback); } } } /** * Receiver for all cross domain commands */ resp.receiver=function(data){ resp.parseCommand(data); } /** * Command parse. * Command format is : #targetWidget$commandName*arg1*arg2...~callback|random number * '|' this is command terminator * */ resp.parseCommand=function(data){ var widgetIndex = data.indexOf("#"); var commandIndex = data.indexOf("$"); if(widgetIndex < 0) return; if(commandIndex < 0) return; var terminatorIndex = data.indexOf("|"); if(terminatorIndex < 0) return; var widgetName = data.substring(widgetIndex+1, commandIndex); var widget = resp.container.getWidget(widgetName); var argumentIndex = data.indexOf("*"); var command = ''; var callbackIndex = data.indexOf("~"); var initWidget = data.indexOf("initWidget"); if(argumentIndex > 0){ command = data.substring(commandIndex+1, argumentIndex); } else { if(callbackIndex > 0){ command = data.substring(commandIndex+1, callbackIndex); }else { command = data.substring(commandIndex+1, terminatorIndex); } } var allArgs = null; if(argumentIndex > 0){ var args = data.substring(argumentIndex+1, callbackIndex > 0 ? callbackIndex : terminatorIndex ); allArgs = args.split('*'); } var callback = ''; if(callbackIndex > 0){ callback = data.substring(callbackIndex+1, terminatorIndex); } if(command == 'globalReload'){ history.go(0); } if(command == 'resp.resize'){ resp.resize(widgetName, allArgs[0], allArgs[1], initWidget); } if(command == 'reload'){ if(widget!=null){ widget.reload(); } } if(command == 'reloadList'){ if(widget!=null && widget.list != null){ widget.list.reload(); } else if (widget!=null && widget.list == null){ widget.afterCaseCreate(); } } if(command == 'submit'){ if(widget!=null){ widget.onSubmit(callback); } } if(command == 'commentSubmit'){ widget.onCommentSubmit(callback); } } resp.generateRandom=function() { var range = 1000000; var nmbrTry = 0; while(nmbrTry < 1000 ){ nmbrTry++; var result = Math.floor(Math.random()*range); var el = document.getElementById("'"+result+"'"); if(el == null){ return result; } } } resp.addEventHandler=function(oTarget,eventType,fnHandler) { if(oTarget.addEventListener){ // for DOM Compliant browsers oTarget.addEventListener(eventType,fnHandler,false); } else if (oTarget.attachEvent){ // for IE oTarget.attachEvent("on"+eventType, fnHandler); } else { oTarget["on"+eventType] = fnHandler; } } resp.baseUrl='https://social.webcomserver.com/wpm'; resp.tenantName = 'default';