From 87cfb2105ae1ceb2918783c79edef6f88cb532d0 Mon Sep 17 00:00:00 2001 From: Remdex Date: Fri, 8 Jun 2018 11:42:06 +0200 Subject: [PATCH] Improve bot workflow --- lhc_web/design/defaulttheme/js/lh.js | 36 ++++++++++++------- lhc_web/design/defaulttheme/js/lh.min.js | 4 +-- .../lhgenericbot/argumenttemplates.php | 13 ++++--- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/lhc_web/design/defaulttheme/js/lh.js b/lhc_web/design/defaulttheme/js/lh.js index 4ba73ae187..5972a6412e 100644 --- a/lhc_web/design/defaulttheme/js/lh.js +++ b/lhc_web/design/defaulttheme/js/lh.js @@ -3161,8 +3161,11 @@ function lh(){ 'class': 'message-row pending-storage pending-storage-bot', text: 'Processing...' }).appendTo(messageBlock); + var scrollHeight = messageBlock.prop("scrollHeight"); + messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); this.syncroRequestSend = true; + clearTimeout(this.userTimeout); $.get(this.wwwDir + 'genericbot/buttonclicked/'+this.chat_id+'/'+this.hash,{payload: payload, id : id, processed : (typeof notHide === 'undefined' || notHide == false)},function(data){ if (typeof notHide === 'undefined' || notHide === false){ @@ -3170,10 +3173,8 @@ function lh(){ } processing.remove(); - var scrollHeight = messageBlock.prop("scrollHeight"); messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); - lhinst.forceBottomScroll = true; lhinst.syncroRequestSend = false; lhinst.syncusercall(); @@ -3194,19 +3195,19 @@ function lh(){ text: 'Processing...' }).appendTo(messageBlock); + var scrollHeight = messageBlock.prop("scrollHeight"); + messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); + this.syncroRequestSend = true; + clearTimeout(this.userTimeout); $.get(this.wwwDir + 'genericbot/buttonclicked/'+this.chat_id+'/'+this.hash+'/(type)/editgenericstep',{payload : step,id : id},function(data){ - processing.remove(); - var scrollHeight = messageBlock.prop("scrollHeight"); messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); - lhinst.forceBottomScroll = true; lhinst.syncroRequestSend = false; lhinst.syncusercall(); - }).fail(function() { lhinst.syncroRequestSend = false; lhinst.syncusercall(); @@ -3229,15 +3230,18 @@ function lh(){ text: 'Processing...' }).appendTo(messageBlock); + var scrollHeight = messageBlock.prop("scrollHeight"); + messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); + this.syncroRequestSend = true; + clearTimeout(this.userTimeout); - $.get(this.wwwDir + 'genericbot/buttonclicked/'+this.chat_id+'/'+this.hash+'/(type)/triggerclicked',{payload: payload, id : id, processed : (typeof notHide === 'undefined' || notHide == false)},function(data){ + $.get(this.wwwDir + 'genericbot/buttonclicked/'+this.chat_id+'/'+this.hash+'/(type)/triggerclicked',{payload: payload, id : id, processed : (typeof notHide === 'undefined' || notHide == false)},function(data) { if (typeof notHide === 'undefined' || notHide === false){ $('.meta-message-'+id).remove(); } processing.remove(); - var scrollHeight = messageBlock.prop("scrollHeight"); messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); @@ -3267,7 +3271,11 @@ function lh(){ text: 'Processing...' }).appendTo(messageBlock); + var scrollHeight = messageBlock.prop("scrollHeight"); + messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); + lhinst.syncroRequestSend = true; + clearTimeout(this.userTimeout); $.get(this.wwwDir + 'genericbot/updatebuttonclicked/'+this.chat_id+'/'+this.hash,{payload: payload, id : id, processed : (typeof notHide === 'undefined' || notHide == false) },function(data){ if (typeof notHide === 'undefined' || notHide === false){ @@ -3275,7 +3283,6 @@ function lh(){ } processing.remove(); - var scrollHeight = messageBlock.prop("scrollHeight"); messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); @@ -3296,18 +3303,23 @@ function lh(){ btn.attr("disabled","disabled"); btn.text("Processing..."); } - + var messageBlock = $('#messagesBlock'); var processing = jQuery('
', { 'class': 'message-row pending-storage pending-storage-bot', text: 'Processing...' - }).appendTo($('#messagesBlock')); + }).appendTo(messageBlock); + + var scrollHeight = messageBlock.prop("scrollHeight"); + messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); if ($('#generic_list-'+id).val() != '') { this.syncroRequestSend = true; + clearTimeout(this.userTimeout); $.get(this.wwwDir + 'genericbot/buttonclicked/'+this.chat_id+'/'+this.hash+'/(type)/valueclicked',{payload: $('#id_generic_list-'+id).val(), id : id},function(data){ $('.meta-message-'+id).remove(); - processing.remove(); + var scrollHeight = messageBlock.prop("scrollHeight"); + messageBlock.stop(true,false).animate({ scrollTop: scrollHeight }, 500); lhinst.forceBottomScroll = true; lhinst.syncroRequestSend = false; diff --git a/lhc_web/design/defaulttheme/js/lh.min.js b/lhc_web/design/defaulttheme/js/lh.min.js index 3a95c2b5d2..957405d1e9 100644 --- a/lhc_web/design/defaulttheme/js/lh.min.js +++ b/lhc_web/design/defaulttheme/js/lh.min.js @@ -1,3 +1,3 @@ function csrfSafeMethod(e){return/^(GET|HEAD|OPTIONS|TRACE)$/.test(e)}function lh(){this.wwwDir=WWW_DIR_JAVASCRIPT,this.addmsgurl="chat/addmsgadmin/",this.addmsgurluser="chat/addmsguser/",this.addmsgurluserchatbox="chatbox/addmsguser/",this.syncuser="chat/syncuser/",this.syncadmin="chat/syncadmin/",this.closechatadmin="chat/closechatadmin/",this.deletechatadmin="chat/deletechatadmin/",this.checkchatstatus="chat/checkchatstatus/",this.syncadmininterfaceurl="chat/syncadmininterface/",this.accepttransfer="chat/accepttransfer/",this.trasnsferuser="chat/transferuser/",this.userclosechaturl="chat/userclosechat/",this.disableremember=!1,this.operatorTyping=!1,this.forceBottomScroll=!1,this.appendSyncArgument="",this.disableSync=!1,this.chat_id=null,this.hash=null,this.soundIsPlaying=!1,this.soundPlayedTimes=0,this.last_message_id=0,this.isSinchronizing=!1,this.isWidgetMode=!1,this.isEmbedMode=!1,this.syncroRequestSend=!1,this.currentMessageText="",this.setWidgetMode=function(e){this.isWidgetMode=e},this.setEmbedMode=function(e){this.isEmbedMode=e},this.setSynchronizationRequestSend=function(e){this.syncroRequestSend=e},this.setSyncUserURL=function(e){this.syncuser=e},this.chatsSynchronising=[],this.chatsSynchronisingMsg=[],this.notificationsArray=[],this.speechHandler=!1,this.underMessageAdd=!1,this.closeWindowOnChatCloseDelete=!1,this.userTimeout=!1,this.lastOnlineSyncTimeout=!1,this.setLastUserMessageID=function(e){this.last_message_id=e},this.setChatID=function(e){this.chat_id=e},this.setwwwDir=function(e){this.wwwDir=e},this.setCloseWindowOnEvent=function(e){this.closeWindowOnChatCloseDelete=e},this.setDisableRemember=function(e){this.disableremember=e},this.setSynchronizationStatus=function(e){this.underMessageAdd=e},this.tabIconContent="face",this.tabIconClass="icon-user-status material-icons icon-user-online",this.audio=new Audio,this.audio.autoplay="autoplay",this.reloadTab=function(e,t,s){$("#ntab-chat-"+e).text(s),0!=$("#CSChatMessage-"+e).length&&($("#CSChatMessage-"+e).unbind("keydown",function(){}),$("#CSChatMessage-"+e).unbind("keyup",function(){})),this.removeSynchroChat(e),this.removeBackgroundChat(e),this.hideNotification(e);var i=this;$.get(this.wwwDir+"chat/adminchat/"+e+"/(remember)/true",function(t){$("#chat-id-"+e).html(t),$("#CSChatMessage-"+e).focus(),i.rememberTab(e),i.addQuateHandler(e),i.loadMainData(e),ee.emitEvent("chatTabLoaded",[e])})},this.loadMainData=function(e){$.getJSON(this.wwwDir+"chat/loadmaindata/"+e,{},function(e){$.each(e.items,function(e,t){var s=$(t.selector);"undefined"!=typeof t.attr&&$.each(t.attr,function(e,t){s.attr(e,t)}),"undefined"!=typeof t.action&&("hide"==t.action?s.hide():"show"==t.action?s.show():"remove"==t.action?s.remove():"click"==t.action&&(s.attr("auto-scroll",1),s.click()))})}).fail(function(){})},this.getSelectedText=function(){var e,t="";return window.getSelection?(e=window.getSelection(),t=e.toString()):document.selection&&"Control"!==document.selection.type&&(e=document.selection.createRange(),t=e.text),{selection:e,text:t}},this.popoverShown=!1,this.popoverShownNow=!1,this.selection=null,this.mouseClicked=function(e){selected=e.data.that.getSelectedText(),$(".popover-copy").popover("destroy"),!selected.text.length||null!==e.data.that.selection&&e.data.that.selection.text===selected.text?e.data.that.selection=null:(e.data.that.selection=selected,$(this).popover({placement:"top",trigger:"manual",animation:!1,html:!0,container:"#chat-id-"+e.data.chat_id,template:'',content:'quote'}).popover("show"),$(this).addClass("popover-copy"),e.data.that.popoverShown=!0,e.data.that.popoverShownNow=!0)},this.addQuateHandler=function(e){this.popoverShown=!1,$("#messagesBlock-"+e+" .message-row").off("mouseup",lhinst.mouseClicked),$("#messagesBlock-"+e+" .message-row").on("mouseup",{chat_id:e,that:this},lhinst.mouseClicked)},this.quateSelection=function(e){$(".popover-copy").popover("destroy");var t=this.selection.text.replace(/[\uD7AF\uD7C7-\uD7CA\uD7FC-\uF8FF\uFA6E\uFA6F\uFADA]/g,"");t=t.replace(/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.*)/gm,""),t=t.replace(/^[0-9]{2}:[0-9]{2}:[0-9]{2}(.*)/gm,""),t=t.replace(/^\s*\n/gm,""),t=t.replace(/^ /gm,""),window.textreplace=t;var s=$("#CSChatMessage-"+e),i=s.val().replace(/^\s*\n/g,"");s.val((""!=i?i+"[quote]"+t+"[/quote]":"[quote]"+t+"[/quote]")+"\n").focus();var a=s[0],n=30;for(a.clientHeight/a.rows;a.scrollHeight>a.clientHeight&&!window.opera&&a.rowsa.clientHeight&&(a.style.overflow="auto"),this.popoverShown=!1},this.hidePopover=function(){this.popoverShownNow===!0?this.popoverShownNow=!1:this.popoverShown===!0&&(this.popoverShown=!1,$(".popover-copy").popover("destroy"))},this.addTab=function(e,t,s,i,a,n){if(!(e.find("#chat-tab-link-"+i).size()>0)){var o='';"undefined"==typeof n||0==parseInt(n)?e.find("> ul").append(o):e.find("> ul > li:eq("+(n-1)+")").after(o),$("#chat-tab-link-"+i).click(function(){var e=$(this);setTimeout(function(){e.find(".msg-nm").remove(),e.removeClass("has-pm"),$("#messagesBlock-"+i).stop(!0,!1).animate({scrollTop:$("#messagesBlock-"+i).prop("scrollHeight")},500),$("#CSChatMessage-"+i).focus(),ee.emitEvent("chatTabClicked",[i,e])},500)});var r=window.location.hash.replace("#/","#"),c=this;$.get(t,function(t){"undefined"==typeof a||a===!0||r=="#chat-id-"+i?(e.find("> ul > li.active").removeClass("active"),e.find("> ul > #chat-tab-li-"+i).addClass("active"),e.find("> div.tab-content > div.active").removeClass("active"),e.find("> div.tab-content").append('
'),window.location.hash="#/chat-id-"+i):e.find("> div.tab-content").append('
'),$("#chat-id-"+i).html(t),$("#CSChatMessage-"+i).focus(),0==c.disableremember&&c.rememberTab(i),c.addQuateHandler(i),c.loadMainData(i),ee.emitEvent("chatTabLoaded",[i])})}},this.rememberTab=function(e){if(localStorage)try{e=parseInt(e);var t=localStorage.getItem("achat_id"),s=new Array;if(null!==t)var s=t.split(",").map(Number);s.indexOf(e)===-1&&s.push(e),localStorage.setItem("achat_id",s.join(","))}catch(i){console.log(i)}},this.forgetChat=function(e){if(localStorage)try{e=parseInt(e);var t=localStorage.getItem("achat_id"),s=new Array;null!==t&&(s=t.split(",").map(Number)),s.indexOf(e)!==-1&&s.splice(s.indexOf(e),1),localStorage.setItem("achat_id",s.join(","))}catch(i){console.log(i)}},this.attachTabNavigator=function(){$("#tabs > ul.nav > li > a").click(function(){$(this).find(".msg-nm").remove(),$(this).removeClass("has-pm")})},this.holdAction=function(e,t){var s=this;$.postJSON(this.wwwDir+"chat/holdaction/"+e,function(i){0==i.error?(1==i.hold?t.addClass("btn-info"):t.removeClass("btn-info"),""!=i.msg&&($("#messagesBlock-"+e).append(i.msg),$("#messagesBlock-"+e).stop(!0,!1).animate({scrollTop:$("#messagesBlock-"+e).prop("scrollHeight")},500)),s.syncadmincall()):alert(i.msg)})},this.copyMessages=function(e){function t(t){e.tooltip("hide").attr("data-original-title",t).tooltip("show")}function s(){setTimeout(function(){e.tooltip("hide")},3e3)}return $("#chat-copy-messages").select(),document.execCommand("copy"),e.tooltip({trigger:"click",placement:"top"}),t(e.attr("data-success")),s(),!1},this.startChat=function(e,t,s,i,a){if(this.removeBackgroundChat(e),this.hideNotification(e),0==this.chatUnderSynchronization(e)){var n="undefined"==typeof i||i,o=0==this.disableremember?"/(remember)/true":"";this.addTab(t,this.wwwDir+"chat/adminchat/"+e+o,s,e,n,a);var r=this;setTimeout(function(){r.syncadmininterfacestatic()},1e3)}else t.find("> ul > li.active").removeClass("active"),t.find("> ul > #chat-tab-li-"+e).addClass("active"),t.find("> div.tab-content > div.active").removeClass("active"),t.find("> div.tab-content > #chat-id-"+e).addClass("active"),window.location.hash="#/chat-id-"+e;ee.emitEvent("chatStartTab",[e])},this.backgroundChats=[],this.startChatBackground=function(e,t,s){if(0==this.chatUnderSynchronization(e)){this.backgroundChats.push(parseInt(e));var i=0==this.disableremember?"/(remember)/true":"";return this.addTab(t,this.wwwDir+"chat/adminchat/"+e+i+"/(arg)/background",s,e,!1),ee.emitEvent("chatStartBackground",[e]),!0}return!1},this.protectCSFR=function(){$("a.csfr-required").click(function(){var e=$(this);e.attr("data-secured")||(e.attr("href",e.attr("href")+"/(csfr)/"+confLH.csrf_token),e.attr("data-secured",1))})},this.setChatHash=function(e){this.hash=e},this.addSynchroChat=function(e,t){this.chatsSynchronising.push(e),this.chatsSynchronisingMsg.push(e+","+t),LHCCallbacks.addSynchroChat&&LHCCallbacks.addSynchroChat(e,t)},this.removeSynchroChat=function(e){for(var t=0;t6&&(s.currentMessageText=n,LHCCallbacks.initTypingMonitoringUserInform?LHCCallbacks.initTypingMonitoringUserInform({chat_id:e,hash:s.hash,status:!0,msg:n}):$.postJSON(t+"chat/usertyping/"+e+"/"+s.hash+"/true",{msg:n},function(t){LHCCallbacks.initTypingMonitoringUser&&LHCCallbacks.initTypingMonitoringUser(e,!0)}))}})},this.typingStoppedUser=function(e){var t=this;1==t.is_typing&&(LHCCallbacks.typingStoppedUserInform?(t.is_typing=!1,LHCCallbacks.typingStoppedUserInform({chat_id:e,hash:this.hash,status:!1})):$.getJSON(this.wwwDir+"chat/usertyping/"+e+"/"+this.hash+"/false",{},function(s){t.is_typing=!1,LHCCallbacks.initTypingMonitoringUser&&LHCCallbacks.initTypingMonitoringUser(e,!1)}).fail(function(){t.is_typing=!1}))},this.refreshFootPrint=function(e){e.addClass("disabled"),$.get(this.wwwDir+"chat/chatfootprint/"+e.attr("rel"),{},function(t){$("#footprint-"+e.attr("rel")).html(t),e.removeClass("disabled")})},this.makeAbstractRequest=function(e,t){return $.get(t.attr("href"),function(t){lhinst.syncadmininterfacestatic(),LHCCallbacks.userRedirectedSurvey&&LHCCallbacks.userRedirectedSurvey(e)}),!1},this.refreshOnlineUserInfo=function(e){e.addClass("disabled"),$.get(this.wwwDir+"chat/refreshonlineinfo/"+e.attr("rel"),{},function(t){$("#online-user-info-"+e.attr("rel")).html(t),e.removeClass("disabled")})},this.processCollapse=function(e){if("chevron_right"==$("#chat-main-column-"+e+" .collapse-right").text()){$("#chat-right-column-"+e).hide(),$("#chat-main-column-"+e).removeClass("col-sm-7").addClass("col-sm-12"),$("#chat-main-column-"+e+" .collapse-right").text("chevron_left");try{localStorage&&localStorage.setItem("lhc_rch",1)}catch(t){}}else{$("#chat-right-column-"+e).show(),$("#chat-main-column-"+e).removeClass("col-sm-12").addClass("col-sm-7"),$("#chat-main-column-"+e+" .collapse-right").text("chevron_right");try{localStorage&&localStorage.removeItem("lhc_rch")}catch(t){}}},this.chatUnderSynchronization=function(e){for(var t=0;t0&&$("#msg-"+e.last_message_id).attr("data-op-id")!=t.msop&&$("#msg-"+e.last_message_id).next().addClass("operator-changes"),e.last_message_id=t.message_id,"false"==t.uw&&e.isWidgetMode&&"undefined"!=typeof parent&&parent.postMessage("lhc_newopmsg","*")}else"true"!=t.status&&$("#status-chat").html(t.status);if(e.userTimeout=setTimeout(chatsyncuser,confLH.chat_message_sinterval),"t"==t.cs&&e.chatsyncuserpending(),""!=t.ott&&"f"!=t.ott){var n=$("#id-operator-typing");n.text(t.ott),n.css("visibility","visible"),e.operatorTyping=!0}else"f"==t.ott&&(e.operatorTyping=!1,$("#id-operator-typing").css("visibility","hidden"));""!=t.op&&e.executeRemoteCommands(t.op)}else $("#status-chat").html(t.status),$("#ChatMessageContainer").remove(),$("#ChatSendButtonContainer").remove(),$("#id-operator-typing").css("visibility","hidden"),e.operatorTyping=!1,"undefined"!=typeof t.op&&""!=t.op&&e.executeRemoteCommands(t.op),t.closed&&1==t.closed&&(ee.emitEvent("chatClosedSyncUser",[e.chat_id]),e.isWidgetMode&&"undefined"!=typeof parent&&window.location!==window.parent.location?parent.postMessage("lhc_chat_closed"+("undefined"!=typeof t.closed_arg?":"+t.closed_arg:""),"*"):("undefined"!=typeof t.closed_arg&&e.parseCloseArgs(t.closed_arg.split(":")),e.chatClosed()))}catch(o){e.userTimeout=setTimeout(chatsyncuser,confLH.chat_message_sinterval)}e.syncroRequestSend=!1},this.parseCloseArgs=function(e){var t=e.length/2;for(i=0;i ul > #chat-tab-li-"+t).index();e.find("> ul > #chat-tab-li-"+t).remove(),e.find("#chat-id-"+t).remove();var i=e.find("> ul > li:eq("+(s-1)+")");if(void 0!==i.attr("id"))var a=i.find("> a");else if(linkTabRight=e.find("> ul > li:eq("+s+")"),linkTabRight.size()>0)var a=linkTabRight.find("> a");else var a=i.find("> a");if(!e.find("> ul > li.active").length&&(a.tab("show"),void 0!==a.attr("id"))){var n=a.attr("href").replace("#chat-id-","");this.removeBackgroundChat(n),this.hideNotification(n),ee.emitEvent("chatTabFocused",[n])}return a.attr("href").replace("#","#/")},this.startChatCloseTabNewWindow=function(e,t,s){return window.open(this.wwwDir+"chat/single/"+e,"chatwindow-chat-id-"+e,"menubar=1,resizable=1,width=800,height=650"),this.smartTabFocus(t,e),1==this.closeWindowOnChatCloseDelete&&window.close(),this.removeSynchroChat(e),this.syncadmininterfacestatic(),!1},this.removeDialogTab=function(e,t,s){if(0!=$("#CSChatMessage-"+e).length&&($("#CSChatMessage-"+e).unbind("keydown",function(){}),$("#CSChatMessage-"+e).unbind("keyup",function(){})),this.removeSynchroChat(e),1==s){var i=this.smartTabFocus(t,e);setTimeout(function(){window.location.hash=i},500),1==this.closeWindowOnChatCloseDelete&&window.close()}this.syncadmininterfacestatic()},this.removeActiveDialogTag=function(e){1==this.closeWindowOnChatCloseDelete&&window.close()},this.deleteChat=function(e,t,s){if(confirm(confLH.transLation.delete_confirm)){var i=this;$.postJSON(this.wwwDir+this.deletechatadmin+e,function(a){if(1==a.error)alert(a.result);else{if(0!=$("#CSChatMessage-"+e).length&&($("#CSChatMessage-"+e).unbind("keydown",function(){}),$("#CSChatMessage-"+e).unbind("keyup",function(){})),1==s){var n=i.smartTabFocus(t,e);setTimeout(function(){window.location.hash=n},500),1==i.closeWindowOnChatCloseDelete&&window.close()}LHCCallbacks.chatDeletedCallback&&LHCCallbacks.chatDeletedCallback(e),i.syncadmininterfacestatic(),i.removeSynchroChat(e)}}).fail(function(e,t,s){console.dir(e),alert("getJSON request failed! "+t+":"+s+":"+e.responseText)})}},this.rejectPendingChat=function(e,t){var s=this;$.postJSON(this.wwwDir+this.deletechatadmin+e,{},function(e){s.syncadmininterfacestatic()}).fail(function(e,t,s){console.dir(e),alert("getJSON request failed! "+t+":"+s+":"+e.responseText)})},this.startChatNewWindow=function(e,t){window.open(this.wwwDir+"chat/single/"+e,"chatwindow-chat-id-"+e,"menubar=1,resizable=1,width=800,height=650").focus();var s=this;setTimeout(function(){s.syncadmininterfacestatic()},1e3),ee.emitEvent("chatStartOpenWindow",[e])},this.startChatNewWindowArchive=function(e,t,s){window.open(this.wwwDir+"chatarchive/viewarchivedchat/"+e+"/"+t+"/(mode)/popup","chatwindow-chat-id-"+t,"menubar=1,resizable=1,width=800,height=650").focus(),ee.emitEvent("chatStartOpenWindowArchive",[e,t])},this.startCoBrowse=function(e){return window.open(this.wwwDir+"cobrowse/browse/"+e,"chatwindow-cobrowse-chat-id-"+e,"menubar=1,resizable=1,width=800,height=650").focus(),!1},this.speechToText=function(e){0==this.speechHandler&&(this.speechHandler=new LHCSpeechToText),this.speechHandler.listen({chat_id:e})},this.startChatTransfer=function(e,t,s,i){var a=this;$.getJSON(this.wwwDir+this.accepttransfer+i,{},function(i){a.startChat(e,t,s),LHCCallbacks.operatorAcceptedTransfer&&LHCCallbacks.operatorAcceptedTransfer(e)}).fail(function(){a.startChat(e,t,s)})},this.startChatNewWindowTransfer=function(e,t,s){return $.getJSON(this.wwwDir+this.accepttransfer+s,{},function(t){LHCCallbacks.operatorAcceptedTransfer&&LHCCallbacks.operatorAcceptedTransfer(e)}),this.startChatNewWindow(e,t)},this.startChatNewWindowTransferByTransfer=function(e,t){var s=this;return $.ajax({type:"GET",url:this.wwwDir+this.accepttransfer+e+"/(mode)/chat",cache:!1,dataType:"json"}).done(function(e){$("#tabs").size()>0?(window.focus(),s.startChat(e.chat_id,$("#tabs"),t)):s.startChatNewWindow(e.chat_id,""),LHCCallbacks.operatorAcceptedTransfer&&LHCCallbacks.operatorAcceptedTransfer(e.chat_id)}),this.syncadmininterfacestatic(),!1},this.blockUser=function(e,t){("undefined"==typeof t||confirm(t))&&$.postJSON(this.wwwDir+"chat/blockuser/"+e,{},function(e){alert(e.msg)})},this.switchLang=function(e,t){var s='';return e.append(s),e.submit(),!1},this.sendLinkToMail=function(e,t){var s=window.parent.$("#MailMessage").val();window.parent.$("#MailMessage").val((""!=s?s+"\n":s)+e),$("#embed-button-"+t).addClass("success")},this.sendLinkToEditor=function(e,t,s){var i=window.parent.$("#CSChatMessage-"+e).val();window.parent.$("#CSChatMessage-"+e).val((""!=i?i+"\n":i)+t),$("#embed-button-"+s).addClass("success")},this.hideTransferModal=function(e){var t=this;setTimeout(function(){$("#myModal").modal("hide"),$("#tabs").size()>0&&t.removeDialogTab(e,$("#tabs"),!0)},1e3)},this.transferChat=function(e){var t=this,s=$("[name=TransferTo"+e+"]:checked").val();$.postJSON(this.wwwDir+this.trasnsferuser+e+"/"+s,{type:"user"},function(s){"false"==s.error&&($("#transfer-block-"+s.chat_id).html(s.result),t.hideTransferModal(e))})},this.changeOwner=function(e){var t=this,s=$("#id_new_user_id").val();$.postJSON(this.wwwDir+this.trasnsferuser+e+"/"+s,{type:"change_owner"},function(s){"false"==s.error&&($("#transfer-block-"+s.chat_id).html(s.result),t.hideTransferModal(e))})},this.chooseSurvey=function(e){var t=$("[name=SurveyItem"+e+"]:checked").val();$.postJSON(this.wwwDir+"survey/choosesurvey/"+e+"/"+t,function(e){"false"==e.error&&$("#survey-block-"+e.chat_id).html(e.result)})},this.redirectContact=function(e,t){("undefined"==typeof t||confirm(t))&&$.postJSON(this.wwwDir+"chat/redirectcontact/"+e,function(t){lhinst.syncadmininterfacestatic(),LHCCallbacks.userRedirectedContact&&LHCCallbacks.userRedirectedContact(e)})},this.redirectToURL=function(e,t){var s=prompt(t,"");null!=s&&lhinst.addRemoteCommand(e,"lhc_chat_redirect:"+s.replace(new RegExp(":","g"),"__SPLIT__"))},this.redirectToURLOnline=function(e,t){var s=prompt(t,"");null!=s&&(lhinst.addRemoteOnlineCommand(e,"lhc_chat_redirect:"+s.replace(new RegExp(":","g"),"__SPLIT__")),lhinst.addExecutionCommand(e,"lhc_cobrowse_multi_command__lhc_chat_redirect:"+s.replace(new RegExp(":","g"),"__SPLIT__")))},this.transferChatDep=function(e){var t=this,s=$("[name=DepartamentID"+e+"]:checked").val();$.postJSON(this.wwwDir+this.trasnsferuser+e+"/"+s,{type:"dep"},function(s){"false"==s.error&&($("#transfer-block-"+s.chat_id).html(s.result),t.hideTransferModal(e))})},this.chatTabsOpen=function(){return window.open(this.wwwDir+"chat/chattabs/","chatwindows","menubar=1,resizable=1,width=800,height=650"),!1},this.userclosedchat=function(){LHCCallbacks.userleftchatNotification&&LHCCallbacks.userleftchatNotification(this.chat_id),$.ajax({type:"GET",url:this.wwwDir+this.userclosechaturl+this.chat_id+"/"+this.hash,cache:!1})},this.userclosedchatembed=function(){window.postMessage&&"undefined"!=typeof parent&&window.location!==window.parent.location?parent.postMessage("lhc_chat_closed_explicit","*"):0==this.chatClosed()&&window.close()},this.continueChatFromSurvey=function(e){return this.isWidgetMode&&"undefined"!=typeof parent&&window.location!==window.parent.location?$.postJSON(this.wwwDir+"survey/backtochat/"+this.chat_id+"/"+this.hash+"/"+e,function(e){parent.postMessage("lhc_continue_chat","*")}):this.chatClosed(),!1},this.explicitClose=!1,this.explicitChatCloseByUser=function(){return this.explicitClose=!0,this.isWidgetMode&&"undefined"!=typeof parent&&window.location!==window.parent.location?parent.postMessage("lhc_chat_closed_explicit","*"):0==this.chatClosed()&&window.close(),!1},this.restoreWidget=function(e){window.postMessage&&window.opener&&(window.opener.postMessage("lhc_ch:hash:"+e,"*"),window.opener.postMessage("lhc_ch:hash_resume:"+e,"*"),window.opener.postMessage("lhc_open_restore","*"),window.close())},this.userclosedchatandbrowser=function(){LHCCallbacks.userleftchatNotification&&LHCCallbacks.userleftchatNotification(this.chat_id),$.get(this.wwwDir+this.userclosechaturl+this.chat_id+"/"+this.hash+"/(eclose)/t",function(e){lhinst.closeWindow()})},this.sendCannedMessage=function(e,t){if($("#id_CannedMessage-"+e).val()>0){t.addClass("secondary");var s=1e3*parseInt($("#id_CannedMessage-"+e).find(":selected").attr("data-delay")),i=this.wwwDir,a=this;if(0==a.is_typing?(a.is_typing=!0,clearTimeout(a.typing_timeout),LHCCallbacks.initTypingMonitoringAdminInform&&LHCCallbacks.initTypingMonitoringAdminInform({chat_id:e,status:!0}),$.getJSON(i+"chat/operatortyping/"+e+"/true",{},function(i){LHCCallbacks.initTypingMonitoringAdmin&&LHCCallbacks.initTypingMonitoringAdmin(e,!0),a.typing_timeout=setTimeout(function(){a.typingStoppedOperator(e),t.removeClass("secondary")},s>3e3?s:3e3)}).fail(function(){a.typing_timeout=setTimeout(function(){a.typingStoppedOperator(e)},3e3)})):(clearTimeout(a.typing_timeout),a.typing_timeout=setTimeout(function(){a.typingStoppedOperator(e)},3e3),t.removeClass("secondary")),s>0)setTimeout(function(){var t={msg:$("#id_CannedMessage-"+e).find(":selected").attr("data-msg")};$("#CSChatMessage-"+e).val(""),$.postJSON(i+a.addmsgurl+e,t,function(t){return LHCCallbacks.addmsgadmin&&LHCCallbacks.addmsgadmin(e),ee.emitEvent("chatAddMsgAdmin",[e]),lhinst.syncadmincall(),!0})},s);else{var n={msg:$("#id_CannedMessage-"+e).find(":selected").attr("data-msg")};$("#CSChatMessage-"+e).val(""),$.postJSON(this.wwwDir+this.addmsgurl+e,n,function(t){return LHCCallbacks.addmsgadmin&&LHCCallbacks.addmsgadmin(e),ee.emitEvent("chatAddMsgAdmin",[e]),lhinst.syncadmincall(),!0})}}return!1},this.voteAction=function(e){var t=this.chat_id;$.postJSON(this.wwwDir+"chat/voteaction/"+this.chat_id+"/"+this.hash+"/"+e.attr("data-id"),{},function(e){"false"==e.error&&(LHCCallbacks.uservoted&&LHCCallbacks.uservoted(t),0==e.status?($(".up-vote-action").removeClass("up-voted"),$(".down-vote-action").removeClass("down-voted")):1==e.status?($(".up-vote-action").addClass("up-voted"),$(".down-vote-action").removeClass("down-voted")):2==e.status&&($(".up-vote-action").removeClass("up-voted"),$(".down-vote-action").addClass("down-voted")))})},this.theme=null,this.chatsyncuserpending=function(){var e=1==this.isWidgetMode?"/(mode)/widget":"",t=null!==this.theme?"/(theme)/"+this.theme:"",s=this;$.getJSON(this.wwwDir+this.checkchatstatus+this.chat_id+"/"+this.hash+e+t,{},function(e){ee.emitEvent("checkChatStatus",[s.chat_id,e]),"false"==e.error&&("false"==e.activated?("false"!=e.result&&$("#status-chat").html(e.result),""!=e.ru&&document.location.replace(e.ru),setTimeout(chatsyncuserpending,confLH.chat_message_sinterval)):($("#status-chat").html(e.result),e.closed&&1==e.closed&&(ee.emitEvent("chatClosedCheckStatus",[s.chat_id]),s.isWidgetMode&&"undefined"!=typeof parent&&window.location!==window.parent.location?parent.postMessage("lhc_chat_closed","*"):s.chatClosed())))}).fail(function(){setTimeout(chatsyncuserpending,confLH.chat_message_sinterval)})},this.setTheme=function(e){this.theme=e},this.survey=null,this.setSurvey=function(e){this.survey=e},this.isBlinking=!1,this.startBlinking=function(){if(0==this.isBlinking){var e=this,t=function(){var t,s=document.title,i="!!! "+document.title,a=function(){document.title=document.title==i?" ":i},n=function(){clearInterval(t),document.title=s,window.onmousemove=null,t=null,e.isBlinking=!1};return function(){t||(t=setInterval(a,1e3),window.onmousemove=n)}}();t(),this.isBlinking=!0}},this.playNewMessageSound=function(){Modernizr.audio&&(this.audio.src=Modernizr.audio.ogg?WWW_DIR_JAVASCRIPT_FILES+"/new_message.ogg":Modernizr.audio.mp3?WWW_DIR_JAVASCRIPT_FILES+"/new_message.mp3":WWW_DIR_JAVASCRIPT_FILES+"/new_message.wav",this.audio.load()),$("textarea[name=ChatMessage]").is(":focus")||this.startBlinking(); -},this.playInvitationSound=function(){Modernizr.audio&&(this.audio.src=Modernizr.audio.ogg?WWW_DIR_JAVASCRIPT_FILES+"/invitation.ogg":Modernizr.audio.mp3?WWW_DIR_JAVASCRIPT_FILES+"/invitation.mp3":WWW_DIR_JAVASCRIPT_FILES+"/invitation.wav",this.audio.load())},this.playPreloadSound=function(){Modernizr.audio&&(this.audio.src=Modernizr.audio.ogg?WWW_DIR_JAVASCRIPT_FILES+"/silence.ogg":Modernizr.audio.mp3?WWW_DIR_JAVASCRIPT_FILES+"/silence.mp3":WWW_DIR_JAVASCRIPT_FILES+"/silence.wav",this.audio.load())},this.loadPreviousMessages=function(e){$.getJSON(this.wwwDir+"chat/loadpreviousmessages/"+e.attr("chat-id")+"/"+e.attr("message-id")+"/(initial)/"+e.attr("data-initial"),function(t){if(0==t.error){e.attr("data-initial",0);var s=$("#messagesBlock-"+e.attr("chat-original-id"));s.prepend(t.result),1==e.attr("auto-scroll")&&(e.attr("auto-scroll",0),s.stop(!0,!1).animate({scrollTop:s.prop("scrollHeight")},500)),1==t.has_messages?(e.attr("message-id",t.message_id),e.attr("chat-id",t.chat_id)):e.remove()}})},this.hidenicknamesstatus=null,this.syncadmincall=function(){this.chatsSynchronising.length>0?0==this.underMessageAdd&&0==this.syncroRequestSend?(this.syncroRequestSend=!0,clearTimeout(this.userTimeout),$.postJSON(this.wwwDir+this.syncadmin,{"chats[]":this.chatsSynchronisingMsg},function(data){"undefined"!=typeof data.error_url&&document.location.replace(data.error_url);try{if("false"==data.error){if("false"!=data.result){var playSound=!1;$.each(data.result,function(e,t){var s=$("#messagesBlock-"+t.chat_id),i=s.prop("scrollHeight"),a=Math.abs(i-s.prop("scrollTop")-s.prop("clientHeight"));s.find(".pending-storage").remove(),s.append(t.content),lhinst.addQuateHandler(t.chat_id),a<20&&s.stop(!0,!1).animate({scrollTop:i},500),lhinst.updateChatLastMessageID(t.chat_id,t.message_id);var n=$("#chat-tab-link-"+t.chat_id);if(!n.parent().hasClass("active"))if(n.find("span.msg-nm").length>0){var o=parseInt(n.find("span.msg-nm").attr("rel"))+t.mn;n.find("span.msg-nm").html(" ("+o+")").attr("rel",o)}else n.append(' ('+t.mn+")"),n.addClass("has-pm");0!=playSound||"false"!=data.uw||"undefined"!=typeof t.ignore&&typeof t.ignore!==!1||(playSound=!0),1!=confLH.new_message_browser_notification||"false"!=data.uw||"undefined"!=typeof t.ignore&&typeof t.ignore!==!1||lhinst.showNewMessageNotification(t.chat_id,t.msg,t.nck),t.msfrom>0&&$("#msg-"+t.msfrom).attr("data-op-id")!=t.msop&&$("#msg-"+t.msfrom).next().addClass("operator-changes"),ee.emitEvent("eventSyncAdmin",[t,e])}),1==confLH.new_message_sound_admin_enabled&&"false"==data.uw&&1==playSound&&lhinst.playNewMessageSound()}if("false"!=data.result_status){var groupTabs=$("#group-chats-status").hasClass("chat-active");$.each(data.result_status,function(i,item){"true"==item.tp?$("#user-is-typing-"+item.chat_id).html(item.tx).css("visibility","visible"):$("#user-is-typing-"+item.chat_id).css("visibility","hidden"),$("#last-msg-chat-"+item.chat_id).text(item.lmsg);var userChatStatus=$("#user-chat-status-"+item.chat_id),wasOnline=userChatStatus.hasClass("icon-user-online");$("#chat-duration-"+item.chat_id).text(item.cdur),userChatStatus.removeClass("icon-user-online icon-user-away icon-user-pageview"),$("#msg-send-status-"+item.chat_id).removeClass("icon-user-online icon-user-offline"),0==item.us?userChatStatus.addClass("icon-user-online"):2==item.us?userChatStatus.addClass("icon-user-away"):3==item.us&&userChatStatus.addClass("icon-user-pageview"),1==groupTabs?1==wasOnline&&0!=item.us||lhinst.hidenicknamesstatus!=groupTabs&&0!=item.us?$("#ntab-chat-"+item.chat_id).hide():(0==wasOnline&&0==item.us||lhinst.hidenicknamesstatus!=groupTabs&&0==item.us)&&$("#ntab-chat-"+item.chat_id).show():lhinst.hidenicknamesstatus!=groupTabs&&$("#ntab-chat-"+item.chat_id).show();var statusel=$("#chat-id-"+item.chat_id+"-mds");statusel.attr("data-chat-status")==item.cs&&statusel.attr("data-chat-user")==item.co||lhinst.updateVoteStatus(item.chat_id),1==item.um?(statusel.removeClass("chat-active"),statusel.addClass("chat-unread"),$("#msg-send-status-"+item.chat_id).addClass("icon-user-offline")):($("#msg-send-status-"+item.chat_id).addClass("icon-user-online"),statusel.removeClass("chat-unread"),statusel.addClass("chat-active")),item.lp!==!1?statusel.attr("title",item.lp+" s."):statusel.attr("title",""),"undefined"!=typeof item.oad&&eval(item.oad)})}lhinst.hidenicknamesstatus=groupTabs,lhinst.userTimeout=setTimeout(chatsyncadmin,confLH.chat_message_sinterval)}}catch(err){lhinst.userTimeout=setTimeout(chatsyncadmin,confLH.chat_message_sinterval)}lhinst.setSynchronizationRequestSend(!1),LHCCallbacks.syncadmincall&&LHCCallbacks.syncadmincall(lhinst,data)}).fail(function(){lhinst.userTimeout=setTimeout(chatsyncadmin,confLH.chat_message_sinterval),lhinst.setSynchronizationRequestSend(!1)})):lhinst.userTimeout=setTimeout(chatsyncadmin,confLH.chat_message_sinterval):this.isSinchronizing=!1},this.updateVoteStatus=function(e){$.getJSON(this.wwwDir+"chat/updatechatstatus/"+e,{},function(t){$("#main-user-info-tab-"+e).html(t.result),ee.emitEvent("chatTabInfoReload",[e])})},this.updateChatLastMessageID=function(e,t){this.chatsSynchronisingMsg[this.getChatIndex(e)]=e+","+t},this.requestNotificationPermission=function(){window.webkitNotifications?window.webkitNotifications.requestPermission():window.Notification?Notification.requestPermission(function(e){}):alert("Notification API in your browser is not supported.")},this.playNewChatAudio=function(){if(clearTimeout(this.soundIsPlaying),this.soundPlayedTimes++,Modernizr.audio&&(this.audio.src=Modernizr.audio.ogg?WWW_DIR_JAVASCRIPT_FILES+"/new_chat.ogg":Modernizr.audio.mp3?WWW_DIR_JAVASCRIPT_FILES+"/new_chat.mp3":WWW_DIR_JAVASCRIPT_FILES+"/new_chat.wav",this.audio.load(),confLH.repeat_sound>this.soundPlayedTimes)){var e=this;this.soundIsPlaying=setTimeout(function(){e.playNewChatAudio()},1e3*confLH.repeat_sound_delay)}},this.focusChanged=function(e){if(1==confLH.new_message_browser_notification&&1==e&&(window.webkitNotifications||window.Notification)){var t=this;$.each(this.chatsSynchronising,function(e,s){"undefined"!=typeof t.notificationsArrayMessages[s]&&(window.webkitNotifications?t.notificationsArrayMessages[s].cancel():t.notificationsArrayMessages[s].close(),delete t.notificationsArrayMessages[s])})}parseInt(this.chat_id)>0&&this.scheduleSync()},this.notificationsArrayMessages=[],this.showNewMessageNotification=function(e,t,s){try{if(window.Notification&&0==focused&&"granted"==window.Notification.permission){"undefined"!=typeof this.notificationsArrayMessages[e]&&(this.notificationsArrayMessages[e].close(),delete this.notificationsArrayMessages[e]);var i=new Notification(s,{icon:WWW_DIR_JAVASCRIPT_FILES_NOTIFICATION+"/notification.png",body:t}),a=this;i.onclick=function(){window.focus(),i.close(),delete a.notificationsArrayMessages[e]},i.onclose=function(){"undefined"!=typeof a.notificationsArrayMessages[e]&&delete a.notificationsArrayMessages[e]},this.notificationsArrayMessages[e]=i,this.scheduleNewMessageClose(i,e)}}catch(n){console.log(n)}},this.scheduleNewMessageClose=function(e,t){var s=this;setTimeout(function(){window.webkitNotifications?e.cancel():e.close(),"undefined"!=typeof s.notificationsArrayMessages[t]&&delete s.notificationsArrayMessages[t]},1e4)},this.playSoundNewAction=function(e,t,s,i,a){if(this.backgroundChats.indexOf(parseInt(t))==-1){1!=confLH.new_chat_sound_enabled||1!=confLH.sn_off&&"flash_on"!=$("#online-offline-user").text()||"pending_chat"!=e&&"transfer_chat"!=e&&"unread_chat"!=e&&"pending_transfered"!=e||(this.soundPlayedTimes=0,this.playNewChatAudio()),$("textarea[name=ChatMessage]").is(":focus")||1!=confLH.sn_off&&"flash_on"!=$("#online-offline-user").text()||"pending_chat"!=e&&"transfer_chat"!=e&&"unread_chat"!=e&&"pending_transfered"!=e||this.startBlinking();var n=this;if(("pending_chat"==e||"transfer_chat"==e||"unread_chat"==e||"pending_transfered"==e)&&(1==confLH.sn_off||"flash_on"==$("#online-offline-user").text())&&window.Notification&&"granted"==window.Notification.permission){var o=new Notification(s,{icon:WWW_DIR_JAVASCRIPT_FILES_NOTIFICATION+"/notification.png",body:i,requireInteraction:!0});o.onclick=function(){"pending_chat"==e||"unread_chat"==e||"pending_transfered"==e?$("#tabs").size()>0?(window.focus(),n.startChat(t,$("#tabs"),a)):n.startChatNewWindow(t,"ChatRequest"):n.startChatNewWindowTransferByTransfer(t,a),o.close()},"pending_transfered"!=e&&("undefined"!==this.notificationsArray[t]&&o.close(),this.notificationsArray[t]=o)}"transfer_chat"==e&&1==confLH.show_alert_transfer&&confirm(confLH.transLation.transfered+"\n\n"+i)&&n.startChatNewWindowTransferByTransfer(t,a),1==confLH.show_alert&&confirm(confLH.transLation.new_chat+"\n\n"+i)&&("pending_chat"==e||"unread_chat"==e||"pending_transfered"==e?$("#tabs").size()>0?(window.focus(),n.startChat(t,$("#tabs"),a)):n.startChatNewWindow(t,"ChatRequest"):n.startChatNewWindowTransferByTransfer(t,a))}},this.syncadmininterfacestatic=function(){try{var e=angular.element("body").scope();e.loadChatList()}catch(t){}},this.addingUserMessage=!1,this.addUserMessageQueue=[],this.addDelayedTimeout=null,this.addmsgadmin=function(e){var t=$("#CSChatMessage-"+e);if(!t.is("[readonly]")){var s={msg:t.val()};if(this.speechHandler!==!1&&this.speechHandler.messageSend(),t.val(""),t.hasClass("edit-mode"))s.msgid=t.attr("data-msgid"),$.postJSON(this.wwwDir+"chat/updatemsg/"+e,s,function(i){if("f"==i.error)return t.removeClass("edit-mode"),t.removeAttr("data-msgid"),$("#msg-"+s.msgid).replaceWith(i.msg),LHCCallbacks.addmsgadmin&&LHCCallbacks.addmsgadmin(e),ee.emitEvent("chatAddMsgAdmin",[e]),!0});else{var i=this,a=$("#messagesBlock-"+e);jQuery("
",{"class":"message-row pending-storage",text:s.msg}).appendTo(a),a.stop(!0,!1).animate({scrollTop:a.prop("scrollHeight")},500),0==this.addingUserMessage&&0==this.addUserMessageQueue.length?(this.addingUserMessage=!0,$.postJSON(this.wwwDir+this.addmsgurl+e,s,function(t){return LHCCallbacks.addmsgadmin&&LHCCallbacks.addmsgadmin(e),ee.emitEvent("chatAddMsgAdmin",[e]),""!=t.r&&($("#messagesBlock-"+e).append(t.r),$("#messagesBlock-"+e).stop(!0,!1).animate({scrollTop:$("#messagesBlock-"+e).prop("scrollHeight")},500)),t.hold_removed===!0?$("#hold-action-"+e).removeClass("btn-info"):t.hold_added===!0&&$("#hold-action-"+e).addClass("btn-info"),lhinst.syncadmincall(),i.addingUserMessage=!1,!0}).fail(function(t){var a='