(function(){page.using={types:["Formats","ActivityExecutionFormat","ActivityFormatEdit"]};var e;$.extend(page,{onInit:function(){t();page.bind("PreUnload",o);u8.services.events.bind("u8.services.navigation.onPreNavigate",i.bind(this),this.id)},onLoad:function(){a()}});function a(){var a=page.url.get("stage");page.busy(true);if(e){e.dispose()}var t=u8.parseRecordUid(page.url.get("activityUid"));var i=page.url.get("formatAlias");var o={defaultFormatName:u(),formatDefinitionFormName:page.url.get("formatDefinitionForm"),formatEditFormName:page.url.get("formatEditForm"),parent:page,showSaveChannelSelectionButton:a=="channelSelection",saveFormatButtonText:a=="channelSelection"?$t("TXT_Campaign_Designer_58"):$t("TXT_Campaign_Designer_59"),formatAlias:i,activityUid:t,allowLoadingOfPublicFormats:page.url.getBoolean("allowLoadingOfPublicFormats"),allowLoadingOfPrivateFormats:page.url.getBoolean("allowLoadingOfPrivateFormats"),model:{local:page.url.getBoolean("local"),private:page.url.getBoolean("private"),lock:page.url.getBoolean("lock"),formatAlias:page.url.get("formatAlias"),activityUid:t}};var n=$("#content").uniqueId("activityFormatEdit",true);e=u8.widget("ActivityFormatEdit",n,o);e.bind("ModelUpdated",s);e.bind("Save",g);e.bind("Proceed",r);page.busy(false)}function t(){var e=page.url.get("stage");if(page.process){page.process.set("stage",e).update("phases")}}function i(e,a){if(a.options&&a.options.arguments&&a.options.arguments.target){a.pending=true;n(function(e){if(e.navigateAway){a.cancel=!e.navigateAway;if(a.pending){a.proceed()}}})}}function o(){u8.services.events.unbind("u8.services.navigation.onPreNavigate",this.id)}function n(e){if(m()){u8.Base.Widgets.MessageBox.showQuestion({message:$t("TXT_Campaign_Designer_142"),buttons:"Ok,Cancel"},function(a,t){if(t.command==="Ok"){e({navigateAway:true})}else{e({navigateAway:false})}})}else{e({navigateAway:true})}}function r(){n(function(e){if(e.navigateAway){u8.services.events.unbind("u8.services.navigation.onPreNavigate",page.id);page.process.proceed({})}})}function s(){if(!page.process){return}var a=page.process;var t=e.model.atLeastOneChannelIsActiveAndConfigurable();a.set("$process","atLeastOneChannelIsSelected",t).update("phases");a.set("$process","formatName",e.model.formatName).update("phases")}function l(e){if(!page.process){return}var a=page.process;a.set("$process","activityExecutionUid",e).update("phases")}function u(){if(page.process){return page.process.get("defaultFormatName")}return page.url.get("defaultFormatName")}function m(){if(!e||!e.model||!e.model.isModified){return false}return e.model.isModified()||page.extraItemsAreModified&&page.extraItemsAreModified(e)}function g(a,t){if(!e.model.formatNameIsModified()){d(t.callback);return}c(t.callback)}function c(a){u8.request("FormatsChannel.FormatExists",{formatName:e.model.formatName,formatType:e.model.formatType,formatScope:"Public"},function(e,t){if(t.error){return}var i=t.response;if(!i){d(a)}else{u8.Base.Widgets.MessageBox.confirm({messageTextId:"TXT_Campaign_Designer_170",buttons:"Yes,No"},function(){d(a)})}})}function d(a){if(page.saveExtraItems){page.saveExtraItems(e)}f(a)}function f(a){var t={user:u8.session.identity.userName,local:e.model.local,lock:e.model.lock,private:e.model["private"]};u8.services.formats.updateFormatHeaderXml(e.model.xml,t);u8.request("CampaignManagementChannel.WriteActivityExecutionFormatXml",{formatXml:e.model.getModelXmlText(),options:{formatOwnerUid:e.model.activityUid,formatOwnerAlias:e.model.formatAlias},formatName:e.model.formatName},function(e,t){if(t.error){page.notify(t.error);t.error.handled=true;return}s();var i=t.response.activityExecutionUid;l(i);var o=t.response.result;if(a){a(o)}})}})();