(function(){"use strict";u8.Crm.Accounts=function(){};$.extend(u8.Crm.Accounts.prototype,{createMerge:function(e,t){function i(){u8.request("RecordMergeChannel.StartMerge",{request:{source:e.sourceUid,destination:e.targetUid}},r)}function r(e,i){if(n(i)){t(i.response)}}function n(e){var i=e.error;if(i){i.handled=true;t(e)}return!i}i()},executeMerge:function(e,t){u8.request("RecordMergeChannel.ExecuteMerge",{request:{mergeId:e.mergeId,resolutions:e.resolutions,useTransaction:e.useTransaction}},t)},createConflictResolution:function(e,t,i,r){var n=u8.Crm.Accounts.ConflictResolutionType;var s=u8.Crm.Accounts.MergeOption;var o=n.Timestamp;if(r){o=n.Relink}else if(i==s.User){o=n.Fields}else if(i==s.Source){o=n.Source}else if(i==s.Target){o=n.Target}return{resolutionType:o,parentInfoAreaId:e.parentInfoAreaId,linkId:e.linkId,source:e.source,fieldIds:t&&o==n.Fields?t:[]}},createResolutionsForTimestamp:function(e){if(!u8.tools.isArray(e)){return[]}var t=[];for(var i=0;i<e.length;i++){t.push(this.createConflictResolution(e[i],null,u8.Crm.Accounts.MergeOption.Timestamp))}return t},deleteRelation:function(e,t){var i=this,r={uid:e,confirm:true};u8.request("AccountManagementChannel.GetReciprocalRelation",r,function(e,o){if(o.error){return t&&t(i,{})}r.reciprocalUid=o.response;if(u8.isValidRecordUid(r.reciprocalUid)&&!("deleteReciprocalRelation"in r)){n()}else{s()}});function n(){u8.Base.Widgets.MessageBox.show({captionTextId:"TXT_standard_header_texts_87",image:"Question",messageTextId:"TXT_details_text_21",radioButtons:[{id:"delete",textId:"TXT_relationship_text_8"},{id:"keep",textId:"TXT_relationship_text_9"}],buttons:"Ok,Cancel",buttonsAlignment:"right"},function(e,n){if(n.command!="Ok"){return t&&t(i,{cancel:true})}r.confirm=false;r.deleteReciprocalRelation=e.getChecked()=="delete";s()})}function s(){if(u8.isValidRecordUid(r.reciprocalUid)&&r.deleteReciprocalRelation){u8.services.crud.deleteMany({uids:[r.uid,r.reciprocalUid],confirm:r.confirm},t)}else{u8.services.crud.delete_({uid:e,confirm:r.confirm},t)}}},getAccounts:function(e,t){var i=this;u8.request("AccountManagementChannel.GetAccounts",{uids:e},function(e,r){t(i,r.error||!r.response?[]:r.response)})},selectAssociationMembers:function(e){e.options={searchAndListName:e.searchAndListName};this._selectAssociationMembers(e,u8.Crm.Widgets.AssociationMemberSelector.Views.list)},selectAssociationMembersGraph:function(e){this._selectAssociationMembers(e,u8.Crm.Widgets.AssociationMemberSelector.Views.graph)},_selectAssociationMembers:function(e,t){var i=u8.application.getWorkWindow();var r=i.$("<div />").appendTo("body");var n={parent:i.page,value:e.uid,fixedFilterName:e.fixedFilterName,openInPopup:true,view:{type:t,options:e.options}};u8.create("AssociationMemberSelector",r,n)}});u8.services.add({name:"accounts",scope:"Application",ctor:u8.Crm.Accounts});u8.Crm.Accounts.MergeOption={NoValue:"",User:"user",Source:"source",Target:"target",Timestamp:"timestamp"};u8.Crm.Accounts.ConflictResolutionType={NoValue:"",Fields:"UseFields",Source:"UseSourceRecord",Target:"UseDestintionRecord",Timestamp:"UseTimestamp",Relink:"NotMatch"};var e={create:function(e,t){if(!e||!e.executeOptions||!e.executeOptions.arguments||!e.executeOptions.arguments.uids||e.executeOptions.arguments.uids.length!=2){t.menuItem.disabled=true}}};u8.services.menus.registerMenuItem("D_WebMerge_Multiple_Companies",e);u8.services.menus.registerMenuItem("D_WebMerge_Multiple_Persons",e)})();