(function(){"use strict";u8.Crm.Widgets.SerialEntryDetailsComboBox=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.SerialEntryDetailsComboBox.defaults,t));this._isCreated=false;this._create()};u8.Crm.Widgets.SerialEntryDetailsComboBox.defaults={additionalChargesParameters:{}};$.extend(u8.Crm.Widgets.SerialEntryDetailsComboBox.prototype,{setValue:function(e){this._value=e;if(this._comboBox){this._comboBox.setValue(e)}},getValue:function(){if(this._comboBox){return this._comboBox.getValue()}return this._value},getItems:function(){return this._items},_create:function(){this._initialize(u8.tools.createdWhenReady.curry(this))},_initialize:function(e){Function.chain(Function.chain.onDisposedAbort,this._loadItems,this._createView.async()).call(this,e)},_loadItems:function(e){var t={name:this.detailsName,options:{serialEntryType:this.serialEntryName,link:this.link,copyUid:this.copyUid,childUid:this.childUid,additionalParameters:this.additionalParameters,additionalDetailsParameters:this.additionalChargesParameters}};var i=this;u8.request("SerialEntryChannel.GetDetails",t,function(e,t){var a=u8.tools.isArray(t.response)&&t.response;i._items=a&&a.map(i.itemSelector)}.chain(e))},_createView:function(){var e=this.$("<div/>").appendTo(this.element)[0];var t=$.extend({},this.comboBoxOptions,{parent:this,value:this._value,items:this.getItems(),onValueChange:this._onComboBoxValueChange.bind(this)});this._comboBox=u8.widget("ComboBox",e,t)},_onComboBoxValueChange:function(e,t){this.raise("ValueChange",t)},dispose:function(){if(this._isDisposed){return}this.Widget_dispose()}});u8.Crm.Widgets.SerialEntryDetailsComboBox.makeClass({name:"SerialEntryDetailsComboBox",deriveFrom:u8.Base.Widgets.Widget,events:["Create","ValueChange"],virtual:["_initialize"]});$.extend(u8.Crm.Widgets.SerialEntryDetailsComboBox,{viewPostCreate:function(e){if(!e.widgetInfo.binding){return}e.widgetInfo.binding=[{sourcePath:"$SerialEntry.link",targetPath:"link",targetToSource:false},{sourcePath:"#AR/uid",targetPath:"copyUid",targetToSource:false},{sourcePath:"#Root/uid",targetPath:"childUid",targetToSource:false},{sourcePath:"$SerialEntry.additionalParameters",targetPath:"additionalParameters",targetToSource:false},{sourcePath:"$SerialEntry.name",targetPath:"serialEntryName",targetToSource:false},e.widgetInfo.binding]}});u8.services.fieldWidgetFactory.register("hidden",[{name:"ChargesComboBox",create:function(e,t,i){return{type:"SerialEntryDetailsComboBox"}},"View.postCreate":function(e){u8.Crm.Widgets.SerialEntryDetailsComboBox.viewPostCreate(e);e.widgetInfo.options.detailsName="charges";e.widgetInfo.options.itemSelector=function(e){return{key:e.chargeString,quantity:e.chargeAmount,text:e.chargeTextInfo}}}},{name:"SampleChargesComboBox",create:function(e,t,i){return{type:"SerialEntryDetailsComboBox"}},"View.postCreate":function(e){u8.services.fieldWidgetFactory.find("ChargesComboBox")["View.postCreate"](e);if(!e.widgetInfo.binding){return}e.widgetInfo.binding.unshift({sourcePath:["Field(Root."+u8.services.schema.getInfoArea("MU").getField("Stock").fieldId+")"],targetPath:"additionalChargesParameters.stockId",targetToSource:false})}}])})();