(function(){"use strict";u8.Crm.Widgets.LyrisCreateMailingListPopup=function(i,t){$.extend(this,u8.Crm.Widgets.LyrisCreateMailingListPopup.defaults,t);this.WidgetContainer();this.element=i;this.$=$w(i).$;this.id=u8.Base.Dom.uniqueId();this._popup=null;this._editor=null;if(this.parent&&this.parent.children){this.parent.children.add(this)}this.commandBindings={Ok:this._onOk.bind(this),Cancel:this._onCancel.bind(this)};this.bind()};u8.Crm.Widgets.LyrisCreateMailingListPopup.makeClass({name:"LyrisCreateMailingListPopup",deriveFrom:u8.Base.Widgets.WidgetContainer,events:["Close","MailingListAdded"]});u8.Crm.Widgets.LyrisCreateMailingListPopup.defaults={popup:{sizing:"fit",allowResize:false,position:"center",showArrow:true}};$.extend(u8.Crm.Widgets.LyrisCreateMailingListPopup.prototype,{open:function(){u8.using({texts:["button_text","Lyris_Integration"]},function(){var i=$.extend(this.popup,{autoShow:false,parent:this,onCreate:this._onPopupCreate.bind(this),onClose:this._onPopupClose.bind(this),title:$t("TXT_Lyris_Integration_49")});this._popup=new u8.Base.Widgets.Popup("<div></div>",i);this._popup.open()}.bind(this))},dispose:function(){if(this._isDisposed){return}this.unbind();this._popup=null;this._editor=null;this.WidgetContainer_dispose();if(this.parent&&this.parent.children){this.parent.children.remove(this.id)}},setValue:function(i){this.model=i||null},getValue:function(){return this.model},_onPopupCreate:function(i,t){this.model.mailingListNameTooltip=$t("TXT_Lyris_Integration_49");this.model.id=this.id;this._popup.getContent().utml({url:"LyrisCreateMailingListPopup.utml.htm",itemOptions:{parent:this._popup},data:this.model});this._popup.autoSizeAndPosition().show()},_onPopupClose:function(){this.dispose()},_onOk:function(){var i=this;u8.services.lyris.createLyrisMailingList(this.model.mailingListName,function(t){switch(t.success){case true:i.raise("MailingListAdded",{id:t.mailingListId,name:i.model.mailingListName});if(i._isDisposed){return}i.raise("Close",{ok:true,cancel:false});i._popup.close();break;case false:var e=i._popup.$("#"+i.id+"_errorMessage");var s=$t("TXT_Lyris_Integration_54")+" "+t.errorMessage;e.text(s);e.show();break}})},_onCancel:function(){this.raise("Close",{ok:false,cancel:true});if(this._isDisposed){return}this._popup.close()}})})();