(function(){"use strict";u8.Crm.Widgets.LyrisMailingListSelector=function(i,t){this.Widget(i,$.extend({},u8.Crm.Widgets.LyrisMailingListSelector.defaults,t));this.commandBindings={"LyrisMailingList/create":this._onCreateLyrisMailingList.bind(this)};this._create()};u8.Crm.Widgets.LyrisMailingListSelector.defaults={allowNull:false,newMailingListSuggestedName:"",mailingLists:[]};$.extend(u8.Crm.Widgets.LyrisMailingListSelector.prototype,{_create:function(){var i=this.$("<div/>").appendTo(this.element)[0];this._comboBox=u8.widget("ComboBox",i,{parent:this,onDropDownSelectionChange:this._onComboBoxValueChanged.bind(this),actions:[{image:"u8-img-add-s",noFocus:true,command:"LyrisMailingList/create"}]});this._isCreated=true;this._populateComboBoxItems()},setValue:function(i){if(i==this.getValue()){return}this.value=i;if(this._comboBox){this._comboBox.setValue(i)}this.raise("ValueChange",{key:i})},setMailingLists:function(i){if(!i){return}this.mailingLists=i;this._populateComboBoxItems()},setNewMailingListSuggestedName:function(i){this.newMailingListSuggestedName=i},getValue:function(){if(!this._comboBox){return this.value}return this._comboBox.getValue()},dispose:function(){if(this._isDisposed){return}if(this._comboBox){this._comboBox=null}this.Widget_dispose()},_onComboBoxValueChanged:function(i,t){var e=t[i.keyProperty];this.setValue(e)},_populateComboBoxItems:function(i){if(!this._comboBox){return}var t=[];var e=this.value;if(this.allowNull){t.push({key:"",text:""})}this.mailingLists.forEach(function(i){t.push({key:i.id,text:i.name})});this._comboBox.withoutEvents(this._comboBox.attr,{items:t});this._comboBox.withoutEvents(this._comboBox.setValue,this.value);this.raise("ListsLoaded");if(i){i()}},_onCreateLyrisMailingList:function(){var i=new u8.Crm.Widgets.LyrisCreateMailingListPopup(document.body,{parent:this,alignTo:this.element,model:{mailingListName:this.newMailingListSuggestedName},onMailingListAdded:this._addNewMailingList.bind(this)});i.open()},_addNewMailingList:function(i,t){var e=this;this.mailingLists.push(t);this._populateComboBoxItems();this.setValue(t.id)}});u8.Crm.Widgets.LyrisMailingListSelector.makeClass({name:"LyrisMailingListSelector",deriveFrom:u8.Base.Widgets.Widget,events:["ValueChange","ListsLoaded"]})})();