(function(){"use strict";u8.Crm.Widgets.DataModelFieldInput=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.DataModelFieldInput.defaults,t))};u8.Crm.Widgets.DataModelFieldInput.defaults={};u8.Crm.Widgets.DataModelFieldInput.makeClass({name:"DataModelFieldInput",deriveFrom:u8.Base.Widgets.Widget,events:["ValueChange"]});$.extend(u8.Crm.Widgets.DataModelFieldInput.prototype,{getValue:function(){return this.value},setValue:function(e){this.value=e;this.raise("ValueChange",{value:e})},setInfoAreaId:function(e){this.infoAreaId=e},setSourceFieldId:function(e){this.sourceFieldId=e;if(this.sourceFieldId){this._initEditMode()}else{this._initNewMode()}},_initEditMode:function(){var e=this;u8.using({schema:this.infoAreaId},function(){e.dataType="";var t=u8.services.typeConverter.toNumber(e.sourceFieldId);e.fieldObj=u8.services.schema.getField(e.infoAreaId,e.sourceFieldId);if(e.fieldObj){e.dataType=e.fieldObj.dataType;e.converter=u8.services.typeConverter.converter(e.fieldObj)}if(e.dataType=="D"){e._addDateInputField()}else if(e.dataType=="F"||e.dataType=="L"){e._addNumericInputField()}else if(e.dataType=="K"){e._addCatalogInputField()}else if(e.dataType=="B"){e._addBooleanInputField()}else{e._addTextInputField()}})},_initNewMode:function(){this._addTextInputField()},_onTextInputValueChange:function(){var e=this._textInput.getValue();this.setValue(e)},_onDateInputValueChange:function(){var e=this._dateInput.getValue();e=this.converter.from(e);this.setValue(e)},_onCatalogInputValueChange:function(e,t){var i=this._catalogInput.getValue();i=this.converter.from(i);this.setValue(i)},_onCheckBoxValueChange:function(){var e=this._checkBox.getValue();e=this.converter.from(e);this.setValue(e)},_addTextInputField:function(){this._cleanInputFields();this._textInput=u8.widget("TextInput",this.element,{parent:this,disabled:this.readonly,readonly:this.readonly,onValueChange:this._onTextInputValueChange.bind(this)});this._textInput.setValue(this.value)},_addDateInputField:function(){this._cleanInputFields();this._dateInput=u8.widget("DateInput",this.element,{parent:this,disabled:this.readonly,converter:this.converter,onValueChange:this._onDateInputValueChange.bind(this)});try{this._dateInput.setValue(this.value)}catch(e){}},_addNumericInputField:function(){this._cleanInputFields();this._textInput=u8.widget("TextInput",this.element,{parent:this,disabled:this.readonly,readonly:this.readonly,onValueChange:this._onTextInputValueChange.bind(this),type:"number"});try{this._textInput.setValue(this.value)}catch(e){}},_addBooleanInputField:function(){this._cleanInputFields();this._checkBox=u8.widget("CheckBox",this.element,{parent:this,disabled:this.readonly,readonly:this.readonly,onValueChange:this._onCheckBoxValueChange.bind(this)});try{this._checkBox.setValue(this.value)}catch(e){}},_addCatalogInputField:function(){this._cleanInputFields();this._catalogInput=u8.widget("CatalogListInput",this.element,{parent:this,infoAreaId:this.infoAreaId,fieldId:this.sourceFieldId,disabled:this.readonly,allowNull:true,onPropertyChange:this._onCatalogInputValueChange.bind(this)});try{this._catalogInput.setValue(this.value.split(","))}catch(e){}},_cleanInputFields:function(){if(this._dateInput){this._dateInput.dispose()}if(this._textInput){this._textInput.dispose()}if(this._catalogInput){this._catalogInput.dispose()}if(this._checkBox){this._checkBox.dispose()}}})})();