1var SalesforceUtils;(function(SalesforceUtils){var DEBUG_ID="[SalesforceAgent] ";var liveagentSrcFetched=false;var CustomWindow;function getLiveAgentSDK(){var def=$.Deferred();if(!liveagentSrcFetched){$.ajax({url:"https://c.la1-c2cs-ukb.salesforceliveagent.com/content/g/js/40.0/deployment.js",dataType:"script",cache:false}).done(function(res){liveagentSrcFetched=true;def.resolve("success");}).fail(function(err){console.log(DEBUG_ID+"liveagent srcipt evaluate failure");console.warn(err);def.reject("");});}else{Logger.log(DEBUG_ID+"liveagent srcipt is already fetched.");def.resolve("fetched");}return def.promise();}SalesforceUtils.getLiveAgentSDK=getLiveAgentSDK;function addProductDetail(product){liveagent.addCustomDetail("Product_Name__c",product);}SalesforceUtils.addProductDetail=addProductDetail;function addOrderIdDetail(orderId){liveagent.addCustomDetail("Order_ID__c",orderId);}SalesforceUtils.addOrderIdDetail=addOrderIdDetail;function addOriginDetail(orgin){liveagent.addCustomDetail("Origin",orgin);}SalesforceUtils.addOriginDetail=addOriginDetail;function setUpLiveagent(liveagentData,buttonID,preChatPayload){var functionDEBUG_ID=DEBUG_ID+"setUpLiveagent: ";try{Logger.log(functionDEBUG_ID+JSON.stringify(preChatPayload));if(!window._laq){window._laq=[];}window._laq.push(function(){liveagent.showWhenOnline(buttonID,document.getElementById("liveagent_button_online"));liveagent.showWhenOffline(buttonID,document.getElementById("liveagent_button_offline"));});liveagent.setName(liveagentData.nickName);liveagent.addCustomDetail("User ID",liveagentData.userID);liveagent.addCustomDetail("Nick Name",liveagentData.nickName);liveagent.addCustomDetail("First Name",liveagentData.firstName);liveagent.addCustomDetail("Last Name",liveagentData.lastName);liveagent.addCustomDetail("Phone Number",liveagentData.phone);liveagent.addCustomDetail("Record Type",liveagentData.recordType);liveagent.addCustomDetail("Case Subject","HKTV Live Chat");liveagent.addCustomDetail("Case Status","New");liveagent.addCustomDetail("Origin",preChatPayload.origin);if(!_.isEmpty(preChatPayload.orderId)){liveagent.addCustomDetail("Order ID",preChatPayload.orderId);liveagent.findOrCreate("Case").map("Subject","Case Subject",false,false,true).map("Status","Case Status",false,false,true).map("Origin","Origin",false,false,true).map("Order_ID__c","Order ID",false,false,true).saveToTranscript("CaseId").showOnCreate();Logger.log(functionDEBUG_ID+"orderID is mapped to Case.");}else{if(!_.isEmpty(preChatPayload.product)){liveagent.addCustomDetail("Product",preChatPayload.product);liveagent.findOrCreate("Case").map("Subject","Case Subject",false,false,true).map("Status","Case Status",false,false,true).map("Origin","Origin",false,false,true).map("Product_Name__c","Product",false,false,true).saveToTranscript("CaseId").showOnCreate();Logger.log(functionDEBUG_ID+"Product is mapped to Case.");}else{liveagent.findOrCreate("Case").map("Subject","Case Subject",false,false,true).map("Status","Case Status",false,false,true).map("Origin","Origin",false,false,true).saveToTranscript("CaseId").showOnCreate();Logger.log(functionDEBUG_ID+"No OrderID & Product is mapped to Case.");}}liveagent.findOrCreate("Account").map("PersonEmail","User ID",true,false,true).map("LastName","Last Name",false,false,true).map("FirstName","First Name",false,false,true).map("Phone","Phone Number",false,false,true).map("RecordTypeId","Record Type",false,false,true);liveagent.findOrCreate("Account").saveToTranscript("AccountId").linkToEntity("Case","AccountId").showOnCreate();}catch(err){console.log(DEBUG_ID+"Set-up failure with below error");console.error(err);}}SalesforceUtils.setUpLiveagent=setUpLiveagent;function initLiveAgent(liveagentData){try{liveagent.init("https://"+liveagentData.salesforce_pod+"/chat",liveagentData.salesforce_deploymentId,liveagentData.salesforce_orgId);console.log(DEBUG_ID+"Live Agent initiated.");}catch(err){console.warn(DEBUG_ID+"Initiate failure with below error");console.error(err);}}SalesforceUtils.initLiveAgent=initLiveAgent;function destoryLiveagent(){liveagentSrcFetched=false;liveagent=undefined;liveAgentDeployment=undefined;window._laq=undefined;var keyList=_.keys(localStorage).filter(function(item){return item.match("liveAgent")?true:false;});if(!_.isEmpty(keyList)){keyList.map(function(item,index){return delete window.localStorage[item];});}}SalesforceUtils.destoryLiveagent=destoryLiveagent;function startLiveChat(){var window_name="LiveChatWindow_HKTVmall";var width=500;var height=480;var top=$(window).height()/2-height/2;var left=$(window).width()/2-width/2;CustomWindow=window.open("",window_name,"width="+width+",height="+height+",top="+top+",left="+left);if(CustomWindow){CustomWindow.onbeforeunload=destoryLiveagent;}else{alert(hktvCommon.stringResources.salesforce.popUpBlock);destoryLiveagent();}}SalesforceUtils.startLiveChat=startLiveChat;function endLiveChat(){if(CustomWindow){CustomWindow.close();}}SalesforceUtils.endLiveChat=endLiveChat;})(SalesforceUtils||(SalesforceUtils={}));var __extends=(this&&this.__extends)||(function(){var extendStatics=Object.
1setPrototypeOf||({__proto__:[]} instanceof Array&&function(d,b){d.__proto__=b;})||function(d,b){for(var p in b){if(b.hasOwnProperty(p)){d[p]=b[p];}}};return function(d,b){extendStatics(d,b);function __(){this.constructor=d;}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __());};})();var UICsPrechatForm=(function(_super){__extends(UICsPrechatForm,_super);function UICsPrechatForm(props){var _this=_super.call(this,props)||this;_this.message=hktvCommon.stringResources.salesforce;_this.queryString=JsonUtils.stringToJson(window.location.search.substring(1),"&")?JsonUtils.stringToJson(window.location.search.substring(1),"&"):"";_this.defaultOption={name:"others",value:_this.message.prechat.category.others};_this.options=[{name:"product",value:_this.message.prechat.category.product},{name:"delivery",value:_this.message.prechat.category.delivery},{name:"refund",value:_this.message.prechat.category.refund},{name:"missing",value:_this.message.prechat.category.missing},{name:"others",value:_this.message.prechat.category.others}];_this.productOption={name:"product",value:_this.message.prechat.category.product};_this.deliveryOption={name:"delivery",value:_this.message.prechat.category.delivery};_this.refundOption={name:"refund",value:_this.message.prechat.category.refund};_this.missingOption={name:"missing",value:_this.message.prechat.category.missing};_this.othersOption={name:"others",value:_this.message.prechat.category.others};_this.state={selected:_this.defaultOption,inputVal:"",isInputError:false,agentOffline:false,getapiMsg:false,liveChatOk:false};_this.handleSelectionChange=_this.handleSelectionChange.bind(_this);_this.handleInputChange=_this.handleInputChange.bind(_this);_this.handleButtonClick=_this.handleButtonClick.bind(_this);_this.startLiveChat=_this.startLiveChat.bind(_this);return _this;}UICsPrechatForm.prototype.componentDidMount=function(){var _this=this;SalesforceUtils.destoryLiveagent();if(this.queryString!=""){this.button_id=typeof this.queryString.btnId!="undefined"?this.queryString.btnId:"5";this.chat_type=typeof this.queryString.chatType!="undefined"?this.queryString.chatType:"";this.chat_content=typeof this.queryString.chatContent!="undefined"?this.queryString.chatContent:"";if(this.button_id!="5"){if(this.button_id=="1"){this.setState({selected:this.productOption,inputVal:this.chat_content});}else{if(this.button_id=="2"){this.setState({selected:this.deliveryOption,inputVal:this.chat_content});}else{if(this.button_id=="3"){this.setState({selected:this.refundOption,inputVal:this.chat_content});}else{if(this.button_id=="4"){this.setState({selected:this.missingOption,inputVal:this.chat_content});}}}}}}this.confirmBtn=this.state.selected;this.getHotlineConfig().done(function(responseData){if(responseData.liveChatOnline){console.log("Call agent");_this.setState({liveChatOk:true});}else{console.log("else case");_this.error_msg=responseData.liveChatOfflineMessage;_this.serviceHour_msg=responseData.liveChatServiceHoursMessage;_this.setState({agentOffline:true,getapiMsg:true,liveChatOk:false});}}).fail(function(){this.setState({agentOffline:true,getapiMsg:false,liveChatOk:false});}.bind(this));};UICsPrechatForm.prototype.startLiveChat=function(){SalesforceUtils.startLiveChat();};UICsPrechatForm.prototype.getHotlineConfig=function(){return $.ajax({type:"GET",url:"/cshotline/getCsHotlineInfo",cache:false});};UICsPrechatForm.prototype.getSerivceHour=function(){var message=this.message;var liveagentData=this.props.liveagentData;var _a=liveagentData.liveChatConfig,_b=_a.serviceStartTime,serviceStartTime=_b===void 0?"":_b,_c=_a.serviceEndTime,serviceEndTime=_c===void 0?"":_c;var startTimeObj=new Date();var endTimeObj=new Date();var locale=hktvCommon.env.currentLanguage||"zh";var convertedStartTime,convertedEndTime;try{startTimeObj.setHours(Number(serviceStartTime.slice(0,2)));startTimeObj.setMinutes(Number(serviceStartTime.slice(2)));endTimeObj.setHours(Number(serviceEndTime.slice(0,2)));endTimeObj.setMinutes(Number(serviceEndTime.slice(2)));if(serviceStartTime&&serviceStartTime){if(typeof new Date().toLocaleStr
1ing=="function"){convertedStartTime=startTimeObj.toLocaleString(locale,{hour:"numeric",minute:"numeric",hour12:true});convertedEndTime=endTimeObj.toLocaleString(locale,{hour:"numeric",minute:"numeric",hour12:true});}else{convertedStartTime=startTimeObj.toTimeString().slice(0,5);convertedEndTime=endTimeObj.toTimeString().slice(0,5);}}}catch(err){console.log(err);}if(convertedStartTime&&convertedEndTime){return message.livechat_service_hour+" ( "+convertedStartTime+" - "+convertedEndTime+" )";}return"";};UICsPrechatForm.prototype.mountLiveagent=function(cs_category,inputVal){if(cs_category===void 0){cs_category="";}if(inputVal===void 0){inputVal="";}var liveagentData=this.props.liveagentData;var buttonIDs=liveagentData.buttonIDs;var startChat=this.startLiveChat.bind(this);var setReactState=this.setState.bind(this);var trackEvent=this.props.analytics.trackEventLiveChat.bind(this);var trackOfflineEvent=this.props.analytics.trackEventLiveChatOffline.bind(this);var isVip=liveagentData.membership==="VIP";var preChatPayload;var buttonID=liveagentData.buttonIDs.buttonOther;var orginDetail="Live Chat - Others";if(isVip){orginDetail="Live Chat - VIP (Others)";}preChatPayload={origin:orginDetail};switch(cs_category){case"product":buttonID=buttonIDs.buttonProduct;orginDetail="Live Chat - Product Enquiry";if(isVip){orginDetail="Live Chat - VIP Product enquiry";}preChatPayload={product:inputVal,origin:orginDetail};break;case"delivery":buttonID=buttonIDs.buttonDelivery;orginDetail="Live Chat - Delivery enquiry";if(isVip){orginDetail="Live Chat - VIP Delivery Enquiry";}preChatPayload={orderId:inputVal,origin:orginDetail};break;case"refund":buttonID=buttonIDs.buttonRefund;orginDetail="Live Chat - Refund status";if(isVip){orginDetail="Live Chat - VIP Refund status";}preChatPayload={orderId:inputVal,origin:orginDetail};break;case"missing":buttonID=buttonIDs.buttonMissing;orginDetail="Live Chat - Missing or bad item";if(isVip){orginDetail="Live Chat - VIP Missing or bad item";}preChatPayload={orderId:inputVal,origin:orginDetail};break;}SalesforceUtils.startLiveChat();this.setState({agentOffline:false,getapiMsg:false});var callback=function(e){if(liveagent){if(e==liveagent.BUTTON_EVENT.BUTTON_UNAVAILABLE){trackOfflineEvent();SalesforceUtils.endLiveChat();setReactState({agentOffline:true});}if(e==liveagent.BUTTON_EVENT.BUTTON_AVAILABLE){trackEvent();liveagent.startChatWithWindow(buttonID,"LiveChatWindow_HKTVmall");}}else{callback=undefined;}};if(!liveagent){SalesforceUtils.getLiveAgentSDK().then(function(){SalesforceUtils.setUpLiveagent(liveagentData,buttonID,preChatPayload);if(cs_category==="product"){Logger.log("[SalesforceAgent] liveagent add product custom detail");}if(cs_category.match(/(delivery|refund|missing)/)){Logger.log("[SalesforceAgent] liveagent add order custom detail");}liveagent.addButtonEventHandler(buttonID,callback);SalesforceUtils.initLiveAgent(liveagentData);});}};UICsPrechatForm.prototype.handleSelectionChange=function(selected){SalesforceUtils.destoryLiveagent();this.setState({selected:selected,isInputError:false,inputVal:"",agentOffline:false});};UICsPrechatForm.prototype.handleInputChange=function(event){var value=event.currentTarget.value;this.setState({inputVal:!_.isEmpty(value)?value:""});};UICsPrechatForm.prototype.handleButtonClick=function(){if(this.state.liveChatOk){var _a=this.state,selected=_a.selected,inputVal=_a.inputVal;this.setState({isInputError:false});this.mountLiveagent(selected.name,inputVal);}else{window.close();}};UICsPrechatForm.prototype.renderNormalHeader=function(){var prechat=this.message.prechat;return(React.createElement("div",null,React.createElement("span",null,prechat.title),React.createElement("div",{style:{textAlign:"center"}},React.createElement(UILoadingDots,{color:"#36B449"}))));};UICsPrechatForm.prototype.renderErrorMessage=function(){var livechat_offline=this.message.livechat_offline;if(!this.state.getapiMsg){this.error_msg=livechat_offline;this.serviceHour_msg=this.getSerivceHour();}return(React.createElement("div",{className:"offline",style:{color:"#EC3F56"}},React.createElement("span",null,this.error_msg),React.createElement("span",null,this.serviceHour_msg)));};UICsPrechatForm.prototype.render=function(){var prechat=this.message.prechat;var _a=this.state,selected=_a.selected,inputVal=_a.inputVal,isInputError=_a.isInputError,agentOffline=_a.agentOffline;var info_title=undefined,info_caption=undefined,info_error=undefined,button_disable=false;switch(selected.name){case"product":info_title=prechat.product.title;info_caption=prechat.product.caption;break;case"delivery":case"refund":case"missing":info_title=prechat.order.title;info_caption=prechat.order.caption;info_error=prechat.order.error;break;case"others":break;case"default":default:break;}return(React.createElement("div",{id:"ui-cs-prechat-form",style:{cursor:"default"}},React.createElement("div",{className:"prechat-form-header",style:{minHeight:83}},agentOffline?this.renderErrorMessage():this.renderNormalHeader()),React.createElement(UIButtonConfirm,{title:this.state.liveChatOk?prechat.start:prechat.close,minWidth:88,handleClick:this.handleButtonClick,disable:button_disable})));};return UICsPrechatForm;}(React.PureComponent));var __extends=(this&&this.__extends)||(function(){var extendStatics=Object.
1setPrototypeOf||({__proto__:[]} instanceof Array&&function(d,b){d.__proto__=b;})||function(d,b){for(var p in b){if(b.hasOwnProperty(p)){d[p]=b[p];}}};return function(d,b){extendStatics(d,b);function __(){this.constructor=d;}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __());};})();var UICsVipHotline=(function(_super){__extends(UICsVipHotline,_super);function UICsVipHotline(props){var _this=_super.call(this,props)||this;_this.message=hktvCommon.stringResources.salesforce;_this.hotlineConfig={};_this.enableHotline=false;_this.state={enableHotline:false,hotlineConfig:{}};if(_this.props.isVip){_this.getHotlineConfig().done(function(responseData){var hotlineConfig=responseData||{};var enableHotline=false;if(responseData.showHotline){enableHotline=true;}_this.setState({enableHotline:enableHotline,hotlineConfig:hotlineConfig});});}return _this;}UICsVipHotline.prototype.getHotlineConfig=function(){return $.ajax({type:"GET",url:"/cshotline/getCsHotlineInfo",cache:false});};UICsVipHotline.prototype.sfHotlineOnClickListener=function(){var HOTLINE_URL=hktvCommon.addPrefixToHktvUrl("cshotline");this.props.trackEvent();window.location.assign(HOTLINE_URL);};UICsVipHotline.prototype.getTimeSlotString=function(){var message=this.message;var hotlineConfig=this.state.hotlineConfig;var hotlineStartTime=new Date();var hotlineEndTime=new Date();var startTimeString=hotlineConfig.startTime||"";var endTimeString=hotlineConfig.endTime||"";var locale=hktvCommon.env.currentLanguage||"zh";var convertedStartTime="",convertedEndTime="";try{hotlineStartTime.setHours(startTimeString.split(":")[0]);hotlineStartTime.setMinutes(startTimeString.split(":")[1]);hotlineEndTime.setHours(endTimeString.split(":")[0]);hotlineEndTime.setMinutes(endTimeString.split(":")[1]);if(hotlineConfig.startTime&&hotlineConfig.endTime){if(typeof hotlineStartTime.toLocaleString=="function"){convertedStartTime=hotlineStartTime.toLocaleString(locale,{hour:"numeric",minute:"numeric",hour12:true});convertedEndTime=hotlineEndTime.toLocaleString(locale,{hour:"numeric",minute:"numeric",hour12:true});}else{convertedStartTime=hotlineStartTime.toTimeString().slice(0,5);convertedEndTime=hotlineEndTime.toTimeString().slice(0,5);}}}catch(err){console.log(err);}if(convertedStartTime&&convertedEndTime){return"";}return message.vip_service_hour+" ( "+convertedStartTime+" - "+convertedEndTime+" )";};UICsVipHotline.prototype.render=function(){var _this=this;var message=this.message;var enableHotline=this.state.enableHotline;return enableHotline&&(React.createElement("div",{className:"Salesforce_hotline",style:{display:"block",cursor:"pointer"},onClick:function(){return _this.sfHotlineOnClickListener();}},React.createElement(UIIconCsVip,null),React.createElement("div",{className:"sf_hotline_message"},React.createElement("span",null,message.vip_title),React.createElement("span",{className:"vipServiceHour"},this.getTimeSlotString()))));};return UICsVipHotline;}(React.PureComponent));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.