(function(){"use strict";u8.Crm.Widgets.InfoAreaSelector=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.InfoAreaSelector.defaults,t));this._create()};u8.Crm.Widgets.InfoAreaSelector.defaults={showPlural:false,prependEmptyValue:false,showLockedInfoAreas:true,showVirtualInfoAreas:true,idPostifx:false};u8.Crm.Widgets.InfoAreaSelector.makeClass({name:"InfoAreaSelector",deriveFrom:u8.Base.Widgets.Widget,events:["ValueChange"]});$.extend(u8.Crm.Widgets.InfoAreaSelector.prototype,{getValue:function(){return this.infoAreaId},setValue:function(e){if(this.infoAreaId==e){return}this.infoAreaId=e;if(this._combo){this._combo.setValue(e)}this.raise("ValueChange",{value:this.getValue()})},dispose:function(){if(this._isDisposed){return}this._combo=null;this.Widget_dispose()},update:function(e){if(e.reason=="attr"){var t={};if(e.properties.infoAreaId){t.selectedItem=this.infoAreaId}if(e.properties.infoAreaIds||e.properties.showPlural||e.properties.prependEmptyValue||e.properties.showLockedInfoAreas){t.items=this._createItemModel()}this._combo.attr(t)}},_create:function(){this.$(this.element).addClass("u8-infoarea-selector");var e=this.element;var t=e.ownerDocument;var i=t.createElement("div");i.style.marginLeft=5;if(this.label){var s=t.createElement("div");s.textContent=this.label;s.style.marginRight=2;s.style.cssFloat="left";s.style.paddingBottom=0;i.appendChild(s)}var a=t.createElement("div");i.appendChild(a);e.style.whiteSpace="nowrap";e.appendChild(i);this._combo=u8.widget("ComboBox",a,$.extend(this.comboBox,{onValueChange:this._onComboBoxValueChange.bind(this),parent:this,items:this._createItemModel(),value:this.infoAreaId}))},_onComboBoxValueChange:function(){if(!this._combo){return}var e=this._combo.getValue();this.setValue(e)},_createItemModel:function(){var e=[];var t=u8.services.schema;var i=this.showPlural;var s=this.infoAreaIds||t.getInfoAreaIds();for(var a=0;a<s.length;a++){var r=s[a];var o=t.getInfoArea(r);if(!this.showLockedInfoAreas&&!o.canView()||!this.showVirtualInfoAreas&&o.isVirtualInfoArea){continue}var n=i?o.labelPlural:o.label;if(!n){n=r}else if(this.idPostfix){n+=" ("+r+")"}e.push({key:r,text:n})}e.sort(u8._.cmp("text"));if(this.prependEmptyValue){e.insert(0,{key:"",text:""})}return e}})})();