(function(){"use strict";u8.Crm.Formats=function(){};$.extend(u8.Crm.Formats.prototype,{find:function(e,t){u8.request("FormatsChannel.Find",{findOptions:e},function(e,r){var o={error:r.error};$.extend(o,r.response);if(t){t(self,o)}})},readXml:function(e,t){var r;if(u8.isValidRecordUid(e.uid)&&e.uid.infoAreaId!="FT"){r=new u8.Base.Request({endPoint:"FormatsChannel.ReadXmlOwned",arguments:{uid:e.uid,formatAlias:e.formatAlias},queue:false,accept:"application/xml"})}else if(u8.isValidRecordId(e.recordId)){r=new u8.Base.Request({endPoint:"FormatsChannel.ReadXmlByRecordId",arguments:{recordId:e.recordId},queue:false,accept:"application/xml"})}else{r=new u8.Base.Request({endPoint:"FormatsChannel.ReadXml",arguments:{formatType:e.formatType,formatName:e.formatName,formatScope:e.formatScope},queue:false,accept:"application/xml"})}var o=this;r.execute(a);function a(e,r){var a=r.response&&($(r.response).xpath("FormatDefinition")[0]||null);if(a){a=u8.Base.Xml.toXmlDocument(a,"extract")}var n={error:r.error,xml:a};if(t){t(o,n)}}},writeXml:function(e,t){var r,o;if(typeof e=="string"){r=e;o=null}else{r=e.xml;o=e.options}u8.request("FormatsChannel.WriteXml",{formatXml:r,options:o},function(e,r){if(t){t(self,r)}})},delete_:function(e,t){var r=this;if(e.showUi!==false){if(u8.isValidRecordId(e.recordId)&&!e.formatName){u8.request("FormatsChannel.Read",{recordId:e.recordId},function(a,n){var i=n.response&&n.response.format;if(!i){return t&&t(r,n)}e.formatName=i.name;o()})}else{o()}}else{a()}function o(){u8.Base.Widgets.MessageBox.showInfo({message:"TXT_net_selectformat_text_0".format({0:e.formatName}),buttons:"Yes,No"},function(e,o){if(o&&"Yes"!=o.command){return t&&t(r,{cancel:true})}a()})}function a(){var o;if(u8.isValidRecordId(e.recordId)){o=new u8.Base.Request({endPoint:"FormatsChannel.DeleteByRecordId",arguments:{recordId:e.recordId}})}else{o=new u8.Base.Request({endPoint:"FormatsChannel.Delete",arguments:{formatType:e.formatType,formatname:e.formatName,formatScope:e.formatScope||""}})}o.execute(function(o,a){var n=a.response&&a.response.recordId;if((a.error||!n)&&e.showUi!==false&&e.suppressDialogErrorMsg!==true){u8.services.notification.error($t("TXT_net_selectformat_text_2"))}return t&&t(r,{error:a.error,recordId:n})})}},updateFormatHeader:function(e,t,r){u8.request("FormatsChannel.UpdateFormatHeader",{recordId:e,updateFormatHeaderRequest:t},r)},updateFormatHeaderXml:function(t,r){if(!t){return false}var o=$(t).xpath("//FormatHeader");if(!o.length){return false}if(typeof r.name!="undefined"){e(o,"Name",r.name)}if(typeof r.user!="undefined"){e(o,"User",r.user)}if(typeof r["private"]!="undefined"){e(o,"Private",r["private"]?"true":"false")}if(typeof r.lock!="undefined"){e(o,"Lock",r.lock?"true":"false")}if(typeof r["local"]!="undefined"){e(o,"Local",r["local"]?"true":"false")}return true},select:function(e,t){$assert(e,"parameter 'options' may not be null");var r=["fieldId","formatType","includePublicFormats","includePrivateFormats","filter","formatName","formatNames","selectionMode","filterFormatName","forLoading"];u8.Base.Widgets.Popup.openWidgetPopup({type:"FormatSelect",widgetOptions:u8.tools.extendSome({},r,e),popupOptions:$.extend({size:e.size,minSize:{width:800,height:380},sizing:e.sizing,alignTo:e.alignTo||null,title:e.title||"",autoShow:false,onClose:a,parent:page},e.popup)},function(e,t){t.popup.autoSizeAndPosition().show()});var o=this;function a(e,r){if(t){t(o,r)}}},edit:function(e,t){var r=this,o=$.extend({scripts:"crm/pages/activityexecution.js"},e);if(o.uid){o.uid=u8.recordUidToString(o.uid)}var a=u8.services.navigation.getPageUrl("FormatEdit",o);var n=new u8.Base.Widgets.Popup(a,{minSize:{width:780,height:400},sizing:"fit",onClose:function(e,o){if(t){t(r,o)}}});n.open()}});function e(e,t,r){var o=e.xpath(t);if(!o.length){var a=e[0].ownerDocument,n=a.createElement(t);if(r){n.appendChild(a.createTextNode(r))}e.append(n)}else if(r){o.text(r)}}u8.services.add({name:"formats",scope:"Login",ctor:u8.Crm.Formats})})();