(function(){var e={lyrisMessageExpand:"expandLyrisMessage",expandViewWidgetName:"executionExpand",lyrisEmailForm:"emailLyrisForm",existsInLyris:"existsInLyris",doesNotExistInLyris:"#doesNotExistInLyris",lyrisMessageId:"lyrisMessageId",emailStandardFormName:"emailForm"};var i=u8.services.activityExecutionFormat.getChannels();function a(i){var a=i.getWidget(e.emailStandardFormName);var t=i.getWidget(e.lyrisEmailForm);return a.active?a:t}function t(e,i){var t;switch(i){case"email":t=a(e);break;default:var n=i+"Form";t=e.getWidget(n);break}return t}function n(i,a){var n=t(i,a.formName);if(a.formName!=="email"){return n.getWidget(e.expandViewWidgetName)}var r=n.getWidget(e.lyrisMessageExpand);if(!r){return n.getWidget(e.expandViewWidgetName)}return r}function r(e){return e.charAt(0).toUpperCase()+e.slice(1)}function o(e){return"AD."+r(e)+"Format"}function s(e){var a=e.formatEditForm;$.each(i,function(i,t){if(e.model.isActiveAndConfigurable(t)){var r=n(a,t);r.save()}})}function d(e){var a=false;var t=e.formatEditForm;$.each(i,function(i,r){if(e.model.isActiveAndConfigurable(r)){var o=n(t,r);if(o.isModified()){a=true}}});return a}page.context={uid:u8.parseRecordUid(page.url.get("activityExecutionUid"))};page.defineFormat={onFormPreCreate:function(e){$(e.element).hide()},onFormCreate:function(e){var i=page.context.uid;var a;var t;this._startLoading();Function.chain(function(e){this._getRequiredFields(function(i){a=i,e()})},function(e){this._getLyrisInformationState(i,function(i){t=i,e()})},function(i){this._setActiveEmailForms(e,t,i)},function(i){this._initFormItems(i,e,a,t)}).call(this,function(){this._endLoading(e)})},onExpandFormCreate:function(e,i){if(i.reason==="PostFormCreate"&&e.model.channel){var a=e.model.channel;var t=u8.services.activityExecutionFormat.getChannelXmlName(a);var n=e;var r=this;u8.request("CampaignManagementChannel.GetFormatChannelMandatoryExpandFieldsDefinition",{channel:t,activityExecutionUid:page.context.uid},function(e,i){if(i.error){return}r._formatMandatoryExpandFields(i.response,n)})}},_formatMandatoryExpandFields:function(e,i){var a=e.fields;var t=this;$.each(a,function(e,a){var n=i.getField({fieldId:a.fieldId,infoAreaId:a.infoAreaId});if(!n){return}var r=$(i.element).find("div.u8-label > span:contains('"+n.label+"')")[0];t._formatLabelForMandatoryField(r)});$(i.element).find(".u8-validationsummary").remove()},_startLoading:function(){page.busy(true)},_endLoading:function(e){page.busy(false);$(e.element).show()},_initFormItems:function(e,i,a,t){this._updateTabs(i);this._formatFormLabelsForMandatoryFields(i,a);this._initExpands(e,i,a,t)},_getLyrisInformationState:function(e,i){u8.services.lyris.getLyrisInformationState(e,i)},_getRequiredFields:function(e){u8.request("CampaignManagementChannel.GetFormatChannelMandatoryXPathsDefinition",{},function(i,a){if(a.error){return}if(e){e(a.response)}})},_setActiveEmailForms:function(i,a,t){var n=e.lyrisEmailForm;var r=i.getWidget(n);var o=i.getWidget(e.emailStandardFormName);if(!o||!r){t();return}if(a.lyrisIsEnabled){o.active=false;r.active=true;$(o.element).hide()}else{o.active=true;r.active=false;$(r.element).hide()}t()},_initExpands:function(a,n,r,s){var d=this;var l=page.context.uid;$.each(i,function(i,a){var r=a.formName;if(r==="phone"||r==="inPerson"||u8.session.environment.isEnterpriseVersion&&!a.enabled){return}if(r==="email"){var m=e.lyrisEmailForm;var f=n.getWidget(m);if(s.lyrisIsEnabled){page.lyrisMessage.initLyrisExpand(f,s,r);return}}var u=t(n,r);var c=o(r);var v=u.getWidget(e.expandViewWidgetName);d._initExpand(v,c,l,r)});if(a){a()}},_formatFormLabelsForMandatoryFields:function(e,a){var n=this;$.each(i,function(i,r){var o=r.formName;if(o==="phone"||o==="inPerson"||u8.session.environment.isEnterpriseVersion&&!r.enabled){return}var s=t(e,o);var d=s.getComponent("$context");for(var l in s.widgets){var m=s.widgets[l];if(m.type==="Label"){var f=s.getWidget(l);var u=f.getValue();var c=u?u.mapping:null;if(c){var v=d.mapping[c];var g=d.xpathPrefix+v;var p=a.paths;if($.inArray(g,p)>-1){n._formatLabelForMandatoryField(f.element)}}}}})},_formatLabelForMandatoryField:function(e){$(e).addClass("u8-fields-must")},_initExpand:function(e,i,a,t){e.model.fieldGroupName=i;e.model.channel=t;e.model.setUid(a)},_updateTabs:function(e){var a=e.getWidget("channelTabs");var t=a.getTabs();var n=this;var r=e.context;$.each(i,function(e,i){var a=i.formName;if(u8.session.environment.isEnterpriseVersion&&!i.enabled){return}n._updateTab(t,a,r)});var o=page.url.get("selectedChannel");if(o){var s=this._findTab(t,o);if(s&&s.visible){t.model.setSelectedItem(s)}}else{t.model.setSelectedItem("$first")}},_updateTab:function(e,i,a){var t=i+"Fixed";var n=i+"Variable";var r=this._findTab(e,i);r.visible=a.get(t)!=="false"||a.get(n)!=="false";e.update({item:r})},_findTab:function(e,i){var a=$.grep(e.model.items,function(e){return e.value.name===i});if(a.length===0){return null}return a[0]}};page.extraItemsAreModified=d;page.saveExtraItems=s})();