(function(){"use strict";u8.Crm.Widgets.LyrisCreateDemographicPopup=function(e,i){$.extend(this,u8.Crm.Widgets.LyrisCreateDemographicPopup.defaults,i);this.WidgetContainer();this.element=e;this.$=$w(e).$;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.LyrisCreateDemographicPopup.makeClass({name:"LyrisCreateDemographicPopup",deriveFrom:u8.Base.Widgets.WidgetContainer,events:["Close","DemographicCreated"]});u8.Crm.Widgets.LyrisCreateDemographicPopup.defaults={popup:{sizing:"fit",allowResize:false,position:"center",showArrow:true}};$.extend(u8.Crm.Widgets.LyrisCreateDemographicPopup.prototype,{open:function(){u8.using({texts:["button_text","Lyris_Integration"]},function(){var e=$.extend(this.popup,{autoShow:false,parent:this,onCreate:this._onPopupCreate.bind(this),onClose:this._onPopupClose.bind(this),title:$t("TXT_Lyris_Integration_63")});this._popup=new u8.Base.Widgets.Popup("<div></div>",e);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(e){this.model=e||null},getValue:function(){return this.model},_onPopupCreate:function(e,i){this._popup.getContent().utml({url:"LyrisCreateDemographicPopup.utml.htm",itemOptions:{parent:this._popup},data:this.model});this._popup.autoSizeAndPosition().show()},_onPopupClose:function(){this.dispose()},_onOk:function(){var e=this;u8.services.lyris.createDemographic(this.model,function(i){switch(i.success){case true:e.raise("DemographicCreated",{demographicId:i.demographicId,demographicName:i.demographicName,mapping:e.model.mapping});if(e._isDisposed){return}e.raise("Close",{ok:true,cancel:false});e._popup.close();break;case false:var t=e._popup.$("#errorMessage");var s=$t("TXT_Lyris_Integration_54")+" "+i.errorMessage;t.text(s);t.show();break}})},_onCancel:function(){this.raise("Close",{ok:false,cancel:true});if(this._isDisposed){return}this._popup.close()}})})();