var Unibase;(function(n){let t;(function(t){let i;(function(i){let r;(function(r){class u extends t.Core.BaseComponent{constructor(){super();this.parentGroupId=0;this.groupId=0;this.groupName="";this._reportManager=i.Managers.ReportManager.Instance()}cssFiles(){return[]}jsFiles(){return["platform/analytics/requests/reportgroup.js","platform/core/infos/status.js"]}html(){return`
`}load(t,i){var r=this;r.parentGroupId=0;$("#"+i).find(".modal-body").css("height",$(window).outerHeight()-$("#"+i).find(".modal-header").outerHeight()-$("#"+i).find(".modal-footer").outerHeight()+"px");t!=0&&r.loadReportGroup(t);$("#btn_SaveReportGrp").click(function(){let e=$("#reportGroup_IsInternalGroup").prop("checked"),f=$("#txt_reportgroupindex").val();if($("#txt_GroupName").val()=="")return MessageHelper.Instance().showError("Please select ReportGroup","divReportGroup_ErrorMessage");let u=new n.Platform.Analytics.Reports.Requests.ReportGroup;u.GroupName=String($("#txt_GroupName").val());u.ReportGroupId=t;u.IsInternalGroup=e;u.ReportGroupIndex=parseInt(f)?parseInt(f):0;u.ParentGroupId=r.parentGroupId;r._reportManager.saveReportGroup(u).then(function(t){let r=JSON.parse(t.result);t.status==n.Data.Status.Error?MessageHelper.Instance().showError(t.message,"divReportGroup_ErrorMessage"):($("#RptGroup_AutoComplete").append(""+r.GroupName+"<\/option>"),MessageHelper.Instance().showSuccess(t.message,""),$("#"+i).modal("hide"),$("#"+i).remove())})});$("#btn_CloseForm").click(function(){$("#"+i).modal("hide");$("#"+i).remove();$("#RptGroup_AutoComplete").remove()});r.loadReportGroups();$("#parentgroupid").change(function(t){r.parentGroupId=Number(t.currentTarget.value);var i=t.currentTarget.textContent.trim();if(r.groupId==r.parentGroupId)return t.currentTarget.value="0",t.currentTarget.textContent="",MessageHelper.Instance().showError(`Cannot select same report group as parent group`,"divReportGroup_ErrorMessage"),!1;r.groupId&&r.parentGroupId&&r._reportManager.checkReportGroupDependency(r.groupId,r.parentGroupId).then(u=>{if(u.status==n.Data.Status.Success&&u.result)return t.currentTarget.value="0",t.currentTarget.textContent="",MessageHelper.Instance().showError(`Parent group ${i} has the current report group ${r.groupName} as parent group, change the parent report group and try again`,"divReportGroup_ErrorMessage"),!1})})}loadForm(){var n=this;n.navigationHelper.popup(0,"",n,null,t.Helpers.Size.Large)}loadReportGroupForm(i){var r=0,u=this;i||(r=n.Themes.Providers.DetailHelper.recordId);u.navigationHelper.popup(r,"",u,null,t.Helpers.Size.Large)}editReportGroup(){var t=this,i=Number(n.Themes.Providers.Detail_Settings.Instance().InputParameters.find(n=>n.Key.endsWith("reportgroupid")).Value);t.navigationHelper.popup(i,"",t,null,n.Platform.Helpers.Size.Large)}loadReportGroup(t){var i=this;i._reportManager.getReportGroupById(t).then(function(t){if(t.status==n.Data.Status.Success){var r=t.result;i.groupId=t.result.ReportGroupId;i.groupName=t.result.GroupName;$("#txt_GroupName").val(r.GroupName);$("#reportGroup_IsInternalGroup").prop("checked",r.IsInternalGroup);$("#txt_reportgroupindex").val(r.ReportGroupIndex);r.ParentGroupId&&i._reportManager.getReportGroupById(r.ParentGroupId).then(t=>{if(t.status==n.Data.Status.Success){var i=new Option(t.result.GroupName,t.result.ReportGroupId.toString(),!0);$("#parentgroupid").append(i)}})}else return MessageHelper.Instance().showError(t.message,"divReportGroup_ErrorMessage")})}exportGroupReports(t){var i=this,r=0;r=t==0?Number(n.Themes.Providers.Detail_Settings.Instance().InputParameters.find(n=>n.Key.endsWith("reportgroupid")).Value):t;r!=0&&(i.navigationHelper.showLoading(),i._reportManager.getReportGroupById(r).then(function(n){let t=n.result.GroupName;i._reportManager.exportGroupreports(r).then(function(n){var u=t+".xml",f=n.result,r=document.createElement("a"),e=new Blob([f],{type:"text/plain"});r.setAttribute("href",window.URL.createObjectURL(e));r.setAttribute("download",u);r.dataset.downloadurl=["text/plain",r.download,r.href].join(":");r.draggable=!0;r.classList.add("dragout");r.click();i.navigationHelper.hideLoading()})}))}deleteReportGroup(){const t=Number(n.Themes.Providers.Detail_Settings.Instance().InputParameters.find(n=>n.Key.endsWith("reportgroupid")).Value),i=Number(n.Themes.Providers.Detail_Settings.Instance().InputParameters.find(n=>n.Key.endsWith("reportcount")).Value);i?bootbox.confirm("One or more reports are associated with this group, Please ensure to delete all reports associated with this group before deleting",()=>{}):bootbox.confirm("Are you sure to delete this group?",i=>{i&&this._reportManager.deleteReportGroup(t).then(t=>{t.status==n.Data.Status.Success?(MessageHelper.Instance().showSuccess("Report group has been sucessfully deleted","divReportGroup_ErrorMessage"),n.Platform.Apps.Managers.AppManager.Instance().getInstallAppId("Unibase_Platform_Analytics_Reports_App_ReportsGroup").then(t=>{t.status==n.Data.Status.Success&&n.Themes.Compact.Components.Nav.Instance().loadList(t.result.InstalledAppId)})):MessageHelper.Instance().showError(t.message,"divReportGroup_ErrorMessage")})})}loadReportGroups(){var n=_appsettings.server_url()+"/apis/v4/unibase/platform/analytics/reportgroups_autocomplete";AutoCompleteHelper.getHelper().Create("#parentgroupid","#hfAutoComplete_ReportGroup",n,null)}static Instance(){return this.instance===undefined&&(this.instance=new u),this.instance}}r.ReportGroup=u})(r=i.Reports||(i.Reports={}))})(i=t.Analytics||(t.Analytics={}))})(t=n.Platform||(n.Platform={}))})(Unibase||(Unibase={}));