Your IP : 18.191.219.238


Current Path : /home/bitrix/ext_www/crm.klimatlend.ua/bitrix/js/crm/
Upload File :
Current File : /home/bitrix/ext_www/crm.klimatlend.ua/bitrix/js/crm/visit.min.js

(function(){var t="bx-crm-visit-default-camera";var e="/bitrix/components/bitrix/crm.activity.visit/ajax.php?site_id="+BX.message("SITE_ID");var i="/bitrix/components/bitrix/crm.activity.editor/ajax.php?siteID="+BX.message("SITE_ID")+"&sessid="+BX.bitrix_sessid();var n=false;var o=false;var s=false;var a={onVisitCreated:BX.DoNothing};BX.CrmActivityVisit=function(t){if(!BX.type.isPlainObject(t))t={};this.buttons={createLead:null,createContact:null,selectEntity:null,addDeal:null,addInvoice:null};this.owner={type:null,id:null};this.createdDeals=[];this.createdInvoices=[];this.id=t.id||"crm-activity-visit-"+Math.round(Math.random()*1e5);this.ajaxUrl=t.ajaxUrl||e;this.recorder=null;this.mainNode=null;this.popup=null;this.hasFaceId=t.hasFaceId||false;this.hasConsent=t.HAS_CONSENT==="Y"||o;this.hasRecognizeConsent=t.HAS_RECOGNIZE_CONSENT==="Y"||s;this.faceIdInstalled=t.FACEID_INSTALLED==="Y";this.faceIdEnabled=t.FACEID_ENABLED==="Y";this.hasPhoto=false;this.faceId=0;this.communicationSearch=null;this.faceSearch=null;this.recordLength=0;this.timestamp=(new Date).getTime();this.timerInterval=null;this.externalRequests={};this._externalEventHandler=this._onExternalEvent.bind(this);this._selectEntityHandler=this._onSelectEntity.bind(this);this.createTimestamp=0;this.entityType=t.OWNER_TYPE||"";this.entityId=t.OWNER_ID||0;this.failed=false;this.vkProfile="";this.vkProfileChanged=false;this.init()};BX.CrmActivityVisit.create=function(t){return new BX.CrmActivityVisit(t)};BX.CrmActivityVisit.prototype.init=function(){BX.addCustomEvent(window,"onLocalStorageSet",this._externalEventHandler)};BX.CrmActivityVisit.prototype.getId=function(){return this.id};BX.CrmActivityVisit.prototype.setId=function(t){this.id=t};BX.CrmActivityVisit.prototype.getMainNode=function(){return this.mainNode};BX.CrmActivityVisit.prototype.setMainNode=function(t){this.mainNode=t};BX.CrmActivityVisit.prototype.getPopup=function(){return this.popup};BX.CrmActivityVisit.prototype.setPopup=function(t){this.popup=t};BX.CrmActivityVisit.prototype.getNode=function(t,e){if(!e)e=this.getMainNode();return e?e.querySelector('[data-role="'+t+'"]'):null};BX.CrmActivityVisit.prototype.getNodeValue=function(t,e){var i=this.getNode(t,e);return i?i.value:null};BX.CrmActivityVisit.prototype.showEdit=function(){var t=this;var e={ajax_action:"EDIT"};if(this.entityType&&this.entityId){e.entityType=this.entityType;e.entityId=this.entityId}t._checkConsent(function(){t._checkRecognizeConsent(function(){t._createAjaxPopup(e,function(){t.createTimestamp=t.getNodeValue("field-create-timestamp");t.owner.type=t.getNode("field-owner-entity-type");t.owner.id=t.getNode("field-owner-entity-id");if(t.owner.type.value&&t.owner.id.value){t.entityType=t.owner.type.value;t.entityId=t.owner.id.value;if(t.owner.type.value!=="LEAD"){var e=t.getNode("entity-links");BX.removeClass(e,"crm-activity-visit-hidden")}}var i=parseInt(t.getNode("field-owner-entity-deal").value);if(i>0){t.createdDeals.push(i)}t.buttons.createContact=t.getNode("create-contact-button");t.buttons.createLead=t.getNode("create-lead-button");t.buttons.selectEntity=t.getNode("select-owner-button");t.buttons.addDeal=t.getNode("add-deal-button");t.buttons.addInvoice=t.getNode("add-invoice-button");if(t.buttons.createContact)t.buttons.createContact.addEventListener("click",t._onCreateButtonClick.bind(t));if(t.buttons.createLead)t.buttons.createLead.addEventListener("click",t._onCreateButtonClick.bind(t));if(t.buttons.selectEntity)t.buttons.selectEntity.addEventListener("click",t._onSelectorButtonClick.bind(t));if(t.buttons.addDeal)t.buttons.addDeal.addEventListener("click",t._onAddButtonClick.bind(t));if(t.buttons.addInvoice)t.buttons.addInvoice.addEventListener("click",t._onAddButtonClick.bind(t));var n=t.getNode("activity-recorder");var o=t.getNode("button-finish");BX.bind(o,"click",t._onFinishButtonClick.bind(t));if(BX.CrmRecorder.isSupported()){t.recorder=new BX.CrmRecorder({element:n});BX.addCustomEvent(t.recorder,"deviceFailure",t._onRecorderDeviceFailure.bind(t));BX.addCustomEvent(t.recorder,"deviceReady",t._onRecorderDeviceReady.bind(t));t.recorder.start();t.timerInterval=setInterval(function(){var e=t.timestamp;var i=(new Date).getTime();var n=i-e;t.recordLength=t.recordLength+n;t.timestamp=i;t._updateTimer()},1e3)}else{BX.addClass(t.getNode("record-timer"),"crm-activity-visit-hidden");BX.removeClass(t.getNode("recorder-error"),"crm-activity-visit-hidden");t.failed=true}var s=t.getNode("faceid-container");if(s){t.faceSearch=new c(s,{visitView:t,onSelect:t._onFaceSelected.bind(t),onReset:t._onFaceReset.bind(t),onSocialProfileSelected:t._onFaceSocialProfileSelected.bind(t)});t.mainNode.style.minWidth="989px";t.hasFaceId=true;var a=t.getNode("crm-card-vk-profile");if(a){t.vkProfile=a.value;if(BX.type.isNotEmptyString(t.vkProfile)&&t.faceSearch){t.faceSearch.setVkProfile(t.vkProfile)}}}setTimeout(function(){t.getPopup().adjustPosition()},150)})})})};BX.CrmActivityVisit.prototype.saveActivity=function(t){var e=this;var i=e.getNode("button-finish");var n=e.getNode("loader-finish");clearInterval(this.timerInterval);BX.addClass(i,"crm-activity-visit-hidden");BX.removeClass(n,"crm-activity-visit-hidden");if(this.recorder){this.recorder.stop(function(i){var n=new FormData;n.append("RECORD",i);n.append("RECORD_LENGTH",Math.floor(e.recordLength/1e3));n.append("CREATED_DEALS[]",e.createdDeals);n.append("CREATED_INVOICES[]",e.createdInvoices);n.append("HAS_PHOTO",e.hasPhoto?"Y":"N");n.append("OWNER_ENTITY_TYPE",e.entityType);n.append("OWNER_ENTITY_ID",e.entityId);n.append("CREATE_TIMESTAMP",e.createTimestamp);if(e.faceSearch){n.append("SAVE_PHOTO",e.faceSearch.savePhoto?"Y":"N");if(e.faceSearch.savePhoto){n.append("IMAGE",e.faceSearch.getImageBlob())}}if(e.vkProfileChanged){n.append("VK_PROFILE",e.vkProfile)}n.append("sessid",BX.bitrix_sessid());n.append("ajax_action","SAVE");BX.ajax({method:"POST",dataType:"json",url:e.ajaxUrl,data:n,preparePost:false,onsuccess:function(e){t()},onprogress:function(t){}})})}else{t()}};BX.CrmActivityVisit.prototype.dispose=function(){if(this.timerInterval)clearInterval(this.timerInterval);BX.removeCustomEvent(window,"onLocalStorageSet",this._externalEventHandler);if(typeof obCrm!=="undefined"&&obCrm.visitCrmSelector){obCrm.visitCrmSelector.RemoveOnSaveListener(this._selectEntityHandler)}};BX.CrmActivityVisit.prototype._checkConsent=function(t){if(this.hasConsent){t();return}var e="<p>"+BX.message("CRM_ACTIVITY_VISIT_CONSENT_BODY_1")+"</p>"+"<p>"+BX.message("CRM_ACTIVITY_VISIT_CONSENT_BODY_2")+"</p>";var i=new BX.PopupWindow("crm_visit_consent_popup"+(new Date).getTime(),null,{titleBar:BX.message("CRM_ACTIVITY_VISIT_CONSENT_TITLE"),content:e,closeIcon:true,closeByEsc:true,events:{onPopupClose:function(){i.destroy()}},buttons:[new BX.PopupWindowButton({text:BX.message("CRM_ACTIVITY_VISIT_CONSENT_AGREED"),className:"popup-window-button-accept",events:{click:function(){o=true;BX.userOptions.save("crm.activity.visit","consent","timestamp",(new Date).getTime());i.close();t()}}}),new BX.PopupWindowButtonLink({text:BX.message("CRM_ACTIVITY_VISIT_CONSENT_CLOSE"),events:{click:function(){i.close()}}})]});i.show()};BX.CrmActivityVisit.prototype._checkRecognizeConsent=function(t){var e=this;if(!this.faceIdInstalled){t();return}if(this.hasRecognizeConsent){t();return}var i=BX.create("div",{style:{"max-width":"595px"},html:BX.message("CRM_ACTIVITY_VISIT_FACEID_AGREEMENT")});var n=new BX.PopupWindow("crm_visit_recognize_consent_popup"+(new Date).getTime(),null,{titleBar:BX.message("CRM_ACTIVITY_VISIT_CONSENT_TITLE"),content:i,closeIcon:true,closeByEsc:true,events:{onPopupClose:function(){n.destroy()}},buttons:[new BX.PopupWindowButton({text:BX.message("CRM_ACTIVITY_VISIT_CONSENT_AGREED"),className:"popup-window-button-accept",events:{click:function(){s=true;e.hasRecognizeConsent=true;n.close();e._saveRecognizeConsent(t)}}}),new BX.PopupWindowButtonLink({text:BX.message("CRM_ACTIVITY_VISIT_CONSENT_CLOSE"),events:{click:function(){s=false;e.hasRecognizeConsent=false;n.close();t()}}})]});n.show()};BX.CrmActivityVisit.prototype._saveRecognizeConsent=function(t){var e={sessid:BX.bitrix_sessid(),ajax_action:"SAVE_RECOGNIZE_CONSENT"};BX.ajax({method:"POST",dataType:"json",url:this.ajaxUrl,data:e,onsuccess:function(e){t()}})};BX.CrmActivityVisit.prototype._createAjaxPopup=function(t,e){t["sessid"]=BX.bitrix_sessid();t["HAS_RECOGNIZE_CONSENT"]=this.hasRecognizeConsent?"Y":"N";var i=this;var n=BX.create("div",{style:{"min-width":i.hasFaceId?"989px":"550px",height:"650px"}});var o=new BX.PopupWindow(i.getId(),null,{content:n,closeIcon:false,noAllPaddings:true,zIndex:-100,closeByEsc:false,draggable:{restrict:false},overlay:{backgroundColor:"black",opacity:30},events:{onPopupClose:function(){i._onPopupClose();i.popup.destroy()}}});o.show();BX.ajax({method:"POST",dataType:"html",url:this.ajaxUrl,data:t,onsuccess:function(t){n.innerHTML=t;i.setMainNode(n);i.setPopup(o);e()}})};BX.CrmActivityVisit.prototype.setOwner=function(t){var e=this;this.owner.type.value=t.entityType;this.owner.id.value=t.entityId;this.entityType=t.entityType;this.entityId=t.entityId;this._reloadOwnerCard(t,function(){var i=e.getNode("owner-selector");var n=e.getNode("entity-links");BX.addClass(i,"crm-activity-visit-hidden");if(t.entityType=="LEAD"){BX.addClass(n,"crm-activity-visit-hidden")}else{BX.removeClass(n,"crm-activity-visit-hidden")}e.getPopup().adjustPosition();if(e.faceSearch){e.faceSearch.__renderSavePhoto()}var o=e.getNode("crm-card-vk-profile");if(o){e.vkProfile=o.value;if(BX.type.isNotEmptyString(e.vkProfile)&&e.faceSearch){e.faceSearch.setVkProfile(e.vkProfile)}}})};BX.CrmActivityVisit.prototype._onCreateButtonClick=function(t){var e=t.target;var i=e.dataset.url;var n=e.dataset.context;this.externalRequests[n]={type:"create",context:n,window:window.open(i)}};BX.CrmActivityVisit.prototype._onExternalEvent=function(t){var e;t=BX.type.isPlainObject(t)?t:{};t.key=t.key||"";var i=t.value||{};i.entityTypeName=i.entityTypeName||"";i.context=i.context||"";i.isCanceled=BX.type.isBoolean(i.isCanceled)?i.isCanceled:false;if(i.isCanceled)return;if(t.key==="onCrmEntityCreate"&&this.externalRequests[i.context]){if(this.externalRequests[i.context]){if(this.externalRequests[i.context]["type"]=="create"){e={entityType:i.entityTypeName,entityId:i.entityId};this.setOwner(e)}else if(this.externalRequests[i.context]["type"]=="add"){if(i.entityTypeName=="DEAL")this.createdDeals.push(parseInt(i.entityId));else if(i.entityTypeName=="INVOICE")this.createdInvoices.push(parseInt(i.entityId));e={entityType:this.entityType,entityId:this.entityId};this.setOwner(e)}if(this.externalRequests[i.context]["window"])this.externalRequests[i.context]["window"].close();delete this.externalRequests[i.context]}}};BX.CrmActivityVisit.prototype._onAddButtonClick=function(t){var e=t.target;var i=e.dataset.url;var n=e.dataset.role;if(n==="add-deal-button"){if(this.owner.type.value==="CONTACT"){i=BX.util.add_url_param(i,{contact_id:this.owner.id.value})}else if(this.owner.type.value==="COMPANY"){i=BX.util.add_url_param(i,{company_id:this.owner.id.value})}}else if(n==="add-invoice-button"){if(this.owner.type.value==="CONTACT"){i=BX.util.add_url_param(i,{contact:this.owner.id.value})}else if(this.owner.type.value==="COMPANY"){i=BX.util.add_url_param(i,{company:this.owner.id.value})}}var o=e.dataset.context;this.externalRequests[o]={type:"add",context:o,window:window.open(i)};window.open(i)};BX.CrmActivityVisit.prototype._onFinishButtonClick=function(t){var e=this;if(this.failed){e.getPopup().close()}else{e.saveActivity(function(){e.getPopup().close();BX.CrmActivityVisit.runCallback("onVisitCreated",{})})}};BX.CrmActivityVisit.prototype._onPopupClose=function(){if(this.communicationSearch)this.communicationSearch.dispose();if(this.recorder)this.recorder.dispose();if(this.faceSearch)this.faceSearch.dispose();this.dispose()};BX.CrmActivityVisit.prototype._reloadOwnerCard=function(t,e){var i=this;var n={sessid:BX.bitrix_sessid(),ajax_action:"GET_CARD",ENTITY_TYPE:t.entityType,ENTITY_ID:t.entityId};BX.ajax({url:i.ajaxUrl,method:"POST",data:n,onsuccess:function(t){var n=i.getNode("activity-owner-card");n.innerHTML=t;e()}})};BX.CrmActivityVisit.prototype._updateTimer=function(){var t=this.getNode("record-length");var e=Math.floor(this.recordLength/1e3/60).toString();var i=Math.floor(this.recordLength/1e3%60).toString();if(e.length<2)e=String.prototype.concat("0",e);if(i.length<2)i=String.prototype.concat("0",i);t.innerText=e+":"+i};BX.CrmActivityVisit.prototype._onSelectorButtonClick=function(){this._openCrmSelector()};BX.CrmActivityVisit.prototype._openCrmSelector=function(){var t=this;if(!n){var e={sessid:BX.bitrix_sessid(),ajax_action:"LOAD_SELECTOR"};BX.ajax({method:"POST",url:t.ajaxUrl,data:e,onsuccess:function(){n=true;setTimeout(t._openCrmSelector.bind(t),50)}})}if(typeof obCrm!=="undefined"&&obCrm.visitCrmSelector){obCrm.visitCrmSelector.Open();obCrm.visitCrmSelector.AddOnSaveListener(this._selectEntityHandler)}};BX.CrmActivityVisit.prototype._onSelectEntity=function(t){var e={entityType:"",entityId:0};var i=false;if(t.lead&&t.lead.hasOwnProperty("0")&&BX.type.isNotEmptyString(t.lead["0"].id)){e.entityType="LEAD";e.entityId=t.lead["0"].id.substr(2);i=true}else if(t.contact&&t.contact.hasOwnProperty("0")&&BX.type.isNotEmptyString(t.contact["0"].id)){e.entityType="CONTACT";e.entityId=t.contact["0"].id.substr(2);i=true}else if(t.company&&t.company.hasOwnProperty("0")&&BX.type.isNotEmptyString(t.company["0"].id)){e.entityType="COMPANY";e.entityId=t.company["0"].id.substr(3);i=true}if(i){this.setOwner(e)}};BX.CrmActivityVisit.prototype._onFaceSelected=function(t){this.hasPhoto=true;this.faceId=t.faceId;if(t.entityType!=""&&t.entityId>0){this.setOwner({entityType:t.entityType,entityId:t.entityId})}};BX.CrmActivityVisit.prototype._onFaceReset=function(t){this.hasPhoto=false};BX.CrmActivityVisit.prototype._onFaceSocialProfileSelected=function(t){this.vkProfile=t;this.vkProfileChanged=true};BX.CrmActivityVisit.prototype._onRecorderDeviceReady=function(){if(this.faceSearch)this.faceSearch.start()};BX.CrmActivityVisit.prototype._onRecorderDeviceFailure=function(t){var e=this.getNode("record-timer");var i=this.getNode("recorder-error");BX.addClass(e,"crm-activity-visit-hidden");BX.removeClass(i,"crm-activity-visit-hidden");i.innerHTML=BX.message("CRM_ACTIVITY_VISIT_ERROR_MIC_FAILURE")+"<br>"+t;this.failed=true};BX.CrmActivityVisit.setCallback=function(t,e){if(a.hasOwnProperty(t)&&BX.type.isFunction(e)){a[t]=e}};BX.CrmActivityVisit.runCallback=function(t,e){if(a.hasOwnProperty(t)&&BX.type.isFunction(a[t])){a[t](e)}};var r=function(t,e){var n=this;this.id="crm-act-visit-"+(new Date).getTime().toString();this.node=t;this.communicationType=BX.CrmCommunicationType.undefined;this.ajaxUrl=e.ajaxUrl||i;this.entityType=null;this.entityId=null;this.entityTitle=null;this.callBacks={onSelect:BX.type.isFunction(e.onSelect)?e.onSelect:l};this.setEntity({entityType:e.entityType||"",entityId:e.entityId||"",entityTitle:e.entityTitle||""});if(typeof BX.CrmCommunicationSearch.messages==="undefined"){BX.CrmCommunicationSearch.messages={SearchTab:BX.message("CRM_ACTIVITY_PLANNER_COMMUNICATION_SEARCH_TAB"),NoData:BX.message("CRM_ACTIVITY_PLANNER_COMMUNICATION_SEARCH_NO_DATA")}}var o=this.getNode("select-owner");var s=this.getNode("input-owner");BX.style(s,"display","none");BX.bind(o,"click",function(t){n.openDialog();return BX.PreventDefault(t)});this._communicationSearch=BX.CrmCommunicationSearch.create(this.id,{entityType:this.entityType,entityId:this.entityId,serviceUrl:this.ajaxUrl,communicationType:this.communicationType,selectCallback:BX.delegate(this.selectCommunication,this),enableSearch:true,enableDataLoading:true,dialogAutoHide:true});this._communicationSearchController=null};r.prototype.getNode=function(t,e){if(!e)e=this.node;return e?e.querySelector('[data-role="'+t+'"]'):null};r.prototype.setEntity=function(t){var e=this.getNode("select-owner");var i=this.getNode("owner-title");this.entityId=t.entityId||0;this.entityType=t.entityType||"";this.entityTitle=t.entityTitle||"";i.innerText=this.entityTitle;if(this.entityId>0)e.innerText=BX.message("CRM_ACTIVITY_VISIT_OWNER_CHANGE");else e.innerText=BX.message("CRM_ACTIVITY_VISIT_OWNER_SELECT")};r.prototype.openDialog=function(){var t=this.getNode("input-owner");var e=this.getNode("select-owner");var i=this.getNode("owner-title");BX.style(e,"display","none");BX.style(t,"display","inline-block");BX.style(i,"display","none");this._communicationSearchController=BX.CrmCommunicationSearchController.create(this._communicationSearch,t);this._communicationSearchController.start();this._communicationSearch.openDialog(this.node,BX.delegate(this.onCloseDialog,this));BX.defer(BX.focus)(t)};r.prototype.onCloseDialog=function(){var t=this.getNode("input-owner");var e=this.getNode("select-owner");var i=this.getNode("owner-title");BX.style(e,"display","inline-block");BX.style(t,"display","none");BX.style(i,"display","inline-block");if(this._communicationSearchController){this._communicationSearchController.stop();this._communicationSearchController=null}t.value=""};r.prototype.selectCommunication=function(t){var e=t.getSettings();this.callBacks.onSelect(e);this.setEntity(e);this._communicationSearch.closeDialog()};r.prototype.dispose=function(){this._communicationSearch.closeDialog()};var c=function(t,i){if(!BX.type.isPlainObject(i))i={};this.ajaxUrl=i.ajaxUrl||e;this.node=t;this.visitView=i.visitView||null;this.mediaStream=null;this.defaulCamera=this.__getDefaultCamera();this.state="video";this.cameraList=[];this.savePhoto=false;this.imageBlob=null;this.elements={loader:this.getNode("faceid-button-picture-loader"),social:this.getNode("faceid-social")};this.buttons={picture:this.getNode("faceid-button-picture"),settings:this.getNode("faceid-button-settings"),seachSocial:this.getNode("faceid-button-search-social"),savePhoto:this.getNode("faceid-button-save-photo")};this.callbacks={onSelect:BX.type.isFunction(i.onSelect)?i.onSelect:l,onReset:BX.type.isFunction(i.onReset)?i.onReset:l,onSocialProfileSelected:BX.type.isFunction(i.onSocialProfileSelected)?i.onSocialProfileSelected:l};this.settingsMenu=null;this.socialSelector=null;this.init();this.__bindEvents()};c.prototype.init=function(){this.buttons.picture.innerText=BX.message("CRM_ACTIVITY_VISIT_OWNER_TAKE_PICTURE");BX.hide(this.buttons.settings)};c.prototype.getNode=function(t,e){if(!e)e=this.node;return e?e.querySelector('[data-role="'+t+'"]'):null};c.prototype.getImageBlob=function(){return this.imageBlob};c.prototype.setImageBlob=function(t){this.imageBlob=t};c.prototype.start=function(){this.__getMediaStream()};c.prototype.changeCamera=function(t){this.defaulCamera=t;this.__setDefaultCamera(t);if(this.mediaStream)u(this.mediaStream);this.mediaStream=null;this.__getMediaStream()};c.prototype.__bindEvents=function(){this.buttons.picture.addEventListener("click",this.__onSearchButtonClick.bind(this));this.buttons.settings.addEventListener("click",this.__onSettingsButtonClick.bind(this));this.buttons.seachSocial.addEventListener("click",this.__onSearchSocialButtonClick.bind(this));this.buttons.savePhoto.addEventListener("click",this.__onSavePhotoButtonClick.bind(this))};c.prototype.__getMediaStream=function(){var t=this;navigator.mediaDevices.getUserMedia(this.__getConstraints()).then(function(e){t.mediaStream=e;var i=t.getNode("faceid-video");i.volume=0;i.srcObject=t.mediaStream;i.play();if(t.cameraList.length===0){t.__getCameraList()}else{BX.show(t.buttons.settings)}}).catch(function(t){console.log("Could not get access to user camera: ",t)})};c.prototype.__getConstraints=function(){var t={audio:false,video:{}};if(this.defaulCamera!=""){if(BX.browser.IsChrome()){t.video.mandatory={sourceId:this.defaulCamera}}else{t.video.deviceId={exact:this.defaulCamera}}}return t};c.prototype.__getCameraList=function(){var t=this;navigator.mediaDevices.enumerateDevices().then(function(e){e.forEach(function(e){if(e.kind!=="videoinput")return;if(e.label="")e.label=BX.message("CRM_ACTIVITY_VISIT_DEFAULT_CAMERA");t.cameraList.push(e)});if(t.cameraList.length>0){BX.show(t.buttons.settings)}})};c.prototype.__getDefaultCamera=function(){return localStorage.getItem(t)||""};c.prototype.__setDefaultCamera=function(e){return localStorage.setItem(t,e)};c.prototype.__onSearchButtonClick=function(){var t=this;var e=t.getNode("faceid-picture-container");var i=t.getNode("faceid-picture");var n=t.getNode("faceid-video-container");if(t.state=="video"){t.createPicture(function(o){t.__setState("picture");t.setImageBlob(o);i.src=URL.createObjectURL(o);u(t.mediaStream);t.mediaStream=null;BX.addClass(n,"crm-activity-visit-hidden");BX.removeClass(e,"crm-activity-visit-hidden");BX.removeClass(t.elements.social,"crm-activity-visit-block-disable");BX.hide(t.buttons.settings);t.__showLoader();t.searchFace(o,function(e){t.__hideLoader();if(e.ERRORS.length>0){console.log("Error received: ",e.ERRORS[0]);return}if(e.SUCCESS===true){t.callbacks.onSelect({entityType:e.DATA.ENTITY_TYPE,entityId:e.DATA.ENTITY_ID,entityTitle:e.DATA.ENTITY_TITLE,faceId:e.FACE_ID})}else if(e.ERRORS.length>0){window.alert(e.ERRORS[0])}})})}else if(t.state=="picture"){t.__setState("video");BX.removeClass(n,"crm-activity-visit-hidden");BX.addClass(e,"crm-activity-visit-hidden");BX.addClass(t.elements.social,"crm-activity-visit-block-disable");BX.removeClass(t.getNode("faceid-button-search-social"),"crm-activity-visit-hidden");BX.addClass(t.getNode("faceid-vk-profile"),"crm-activity-visit-hidden");t.__getMediaStream();t.callbacks.onReset()}};c.prototype.__onSettingsButtonClick=function(t){var e=this;var i=[];if(this.settingsMenu){this.settingsMenu.popupWindow.close();this.settingsMenu=null;return}if(this.cameraList.length===0)return;this.cameraList.forEach(function(t){var n={id:"setCamera"+t.deviceId,text:t.label,onclick:function(){e.changeCamera(t.deviceId);e.settingsMenu.popupWindow.close()}};if(t.deviceId==e.__getDefaultCamera()){n.className="crm-activity-visit-popup-settings-icon-checked"}else{n.className="crm-activity-visit-popup-settings-icon-none"}i.push(n)});this.settingsMenu=BX.PopupMenu.create("visitTrackerCameraSettingsMenu",this.buttons.settings,i,{autoHide:true,offsetTop:0,offsetLeft:Math.round(e.buttons.settings.offsetWidth/2),angle:{position:"top"},events:{onPopupClose:function(){e.settingsMenu.popupWindow.destroy();BX.PopupMenu.destroy("visitTrackerCameraSettingsMenu")},onPopupDestroy:function(){e.settingsMenu=null}}});this.settingsMenu.popupWindow.show()};c.prototype.__onSearchSocialButtonClick=function(t){this.socialSelector=new d({imageBlob:this.getImageBlob(),onSelect:this.__onSocialProfileSelected.bind(this),onDispose:this.__onSocialSelectorClosed.bind(this)});this.socialSelector.show()};c.prototype.__onSavePhotoButtonClick=function(t){this.savePhoto=!this.savePhoto;if(this.savePhoto)BX.addClass(this.buttons.savePhoto,"crm-activity-visit-faceid-checkbox-active");else BX.removeClass(this.buttons.savePhoto,"crm-activity-visit-faceid-checkbox-active")};c.prototype.__setState=function(t){var e=this.getNode("faceid-button-picture");switch(t){case"picture":e.innerText=BX.message("CRM_ACTIVITY_VISIT_OWNER_RETAKE_PICTURE");break;case"video":e.innerText=BX.message("CRM_ACTIVITY_VISIT_OWNER_TAKE_PICTURE");break}this.state=t;this.__renderSavePhoto()};c.prototype.__showLoader=function(){BX.addClass(this.buttons.picture,"crm-activity-visit-hidden");BX.removeClass(this.elements.loader,"crm-activity-visit-hidden")};c.prototype.__hideLoader=function(){BX.removeClass(this.buttons.picture,"crm-activity-visit-hidden");BX.addClass(this.elements.loader,"crm-activity-visit-hidden")};c.prototype.createPicture=function(t){var e=this.getNode("faceid-canvas");var i=e.getContext("2d");var n=this.getNode("faceid-video");var o=n.videoWidth;var s=n.videoHeight;if(o===0||s===0)return false;e.width=o;e.height=s;i.drawImage(n,0,0,o,s);e.toBlob(function(e){t(e)})};c.prototype.searchFace=function(t,e){var i=this;var n=new FormData;n.append("IMAGE",t);n.append("sessid",BX.bitrix_sessid());n.append("ajax_action","RECOGNIZE");BX.ajax({method:"POST",dataType:"json",url:i.ajaxUrl,data:n,preparePost:false,onsuccess:function(t){e(t)}})};c.prototype.setVkProfile=function(t){var e=this.getNode("faceid-vk-profile");var i=this.getNode("faceid-vk-profile-link");var n=this.getNode("faceid-button-search-social");i.innerText="VK.com/"+BX.util.htmlspecialchars(t);i.href="https://vk.com/"+BX.util.htmlspecialchars(t);BX.addClass(n,"crm-activity-visit-hidden");BX.removeClass(e,"crm-activity-visit-hidden")};c.prototype.__onSocialProfileSelected=function(t){this.setVkProfile(t);this.callbacks.onSocialProfileSelected(t)};c.prototype.__onSocialSelectorClosed=function(){this.socialSelector=null};c.prototype.__renderSavePhoto=function(){if(this.state==="picture"&&this.visitView.owner.type.value==="CONTACT"){BX.removeClass(this.buttons.savePhoto,"crm-activity-visit-hidden")}else{BX.addClass(this.buttons.savePhoto,"crm-activity-visit-hidden")}};c.prototype.dispose=function(){if(this.mediaStream){u(this.mediaStream);this.mediaStream=null}};var d=function(t){this.node=null;this.popup=null;this.imageBlob=t.imageBlob;this.callbacks={onSelect:BX.type.isFunction(t.onSelect)?t.onSelect:l,onDispose:BX.type.isFunction(t.onDispose)?t.onDispose:l}};d.prototype.getNode=function(t,e){if(!e)e=this.node;return e?e.querySelector('[data-role="'+t+'"]'):null};d.prototype.setImageBlob=function(t){this.imageBlob=t};d.prototype._bindEvents=function(){var t=document.querySelectorAll('[data-role="faceid-social-button-select"]');var e;if(t){for(e=0;e<t.length;e++){t.item(e).addEventListener("click",this._onSelectButtonClick.bind(this))}}};d.prototype.show=function(){var t=this;var e=this.getNode("template-social-search",document).innerHTML;this.node=BX.create("div",{html:e});this.popup=new BX.PopupWindow("crm-activity-visit-social-selector",null,{titleBar:BX.message("CRM_ACTIVITY_VISIT_FACEID_SOCIAL_SEACH_IN_PROCESS"),content:this.node,closeIcon:true,closeByEsc:true,draggable:true,noAllPaddings:true,events:{OnPopupClose:function(){this.destroy()},OnPopupDestroy:function(){t.dispose()}}});this.popup.show();this.startSearch(function(e){t.node.innerHTML=e;t.popup.adjustPosition();t._bindEvents()})};d.prototype.startSearch=function(t){var i=new FormData;i.append("IMAGE",this.imageBlob);i.append("sessid",BX.bitrix_sessid());i.append("ajax_action","SEARCH_SOCIAL");BX.ajax({method:"POST",dataType:"html",url:e,data:i,preparePost:false,onsuccess:function(e){t(e)}})};d.prototype._onSelectButtonClick=function(t){var e=t.target.dataset.profile;this.callbacks.onSelect(e);this.popup.close()};d.prototype.dispose=function(){this.callbacks.onDispose()};var l=function(){};var u=function(t){if(!(t instanceof MediaStream))return;if(typeof t.getTracks==="undefined"){t.stop()}else{t.getTracks().forEach(function(t){t.stop()})}}})();
//# sourceMappingURL=visit.map.js