uawdijnntqw1x1x1
IP : 3.16.30.154
Hostname : axolotl
Kernel : Linux axolotl 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
OS : Linux
PATH:
/
var
/
www
/
axolotl
/
data
/
www
/
axolotl.ru
/
..
/
b24.axolotl.ru
/
public_html
/
bitrix
/
js
/
crm
/
activity.min.js
/
/
if(typeof BX.CrmActivityEditor=="undefined"){BX.CrmActivityEditorType={recent:"RECENT",history:"HISTORY",mixed:"MIXED"};BX.CrmActivityStorageType={undefined:0,file:1,webdav:2,disk:3};BX.CrmActivityEditor=function(){this._id="";this._settings={};this._items=[];this._onActivityChangeHandlers=[];this._saveHandler=BX.delegate(this._handleActivitySave,this);this._dlgCloseHandler=BX.delegate(this._handleActivityDialogClose,this);this._dlgOpenerId=null;this._createEventHandler=BX.delegate(this.handleAddEventClick,this);this._createTaskHandler=BX.delegate(this.handleAddTaskClick,this);this._createCallHandler=BX.delegate(this.handleAddCallClick,this);this._createMeetingHandler=BX.delegate(this.handleAddMeetingClick,this);this._createEmailCreateHandler=BX.delegate(this.handleAddEmailClick,this);this._eventListPageReloadHandler=null;this._markAsCompletedOnView=true;this._isLocked=false;this._lockMessage="";this._initialized=false};BX.CrmActivityEditor.prototype={initialize:function(t,e,i){this._id=BX.type.isNotEmptyString(t)?t:"crm_activity_editor";this._settings=e?e:{};var n=this.isUIEnabled();for(var a=0;a<i.length;a++){var r=i[a];var s=r["rowID"]?r["rowID"]:"";r["enableUI"]=n&&s!=="";this._items.push(BX.CrmActivity.create(r,s!==""?BX(s):null,this))}this.showHeading(this._items.length>0);this.showHint(this._items.length===0);var o=this.getContainer();if(n){var l=BX.findChild(o,{tag:"a",class:"crm-activity-command-show-all"},true,false);if(l){BX.bind(l,"click",BX.delegate(this.handleShowAllClick,this))}}var c=this.getToolbarContainer();if(!c){c=o}if(c&&!this.getSetting("readOnly",true)&&this.getSetting("enableToolbar",true)){BX.bind(BX.findChild(c,{class:"crm-activity-command-add-event"},true,false),"click",this._createEventHandler);if(this.isTasksEnabled()){var d=BX.findChild(c,{class:"crm-activity-command-add-task"},true,false);if(d){BX.bind(d,"click",this._createTaskHandler)}}if(this.isCalendarEventsEnabled()){var g=BX.findChild(c,{class:"crm-activity-command-add-call"},true,false);if(g){BX.bind(g,"click",this._createCallHandler)}var h=BX.findChild(c,{class:"crm-activity-command-add-meeting"},true,false);if(h){BX.bind(h,"click",this._createMeetingHandler)}}if(this.isEmailsEnabled()){var m=BX.findChild(c,{class:"crm-activity-command-add-email"},true,false);if(m){BX.bind(m,"click",this._createEmailCreateHandler)}}BX.onCustomEvent(this,"toolbarBuildUp",[{container:c}])}var u=BX(this.getSetting("serviceContainerID","service_container"));if(u){BX.cleanNode(u)}if(typeof window["bxClock_"+this.getSetting("clockInputID","")]!=="undefined"){delete window["bxClock_"+this.getSetting("clockInputID","")]}this._markAsCompletedOnView=!!this.getSetting("markAsCompletedOnView",true);this._initialized=true;return this._id},release:function(){if(!this._initialized){return}var t=this.getToolbarContainer();if(!t){t=this.getContainer()}if(t&&!this.getSetting("readOnly",true)&&this.getSetting("enableToolbar",true)){if(this._eventListPageReloadHandler){BX.removeCustomEvent(window,"CrmBeforeEventPageReload",this._eventListPageReloadHandler)}BX.unbind(BX.findChild(t,{class:"crm-activity-command-add-event"},true,false),"click",this._createEventHandler);if(this.isTasksEnabled()){var e=BX.findChild(t,{class:"crm-activity-command-add-task"},true,false);if(e){BX.unbind(e,"click",this._createTaskHandler)}}if(this.isCalendarEventsEnabled()){var i=BX.findChild(t,{class:"crm-activity-command-add-call"},true,false);if(i){BX.unbind(i,"click",this._createCallHandler)}var n=BX.findChild(t,{class:"crm-activity-command-add-meeting"},true,false);if(n){BX.unbind(n,"click",this._createMeetingHandler)}}if(this.isEmailsEnabled()){var a=BX.findChild(t,{class:"crm-activity-command-add-email"},true,false);if(a){BX.unbind(a,"click",this._createEmailCreateHandler)}}this._initialized=false;BX.onCustomEvent(this,"release")}},getId:function(){return this._id},getType:function(){return this.getSetting("type",BX.CrmActivityEditorType.mixed)},isDiskEnabled:function(){return this.getSetting("enableDisk",false)},isWebDavEnabled:function(){return this.getSetting("enableWebDav",false)},getDefaultStorageTypeId:function(){var t=parseInt(this.getSetting("defaultStorageTypeId",BX.CrmActivityStorageType.undefined));if(t===BX.CrmActivityStorageType.undefined){if(this.isDiskEnabled()){t=BX.CrmActivityStorageType.disk}else if(this.isWebDavEnabled()){t=BX.CrmActivityStorageType.webdav}else{t=BX.CrmActivityStorageType.file}}return t},getSetting:function(t,e){return typeof this._settings[t]!="undefined"?this._settings[t]:e},setSetting:function(t,e){this._settings[t]=e},getOwnerType:function(){return this.getSetting("ownerType","")},getOwnerId:function(){var t=parseInt(this.getSetting("ownerID",0));return!isNaN(t)?t:0},isTaskTracingEnabled:function(){return this.getSetting("enableTaskTracing",false)},isTasksEnabled:function(){return this.getSetting("enableTasks",false)},isCalendarEventsEnabled:function(){return this.getSetting("enableCalendarEvents",false)},isEmailsEnabled:function(){return this.getSetting("enableEmails",false)},getContainer:function(){return BX(this.getSetting("containerID","action_list"))},getToolbarContainer:function(){var t=this.getSetting("toolbarID","");return BX.type.isNotEmptyString(t)?BX(t):null},getServiceContainer:function(){var t=this.getSetting("serviceContainerID","service_container");var e=BX(t);if(!e){e=BX.create("DIV",{props:{id:t}});document.body.appendChild(e)}return e},getHeading:function(){return BX.findChild(this.getContainer(),{tag:"tr",class:"crm-activity-table-head"},true,false)},showHeading:function(t){t=!!t;var e=this.getHeading();if(e){e.style.display=t?"":"none"}},getHint:function(){return BX.findChild(this.getContainer(),{tag:"div",class:"crm-view-no-actions-hint"},true,false)},showHint:function(t){t=!!t;var e=this.getHint();if(e){e.style.display=t?"":"none"}},getButton:function(){return BX(this.getSetting("buttonID"),"")},getItemIndexById:function(t){for(var e=0;e<this._items.length;e++){if(this._items[e].getId()==t){return e}}return-1},getItemById:function(t){var e=this.getItemIndexById(t);return e>=0?this._items[e]:null},isUIEnabled:function(){return this.getSetting("enableUI",false)},setItems:function(t,e){for(var i=0;i<this._items.length;i++){this._items[i].cleanLayout()}this._items=[];var n=this.isUIEnabled();var a;if(n){var r=BX.findChild(this.getContainer(),{tag:"table",class:"crm-activity-table"},true,false);if(!r){return}this.showHeading(true);var s=r.tBodies[0];for(var o=0;o<t.length;o++){a=t[o];a["enableUI"]=true;var l=s.insertRow(-1);l.className="crm-activity-row";var c=BX.CrmActivity.create(a,l,this);this._items.push(c);c.layout()}this.showHint(this._items.length===0);this.showAll();this._syncRows()}else{for(var d=0;d<t.length;d++){a=t[d];a["enableUI"]=false;this._items.push(BX.CrmActivity.create(a,null,this))}}},showAll:function(){if(!this.isUIEnabled()){return}var t=BX.findChild(this.getContainer(),{tag:"a",class:"crm-activity-command-show-all"},true,false);if(!t||t.style.display=="none"){return}t.style.display="none";var e=BX.findChildren(this.getContainer(),{tag:"tr",class:"crm-activity-row"},true);if(!e){return}for(var i=0;i<e.length;i++){var n=e[i];if(n.style.display=="none"){n.style.display=""}}},display:function(t){this.getContainer().style.display=t?"":"none";var e=this.getButton();if(t){BX.addClass(e,"bx-crm-view-fieldset-title-selected")}else{BX.removeClass(e,"bx-crm-view-fieldset-title-selected")}},openActivityDialog:function(t,e,i,n){var a=this.getItemById(e);if(!a){return}if(this._dlgOpenerId){window.clearTimeout(this._dlgOpenerId)}if(!i){i={}}var r=parseInt(a.getSetting("typeID","0"));var s=a.getSetting("ownerType",this.getSetting("ownerType",""));var o=parseInt(a.getSetting("ownerID",this.getSetting("ownerID","0")));var l=null;if(r===BX.CrmActivityType.call||r===BX.CrmActivityType.meeting||r===BX.CrmActivityType.activity){var c={ID:a.getSetting("ID",0),ownerType:s,ownerID:o,ownerTitle:a.getSetting("ownerTitle",""),ownerUrl:a.getSetting("ownerUrl",""),typeID:r,subject:a.getSetting("subject",""),description:a.getSetting("description",""),descriptionHtml:a.getSetting("descriptionHtml",""),descriptionBBCode:a.getSetting("descriptionBBCode",""),location:a.getSetting("location",""),start:a.getSetting("start",""),end:a.getSetting("end",""),deadline:a.getSetting("deadline",""),completed:a.getSetting("completed",false),notifyType:a.getSetting("notifyType",""),notifyValue:a.getSetting("notifyValue",""),priority:a.getSetting("priority",""),responsibleID:a.getSetting("responsibleID",""),responsibleName:a.getSetting("responsibleName",""),responsibleUrl:a.getSetting("responsibleUrl",""),storageTypeID:a.getSetting("storageTypeID",""),files:a.getSetting("files",[]),webdavelements:a.getSetting("webdavelements",[]),diskfiles:a.getSetting("diskfiles",[]),communicationsLoaded:a.getSetting("communicationsLoaded",true),communications:a.getSetting("communications",[]),uploadID:this.getSetting("uploadID",""),uploadControlID:this.getSetting("uploadControlID",""),uploadInputID:this.getSetting("uploadInputID",""),clockID:this.getSetting(r===BX.CrmActivityType.call?"callClockID":"meetingClockID",""),clockInputID:this.getSetting(r===BX.CrmActivityType.call?"callClockInputID":"meetingClockInputID",""),prefix:this.getSetting("prefix",""),serviceUrl:this.getSetting("serviceUrl",""),serverTime:this.getSetting("serverTime",""),imagePath:this.getSetting("imagePath",""),defaultStorageTypeId:this.getDefaultStorageTypeId(),userID:this.getSetting("userID",""),userFullName:this.getSetting("userFullName",""),userSearchJsName:this.getSetting("userSearchJsName",""),disableStorageEdit:this.getSetting("disableStorageEdit",false)};if(r===BX.CrmActivityType.call){c["direction"]=parseInt(a.getSetting("direction",BX.CrmActivityDirection.outgoing));c["callToFormat"]=this.getSetting("callToFormat",BX.CrmCalltoFormat.slashless)}l=BX.CrmActivityCalEvent.create(c,this,i)}else if(r===BX.CrmActivityType.email){var d={ID:a.getSetting("ID",0),ownerType:s,ownerID:o,ownerTitle:a.getSetting("ownerTitle",""),ownerUrl:a.getSetting("ownerUrl",""),typeID:BX.CrmActivityType.email,subject:a.getSetting("subject",""),description:a.getSetting("description",""),descriptionHtml:a.getSetting("descriptionHtml",""),descriptionBBCode:a.getSetting("descriptionBBCode",""),start:a.getSetting("start",""),end:a.getSetting("end",""),deadline:a.getSetting("deadline",""),completed:a.getSetting("completed",false),priority:a.getSetting("priority",""),responsibleID:a.getSetting("responsibleID",""),responsibleName:a.getSetting("responsibleName",""),responsibleUrl:a.getSetting("responsibleUrl",""),storageTypeID:a.getSetting("storageTypeID",""),files:a.getSetting("files",[]),webdavelements:a.getSetting("webdavelements",[]),diskfiles:a.getSetting("diskfiles",[]),communicationsLoaded:a.getSetting("communicationsLoaded",true),communications:a.getSetting("communications",[]),userFullName:this.getSetting("userFullName",""),userEmail:this.getSetting("userEmail",""),userEmail2:this.getSetting("userEmail2",""),crmEmail:this.getSetting("crmEmail",""),lastUsedEmail:this.getSetting("lastUsedEmail",""),lastUsedMailTemplateID:this.getSetting("lastUsedMailTemplateID",0),uploadID:this.getSetting("emailUploadContainerID",""),uploadControlID:this.getSetting("emailUploadControlID",""),uploadInputID:this.getSetting("emailUploadInputID",""),lheContainerID:this.getSetting("emailLheContainerID",""),lheJsName:this.getSetting("emailLheJsName",""),prefix:this.getSetting("prefix",""),serviceUrl:this.getSetting("serviceUrl",""),serverTime:this.getSetting("serverTime",""),imagePath:this.getSetting("imagePath",""),defaultStorageTypeId:this.getDefaultStorageTypeId(),mailTemplateData:this.getSetting("mailTemplateData",[])};d["direction"]=parseInt(a.getSetting("direction",BX.CrmActivityDirection.outgoing));if(this._markAsCompletedOnView&&!a.getSetting("completed",false)&&!BX.SidePanel){d["completed"]=true;this.setActivityCompleted(a.getSetting("ID",0),true,null,{disableNotification:true})}l=BX.CrmActivityEmail.create(d,this,i)}else if(r===BX.CrmActivityType.task){var g=parseInt(a.getSetting("associatedEntityID",0));if(g<=0){return}if(typeof top.window["taskIFramePopup"]==="object"&&typeof top.window["taskIFramePopup"].view==="function"){if(typeof window["tasksIFrameList"]==="undefined"){top.window["tasksIFrameList"]=[]}if(t===BX.CrmDialogMode.edit){top.window["taskIFramePopup"].edit(g,top.window["tasksIFrameList"])}else{top.window["taskIFramePopup"].view(g,top.window["tasksIFrameList"])}}else{var h=BX.message(t===BX.CrmDialogMode.edit?"CRM_TASK_EDIT_PATH":"CRM_TASK_VIEW_PATH");h=h.replace("#user_id#",BX.message("USER_ID"));h=h.replace("#task_id#",g);h=BX.util.add_url_param(h,{IFRAME:"Y",IFRAME_TYPE:"SIDE_SLIDER"});if(BX.SidePanel){BX.SidePanel.Instance.open(h)}else{window.top.location.href=h}}}else if(r===BX.CrmActivityType.provider&&BX.CrmActivityProvider){var m=a.getSetting("providerID","");if(m==="STORE_DOCUMENT"){var u=parseInt(a.getSetting("ownerID",0));if(u<=0){return}var p=BX.message("CMR_DEAL_DETAILS_PATH");p=p.replace("#deal_id#",u);p=BX.util.add_url_param(p,{IFRAME:"Y",IFRAME_TYPE:"SIDE_SLIDER"});if(BX.SidePanel){BX.SidePanel.Instance.open(p)}else{window.top.location.href=p}return}if(m==="REST_APP"){BX.rest.AppLayout.openApplication(a.getSetting("associatedEntityID",0),{action:"view_activity",activity_id:a.getSetting("ID",0)});return}var f={ID:a.getSetting("ID",0),ownerType:s,ownerID:o,ownerTitle:a.getSetting("ownerTitle",""),ownerUrl:a.getSetting("ownerUrl",""),subject:a.getSetting("subject",""),description:a.getSetting("description",""),descriptionHtml:a.getSetting("descriptionHtml",""),descriptionBBCode:a.getSetting("descriptionBBCode",""),start:a.getSetting("start",""),end:a.getSetting("end",""),deadline:a.getSetting("deadline",""),completed:a.getSetting("completed",false),priority:a.getSetting("priority",""),responsibleID:a.getSetting("responsibleID",""),responsibleName:a.getSetting("responsibleName",""),responsibleUrl:a.getSetting("responsibleUrl",""),storageTypeID:a.getSetting("storageTypeID",""),files:a.getSetting("files",[]),webdavelements:a.getSetting("webdavelements",[]),diskfiles:a.getSetting("diskfiles",[]),communicationsLoaded:a.getSetting("communicationsLoaded",true),communications:a.getSetting("communications",[]),userFullName:this.getSetting("userFullName",""),userEmail:this.getSetting("userEmail",""),userEmail2:this.getSetting("userEmail2",""),crmEmail:this.getSetting("crmEmail",""),lastUsedEmail:this.getSetting("lastUsedEmail",""),lastUsedMailTemplateID:this.getSetting("lastUsedMailTemplateID",0),uploadID:this.getSetting("emailUploadContainerID",""),uploadControlID:this.getSetting("emailUploadControlID",""),uploadInputID:this.getSetting("emailUploadInputID",""),lheContainerID:this.getSetting("emailLheContainerID",""),lheJsName:this.getSetting("emailLheJsName",""),prefix:this.getSetting("prefix",""),serviceUrl:this.getSetting("serviceUrl",""),serverTime:this.getSetting("serverTime",""),imagePath:this.getSetting("imagePath",""),defaultStorageTypeId:this.getDefaultStorageTypeId(),mailTemplateData:this.getSetting("mailTemplateData",[])};l=BX.CrmActivityProvider.create(f,this,i)}if(!l){return}l.addOnSave(this._saveHandler);l.addOnDialogClose(this._dlgCloseHandler);if(typeof n==="function"){l.addOnDialogClose(n)}var v=this;this._dlgOpenerId=window.setTimeout(function(){l.openDialog(t);v._dlgOpenerId=null},100)},setActivityCompleted:function(t,e,i,n){if(!BX.type.isPlainObject(n)){n={}}var a=!!n["disableNotification"];var r=this.getItemById(t);var s=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:t,action:"complete",ownertype:r?r.getSetting("ownerType",this.getSetting("ownerType","")):"",ownerid:r?parseInt(r.getSetting("ownerID",this.getSetting("ownerID",""))):0,completed:e?"Y":"N"});var o=this;BX.ajax({url:s,method:"POST",dataType:"json",data:{ACTION:"COMPLETE",COMPLETED:e?1:0,ITEM_ID:t,OWNER_TYPE:r?r.getSetting("ownerType",this.getSetting("ownerType","")):"",OWNER_ID:r?parseInt(r.getSetting("ownerID",this.getSetting("ownerID",""))):0},onsuccess:function(t){if(t["ITEM_ID"]){var e=t["ITEM_ID"];var n=!!t["COMPLETED"];var r=o.getItemById(e);if(r){r.setCompleted(n);r.layout()}if(BX.type.isFunction(i)){try{i(t)}catch(t){}}if(!a){var s=r?r.getSettings():{ID:e,completed:n};o._notifyActivityChange("UPDATE",s,true);BX.Crm.Activity.Planner.Manager.fireGlobalEvent("onAfterActivitySave",s)}}},onfailure:function(t){}})},setActivityPriority:function(t,e,i){var n=this.getItemById(t);if(!n){return false}var a=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:t,action:"set_priority",ownertype:n.getSetting("ownerType",this.getSetting("ownerType","")),ownerid:n.getSetting("ownerID",this.getSetting("ownerID","")),priority:e});var r=this;BX.ajax({url:a,method:"POST",dataType:"json",data:{ACTION:"SET_PRIORITY",ITEM_ID:t,PRIORITY:e,OWNER_TYPE:n.getSetting("ownerType",this.getSetting("ownerType","")),OWNER_ID:n.getSetting("ownerID",this.getSetting("ownerID",""))},onsuccess:function(t){if(t["ITEM_ID"]){var e=r.getItemById(t["ITEM_ID"]);if(e){e.setPriority(t["PRIORITY"]);e.layout();if(BX.type.isFunction(i)){try{i(t)}catch(t){}}r._notifyActivityChange("UPDATE",e.getSettings(),true)}}},onfailure:function(t){}})},postponeActivity:function(t,e,i){var n=this.getItemById(t);var a=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:t,action:"postpone",ownertype:n?n.getSetting("ownerType",this.getSetting("ownerType","")):"",ownerid:n?parseInt(n.getSetting("ownerID",this.getSetting("ownerID",""))):0,offset:e});var r=this;BX.ajax({url:a,method:"POST",dataType:"json",data:{ACTION:"POSTPONE",OFFSET:e,ITEM_ID:t,OWNER_TYPE:n?n.getSetting("ownerType",this.getSetting("ownerType","")):"",OWNER_ID:n?parseInt(n.getSetting("ownerID",this.getSetting("ownerID",""))):0},onsuccess:function(t){if(t["ITEM_ID"]){if(BX.type.isFunction(i)){try{i(t)}catch(t){}}}},onfailure:function(t){}})},viewActivity:function(t,e){if(!BX.type.isNumber(t)){t=parseInt(t);if(isNaN(t)){t=0}}if(t<=0){return}var i=this.getItemById(t);if(i){if(i["_settings"]&&i["_settings"]["customViewLink"]){BX.Crm.Page.open(i["_settings"]["customViewLink"])}else{this.openActivityDialog(BX.CrmDialogMode.view,t,e,null)}return}var n=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:t,action:"get_activity",ownertype:this.getSetting("ownerType",""),ownerid:this.getSetting("ownerID","")});BX.ajax({url:n,method:"POST",dataType:"json",data:{ACTION:"GET_ACTIVITY",ID:t,OWNER_TYPE:this.getSetting("ownerType",""),OWNER_ID:this.getSetting("ownerID","")},onsuccess:BX.delegate(function(i){if(typeof i["ACTIVITY"]!=="undefined"){if(i["ACTIVITY"]["customViewLink"]){BX.Crm.Page.open(i["ACTIVITY"]["customViewLink"])}else{this._handleActivityChange(i["ACTIVITY"]);this.openActivityDialog(BX.CrmDialogMode.view,t,e,null)}}},this),onfailure:function(t){}})},editActivity:function(t,e){t=parseInt(t);if(isNaN(t)){return}var i=this.getItemById(t);if(i){this.openActivityDialog(BX.CrmDialogMode.edit,t,e,null);return}var n=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:t,action:"get_activity",ownertype:this.getSetting("ownerType",""),ownerid:this.getSetting("ownerID","")});BX.ajax({url:n,method:"POST",dataType:"json",data:{ACTION:"GET_ACTIVITY",ID:t,OWNER_TYPE:this.getSetting("ownerType",""),OWNER_ID:this.getSetting("ownerID","")},onsuccess:BX.delegate(function(i){if(typeof i["ACTIVITY"]!=="undefined"){this._handleActivityChange(i["ACTIVITY"]);this.openActivityDialog(BX.CrmDialogMode.edit,t,e,null)}},this),onfailure:function(t){}})},deleteActivity:function(t,e,i){t=parseInt(t);if(isNaN(t)){return false}var n=this.getItemById(t);if(!n){return false}e=!!e;if(!e&&!window.confirm(BX.CrmActivityEditor.getMessage("deletionConfirm"))){return false}var a=this;var r=n.getSettings();var s=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:t,action:"delete",ownertype:n.getSetting("ownerType",this.getSetting("ownerType","")),ownerid:n.getSetting("ownerID",this.getSetting("ownerID",""))});BX.ajax({url:s,method:"POST",dataType:"json",data:{ACTION:"DELETE",ITEM_ID:t,OWNER_TYPE:n.getSetting("ownerType",this.getSetting("ownerType","")),OWNER_ID:n.getSetting("ownerID",this.getSetting("ownerID",""))},onsuccess:function(e){if(typeof e["DELETED_ITEM_ID"]!="undefined"&&e["DELETED_ITEM_ID"]==t){a._handleActivityDelete(r);if(BX.type.isFunction(i)){try{i(r)}catch(t){}}a._notifyActivityChange("DELETE",r,true)}},onfailure:function(t){}});return true},setActivityCommunications:function(t,e){var i=this.getItemById(t);if(i){i.setSetting("communicationsLoaded",true);i.setSetting("communications",e)}},handleAddEventClick:function(t){BX.PreventDefault(t);this.addEvent()},addEvent:function(){var t=this.getSetting("addEventUrl","");if(t===""){return}t=BX.util.add_url_param(t,{FORM_ID:"",ENTITY_TYPE:this.getOwnerType(),ENTITY_ID:this.getOwnerId()});var e=new BX.CDialog({content_url:t,width:"498",height:"275",resizable:false});e.Show();if(!this._eventListPageReloadHandler){this._eventListPageReloadHandler=BX.delegate(this._onEventListPageReload,this);BX.addCustomEvent(window,"CrmBeforeEventPageReload",this._eventListPageReloadHandler)}},_onEventListPageReload:function(t){BX.removeCustomEvent(window,"CrmBeforeEventPageReload",this._eventListPageReloadHandler);this._eventListPageReloadHandler=null;var e=this.getSetting("formId","");if(e===""){return}var i="bxForm_"+e;if(typeof window[i]!=="undefined"){var n=window[i];var a=this.getSetting("eventTabId");if(a!==n.GetActiveTabId()){n.SelectTab(a)}t.cancel=true}},addTask:function(t){if(!this.isTasksEnabled()){return}if(typeof t!=="object"){t={}}if(typeof t["ownerType"]==="undefined"){t["ownerType"]=this.getSetting("ownerType","")}if(typeof t["ownerID"]==="undefined"){t["ownerID"]=this.getSetting("ownerID","")}var e={UF_CRM_TASK:[BX.CrmOwnerTypeAbbr.resolve(t["ownerType"])+"_"+t["ownerID"]],TITLE:"CRM: ",TAGS:"crm"};if(typeof window.top["taskIFramePopup"]==="object"&&typeof window.top["taskIFramePopup"].add==="function"){window.top["taskIFramePopup"].add(e)}else{var i=BX.message("CRM_TASK_CREATION_PATH");i=i.replace("#user_id#",BX.message("USER_ID"));i=BX.util.add_url_param(i,BX.mergeEx(e,{IFRAME:"Y",IFRAME_TYPE:"SIDE_SLIDER"}));if(BX.SidePanel){BX.SidePanel.Instance.open(i)}else{window.top.location.href=i}}},handleAddTaskClick:function(t){BX.PreventDefault(t);this.addTask()},getUserEmails:function(){var t=[];var e=this.getSetting("emailTemplate",null);if(e&&e["from"]){t.push(e["from"])}var i=this.getSetting("crmEmail","");var n=this.getSetting("userEmail","");var a=this.getSetting("userEmail2","");if(n==i)n="";if(a==i||a==n)a="";var r=this.getSetting("userFullName","");if(a!=="")t.push(r===""?a:r+" <"+a+">");if(i!="")t.push(r===""?i:r+" <"+i+">");if(n!=="")t.push(r===""?n:r+" <"+n+">");return t},addCall:function(t){if(!this.isCalendarEventsEnabled()){return null}if(this.isLocked()){this.showLockMessage();return null}if(typeof t!=="object"){t={}}if(typeof t["ownerType"]==="undefined"){t["ownerType"]=this.getSetting("ownerType","")}if(typeof t["ownerID"]==="undefined"){t["ownerID"]=this.getSetting("ownerID","0")}if(typeof t["ownerUrl"]==="undefined"){t["ownerUrl"]=this.getSetting("ownerUrl","")}if(typeof t["ownerTitle"]==="undefined"){t["ownerTitle"]=this.getSetting("ownerTitle","")}t["typeID"]=BX.CrmActivityType.call;t["uploadID"]=this.getSetting("uploadID","");t["uploadControlID"]=this.getSetting("uploadControlID","");t["uploadInputID"]=this.getSetting("uploadInputID","");t["clockID"]=this.getSetting("callClockID","");t["clockInputID"]=this.getSetting("callClockInputID","");t["prefix"]=this.getSetting("prefix","");t["serviceUrl"]=this.getSetting("serviceUrl","");t["serverTime"]=this.getSetting("serverTime","");t["imagePath"]=this.getSetting("imagePath","");t["userID"]=this.getSetting("userID","");t["userFullName"]=this.getSetting("userFullName","");t["userSearchJsName"]=this.getSetting("userSearchJsName","");t["defaultStorageTypeId"]=this.getDefaultStorageTypeId();t["callToFormat"]=this.getSetting("callToFormat",BX.CrmCalltoFormat.slashless);var e=BX.CrmActivityCalEvent.create(t,this);e.addOnSave(this._saveHandler);e.addOnDialogClose(this._dlgCloseHandler);e.openDialog(BX.CrmDialogMode.edit);return e},addMeeting:function(t){if(!this.isCalendarEventsEnabled()){return null}if(this.isLocked()){this.showLockMessage();return null}if(typeof t!=="object"){t={}}if(typeof t["ownerType"]==="undefined"){t["ownerType"]=this.getSetting("ownerType","")}if(typeof t["ownerID"]==="undefined"){t["ownerID"]=this.getSetting("ownerID","0")}if(typeof t["ownerUrl"]==="undefined"){t["ownerUrl"]=this.getSetting("ownerUrl","")}if(typeof t["ownerTitle"]==="undefined"){t["ownerTitle"]=this.getSetting("ownerTitle","")}t["typeID"]=BX.CrmActivityType.meeting;t["uploadID"]=this.getSetting("uploadID","");t["uploadControlID"]=this.getSetting("uploadControlID","");t["uploadInputID"]=this.getSetting("uploadInputID","");t["clockID"]=this.getSetting("meetingClockID","");t["clockInputID"]=this.getSetting("meetingClockInputID","");t["prefix"]=this.getSetting("prefix","");t["serviceUrl"]=this.getSetting("serviceUrl","");t["serverTime"]=this.getSetting("serverTime","");t["imagePath"]=this.getSetting("imagePath","");t["userID"]=this.getSetting("userID","");t["userFullName"]=this.getSetting("userFullName","");t["userSearchJsName"]=this.getSetting("userSearchJsName","");t["defaultStorageTypeId"]=this.getDefaultStorageTypeId();var e=BX.CrmActivityCalEvent.create(t,this);e.addOnSave(this._saveHandler);e.addOnDialogClose(this._dlgCloseHandler);e.openDialog(BX.CrmDialogMode.edit);return e},addDelivery:function(t){if(BX.CrmEntityType.names.deal!==t.ownerType){return null}if(typeof t!=="object"){t={}}if(typeof t["ownerType"]==="undefined"){t["ownerType"]=this.getSetting("ownerType","")}if(typeof t["ownerID"]==="undefined"){t["ownerID"]=this.getSetting("ownerID","0")}if(typeof t["orderList"]==="undefined"){t["orderList"]=[]}var e=BX.CrmActivityDelivery.create(t,this);e.openDialog();return e},addEmail:function(t){if(!this.isEmailsEnabled()){return null}if(this.isLocked()){this.showLockMessage();return null}if(typeof t!=="object"){t={}}if(typeof t["ownerType"]==="undefined"){t["ownerType"]=this.getSetting("ownerType","")}if(typeof t["ownerID"]==="undefined"){t["ownerID"]=this.getSetting("ownerID","")}if(typeof t["ownerUrl"]==="undefined"){t["ownerUrl"]=this.getSetting("ownerUrl","")}if(typeof t["ownerTitle"]==="undefined"){t["ownerTitle"]=this.getSetting("ownerTitle","")}t["userFullName"]=this.getSetting("userFullName","");t["userEmail"]=this.getSetting("userEmail","");t["userEmail2"]=this.getSetting("userEmail2","");t["crmEmail"]=this.getSetting("crmEmail","");t["lastUsedEmail"]=this.getSetting("lastUsedEmail","");t["lastUsedMailTemplateID"]=this.getSetting("lastUsedMailTemplateID",0);t["uploadID"]=this.getSetting("emailUploadContainerID","");t["uploadControlID"]=this.getSetting("emailUploadControlID","");t["uploadInputID"]=this.getSetting("emailUploadInputID","");t["lheContainerID"]=this.getSetting("emailLheContainerID","");t["lheJsName"]=this.getSetting("emailLheJsName","");t["prefix"]=this.getSetting("prefix","");t["serviceUrl"]=this.getSetting("serviceUrl","");t["serverTime"]=this.getSetting("serverTime","");t["imagePath"]=this.getSetting("imagePath","");t["defaultStorageTypeId"]=this.getDefaultStorageTypeId();t["mailTemplateData"]=this.getSetting("mailTemplateData",[]);t["typeID"]=BX.CrmActivityType.email;var e=BX.CrmActivityEmail.create(t,this);e.addOnSave(this._saveHandler);e.addOnDialogClose(this._dlgCloseHandler);e.openDialog(BX.CrmDialogMode.edit);return e},saveWait:function(t,e){if(!BX.type.isPlainObject(e)){e={}}var i=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"save_wait"});BX.ajax({url:i,method:"POST",dataType:"json",data:{ACTION:"SAVE_WAIT",DATA:t},onsuccess:function(t){if(BX.type.isFunction(e["success"])){e["success"](t)}},onfailure:function(t){if(BX.type.isFunction(e["failure"])){e["failure"](t)}}})},handleAddCallClick:function(t){this.addCall();return BX.PreventDefault(t)},handleAddMeetingClick:function(t){this.addMeeting();return BX.PreventDefault(t)},addActivityChangeHandler:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onActivityChangeHandlers.length;e++){if(this._onActivityChangeHandlers[e]==t){return}}this._onActivityChangeHandlers.push(t)},removeActivityChangeHandler:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onActivityChangeHandlers.length;e++){if(this._onActivityChangeHandlers[e]==t){this._onActivityChangeHandlers.splice(e,1);return}}},reloadItems:function(){var t=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"get_activities",ownertype:this.getOwnerType(),ownerid:this.getOwnerId()});var e=this;BX.ajax({url:t,method:"POST",dataType:"json",data:{ACTION:"GET_ACTIVITIES",OWNER_TYPE:this.getOwnerType(),OWNER_ID:this.getOwnerId(),COMPLETED:this.getType()===BX.CrmActivityEditorType.history?1:0},onsuccess:function(t){e.setItems(t["DATA"]["ITEMS"],false)},onfailure:function(t){}})},isLocked:function(){return this._isLocked},setLocked:function(t){this._isLocked=!!t},getLockMessage:function(){return this._lockMessage},setLockMessage:function(t){this._lockMessage=BX.type.isNotEmptyString(t)?t:""},lockAndRelease:function(t){if(BX.type.isNotEmptyString(t)){this.setLockMessage(t)}this.setLocked(true);this.release()},showLockMessage:function(){if(this._lockMessage!==""){BX.NotificationPopup.show("activity_editor_locked",{messages:[this._lockMessage],timeout:1e3})}},handleAddEmailClick:function(t){this.addEmail();return BX.PreventDefault(t)},handleShowAllClick:function(t){BX.PreventDefault(t);this.showAll()},_handleActivitySave:function(t,e){if(!e){return}var i=e["ACTIVITY"];if(!i){return}this._handleActivityChange(i);this._notifyActivityChange(t&&parseInt(t.getId())>0?"UPDATE":"CREATE",i,true)},_handleActivityDialogClose:function(t){t.removeOnSave(this._saveHandler);t.removeOnDialogClose(this._dlgCloseHandler);var e=t.getButtonId();var i=this.getItemById(t.getId());if(!i){return}var n=i.getSettings();if(t.getMode()===BX.CrmDialogMode.view){if(e===BX.CrmActivityDialogButton.edit){this.openActivityDialog(BX.CrmDialogMode.edit,i.getId(),{markChanged:t.isChanged()})}else if(t.isChanged()){this._handleActivityChange(n);this._notifyActivityChange("UPDATE",n,true)}}else if(e===BX.CrmActivityDialogButton.cancel&&t.isChanged()){this._handleActivityChange(n);this._notifyActivityChange("UPDATE",n,true)}},_handleActivityChange:function(t){var e=typeof t["ID"]!="undefined"?parseInt(t["ID"]):0;var i=e>0?this.getItemIndexById(e):null;var n=i>=0?this._items[i]:null;var a=this.getType();var r=typeof t["completed"]!="undefined"?t["completed"]:false;if(a===BX.CrmActivityEditorType.history&&!r||a===BX.CrmActivityEditorType.recent&&r){this._removeItemByIndex(e>0?this.getItemIndexById(e):-1);return}t["enableUI"]=this.isUIEnabled();if(!this.isUIEnabled()){if(n){n.setSettings(t)}else{n=BX.CrmActivity.create(t,null,this);this._items.push(n)}}else{this.showAll();var s=BX.findChild(this.getContainer(),{tag:"table",class:"crm-activity-table"},true,false);if(!s){return}this.showHeading(true);var o=s.tBodies[0];var l=null;var c=0;if(n){this._items.splice(i,1);n.setSettings(t);c=this._calculateItemIndex(n);if(this._items.length>0&&c<this._items.length){this._items.splice(c,0,n)}else{this._items.push(n)}l=n.getRow();o.removeChild(l);if(o.rows.length>0&&c<o.rows.length){o.insertBefore(l,o.rows[c])}else{o.appendChild(l)}n.layout()}else{n=BX.CrmActivity.create(t,null,this);c=this._calculateItemIndex(n);if(c<this._items.length){this._items.splice(c,0,n)}else{this._items.push(n)}l=o.insertRow(c<o.rows.length?c:-1);l.className="crm-activity-row";n.setRow(l);n.layout()}this.showHint(this._items.length===0);this._syncRows()}},_handleActivityDelete:function(t){var e=typeof t["ID"]!="undefined"?parseInt(t["ID"]):0;this._removeItemByIndex(e>0?this.getItemIndexById(e):-1)},_removeItemByIndex:function(t){var e=t>=0?this._items[t]:null;if(!e){return}this._items.splice(t,1);if(this.isUIEnabled()){e.cleanLayout();this.showHeading(this._items.length>0);this.showHint(this._items.length===0);this.showAll();this._syncRows()}},_calculateItemIndex:function(t){var e=this._items.length;var i=t.getDeadline();var n,a;if(i!==null){for(var r=0;r<this._items.length;r++){curItem=this._items[r];n=curItem.getDeadline();if(n===null){continue}var s=i.getTime()-n.getTime();if(Math.abs(s)<1e3){s=0}if(s>0||s===0&&parseInt(t.getId())>parseInt(curItem.getId())){continue}e=r;break}}else{var o=t.getSubject();for(var l=0;l<this._items.length;l++){a=this._items[l].getSubject();n=this._items[l].getDeadline();if(n!==null||o<a){e=l;break}}}return e},_syncRows:function(){var t=BX.findChild(this.getContainer(),{tag:"table",class:"crm-activity-table"},true,false);if(!t){return}var e=t.tBodies[0];for(var i=0;i<e.rows.length;i++){if((i+1)%2===0){BX.addClass(e.rows[i],"crm-activity-row-even")}else{BX.removeClass(e.rows[i],"crm-activity-row-even")}}},_findTaskItem:function(t){for(var e=0;e<this._items.length;e++){var i=this._items[e];if(parseInt(i.getSetting("typeID",0))===BX.CrmActivityType.task&&parseInt(i.getSetting("associatedEntityID",0))===t){return i}}return null},_handleTaskAdd:function(t){if(this.getType()===BX.CrmActivityEditorType.history||!this.isTaskTracingEnabled()){return}var e=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"get_task",ownertype:this.getSetting("ownerType",""),ownerid:this.getSetting("ownerID",""),taskid:t});var i=this;BX.ajax({url:e,method:"POST",dataType:"json",data:{ACTION:"GET_TASK",OWNER_TYPE:this.getSetting("ownerType",""),OWNER_ID:this.getSetting("ownerID",""),TASK_ID:t},onsuccess:function(t){i._handleActivitySave(null,t)},onfailure:function(t){}})},_handleTaskChange:function(t){if(!this.isTaskTracingEnabled()){return}var e=this._findTaskItem(t);if(!e){return}var i=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:this.getSetting("ID","0"),action:"get_task",ownertype:this.getSetting("ownerType",""),ownerid:this.getSetting("ownerID",""),taskid:t});var n=this;window.setTimeout(function(){BX.ajax({url:i,method:"POST",dataType:"json",data:{ACTION:"GET_TASK",ITEM_ID:n.getSetting("ID","0"),OWNER_TYPE:n.getSetting("ownerType",""),OWNER_ID:n.getSetting("ownerID","0"),TASK_ID:t},onsuccess:function(t){n._handleActivitySave(null,t)},onfailure:function(t){}})},300)},_handleTaskDelete:function(t){var e=this._findTaskItem(t);if(e){e.remove(true);this._notifyActivityChange("DELETE",e.getSettings(),true)}},_notifyActivityChange:function(t,e,i,n){if(!n){n=this}this._notify(this._onActivityChangeHandlers,[this,t,e,n]);if(!!i){BX.CrmActivityEditor.notifyActivityChange(this,t,e)}},_notify:function(t,e){var i=[];for(var n=0;n<t.length;n++){i.push(t[n])}for(var a=0;a<i.length;a++){try{i[a].apply(this,e?e:[])}catch(t){}}},handleExternalActivityChange:function(t,e,i){if(t==this){return}var n=this.isUIEnabled();var a=typeof i["ID"]!="undefined"?parseInt(i["ID"]):0;if(e==="DELETE"){this._handleActivityDelete(i);this._notifyActivityChange(e,i,false,t)}else if(e==="CREATE"||e==="UPDATE"){this._handleActivityChange(i);this._notifyActivityChange(e,i,false,t)}},getWebDavElementInfo:function(t,e){var i=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"get_webdav_element_info",elementid:t});BX.ajax({url:i,method:"POST",dataType:"json",data:{ACTION:"GET_WEBDAV_ELEMENT_INFO",ELEMENT_ID:t},onsuccess:function(t){var i=t["DATA"]?t["DATA"]:{};if(BX.type.isFunction(e)){try{e(i["INFO"]?i["INFO"]:{})}catch(t){}}},onfailure:function(t){}})},prepareWebDavUploader:function(t,e,i){t=BX.type.isNotEmptyString(t)?t:"activity_uploader";var n=typeof BX.CrmWebDavUploader.items[t]!=="undefined"?BX.CrmWebDavUploader.items[t]:null;if(n){n.cleanLayout()}else{n=BX.CrmWebDavUploader.create(t,{urlSelect:this.getSetting("webDavSelectUrl",""),urlUpload:this.getSetting("webDavUploadUrl",""),urlShow:this.getSetting("webDavShowUrl",""),elementInfoLoader:BX.delegate(this.getWebDavElementInfo,this),msg:{loading:BX.CrmActivityEditor.getMessage("webdavFileLoading","Loading..."),file_exists:BX.CrmActivityEditor.getMessage("webdavFileAlreadyExists","File already exists!"),access_denied:"<p style='margin-top:0;'>"+BX.CrmActivityEditor.getMessage("webdavFileAccessDenied","Access denied!")+"</p>",title:BX.CrmActivityEditor.getMessage("webdavTitle","Files"),attachFile:BX.CrmActivityEditor.getMessage("webdavAttachFile","Attach file"),dragFile:BX.CrmActivityEditor.getMessage("webdavDragFile","Drag a files to this area"),selectFile:BX.CrmActivityEditor.getMessage("webdavSelectFile","or select a file in your computer"),selectFromLib:BX.CrmActivityEditor.getMessage("webdavSelectFromLib","Select from library"),loadFiles:BX.CrmActivityEditor.getMessage("webdavLoadFiles","Load files")}})}n.setMode(e);n.setValues(i);var a=BX.create("DIV",{attrs:{class:"bx-crm-dialog-activity-webdav-container"}});n.layout(a);return a},prepareDiskUploader:function(t,e,i){t=BX.type.isNotEmptyString(t)?t:"activity_uploader";var n=typeof BX.CrmDiskUploader.items[t]!=="undefined"?BX.CrmDiskUploader.items[t]:null;if(n){n.show(false);n.removeAllItems();n.cleanLayout()}else{n=BX.CrmDiskUploader.create(t,{msg:{diskAttachFiles:BX.CrmActivityEditor.getMessage("diskAttachFiles",""),diskAttachedFiles:BX.CrmActivityEditor.getMessage("diskAttachedFiles",""),diskSelectFile:BX.CrmActivityEditor.getMessage("diskSelectFile",""),diskSelectFileLegend:BX.CrmActivityEditor.getMessage("diskSelectFileLegend",""),diskUploadFile:BX.CrmActivityEditor.getMessage("diskUploadFile",""),diskUploadFileLegend:BX.CrmActivityEditor.getMessage("diskUploadFileLegend","")}})}n.setMode(e);n.setValues(i);var a=BX.create("DIV",{attrs:{class:"bx-crm-dialog-activity-webdav-container"}});n.layout(a);return a},prepareFileList:function(t,e){var i=BX.create("DIV",{attrs:{className:"bx-crm-dialog-view-activity-files"}});if(!(BX.type.isArray(t)&&t.length>0)){return i}if(!BX.type.isString(e)){e=""}for(var n=0;n<t.length;n++){var a=t[n];var r=typeof a["id"]!=="undefined"?a["id"].toString():"";if(r===""){r=Math.random().toString().substring(2)}var s="File"+r;if(e!==""){s=e+s}a["containerId"]=s;i.appendChild(BX.create("DIV",{attrs:{id:s,className:"bx-crm-dialog-view-activity-file"},children:[BX.create("SPAN",{attrs:{className:"bx-crm-dialog-view-activity-file-num"},text:(n+1).toString()}),BX.create("A",{attrs:{className:"bx-crm-dialog-view-activity-file-text",target:"_blank",href:a["url"]},text:a["name"]})]}))}return i},prepareFileUploader:function(t,e,i){if(BX.CFileInput.Items[t]){BX.CFileInput.Items[t].setFiles(i)}var n=BX(e);if(n){n.style.display=""}return n},getWebDavUploaderValues:function(t){var e=[];var i=BX.CrmWebDavUploader.items[t];var n=i?i.getValues():[];for(var a=0;a<n.length;a++){e.push(n[a]["ID"])}return e},getDiskUploaderValues:function(t){var e=BX.CrmDiskUploader.items[t];return e?e.getFileIds():[]},getFileUploaderValues:function(t){var e=[];if(BX.type.isElementNode(t)){e.push(t.value)}else if(BX.type.isArray(t)||typeof t.length!=="undefined"){for(var i=0;i<t.length;i++){e.push(t[i].value)}}return e},hideClock:function(t){var e=BX(t);if(e){e.style.display="none";this.getServiceContainer().appendChild(e)}},hideUploader:function(t,e){var i=BX(t);if(i){i.style.display="none";this.getServiceContainer().appendChild(i)}if(BX.CFileInput&&BX.CFileInput.Items&&BX.CFileInput.Items[e]){BX.CFileInput.Items[e].Clear()}},createOwnershipSelector:function(t,e){var i=this.getSetting("ownershipSelectorData");if(!i){return null}return CRM.Set(e,"test","",BX.type.isArray(i["items"])?i["items"]:[],false,false,["deal"],i["messages"]?i["messages"]:{},true)},getCommunicationHtml:function(t,e,i){var n=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"get_communication_html"});BX.ajax({url:n,method:"POST",dataType:"json",data:{ACTION:"GET_COMMUNICATION_HTML",TYPE_NAME:t,VALUE:e},onsuccess:function(t){var e=t["DATA"]?t["DATA"]:{};if(BX.type.isFunction(i)){try{i(e["HTML"]?e["HTML"]:{})}catch(t){}}},onfailure:function(t){}})},getActivityCommunications:function(t,e,i){var n=BX.type.isFunction(e);i=!!i;var a=this.getItemById(t);if(!a&&!i){if(n){try{e([])}catch(t){}}return}if(a&&a.getSetting("communicationsLoaded",true)){if(n){try{e(a.getSetting("communications",[]))}catch(t){}}return}var r=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:t,action:"get_activity_communications"});BX.ajax({url:r,method:"POST",dataType:"json",data:{ACTION:"GET_ACTIVITY_COMMUNICATIONS",ID:t},onsuccess:function(t){var i=typeof t["ACTIVITY_COMMUNICATIONS"]!=="undefined"&&typeof t["ACTIVITY_COMMUNICATIONS"]["DATA"]!=="undefined"?t["ACTIVITY_COMMUNICATIONS"]["DATA"]:{};var r=i["COMMUNICATIONS"]?i["COMMUNICATIONS"]:[];if(a){a.setSetting("communicationsLoaded",true);a.setSetting("communications",r)}if(n){try{e(r)}catch(t){}}},onfailure:function(t){}})},getActivityCommunicationsPage:function(t,e,i,n){var a=BX.type.isFunction(n);var r=this.getItemById(t);if(!r){if(a){try{n([])}catch(t){}}return}var s=BX.util.add_url_param(this.getSetting("serviceUrl",""),{id:t,action:"get_activity_communications_page"});BX.ajax({url:s,method:"POST",dataType:"json",data:{ACTION:"GET_ACTIVITY_COMMUNICATIONS_PAGE",ID:t,PAGE_SIZE:e,PAGE_NUMBER:i},onsuccess:function(t){var r=typeof t["ACTIVITY_COMMUNICATIONS_PAGE"]!=="undefined"&&typeof t["ACTIVITY_COMMUNICATIONS_PAGE"]["DATA"]!=="undefined"?t["ACTIVITY_COMMUNICATIONS_PAGE"]["DATA"]:{};var s=r["COMMUNICATIONS"]?r["COMMUNICATIONS"]:[];e=r["PAGE_SIZE"]?r["PAGE_SIZE"]:e;i=r["PAGE_NUMBER"]?r["PAGE_NUMBER"]:i;var o=r["PAGE_COUNT"]?r["PAGE_COUNT"]:1;if(a){try{n(s,e,i,o)}catch(t){}}},onfailure:function(t){}})},getActivityViewData:function(t,e){if(!BX.type.isFunction(e)){return}var i=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"get_activity_view_data"});BX.ajax({url:i,method:"POST",dataType:"json",data:{ACTION:"GET_ACTIVITY_VIEW_DATA",PARAMS:t},onsuccess:function(t){try{e(t)}catch(t){}},onfailure:function(t){}})}};BX.CrmActivityEditor._default=null;BX.CrmActivityEditor.getDefault=function(){return this._default};BX.CrmActivityEditor.setDefault=function(t){this._default=t};BX.CrmActivityEditor.items={};BX.CrmActivityEditor.create=function(t,e,i){var n=new BX.CrmActivityEditor;t=n.initialize(t,e,i);this.items[t]=n;if(!this._default){this._default=n}return n};BX.CrmActivityEditor.setActivities=function(t,e,i){var n=this.items[t];if(!n){return}n.setItems(e,i);var a=n.getOwnerType();var r=n.getOwnerId();for(var s in this.items){if(s==t){continue}var o=this.items[s];if(o.getOwnerType()==a&&o.getOwnerId()==r){o.reloadItems()}}};BX.CrmActivityEditor._copyObject=function(t){if(t==null||t==undefined||typeof t!=="object"){return t}var e=t.constructor();for(var i in t){if(t.hasOwnProperty(i)){e[i]=t[i]}}return e};BX.CrmActivityEditor.notifyActivityChange=function(t,e,i){for(var n in this.items){if(!this.items.hasOwnProperty(n)){continue}var a=this.items[n];if(t&&t.getId&&a.getId()===t.getId()){continue}a.handleExternalActivityChange(t,e,this._copyObject(i))}};BX.CrmActivityEditor.addTask=function(){if(this._default){this._default.addTask()}};BX.CrmActivityEditor.addCall=function(){if(this._default){this._default.addCall()}};BX.CrmActivityEditor.addMeeting=function(){if(this._default){this._default.addMeeting()}};BX.CrmActivityEditor.addEmail=function(t){if(this._default){this._default.addEmail(t)}};BX.CrmActivityEditor.display=function(t,e){if(typeof this.items[t]!="undefined"){this.items[t].display(e)}};BX.CrmActivityEditor.prepareDialogTitle=function(t,e){var i=BX.create("DIV",{attrs:{className:"bx-crm-dialog-tittle-wrap"},children:[BX.create("SPAN",{text:t,props:{className:"bx-crm-dialog-title-text"}})]});if(BX.type.isArray(e)&&e.length>0){for(var n=0;n<e.length;n++){i.appendChild(e[n])}}return i};BX.CrmActivityEditor.prepareDialogButtons=function(t){var e=[];for(var i=0;i<t.length;i++){var n=t[i];e.push(n["type"]==="link"?new BX.PopupWindowButtonLink(n["settings"]):new BX.PopupWindowButton(n["settings"]))}return e};BX.CrmActivityEditor.prepareDialogCell=function(t,e){var i=t.insertCell(-1);if(e["children"]){this.appendChild(i,e["children"])}BX.adjust(i,{attrs:e["attrs"]?e["attrs"]:{},props:e["props"]?e["props"]:{}});return i};BX.CrmActivityEditor.prepareDialogRow=function(t,e){var i=t.insertRow(-1);if(e["skipTitle"]!==true){if(e["headerCell"]){var n=e["headerCell"];if(!n["attrs"]){n["attrs"]={}}if(!BX.type.isNotEmptyString(n["attrs"]["className"])){n["attrs"]["className"]="bx-crm-dialog-activity-table-left"}this.prepareDialogCell(i,n)}else{this.prepareDialogCell(i,{attrs:{className:"bx-crm-dialog-activity-table-left"},children:[e["title"]?e["title"]:" "]})}}if(BX.type.isArray(e["contentCells"])){for(var a=0;a<e["contentCells"].length;a++){var r=e["contentCells"][a];if(!r["attrs"]){r["attrs"]={}}if(!BX.type.isNotEmptyString(r["attrs"]["className"])){r["attrs"]["className"]="bx-crm-dialog-activity-table-right"}this.prepareDialogCell(i,r)}}else if(e["content"]){var s={className:"bx-crm-dialog-activity-table-right"};if(e["skipTitle"]){s["colspan"]=2}this.prepareDialogCell(i,{attrs:s,children:BX.type.isArray(e["content"])?e["content"]:[e["content"]]})}};BX.CrmActivityEditor.appendChild=function(t,e){if(!BX.type.isElementNode(t)){return}if(BX.type.isArray(e)){for(var i=0;i<e.length;i++){this.appendChild(t,e[i])}}else if(BX.type.isDomNode(e)){t.appendChild(e)}else if(BX.type.isNotEmptyString(e)){t.appendChild(document.createTextNode(e))}};BX.CrmActivityEditor.insertAfter=function(t,e,i){var n=null;var a=false;for(var r=0;r<=t.childNodes.length;r++){if(a){n=t.childNodes[r];break}if(t.childNodes[r]==i){a=true}}if(n!=null){t.insertBefore(e,n)}else if(a){t.appendChild(e)}return e};BX.CrmActivityEditor.findDialogElement=function(t,e){if(!t){return null}var i=typeof t[e]!="undefined"?t[e]:"";if(!BX.type.isNotEmptyString(i)){return null}var n=BX(i);if(n){return n}var a=document.forms[t["form"]];if(a){try{n=a.elements[i]}catch(t){}}return n};BX.CrmActivityEditor.findDialogElements=function(t,e){if(!t){return[]}var i=document.forms[t["form"]];if(!i||!i.elements[e]){return[]}return i.elements[e]};BX.CrmActivityEditor.getJSObject=function(t,e,i){if(!i){i=window}var n=typeof t[e]!="undefined"?t[e]:"";return BX.type.isNotEmptyString(n)&&typeof i[n]!="undefined"?i[n]:null};BX.CrmActivityEditor.hideUploader=function(t,e){var i=BX(t);if(i){i.style.display="none";document.body.appendChild(i)}if(BX.CFileInput&&BX.CFileInput.Items&&BX.CFileInput.Items[e]){BX.CFileInput.Items[e].Clear()}};BX.CrmActivityEditor.hideClock=function(t){var e=BX(t);if(e){e.style.display="none";document.body.appendChild(e)}};BX.CrmActivityEditor.hideLhe=function(t){var e=BX(t);if(e){e.style.display="none";document.body.appendChild(e)}};BX.CrmActivityEditor.resolvePriorityClassName=function(t,e){t=parseInt(t);e=!!e;var i="bx-crm-dialog-priority-text";if(t===BX.CrmActivityPriority.high){i+=" bx-crm-dialog-priority-text-high"}else if(t===BX.CrmActivityPriority.medium){i+=" bx-crm-dialog-priority-text-medium"}else if(t===BX.CrmActivityPriority.low){i+=" bx-crm-dialog-priority-text-low"}if(e){i+=" bx-crm-dialog-priority-read-only-text"}return i};BX.CrmActivityEditor.getDateTimeFormat=function(){var t=BX.message("FORMAT_DATETIME");return BX.date.convertBitrixFormat(BX.type.isNotEmptyString(t)?t:"DD.MM.YYYY HH:MI:SS")};BX.CrmActivityEditor.getDateFormat=function(){var t=BX.message("FORMAT_DATE");return BX.date.convertBitrixFormat(BX.type.isNotEmptyString(t)?t:"DD.MM.YYYY")};BX.CrmActivityEditor.getTimeFormat=function(){var t=BX.message("FORMAT_DATETIME");var e=BX.message("FORMAT_DATE");var i=t.indexOf(e);var n=t;if(i>=0){n=t.replace(new RegExp("[\\s]*"+e+"[\\s]*"),"")}return BX.date.convertBitrixFormat(BX.type.isNotEmptyString(n)?n:"HH:MI:SS")};BX.CrmActivityEditor.joinDateTime=function(t,e){var i=BX.message("FORMAT_DATETIME");var n=BX.message("FORMAT_DATE");var a=i.indexOf(n);var r=i;if(a>=0){r=i.replace(new RegExp("[\\s]*"+n+"[\\s]*"),"")}return i.replace(new RegExp(n),t).replace(new RegExp(r),e)};BX.CrmActivityEditor.trimDateTimeString=function(t){var e=/(\d{2}):(\d{2}):(\d{2})/;var i=e.exec(t);if(!i||i.length<4){return t}var n=t.substring(0,i.index)+i[1]+":"+i[2];var a=i.index+8;if(a<t.length){n+=t.substring(a)}return n};BX.CrmActivityEditor.loadClock=function(t){var e=window["bxClock_"+t];if(e){e.pInput=BX(t);return}var i=window["bxLoadClock_"+t];if(BX.type.isFunction(i)){i(function(e){e.pInput=BX(t)})}};BX.CrmActivityEditor.onBeforeHide=function(){};BX.CrmActivityEditor.onAfterHide=function(){};BX.CrmActivityEditor.onBeforeShow=function(){};BX.CrmActivityEditor.onAfterShow=function(){};BX.CrmActivityEditor.onPopupTaskAdded=function(t){var e=BX.CrmActivityEditor.items;for(var i in e){if(e.hasOwnProperty(i)){e[i]._handleTaskAdd(t["id"])}}};BX.CrmActivityEditor.onPopupTaskChanged=function(t){var e=BX.CrmActivityEditor.items;for(var i in e){if(e.hasOwnProperty(i)){e[i]._handleTaskChange(t["id"])}}};BX.CrmActivityEditor.invalidateTaskPopupOverlay=function(){if(!BX.CrmActivityEditor._tryToRefreshTaskPopupOverlay()){return}window.setTimeout(function(){BX.CrmActivityEditor._tryToRefreshTaskPopupOverlay()},300);window.setTimeout(function(){BX.CrmActivityEditor._tryToRefreshTaskPopupOverlay()},600);window.setTimeout(function(){BX.CrmActivityEditor._tryToRefreshTaskPopupOverlay()},1200)};BX.CrmActivityEditor.invalidateTaskPopupOverlayCallback=null;BX.CrmActivityEditor.attachInterfaceGridReload=function(){if(!this.invalidateTaskPopupOverlayCallback){this.invalidateTaskPopupOverlayCallback=BX.delegate(this.invalidateTaskPopupOverlay,this);BX.addCustomEvent(window,"BXInterfaceGridAfterReload",this.invalidateTaskPopupOverlayCallback)}};BX.CrmActivityEditor._tryToRefreshTaskPopupOverlay=function(){if(typeof window.top.BX.TasksIFrameInst==="undefined"){return false}try{window.top.BX.TasksIFrameInst.__onWindowResize();window.top.BX.TasksIFrameInst.__onContentResize()}catch(t){return false}return true};BX.CrmActivityEditor.onPopupTaskDeleted=function(t){var e=BX.CrmActivityEditor.items;for(var i in e){if(e.hasOwnProperty(i)){e[i]._handleTaskDelete(t)}}};BX.CrmActivityEditor.parseEmail=function(t){var e=/([^<]+)<\s*([^>]+)\s*>/;var i=e.exec(t);return i?{name:i[1],address:i[2]}:{name:"",address:t}};BX.CrmActivityEditor.validateEmail=function(t){var e=/^.*[<]?\s*[\w\-\+_]+(\.[\w\-\+_]+)*@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*[>]?$/;return e.test(t)};BX.CrmActivityEditor.validatePhone=function(t){var e=/^\s*\+?[\d-\s\(\)]+\s*$/;return e.test(t)};BX.CrmActivityEditor.getMessage=function(t,e){return typeof this.messages!=="undefined"&&this.messages[t]?this.messages[t]:e};BX.CrmActivityEditor.viewActivity=function(t,e,i){var n=this.items[t];if(typeof n!=="undefined"){n.viewActivity(e,i)}};BX.CrmActivityEditor.createCommunicationSearch=function(t,e){return typeof BX.CrmCommunicationSearch!=="undefined"?BX.CrmCommunicationSearch.create(t,e):null};BX.CrmActivityEditor.getDefaultCommunication=function(t,e,i,n){var a=this.createCommunicationSearch("COMM_SEARCH_"+t+"_"+e+"_"+Math.random().toString().substring(2),{entityType:t,entityId:e,serviceUrl:n,communicationType:i,selectCallback:null,enableSearch:false});return a?a.getDefaultCommunication():null};BX.CrmActivityEditor._isFlvPlayerLoaded=false;BX.CrmActivityEditor.isFlvPlayerLoaded=function(){return this._isFlvPlayerLoaded};BX.CrmActivityEditor.loadFlvPlayer=function(){if(this._isFlvPlayerLoaded||!BX.type.isNotEmptyString(BX.CrmActivityEditor["flashPlayerApiUrl"])){return}BX.loadScript(BX.CrmActivityEditor["flashPlayerApiUrl"],function(){BX.CrmActivityEditor._isFlvPlayerLoaded=true;window.setTimeout(function(){BX.onCustomEvent(window,"CrmActivityEditorFlvPlayerLoaded")},0)})};BX.CrmActivityEditor.isAudioVideoFile=function(t){if(!BX.type.isNotEmptyString(t)){return false}t=t.toUpperCase();return t==="FLV"||t==="MP3"||t==="MP4"||t==="VP6"||t==="AAC"};BX.CrmActivityEditor._fileExtRx=/\.([a-z0-9]+)$/i;BX.CrmActivityEditor.getFileExtension=function(t){if(!BX.type.isNotEmptyString(t)){return""}var e=this._fileExtRx.exec(t);return BX.type.isArray(e)&&e.length>1?e[1]:""};BX.CrmDialogMode={edit:1,view:2};BX.CrmOwnerTypeAbbr={undefined:"",lead:"L",deal:"D",contact:"C",company:"CO",order:"O",smartInvoice:"SI",dynamicPrefix:"T",resolve:function(t){if(t==="LEAD"){return this.lead}else if(t==="DEAL"){return this.deal}else if(t==="CONTACT"){return this.contact}else if(t==="COMPANY"){return this.company}else if(t==="ORDER"){return this.order}else if(t==="SMART_INVOICE"){return this.smartInvoice}else if(t.indexOf("DYNAMIC_")===0){var e=Number(t.substr(8));if(e>0){return this.dynamicPrefix+e.toString(16)}}return this.undefined}};BX.CrmActivityType={undefined:0,meeting:1,call:2,task:3,email:4,activity:5,provider:6,getName:function(t){for(var e=0;e<this._items.length;e++){if(this._items[e]["value"]==t){return this._items[e]["text"]}}return"["+t+"]"},_items:[],getListItems:function(){return this._items},setListItems:function(t){this._items=t}};BX.CrmActivityStatus={undefined:0,waiting:1,completed:2,autoCompleted:3,isFinal:function(t){return t==this.completed||t==this.autoCompleted},getName:function(t,e){if(BX.type.isArray(this._items[t])){var i=this._items[t];for(var n=0;n<i.length;n++){if(i[n]["value"]==e){return i[n]["text"]}}}return"["+e+"]"},_items:{},getListItems:function(t){return BX.type.isArray(this._items[t])?this._items[t]:[]},setListItems:function(t){this._items=t}};BX.CrmActivityNotifyType={none:0,min:1,hour:2,day:3,descrTemplate:"",getDescription:function(t,e){if(t==0){return BX.CrmActivityEditor.getMessage("no")}return this.descrTemplate.replace(/%TYPE%/gi,this.getName(t)).replace(/%VALUE%/gi,e)},getName:function(t){if(t==0){return BX.CrmActivityEditor.getMessage("no")}for(var e=0;e<this._items.length;e++){if(this._items[e]["value"]==t){return this._items[e]["text"]}}return"["+t+"]"},getNext:function(t){if(!BX.type.isNumber(t)){t=parseInt(t)}return t<this.day?t+1:this.min},getAllNames:function(){var t=[];for(var e=0;e<this._items.length;e++){t.push(this._items[e]["text"])}return t},_items:[],getListItems:function(){return this._items},setListItems:function(t){this._items=t}};BX.CrmActivityPriority={none:0,low:1,medium:2,high:3,_items:[],getName:function(t){for(var e=0;e<this._items.length;e++){if(this._items[e]["value"]==t){return this._items[e]["text"]}}return"["+t+"]"},getListItems:function(){return this._items},setListItems:function(t){this._items=t}};BX.CrmActivityDirection={undefined:0,incoming:1,outgoing:2,getName:function(t,e){if(BX.type.isArray(this._items[t])){var i=this._items[t];for(var n=0;n<i.length;n++){if(i[n]["value"]==e){return i[n]["text"]}}}return"["+e+"]"},_items:[],getListItems:function(t){return BX.type.isArray(this._items[t])?this._items[t]:[]},setListItems:function(t){this._items=t}};BX.CrmActivityDialogButton={undefined:0,ok:1,cancel:2,edit:3,save:4};BX.CrmActivity=function(){this._viewMode=true;this._settings={};this._row=this._editor=null};BX.CrmActivity.prototype={initialize:function(t,e,i){this._settings=t?t:{};this._editor=i;this.setRow(e)},isUIEnabled:function(){return this.getSetting("enableUI",true)},remove:function(t){if(this._editor.deleteActivity(this.getSetting("ID"),t)){this.cleanLayout()}},handleDeleteClick:function(t){BX.PreventDefault(t);this.remove(false);return false},handleTypeClick:function(t){BX.PreventDefault(t);this.openViewDialog();return false},handleSubjectClick:function(t){BX.PreventDefault(t);this.openViewDialog();return false},openViewDialog:function(){this._editor.openActivityDialog(BX.CrmDialogMode.view,this.getId())},getId:function(){return this.getSetting("ID",0)},getStartDate:function(){var t=this.getSetting("start","");return t?BX.parseDate(t):null},getEndDate:function(){var t=this.getSetting("end","");return t?BX.parseDate(t):null},getDeadline:function(){var t=this.getSetting("deadline","");return t?BX.parseDate(t):null},getSubject:function(){return this.getSetting("subject","")},getRow:function(){return this._row},setRow:function(t){if(!this.isUIEnabled()){return}this._row=t;if(!t){return}var e=BX.findChild(this._row,{tag:"a",class:"crm-activity-type"},true,false);if(e){BX.bind(e,"click",BX.delegate(this.handleTypeClick,this))}var i=BX.findChild(this._row,{tag:"a",class:"crm-activity-subject"},true,false);if(i){BX.bind(i,"click",BX.delegate(this.handleSubjectClick,this))}var n=BX.findChild(this._row,{tag:"span",class:"crm-view-table-column-delete"},true,false);if(n){BX.bind(n,"click",BX.delegate(this.handleDeleteClick,this));n.setAttribute("title",BX.CrmActivityEditor.getMessage("deleteButtonTitle"))}},getSetting:function(t,e){return typeof this._settings[t]!="undefined"?this._settings[t]:e},saveSettings:function(){},getSettings:function(){return this._settings},setSettings:function(t){this._settings=t?t:{}},setSetting:function(t,e){this._settings[t]=e},setCompleted:function(t){this._settings["completed"]=t},setPriority:function(t){this._settings["priority"]=t},isCompleted:function(){return this.getSetting("completed",false)},layout:function(){if(!this.isUIEnabled()){return}var t=this._row;if(!t){return}BX.cleanNode(t,false);if(parseInt(this.getSetting("priority",BX.CrmActivityPriority.medium))===BX.CrmActivityPriority.high){BX.addClass(t,"crm-activity-row-important")}else{BX.removeClass(t,"crm-activity-row-important")}var e=BX.create("SPAN",{props:{className:"crm-view-table-column-delete"}});t.insertCell(-1).appendChild(e);BX.bind(e,"click",BX.delegate(this.handleDeleteClick,this));t.insertCell(-1).appendChild(BX.create("A",{props:{href:"#",className:"crm-activity-type"},text:BX.CrmActivityType.getName(this.getSetting("typeID","")),events:{click:BX.delegate(this.handleTypeClick,this)}}));t.insertCell(-1).appendChild(BX.create("A",{props:{href:"#",className:"crm-activity-subject"},text:this.getSetting("subject",""),events:{click:BX.delegate(this.handleSubjectClick,this)}}));var i=this.getSetting("deadline","");i=i!==""?BX.parseDate(i):null;t.insertCell(-1).appendChild(BX.create("SPAN",{text:i?BX.CrmActivityEditor.trimDateTimeString(BX.date.format(BX.CrmActivityEditor.getDateTimeFormat(),i)):"",style:{color:!this.isCompleted()&&i&&i<new Date?"#ff0000":""}}));t.insertCell(-1).appendChild(BX.create("SPAN",{text:this.getSetting("responsibleName","")}))},cleanLayout:function(){if(!this.isUIEnabled()){return}if(this._row){BX.cleanNode(this._row,true)}}};BX.CrmActivity.create=function(t,e,i){var n=new BX.CrmActivity;n.initialize(t,e,i);return n};BX.CrmActivityCalEvent=function(){this._settings={};this._options={};this._cntWrapper=null;this._ttlWrapper=null;this._dlgID="";this._dlg=null;this._dlgMode=BX.CrmDialogMode.view;this._dlgCfg={};this._onSaveHandlers=[];this._onDlgCloseHandlers=[];this._editor=null;this._communication=null;this._communicationSearch=null;this._isChanged=false;this._buttonId=BX.CrmActivityDialogButton.undefined;this._uploaderName="cal_event_uploader";this._storageTypeId=BX.CrmActivityStorageType.undefined;this._storageElementInfos=[];this._owner=null;this._userSearchPopup=null;this._salt="";this._callCreationHandler=BX.delegate(this._handleCallCreation,this);this._meetingCreationHandler=BX.delegate(this._handleMeetingCreation,this);this._emailCreationHandler=BX.delegate(this._handleEmailCreation,this);this._taskCreationHandler=BX.delegate(this._handleTaskCreation,this);this._expandHandler=BX.delegate(this._handleExpand,this);this._titleMenu=null;this._expanded=false;this._communicationWaiter=null;this._communicationsReady=true;this._requestIsRunning=false;this._hasFlvPlayer=false;this._disableStorageEdit=false};BX.CrmActivityCalEvent.prototype={initialize:function(t,e,i){this._settings=t?t:{};this._editor=e;this._options=i?i:{};var n=this.getSetting("ownerType","");var a=this.getSetting("ownerID","");this._salt=Math.random().toString().substring(2);this._communicationSearch=BX.CrmActivityEditor.createCommunicationSearch("COMM_SEARCH_"+n+"_"+a+"_"+this._salt,{entityType:n,entityId:a,serviceUrl:this.getSetting("serviceUrl",""),communicationType:this.getType()===BX.CrmActivityType.call?BX.CrmCommunicationType.phone:BX.CrmCommunicationType.undefined,selectCallback:BX.delegate(this._handleCommunicationSelect,this),enableSearch:true,enableDataLoading:false});this._isChanged=this.getOption("markChanged",false);this._disableStorageEdit=this.getOption("disableStorageEdit",false)||this.getSetting("disableStorageEdit",false)},getMode:function(){return this._dlgMode},getMessage:function(t){return BX.CrmActivityCalEvent.messages&&BX.CrmActivityCalEvent.messages[t]?BX.CrmActivityCalEvent.messages[t]:""},getSetting:function(t,e){return typeof this._settings[t]!="undefined"?this._settings[t]:e},setSetting:function(t,e){this._settings[t]=e},getOption:function(t,e){return typeof this._options[t]!="undefined"?this._options[t]:e},getType:function(){return this.getSetting("typeID",BX.CrmActivityType.activity)},getId:function(){return parseInt(this.getSetting("ID","0"))},getOwnerType:function(){return this.getSetting("ownerType","")},getOwnerId:function(){return this.getSetting("ownerID","")},canChangeOwner:function(){if(this.getMode()!==BX.CrmDialogMode.edit||this.getId()>0){return false}var t=this.getOwnerType();if(t==="LEAD"){return false}return t!=="DEAL"||this._editor.getOwnerType()!=="DEAL"},displayOwner:function(){return this.getSetting("ownerType","")==="DEAL"},getDefaultStorageTypeId:function(){return parseInt(this.getSetting("defaultStorageTypeId",BX.CrmActivityStorageType.file))},getStatusId:function(){return this.getSetting("completed",false)?BX.CrmActivityStatus.completed:BX.CrmActivityStatus.waiting},getStatusName:function(){return BX.CrmActivityStatus.getName(this.getType(),this.getStatusId())},isChanged:function(){return this._isChanged},getButtonId:function(){return this._buttonId},getEditor:function(){return this._editor},openDialog:function(t){var e=this.getId();if(!t){t=e>0?BX.CrmDialogMode.view:BX.CrmDialogMode.edit}if(BX.CrmActivityProvider){var i=BX.CrmActivityProvider.create(this._settings,this._editor,this._options);window.setTimeout(function(){i.openDialog(t)},10);return}this._dlgMode=t;var n=this._dlgID="CrmActivity"+(this.getType()==BX.CrmActivityType.meeting?"Meeting":"Call")+(t==BX.CrmDialogMode.edit?e>0?"Edit":"Create":"View")+(e>0?e:"");if(BX.CrmActivityCalEvent.dialogs[n]){BX.CrmActivityCalEvent.dialogs[n].destroy()}this._dlgCfg={};var a=this;this._dlg=new BX.PopupWindow(n,null,{className:"bx-crm-dialog-wrap bx-crm-dialog-activity-call-event",autoHide:false,draggable:true,offsetLeft:0,offsetTop:0,bindOptions:{forceBindPosition:false},closeByEsc:false,closeIcon:true,zIndex:-12,titleBar:{content:t==BX.CrmDialogMode.edit?this._prepareEditDlgTitle():this._prepareViewDlgTitle()},events:{onPopupShow:function(){if(a._ttlWrapper){BX.bind(BX.findParent(a._ttlWrapper,{class:"popup-window-titlebar"}),"dblclick",a._expandHandler)}},onPopupClose:BX.delegate(function(){if(this._communicationSearch){this._communicationSearch.closeDialog()}this._closeOwnerSelector();if(this._userSearchPopup){this._userSearchPopup.close()}this._releaseFlvPlayers();this._editor.hideClock(this.getSetting("clockID",""));this._editor.hideUploader(this.getSetting("uploadID",""),this.getSetting("uploadControlID",""));this._dlg.destroy()},this),onPopupDestroy:BX.proxy(function(){a._dlg=null;a._wrapper=null;a._ttlWrapper=null;delete BX.CrmActivityCalEvent.dialogs[n]},this)},content:t==BX.CrmDialogMode.edit?this._prepareEditDlgContent(n):this._prepareViewDlgContent(n),buttons:t==BX.CrmDialogMode.edit?this._prepareEditDlgButtons():this._prepareViewDlgButtons()});BX.CrmActivityCalEvent.dialogs[n]=this._dlg;var r=null;if(this._communicationSearch&&!this._communicationSearch.isDataLoaded()){if(!r){r={}}this._communicationSearch.prepareDataRequest(r)}if(e<=0){if(r){this._communicationsReady=false;this._findElement("contacts").appendChild(this._prepareCommunicationWaiter());this._editor.getActivityViewData(r,BX.delegate(this.processDataLoadingResponse,this))}else{var s=this._communicationSearch?this._communicationSearch.getDefaultCommunication():null;if(s){this._addCommunication(s.getSettings())}}}else{var o=this.getSetting("communicationsLoaded",true);if(!o){if(!r){r={}}r["ACTIVITY_COMMUNICATIONS"]={ID:e}}else{var l=this.getSetting("communications",[]);if(l.length>0){this._addCommunication(l[0])}}if(r){this._communicationsReady=false;this._findElement("contacts").appendChild(this._prepareCommunicationWaiter());this._editor.getActivityViewData(r,BX.delegate(this.processDataLoadingResponse,this))}}if(this.displayOwner()){this._setupOwner({type:this.getSetting("ownerType",""),id:parseInt(this.getSetting("ownerID",0)),title:this.getSetting("ownerTitle",""),url:this.getSetting("ownerUrl","")},!this.canChangeOwner())}if(this.canChangeOwner()){window.setTimeout(BX.delegate(function(){var t=this._editor.createOwnershipSelector(this._dlgID,BX(this.getDialogConfigValue("change_owner_button")));obCrm[t].AddOnSaveListener(BX.delegate(this._handleOwnerSelect,this));this.setDialogConfigValue("owner_selector_id",t)},this),0)}if(this._hasFlvPlayer){if(BX.CrmActivityEditor.isFlvPlayerLoaded()){this._initializeFlvPlayers()}else{BX.addCustomEvent(window,"CrmActivityEditorFlvPlayerLoaded",BX.delegate(this._onFlvPlayerLoad,this));BX.CrmActivityEditor.loadFlvPlayer()}}window.setTimeout(BX.delegate(function(){var t=this._findElement("subject");if(t){t.focus()}},this),0);this._dlg.show()},closeDialog:function(){if(this._communicationSearchController){this._communicationSearchController.stop();this._communicationSearchController=null}if(this._communicationSearch){this._communicationSearch.closeDialog()}if(this._webDavUploader){this._webDavUploader.cleanLayout()}this._closeOwnerSelector();if(this._titleMenu){this._titleMenu.removeCreateEmailListener(this._emailCreationHandler);this._titleMenu.removeCreateTaskListener(this._taskCreationHandler);this._titleMenu.removeCreateCallListener(this._callCreationHandler);this._titleMenu.removeCreateMeetingListener(this._meetingCreationHandler);this._titleMenu.cleanLayout()}if(!this._dlg){return}this._notifyDialogClose();this._dlg.close()},_lockSaveButton:function(){if(!this._dlg){return}var t=BX.findChild(this._dlg.popupContainer,{class:"popup-window-button-accept"},true,false);if(t){BX.removeClass(t,"popup-window-button-accept");BX.addClass(t,"popup-window-button-disable")}},_unlockSaveButton:function(){if(!this._dlg){return}var t=BX.findChild(this._dlg.popupContainer,{class:"popup-window-button-disable"},true,false);if(t){BX.removeClass(t,"popup-window-button-disable");BX.addClass(t,"popup-window-button-accept")}},_prepareEditDlgTitle:function(){var t="";var e=this.getId();if(e<=0){t=this.getType()==BX.CrmActivityType.meeting?BX.CrmActivityCalEvent.messages["addMeetingDlgTitle"]:BX.CrmActivityCalEvent.messages["addCallDlgTitle"]}else{var i=this.getSetting("subject","");t=BX.CrmActivityCalEvent.messages["editDlgTitle"];t=t.replace(/%SUBJECT%/i,i.length>0?i:"#"+e)}return this._ttlWrapper=BX.CrmActivityEditor.prepareDialogTitle(t)},_prepareEditDlgContent:function(t){var e=this.getId()<=0;var i=this.getType();var n=this._dlgCfg;var a=this._salt;var r=this._cntWrapper=BX.create("DIV",{attrs:{className:this.getType()==BX.CrmActivityType.meeting?"bx-crm-dialog-add-meeting-popup":"bx-crm-dialog-add-call-popup"}});n["error"]=this._prepareCode("activity_cal_event_error",a);r.appendChild(BX.create("DIV",{attrs:{className:"bx-crm-dialog-activity-error",style:"display:none;"},props:{id:n["error"]}}));n["form"]=this._prepareCode("activity_cal_event");var s=BX.create("FORM",{props:{name:n["form"]}});r.appendChild(s);var o=BX.create("TABLE",{attrs:{className:"bx-crm-dialog-activity-table"}});o.cellSpacing="0";o.cellPadding="0";o.border="0";s.appendChild(o);var l=BX.parseDate(this.getSetting("start",""));if(!l){l=new Date}n["startDate"]=this._prepareCode("startDate",a);n["startTime"]=this.getSetting("clockInputID","");n["enableNotifyWrapper"]=this._prepareCode("enableNotifyWapper");n["enableNotify"]=this._prepareCode("enableNotify");n["notifyVal"]=this._prepareCode("notifyVal");n["notifyTypeSwitch"]=this._prepareCode("notifyTypeSwitch");n["notifyType"]=this._prepareCode("notifyType");var c=this.getSetting("notifyType",BX.CrmActivityNotifyType.none);var d=this.getSetting("notifyValue",0);var g=c!=BX.CrmActivityNotifyType.none;var h=BX(n["startTime"]);if(h){h.className="bx-crm-dialog-input "+(BX.isAmPmMode()?"bx-crm-dialog-input-time-wide":"bx-crm-dialog-input-time");var m=BX.CrmActivityEditor.getTimeFormat().replace(/:?\s*s/,"");h.value=BX.date.format(m,l)}BX.CrmActivityEditor.loadClock(this.getSetting("clockInputID",""));var u=BX(this.getSetting("clockID",""));if(u){u.style.display="inline-block"}BX.CrmActivityEditor.prepareDialogRow(o,{title:BX.create("SPAN",{text:this.getMessage("datetime")+":"}),contentCells:[{attrs:{className:"bx-crm-dialog-activity-table-right"},children:[BX.create("DIV",{children:[BX.create("INPUT",{attrs:{className:"bx-crm-dialog-input bx-crm-dialog-input-date"},props:{type:"text",id:n["startDate"],name:n["startDate"],value:BX.date.format(BX.CrmActivityEditor.getDateFormat(),l)},style:{width:"70px"},events:{click:BX.delegate(this._handleDateInputClick,this)}}),BX.create("A",{props:{href:"javascript:void(0);",title:this.getMessage("setDate")},children:[BX.create("IMG",{attrs:{src:this.getSetting("imagePath","")+"calendar.gif",className:"calendar-icon",alt:this.getMessage("setDate")},events:{click:BX.delegate(this._handleDateInputClick,this),mouseover:BX.delegate(this._handleDateImageMouseOver,this),mouseout:BX.delegate(this._handleDateImageMouseOut,this)}})]}),u]}),BX.create("DIV",{attrs:{className:"bx-crm-dialog-remind-wrapper"+(g?"":" bx-crm-dialog-remind-wrapper-hidden")},props:{id:n["enableNotifyWrapper"]},children:[BX.create("INPUT",{attrs:{className:"bx-crm-dialog-checkbox",checked:g},props:{type:"checkbox",id:n["enableNotify"],name:n["enableNotify"]},events:{click:BX.delegate(this.handleNotifyToggle,this)}}),BX.create("LABEL",{attrs:{className:"bx-crm-dialog-label",for:n["enableNotify"]},text:this.getMessage("enableNotification")}),BX.create("INPUT",{attrs:{className:"bx-crm-dialog-input bx-crm-dialog-input-remind-time"},props:{type:"text",id:n["notifyVal"],name:n["notifyVal"],value:g?d:15}}),BX.create("SPAN",{attrs:{className:"bx-crm-dialog-input-remind-type"},props:{id:n["notifyTypeSwitch"],name:n["notifyTypeSwitch"]},html:BX.CrmActivityNotifyType.getName(g?c:BX.CrmActivityNotifyType.min),events:{click:BX.delegate(this._handleNotifyTypeChange,this)}}),BX.create("INPUT",{props:{id:n["notifyType"],name:n["notifyType"],type:"hidden",value:g?c:BX.CrmActivityNotifyType.min}})]})]}]});if(i===BX.CrmActivityType.activity||i===BX.CrmActivityType.meeting){var p=this.getSetting("location","");n["location"]=this._prepareCode("location");BX.CrmActivityEditor.prepareDialogRow(o,{title:BX.create("SPAN",{html:this.getMessage("location")+":"}),content:BX.create("INPUT",{attrs:{className:"bx-crm-dialog-input"},props:{type:"text",id:n["location"],name:n["location"],value:p}})})}if(i===BX.CrmActivityType.call){var f=parseInt(this.getSetting("direction",BX.CrmActivityDirection.outgoing));this.setSetting("direction",f);n["direction"]=this._prepareCode("direction");BX.CrmActivityEditor.prepareDialogRow(o,{title:BX.create("SPAN",{text:this.getMessage("direction")+":"}),content:[BX.create("SPAN",{attrs:{className:"bx-crm-dialog-status-text"},props:{id:n["direction"]},text:BX.CrmActivityDirection.getName(BX.CrmActivityType.call,f),events:{click:BX.delegate(this._handleDirectionChange,this)}})]})}n["contacts"]=this._prepareCode("contacts",a);var v=BX.create("DIV",{attrs:{className:"bx-crm-dialog-comm-block"},props:{id:n["contacts"]},events:{click:BX.delegate(this._openCommunicationDialog,this)}});BX.CrmActivityEditor.prepareDialogRow(o,{title:BX.create("SPAN",{html:this.getMessage("partner")+":"}),content:[v]});n["subject"]=this._prepareCode("subject");var y=this.getSetting("subject","");BX.CrmActivityEditor.prepareDialogRow(o,{title:BX.create("SPAN",{text:BX.CrmActivityCalEvent.messages["subject"]+":"}),content:BX.create("INPUT",{attrs:{className:"bx-crm-dialog-input",placeholder:this.getMessage(this.getType()==BX.CrmActivityType.meeting?"meetingSubjectHint":"callSubjectHint")},props:{type:"text",id:n["subject"],name:n["subject"],value:y}})});var C=this.getSetting("description","");var _=n["hasDescription"]=C!=="";if(!_){C=i==BX.CrmActivityType.meeting?BX.CrmActivityCalEvent.messages["meetingDescrHint"]:BX.CrmActivityCalEvent.messages["callDescrHint"]}n["description"]=this._prepareCode("description");BX.CrmActivityEditor.prepareDialogRow(o,{contentCells:[{attrs:{className:"bx-crm-dialog-activity-table-right"},children:[BX.create("TEXTAREA",{attrs:{className:"bx-crm-dialog-description-form"},props:{id:n["description"],name:n["description"],value:C},events:{focus:BX.delegate(this._handleEditDescriptionFocus,this),blur:BX.delegate(this._handleEditDescriptionBlur,this)}})]}]});var B=e?this.getSetting("userID",0):this.getSetting("responsibleID",0);var X=e?this.getSetting("userFullName",0):this.getSetting("responsibleName",0);n["responsibleSearch"]=this._prepareCode("responsibleSearch");n["responsibleData"]=this._prepareCode("responsibleData");var S=BX.create("INPUT",{attrs:{className:"bx-crm-dialog-input"},props:{type:"text",id:n["responsibleSearch"],value:X}});var I=BX.create("INPUT",{attrs:{},props:{type:"hidden",id:n["responsibleData"],value:B}});BX.CrmActivityEditor.prepareDialogRow(o,{title:BX.create("SPAN",{html:this.getMessage("responsible")+":"}),content:[S,I]});this._userSearchPopup=BX.CrmUserSearchPopup.createIfNotExists(t+"Responsible",{searchInput:S,dataInput:I,componentName:this.getSetting("userSearchJsName"),user:{id:B,name:X},serviceContainer:this._editor.getServiceContainer()});if(this.canChangeOwner()){n["change_owner_button"]=this._prepareCode("change_owner_button",a);var w=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-owner-change-text"},props:{id:n["change_owner_button"]},text:this.getMessage("change"),events:{click:BX.delegate(this._handleChangeOwnerClick,this)}});n["owner_info_wrapper"]=this._prepareCode("owner_info_wrapper",a);BX.CrmActivityEditor.prepareDialogRow(o,{title:BX.create("SPAN",{text:this.getMessage("owner")+":"}),content:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-block"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-info-wrapper"},props:{id:n["owner_info_wrapper"]}}),BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-button-wrapper"},children:[w]})]})]})}else if(this.displayOwner()){n["owner_info_wrapper"]=this._prepareCode("owner_info_wrapper",a);BX.CrmActivityEditor.prepareDialogRow(o,{title:BX.create("SPAN",{text:this.getMessage("owner")+":"}),content:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-block"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-info-wrapper"},props:{id:n["owner_info_wrapper"]}})]})]})}n["status_text"]=this._prepareCode("status_text");var D=this.getSetting("completed",false)?BX.CrmActivityStatus.completed:BX.CrmActivityStatus.waiting;var A=BX.create("DIV",{attrs:{className:"bx-crm-dialog-status"},text:this.getMessage("status")+":"});A.appendChild(BX.create("SPAN",{attrs:{className:"bx-crm-dialog-status-text"},props:{id:n["status_text"]},text:BX.CrmActivityStatus.getName(i,D),events:{click:BX.delegate(this._handleStatusChange,this)}}));BX.CrmActivityEditor.prepareDialogRow(o,{title:"",content:A});var T=this.getSetting("priority",BX.CrmActivityPriority.medium);n["priority_text"]=this._prepareCode("priority_text");var E=BX.create("SPAN",{attrs:{className:BX.CrmActivityEditor.resolvePriorityClassName(T)},props:{id:n["priority_text"]},events:{click:BX.delegate(this._handlePriorityChange,this)}});E.appendChild(BX.create("I"));E.appendChild(document.createTextNode(BX.CrmActivityPriority.getName(T)));BX.CrmActivityEditor.prepareDialogRow(o,{title:"",content:[document.createTextNode(this.getMessage("priority")+":"),E]});if(i===BX.CrmActivityType.activity){n["type_text"]=this._prepareCode("type_text");var b=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-activity-type-text"},props:{id:n["type_text"]},text:this.getMessage("undefinedType"),events:{click:BX.delegate(this._handleTypeChange,this)}});BX.CrmActivityEditor.prepareDialogRow(o,{title:"",content:[document.createTextNode(this.getMessage("type")+":"),b]})}if(!this._disableStorageEdit){var N=parseInt(this.getSetting("storageTypeID",BX.CrmActivityStorageType.undefined));if(isNaN(N)||N===BX.CrmActivityStorageType.undefined){N=this.getDefaultStorageTypeId()}this._storageTypeId=N;if(N===BX.CrmActivityStorageType.webdav){var M=this._editor.prepareWebDavUploader(this._uploaderName,this.getMode(),this.getSetting("webdavelements",[]));BX.CrmActivityEditor.prepareDialogRow(o,{content:M})}else if(N===BX.CrmActivityStorageType.disk){var P=this._editor.prepareDiskUploader(this._uploaderName,this.getMode(),this.getSetting("diskfiles",[]));BX.CrmActivityEditor.prepareDialogRow(o,{content:P})}else{BX.CrmActivityEditor.prepareDialogRow(o,{content:this._editor.prepareFileUploader(this.getSetting("uploadControlID",""),this.getSetting("uploadID",""),this.getSetting("files",[]))})}}return r},_prepareEditDlgButtons:function(){return BX.CrmActivityEditor.prepareDialogButtons([{type:"button",settings:{text:BX.CrmActivityEditor.getMessage("saveDlgButton"),className:"popup-window-button-accept",events:{click:BX.delegate(this._handleAcceptButtonClick,this)}}},{type:"link",settings:{text:BX.CrmActivityEditor.getMessage("cancelShortDlgButton"),className:"popup-window-button-link-cancel",events:{click:BX.delegate(this._handleCancelButtonClick,this)}}}])},_prepareViewDlgTitle:function(){var t=BX.CrmActivityCalEvent.messages["activity"];switch(this.getType()){case BX.CrmActivityType.meeting:t=BX.CrmActivityCalEvent.messages["meeting"];break;case BX.CrmActivityType.call:t=BX.CrmActivityCalEvent.messages["call"];break}var e=this.getSetting("subject","");var i=BX.CrmActivityCalEvent.messages["viewDlgTitle"];i=i.replace(/%TYPE%/gi,t);i=i.replace(/%SUBJECT%/gi,e.length>0?e:"#"+this.getSetting("ID","0"));this._titleMenu=BX.CrmActivityMenu.create("",{enableTasks:this._editor.isTasksEnabled(),enableCalendarEvents:this._editor.isCalendarEventsEnabled(),enableEmails:this._editor.isEmailsEnabled()},{createTask:this._taskCreationHandler,createCall:this._callCreationHandler,createMeeting:this._meetingCreationHandler,createEmail:this._emailCreationHandler});var n=this._ttlWrapper=BX.CrmActivityEditor.prepareDialogTitle(i);this._titleMenu.layout(n);return n},_prepareViewDlgContent:function(t){var e=this.getOption("enableInstantEdit",true);var i=this.getType();var n=this._dlgCfg;var a=this._salt;var r=this._cntWrapper=BX.create("DIV",{attrs:{className:this.getType()==BX.CrmActivityType.meeting?"bx-crm-dialog-view-meeting-popup":"bx-crm-dialog-view-call-popup"}});n["form"]=this._prepareCode("activity_cal_event",a);var s=BX.create("FORM",{props:{name:n["form"]}});r.appendChild(s);var o=BX.create("TABLE");o.cellSpacing="0";o.cellPadding="0";o.border="0";o.className=this.getType()==BX.CrmActivityType.meeting?"bx-crm-dialog-view-meeting-table":"bx-crm-dialog-view-call-table";s.appendChild(o);var l=BX.parseDate(this.getSetting("start",""));if(!l){l=new Date}BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("datetime")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[BX.CrmActivityEditor.trimDateTimeString(BX.date.format(BX.CrmActivityEditor.getDateTimeFormat(),l))]}]});var c=i==BX.CrmActivityType.meeting?this.getSetting("location",""):"";if(BX.type.isNotEmptyString(c)){BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("location")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[c]}]})}n["contacts"]=this._prepareCode("contacts",a);var d=BX.create("DIV",{attrs:{className:"bx-crm-dialog-comm-block"},props:{id:n["contacts"]}});if(i==BX.CrmActivityType.call){var g=parseInt(this.getSetting("direction",BX.CrmActivityDirection.outgoing));n["direction"]=this._prepareCode("direction");BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("direction")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[BX.CrmActivityDirection.getName(BX.CrmActivityType.call,g)]}]})}BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("partner")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[d]}]});n["status_text"]=this._prepareCode("status_text",a);var h=this.getSetting("completed",false)?BX.CrmActivityStatus.completed:BX.CrmActivityStatus.waiting;BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("status")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[BX.create("SPAN",{attrs:{className:e?"bx-crm-dialog-status-text":"bx-crm-dialog-status-text bx-crm-dialog-status-read-only-text"},props:{id:n["status_text"]},text:BX.CrmActivityStatus.getName(i,h),events:{click:e?BX.delegate(this._handleStatusChange,this):null}})]}]});var m=this.getSetting("priority",BX.CrmActivityPriority.medium);n["priority_text"]=this._prepareCode("priority_text",a);var u=BX.create("SPAN",{attrs:{className:BX.CrmActivityEditor.resolvePriorityClassName(m,!e)},props:{id:n["priority_text"]},events:{click:e?BX.delegate(this._handlePriorityChange,this):null}});u.appendChild(BX.create("I"));u.appendChild(document.createTextNode(BX.CrmActivityPriority.getName(m)));BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("priority")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[u]}]});BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("subject")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[this.getSetting("subject","")]}]});var p=this.getSetting("descriptionHtml","");if(p===""){p=this.getSetting("description","");if(p!==""){p=p.replace(/<script[^>]*>.*?<\/script>/g,"");p=p.replace(/<script[^>]*>/g,"");p=BX.util.htmlspecialchars(p);p=p.replace(/\r\n/g,"<br/>");p=p.replace(/(\r|\n)/g,"<br/>")}}if(p.length>0){s.appendChild(BX.create("DIV",{attrs:{className:"bx-crm-dialog-view-activity-descr"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-view-activity-descr-title"},text:this.getMessage("description")+":"}),BX.create("DIV",{attrs:{className:"bx-crm-dialog-view-activity-descr-text"},html:p})]}))}var f=this.getSetting("responsibleName","");if(BX.type.isNotEmptyString(f)){var v=f;var y=this.getSetting("responsibleUrl","");if(BX.type.isNotEmptyString(y)){v=BX.create("A",{attrs:{className:"bx-crm-dialog-responsible-user-link",href:y,target:"_blank"},text:f})}BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("responsible")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[v]}]})}if(this.displayOwner()){n["owner_info_wrapper"]=this._prepareCode("owner_info_wrapper",a);BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("owner")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-block"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-info-wrapper"},props:{id:n["owner_info_wrapper"]}})]})]}]})}var C=parseInt(this.getSetting("storageTypeID",BX.CrmActivityStorageType.undefined));if(isNaN(C)||C===BX.CrmActivityStorageType.undefined){C=this.getDefaultStorageTypeId()}this._storageTypeId=C;if(C===BX.CrmActivityStorageType.webdav){var _=this.getSetting("webdavelements",[]);for(var B=0;B<_.length;B++){var X={id:_[B]["ID"],name:_[B]["NAME"],url:_[B]["VIEW_URL"],ext:BX.CrmActivityEditor.getFileExtension(_[B]["NAME"]).toUpperCase()};if(!this._hasFlvPlayer&&BX.CrmActivityEditor.isAudioVideoFile(X["ext"])){this._hasFlvPlayer=true}this._storageElementInfos.push(X)}}else if(C===BX.CrmActivityStorageType.disk){var S=this.getSetting("diskfiles",[]);for(var I=0;I<S.length;I++){var w={id:S[I]["ID"],name:S[I]["NAME"],url:S[I]["VIEW_URL"],ext:BX.CrmActivityEditor.getFileExtension(S[I]["NAME"]).toUpperCase()};if(!this._hasFlvPlayer&&BX.CrmActivityEditor.isAudioVideoFile(w["ext"])){this._hasFlvPlayer=true}this._storageElementInfos.push(w)}}else{var D=this.getSetting("files",[]);for(var A=0;A<D.length;A++){var T={id:"",name:D[A]["fileName"],url:D[A]["fileURL"],ext:BX.CrmActivityEditor.getFileExtension(D[A]["fileName"]).toUpperCase()};if(!this._hasFlvPlayer&&BX.CrmActivityEditor.isAudioVideoFile(T["ext"])){this._hasFlvPlayer=true}this._storageElementInfos.push(T)}}if(this._storageElementInfos.length>0){var E=[];var b=[];for(var N=0;N<this._storageElementInfos.length;N++){var M=this._storageElementInfos[N];if(BX.CrmActivityEditor.isAudioVideoFile(M["ext"])){b.push(M)}else{E.push(M)}}if(E.length>0){BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("files")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[this._editor.prepareFileList(E,this._dlgID)]}]})}if(b.length>0){BX.CrmActivityEditor.prepareDialogRow(o,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("records")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[this._editor.prepareFileList(b,this._dlgID)]}]})}}return r},_prepareViewDlgButtons:function(){var t=[];t.push({type:"button",settings:{text:BX.CrmActivityEditor.getMessage("closeDlgButton"),className:"popup-window-button-accept",events:{click:BX.delegate(this._handleCancelButtonClick,this)}}});if(this.getOption("enableEditButton",true)){t.push({type:"link",settings:{text:BX.CrmActivityEditor.getMessage("editDlgButton"),className:"popup-window-button-link-cancel",events:{click:BX.delegate(this._handleAcceptButtonClick,this)}}})}return BX.CrmActivityEditor.prepareDialogButtons(t)},_onFlvPlayerLoad:function(){this._initializeFlvPlayers()},_releaseFlvPlayers:function(){if(!this._hasFlvPlayer){return}if(typeof window["jwplayer"]!=="undefined"){for(var t=0;t<this._storageElementInfos.length;t++){var e=this._storageElementInfos[t];var i=BX.type.isNotEmptyString(e["containerId"])?e["containerId"]:"";if(i!==""&&jwplayer(i)){jwplayer(i).stop();jwplayer.api.destroyPlayer(i)}}}this._hasFlvPlayer=false},_initializeFlvPlayers:function(){var t=BX.type.isNotEmptyString(BX.CrmActivityEditor["flashPlayerUrl"])?BX.CrmActivityEditor["flashPlayerUrl"]:"";if(t===""){return}for(var e=0;e<this._storageElementInfos.length;e++){var i=this._storageElementInfos[e];if(!BX.CrmActivityEditor.isAudioVideoFile(i["ext"])){continue}var n=BX.type.isNotEmptyString(i["containerId"])?i["containerId"]:"";var a=BX.type.isNotEmptyString(i["url"])?i["url"]:"";if(n===""||a===""){continue}var r=BX(n);BX.cleanNode(r);var s=n+"FwPlayer";r.appendChild(BX.create("DIV",{attrs:{className:"bx-crm-dialog-activity-fwplayer-wrapper"},children:[BX.create("DIV",{attrs:{id:s}})]}));r.appendChild(BX.create("A",{attrs:{className:"bx-crm-dialog-activity-fwplayer-download-link",href:a},text:this.getMessage("download")}));var o=BX.type.isNotEmptyString(i["name"])?i["name"]:"";if(this._storageTypeId===BX.CrmActivityStorageType.webdav){if(o===""){o="dummy.flv"}var l=new RegExp(o+"$","i");if(!l.test(a)){a+=o}}var c=jwplayer(s);if(c){c.setup({players:[{type:"html5"},{type:"flash",src:t}],file:a,provider:"video",controlbar:"bottom","logo.hide":"true",allowfullscreen:"false",icon:"false",height:"24px",width:"300px"})}}},_handleDateInputClick:function(t){var e=this._dlgCfg["startDate"];BX.calendar({node:BX(e),field:e,bTime:false,serverTime:this.getSetting("serverTime",""),bHideTimebar:true})},_handleDateImageMouseOver:function(t){BX.addClass(t.target,"calendar-icon-hover")},_handleDateImageMouseOut:function(t){if(!t){t=window.event}BX.removeClass(t.target,"calendar-icon-hover")},_createSelect:function(t,e){var i=BX.create("SELECT",t);for(var n=0;n<e.length;n++){var a=e[n];if(!a["value"]){continue}if(!a["text"]){a["text"]=a["value"]}var r=BX.create("OPTION",e[n]);if(!BX.browser.isIE){i.add(r,null)}else{try{i.add(r,i.options[null])}catch(t){i.add(r,null)}}}return i},_handleChangeOwnerClick:function(t){if(!this.canChangeOwner()){return}this._openOwnerSelector()},_openOwnerSelector:function(){var t=this.getDialogConfigValue("owner_selector_id","");if(t!==""&&obCrm&&obCrm[t]){obCrm[t].Open()}},_closeOwnerSelector:function(){var t=this.getDialogConfigValue("owner_selector_id","");if(t!==""&&obCrm&&obCrm[t]){obCrm[t].Clear();delete obCrm[t]}},_handleOwnerSelect:function(t){if(!this.canChangeOwner()){return}for(var e in t){if(t.hasOwnProperty(e)){this._setupOwner(t[e][0],false);break}}},_setupOwner:function(t,e){e=!!e;this._owner={typeName:t.type.toUpperCase(),id:parseInt(t.id)};var i=BX(this.getDialogConfigValue("owner_info_wrapper"));if(!i){return}BX.cleanNode(i,false);var n=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-owner-info"},children:[BX.create("A",{attrs:{className:"bx-crm-dialog-owner-info-link",href:t.url,target:"_blank"},text:t.title})]});if(!e){n.appendChild(BX.create("SPAN",{attrs:{className:"finder-box-selected-item-icon"},events:{click:BX.delegate(this._handleDeleteOwnerClick,this)}}))}i.appendChild(n)},_handleDeleteOwnerClick:function(t){if(!this.canChangeOwner()){return}if(!t){t=window.event}var e=t.target;if(e){BX.remove(BX.findParent(e,{tagName:"SPAN",className:"bx-crm-dialog-owner-info"}))}this._owner=null},_prepareOptions:function(t,e){if(!BX.type.isArray(t)){return[]}var i=[];for(var n=0;n<t.length;n++){var a=t[n];i.push(BX.create("OPTION",{props:{value:a["value"],text:a["text"],selected:a["value"]==e}}))}return i},_handleCallCreation:function(t){var e={};var i=this.getSetting("ownerType","");var n=parseInt(this.getSetting("ownerID",0));if(i!==""&&n>0){e["ownerType"]=i;e["ownerID"]=n;e["ownerTitle"]=this.getSetting("ownerTitle","");e["ownerUrl"]=this.getSetting("ownerUrl","")}e["subject"]=this.getSetting("subject","");e["description"]=this.getSetting("description","");e["priority"]=this.getSetting("priority","");e["direction"]=BX.CrmActivityDirection.outgoing;if(this.getType()===BX.CrmActivityType.call){e["communications"]=this.getSetting("communications",[])}else if(this.getSetting("ownerType","")==="DEAL"){var a=this.getSetting("communications",[]);var r=BX.type.isArray(a)&&a.length>0?a[0]:null;if(r){var s=r["entityType"];if(!BX.type.isNotEmptyString(s)){s=i}var o=parseInt(r["entityId"]);if(isNaN(o)||o<=0){o=n}var l=BX.CrmActivityEditor.getDefaultCommunication(s,o,BX.CrmCommunicationType.phone,this.getSetting("serviceUrl",""));if(l){e["communications"]=[l.getSettings()]}}}this._editor.addCall(e)},_handleMeetingCreation:function(t){var e={};var i=this.getSetting("ownerType","");var n=parseInt(this.getSetting("ownerID",0));if(i!==""&&n>0){e["ownerType"]=i;e["ownerID"]=n;e["ownerTitle"]=this.getSetting("ownerTitle","");e["ownerUrl"]=this.getSetting("ownerUrl","")}e["subject"]=this.getSetting("subject","");e["description"]=this.getSetting("description","");e["priority"]=this.getSetting("priority","");if(this.getType()===BX.CrmActivityType.meeting){e["location"]=this.getSetting("location","");e["communications"]=this.getSetting("communications",[])}else if(this.getSetting("ownerType","")==="DEAL"){var a=this.getSetting("communications",[]);var r=BX.type.isArray(a)&&a.length>0?a[0]:null;if(r){var s=r["entityType"];if(!BX.type.isNotEmptyString(s)){s=i}var o=parseInt(r["entityId"]);if(isNaN(o)||o<=0){o=n}var l=BX.CrmActivityEditor.getDefaultCommunication(s,o,BX.CrmCommunicationType.undefined,this.getSetting("serviceUrl",""));if(l){e["communications"]=[l.getSettings()]}}}this._editor.addMeeting(e)},_handleEmailCreation:function(t){var e={};var i=this.getSetting("ownerType","");var n=parseInt(this.getSetting("ownerID",0));if(i!==""&&n>0){e["ownerType"]=i;e["ownerID"]=n;e["ownerTitle"]=this.getSetting("ownerTitle","");e["ownerUrl"]=this.getSetting("ownerUrl","")}if(this.getSetting("ownerType","")==="DEAL"){var a=this.getSetting("communications",[]);var r=BX.type.isArray(a)&&a.length>0?a[0]:null;if(r){var s=r["entityType"];if(!BX.type.isNotEmptyString(s)){s=i}var o=parseInt(r["entityId"]);if(isNaN(o)||o<=0){o=n}var l=BX.CrmActivityEditor.getDefaultCommunication(s,o,BX.CrmCommunicationType.email,this.getSetting("serviceUrl",""));if(l){e["communications"]=[l.getSettings()]}}}this._editor.addEmail(e)},_handleTaskCreation:function(t){var e={};var i=this.getSetting("ownerType","");var n=parseInt(this.getSetting("ownerID",0));if(i!==""&&n>0){e["ownerType"]=i;e["ownerID"]=n}this._editor.addTask(e)},_syncStatus:function(){var t=this.getSetting("completed",false);var e=this._findElement("status_text");if(e){e.innerHTML=BX.CrmActivityStatus.getName(this.getType(),t?BX.CrmActivityStatus.completed:BX.CrmActivityStatus.waiting)}},_handleStatusChange:function(t){if(!this.getOption("enableInstantEdit",true)){return}this._isChanged=true;if(this._dlgMode===BX.CrmDialogMode.edit){this._settings["completed"]=!this.getSetting("completed",false);this._syncStatus()}else{var e=this;this._editor.setActivityCompleted(this.getId(),!this.getSetting("completed",false),function(t){e._settings["completed"]=!!t["COMPLETED"];e._syncStatus()})}},_handleTypeChange:function(t){if(!this.getOption("enableInstantEdit",true)){return}var e=this._findElement("type_text");if(!e){return}var i="crm-activity-type";if(typeof BX.PopupMenu.Data[i]!=="undefined"){BX.PopupMenu.Data[i].popupWindow.destroy();delete BX.PopupMenu.Data[i]}var n=this;BX.PopupMenu.show(i,e,[{text:BX.CrmActivityType.getName(BX.CrmActivityType.call),className:"bx-crm-action-type-link",onclick:function(t){n._setType(BX.CrmActivityType.call);this.popupWindow.close()}},{text:BX.CrmActivityType.getName(BX.CrmActivityType.meeting),className:"bx-crm-action-type-link",onclick:function(t){n._setType(BX.CrmActivityType.meeting);this.popupWindow.close()}}],{offsetTop:0,offsetLeft:-30})},_syncDirection:function(){var t=this._findElement("direction");if(t){t.innerHTML=BX.CrmActivityDirection.getName(BX.CrmActivityType.call,parseInt(this.getSetting("direction",BX.CrmActivityDirection.incoming)))}},_handleDirectionChange:function(t){if(!this.getOption("enableInstantEdit",true)){return}this._settings["direction"]=parseInt(this.getSetting("direction",BX.CrmActivityDirection.outgoing))===BX.CrmActivityDirection.outgoing?BX.CrmActivityDirection.incoming:BX.CrmActivityDirection.outgoing;this._syncDirection();this._settings["completed"]=this._settings["direction"]===BX.CrmActivityDirection.incoming;this._syncStatus()},_syncPriority:function(){var t=this.getSetting("priority",BX.CrmActivityPriority.low);var e=this._findElement("priority_text");if(!e){return}BX.cleanNode(e,false);e.className=BX.CrmActivityEditor.resolvePriorityClassName(t);e.appendChild(BX.create("I"));e.appendChild(document.createTextNode(BX.CrmActivityPriority.getName(t)))},_setPriority:function(t){this._isChanged=true;if(this._dlgMode===BX.CrmDialogMode.edit){this._settings["priority"]=t;this._syncPriority()}else{var e=this;this._editor.setActivityPriority(this.getId(),t,function(t){e._settings["priority"]=t["PRIORITY"];e._syncPriority()})}},_syncType:function(){var t=this.getSetting("type",BX.CrmActivityType.activity);var e=this._findElement("type_text");if(!e){return}BX.cleanNode(e,false);e.appendChild(document.createTextNode(BX.CrmActivityType.getName(t)))},_setType:function(t){if(this._dlgMode===BX.CrmDialogMode.edit){this._settings["type"]=t;this._syncType()}},_handleEditDescriptionFocus:function(t){var e=this._findElement("description");if(e){BX.addClass(e,"bx-crm-dialog-description-form-active");if(!this.getDialogParam("hasDescription",false)){e.value=""}}},_handleEditDescriptionBlur:function(t){var e=this._findElement("description");if(e){BX.removeClass(e,"bx-crm-dialog-description-form-active");var i=e.value!=="";this.setDialogParam("hasDescription",i);if(!i){e.value=this.getType()==BX.CrmActivityType.meeting?BX.CrmActivityCalEvent.messages["meetingDescrHint"]:BX.CrmActivityCalEvent.messages["callDescrHint"]}}},_handlePriorityChange:function(t){if(!this.getOption("enableInstantEdit",true)){return}var e=this._findElement("priority_text");if(!e){return}var i="crm-activity-priority";if(typeof BX.PopupMenu.Data[i]!=="undefined"){BX.PopupMenu.Data[i].popupWindow.destroy();delete BX.PopupMenu.Data[i]}var n=this;BX.PopupMenu.show(i,e,[{text:BX.CrmActivityPriority.getName(BX.CrmActivityPriority.low),className:"bx-crm-priority-low-link lead-menu-imp-active",onclick:function(t){n._setPriority(BX.CrmActivityPriority.low);this.popupWindow.close()}},{text:BX.CrmActivityPriority.getName(BX.CrmActivityPriority.medium),className:"bx-crm-priority-medium-link",onclick:function(t){n._setPriority(BX.CrmActivityPriority.medium);this.popupWindow.close()}},{text:BX.CrmActivityPriority.getName(BX.CrmActivityPriority.high),className:"bx-crm-priority-high-link",onclick:function(t){n._setPriority(BX.CrmActivityPriority.high);this.popupWindow.close()}}],{offsetTop:0,offsetLeft:-30})},handleNotifyToggle:function(t){BX.toggleClass(this._findElement("enableNotifyWrapper"),"bx-crm-dialog-remind-wrapper-hidden")},_handleNotifyTypeChange:function(t){var e=this._findElement("notifyType");var i=BX.CrmActivityNotifyType.getNext(e.value);e.value=i;this._findElement("notifyTypeSwitch").innerHTML=BX.CrmActivityNotifyType.getName(i)},getDialogValue:function(t,e){var i=this._findElement(t);return i?i.value:e},getDialogConfigValue:function(t,e){var i=this._dlgCfg;return i&&typeof i[t]!="undefined"?i[t]:e},setDialogConfigValue:function(t,e){this._dlgCfg[t]=e},getDialogForm:function(){var t=this._dlgCfg;return t&&typeof t["form"]!="undefined"?document.forms[t["form"]]:null},_findElement:function(t){return BX.CrmActivityEditor.findDialogElement(this._dlgCfg,t)},getDialogElements:function(t){var e=this._dlgCfg;if(!e){return[]}var i=document.forms[e["form"]];if(!i||!i.elements[t]){return[]}return i.elements[t]},getDialogParam:function(t,e){var i=this._dlgCfg;return i&&typeof i[t]!=="undefined"?i[t]:e},setDialogParam:function(t,e){this._dlgCfg[t]=e},_handleCancelButtonClick:function(){this._buttonId=BX.CrmActivityDialogButton.cancel;this._notifyDialogClose();this._releaseFlvPlayers();this._dlg.close()},_handleAcceptButtonClick:function(t){if(!this._communicationsReady){return}if(this._communicationSearch){this._communicationSearch.closeDialog()}if(!this._dlg){return}if(this._dlgMode==BX.CrmDialogMode.view){this._buttonId=BX.CrmActivityDialogButton.edit;this._notifyDialogClose();this._dlg.close();return}if(this._requestIsRunning){return}this._buttonId=BX.CrmActivityDialogButton.save;this._isChanged=true;var e=this.getType();var i={};i["ID"]=this.getId();var n=this.getDialogValue("startDate","");if(!BX.type.isNotEmptyString(n)){n=BX.formatDate(null,BX.message("FORMAT_DATE"))}var a=this.getDialogValue("startTime","");if(!BX.type.isNotEmptyString(a)){a=BX.formatDate(null,"HH:MI")}i["start"]=BX.CrmActivityEditor.joinDateTime(n,a);if(this._findElement("enableNotify").checked){i["notify"]={value:this.getDialogValue("notifyVal",""),type:this.getDialogValue("notifyType","")}}i["type"]=this.getSetting("type",e);i["priority"]=this.getSetting("priority",BX.CrmActivityPriority.medium);i["location"]=this.getDialogValue("location","");i["subject"]=this.getDialogValue("subject","");i["description"]=this.getDialogParam("hasDescription",false)?this.getDialogValue("description",""):"";i["completed"]=this.getSetting("completed",false)?1:0;i["responsibleID"]=this.getDialogValue("responsibleData","");var r="";var s=0;if(this.canChangeOwner()){r=this._owner?this._owner["typeName"]:"";s=this._owner?parseInt(this._owner["id"]):0}if(r===""||s<=0){var o=this.getSetting("ownerType","");var l=parseInt(this.getSetting("ownerID",0));if(o!=="DEAL"&&this._communication){r=this._communication.getEntityType();s=this._communication.getEntityId()}else{r=o;s=l}if(r===""||s<=0){this._clearError();this._showError(this.getMessage("ownerNotDefined"));return}}i["ownerType"]=r;i["ownerID"]=s;if(e==BX.CrmActivityType.call){i["direction"]=this.getSetting("direction",BX.CrmActivityDirection.outgoing)}if(this._communication){i["communication"]={id:this._communication.getId(),type:this._communication.getType(),entityType:this._communication.getEntityType(),entityId:this._communication.getEntityId(),value:this._communication.getValue()}}if(this._disableStorageEdit){i["disableStorageEdit"]="Y"}else{i["storageTypeID"]=this._storageTypeId;if(this._storageTypeId===BX.CrmActivityStorageType.webdav){i["webdavelements"]=this._editor.getWebDavUploaderValues(this._uploaderName)}else if(this._storageTypeId===BX.CrmActivityStorageType.disk){i["diskfiles"]=this._editor.getDiskUploaderValues(this._uploaderName)}else{i["files"]=this._editor.getFileUploaderValues(this.getDialogElements(this.getSetting("uploadInputID","")+"[]"));var c=this.getSetting("uploadControlID","");if(typeof BX.CFileInput!=="undefined"&&typeof BX.CFileInput.Items[c]!=="undefined"){i["uploadControlCID"]=BX.CFileInput.Items[c].CID}}}this._requestIsRunning=true;this._lockSaveButton();var d=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"save_activity"});var g=this;BX.ajax({url:d,method:"POST",dataType:"json",data:{ACTION:"SAVE_ACTIVITY",DATA:i},onsuccess:function(t){if(typeof t["ERROR"]!="undefined"){g._clearError();g._showError(t["ERROR"])}else{g._closeOwnerSelector();g._notifySave(t);g._notifyDialogClose();g._dlg.close()}g._requestIsRunning=false;g._unlockSaveButton()},onfailure:function(t){g._clearError();g._showError(t);g._requestIsRunning=false;g._unlockSaveButton()}})},_openCommunicationDialog:function(t){var e=this._findElement("contacts");if(!e){return}var i=this._dlgCfg;if(!i["contactSearch"]){i["contactSearch"]=this._prepareCode("contactSearch",this._salt);var n=BX(i["contactSearch"]);if(!n){n=BX.create("INPUT",{attrs:{className:"bx-crm-dialog-comm-search"},props:{id:i["contactSearch"],type:"text"},events:{keypress:BX.delegate(this._handleQuickSearchKeyPress,this)}});e.appendChild(n)}n.focus();if(!this._communicationSearchController){this._communicationSearchController=BX.CrmCommunicationSearchController.create(this._communicationSearch,n)}this._communicationSearchController.start()}this._communicationSearch.openDialog(e,BX.delegate(this._handleCommunicationDialogClose,this))},_getQuickSearch:function(){return this._dlgCfg["contactSearch"]?BX(this._dlgCfg["contactSearch"]):null},_handleCommunicationDialogClose:function(){if(this._communicationSearchController){this._communicationSearchController.stop();this._communicationSearchController=null}var t=this._findElement("contactSearch");if(t){BX.remove(t);delete this._dlgCfg["contactSearch"]}},_addCommunication:function(t){if(!t){return}if(this._communication){this._communication.cleanupLayout()}t["mode"]=this._dlgMode;t["callToFormat"]=this.getSetting("callToFormat",BX.CrmCalltoFormat.slashless);this._communication=BX.CrmActivityCommunication.create(t,this);this._communication.layout(this._findElement("contacts"),this._getQuickSearch());if(this._communicationSearch){this._communicationSearch.adjustDialogPosition()}this.validate()},_prepareCommunicationWaiter:function(){if(!this._communicationWaiter){this._communicationWaiter=BX.create("DIV",{attrs:{className:"bx-crm-dialog-comm-wait-wrapper"},text:BX.CrmActivityEditor.getMessage("dataLoading")})}return this._communicationWaiter},processDataLoadingResponse:function(t){var e=this._findElement("contacts");if(this._communicationWaiter){e.removeChild(this._communicationWaiter)}var i;if(typeof t["ACTIVITY_COMMUNICATIONS"]!=="undefined"){var n=typeof t["ACTIVITY_COMMUNICATIONS"]["DATA"]!=="undefined"?t["ACTIVITY_COMMUNICATIONS"]["DATA"]:{};i=n["COMMUNICATIONS"]&&BX.type.isArray(n["COMMUNICATIONS"])?n["COMMUNICATIONS"]:[];this.setSetting("communications",i);this.setSetting("communicationsLoaded",true);if(i.length>0){this._addCommunication(i[0])}this._editor.setActivityCommunications(this.getId(),i)}this._communicationsReady=true;if(this._communicationSearch&&!this._communicationSearch.isDataLoaded()){this._communicationSearch.processDataResponse(t)}if(this.getId()<=0&&this._dlgMode===BX.CrmDialogMode.edit&&!this._communication){var a=this._communicationSearch?this._communicationSearch.getDefaultCommunication():null;if(a){this._addCommunication(a.getSettings())}}},_loadCommunications:function(){this._communicationsReady=false;if(!this._communicationWaiter){this._communicationWaiter=BX.create("DIV",{attrs:{className:"bx-crm-dialog-comm-wait-wrapper"},text:BX.CrmActivityEditor.getMessage("dataLoading")})}var t=this._communicationWaiter;var e=this._findElement("contacts");e.appendChild(t);var i=this;this._editor.getActivityCommunications(this.getId(),function(n){if(!BX.type.isArray(n)){n=[]}i.setSetting("communications",n);i.setSetting("communicationsLoaded",true);e.removeChild(t);if(n.length>0){i._addCommunication(n[0])}i._communicationsReady=true})},_handleCommunicationSelect:function(t){this._communicationSearch.closeDialog();this._addCommunication(t.getSettings())},deleteCommunication:function(t){this._communication=null;this.validate()},_prepareCode:function(t,e){e=BX.type.isNotEmptyString(e)?e:"";var i=this.getSetting("prefix","");return(i.length>0?i+"_":"")+(e.length>0?e+"_":"")+t},addOnSave:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onSaveHandlers.length;e++){if(this._onSaveHandlers[e]==t){return}}this._onSaveHandlers.push(t)},removeOnSave:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onSaveHandlers.length;e++){if(this._onSaveHandlers[e]==t){this._onSaveHandlers.splice(e,1);return}}},_notifySave:function(t){this._notify(this._onSaveHandlers,[this,t])},addOnDialogClose:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onDlgCloseHandlers.length;e++){if(this._onDlgCloseHandlers[e]==t){return}}this._onDlgCloseHandlers.push(t)},removeOnDialogClose:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onDlgCloseHandlers.length;e++){if(this._onDlgCloseHandlers[e]==t){this._onDlgCloseHandlers.splice(e,1);return}}},_notifyDialogClose:function(){this._notify(this._onDlgCloseHandlers,[this])},_notify:function(t,e){var i=[];for(var n=0;n<t.length;n++){i.push(t[n])}for(var a=0;a<i.length;a++){try{i[a].apply(this,e?e:[])}catch(t){}}},_tryAddCustomCommunication:function(t){if(!BX.type.isNotEmptyString(t)){return false}this._addCommunication({entityId:"0",entityTitle:"",entityType:"CONTACT",type:this.getType()===BX.CrmActivityType.call?"PHONE":"",value:t});return true},_handleQuickSearchKeyPress:function(t){if(!t){t=window.event}if(t.keyCode!==13&&t.keyCode!==27){return}var e=this._getQuickSearch();if(!e){return}if(t.keyCode===27){e.value="";e.focus();return}if(this._tryAddCustomCommunication(e.value,true)){e.value="";e.focus()}},validate:function(){this._clearError();if(this._communication&&!this._communication.isValid()){this._showError(this._communication.getError())}},_showError:function(t){var e=BX(this._dlgCfg["error"]);if(!e){return}if(!BX.type.isArray(t)){t=[t]}for(var i=0;i<t.length;i++){e.appendChild(BX.create("P",{text:t[i]}))}e.style.display="";if(this._communicationSearch){this._communicationSearch.adjustDialogPosition()}},_clearError:function(){var t=BX(this._dlgCfg["error"]);if(!t){return}t.innerHTML="";t.style.display="none";if(this._communicationSearch){this._communicationSearch.adjustDialogPosition()}},_handleExpand:function(){if(!this._dlg){return}if(!this._expanded){BX.addClass(this._dlg.popupContainer,"bx-crm-dialog-activity-call-event-wide");BX.removeClass(this._dlg.popupContainer,"bx-crm-dialog-activity-call-event")}else{BX.addClass(this._dlg.popupContainer,"bx-crm-dialog-activity-call-event");BX.removeClass(this._dlg.popupContainer,"bx-crm-dialog-activity-call-event-wide")}this._expanded=!this._expanded;var t=BX.GetWindowInnerSize(document);var e=BX.GetWindowScrollPos(document);var i=BX.pos(this._dlg.popupContainer);this._dlg.popupContainer.style.left=e.scrollLeft+(t.innerWidth-i.width)/2+"px";this._dlg.popupContainer.style.top=e.scrollTop+(t.innerHeight-i.height)/2+"px"}};BX.CrmActivityCalEvent.dialogs={};BX.CrmActivityCalEvent.create=function(t,e,i){var n=new BX.CrmActivityCalEvent;n.initialize(t,e,i);return n};BX.CrmActivityEmail=function(){this._settings={};this._options={};this._cntWrapper=null;this._ttlWrapper=null;this._dlg=null;this._dlgMode=BX.CrmDialogMode.view;this._dlgCfg={};this._onSaveHandlers=[];this._onDlgCloseHandlers=[];this._editor=null;this._communications=[];this._communicationSearch=null;this._communicationSearchController=null;this._isChanged=false;this._buttonId=BX.CrmActivityDialogButton.undefined;this._uploaderName="email_uploader";this._storageTypeId=BX.CrmActivityStorageType.undefined;this._owner=null;this._salt="";this._callCreationHandler=BX.delegate(this._handleCallCreation,this);this._meetingCreationHandler=BX.delegate(this._handleMeetingCreation,this);this._emailCreationHandler=BX.delegate(this._handleEmailCreation,this);this._taskCreationHandler=BX.delegate(this._handleTaskCreation,this);this._expandHandler=BX.delegate(this._handleExpand,this);this._titleMenu=null;this._expanded=false;this._templateSelector=null;this._templateId=0;this._communicationWaiter=null;this._communicationsReady=true;this._showAllCommunicationsButton=null;this._requestIsRunning=false;this._paginator=null};BX.CrmActivityEmail.prototype={initialize:function(t,e,i){this._settings=t?t:{};this._editor=e;this._options=i?i:{};this._isChanged=this.getOption("markChanged",false);var n=this.getSetting("ownerType","");var a=this.getSetting("ownerID","");this._salt=Math.random().toString().substring(2);if(typeof BX.CrmCommunicationSearch!=="undefined"){this._communicationSearch=BX.CrmCommunicationSearch.create("COMM_SEARCH_"+n+"_"+a,{entityType:n,entityId:a,serviceUrl:this.getSetting("serviceUrl",""),communicationType:BX.CrmCommunicationType.email,selectCallback:BX.delegate(this._handleCommunicationSelect,this),enableSearch:true,enableDataLoading:false})}},getMode:function(){return this._dlgMode},getSetting:function(t,e){return typeof this._settings[t]!="undefined"?this._settings[t]:e},setSetting:function(t,e){this._settings[t]=e},getOption:function(t,e){return typeof this._options[t]!="undefined"?this._options[t]:e},getMessage:function(t){return BX.CrmActivityEmail.messages&&BX.CrmActivityEmail.messages[t]?BX.CrmActivityEmail.messages[t]:""},getDialogValue:function(t,e){var i=this._findElement(t);return i?i.value:e},setDialogValue:function(t,e){var i=this._findElement(t);if(i){i.value=e}},getDialogConfigValue:function(t,e){var i=this._dlgCfg;return i&&typeof i[t]!="undefined"?i[t]:e},setDialogConfigValue:function(t,e){this._dlgCfg[t]=e},getType:function(){return BX.CrmActivityType.email},getId:function(){return parseInt(this.getSetting("ID","0"))},getMessageType:function(){return this.getSetting("messageType","")},getOriginalMessageId:function(){return this.getSetting("originalMessageID",0)},getOwnerType:function(){return this.getSetting("ownerType","")},getOwnerId:function(){return this.getSetting("ownerID","")},canChangeOwner:function(){if(this.getMode()!==BX.CrmDialogMode.edit||this.getId()>0){return false}var t=this.getOwnerType();if(t==="LEAD"){return false}return t!=="DEAL"||this._editor.getOwnerType()!=="DEAL"},displayOwner:function(){return this.getSetting("ownerType","")==="DEAL"},getDefaultStorageTypeId:function(){return parseInt(this.getSetting("defaultStorageTypeId",BX.CrmActivityStorageType.file))},openDialog:function(t){var e=this.getId();if(!t){t=e>0?BX.CrmDialogMode.view:BX.CrmDialogMode.edit}if(BX.CrmActivityProvider&&(t==BX.CrmDialogMode.view||top.BX.SidePanel)){var i=BX.CrmActivityProvider.create(this._settings,this._editor,this._options,this);window.setTimeout(function(){i.openDialog(t)},10);return}this._dlgMode=t;var n="CrmActivityEmail"+(t===BX.CrmDialogMode.edit?"Edit":"View")+e;if(BX.CrmActivityEmail.dialogs[n]){return}var a=this;this._dlg=new BX.PopupWindow(n,null,{className:"bx-crm-dialog-wrap bx-crm-dialog-activity-email",autoHide:false,draggable:true,offsetLeft:0,offsetTop:0,bindOptions:{forceBindPosition:false},closeByEsc:false,closeIcon:true,zIndex:-12,titleBar:{content:t==BX.CrmDialogMode.edit?this._prepareEditDlgTitle():this._prepareViewDlgTitle()},events:{onPopupShow:BX.delegate(this._onDlgShow,this),onAfterPopupShow:BX.delegate(this._onAfterDlgShow,this),onPopupClose:BX.delegate(function(){a._communicationSearch.closeDialog();BX.CrmActivityEditor.hideUploader(a.getSetting("uploadID",""),a.getSetting("uploadControlID",""));BX.CrmActivityEditor.hideLhe(a.getSetting("lheContainerID",""));a._dlg.destroy()},this),onPopupDestroy:BX.proxy(function(){a._dlg=null;a._wrapper=null;a._ttlWrapper=null;delete BX.CrmActivityEmail.dialogs[n]},this)},content:t==BX.CrmDialogMode.edit?this._prepareEditDlgContent(n):this._prepareViewDlgContent(n),buttons:t==BX.CrmDialogMode.edit?this._prepareEditDlgButtons():this._prepareViewDlgButtons()});BX.CrmActivityEmail.dialogs[n]=this._dlg;var r=null;if(t===BX.CrmDialogMode.edit){var s=this.getSetting("communicationsLoaded",true);if(e>0&&!s){r={ACTIVITY_COMMUNICATIONS:{ID:e}}}if(this._communicationSearch&&!this._communicationSearch.isDataLoaded()){if(!r){r={}}this._communicationSearch.prepareDataRequest(r)}if(s){this._communicationsReady=false;this._prepareCommunications();if(e<=0&&this._communications.length===0&&this.getMessageType()===""){var o=this._communicationSearch?this._communicationSearch.getDefaultCommunication():null;if(o){this._addCommunication(o.getSettings())}}}if(r){this._communicationsReady=s;if(!s){this._findElement("to").appendChild(this._prepareCommunicationWaiter())}this._editor.getActivityViewData(r,BX.delegate(this.processViewDataResponse,this))}}else{var l=20;var c=1;var d=this._editor.getId().toString()+"_"+this.getId().toString()+"_"+l.toString();if(typeof BX.CrmActivityCommunicationPaginator.items[d]!=="undefined"){this._paginator=BX.CrmActivityCommunicationPaginator.items[d]}else{this._paginator=BX.CrmActivityCommunicationPaginator.create(d,BX.CrmParamBag.create({editor:this._editor,activityId:this.getId(),pageSize:l}))}this._findElement("to").appendChild(this._prepareCommunicationWaiter());r={ACTIVITY_COMMUNICATIONS_PAGE:{ID:e,PAGE_SIZE:l,PAGE_NUMBER:c}};if(this._communicationSearch&&!this._communicationSearch.isDataLoaded()){this._communicationSearch.prepareDataRequest(r)}this._editor.getActivityViewData(r,BX.delegate(this.processViewDataResponse,this))}if(this.displayOwner()){this._setupOwner({type:this.getSetting("ownerType",""),id:this.getSetting("ownerID","0"),title:this.getSetting("ownerTitle",""),url:this.getSetting("ownerUrl","")},!this.canChangeOwner())}if(this.canChangeOwner()){window.setTimeout(BX.delegate(function(){var t=this._editor.createOwnershipSelector(this._dlgID,BX(this.getDialogConfigValue("change_owner_button")));obCrm[t].AddOnSaveListener(BX.delegate(this._handleOwnerSelect,this));this.setDialogConfigValue("owner_selector_id",t)},this),0)}this._dlg.show();if(t===BX.CrmDialogMode.edit){var g=this.getSetting("lastUsedEmail","");if(g!==""){this.setDialogValue("from",g)}if(typeof this._dlgCfg["template"]!=="undefined"){var h=[{value:0,text:this.getMessage("noTemplate"),enabled:true,default:true}];var m=this.getSetting("mailTemplateData",[]);for(var u=0;u<m.length;u++){var p=m[u];if(p.bodyType&&p.bodyType=="HTML")continue;h.push({value:parseInt(p["id"]),text:p["title"]})}var f=this._templateSelector=BX.CrmSelector.create(this._dlgCfg["template"],{container:BX(this._dlgCfg["template"]),title:"",selectedValue:"",items:h,layout:{insertBefore:{className:"crm-view-actions"}}});f.layout();f.addOnSelectListener(BX.delegate(this._handleTemplateChange,this))}}},_onDlgShow:function(){if(this._ttlWrapper){BX.bind(BX.findParent(this._ttlWrapper,{class:"popup-window-titlebar"}),"dblclick",this._expandHandler)}},_onAfterDlgShow:function(){var t=BXHtmlEditor.Get(this.getSetting("lheJsName"));if(t){t.CheckAndReInit();t.ResizeSceleton(0,198);if(this._dlgMode===BX.CrmDialogMode.edit){var e=this.getSetting("descriptionBBCode","");if(e===""){e=this.getSetting("description","");e=e.replace(/<br\s*?\/?>/gi,"\n")}t.SetContent(e,true)}}},closeDialog:function(){if(this._communicationSearchController){this._communicationSearchController.stop();this._communicationSearchController=null}if(this._communicationSearch){this._communicationSearch.closeDialog()}if(this._titleMenu){this._titleMenu.removeCreateTaskListener(this._taskCreationHandler);this._titleMenu.removeCreateCallListener(this._callCreationHandler);this._titleMenu.removeCreateMeetingListener(this._meetingCreationHandler);this._titleMenu.cleanLayout()}if(!this._dlg){return}this._notifyDialogClose();this._dlg.close()},addOnSave:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onSaveHandlers.length;e++){if(this._onSaveHandlers[e]==t){return}}this._onSaveHandlers.push(t)},removeOnSave:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onSaveHandlers.length;e++){if(this._onSaveHandlers[e]==t){this._onSaveHandlers.splice(e,1);return}}},addOnDialogClose:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onDlgCloseHandlers.length;e++){if(this._onDlgCloseHandlers[e]==t){return}}this._onDlgCloseHandlers.push(t)},removeOnDialogClose:function(t){if(!BX.type.isFunction(t)){return}for(var e=0;e<this._onDlgCloseHandlers.length;e++){if(this._onDlgCloseHandlers[e]==t){this._onDlgCloseHandlers.splice(e,1);return}}},deleteCommunication:function(t){for(var e=0;e<this._communications.length;e++){if(t!==this._communications[e]){continue}this._communications.splice(e,1);break}this.validate()},applyTemplate:function(t){var e=this._templateId=parseInt(t);if(e===0){this._setupFromTemplate({from:"",subject:"",body:""});return}var i="TEMPLATE_"+e+"_"+this.getSetting("ownerType")+"_"+this.getSetting("ownerID");if(typeof BX.CrmActivityEmail.prepredTemplates[i]!=="undefined"){this._setupFromTemplate(BX.CrmActivityEmail.prepredTemplates[i]);return}var n=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"prepare_mail_template",ownertype:this.getSetting("ownerType",""),ownerid:this.getSetting("ownerID",""),templateid:e});var a=this;BX.ajax({url:n,method:"POST",dataType:"json",data:{ACTION:"PREPARE_MAIL_TEMPLATE",TEMPLATE_ID:e,OWNER_TYPE:this.getSetting("ownerType"),OWNER_ID:this.getSetting("ownerID"),CONTENT_TYPE:"BBCODE"},onsuccess:function(t){var e=t["DATA"];if(e){var i={from:BX.type.isNotEmptyString(e["FROM"])?e["FROM"]:"",subject:BX.type.isNotEmptyString(e["SUBJECT"])?e["SUBJECT"]:"",body:BX.type.isNotEmptyString(e["BODY"])?e["BODY"]:""};BX.CrmActivityEmail.prepredTemplates["TEMPLATE_"+e["ID"]+"_"+e["OWNER_TYPE"]+"_"+e["OWNER_ID"]]=i;a._setupFromTemplate(i)}},onfailure:function(t){}})},getDialogElements:function(t){var e=this._dlgCfg;if(!e){return[]}var i=document.forms[e["form"]];if(!i||!i.elements[t]){return[]}return i.elements[t]},isChanged:function(){return this._isChanged},getButtonId:function(){return this._buttonId},_lockSaveButton:function(){if(!this._dlg){return}var t=BX.findChild(this._dlg.popupContainer,{class:"popup-window-button-accept"},true,false);if(t){BX.removeClass(t,"popup-window-button-accept");BX.addClass(t,"popup-window-button-disable")}},_unlockSaveButton:function(){if(!this._dlg){return}var t=BX.findChild(this._dlg.popupContainer,{class:"popup-window-button-disable"},true,false);if(t){BX.removeClass(t,"popup-window-button-disable");BX.addClass(t,"popup-window-button-accept")}},_prepareCode:function(t,e){e=BX.type.isNotEmptyString(e)?e:"";var i=this.getSetting("prefix","");return(i.length>0?i+"_":"")+(e.length>0?e+"_":"")+t},_prepareEditDlgTitle:function(){return this._ttlWrapper=BX.CrmActivityEditor.prepareDialogTitle(this.getMessage("addEmailDlgTitle"))},_prepareViewDlgTitle:function(){var t=this.getSetting("subject","");var e=this.getMessage("viewDlgTitle");e=e.replace(/%TYPE%/gi,this.getMessage("email"));e=e.replace(/%SUBJECT%/gi,t.length>0?t:"#"+this.getSetting("ID","0"));this._titleMenu=BX.CrmActivityMenu.create("",{enableTasks:this._editor.isTasksEnabled(),enableCalendarEvents:this._editor.isCalendarEventsEnabled(),enableEmails:false},{createTask:this._taskCreationHandler,createCall:this._callCreationHandler,createMeeting:this._meetingCreationHandler});var i=this._ttlWrapper=BX.CrmActivityEditor.prepareDialogTitle(e);this._titleMenu.layout(i);return i},_prepareEditDlgContent:function(t){var e=this._dlgCfg={};var i=Math.random().toString().substring(2);e["wrapper"]=this._cntWrapper=this._prepareCode("activity_email_wrapper");var n=BX.create("DIV",{attrs:{className:"bx-crm-dialog-add-email-popup"},props:{id:e["wrapper"]}});e["error"]=this._prepareCode("activity_email_event_error");n.appendChild(BX.create("DIV",{attrs:{className:"bx-crm-dialog-activity-error",style:"display:none;"},props:{id:e["error"]}}));e["form"]=this._prepareCode("activity_email_event");var a=BX.create("FORM",{props:{name:e["form"]}});n.appendChild(a);var r=BX.create("TABLE",{attrs:{className:"bx-crm-dialog-activity-table"}});r.cellSpacing="0";r.cellPadding="0";r.border="0";a.appendChild(r);e["from"]=this._prepareCode("from");BX.CrmActivityEditor.prepareDialogRow(r,{title:BX.create("SPAN",{text:this.getMessage("from")+":"}),content:BX.create("INPUT",{attrs:{className:"bx-crm-dialog-input"},props:{type:"text",id:e["from"],name:e["from"],value:this._prepareDefaultFrom()},events:{click:BX.delegate(this._handleAddresserClick,this),change:BX.delegate(this._handleAddresseeChange,this)}})});e["to"]=this._prepareCode("to");var s=BX.create("DIV",{attrs:{className:"bx-crm-dialog-comm-block"},props:{id:e["to"]},events:{click:BX.delegate(this._openCommunicationDialog,this)}});BX.CrmActivityEditor.prepareDialogRow(r,{title:BX.create("SPAN",{text:this.getMessage("to")+":"}),content:[s]});e["subject"]=this._prepareCode("subject");BX.CrmActivityEditor.prepareDialogRow(r,{title:BX.create("SPAN",{text:this.getMessage("subject")+":"}),content:BX.create("INPUT",{attrs:{className:"bx-crm-dialog-input"},props:{type:"text",id:e["subject"],name:e["subject"],value:this.getSetting("subject","")}})});if(this.getMessageType()!=="FWD"){var o=this.getSetting("mailTemplateData",[]);if(o.length>0){e["template"]=this._prepareCode("template");BX.CrmActivityEditor.prepareDialogRow(r,{title:BX.create("SPAN",{text:this.getMessage("template")+":"}),content:BX.create("DIV",{attrs:{className:"bx-crm-dialog-popup-select-block"},props:{id:e["template"]}})})}}var l=BX(this.getSetting("lheContainerID",""));if(l){l.style.display=""}BX.CrmActivityEditor.prepareDialogRow(r,{skipTitle:true,contentCells:[{attrs:{colspan:2},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-text-editor-wrap"},style:{border:"none",background:"white",height:"auto",minHeight:"200px"},children:[l]})]}]});if(this.canChangeOwner()){e["change_owner_button"]=this._prepareCode("change_owner_button",i);var c=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-owner-change-text"},props:{id:e["change_owner_button"]},text:this.getMessage("change"),events:{click:BX.delegate(this._handleChangeOwnerClick,this)}});e["owner_info_wrapper"]=this._prepareCode("owner_info_wrapper",i);BX.CrmActivityEditor.prepareDialogRow(r,{title:BX.create("SPAN",{text:this.getMessage("owner")+":"}),content:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-block"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-info-wrapper"},props:{id:e["owner_info_wrapper"]}}),BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-button-wrapper"},children:[c]})]})]})}var d=parseInt(this.getSetting("storageTypeID",BX.CrmActivityStorageType.undefined));if(isNaN(d)||d===BX.CrmActivityStorageType.undefined){d=this.getDefaultStorageTypeId()}this._storageTypeId=d;if(d===BX.CrmActivityStorageType.webdav){var g=this._editor.prepareWebDavUploader(this._uploaderName,this.getMode(),this.getSetting("webdavelements",[]));BX.CrmActivityEditor.prepareDialogRow(r,{skipTitle:true,content:g})}else if(d===BX.CrmActivityStorageType.disk){var h=this._editor.prepareDiskUploader(this._uploaderName,this.getMode(),this.getSetting("diskfiles",[]));BX.CrmActivityEditor.prepareDialogRow(r,{skipTitle:true,content:h})}else{BX.CrmActivityEditor.prepareDialogRow(r,{skipTitle:true,content:this._editor.prepareFileUploader(this.getSetting("uploadControlID",""),this.getSetting("uploadID",""),this.getSetting("files",[]))})}return n},_prepareViewDlgContent:function(t){var e=this.getType();var i=this._dlgCfg={};var n=this._salt;var a=this._cntWrapper=BX.create("DIV",{attrs:{className:"bx-crm-dialog-view-email-popup"}});i["form"]=this._prepareCode("activity_email",n);var r=BX.create("FORM",{props:{name:i["form"]}});a.appendChild(r);var s=BX.create("TABLE");s.cellSpacing="0";s.cellPadding="0";s.border="0";s.className="bx-crm-dialog-view-email-table";r.appendChild(s);var o=BX.parseDate(this.getSetting("start",""));if(!o){o=new Date}BX.CrmActivityEditor.prepareDialogRow(s,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("datetime")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[BX.CrmActivityEditor.trimDateTimeString(BX.date.format(BX.CrmActivityEditor.getDateTimeFormat(),o))]}]});var l=parseInt(this.getSetting("direction",BX.CrmActivityDirection.outgoing));i["direction"]=this._prepareCode("direction",n);BX.CrmActivityEditor.prepareDialogRow(s,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("direction")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[BX.CrmActivityDirection.getName(BX.CrmActivityType.email,l)]}]});i["to"]=this._prepareCode("to",n);var c=BX.create("DIV",{attrs:{className:"bx-crm-dialog-comm-block"},props:{id:i["to"]}});BX.CrmActivityEditor.prepareDialogRow(s,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage(l===BX.CrmActivityDirection.outgoing?"addresser":"addressee")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[c]}]});BX.CrmActivityEditor.prepareDialogRow(s,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("subject")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[this.getSetting("subject","")]}]});var d=this.getSetting("descriptionHtml","");if(d===""){d=this.getSetting("description","");if(d!==""){d=d.replace(/<script[^>]*>.*?<\/script>/g,"");d=d.replace(/<script[^>]*>/g,"");d=d.replace(/\r\n/g,"<br/>");d=d.replace(/(\r|\n)/g,"<br/>")}}if(d.length>0){r.appendChild(BX.create("DIV",{attrs:{className:"bx-crm-dialog-view-activity-descr"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-view-activity-descr-title"},text:this.getMessage("description")+":"}),BX.create("DIV",{attrs:{className:"bx-crm-dialog-view-activity-descr-text"},html:d})]}))}if(this.displayOwner()){i["owner_info_wrapper"]=this._prepareCode("owner_info_wrapper",n);BX.CrmActivityEditor.prepareDialogRow(s,{headerCell:{attrs:{className:"bx-crm-dialog-view-cell-left"},children:[this.getMessage("owner")+":"]},contentCells:[{attrs:{className:"bx-crm-dialog-view-cell-left-right"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-block"},children:[BX.create("DIV",{attrs:{className:"bx-crm-dialog-owner-info-wrapper"},props:{id:i["owner_info_wrapper"]}})]})]}]})}var g=parseInt(this.getSetting("storageTypeID",BX.CrmActivityStorageType.undefined));if(isNaN(g)||g===BX.CrmActivityStorageType.undefined){g=this.getDefaultStorageTypeId()}this._storageTypeId=g;var h=[];if(g===BX.CrmActivityStorageType.webdav){var m=this.getSetting("webdavelements",[]);for(var u=0;u<m.length;u++){h.push({name:m[u]["NAME"],url:m[u]["VIEW_URL"]})}if(h.length>0){r.appendChild(this._editor.prepareFileList(h))}}else if(g===BX.CrmActivityStorageType.disk){var p=this.getSetting("diskfiles",[]);for(var f=0;f<p.length;f++){h.push({name:p[f]["NAME"],url:p[f]["VIEW_URL"]})}if(h.length>0){r.appendChild(this._editor.prepareFileList(h))}}else{var v=this.getSetting("files",[]);for(var y=0;y<v.length;y++){h.push({name:v[y]["fileName"],url:v[y]["fileURL"]})}if(h.length>0){r.appendChild(this._editor.prepareFileList(h))}}return a},_openCommunicationDialog:function(t){var e=this._findElement("to");if(!e){return}var i=this._dlgCfg;i["contactSearch"]=this._prepareCode("contactSearch",this._salt);var n=BX(i["contactSearch"]);if(!n){n=BX.create("INPUT",{attrs:{className:"bx-crm-dialog-comm-search"},props:{id:i["contactSearch"],type:"text"},events:{keypress:BX.delegate(this._handleQuickSearchKeyPress,this)}});e.appendChild(n)}n.focus();if(!this._communicationSearchController){this._communicationSearchController=BX.CrmCommunicationSearchController.create(this._communicationSearch,n)}this._communicationSearchController.start();this._communicationSearch.openDialog(e,BX.delegate(this._handleCommunicationDialogClose,this))},_prepareDefaultFrom:function(){var t=this.getSetting("userFullName","");var e=this.getSetting("userEmail","");var i=this.getSetting("userEmail2","");var n=this.getSetting("crmEmail","");if(BX.type.isNotEmptyString(n))e=n;else if(BX.type.isNotEmptyString(i))e=i;return BX.type.isNotEmptyString(e)?(BX.type.isNotEmptyString(t)?t+" ":"")+"<"+e+">":""},_getQuickSearch:function(){return this._dlgCfg["contactSearch"]?BX(this._dlgCfg["contactSearch"]):null},_setupFromTemplate:function(t){var e=t["from"];if(e===""){e=this.getSetting("lastUsedEmail","");if(e===""){e=this._prepareDefaultFrom()}}this.setDialogValue("from",e);var i=this.getMessageType();if(i!=="RE"){this.setDialogValue("subject",t["subject"])}var n=BXHtmlEditor.Get(this.getSetting("lheJsName"));if(n){var a=t["body"];if(i=="RE"){var r=this.getSetting("descriptionBBCode","");if(r==""){r=this.getSetting("description","");r=r.replace(/<br\s*?\/?>/gi,"\n")}if(r!=="")a+=r}n.CheckAndReInit(a)}},_handleCommunicationDialogClose:function(){if(this._communicationSearchController){this._communicationSearchController.stop();this._communicationSearchController=null}var t=this._getQuickSearch();if(t){this._tryAddCustomCommunication(t.value);BX.remove(t)}delete this._dlgCfg["contactSearch"]},_handleCommunicationSelect:function(t){this._addCommunication(t.getSettings());var e=this._getQuickSearch();if(e){BX.remove(e)}delete this._dlgCfg["contactSearch"];this._communicationSearch.closeDialog()},_handleTemplateChange:function(t,e){if(e){this.applyTemplate(parseInt(e.getValue()))}},_addCommunication:function(t){if(!t){return}if(!BX.type.isNotEmptyString(t["type"])){t["type"]="EMAIL"}t["mode"]=this._dlgMode;var e=BX.CrmActivityCommunication.create(t,this);for(var i=0;i<this._communications.length;i++){if(e.equals(this._communications[i])){return}}this._communications.push(e);e.layout(this._findElement("to"),this._getQuickSearch());if(this._communicationSearch){this._communicationSearch.adjustDialogPosition()}this.validate()},_prepareCommunicationWaiter:function(){if(!this._communicationWaiter){this._communicationWaiter=BX.create("DIV",{attrs:{className:"bx-crm-dialog-comm-wait-wrapper"},text:BX.CrmActivityEditor.getMessage("dataLoading")})}return this._communicationWaiter},processViewDataResponse:function(t){var e=this._findElement("to");if(this._communicationWaiter){e.removeChild(this._communicationWaiter)}var i;if(typeof t["ACTIVITY_COMMUNICATIONS"]!=="undefined"){var n=typeof t["ACTIVITY_COMMUNICATIONS"]["DATA"]!=="undefined"?t["ACTIVITY_COMMUNICATIONS"]["DATA"]:{};i=n["COMMUNICATIONS"]&&BX.type.isArray(n["COMMUNICATIONS"])?n["COMMUNICATIONS"]:[];this.setSetting("communications",i);this.setSetting("communicationsLoaded",true);this._prepareCommunications()}else if(typeof t["ACTIVITY_COMMUNICATIONS_PAGE"]!=="undefined"){var a=typeof t["ACTIVITY_COMMUNICATIONS_PAGE"]["DATA"]!=="undefined"?t["ACTIVITY_COMMUNICATIONS_PAGE"]["DATA"]:{};i=a["COMMUNICATIONS"]&&BX.type.isArray(a["COMMUNICATIONS"])?a["COMMUNICATIONS"]:[];var r=a["PAGE_SIZE"]?a["PAGE_SIZE"]:20;var s=a["PAGE_NUMBER"]?a["PAGE_NUMBER"]:1;var o=a["PAGE_COUNT"]?a["PAGE_COUNT"]:1;for(var l=0;l<i.length;l++){this._addCommunication(i[l])}if(this._paginator){this._paginator.setupPageData(i,r,s,o)}if(o>1){this._showAllCommunicationsButton=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-comm-block-button"},events:{click:BX.delegate(this._handleShowAllCommBtnClick,this)},text:BX.CrmActivityEditor.getMessage("showAllCommunication")});e.parentNode.appendChild(this._showAllCommunicationsButton)}else{this.setSetting("communications",i);this.setSetting("communicationsLoaded",true)}}this._communicationsReady=true;if(this._communicationSearch&&!this._communicationSearch.isDataLoaded()){this._communicationSearch.processDataResponse(t)}if(this.getId()<=0&&this._dlgMode===BX.CrmDialogMode.edit&&this._communications.length===0&&this.getMessageType()===""){var c=this._communicationSearch?this._communicationSearch.getDefaultCommunication():null;if(c){this._addCommunication(c.getSettings())}}},_prepareCommunications:function(){if(this._communicationsReady){return}var t=this.getSetting("communications",[]);for(var e=0;e<t.length;e++){this._addCommunication(t[e])}this._communicationsReady=true},_findElement:function(t){return BX.CrmActivityEditor.findDialogElement(this._dlgCfg,t)},_findElements:function(t){return BX.CrmActivityEditor.findDialogElements(this._dlgCfg,t)},_notifySave:function(t){for(var e=0;e<this._onSaveHandlers.length;e++){try{this._onSaveHandlers[e](this,t)}catch(t){}}},_notifyDialogClose:function(){for(var t=0;t<this._onDlgCloseHandlers.length;t++){try{this._onDlgCloseHandlers[t](this)}catch(t){}}},_prepareEditDlgButtons:function(){return BX.CrmActivityEditor.prepareDialogButtons([{type:"button",settings:{text:BX.CrmActivityEditor.getMessage("sendDlgButton"),className:"popup-window-button-accept",events:{click:BX.delegate(this._handleSaveBtnClick,this)}}},{type:"link",settings:{text:BX.CrmActivityEditor.getMessage("cancelShortDlgButton"),className:"popup-window-button-link-cancel",events:{click:BX.delegate(this._handleCloseBtnClick,this)}}}])},_prepareViewDlgButtons:function(){var t=[];var e=parseInt(this.getSetting("direction",BX.CrmActivityDirection.outgoing));if(e===BX.CrmActivityDirection.incoming){t.push({type:"button",settings:{text:BX.CrmActivityEditor.getMessage("replyDlgButton"),className:"popup-window-button-accept",events:{click:BX.delegate(this._handleReplyBtnClick,this)}}})}t.push({type:"button",settings:{text:BX.CrmActivityEditor.getMessage("forwardDlgButton"),className:"popup-window-button-accept",events:{click:BX.delegate(this._handleForwardBtnClick,this)}}});t.push({type:"link",settings:{text:BX.CrmActivityEditor.getMessage("closeDlgButton"),className:"popup-window-button-link-cancel",events:{click:BX.delegate(this._handleCloseBtnClick,this)}}});return BX.CrmActivityEditor.prepareDialogButtons(t)},_handleCallCreation:function(t){var e={};var i=this.getSetting("ownerType","");var n=parseInt(this.getSetting("ownerID",0));if(typeof BX.Crm.Activity.Planner!=="undefined"){(new BX.Crm.Activity.Planner).showEdit({TYPE_ID:BX.CrmActivityType.call,OWNER_TYPE:i,OWNER_ID:n,FROM_ACTIVITY_ID:this.getId()});return}if(i!==""&&n>0){e["ownerType"]=i;e["ownerID"]=n;e["ownerTitle"]=this.getSetting("ownerTitle","");e["ownerUrl"]=this.getSetting("ownerUrl","")}e["subject"]=this.getSetting("subject","");e["direction"]=BX.CrmActivityDirection.outgoing;if(this.getSetting("ownerType","")==="DEAL"){var a=this.getSetting("communications",[]);if(BX.type.isArray(a)){for(var r=0;r<a.length;r++){var s=a[r];var o=s["entityType"];if(!BX.type.isNotEmptyString(o)){o=i}var l=parseInt(s["entityId"]);if(isNaN(l)||l<=0){l=n}var c=BX.CrmActivityEditor.getDefaultCommunication(o,l,BX.CrmCommunicationType.phone,this.getSetting("serviceUrl",""));if(c){e["communications"]=[c.getSettings()];break}}}}this._editor.addCall(e)},_handleMeetingCreation:function(t){var e={};var i=this.getSetting("ownerType","");var n=parseInt(this.getSetting("ownerID",0));if(typeof BX.Crm.Activity.Planner!=="undefined"){(new BX.Crm.Activity.Planner).showEdit({TYPE_ID:BX.CrmActivityType.meeting,OWNER_TYPE:i,OWNER_ID:n,FROM_ACTIVITY_ID:this.getId()});return}if(i!==""&&n>0){e["ownerType"]=i;e["ownerID"]=n;e["ownerTitle"]=this.getSetting("ownerTitle","");e["ownerUrl"]=this.getSetting("ownerUrl","")}e["subject"]=this.getSetting("subject","");if(this.getSetting("ownerType","")==="DEAL"){var a=this.getSetting("communications",[]);if(BX.type.isArray(a)){for(var r=0;r<a.length;r++){var s=a[r];var o=s["entityType"];if(!BX.type.isNotEmptyString(o)){o=i}var l=parseInt(s["entityId"]);if(isNaN(l)||l<=0){l=n}var c=BX.CrmActivityEditor.getDefaultCommunication(o,l,BX.CrmCommunicationType.undefined,this.getSetting("serviceUrl",""));if(c){e["communications"]=[c.getSettings()];break}}}}this._editor.addMeeting(e)},_handleTaskCreation:function(t){var e={};var i=this.getSetting("ownerType","");var n=parseInt(this.getSetting("ownerID",0));if(i!==""&&n>0){e["ownerType"]=i;e["ownerID"]=n}this._editor.addTask(e)},_handleCloseBtnClick:function(t){this._buttonId=BX.CrmActivityDialogButton.cancel;this.closeDialog()},_handleReplyBtnClick:function(t){var e=this._editor;var i=e.getOwnerType();var n=e.getOwnerId();if(i===""||n<=0){i=this.getOwnerType();n=this.getOwnerId()}var a={ownerType:i,ownerID:n,subject:this.getSetting("subject",""),description:this.getSetting("description",""),descriptionBBCode:this.getSetting("descriptionBBCode",""),communications:[],communicationsLoaded:this.getSetting("communicationsLoaded",true),messageType:"RE",originalMessageID:this.getId()};var r=function(){var t="\n\n-------- Original message --------\n";if(a["communications"].length>0){var e=a["communications"][0]["value"]?a["communications"][0]["value"]:"";var i=a["communications"][0]["entityTitle"]?a["communications"][0]["entityTitle"]:"";if(e){t+=i?'From: "'+i+'" <[URL=mailto:'+e+"]"+e+"[/URL]>\n":"From: [URL=mailto:"+e+"]"+e+"[/URL]\n"}}if(a["subject"])t+="Subject: "+a["subject"]+"\n";a["subject"]="Re: "+a["subject"];if(a["description"])a["description"]=t+"\n"+a["description"];if(a["descriptionBBCode"])a["descriptionBBCode"]=t+"\n"+a["descriptionBBCode"]};var s=this.getSetting("communicationsLoaded",true);if(s){a["communications"]=this.getSetting("communications",[]);a["communicationsLoaded"]=true;r();this.closeDialog();e.addEmail(a)}else{var o=this;e.getActivityCommunications(this.getId(),function(t){if(!BX.type.isArray(t)){t=[]}a["communications"]=t;a["communicationsLoaded"]=true;r();o.closeDialog();e.addEmail(a)})}},_handleForwardBtnClick:function(t){this.closeDialog();var e={ownerType:"",ownerID:0,subject:"Fwd: "+this.getSetting("subject",""),description:this.getSetting("description",""),descriptionBBCode:this.getSetting("descriptionBBCode",""),communications:[],communicationsLoaded:true,messageType:"FWD",originalMessageID:this.getId()};var i="\n-------- Forwarded message --------\n";if(e["description"])e["description"]=i+"\n"+e["description"];if(e["descriptionBBCode"])e["descriptionBBCode"]=i+"\n"+e["descriptionBBCode"];var n=e["storageTypeID"]=parseInt(this.getSetting("storageTypeID",BX.CrmActivityStorageType.undefined));if(n===BX.CrmActivityStorageType.file){e["files"]=this.getSetting("files",[])}else if(n===BX.CrmActivityStorageType.webdav){e["webdavelements"]=this.getSetting("webdavelements",[])}else if(n===BX.CrmActivityStorageType.disk){e["diskfiles"]=this.getSetting("diskfiles",[])}this._editor.addEmail(e)},_handleSaveBtnClick:function(t){if(this._requestIsRunning||!this._communicationsReady||!this._dlg){return}var e={};e["ID"]=this.getId();e["from"]=this.getDialogValue("from","");if(e["from"]!==""){this._editor.setSetting("lastUsedEmail",e["from"])}e["communications"]=[];var i;for(var n=0;n<this._communications.length;n++){i=this._communications[n];e["communications"].push({id:i.getId(),type:i.getType(),entityType:i.getEntityType(),entityId:i.getEntityId(),value:i.getValue()})}e["subject"]=this.getDialogValue("subject","");e["message"]="";var a=BXHtmlEditor.Get(this.getSetting("lheJsName"));if(a)e["message"]=a.GetContent();e["storageTypeID"]=this._storageTypeId;if(this._storageTypeId===BX.CrmActivityStorageType.webdav){e["webdavelements"]=this._editor.getWebDavUploaderValues(this._uploaderName)}else if(this._storageTypeId===BX.CrmActivityStorageType.disk){e["diskfiles"]=this._editor.getDiskUploaderValues(this._uploaderName)}else{e["files"]=this._editor.getFileUploaderValues(this.getDialogElements(this.getSetting("uploadInputID","")+"[]"));var r=this.getSetting("uploadControlID","");if(typeof BX.CFileInput!=="undefined"&&typeof BX.CFileInput.Items[r]!=="undefined"){e["uploadControlCID"]=BX.CFileInput.Items[r].CID}}var s="";var o=0;var l=this.getSetting("ownerType","");var c=parseInt(this.getSetting("ownerID",0));if(this.canChangeOwner()){s=this._owner?this._owner["typeName"]:"";o=this._owner?parseInt(this._owner["id"]):0}if((s===""||o<=0)&&l!=="DEAL"&&this._communications&&this._communications.length>0){for(var d=0;d<this._communications.length;d++){i=this._communications[d];s=i.getEntityType();o=parseInt(i.getEntityId());if(s!==""&&o>0){break}}}if(s===""||o<=0){if(l!==""&&c>0){s=l;o=c}else{this._clearError();this._showError(this.getMessage("ownerNotDefined"));return}}e["ownerType"]=s;e["ownerID"]=o;if(this.getMessageType()==="FWD"){e["FORWARDED_ID"]=parseInt(this.getSetting("originalMessageID",0))}else if(this.getMessageType()=="RE"){e["REPLIED_ID"]=parseInt(this.getSetting("originalMessageID",0))}e["templateID"]=this._templateId;this._buttonId=BX.CrmActivityDialogButton.save;this._isChanged=true;this._requestIsRunning=true;this._lockSaveButton();var g=BX.util.add_url_param(this.getSetting("serviceUrl",""),{action:"save_email"});var h=this;BX.ajax({url:g,method:"POST",dataType:"json",data:{ACTION:"SAVE_EMAIL",DATA:e},onsuccess:function(t){if(typeof t["ERROR"]!="undefined"){h._clearError();h._showError(t["ERROR"])}else{h._notifySave(t);h.closeDialog()}h._requestIsRunning=false;h._unlockSaveButton()},onfailure:function(t){h._clearError();h._showError(t);h._requestIsRunning=false;h._unlockSaveButton()}})},_handleShowAllCommBtnClick:function(t){var e=this.getId();var i=e>0?BX.CrmDialogMode.view:BX.CrmDialogMode.edit;var n="CrmCommunicationList"+(i===BX.CrmDialogMode.edit?"Edit":"View")+e;var a=BX.CrmActivityCommunicationListDialog.create(n,BX.CrmParamBag.create({activityId:e,editor:this._editor,pageSize:20,anchor:this._showAllCommunicationsButton}));a.open()},_tryAddCustomCommunication:function(t){if(!BX.type.isNotEmptyString(t)){return false}var e=BX.CrmActivityEditor.parseEmail(t);this._addCommunication({entityId:"0",entityTitle:e["name"],entityType:"CONTACT",type:"EMAIL",value:e["address"]});return true},_handleQuickSearchKeyPress:function(t){if(!t){t=window.event}if(t.keyCode!==13&&t.keyCode!==27){return}var e=this._getQuickSearch();if(!e){return}if(t.keyCode===27){e.value="";e.focus();return}if(this._tryAddCustomCommunication(e.value)){e.value="";e.focus()}},_handleAddresseeChange:function(t){this.validate()},_handleChangeOwnerClick:function(t){if(!this.canChangeOwner()){return}this._openOwnerSelector()},_openOwnerSelector:function(){var t=this.getDialogConfigValue("owner_selector_id","");if(t!==""&&obCrm&&obCrm[t]){obCrm[t].Open()}},_closeOwnerSelector:function(){var t=this.getDialogConfigValue("owner_selector_id","");if(t!==""&&obCrm&&obCrm[t]){obCrm[t].Clear();delete obCrm[t]}},_handleOwnerSelect:function(t){if(!this.canChangeOwner()){return}for(var e in t){if(t.hasOwnProperty(e)){this._setupOwner(t[e][0],false);break}}},_handleAddresserClick:function(t){var e=BX(this.getDialogConfigValue("from"));if(!e){return}var i="crm-activity-email-addresser";if(typeof BX.PopupMenu.Data[i]!=="undefined"){BX.PopupMenu.Data[i].popupWindow.destroy();delete BX.PopupMenu.Data[i]}var n=[];var a=this._editor.getUserEmails();if(a.length>0){for(var r=0;r<a.length;r++){var s=a[r];n.push({text:BX.util.htmlspecialchars(s),className:"",onclick:BX.delegate(this._handleAddresserSelect,this)})}}if(n.length===0){return}BX.PopupMenu.show(i,e,n,{offsetTop:0,offsetLeft:0})},_handleAddresserSelect:function(t){if(!t){t=window.event}var e=t.target;if(!e){return}if(e.className!=="menu-popup-item"){e=BX.findParent(e,{className:"menu-popup-item"})}var i=BX.findChild(e,{className:"menu-popup-item-text"},true,false);if(!i){return}var n=BX(this.getDialogConfigValue("from"));if(n){n.value=BX.util.htmlspecialcharsback(i.innerHTML)}var a="crm-activity-email-addresser";if(typeof BX.PopupMenu.Data[a]!=="undefined"){BX.PopupMenu.Data[a].popupWindow.destroy();delete BX.PopupMenu.Data[a]}},_setupOwner:function(t,e){e=!!e;this._owner={typeName:t.type.toUpperCase(),id:parseInt(t.id)};var i=BX(this.getDialogConfigValue("owner_info_wrapper"));if(!i){return}BX.cleanNode(i,false);var n=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-owner-info"},children:[BX.create("A",{attrs:{className:"bx-crm-dialog-owner-info-link",href:t.url,target:"_blank"},text:t.title})]});if(!e){n.appendChild(BX.create("SPAN",{attrs:{className:"finder-box-selected-item-icon"},events:{click:BX.delegate(this._handleDeleteOwnerClick,this)}}))}i.appendChild(n)},_handleDeleteOwnerClick:function(t){if(!this.canChangeOwner()){return}if(!t){t=window.event}var e=t.target;if(e){BX.remove(BX.findParent(e,{tagName:"SPAN",className:"bx-crm-dialog-owner-info"}))}this._owner=null},validate:function(){this._clearError();var t=this._findElement("from");if(t){if(t.value===""){this._showError(BX.CrmActivityEditor.getMessage("addresseeIsEmpty"))}else if(!BX.CrmActivityEditor.validateEmail(t.value)){this._showError(BX.CrmActivityEditor.getMessage("invalidEmailError").replace("#VALUE#",t.value))}}if(this._communications.length===0){this._showError(BX.CrmActivityEditor.getMessage("addresserIsEmpty"))}else{for(var e=0;e<this._communications.length;e++){var i=this._communications[e];if(!i.isValid()){this._showError(i.getError())}}}},_showError:function(t){var e=this._findElement("error");if(!e){return}if(!BX.type.isArray(t)){t=[t]}for(var i=0;i<t.length;i++){e.appendChild(BX.create("P",{text:t[i]}))}e.style.display="";if(this._communicationSearch){this._communicationSearch.adjustDialogPosition()}},_clearError:function(){var t=this._findElement("error");if(!t){return}t.innerHTML="";t.style.display="none";if(this._communicationSearch){this._communicationSearch.adjustDialogPosition()}},_handleExpand:function(){if(!this._dlg){return}if(!this._expanded){BX.addClass(this._dlg.popupContainer,"bx-crm-dialog-activity-email-wide");BX.removeClass(this._dlg.popupContainer,"bx-crm-dialog-activity-email")}else{BX.addClass(this._dlg.popupContainer,"bx-crm-dialog-activity-email");BX.removeClass(this._dlg.popupContainer,"bx-crm-dialog-activity-email-wide")}this._expanded=!this._expanded;var t=BX.GetWindowInnerSize(document);var e=BX.GetWindowScrollPos(document);var i=BX.pos(this._dlg.popupContainer);this._dlg.popupContainer.style.left=e.scrollLeft+(t.innerWidth-i.width)/2+"px";this._dlg.popupContainer.style.top=e.scrollTop+(t.innerHeight-i.height)/2+"px"}};BX.CrmActivityEmail.prepareReply=function(t){var e="\n\n-------- Original message --------\n";if(t["communications"].length>0){var i=t["communications"][0]["value"]?t["communications"][0]["value"]:"";var n=t["communications"][0]["entityTitle"]?t["communications"][0]["entityTitle"]:"";if(i){e+=n?'From: "'+n+'" <[URL=mailto:'+i+"]"+i+"[/URL]>\n":"From: [URL=mailto:"+i+"]"+i+"[/URL]\n"}}if(t["subject"]){e+="Subject: "+t["subject"]+"\n"}t["subject"]="Re: "+t["subject"];if(t["description"]){t["description"]=e+"\n"+t["description"]}if(t["descriptionBBCode"]){t["descriptionBBCode"]=e+"\n"+t["descriptionBBCode"]}};BX.CrmActivityEmail.prepredTemplates={};BX.CrmActivityEmail.dialogs={};BX.CrmActivityEmail.create=function(t,e,i){var n=new BX.CrmActivityEmail;n.initialize(t,e,i);return n};BX.CrmActivityCommunication=function(){this._settings={};this._activity=null;this._wrapper=null;this._isValid=true;this._sipCallButton=null;this._sipCallButtonClickHandler=BX.delegate(this._onSipCallButtonClick,this)};BX.CrmActivityCommunication.prototype={initialize:function(t,e){if(!e){throw"Activity is not defined."}this._activity=e;this._settings=t?t:{};var i=this.getValue();if(this.getType()==="PHONE"){this._isValid=i!==""&&BX.CrmActivityEditor.validatePhone(i)}else if(this.getType()==="EMAIL"){this._isValid=i!==""&&BX.CrmActivityEditor.validateEmail(i)}else if(this.getType()===""&&i===""){this._settings["value"]=this.getSetting("entityTitle","")}},getSetting:function(t,e){return typeof this._settings[t]!="undefined"?this._settings[t]:e},getId:function(){return parseInt(this.getSetting("id",0))},getType:function(){return this.getSetting("type","")},getEntityType:function(){return this.getSetting("entityType","")},getEntityId:function(){return this.getSetting("entityId","")},getValue:function(){return this.getSetting("value","")},getEntityTitle:function(){return this.getSetting("entityTitle","")},getMode:function(){return this.getSetting("mode",BX.CrmDialogMode.edit)},isSipEnabled:function(){return this.getSetting("enableSip",false)},equals:function(t){return this.getType()===t.getType()&&this.getValue()===t.getValue()&&this.getEntityId()===t.getEntityId()&&this.getEntityType()===t.getEntityType()},isValid:function(){return this._isValid},getError:function(){if(this.isValid()){return""}if(this.getType()==="PHONE"){return BX.CrmActivityEditor.getMessage("invalidPhoneError").replace("#VALUE#",this.getValue())}else if(this.getType()==="EMAIL"){return BX.CrmActivityEditor.getMessage("invalidEmailError").replace("#VALUE#",this.getValue())}return""},_createEntityLink:function(t,e){return BX.create("A",{attrs:{className:"bx-crm-dialog-communication-entity-link",href:e,target:"_blank"},text:t})},_loadHtml:function(t){this._activity.getEditor().getCommunicationHtml(this.getSetting("type"),this.getSetting("value",""),BX.delegate(function(e){t.innerHTML=e},this))},layout:function(t,e){var i=this.getMode();var n=this._wrapper=BX.create("SPAN",{attrs:{className:this.isValid()?"bx-crm-dialog-contact":"bx-crm-dialog-contact bx-crm-dialog-contact-invalid"}});var a=this.getSetting("type");var r=this.getSetting("entityTitle","");var s=this.getSetting("entityUrl","");var o=this.getSetting("value","");if(a==="PHONE"){var l=parseInt(this.getSetting("callToFormat",BX.CrmCalltoFormat.slashless));if(i===BX.CrmDialogMode.view&&BX.type.isNotEmptyString(s)){n.appendChild(this._createEntityLink(r,s));n.appendChild(document.createTextNode(" "))}else{n.appendChild(BX.create("SPAN",{attrs:{className:"bx-crm-dialog-contact-name"},text:r+" "}))}var c=BX.create("A",{attrs:{className:l===BX.CrmCalltoFormat.custom?"crm-fld-disabled":"crm-fld-text",href:(l===BX.CrmCalltoFormat.standard?"callto://":"callto:")+o,title:o},text:o});if(l===BX.CrmCalltoFormat.bitrix){BX.bind(c,"click",this._sipCallButtonClickHandler)}var d=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-contact-phone"},children:[c]});n.appendChild(d);if(this.isSipEnabled()&&this.getMode()===BX.CrmDialogMode.view){this._sipCallButton=BX.create("SPAN",{attrs:{className:"crm-client-contacts-block-text-tel-icon"}});BX.bind(this._sipCallButton,"click",this._sipCallButtonClickHandler);n.appendChild(this._sipCallButton)}if(l===BX.CrmCalltoFormat.custom){this._loadHtml(d)}}else if(a==="EMAIL"){if(r!==""){if(i===BX.CrmDialogMode.view&&BX.type.isNotEmptyString(s)){n.appendChild(this._createEntityLink(r,s));n.appendChild(document.createTextNode(" "));n.appendChild(BX.create("SPAN",{text:" <"+o+">"}))}else{n.appendChild(BX.create("SPAN",{text:r+" <"+o+">"}))}}else{n.appendChild(BX.create("SPAN",{text:o}))}}else if(a===""){if(i===BX.CrmDialogMode.view&&BX.type.isNotEmptyString(s)){n.appendChild(this._createEntityLink(o,s))}else{n.appendChild(BX.create("SPAN",{text:o}))}}else{n.appendChild(BX.create("SPAN",{text:r!==""?r+" "+o:o}))}if(i===BX.CrmDialogMode.edit){n.appendChild(BX.create("SPAN",{attrs:{className:"finder-box-selected-item-icon"},events:{click:BX.delegate(this._handleDeletion,this)}}))}if(BX.type.isElementNode(e)){t.insertBefore(n,e)}else{t.appendChild(n)}},cleanupLayout:function(){if(this._sipCallButton){BX.unbind(this._sipCallButton,"click",this._sipCallButtonClickHandler);this._sipCallButton=null}if(this._wrapper){BX.remove(this._wrapper);this._wrapper=null}},_handleDeletion:function(t){if(this.getMode()!==BX.CrmDialogMode.edit){return}this._activity.deleteCommunication(this);this.cleanupLayout();BX.eventCancelBubble(t)},_onSipCallButtonClick:function(t){if(typeof BX.CrmSipManager!=="undefined"){BX.CrmSipManager.startCall({number:this.getSetting("value",""),enableInfoLoading:true},{ENTITY_TYPE:BX.CrmSipManager.resolveSipEntityTypeName(this.getSetting("entityType","")),ENTITY_ID:this.getSetting("entityId",""),SRC_ACTIVITY_ID:this._activity.getId().toString()},true,this._sipCallButton)}return BX.PreventDefault(t)}};BX.CrmActivityCommunication.create=function(t,e){var i=new BX.CrmActivityCommunication;i.initialize(t,e);return i};BX.CrmActivityMenu=function(){this._id="";this._settings={};this._createEmailListeners=[];this._createTaskListeners=[];this._createCallListeners=[];this._createMeetingListeners=[];this._documentClickHandler=BX.delegate(this._onDocumentClick,this);this._isPopupMenuShown=false;this._wrapper=null;this._popupMenu=null};BX.CrmActivityMenu.prototype={initialize:function(t,e,i){this._id=BX.type.isNotEmptyString(t)?t:Math.random().toString().substring(2);this._settings=e?e:{};if(i){if(i["createTask"]){this.addCreateTaskListener(i["createTask"])}if(i["createCall"]){this.addCreateCallListener(i["createCall"])}if(i["createMeeting"]){this.addCreateMeetingListener(i["createMeeting"])}if(i["createEmail"]){this.addCreateEmailListener(i["createEmail"])}}},getSetting:function(t,e){return typeof this._settings[t]!="undefined"?this._settings[t]:e},getMessage:function(t,e){var i=BX.CrmActivityMenu.messages;return typeof i!=="undefined"&&i[t]?i[t]:e},isTasksEnabled:function(){return this.getSetting("enableTasks",false)},isCalendarEventsEnabled:function(){return this.getSetting("enableCalendarEvents",false)},isEmailsEnabled:function(){return this.getSetting("enableEmails",false)},layout:function(t,e){var i=this.isTasksEnabled();var n=this.isCalendarEventsEnabled();var a=this.isEmailsEnabled();if(!a&&!i&&!n){return}if(!e)e={};var r=this._wrapper=BX.create("UL",{attrs:{className:e.wrapperClassName||"bx-crm-dialog-view-menu-wrapper"}});t.appendChild(r);if(a){r.appendChild(BX.create("LI",{attrs:{className:"bx-crm-dialog-view-menu-mess"},events:{click:BX.delegate(this._onCreateEmailClick,this)}}))}if(i||n){var s=this._popupMenu=BX.create("UL",{attrs:{id:"crm_activity_menu"+"_"+this._id},children:[BX.create("LI",{attrs:{className:"bx-crm-dialog-view-menu-arrow"}})]});if(i){s.appendChild(BX.create("LI",{children:[BX.create("A",{attrs:{className:"bx-crm-dialog-view-menu-task",href:"#"},events:{click:BX.delegate(this._onCreateTaskClick,this)},text:this.getMessage("task","Task")})]}))}if(n){s.appendChild(BX.create("LI",{children:[BX.create("A",{attrs:{className:"bx-crm-dialog-view-menu-call",href:"#"},events:{click:BX.delegate(this._onCreateCallClick,this)},text:this.getMessage("call","Call")})]}));s.appendChild(BX.create("LI",{children:[BX.create("A",{attrs:{className:"bx-crm-dialog-view-menu-meeting",href:"#"},events:{click:BX.delegate(this._onCreateMeetingClick,this)},text:this.getMessage("meeting","Meeting")})]}))}r.appendChild(BX.create("LI",{attrs:{className:"bx-crm-dialog-view-menu-more"},children:[BX.create("SPAN",{events:{click:BX.delegate(this._onMenuClick,this)}}),s]}))}},cleanLayout:function(){if(this._wrapper){BX.cleanNode(this._wrapper,true)}},_onMenuClick:function(t){BX.PreventDefault(t);this.showPopupMenu(!this._isPopupMenuShown)},_onDocumentClick:function(t){if(this._isPopupMenuShown){this.showPopupMenu(false)}},showPopupMenu:function(t){t=!!t;this._isPopupMenuShown=t;var e=this._popupMenu;if(e){if(t){BX.addClass(e,"display");BX.bind(document.body,"click",this._documentClickHandler)}else{BX.removeClass(e,"display");BX.unbind(document.body,"click",this._documentClickHandler)}}},addCreateEmailListener:function(t){this._addListener(t,this._createEmailListeners)},removeCreateEmailListener:function(t){this._removeListener(t,this._createEmailListeners)},addCreateTaskListener:function(t){this._addListener(t,this._createTaskListeners)},removeCreateTaskListener:function(t){this._removeListener(t,this._createTaskListeners)},addCreateCallListener:function(t){this._addListener(t,this._createCallListeners)},removeCreateCallListener:function(t){this._removeListener(t,this._createCallListeners)},addCreateMeetingListener:function(t){this._addListener(t,this._createMeetingListeners)},removeCreateMeetingListener:function(t){this._removeListener(t,this._createMeetingListeners)},_onCreateEmailClick:function(t){this._notify(this._createEmailListeners,[this])},_onCreateTaskClick:function(t){BX.PreventDefault(t);this.showPopupMenu(false);this._notify(this._createTaskListeners,[this])},_onCreateCallClick:function(t){BX.PreventDefault(t);this.showPopupMenu(false);this._notify(this._createCallListeners,[this])},_onCreateMeetingClick:function(t){BX.PreventDefault(t);this.showPopupMenu(false);this._notify(this._createMeetingListeners,[this])},_addListener:function(t,e){if(!BX.type.isFunction(t)){return}for(var i=0;i<e.length;i++){if(e[i]==t){return}}e.push(t)},_removeListener:function(t,e){if(!BX.type.isFunction(t)){return}for(var i=0;i<e.length;i++){if(e[i]==t){e.splice(i,1);return}}},_notify:function(t,e){var i=[];for(var n=0;n<t.length;n++){i.push(t[n])}for(var a=0;a<i.length;a++){try{i[a].apply(this,e?e:[])}catch(t){}}}};BX.CrmActivityMenu.create=function(t,e,i){var n=new BX.CrmActivityMenu;n.initialize(t,e,i);return n};if(typeof BX.CrmCalltoFormat==="undefined"){BX.CrmCalltoFormat={undefined:0,standard:1,slashless:2,custom:3,bitrix:4}}BX.CrmActivityCommunicationPaginator=function(){this._editor=null;this._pageSize=20;this._pageNumber=1;this._pageCount=1;this._pages={};this._callback=null;this._activityChangeHandler=BX.delegate(this._onActivityChange,this)};BX.CrmActivityCommunicationPaginator.prototype={initialize:function(t,e){this._id=t;this._settings=e?e:e=BX.CrmParamBag.create(null);this._activityId=e.getIntParam("activityId");if(this._activityId<=0){throw"BX.CrmActivityCommunicationPaginator.initialize: activityId not found!"}this._editor=e.getParam("editor");if(!this._editor){throw"BX.CrmActivityCommunicationPaginator.initialize: editor not found!"}this._editor.addActivityChangeHandler(this._activityChangeHandler);this._pageSize=e.getIntParam("pageSize",20);this._pageNumber=e.getIntParam("pageNumber",1);this._pageCount=this._pageNumber},getId:function(){return this._id},getActivityId:function(){return this._activityId},getPageSize:function(){return this._pageSize},getPageNumber:function(){return this._pageNumber},getPageCount:function(){return this._pageCount},getPage:function(t,e){t=parseInt(t);if(t<=0){return}if(typeof this._pages[t]!=="undefined"){this._pageNumber=t;if(BX.type.isFunction(e)){e(this,this._pages[t])}return}BX.showWait();if(BX.type.isFunction(e)){this._callback=e}this._editor.getActivityCommunicationsPage(this._activityId,this._pageSize,t,BX.delegate(this._onPageLoad,this))},setupPageData:function(t,e,i,n){this._pageNumber=parseInt(i);this._pageCount=parseInt(n);this._pages[this._pageNumber]=t;if(this._callback){this._callback(this,t)}},_onPageLoad:function(t,e,i,n){BX.closeWait();this.setupPageData(t,e,i,n)},_onActivityChange:function(t,e,i){if(parseInt(i["ID"])===this._activityId){this._editor.removeActivityChangeHandler(this._activityChangeHandler);delete BX.CrmActivityCommunicationPaginator.items[this.getId()]}}};BX.CrmActivityCommunicationPaginator.items={};BX.CrmActivityCommunicationPaginator.create=function(t,e){var i=new BX.CrmActivityCommunicationPaginator;i.initialize(t,e);this.items[i.getId()]=i;return i};BX.CrmActivityCommunicationListDialog=function(){this._id="";this._settings=null;this._editor=null;this._activity=null;this._popup=null;this._wrapper=null;this._paginator=null;this._commBlock=null;this._prevPageButton=null;this._communications=[]};BX.CrmActivityCommunicationListDialog.prototype={initialize:function(t,e){this._id=t;this._settings=e?e:e=BX.CrmParamBag.create(null);this._editor=e.getParam("editor");if(!this._editor){throw"BX.CrmActivityCommunicationListDialog.initialize: editor not found!"}var i=e.getIntParam("activityId");this._activity=this._editor.getItemById(i);if(!this._activity){throw"BX.CrmActivityCommunicationListDialog.initialize: activity not found!"}var n=e.getIntParam("pageSize",20);var a=this._editor.getId().toString()+"_"+i.toString()+"_"+n.toString();if(typeof BX.CrmActivityCommunicationPaginator.items[a]!=="undefined"){this._paginator=BX.CrmActivityCommunicationPaginator.items[a]}else{this._paginator=BX.CrmActivityCommunicationPaginator.create(a,BX.CrmParamBag.create({editor:this._editor,activityId:i,pageSize:n}))}},getId:function(){return this._id},open:function(){if(this._popup){this._popup.show();return}var t=this._settings;this._popup=BX.PopupWindowManager.create(this._id,t.getParam("anchor"),{className:"bx-crm-dialog-wrap crm-activity-comm-list bx-crm-dialog-activity-comm-list",closeByEsc:true,autoHide:true,offsetLeft:0,closeIcon:false,content:this._prepareContent(),events:{onPopupClose:BX.delegate(this._onPopupClose,this)},buttons:[new BX.PopupWindowButtonLink({text:BX.message["JS_CORE_WINDOW_CLOSE"],className:"popup-window-button-link-cancel",events:{click:BX.delegate(this._onCancelButtonClick,this)}})]});this._prepagePage(1);this._popup.show()},close:function(){if(this._popup){this._popup.close()}},_onPopupClose:function(){if(this._popup){this._popup.destroy();this._popup=null}},_prepareContent:function(){var t=this._wrapper=BX.create("DIV",{attrs:{class:"bx-crm-dialog-view-comm-list-popup"}});var e=this._commBlock=BX.create("DIV",{attrs:{class:"bx-crm-dialog-comm-block"}});t.appendChild(e);this._prevPageButton=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-comm-block-button"},style:{display:"none"},events:{click:BX.delegate(this._onPrevPageBtnClick,this)},text:BX.CrmActivityEditor.getMessage("prevPage")});t.appendChild(this._prevPageButton);this._nextPageButton=BX.create("SPAN",{attrs:{className:"bx-crm-dialog-comm-block-button"},style:{display:"none"},events:{click:BX.delegate(this._onNextPageBtnClick,this)},text:BX.CrmActivityEditor.getMessage("nextPage")});t.appendChild(this._nextPageButton);return t},_onCancelButtonClick:function(t){this.close()},_onPrevPageBtnClick:function(t){var e=this._paginator.getPageNumber();if(e>1){this._prepagePage(e-1)}},_onNextPageBtnClick:function(t){var e=this._paginator.getPageNumber();var i=this._paginator.getPageCount();if(e<i){this._prepagePage(e+1)}},_prepagePage:function(t){t=parseInt(t);if(t<=0){t=this._paginator.getPageNumber()}this._paginator.getPage(t,BX.delegate(this._onPageLoad,this))},_onPageLoad:function(t,e){for(var i=0;i<this._communications.length;i++){this._communications[i].cleanupLayout()}this._communications=[];if(!BX.type.isArray(e)){e=[]}for(var n=0;n<e.length;n++){this._addCommunication(e[n])}var a=this._paginator.getPageNumber();var r=this._paginator.getPageCount();this._prevPageButton.style.display=a>1?"":"none";this._nextPageButton.style.display=a<r?"":"none"},_addCommunication:function(t){if(!t){return}t["mode"]=BX.CrmDialogMode.view;var e=BX.CrmActivityCommunication.create(t,this._activity);for(var i=0;i<this._communications.length;i++){if(e.equals(this._communications[i])){return}}this._communications.push(e);e.layout(this._commBlock)}};BX.CrmActivityCommunicationListDialog.create=function(t,e){var i=new BX.CrmActivityCommunicationListDialog;i.initialize(t,e);return i};BX.CrmActivityDelivery=function(){this._settings=null;this._editor=null;this._ownerID=null;this._ownerType=null;this._orderList=null;this._additionalOrders=[]};BX.CrmActivityDelivery.prototype={initialize:function(t,e){this._settings=t||{};this._editor=e;this._ownerID=this._settings["ownerID"]||0;this._ownerType=this._settings["ownerType"]||"";this._orderList=this._settings["orderList"]||[]},openDialog:function(){var t=this._getLatestOrderId();var e={context:"deal",templateMode:"create",mode:"delivery",analyticsLabel:"salescenterClickDeliveryActivity",ownerTypeId:BX.CrmEntityType.enumeration.deal,ownerId:this._ownerID,orderId:t};BX.loadExt("salescenter.manager").then(function(){BX.Salescenter.Manager.openApplication(e).then(this._refreshDeal.bind(this))}.bind(this))},_getLatestOrderId:function(){var t=this._orderList.map(function(t){if(t.ORDER_ID){return parseInt(t.ORDER_ID)}return 0});this._additionalOrders.map(function(e){t.push(parseInt(e))});if(t.length>0){return Math.max.apply(Math,t)}return 0},_refreshDeal:function(t){if(t){var e=t.get("deal");if(e&&e.PRODUCT_LIST){this._refreshProductList(e)}var i=t.get("order");if(i&&i.id){this.rememberCurrentOrder(i.id)}}},_refreshProductList:function(t){try{var e=BX.Crm.EntityEditor.getDefault();e.reload();e.tapController("PRODUCT_ROW_PROXY",function(e){if(e._externalEditor){e._externalEditor.reinitialize(t.PRODUCT_LIST)}});e.tapController("PRODUCT_LIST",function(t){t.reinitializeProductList()})}catch(t){}},rememberCurrentOrder:function(t){this._additionalOrders.push(parseInt(t))}};BX.CrmActivityDelivery.instance=null;BX.CrmActivityDelivery.getInstance=function(){BX.CrmActivityDelivery.instance=BX.CrmActivityDelivery.instance||new BX.CrmActivityDelivery;return BX.CrmActivityDelivery.instance};BX.CrmActivityDelivery.create=function(t,e){var i=BX.CrmActivityDelivery.getInstance();i.initialize(t,e);return i}} //# sourceMappingURL=activity.map.js
/var/www/axolotl/data/www/axolotl.ru/../b24.axolotl.ru/public_html/bitrix/js/crm/activity.min.js