(function(){u8.Crm.TypeConverter=function(){};u8.Crm.TypeConverter.makeClass({name:"TypeConverter",deriveFrom:u8.Base.TypeConverter});$.extend(u8.Crm.TypeConverter.prototype,{tryDateToString:function(e,t){if(t&&t.schema){t=this._fieldSchemaToDateFormat(t.schema)}return this.TypeConverter_tryDateToString(e,t)},dateToString:function(e,t){if(t&&t.schema){t=this._fieldSchemaToDateFormat(t.schema,t.fieldInfo)}return this.TypeConverter_dateToString(e,t)},numberToString:function(e,t){if(t&&t.schema){t=this._fieldSchemaToNumberFormat(t.schema,t)}e=this.TypeConverter_numberToString(e,t);if(t&&t.leadingZeros&&t.schema){e=e.leftPad(t.schema.length,"0")}return e},timeToString:function(e,t){if(t&&t.schema){t=this._fieldSchemaToTimeFormat(t.schema,{format:t.format})}return this.TypeConverter_timeToString(e,t)},toString:function(e,t,r){if(t===null||typeof t=="undefined"){return""}if(e.isBooleanField()){return this.booleanToString(t)}if(e.isRepField()||e.isCatalogField()||e.isTenantField()){return t.toString()}if(e.isNumericField()){if(t===""){return t}else{return this.numberToString(t,{schema:e})}}if(e.isDateField()){return this.dateToString(t,{schema:e,fieldInfo:r})}if(e.isTimeField()){return this.timeToString(t,{schema:e})}return t.toString()},toObject:function(e,t,r){if(e.isBooleanField()){return this.toBoolean(t)}else if(e.isNumericField()){return this.toNumber(t,{schema:e})}else if(e.isDateField()){return this.toDate(t,{schema:e,fieldInfo:r})}else if(e.isCatalogField()){var i=parseInt(t);if(!isNaN(i)){return i}else{return t}}else if(e.isTimeField()){return this.toTime(t)}else{return t}},toNumber:function(e,t){if(t&&t.schema){t=this._fieldSchemaToNumberFormat(t.schema)}return this.TypeConverter_toNumber(e,t)},toDate:function(e,t){if(t&&t.schema){t=this._fieldSchemaToDateFormat(t.schema,t.fieldInfo)}return this.TypeConverter_toDate(e,t)},isValidTime:function(e,t){if(t&&t.schema){t=this._fieldSchemaToTimeFormat(t.schema)}return this.TypeConverter_isValidTime(e,t)},isValidDate:function(e,t){if(t&&t.schema){t=this._fieldSchemaToDateFormat(t.schema)}return this.TypeConverter_isValidDate(e,t)},isValidNumber:function(e,t){if(t&&t.schema){t=this._fieldSchemaToNumberFormat(t.schema,t)}return this.TypeConverter_isValidNumber(e,t)},isEmptyValue:function(e,t){if(!e){return undefined}if(e.format&u8.Crm.Schema.FieldFormatFlags.FieldId){return t==-1}if(!t&&t!==0){return true}else if(e.isBooleanField()){return!u8.services.typeConverter.toBoolean(t)}else if(e.isCatalogField()){return t=="0"&&!u8.services.catalogs.codeToText(e,t)}return false},getEmptyValue:function(e){if(!e){return undefined}if(e.format&u8.Crm.Schema.FieldFormatFlags.FieldId){return"-1"}return""},converter:function(t,r,i){if(u8.tools.isInstanceOfClass(t,"FieldSchema")){return e(t,i)}else if(typeof t=="string"&&t=="FieldHook"){return null}return this.TypeConverter_converter(t,r)},_fieldSchemaToNumberFormat:function(e,t){if(!e){return"Default"}if(!e.__numberFormat){var r=u8.Crm.Schema.FieldFormatFlags;var i=e.format;var n=i&r.DigitGrouping?u8.session.localeSettings.thousandSeparator:null;var a=i&r.Negative||e.dataType=="F";e.__numberFormat={decimalDigits:e.getDecimalDigits(),decimalSeparator:u8.session.localeSettings.decimalSeparator,thousandSeparator:n,percent:!!(i&r.Percent),positive:!a,leadingZeros:!!(i&r.LeadingZeros)}}if(t){return $.extend({},e.__numberFormat,t)}return e.__numberFormat},_fieldSchemaToDateFormat:function(e,t){var r=t&&t.attributes&&t.attributes.contains("dateMonthYear");return{includeDay:!r&&!(e.format&(u8.Crm.Schema.FieldFormatFlags.DateMMYYYY|u8.Crm.Schema.FieldFormatFlags.DateMMYY)),includeYear:!(e.format&u8.Crm.Schema.FieldFormatFlags.DateDDMM)}},_fieldSchemaToTimeFormat:function(e,t){var r={format:"Time",includeMillis:!!(e.format&u8.Crm.Schema.FieldFormatFlags.TimeHHMMSSTTT),includeSeconds:!!(e.format&u8.Crm.Schema.FieldFormatFlags.TimeHHMMSS)};if(t&&t.format&&t.format.startsWith("HHMM")){if(r.includeMillis){r.format="HHMMSSTTT"}else if(r.includeSeconds){r.format="HHMMSS"}else{r.format="HHMM"}}return r}});function e(e,t){return{from:function(r){try{return u8.services.typeConverter.toString(e,r,t)||null}catch(e){}return null},to:function(r){try{return u8.services.typeConverter.toObject(e,r,t)||null}catch(e){}return null}}}u8.services.add({name:"typeConverter",type:"TypeConverter",scope:"Session"})})();