Built motion from commit (unavailable).|2.5.30
[motion2.git] / snippet / 3.0.0 / scripts / chat-30c3a00b.js
1 (self.webpackChunkmotion_chat=self.webpackChunkmotion_chat||[]).push([["chat-30c3a00b"],{"./src/js/index.module.js":(e,t,n)=>{"use strict";n("./node_modules/angular-animate/index.js"),n("./node_modules/angular-aria/index.js"),n("./node_modules/angular-messages/index.js"),n("./node_modules/angular-material/index.js"),n("./node_modules/angular-resource/index.js"),n("./node_modules/angular-sanitize/index.js"),n("./node_modules/ng-csv/build/ng-csv.min.js"),n("./node_modules/ng-embed/src/ng-embed.js"),n("./node_modules/@uirouter/angularjs/lib-esm/index.js"),n("./node_modules/angular-local-storage/index.js"),n("./node_modules/angular-rateit/dist/ng-rateit.js"),n("./node_modules/@flowjs/ng-flow/dist/ng-flow.js"),n("./node_modules/emojionearea/dist/emojionearea.js"),n("./node_modules/jquery-textcomplete/dist/jquery.textcomplete.js");var o=n("./node_modules/moment/moment.js"),i=n.n(o),s=n("./node_modules/lodash.map/index.js"),r=n.n(s);function a(e,t,n,o,s,a,l,c,d){const u=this;function m(){let e;const t=Math.max(document.body.clientHeight,window.innerHeight||0),n=t/100*0+450;return e=t<n?450-(n-t):450,e}function p(e){e>240?(null!==document.getElementById("chat-app")&&(document.getElementById("chat-app").style.height=e+"px"),null!==document.getElementById("chatContent1")&&(document.getElementById("chatContent1").style.height=e-108+"px"),null!==document.getElementById("id-row")&&(document.getElementById("id-row").style.height=e-52+"px"),null!==document.getElementById("chat-app")&&(document.getElementById("chat-app").style.top="0%")):(null!==document.getElementById("chat-app")&&(document.getElementById("chat-app").style.height="190px"),null!==document.getElementById("chatContent1")&&(document.getElementById("chatContent1").style.height="134px"),null!==document.getElementById("id-row")&&(document.getElementById("id-row").style.height="190px"),null!==document.getElementById("chat-app")&&(document.getElementById("chat-app").style.top="calc(100% - 240px)"))}function f(t,n,o){const i=a.get(t)||{};o?delete i[e.location]:i[e.location]=n,a.set(t,i)}function g(n){var o;e.layout.up=n,f(c,e.layout),o=n?"show":"hide",t.parent.postMessage({cmd:o},"*"),e.$$phase||e.$apply()}e.location=e.settings.location,u.$onInit=function(){e.status="init";const o=e.settings.color,i=e.settings.textColor,s=Math.max(document.documentElement.clientHeight,window.innerHeight||0),r=document.documentElement.clientWidth;document.documentElement.style.setProperty("--xc-ws-div-color",o),document.documentElement.style.setProperty("--xc-ws-text-color",i),document.documentElement.style.setProperty("--xc-ws-client-height",s),document.documentElement.style.setProperty("--xc-ws-client-width",r);let l=!1;const u=a.get(d)||{},f=a.get(c)||{};e.visitor=u[e.location]?u[e.location]:{},e.layout=f[e.location]?f[e.location]:{},e.visitor.interaction&&e.layout.up?l=!0:e.layout.up=!0,"bottom_right"===e.settings.alignment&&g(l),n.go(function(){const t=e.settings.online,n=!!(e.visitor&&e.visitor.interaction&&e.visitor.interaction.id),o=Number(e.settings.maxInteractions)&&Number(e.settings.openedInteractions)>=Number(e.settings.maxInteractions);return!!(n||!o&&t)}()?"app.online":"app.offline",null,{location:"replace"});let h="";h=e.settings.online||!e.settings.hideWhenOffline?"init":"offline",t.parent.postMessage({cmd:h,div_color:o,text_color:i,client_height:s,client_width:r},"*");const y=document.createElement("style");document.head.appendChild(y),y.sheet.insertRule(".mdi-send:before {color:"+e.settings.color+"!important}"),window.visualViewport&&window.visualViewport.addEventListener("resize",(function(){document.getElementById("chatContent1")&&p(m())}))},u.close=function(){const t=e.visitor.interaction;if(t&&t.id){const s=o.confirm().parent(angular.element(document.querySelector("#chat-app"))).clickOutsideToClose(!0).title(e.settings.closingQuestion||"Do you want to close the interaction?").ok("Ok").cancel("Cancel");o.show(s).then((function(){return l.chatInteraction.customUpdate({id:t.id,closed:!0,closeReason:"contact",closedAt:i()().format("YYYY-MM-DD HH:mm:ss")}).$promise})).then((function(){n.go("app.closing",null,{location:"replace"})})).catch((function(e){console.error("keep open",e)}))}},u.toggle=g,u.download=function(){const t=s.defer(),n=e.visitor.interaction;return n&&n.id&&l.chatInteraction.getMessages({intid:n.id,includeAll:!0}).$promise.then((function(n){t.resolve(r()(n.rows.slice(1),(function(t){let n;if("in"===t.direction&&(n=e.settings.customerAlias||e.visitor.from||"Visitor"+t.ContactId),"out"===t.direction)switch(e.settings.agentIdentifier){case"website_alias":n=t.UserId?e.settings.agentAlias+t.UserId:"System";break;case"agent_alias":n=t.UserId?t.User.alias||t.User.fullname:"System";break;case"agent_fullname":n=t.UserId?t.User.fullname:"System";break;default:n=t.UserId?e.settings.agentAlias+t.UserId:"System"}return{sender:n,message:t.body,createdAt:i()(t.createdAt).format("MM/DD/YYYY HH:mm:ss")}})))})).catch((function(e){console.error(e)})),t.promise},u.getHeaderShape=function(){return"rounded"===e.settings.header_shape?"15px":"0px"},e.updateStorage=f,window.addEventListener("message",(function(e){"show"===e.data.evt?g(!0):"hide"===e.data.evt&&g(!1)}),!1),window.addEventListener("resize",(function(){document.getElementById("chatContent1")&&document.getElementById("chat-app")&&document.getElementById("id-row")&&p(m())})),window.visualViewport&&window.visualViewport.addEventListener("resize",(function(){document.getElementById("chatContent1")&&document.getElementById("chat-app")&&document.getElementById("id-row")&&p(m())}))}a.$inject=["$rootScope","$window","$state","$mdDialog","$q","localStorageService","api","STORAGE_LAYOUT","STORAGE_VISITOR"];var l=n("./node_modules/lodash.forin/index.js"),c=n.n(l),d=n("./node_modules/lodash.isnil/index.js"),u=n.n(d);const m=n.p+"templates/chat/index.tpl.html/index.tpl.html",p=n.p+"templates/closing/index.tpl.html/index.tpl.html",f=n.p+"templates/offline/index.tpl.html/index.tpl.html",g=n.p+"templates/online/index.tpl.html/index.tpl.html",h=n.p+"templates/unmanaged/index.tpl.html/index.tpl.html",y=n.p+"templates/waiting/index.tpl.html/index.tpl.html";function v(e,t){const n=t.search();e.settings={cursor:"pointer",hide:!0},c()(n,(function(t,n){""===t||u()(t)||("true"===t&&(t=!0),"false"===t&&(t=!1),e.settings[n]=t)}))}function b(e,t,n,o,i,s){n.html5Mode(!0),o.defaults.headers.get||(o.defaults.headers.get={}),o.defaults.headers.get["If-Modified-Since"]="Mon, 26 Jul 1997 05:00:00 GMT",o.defaults.headers.get["Cache-Control"]="no-cache",o.defaults.headers.get.Pragma="no-cache",i.setPrefix(s),e.state("app",{abstract:!0}).state("app.waiting",{url:"/waiting",templateUrl:y,controller:"WaitingController as vm"}).state("app.online",{url:"/online",templateUrl:g,controller:"OnlineController as vm"}).state("app.offline",{url:"/offline",templateUrl:f,controller:"OfflineController as vm"}).state("app.chat",{url:"/chat",templateUrl:m,controller:"ChatController as vm"}).state("app.unmanaged",{url:"/unmanaged",templateUrl:h,controller:"UnmanagedController as vm"}).state("app.closing",{url:"/closing",templateUrl:p,controller:"ClosingController as vm"})}b.$inject=["$stateProvider","$urlRouterProvider","$locationProvider","$httpProvider","localStorageServiceProvider","STORAGE_PREFIX"],v.$inject=["$rootScope","$location"];var w=n("./node_modules/lodash.merge/index.js"),I=n.n(w);function $(e,t,n,o,i,s){const r=this;function a(t){return function(o){r.errors[t]=o.data;const i=n.simple().textContent(e.settings.formSubmitFailureMessage||"Form submission error").toastClass("md-failure-toast").position("top");n.show(i)}}function l(){e.loading=!1}function c(){e.settings.online?t.go("app.online",null,{location:"replace"}):t.go("app.offline",null,{location:"replace"})}function d(){r.form={},r.upColor=null,r.downColor=null,r.userForm.$setPristine(),r.userForm.$setUntouched(),delete e.visitor.interaction,e.enableDownload=!1}r.$onInit=function(){e.status="closing",e.updateStorage(i,null,!0),e.updateStorage(s,null,!0),e.loading=!1},r.submit=function(){e.loading=!0,e.visitor.interaction&&e.visitor.interaction.id?o.chatInteraction.close(I()({id:e.visitor.interaction.id,ratingType:e.settings.ratingType,customer:e.settings.customerAlias||e.visitor.from},r.form)).$promise.then((function(){delete r.errors.submit;const t=n.simple().textContent(e.settings.formSubmitSuccessMessage||"Form properly submitted").toastClass("md-success-toast").parent(angular.element(document.querySelector("#chat-toolbar")));n.show(t)})).then(d).then(c).catch(a("submit")).finally(l):(l(),a("submit"))},r.skip=function(){d(),c()},r.form={},r.errors={}}function S(e,t){const n={id:"@id",token:e.settings.token},o={};return o.baseUrl=e.settings.remote+"/api/",o.chatWebsite=t(o.baseUrl+"chat/websites/:id",n,{notify:{method:"POST",url:o.baseUrl+"chat/websites/:id/notify"},offline:{method:"POST",url:o.baseUrl+"chat/websites/:id/offline"},getFields:{method:"GET",url:o.baseUrl+"chat/websites/:id/fields"}}),o.chatInteraction=t(o.baseUrl+"chat/interactions/:id",n,{update:{method:"PUT",url:o.baseUrl+"chat/interactions/:id"},customUpdate:{method:"PUT",url:o.baseUrl+"chat/interactions/:id/custom_update"},close:{method:"PUT",url:o.baseUrl+"chat/interactions/:id/close"},getMessages:{method:"GET",url:o.baseUrl+"chat/interactions/:intid/my_messages"},uploadAttachment:{method:"POST",url:o.baseUrl+"chat/interactions/:id/attachment_upload",headers:{"Content-Type":void 0},transformRequest:angular.identity},downloadAttachment:{method:"GET",url:o.baseUrl+"chat/interactions/:id/attachment_download"}}),o.chatMessage=t(o.baseUrl+"chat/messages/:id",n,{update:{method:"PUT",url:o.baseUrl+"chat/messages/:id"}}),o}$.$inject=["$rootScope","$state","$mdToast","api","STORAGE_VISITOR","STORAGE_LAYOUT"],S.$inject=["$rootScope","$resource"];var x=n("./node_modules/lodash.find/index.js"),j=n.n(x),A=n("./node_modules/lodash.values/index.js"),E=n.n(A),C=n("./node_modules/jquery/dist/jquery.js");function T(e,t,n,o,i,s,r,a,l,c){const d=this;let m,p,f,g;function h(){n((function(){const e=i[0].getElementsByClassName("chat-messages")[0];e&&(e.scrollTop=e.scrollHeight)}))}function y(e){return function(t){d.errors[e]=t.data,h()}}function v(e){a.chatWebsite.notify(e).$promise.then((function(e){delete d.errors.chatMessageError,u()(t.visitor.interaction)&&(t.visitor.interaction={id:e.interaction.id},t.updateStorage(l,t.visitor)),m[0].emojioneArea.setText(""),h()})).catch(y("chatMessageError"))}function b(){t.settings.online?s.go("app.online",null,{location:"replace"}):s.go("app.offline",null,{location:"replace"})}function w(){t.visitor&&t.visitor.interaction&&t.visitor.interaction.id&&a.chatInteraction.get({id:t.visitor.interaction.id}).$promise.then((function(e){delete d.errors.getInteraction,e.closed&&(t.visitor.interaction.closed=!0,t.updateStorage(l,t.visitor),"unmanaged"===e.disposition?s.go("app.unmanaged",null,{location:"replace"}):s.go("app.closing",null,{location:"replace"}))})).catch((function(e){switch(e.status){case 403:s.go("app.closing",null,{location:"replace"});break;case 404:t.updateStorage(l,null,!0),t.updateStorage(c,null,!0),b();break;case 405:s.go("app.unmanaged",null,{location:"replace"});break;default:console.error(e)}}))}function $(e){const n=m[0].emojioneArea.getText();e&&13===e.keyCode&&e.shiftKey||e&&13!==e.keyCode||""!==n&&v(I()({body:n},t.visitor))}function S(){t.visitor&&t.visitor.interaction&&t.visitor.interaction.id&&a.chatInteraction.getMessages({intid:t.visitor.interaction.id,includeAgent:!0,id:g||void 0}).$promise.then((function(e){if(delete d.errors.interaction,e.count){let o=!1,i=0;for(i=0,o=!1;i<e.rows.length;i++){const s=j()(t.messages,{id:e.rows[i].id});s?e.rows[i].read&&(s.read=!0):(o=!0,t.messages.push(e.rows[i])),"out"!==e.rows[i].direction||e.rows[i].read||(n=e.rows[i].id,a.chatMessage.update({id:n,read:!0}).$promise.catch((function(e){console.error(e)})))}o&&h(),e.rows[i-1].read&&(g=e.rows[i-1].id)}var n})).catch((function(e){switch(e.status){case 403:s.go("app.closing",null,{location:"replace"});break;case 405:s.go("app.unmanaged",null,{location:"replace"});break;default:console.error(e)}}))}d.errors={},t.messages=[],d.emojiOptions={watchEmbedData:!1,fontSmiley:!1,emoji:!0,link:!0,linkTarget:"_blank"},d.$onInit=function(){t.status="chat",t.loading=!1,t.settings.showMenu=!0,d.replyMessage="",t.visitor.interaction&&t.visitor.interaction.closed?(t.updateStorage(l,null,!0),t.updateStorage(c,null,!0),b()):(w(),p=o(S,2e3),f=o(w,3e3)),m=C("#emojionearea").emojioneArea({placeholder:t.settings.placeholderMessage||"Type a message",events:{keyup:function(e,t){$(t)},ready:function(){this.setFocus()}}})},d.reply=$,d.reply_button=function(){const e=m[0].emojioneArea.getText();""!==e&&(v(I()({body:e},t.visitor)),m[0].emojioneArea.setFocus())},d.fileAdded=function(e){const n=new FormData;n.append("file",e.file),r.post(t.settings.remote+"/api/chat/interactions/"+t.visitor.interaction.id+"/attachment_upload?token="+t.settings.token,n,{transformRequest:angular.identity,headers:{"Content-Type":void 0}}).then((function(e){(e=e.data).id?(delete d.errors.sendAttachment,v(I()({body:'<a href="'+t.settings.remote+"/api/chat/interactions/"+t.visitor.interaction.id+"/attachment_download?attachId="+e.id+"&token="+t.settings.token+'" target="_blank">'+e.name+"</a>",AttachmentId:e.id},t.visitor))):y("sendAttachment")}),y("sendAttachment"))},e.$on("$destroy",(function(){o.cancel(p),o.cancel(f),p=null,f=null})),t.$on("$download",(function(e,n){n&&n(E()(t.messages))}))}T.$inject=["$scope","$rootScope","$timeout","$interval","$document","$state","$http","api","STORAGE_VISITOR","STORAGE_LAYOUT"];var _=n("./node_modules/lodash.random/index.js"),U=n.n(_),k=n("./node_modules/lodash.clonedeep/index.js"),O=n.n(k),M=n("./node_modules/json-form-data/src/jsonToFormData.js"),F=n.n(M);function R(e,t,n,o,i,s){const r=this;let a=null,l=null;t.typeField="";const c={showLeafArrayIndexes:!0,includeNullValues:!1,mapping:function(e){return"boolean"==typeof e?+e?"1":"0":e}};function d(){delete r.errors.submit,t.$emit("hide"),r.fields=O()(l),r.form={},r.userForm.$setPristine(),r.userForm.$setUntouched();const e=o.simple().textContent(t.settings.formSubmitSuccessMessage||"Form properly submitted").toastClass("md-success-toast").parent(angular.element(document.querySelector("#chat-toolbar")));o.show(e)}r.initUploadButton=function(t){const n=r.fields[t],o=i.find(".upload-item");if(o.length){const t=angular.element(o[0].querySelector(".upload-button")),i=angular.element(o[0].querySelector("input[type=file]")),s=t.find("label");s.length&&s.css("display","none"),t.on("click",(()=>{s.css("display","none"),"function"==typeof i.trigger?i.trigger("click"):i[0].click()})),i.on("change",(t=>{e.$apply((function(){"string"==typeof n.props.error&&(n.props.error=null);const e=Array.from(t.target.files),o=1048576*n.config.size;e.some((e=>e.size>=o))?(n.options=[],n.props.error=n.config.sizeErrMessage):n.options=e.map((e=>{const{name:t,size:n,type:o}=e;return{name:t,size:n,type:o,file:e}})),r.form[n.props.title]=n.options}))}))}},r.removeFileItem=function(e,t){e.options.splice(t,1),r.form[e.props.title]=e.options},r.setupFileInput=function(e){console.log("form item setup",e);const t=i.find(".upload-item"),n=angular.element(t[0].querySelector("input[type=file]")),{multipleUpload:o,accept:s}=e.config;o&&n.attr("multiple","multiple"),s&&n[0].setAttribute("accept",s)},r.makeFileOptionsVisible=function(){const e=Array.from(i.find(".filename-label")),t=e[e.length-1];t&&t.scrollIntoView&&t.scrollIntoView()},r.$onInit=function(){t.status="offline",r.visitor={id:t.settings.id,mapKeyOffline:"firstName",from:"Anonymous"+U()(1,1e6)},t.settings.showMenu=!1,t.loading=!1,n.chatWebsite.getFields({id:t.settings.id,online:!1}).$promise.then((function(e){e.count&&(a=e.fromKey,l=O()(e.rows),r.fields=O()(l))})).then((function(){for(let e=0;e<r.fields.length;e++){const n=r.fields[e];if(t.typeField+=n.type,void 0!==n.props&&n.props.helpText){const t=RegExp.prototype.test.bind(/(<([^>]+)>)/i);r.checkHTML[e]=t(n.props.helpText)}}})).catch((function(e){console.error(e)}))},r.submit=function(){t.loading=!0;const e={...r.form};for(let n=0;n<r.fields.length;n++){const o=r.fields[n];o.props&&void 0!==e[o.props.title]&&(u()(o.cmField)||(r.visitor[o.cmField]=Array.isArray(e[o.props.title])?e[o.props.title].join():e[o.props.title]),n===a&&(u()(t.settings.mapKeyOffline)||(r.visitor.mapKeyOffline=t.settings.mapKeyOffline,r.visitor.from=Array.isArray(e[o.props.title])?e[o.props.title].join():e[o.props.title])),"upload"===o.type&&(e[o.props.title]=e[o.props.title].map((e=>e.file))))}const i=Array.isArray(r.fields)?r.fields.filter((e=>"upload"===e.type)):[],l=I()({body:e},r.visitor),m=null!=e&&i.length>0,p=null!==e&&"{}"!==JSON.stringify(e);var f,g;(m?(f=l,s({url:`${n.baseUrl}chat/websites/${f.id}/offline`,headers:{"Content-Type":void 0},data:F()(f,{...c,initialFormData:new FormData}),method:"POST"})):p?n.chatWebsite.offline(l).$promise:Promise.reject("INVALID_FORM")).then(d).catch((g="submit",function(e){const n=o.simple().textContent(t.settings.formSubmitFailureMessage||"Form submission error").toastClass("md-failure-toast").parent(angular.element(document.querySelector("#chat-toolbar")));o.show(n),r.errors[g]=e.data})).finally((()=>{r.form.invalid||(r.form={}),t.loading=!1}))},r.toggle=function(e,t){r.form[e]||(r.form[e]=[]);const n=r.form[e].indexOf(t);n>-1?r.form[e].splice(n,1):r.form[e].push(t)},r.exists=function(e,t){return r.form[e]||(r.form[e]=[]),r.form[e].indexOf(t)>-1},r.checkHTML=[],r.form={},r.errors={},r.userForm={}}function P(e,t,n,o){const i=this;let s=null;i.checkHTML=[],i.form={},i.errors={},i.userForm={},i.disableItem=!1,i.$onInit=function(){e.status="online",e.visitor&&e.visitor.interaction?e.visitor.interaction.id?t.go("app.chat",null,{location:"replace"}):t.go("app.waiting",null,{location:"replace"}):(e.visitor={id:e.settings.id,mapKey:"firstName",from:"Anonymous"+U()(1,1e6)},e.settings.showMenu=!1,e.updateStorage(o,e.visitor),n.chatWebsite.getFields({id:e.settings.id,online:!0}).$promise.then((function(e){e.count&&(s=e.fromKey,i.fields=e.rows)})).then((function(){for(let e=0;e<i.fields.length;e++){const t=i.fields[e];if(t.props.helpText){const n=RegExp.prototype.test.bind(/(<([^>]+)>)/i);i.checkHTML[e]=n(t.props.helpText)}}})).catch((function(e){console.error(e)})))},i.submit=function(){let r="New chat request \n";for(let t=0;t<i.fields.length;t++){const n=i.fields[t];n.props&&void 0!==i.form[n.props.title]&&(u()(n.variable)||(e.visitor[n.variable]=Array.isArray(i.form[n.props.title])?i.form[n.props.title].join():i.form[n.props.title]),u()(n.cmField)||(e.visitor[n.cmField]=Array.isArray(i.form[n.props.title])?i.form[n.props.title].join():i.form[n.props.title]),t===s&&(u()(e.settings.mapKey)||(e.visitor.mapKey=e.settings.mapKey,e.visitor.from=Array.isArray(i.form[n.props.title])?i.form[n.props.title].join():i.form[n.props.title])),i.form[n.props.title]&&(r+=n.props.title+": "+i.form[n.props.title]+"\n"))}var a;a=I()({body:r,referer:e.settings.referer,customerIp:e.settings.customerIp},e.visitor),i.disableItem=!0,n.chatWebsite.notify(a).$promise.then((function(n){delete i.errors.chatMessageError,e.visitor.message={id:n.message.id},e.visitor.interaction={id:n.interaction.id},e.updateStorage(o,e.visitor),i.disableItem=!1,e.settings.enableCustomerWriting?t.go("app.chat",null,{location:"replace"}):t.go("app.waiting",null,{location:"replace"})})).catch((function(e){i.disableItem=!1,console.error(e)}))},i.toggle=function(e,t){i.form[e]||(i.form[e]=[]);const n=i.form[e].indexOf(t);n>-1?i.form[e].splice(n,1):i.form[e].push(t)},i.exists=function(e,t){return i.form[e]||(i.form[e]=[]),i.form[e].indexOf(t)>-1}}function Y(e,t,n,o,i,s){const r=this;function a(){e.settings.online?t.go("app.online",null,{location:"replace"}):t.go("app.offline",null,{location:"replace"})}function l(){r.form={},r.upColor=null,r.downColor=null,r.userForm.$setPristine(),r.userForm.$setUntouched(),e.visitor={},e.enableDownload=!1,e.$emit("hide")}function c(t){return function(o){r.errors[t]=o.data;const i=n.simple().textContent(e.settings.formSubmitFailureMessage||"Form submission error").toastClass("md-failure-toast").parent(angular.element(document.querySelector("#chat-toolbar")));n.show(i)}}function d(){e.loading=!1}r.form={},r.errors={},r.$onInit=function(){e.status="unmanaged",e.updateStorage(i,null,!0),e.updateStorage(s,null,!0),e.loading=!1},r.submit=function(){e.loading=!0,e.visitor.interaction&&e.visitor.interaction.id?o.chatInteraction.customUpdate({id:e.visitor.interaction.id,note:r.form.note}).$promise.then((function(){delete r.errors.submit;const t=n.simple().textContent(e.settings.formSubmitSuccessMessage||"Form properly submitted").toastClass("md-success-toast").parent(angular.element(document.querySelector("#chat-toolbar")));n.show(t)})).then(l).then(a).catch(c("submit")).finally(d):(d(),c("submit"))},r.skip=function(){l(),a()}}function H(e,t,n,o,s,r,a,l){let c,d=!1;function u(){let t={},n=!1;r.chatInteraction.get({id:e.visitor.interaction.id}).$promise.then((function(n){return t=n,r.chatInteraction.getMessages({intid:e.visitor.interaction.id}).$promise})).then((function(i){n=i.rows.length>1,t.closed?(e.visitor.interaction.closed=!0,e.updateStorage(a,e.visitor),"unmanaged"===t.disposition&&o.go("app.unmanaged",null,{location:"replace"})):t.UserId?(e.visitor.interaction.UserId=t.UserId,e.updateStorage(a,e.visitor),o.go("app.chat",null,{location:"replace"})):n&&o.go("app.chat",null,{location:"replace"})})).catch((function(e){switch(e.status){case 403:o.go("app.closing",null,{location:"replace"});break;case 405:o.go("app.unmanaged",null,{location:"replace"});break;default:console.error(e)}}))}function m(){if(e.visitor&&e.visitor.interaction&&e.visitor.interaction.id&&!d){d=!0;const t=new XMLHttpRequest;t.open("PUT",e.settings.remote+"/api/chat/interactions/"+e.visitor.interaction.id+"/abandon?token="+e.settings.token,!1),t.setRequestHeader("Content-type","application/json; charset=utf-8"),t.send(JSON.stringify({channel:"chat",interaction:{id:e.visitor.interaction.id},message:{id:e.visitor.message.id},disposition:"abandoned",closed:!0,closeReason:"contact",closedAt:i()().format("YYYY-MM-DD HH:mm:ss")})),4===t.readyState&&200===t.status&&(e.updateStorage(a,null,!0),e.updateStorage(l,null,!0))}}this.$onInit=function(){e.status="waiting",e.visitor&&e.visitor.interaction&&e.visitor.interaction.id&&(c=n(u,3e3))},t.$on("$destroy",(function(){s.removeEventListener("beforeunload",m),s.removeEventListener("unload",m),n.cancel(c)})),s.addEventListener("beforeunload",m),s.addEventListener("unload",m)}function B(e){return function(t){return e.trustAsHtml(t)}}R.$inject=["$scope","$rootScope","api","$mdToast","$element","$http"],P.$inject=["$rootScope","$state","api","STORAGE_VISITOR"],Y.$inject=["$rootScope","$state","$mdToast","api","STORAGE_VISITOR","STORAGE_LAYOUT"],H.$inject=["$rootScope","$scope","$interval","$state","$window","api","STORAGE_VISITOR","STORAGE_LAYOUT"],B.$inject=["$sce"],angular.module("motion-chat",["ngAnimate","ngAria","ngMessages","ngMaterial","ngResource","ngSanitize","ngCsv","ngEmbed","ui.router","LocalStorageModule","ngRateIt","flow"]).filter("toTrusted",B).constant("STORAGE_PREFIX","motion_chat").constant("STORAGE_VISITOR","visitor").constant("STORAGE_LAYOUT","layout").directive("ngEnter",(function(){return function(e,t,n){t.bind("keydown keypress",(function(t){13===t.which&&(e.$apply((function(){e.$eval(n.ngEnter)})),t.preventDefault())}))}})).directive("ngPrint",(function(){return{link:function(e,t){t.on("click",(function(){document.getElementById("chatContent1")&&function(e,t){const n=document.createElement("div"),o=t.visitor,s=t.settings;let r;for(let e=0;e<t.messages.length;e++){const a=t.messages[e];let l="Sender: ";const c="Message: "+a.body,d="Sent At: "+i()(a.createdAt).format("YYYY-MM-DD HH:mm:ss");if(0!==e){switch(t.settings.agentIdentifier){case"website_alias":l+="out"===a.direction?a.UserId?s.agentAlias+a.UserId:"System":s.customerAlias||o.from||"Visitor"+a.ContactId;break;case"agent_alias":l+="out"===a.direction?a.UserId?a.User.alias||a.User.fullname:"System":s.customerAlias||o.from||"Visitor"+a.ContactId;break;case"agent_fullname":l+="out"===a.direction?a.UserId?a.User.fullname:"System":s.customerAlias||o.from||"Visitor"+a.ContactId;break;default:l+="out"===a.direction?a.UserId?(s.agentAlias||"Agent")+a.UserId:"System":s.customerAlias||o.from||"Visitor"+a.ContactId}n.appendChild(document.createTextNode(l)),n.appendChild(document.createElement("br")),n.appendChild(document.createTextNode(c)),n.appendChild(document.createElement("br")),n.appendChild(document.createTextNode(d)),n.appendChild(document.createElement("br")),n.appendChild(document.createElement("br"))}else r=a.createdAt}const a=window.open();a.document.write("<html><head><title>"+document.title+"</title>"),a.document.write("</head><body >"),a.document.write("<h3> Website: "+s.referer+"</h3>"),a.document.write("<h3> Start Time: "+i()(r).format("YYYY-MM-DD HH:mm:ss")+"</h3>"),a.document.write("<h3> Print Time: "+i()().format("YYYY-MM-DD HH:mm:ss")+"</h3>"),a.document.write(n.innerHTML),a.document.write("</body></html>"),a.document.close(),a.focus(),a.print(),a.close()}(0,e)}))},restrict:"A"}})).controller("ChatController",T).controller("ClosingController",$).config(["$mdGestureProvider",function(e){e.skipClickHijack()}]).controller("IndexController",a).factory("api",S).config(b).run(v).controller("OfflineController",R).config(["$mdGestureProvider",function(e){e.skipClickHijack()}]).controller("OnlineController",P).controller("UnmanagedController",Y).controller("WaitingController",H)}},e=>{"use strict";var t=t=>e(e.s=t);e.O(0,["vendor-index-cdd60c62","vendor-index-059be3de","vendor-angular-76f2ed34","vendor-angular-58d021f3","vendor-ng-embed","vendor-moment","vendor-jquery","vendor-jquery.textcomplete","vendor-emojionearea","vendor-emojione","vendor-angular-sanitize","vendor-angular-resource","vendor-angular-messages","vendor-angular-material","vendor-angular-local-storage","vendor-angular-animate","vendor-urlMatcher","vendor-transition","vendor-stateService","vendor-stateDirectives","vendor-flow","chat-296f7ffc","chat-ba5cce0a","chat-b63e7516","chat-5ee9077d","chat-b7633cdf","chat-0bc0478e","chat-d717b98e","chat-fb71bc84","chat-ab94cf03"],(()=>(t("./node_modules/jquery/dist/jquery.js"),t("./node_modules/angular/index-exposed.js"),t("./node_modules/moment/moment.js"),t("./node_modules/@flowjs/flow.js/src/flow.js"),t("./node_modules/emojione/lib/js/emojione.js"),t("./src/js/index.module.js")))),e.O()}]);
2 //# sourceMappingURL=chat-30c3a00b.js.map