(function(){"use strict";u8.Crm.Widgets.SerialEntryScaleOfDiscountComboBox=function(t,e){this._doNotChangeAmount=true;this.SerialEntryDetailsComboBox(t,$.extend({},u8.Crm.Widgets.SerialEntryScaleOfDiscountComboBox.defaults,e));this.bind({onValueChange:this._onValueChange.bind(this),onCreate:this._onCreate.bind(this)})};u8.Crm.Widgets.SerialEntryScaleOfDiscountComboBox.makeClass({name:"SerialEntryScaleOfDiscountComboBox",deriveFrom:u8.Crm.Widgets.SerialEntryDetailsComboBox,events:["Create","ValueChange","QuantityChange"]});u8.Crm.Widgets.SerialEntryScaleOfDiscountComboBox.defaults={};$.extend(u8.Crm.Widgets.SerialEntryScaleOfDiscountComboBox.prototype,{dispose:function(){if(this._isDisposed){return}this.unbind();this.Widget_dispose()},setQuantity:function(t){t=parseInt(t,10);if(isNaN(t)){return}this._quantity=t;this._quantityChange()},getQuantity:function(){return this._quantity},_initialize:function(t){Function.join(this.SerialEntryDetailsComboBox__initialize,this._loadSettings).call(this,t)},_loadSettings:function(t){var e=u8.Crm.Widgets.SerialEntryScaleOfDiscountComboBox;this._doNotChangeAmount=e._doNotChangeAmount;if(this._doNotChangeAmount!==undefined){if(t){t()}return}var i=this;var n={section:"OPTION",option:"NO_SCALE_DISCOUNT"};u8.request("SettingsChannel.GetCoreConfigurationBooleanValue",n,function(t,n){i._doNotChangeAmount=e._doNotChangeAmount=n.response}.chain(t))},_quantityToKey:function(t){var e=undefined;(this.getItems()||[]).every(function(i){if(i.bulkDiscountVon<=t&&t<=i.bulkDiscountBis){e=i.bulkDiscountVon}return!e});return e},_keyToQuantity:function(t){return t},_quantityChange:function(){this.raise("QuantityChange",{});this.setValue(this._quantityToKey(this._quantity))},_onValueChange:function(t,e){if(this._doNotChangeAmount){return}var i=this.getValue();if(this._quantityToKey(this._quantity)!=i){var n=this._keyToQuantity(i);this.setQuantity(n)}},_onCreate:function(t,e){if(this._quantity){this.setQuantity(this._quantity)}}});u8.services.fieldWidgetFactory.register("hidden",[{name:"ScaleOfDiscountComboBox",create:function(t,e,i){return{type:"SerialEntryScaleOfDiscountComboBox"}},"View.postCreate":function(t){u8.Crm.Widgets.SerialEntryDetailsComboBox.viewPostCreate(t);var e=t.widgetInfo.binding;if(e){e.push({isDynamic:true,sourcePath:["Field(Root."+u8.services.schema.getField("UP","Quantity").fieldId+")"],targetPath:"@quantity",targetToSource:true,sourceToTarget:true})}$.extend(t.widgetInfo.options,{detailsName:"discounts",itemSelector:function(t){return $.extend(t,{key:t.bulkDiscountVon,text:t.bulkDiscountTextInfo||""})}})}}])})();