(function(){"use strict";$.extend(page,{onLoad:function(){e()}});page.using={texts:["Lyris_Integration"],types:["LyrisCrmFieldMapper","LyrisDemographicMapping","LyrisCrmFieldPicker","LyrisModel","LyrisEntityLabel","LyrisSegmentCreator","LyrisTargetGroupTransferOverview","LyrisTargetGroupTransferScheduler"]};page.commandBindings={Proceed:d,ClearSelection:l};page.constants={processPhases:{pickCrmFields:"pickCrmFields",mapCrmFields:"mapCrmFields",createSegment:"createSegment",overview:"overview",scheduleTransfer:"scheduleTransfer"},statusModelProperties:{denyProceed:"denyProceed"}};function e(){page.context=new u8.Crm.Lyris.TransferTargetGroupProcessContext;var e=s();u8.services.lyris.getTransferTargetGroupOverview(e,function(e){var s=$("#content");var a=$("#footer");var n=page.url.get("stage");var d=page.process;page.context.statusModel=u8.create("Model",{properties:{denyProceed:false,denyScheduleTransfer:e.status!=u8.Crm.Lyris.TransferTargetGroupToLyrisPreconditionStatus.canBeStarted}});t(page.process,n,e);switch(n){case page.constants.processPhases.pickCrmFields:r(s,a,e);break;case page.constants.processPhases.mapCrmFields:o(s,a,e);break;case page.constants.processPhases.createSegment:c(s,a,e);break;case page.constants.processPhases.overview:i(s,a,e);break;case page.constants.processPhases.scheduleTransfer:p(s,a,e);break}})}function t(e,t,s){e.set("$process","stage",t).update("phases");e.set("$process","segmentHasBeenCreated",s.segmentHasBeenCreated).update("all");e.set("$process","canBeScheduled",s.segmentHasBeenCreated&&s.status==u8.Crm.Lyris.TransferTargetGroupToLyrisPreconditionStatus.canBeStarted).update("all")}function s(){var e=page.url.get("uid");return u8.parseRecordUid(e)}function a(e,t){e.utml({url:"~/crm/LyrisTargetGroupTransferFooter.utml.htm",data:t,itemOptions:{parent:page,context:page.context.statusModel}})}function r(e,t){var r=s();page.context.picker=u8.widget("LyrisCrmFieldPicker",e[0],{parent:page,candidateCrmFields:page.context.candidateCrmFields,activityUid:r,bindings:["@candidateCrmFields==>@candidateCrmFields"],onSave:n});page.context.statusModel.set(page.constants.statusModelProperties.denyProceed,false);a(t,{isLastPhase:false,showClearSelectionButton:true})}function n(){var e=page.process;if(!e){return}var t=s();e.proceed({uid:t})}function o(e,t,r){var o=s();page.context.mapper=u8.widget("LyrisCrmFieldMapper",e[0],{parent:page,activityUid:o,onSave:n});page.context.statusModel.set(page.constants.statusModelProperties.denyProceed,false);a(t,{isLastPhase:false,showClearSelectionButton:false})}function c(e,t,r){page.context.statusModel.set(page.constants.statusModelProperties.denyProceed,!r.segmentHasBeenCreated);var n=s();page.context.segmentCreator=u8.widget("LyrisSegmentCreator",e[0],{parent:page,activityUid:n,segmentHasBeenCreated:r.segmentHasBeenCreated,onSegmentStateChange:u,onSegmentCreate:g});a(t,{isLastPhase:false,showClearSelectionButton:false})}function i(e,t,r){var n=s();page.context.overview=u8.widget("LyrisTargetGroupTransferOverview",e[0],{parent:page,activityUid:n,targetGroupEntitiesToBeTransferred:r.targetGroupEntitiesToBeTransferred,status:r.status});var o=r.status==u8.Crm.Lyris.TransferTargetGroupToLyrisPreconditionStatus.canBeStarted;page.context.statusModel.set(page.constants.statusModelProperties.denyProceed,!o);a(t,{isLastPhase:false,showClearSelectionButton:false})}function p(e,t,r){page.context.statusModel.set("denyScheduleTransfer",r.status!=u8.Crm.Lyris.TransferTargetGroupToLyrisPreconditionStatus.canBeStarted);var n=s();page.context.overview=u8.widget("LyrisTargetGroupTransferScheduler",e[0],{parent:page,activityUid:n,status:r.status});page.context.statusModel.set(page.constants.statusModelProperties.denyProceed,false);a(t,{isLastPhase:true,showClearSelectionButton:false})}function d(e){var t=page.url.get("stage");var a=page.process;if(!a){return}var r=function(){var e=s();a.proceed({uid:e})};switch(t){case page.constants.processPhases.pickCrmFields:page.context.picker.saveCandidateCrmFields(r);break;case page.constants.processPhases.mapCrmFields:page.context.mapper.saveMappings(r);break;case page.constants.processPhases.createSegment:case page.constants.processPhases.overview:case page.constants.processPhases.scheduleTransfer:r();break}}function u(e,t){page.context.statusModel.set(page.constants.statusModelProperties.denyProceed,!t.segmentExists)}function g(e,t){page.context.statusModel.set(page.constants.statusModelProperties.denyProceed,!t.success)}function l(e){var t=page.url.get("stage");var s=page.process;if(!s){return}switch(t){case page.constants.processPhases.pickCrmFields:page.context.picker.clearSelectedCrmFields();break}}})();