Your IP : 13.58.173.30
(function(){BX.namespace("BX.rest");if(!!BX.rest.AppLayout){return}BX.rest.AppLayout=function(e){this.params={firstRun:!!e.firstRun,appHost:e.appHost,appProto:e.appProto,authId:e.authId,authExpires:e.authExpires,refreshId:e.refreshId,placement:e.placement,formName:e.formName,frameName:e.frameName,loaderName:e.loaderName,layoutName:e.layoutName,ajaxUrl:e.ajaxUrl,controlUrl:e.controlUrl,isAdmin:!!e.isAdmin,staticHtml:!!e.staticHtml,id:e.id,appId:e.appId,appV:e.appV,appI:e.appI,appSid:e.appSid,memberId:e.memberId,restPath:e.restPath,proto:e.proto,userOptions:e.userOptions,appOptions:e.appOptions,placementOptions:e.placementOptions};this.userSelectorControl=[null,null];this.userSelectorControlCallback=null;this.bAccessLoaded=false;this._appOptionsStack=[];this._inited=false;this._destroyed=false;this.deniedInterface=[];this.selectUserCallback_1_value=[];this.messageInterface=new(BX.rest.AppLayout.initializePlacement(this.params.placement));BX.bind(window,"message",BX.proxy(this.receiveMessage,this))};BX.rest.AppLayout.openApplication=function(e,t,s,a){var i=BX.message("REST_APPLICATION_URL").replace("#id#",parseInt(e));i=BX.util.add_url_param(i,{_r:Math.random()});var n={ID:e,PLACEMENT_OPTIONS:t,POPUP:1};if(!!s){if(typeof s.PLACEMENT!=="undefined"){n.PLACEMENT=s.PLACEMENT}if(typeof s.PLACEMENT_ID!=="undefined"){n.PLACEMENT_ID=s.PLACEMENT_ID}}BX.SidePanel.Instance.open(i,{cacheable:false,contentCallback:function(e){var t=new top.BX.Promise;top.BX.ajax.post(e.url,{sessid:BX.bitrix_sessid(),site:BX.message("SITE_ID"),PARAMS:{template:"",params:n}},function(e){t.fulfill(e)});return t},events:{onClose:function(){if(!!a){a()}}}});var r=top.BX.SidePanel.Instance.getTopSlider();top.BX.addCustomEvent(top,"Rest:AppLayout:ApplicationInstall",function(i,n){n.redirect=false;r.close(false,function(){BX.rest.AppLayout.openApplication(e,t,s,a)})})};BX.rest.AppLayout.prototype={init:function(){if(!this._inited&&!!document.forms[this.params.formName]){var e=BX(this.params.loaderName);BX.bind(BX(this.params.frameName),"load",function(){BX.addClass(e,"app-loading-msg-loaded");BX.removeClass(this,"app-loading");setTimeout(function(){BX.remove(e)},300)});if(this.params.staticHtml){BX(this.params.frameName).src=document.forms[this.params.formName].action}else{document.forms[this.params.formName].submit()}this._inited=true}},destroy:function(){BX.unbind(window,"message",BX.proxy(this.receiveMessage,this));BX(this.params.frameName).parentNode.removeChild(BX(this.params.frameName));this._destroyed=true},query:function(e,t){var s={sessid:BX.bitrix_sessid(),site:BX.message("SITE_ID"),PARAMS:{template:"",params:{ID:this.params.id}}};if(!!e){s=BX.mergeEx(s,e)}return BX.ajax({dataType:"json",method:"POST",url:this.params.ajaxUrl,data:s,onsuccess:t})},receiveMessage:function(t){t=t||window.event;if(t.origin!=this.params.appProto+"://"+this.params.appHost||!t.data){return}var s=e(t.data,":"),a=[];if(s[3]!=this.params.appSid){return}if(s[1]){a=JSON.parse(s[1])}if(!!this.messageInterface[s[0]]&&!BX.util.in_array(s[0],this.deniedInterface)){var i=s[2];var n=!i?BX.DoNothing:BX.delegate(function(e){var t=BX(this.params.frameName);if(!!t&&!!t.contentWindow){t.contentWindow.postMessage(i+":"+(typeof e=="undefined"?"":JSON.stringify(e)),this.params.appProto+"://"+this.params.appHost)}},this);this.messageInterface[s[0]].apply(this,[a,n])}},denyInterface:function(e){this.deniedInterface=BX.util.array_merge(this.deniedInterface,e)},allowInterface:function(e){var t=[];for(var s=0;s<this.deniedInterface.length;s++){if(!BX.util.in_array(this.deniedInterface[s],e)){t.push(this.deniedInterface[s])}}this.deniedInterface=t},sendAppOptions:function(){if(this._appOptionsStack.length>0){var e=this._appOptionsStack;this._appOptionsStack=[];var t=[];for(var s=0;s<e.length;s++){t.push({name:e[s][0],value:e[s][1]})}var a={action:"set_option",options:t};this.query(a,function(t){for(var s=0;s<e.length;s++){e[s][2](t)}})}},loadControl:function(e,t,s){if(!t){t={}}t.control=e;t.sessid=BX.bitrix_sessid();BX.ajax({method:"POST",url:this.params.controlUrl,data:t,processScriptsConsecutive:true,onsuccess:s})},reInstall:function(){BX.proxy(this.messageInterface.setInstallFinish,this)({value:false})},selectUserCallback_0:function(e){var t=BX.util.array_values(e);if(!!t&&t.length>0){BX.defer(this.userSelectorControl[0].close,this.userSelectorControl[0])();if(!!this.userSelectorControlCallback){this.userSelectorControlCallback.apply(this,[t[0]])}}},selectUserCallback_1:function(e){if(e===true){var t=BX.util.array_values(this.selectUserCallback_1_value);BX.defer(this.userSelectorControl[1].close,this.userSelectorControl[1])();if(!!this.userSelectorControlCallback){this.userSelectorControlCallback.apply(this,[t])}}else{this.selectUserCallback_1_value=e}},hideUpdate:function(e,t){BX.userOptions.save("app_options","params_"+this.params.appId+"_"+this.params.appV,"skip_update_"+e,1);t()}};BX.rest.AppLayout.initizalizePlacementInterface=function(e){var t=function(){};BX.extend(t,e);t.prototype.events=BX.clone(t.superclass.events);return t};BX.rest.AppLayout.initializePlacement=function(e){e=(e+"").toUpperCase();if(!BX.rest.AppLayout.placementInterface[e]){BX.rest.AppLayout.placementInterface[e]=BX.rest.AppLayout.initizalizePlacementInterface(e==="DEFAULT"?BX.rest.AppLayout.MessageInterface:BX.rest.AppLayout.MessageInterfacePlacement)}return BX.rest.AppLayout.placementInterface[e]};BX.rest.AppLayout.initializePlacementByEvent=function(e,t){BX.addCustomEvent(t,function(t){var s=BX.rest.AppLayout.initializePlacement(e);if(!!t.events){for(var a=0;a<t.events.length;a++){s.prototype.events.push(t.events[a])}}for(var i in t){if(i!=="events"&&t.hasOwnProperty(i)){s.prototype[i]=t[i]}}})};BX.rest.AppLayout.MessageInterface=function(){};BX.rest.AppLayout.MessageInterface.prototype={events:[],getInitData:function(e,t){t({LANG:BX.message("LANGUAGE_ID"),DOMAIN:location.host,PROTOCOL:this.params.proto,PATH:this.params.restPath,AUTH_ID:this.params.authId,AUTH_EXPIRES:this.params.authExpires,REFRESH_ID:this.params.refreshId,MEMBER_ID:this.params.memberId,FIRST_RUN:this.params.firstRun,IS_ADMIN:this.params.isAdmin,INSTALL:this.params.appI,USER_OPTIONS:this.params.userOptions,APP_OPTIONS:this.params.appOptions,PLACEMENT:this.params.placement,PLACEMENT_OPTIONS:this.params.placementOptions});this.params.firstRun=false},getInterface:function(e,t){var s={command:[],event:[]};for(var a in this.messageInterface){if(a!=="events"&&a!=="constructor"&&!BX.rest.AppLayout.MessageInterfacePlacement.prototype[a]&&!BX.util.in_array(a,this.deniedInterface)){s.command.push(a)}}for(var i=0;i<this.messageInterface.events.length;i++){s.event.push(this.messageInterface.events[i])}t(s)},refreshAuth:function(e,t){e={action:"access_refresh"};this.query(e,BX.delegate(function(e){if(!!e["access_token"]){this.params.authId=e["access_token"];this.params.authExpires=e["expires_in"];this.params.refreshId=e["refresh_token"];t({AUTH_ID:this.params.authId,AUTH_EXPIRES:this.params.authExpires,REFRESH_ID:this.params.refreshId})}else{alert("Unable to get new token! Reload page, please!")}},this))},resizeWindow:function(e,t){var s=BX(this.params.layoutName);e.width=e.width=="100%"?e.width:(parseInt(e.width)||100)+"px";e.height=parseInt(e.height);if(!!e.width){s.style.width=e.width}if(!!e.height){s.style.height=e.height+"px"}var a=BX.pos(s);t({width:a.width,height:a.height})},setTitle:function(e,t){BX.ajax.UpdatePageTitle(e.title);t(e)},setScroll:function(e,t){if(!!e&&typeof e.scroll!="undefined"&&e.scroll>=0){window.scrollTo(BX.GetWindowScrollPos().scrollLeft,parseInt(e.scroll))}t(e)},setUserOption:function(e,t){this.params.userOptions[e.name]=e.value;BX.userOptions.save("app_options","options_"+this.params.appId,e.name,e.value);t(e)},setAppOption:function(e,t){if(this.params.isAdmin){this._appOptionsStack.push([e.name,e.value,t]);BX.defer(this.sendAppOptions,this)()}},setInstall:function(e,t){BX.userOptions.save("app_options","params_"+this.params.appId+"_"+this.params.appV,"install",!!e["install"]?1:0);t(e)},setInstallFinish:function(e,t){var s={action:"set_installed",v:typeof e.value=="undefined"||e.value!==false?"Y":"N"};this.query(s,BX.delegate(function(e){var t={redirect:true};top.BX.onCustomEvent(top,"Rest:AppLayout:ApplicationInstall",[s.v,t],false);if(t.redirect){window.location=BX.util.add_url_param(window.location.href,{install_finished:!!e.result?"Y":"N"})}},this))},selectUser:function(e,t){this.userSelectorControlCallback=t;var s=parseInt(e.mult+0);if(s){if(this.userSelectorControl[s]){this.userSelectorControl[s].close();this.userSelectorControl[s].destroy();this.userSelectorControl[s]=null}}else if(!!this.userSelectorControl[s]){this.userSelectorControl[s].show();return}var a={name:"USER_"+s,onchange:"user_selector_cb_"+parseInt(Math.random()*1e5),site_id:BX.message("SITE_ID")};if(s){a.mult=true}window[a.onchange]=BX.delegate(this["selectUserCallback_"+s],this);this.loadControl("user_selector",a,BX.delegate(function(t){this.userSelectorControl[s]=BX.PopupWindowManager.create("app-user-popup-"+s,null,{autoHide:true,content:t,zIndex:2e3});if(s){this.userSelectorControl[s].setButtons([new BX.PopupWindowButton({text:BX.message("REST_ALT_USER_SELECT"),className:"popup-window-button-accept",events:{click:function(){window[a.onchange](true)}}})])}this.userSelectorControl[parseInt(e.mult+0)].show();BX("USER_"+s+"_selector_content").style.display="block"},this))},selectAccess:function(e,t){if(!this.bAccessLoaded){this.loadControl("access_selector",{},BX.defer(function(){this.bAccessLoaded=true;BX.defer(this.messageInterface.selectAccess,this)(e,t)},this))}else{BX.Access.Init({groups:{disabled:true}});e.value=e.value||[];var s={};for(var a=0;a<e.value.length;a++){s[e.value[a]]=true}BX.Access.SetSelected(s);BX.Access.ShowForm({callback:function(e){var s=[];for(var a in e){if(e.hasOwnProperty(a)){for(var i in e[a]){if(e[a].hasOwnProperty(i)){s.push(e[a][i])}}}}t(s)}})}},selectCRM:function(e,t,s){if(!s){this.loadControl("crm_selector",{entityType:e.entityType,multiple:!!e.multiple?"Y":"N",value:e.value},BX.delegate(function(){BX.defer(this.messageInterface.selectCRM,this)(e,t,true)},this));return}if(!window.obCrm){setTimeout(BX.delegate(function(){BX.proxy(this.messageInterface.selectCRM,this)(e,t,true)},this),500)}else{obCrm["restCrmSelector"].Open();obCrm["restCrmSelector"].AddOnSaveListener(function(e){t(e);obCrm["restCrmSelector"].Clear()})}},reloadWindow:function(){window.location.reload()},imCallTo:function(e){BXIM.callTo(e.userId,!!e.video)},imPhoneTo:function(e){BXIM.phoneTo(e.phone)},imOpenMessenger:function(e){BXIM.openMessenger(e.dialogId)},imOpenHistory:function(e){BXIM.openHistory(e.dialogId)},openApplication:function(e,t){BX.rest.AppLayout.openApplication(this.params.id,e,{},t)},closeApplication:function(e,t){if(top.BX.SidePanel.Instance.isOpen()&&top.BX.SidePanel.Instance.getTopSlider().url.match(new RegExp("^"+BX.message("REST_APPLICATION_URL")))){top.BX.SidePanel.Instance.close(false,t)}}};BX.rest.AppLayout.MessageInterfacePlacement=BX.rest.AppLayout.initizalizePlacementInterface(BX.rest.AppLayout.MessageInterface);BX.rest.AppLayout.MessageInterfacePlacement.prototype.placementBindEvent=function(e,t){if(!!e.event&&BX.util.in_array(e.event,this.messageInterface.events)){var s=BX.delegate(function(){if(!this._destroyed){t.apply(this,arguments)}else{BX.removeCustomEvent(e.event,s)}},this);BX.addCustomEvent(e.event,s)}};BX.rest.layoutList={};BX.rest.placementList={};BX.rest.AppLayout.placementInterface={};BX.rest.AppLayout.get=function(e){return BX.rest.layoutList[e]};BX.rest.AppLayout.set=function(e,t,s){e=(e+"").toUpperCase();s.appSid=t;s.placement=e;BX.rest.layoutList[t]=new BX.rest.AppLayout(s);return BX.rest.layoutList[t]};BX.rest.AppLayout.getPlacement=function(e){return BX.rest.placementList[(e+"").toUpperCase()]};BX.rest.AppLayout.setPlacement=function(e,t){BX.rest.placementList[(e+"").toUpperCase()]=t};BX.rest.AppLayout.initialize=function(e,t){e=(e+"").toUpperCase();BX.rest.layoutList[e]=BX.rest.layoutList[t];BX.rest.layoutList[e].init()};BX.rest.AppLayout.destroy=function(e){var t=BX.rest.AppLayout.get(e);if(!!t){t.destroy()}BX.rest.layoutList[t.params.appSid]=null;if(!!BX.rest.AppLayout.placementInterface[e]){BX.rest.layoutList[e]=null}};function e(e,t){var s=e.split(t);return[s[0],s.slice(1,s.length-2).join(t),s[s.length-2],s[s.length-1]]}})();