(function(){"use strict";u8.Crm.Widgets.CatalogRatingInput=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.CatalogRatingInput.defaults,t));this._createModel()};u8.Crm.Widgets.CatalogRatingInput.defaults={infoAreaId:null,fieldId:null,imageTemplate:null};u8.Crm.Widgets.CatalogRatingInput.makeClass({name:"CatalogRatingInput",deriveFrom:u8.Base.Widgets.Widget,events:["ValueChange","Create"]});$.extend(u8.Crm.Widgets.CatalogRatingInput.prototype,{dispose:function(){if(this._isDisposed){return}if(this._model){this._model.dispose()}this.Widget_dispose()},update:function(e){if(!e){return this._create()}if(!this._isCreated){return undefined}switch(e.reason){case"attr":var t=this,i=e.properties,a=["readonly","disabled","tabIndex"].reduce(function(e,a){if(i&&a in i){e[a]=t[a]}return e},{});this._ratingInput.attr(a);break;case"items":this._model.update();break;default:break}},isFocusable:function(){return this._ratingInput&&this._ratingInput.isFocusable()},getValue:function(){return this._model.getValue()},setValue:function(e){this._model.setValue(e);return this},getParentValue:function(){return this._model.getParentValue()},setParentValue:function(e){this._model.setParentValue(e)},_createModel:function(){if(!("lockedCatalogMode"in this)){this.inheritProperty("lockedCatalogMode",u8.session.webConfigValues.get("Query_Analysis.ShowLockedCatalogValues")||u8.Crm.Catalogs.LockedCatalogMode.disable)}var e={id:this.id,page:this.page,allowNull:this.allowNull,infoAreaId:this.infoAreaId,fieldId:this.fieldId,order:this.itemsOrder,lockedCatalogMode:this.lockedCatalogMode,prependNullItem:false,onCreate:this._onModelCreate.bind(this),onUpdate:this._onModelUpdate.bind(this)};if(typeof this.value!="undefined"){e.value=this.value;delete this.value}if(typeof this.parentValue!="undefined"){e.parentValue=this.parentValue;delete this.parentValue}this._model=u8.services.catalogs.createItemsModel(e)},_updateRatingInput:function(){if(this._ratingInput.items.length<=0||this._ratingInput.items[0]._loading){return}this._assertValue(this._value);this._ratingInput.setValue(this._value)},_createView:function(){this.empty();var e=this.imageTemplate;var t=this.style||(this.imageTemplate?"images":"boxes");this._ratingInput=new u8.Base.Widgets.RatingInput(this.element,$.extend({imageTemplate:e,mode:this.mode||(e?"radio":"range"),itemToStyle:t=="images"?null:undefined,items:this._model.items,value:this._model.getValue(),keyProperty:"code",textProperty:"text",style:t,styleOrder:this.styleOrder,readonly:this.readonly,disabled:this.disabled,allowNull:this._model.allowNull,nullValue:this._model.nullValue,showValue:this.showValue,tabIndex:this.tabIndex,parent:this,onValueChange:this._onRatingInputValueChange.bind(this)},this.ratingInput))},_onModelCreate:function(e){this._model=e;this._createView();this._isCreated=true;this.raise("Create",{})},_onModelUpdate:function(e,t){if(t.items){if(this._ratingInput){this._ratingInput.attr({items:this._model.items})}}if(t.value){var i=this._model.getValue();if(this._ratingInput){this._ratingInput.setValue(i)}this.raise("ValueChange",{value:i})}},_onRatingInputValueChange:function(e){this._model.setValue(e.getValue())}})})();