(function(){"use strict";u8.Crm.Widgets.KPIDataModelFieldSelector=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.KPIDataModelFieldSelector.defaults,t));this._create()};u8.Crm.Widgets.KPIDataModelFieldSelector.noFieldSelectedValue=-1;u8.Crm.Widgets.KPIDataModelFieldSelector.defaults={value:u8.Crm.Widgets.KPIDataModelFieldSelector.noFieldSelectedValue};u8.Crm.Widgets.KPIDataModelFieldSelector.makeClass({name:"KPIDataModelFieldSelector",deriveFrom:u8.Base.Widgets.Widget,events:["ValueChange"]});$.extend(u8.Crm.Widgets.KPIDataModelFieldSelector.prototype,{getValue:function(){return this.value},setValue:function(e){if(this.value==e){return}this.value=e;this._combo.setValue(e);this.raise("ValueChange",{value:this.getValue()})},setInfoAreaId:function(e){if(!e){return}var t=this.infoAreaId!=e;if(t){this.setValue(u8.Crm.Widgets.KPIDataModelFieldSelector.noFieldSelectedValue)}this.infoAreaId=e;var i=this;this._createItemModel(function(e){i._combo.attr({items:e,selectedItem:i.getValue()})})},dispose:function(){if(this._isDisposed){return}this._combo=null;this.Widget_dispose()},update:function(e){if(e.reason=="attr"){if(e.properties.value){this.setValue(e.properties.value)}if(e.properties.infoAreaId){this.setInfoAreaId(e.properties.infoAreaId)}}},_create:function(){this.$(this.element).addClass("u8-datamodelfield-selector");var e=this.element;var t=e.ownerDocument;var i=t.createElement("div");i.style.marginLeft=5;if(this.label){var a=t.createElement("div");a.textContent=this.label;a.style.marginRight=2;a.style.cssFloat="left";a.style.paddingBottom=0;i.appendChild(a)}var l=t.createElement("div");i.appendChild(l);e.style.whiteSpace="nowrap";e.appendChild(i);this._combo=u8.widget("ComboBox",l,$.extend(this.comboBox,{onValueChange:this._onComboBoxValueChange.bind(this),parent:this,value:this.value}))},_onComboBoxValueChange:function(){if(!this._combo){return}var e=this._combo.getValue();this.setValue(e)},_createItemModel:function(e){var t=this;if(this.infoAreaId){u8.using({schema:this.infoAreaId},function(){u8.services.kpis.getFieldsAllowedForKPIDefinition(t.infoAreaId,function(i){var a=[];var l=u8.services.schema.getInfoArea(t.infoAreaId);for(var o=0;o<i.length;o++){var s=i[o];var r=l.fieldsById[s];var d=r.fieldId;var n=r.label;a.push({key:d,text:n})}a.sort(u8._.cmp("text"));a.insert(0,{key:u8.Crm.Widgets.KPIDataModelFieldSelector.noFieldSelectedValue,text:""});e(a)})})}}})})();