(function(){"use strict";u8.Crm.Widgets.RepExplorerPopup=function(t,e){this.Widget($w(t),u8.tools.extend(true,{},u8.Crm.Widgets.RepExplorerPopup.defaults,e||{}));this._popup=null;this._buttons=[];this._closeArgs={}};u8.Crm.Widgets.RepExplorerPopup.makeClass({name:"RepExplorerPopup",deriveFrom:u8.Base.Widgets.Widget,events:["Open","Close"]});u8.Crm.Widgets.RepExplorerPopup.defaults={popup:{position:"center",alignTo:"window",size:{width:750,height:450},allowMaximize:true,disposeOnClose:false,title:null},repExplorer:{model:{mode:"singleSelect"}},buttons:null,disposeOnClose:false};var t={ok:"TXT_RepUtils_text_9",cancel:"TXT_RepUtils_text_8"};$.extend(u8.Crm.Widgets.RepExplorerPopup.prototype,{open:function(){var t=this;if(!this._popup){this._popup=new u8.Base.Widgets.Popup("<div class='u8-padding-l u8-layout-fill'></div>",this.popup);this._popup.bind("Create",this._onPopupCreate.bind(this),this.id);this._popup.bind("Close",this._onPopupClose.bind(this));u8.using({texts:["RepUtils_text"]},function(){if(t._popup.title===null){t._popup.title=$t("TXT_RepUtils_text_0")}t._popup.open()})}else{this._popup.open()}},dispose:function(){if(this._isDisposed){return}if(this._popup){this._popup.dispose()}this._popup=null;this._repExplorer=null;this._buttons=null;this._model.unbind("*",this.id);this.Widget_dispose()},getModel:function(){return this._model},_onModelRepStateChange:function(){if(!this._model.mode.multiSelect||this._model.selectAll===true){this._popup.close()}},_onPopupCreate:function(e,i){var s=e.getContent(),o=s.window().$,p=o("<div></div>").addClass("center").attr("id",this.id+"_RepExplorer").appendTo(s),n=o.extend({},this.repExplorer,{parent:this});this._repExplorer=new u8.Crm.Widgets.RepExplorer(p,n);this._model=this._repExplorer.model;this._model.bind("RepStateChange",this._onModelRepStateChange.bind(this),this.id);if(this._model.filterName){this._popup.setTitle([this._popup.title," (",this._model.filterName,")"].join(""))}if(this.buttons&&this.buttons.length>0){var u=o("<div></div>").addClass("bottom").addClass("u8-buttons").appendTo(s);for(var l=0;l<this.buttons.length;l++){var d=o("<button type='button'></button>").addClass("u8-repexplorer-popup-button").appendTo(u),r=this.buttons[l];var h=typeof r=="object"?r.text?r.text:$t(t[r.id]):r;r=new u8.Base.Widgets.Button(d,{parent:this,text:h,onClick:this._onButtonClick.bind(this),_button:r});this._buttons.push(r)}}u8.Base.Dom.layout(s.get(0),{name:"dock",includeContainerPadding:true});this._popup.unbind("*",this.id);this.raise("Open")},_onPopupClose:function(t,e){this.raise("Close",this._closeArgs);if(this.disposeOnClose){this.dispose()}},_onButtonClick:function(t,e){this._closeArgs.button=t._button;this._popup.close()}})})();