
const staticDashlets=["hypermap_map_inboard","latestalerts_map_inboard","metrics_map_inboard","metrics_map_inboard","xicore_getting_started_inboard","xicore_admin_tasks_inboard","xicore_eventqueue_chart_inboard","xicore_component_status_inboard","xicore_server_stats_inboard","xicore_monitoring_stats_inboard","xicore_monitoring_stats_inboard","xicore_monitoring_process_inboard","xicore_host_status_summary_inboard","xicore_service_status_summary_inboard","xicore_comments_inboard","xicore_hostgroup_status_overview_inboard","xicore_hostgroup_status_overview_inboard","xicore_servicegroup_status_overview_inboard","xicore_servicegroup_status_grid_inboard","xicore_hostgroup_status_summary_inboard","xicore_servicegroup_status_summary_inboard","xicore_available_updates_inboard","xicore_network_outages_inboard","xicore_network_outages_summary_inboard","xicore_network_health_inboard","xicore_host_status_tac_summary_inboard","xicore_service_status_tac_summary_inboard","xicore_feature_status_tac_summary_inboard","alert_history_inboardclass","availability_report_inboard","gauges_inboardclass","modern_gauge_inboardclass","rss_dashlet_inboardclass","sla_report_inboard","snmptraps_inboardclass","worldtimeserver_inboardclass",];$(document).ready(function(){init_dashlet_js();if(document.getElementById("maincontentframe")){document.getElementById("maincontentframe").focus();}
let localStorageDashlets=JSON.parse(localStorage.getItem("dashlets"));let storedDashlets=JSON.parse(localStorage.getItem("dashlets"))||[];storedDashlets.forEach(item=>{if(item.props&&item.props.type==="delete"){storedDashlets=storedDashlets.filter(d=>d.dashlet!==item.dashlet);localStorage.setItem("dashlets",JSON.stringify(storedDashlets));}});});function get_dashlet_dashboard_id(){var b=$("body");var bid=b[0].id;var board="";var pre=bid.substr(0,9);if(pre=="dashboard"){board=bid.substr(10);}else{board="screen";}
return board;}
function init_dashlet_js(){var Mementos=[];var redoMementos=[];var toBeDeleted=[];var gridSize=10;let widthOffset=30;if(is_neptune()){widthOffset=30;}
let heightOffset=50;if(is_neptune()){heightOffset=45;}
Mementos=new Proxy(Mementos,{set(target,property,value){target[property]=value;return true;}});$("#fake-message-delete").click(function(){$("#fake-data-message").hide();});function updateDashletZIndex(container){let highestZIndex=0;$(".dashboarddashletcontainer").each(function(){let zIndex=parseInt($(this).css("z-index"),10);if(zIndex>highestZIndex){highestZIndex=zIndex;}});let newZIndex=highestZIndex+1;container.css("z-index",newZIndex);var board=get_dashlet_dashboard_id();var dashletid=$(container)[0].id;var dashlet=dashletid.substr(17);var optsarr={board:board,dashlet:dashlet,props:{zindex:newZIndex},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);}
$(".dashboarddashletcontainer").click(function(){updateDashletZIndex($(this));});$(".dashboarddashletcontainer").hover(function(){var theclass="dashboarddashlethover";var dragdisabled=$(this).hasClass("ui-draggable-disabled");if(dragdisabled==true){theclass+=" dashboarddashlethover-pinned";}
$(this).addClass(theclass);$(this).find(".dashboarddashletcontrol").each(function(){$(this).css("visibility","visible");});$(this).children(".ui-resizable-se").each(function(){$(this).css("visibility","visible");});const title=$(this).find(".dashlettopbox").find(".dashlettitle");if(title.hasClass("hiddentitle")){title.css("visibility","hidden");}else{title.css("visibility","visible");}},function(){$(this).removeClass("dashboarddashlethover");$(this).removeClass("dashboarddashlethover-pinned");$(this).find(".dashboarddashletcontrol").each(function(){$(this).css("visibility","hidden");});$(this).children(".ui-resizable-se").each(function(){$(this).css("visibility","hidden");});});$(".dashletpin, .dashletpin-dropdown").click(function(){var container=$(this).closest(".dashboarddashletcontainer");var pinned=0;var dragdisabled=$(container).hasClass("ui-draggable-disabled");if(dragdisabled==true){$(container).draggable("enable");if($(this).hasClass("dashletpin")){$(this).find("i").removeClass("fa-rotate-180");$(this).attr("data-original-title","Pin");$(this).tooltip("show");}else{$(this).text("Pin");}
$(container).resizable("enable");pinned=0;}else{$(container).draggable("disable");if($(this).hasClass("dashletpin")){$(this).find("i").addClass("fa-rotate-180");$(this).attr("data-original-title","Unpin");$(this).tooltip("show");}else{$(this).text("Unpin");}
$(container).resizable("disable");pinned=1;}
var board=get_dashlet_dashboard_id();var dashletid=$(container)[0].id;var dashlet=dashletid.substr(17);var zindex=$(container[0]).css("z-index");var optsarr={board:board,dashlet:dashlet,props:{pinned:pinned,zindex:zindex,type:"pin",},};Mementos.push(optsarr);var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);});$(".showalldashletbackgrounds").click(function(){$(".dashboarddashletcontainer").each(function(){if($(this).hasClass("hidebordersandbackgrounds")){$(this).removeClass("hidebordersandbackgrounds");}
let icon=$(this).find(".dashlettogglebackground");let dropdownOption=$(this).find(".dashlettogglebackground-dropdown");icon.attr("data-original-title","Hide Background");icon.find("i").html("shadow_minus");dropdownOption.text("Hide Background");var optsarr={board:get_dashlet_dashboard_id(),dashlet:$(this)[0].id.substr(17),props:{hideBackgroundAndBorders:false},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);});});$(".hidealldashletbackgrounds").click(function(){$(".dashboarddashletcontainer").each(function(){if(!$(this).hasClass("hidebordersandbackgrounds")){$(this).addClass("hidebordersandbackgrounds");}
let icon=$(this).find(".dashlettogglebackground");let dropdownOption=$(this).find(".dashlettogglebackground-dropdown");icon.attr("data-original-title","Show Background");icon.find("i").html("shadow_add");dropdownOption.text("Show Background");var optsarr={board:get_dashlet_dashboard_id(),dashlet:$(this)[0].id.substr(17),props:{hideBackgroundAndBorders:true},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);});});$(".dashlettogglebackground, .dashlettogglebackground-dropdown").click(function(){let container=$(this).closest(".dashboarddashletcontainer");let icon=container.find(".dashlettogglebackground");let dropdownOption=container.find(".dashlettogglebackground-dropdown");if(container.hasClass("hidebordersandbackgrounds")){icon.attr("data-original-title","Hide Background");icon.find("i").html("shadow_minus");icon.tooltip("show");dropdownOption.text("Hide Background");container.removeClass("hidebordersandbackgrounds");}else{icon.attr("data-original-title","Show Background");icon.find("i").html("shadow_add");icon.tooltip("show");dropdownOption.text("Show Background");container.addClass("hidebordersandbackgrounds");}
var optsarr={board:get_dashlet_dashboard_id(),dashlet:container[0].id.substr(17),props:{hideBackgroundAndBorders:container.hasClass("hidebordersandbackgrounds")},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);});$(".dashlethidetitle, .dashlethidetitle-dropdown").click(function(){var topbox=$(this).closest(".dashlettopbox");var container=$(this).closest(".dashboarddashletcontainer");var title=topbox.find(".dashlettitle");var titleIcon=topbox.find(".dashlethidetitle");var titleDropdownOption=topbox.find(".dashlethidetitle-dropdown");var showtitle=1;if(title.hasClass("hiddentitle")){titleIcon.find("i").html("visibility_off");titleIcon.attr("data-original-title","Hide Title");titleIcon.tooltip("show");titleDropdownOption.text("Hide Title");title.removeClass("hiddentitle");}else{titleIcon.find("i").html("visibility");titleIcon.attr("data-original-title","Show Title");titleIcon.tooltip("show");titleDropdownOption.text("Show Title");title.addClass("hiddentitle");showtitle=0;}
var board=get_dashlet_dashboard_id();var dashletid=$(container)[0].id;var dashlet=dashletid.substr(17);var optsarr={board:board,dashlet:dashlet,props:{showtitle:showtitle,type:"title",},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);});$(".dashletdelete, .dashletdelete-dropdown").click(function(){show_throbber();var board=get_dashlet_dashboard_id();if(demo_mode==1&&board=="home"){console.log("Deleting dashlets from the home page dashboard is disabled while in demo mode.");var content="<div id='popup_header' style='margin-bottom: 5px;'><b>"+
_("Error")+"</b></div><div id='popup_data'><p>"+
_("Deleting dashlets from the home page dashboard is disabled while in demo mode.")+"</p></div>";hide_throbber();set_child_popup_content(content);display_child_popup();fade_child_popup("red",2000);return;}
var conf=confirm(_("Are you sure you would like to delete this dashlet?."));if(!conf){hide_throbber();console.log("User canceled delete");return;}
var container=$(this).closest(".dashboarddashletcontainer");var dashletid=$(container)[0].id;var dashlet=dashletid.substr(17);var optsarr={board:board,dashlet:dashlet,props:{type:"delete",},};Mementos.push(optsarr);var opts=JSON.stringify(optsarr);toBeDeleted.push(optsarr);var result=get_ajax_data("setdashletproperty",opts);localStorage.setItem("dashlets",JSON.stringify(toBeDeleted));show_throbber();var content="<div id='popup_header'><b>"+
_("Dashlet Deleted")+"</b></div><div id='popup_data'><p>"+
_("Dashlet removed from dashboard.")+"</p></div>";hide_throbber();set_child_popup_content(content);display_child_popup();fade_child_popup("red");$(container).fadeOut("slow");});$(".arrange-dashboard-dashlets").click(function(){let padding=0;let currentX=padding;let currentY=padding;let maxHeightInRow=0;let dashlets=[];let pinnedDashlets=[];$(".dashboarddashletcontainer").each(function(){let dashlet={container:$(this),width:$(this).outerWidth(true),height:$(this).outerHeight(true),left:$(this).position().left,top:$(this).position().top,pinned:$(this).hasClass("ui-draggable-disabled")}
if(dashlet.pinned){pinnedDashlets.push(dashlet);}else{dashlets.push(dashlet);}});dashlets.sort((a,b)=>a.height-b.height);function checkCollision(x,y,width,height){for(let pinnedDashlet of pinnedDashlets){if(x+width>pinnedDashlet.left&&x<pinnedDashlet.left+pinnedDashlet.width&&y+height>pinnedDashlet.top&&y<pinnedDashlet.top+pinnedDashlet.height){return{collision:true,pinnedDashletBottom:pinnedDashlet.top+pinnedDashlet.height};}}
return{collision:false};}
function findNextValidY(startY,currentX,width){let nextY=startY;let hasCollision;do{hasCollision=false;for(let pinnedDashlet of pinnedDashlets){if(currentX+width>pinnedDashlet.left&&currentX<pinnedDashlet.left+pinnedDashlet.width&&nextY<pinnedDashlet.top+pinnedDashlet.height&&nextY+padding>=pinnedDashlet.top){nextY=pinnedDashlet.top+pinnedDashlet.height+padding;hasCollision=true;}}}while(hasCollision);return nextY;}
let maxY=padding;dashlets.forEach(dashlet=>{let attempts=0;const maxAttempts=100;let validPosition=false;while(!validPosition&&attempts<maxAttempts){attempts++;if((currentX+dashlet.width)>$(window).width()){currentX=padding;currentY=findNextValidY(maxY+padding,currentX,dashlet.width);maxHeightInRow=0;}
const collisionResult=checkCollision(currentX,currentY,dashlet.width,dashlet.height);if(collisionResult.collision){if((currentX+dashlet.width+padding)>=$(window).width()){currentX=padding;currentY=findNextValidY(Math.max(maxY,collisionResult.pinnedBottom)+padding,currentX,dashlet.width);continue;}
currentX+=Math.min(50,dashlet.width/2);continue;}
validPosition=true;}
if(!validPosition){currentX=padding;currentY=maxY+padding;}
dashlet.container.animate({left:currentX+"px",top:currentY+"px"},500);var optsarr={board:get_dashlet_dashboard_id(),dashlet:dashlet.container[0].id.substr(17),props:{top:currentY,left:currentX,zIndex:dashlet.container.css("zIndex")},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);currentX+=dashlet.width+padding;if(currentY+dashlet.height>maxY){maxY=currentY+dashlet.height;}
maxHeightInRow=Math.max(maxHeightInRow,dashlet.height);});});$(".dashletreconfigure, .dashletreconfigure-dropdown").click(function(){var container=$(this).closest(".dashboarddashletcontainer");var title=container.find(".dashlettitle").text();var dashletName=$(this).data('dashlet-name');var board=get_dashlet_dashboard_id();var dashletid=$(container)[0].id;var dashlet=dashletid.substr(17);whiteout();show_throbber();var optsarr={board:board,dashlet:dashlet,};var opts=JSON.stringify(optsarr);var dashletArgs=JSON.parse(get_ajax_data("getdashletargs",opts)).dashletargs;if(!dashletArgs){return;}
var optsarr={name:dashletName};var opts=JSON.stringify(optsarr);var dashletConfigHTMLtext=JSON.parse(get_ajax_data("getdashletconfightml",opts)).confightml;var dashletConfigHTML=document.createElement('div');dashletConfigHTML.innerHTML=dashletConfigHTMLtext;gaugeCurrentHost='';gaugeCurrentService='';Object.keys(dashletArgs).forEach(key=>{const element=dashletConfigHTML.querySelector(`[name="${key}"], [name="${key}[]"], [id=${key}]`);if(!element){return;}
let value=dashletArgs[key];if(element.tagName==='SELECT'){if(element.getAttribute("id")==="gauges_form_name"){gaugeCurrentHost=value;load_gauge_hosts(gaugeCurrentHost);}else if(element.getAttribute("id")==="gauges_form_services"){gaugeCurrentService=value;getgaugejson(gaugeCurrentHost,gaugeCurrentService);}else if(element.getAttribute("id")==="gauges_form_ds"){gaugeCurrentDatasource=value;getgaugeservices(gaugeCurrentHost,gaugeCurrentService,gaugeCurrentDatasource);}
Array.from(element.options).forEach(option=>{if(Array.isArray(value)){if(value.includes(option.value)){option.setAttribute("selected",true);}}else if(value==option.value){option.setAttribute("selected",true);}});element.setAttribute("value",value);if(key==='group_select'&&value!='all'){let multipleSelectElement=dashletConfigHTML.querySelector(`[id=${value}_select]`);multipleSelectElement.classList.remove("hide");}}else if(element.tagName==='TEXTAREA'){element.setAttribute("value",value);element.innerHTML=value;}else if(element.type==='checkbox'||element.type==='radio'){if(value==="on")element.setAttribute("checked","checked");}else{element.setAttribute("value",value);}});var content=`
            <div id='popup_header' style='padding-bottom: 5px;'>
                <b>${_('Reconfigure Dashlet')}</b>
            </div>
            <div id='popup_data'>
                <p>${_('Use this to reconfigure an existing dashlet.')}</p>
            </div>
            <form id='reconfiguredashlet_form'>
                <div class='popup-form-box'>
                    <div>
                        <label for='reconfiguredashletTitleBox'>${_('New Title')}</label>
                    </div>
                    <input
                        type='text'
                        size='30'
                        name='title'
                        id='reconfiguredashletTitleBox'
                        value='${title}'
                        class='form-control'
                    >
                    <div id="dashlet-config-html"></div>
                </div>

                <div id='reconfiguredashletFormButtons'>
                    <input
                        type='submit'
                        class='btn btn-sm btn-primary'
                        name='submitButton'
                        value='${_('Submit')}'
                        id='submitReconfigureDashletButton'
                    >
                </div>
            </form>
        `;hide_throbber();set_child_popup_content(content);document.getElementById("dashlet-config-html").appendChild(dashletConfigHTML);display_child_popup();try{if(dashletConfigHTML.querySelector('#gauges_enhanced_form_name')){var eh=dashletArgs['host']||'';var es=dashletArgs['service']||'';var ed=dashletArgs['ds']||'';if(typeof load_gauge_hosts_enhanced==='function'){load_gauge_hosts_enhanced(eh);}
if(typeof getGaugesEnhancedJson==='function'){getGaugesEnhancedJson(eh,es);}
if(typeof getGaugesEnhancedServices==='function'){getGaugesEnhancedServices(eh,es,ed);}}
if(dashletConfigHTML.querySelector('#gauges_form_name')){var lh=dashletArgs['host']||'';var ls=dashletArgs['service']||'';var ld=dashletArgs['ds']||'';if(typeof load_gauge_hosts==='function'){load_gauge_hosts(lh);}
if(typeof getgaugejson==='function'){getgaugejson(lh,ls);}
if(typeof getgaugeservices==='function'){getgaugeservices(lh,ls,ld);}}}catch(e){if(window&&window.console&&console.warn){console.warn('Gauge dropdown init failed:',e);}}
var argsarr={board:board,dashlet:dashlet,update_dashlet_args:true,props:{}};let newTitle="";$("#reconfiguredashlet_form").submit(function(){;$(this).find(":input, :password, :checkbox, :radio, :submit, :reset").each(function(){let name=this.name||this.id||this.parentNode.name||this.parentNode.id;if(!name){return;}
if(['submitButton'].includes(name)){return;}
if(name==='title'){newTitle=$(this).val();}
if(name==='group_select'){argsarr.props[name]=this.value;if(this.value==='hostgroup'||this.value==='servicegroup'){argsarr.props[this.value]=[];}}
else if($(this).is('select[multiple]')){let values=$(this).val()||[];if(name.endsWith('[]')){let groupType=name.slice(0,-2);if(argsarr.props['group_select']===groupType){argsarr.props[groupType]=values;}}else{argsarr.props[name]=values;}}
else if(name.endsWith('[]')){let groupType=name.slice(0,-2);if(!argsarr.props[groupType]){argsarr.props[groupType]=[];}
if(this.value&&argsarr.props['group_select']===groupType){argsarr.props[groupType].push(this.value);}}
else if($(this).is(':checkbox')){argsarr.props[name]=this.checked?this.value:"off";}else{argsarr.props[name]=this.value;}});if(argsarr.props.hasOwnProperty('group_select')&&argsarr.props['group_select']==='all'){argsarr.props['hostgroup']=[];argsarr.props['servicegroup']=[];}
var args=JSON.stringify(argsarr);var result=get_ajax_data("setdashletproperty",args);var optsarr={board:board,dashlet:dashlet,props:{title:newTitle},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);set_child_popup_content("<div id='popup_header'><b>"+_('Dashlet Updated')+"</b></div><div id='popup_data'><p>"+_('Dashlet successfully updated.')+"</p></div>");fade_child_popup("green");setTimeout(function(){window.location.reload();},500);return false;});});function applyScaleToDashlet(gp,scaleFactor,scaleBorder=false){show_throbber();var currentWidth=gp.width();var currentHeight=gp.height();var fc=gp.children(".dashboarddashlet").first();var currentTransform=fc.css("transform");if(currentTransform==="none")currentTransform="";let currentScale=1;const match=currentTransform.match(/matrix\(\s*([^\s,]+),\s*0,\s*0,\s*([^\s,]+),\s*0,\s*0\s*\)/);if(match){currentScale=parseFloat(match[1]);}
const newScale=currentScale*scaleFactor;const newTransform="matrix("+newScale+",0,0,"+newScale+",0,0)";fc.css({"transform":newTransform,"transform-origin":"top left",});var width=currentWidth/(newScale);var height=currentHeight/(newScale);fc.css({"width":width+"px","height":height+"px",});var board=get_dashlet_dashboard_id();var dashletid=gp[0].id;var dashlet=dashletid.substr(17);var optsarr={board:board,dashlet:dashlet,props:{type:"scale",scale:newScale,},};var opts=JSON.stringify(optsarr);Mementos.push(optsarr);var result=get_ajax_data("setdashletproperty",opts);hide_throbber();}
$(".dashletplus, .dashletplus-dropdown").click(function(){applyScaleToDashlet($(this).closest(".dashboarddashletcontainer"),1.25,false);});$(".dashletminus, .dashletminus-dropdown").click(function(){applyScaleToDashlet($(this).closest(".dashboarddashletcontainer"),0.8,false);});function undo(){let optsarr=Mementos[Mementos.length-1];if(optsarr){let dashlet=document.querySelector("#dashletcontainer-"+optsarr.dashlet);if(optsarr.props.type=="drag"){let top=dashlet.style.top.slice(0,-2);let left=dashlet.style.left.slice(0,-2);const currentDashletState={board:optsarr.board,dashlet:optsarr.dashlet,props:{top:top,left:left,zindex:optsarr.props.zindex,type:optsarr.props.type,},};redoMementos.push(currentDashletState);dashlet.style.top=`${optsarr.props.top}px`;dashlet.style.left=`${optsarr.props.left}px`;dashlet.style.zindex=`${optsarr.props.zindex}`;var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);var y=1;Mementos.pop();}else if(optsarr.props.type=="resize"){let dashlet=document.querySelector("#dashletcontainer-"+optsarr.dashlet);let dashletContent=dashlet.querySelector(".dashboarddashlet");let height=dashlet.style.height.slice(0,-2);let width=dashlet.style.width.slice(0,-2);let currentDashletState={board:optsarr.board,dashlet:optsarr.dashlet,props:{height:height,width:width,type:optsarr.props.type,},};redoMementos.push(currentDashletState);dashlet.style.height=`${optsarr.props.height}px`;dashlet.style.width=`${optsarr.props.width}px`;dashletContent.style.height=`${optsarr.props.height}px`;dashletContent.style.width=`${optsarr.props.width}px`;var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);Mementos.pop();}else if(optsarr.props.type=="pin"){let gp=document.querySelector("#dashletcontainer-"+optsarr.dashlet);let pinButton=gp.querySelector(".dashletpin");let pinned=0;let dragdisabled=$(gp).hasClass("ui-draggable-disabled");if(dragdisabled==true){$(gp).draggable("enable");$(pinButton).find("i").removeClass("fa-rotate-180");$(pinButton).attr("data-original-title","Pin");$(gp).resizable("enable");pinned=0;}else{$(gp).draggable("disable");$(pinButton).find("i").addClass("fa-rotate-180");$(pinButton).attr("data-original-title","Unpin");$(gp).resizable("disable");pinned=1;}
const currentDashletState={board:optsarr.board,dashlet:optsarr.dashlet,props:{type:optsarr.props.type,},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);redoMementos.push(currentDashletState);Mementos.pop();}else if(optsarr.props.type=="delete"){let dashlet=document.querySelector("#dashletcontainer-"+optsarr.dashlet);let dashlets=JSON.parse(localStorage.getItem("dashlets"));for(let i=0;i<dashlets.length;i++){if(dashlets[i].dashlet==optsarr.dashlet){dashlets.splice(i,1);}}
localStorage.setItem("dashlets",JSON.stringify(dashlets));$(dashlet).fadeIn("fast");const currentDashletState={board:optsarr.board,dashlet:optsarr.dashlet,props:{type:optsarr.props.type,},};redoMementos.push(currentDashletState);toBeDeleted.pop();Mementos.pop();}}}
function redo(){let optsarr=redoMementos[redoMementos.length-1];if(optsarr){let dashlet=document.querySelector("#dashletcontainer-"+optsarr.dashlet);if(optsarr.props.type=="drag"){let top=dashlet.style.top.slice(0,-2);let left=dashlet.style.left.slice(0,-2);const currentDashletState={board:optsarr.board,dashlet:optsarr.dashlet,props:{top:top,left:left,zindex:optsarr.props.zindex,type:optsarr.props.type,},};Mementos.push(currentDashletState);dashlet.style.top=`${optsarr.props.top}px`;dashlet.style.left=`${optsarr.props.left}px`;dashlet.style.zindex=`${optsarr.props.zindex}`;var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);redoMementos.pop();}else if(optsarr.props.type=="resize"){let dashlet=document.querySelector("#dashletcontainer-"+optsarr.dashlet);let dashletContent=dashlet.querySelector(".dashboarddashlet");let height=dashlet.style.height.slice(0,-2);let width=dashlet.style.width.slice(0,-2);let currentDashletState={board:optsarr.board,dashlet:optsarr.dashlet,props:{height:height,width:width,type:optsarr.props.type,},};Mementos.push(currentDashletState);dashlet.style.height=`${optsarr.props.height}px`;dashlet.style.width=`${optsarr.props.width}px`;dashletContent.style.height=`${optsarr.props.height}px`;dashletContent.style.width=`${optsarr.props.width}px`;var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);redoMementos.pop();}else if(optsarr.props.type=="pin"){let gp=document.querySelector("#dashletcontainer-"+optsarr.dashlet);let pinButton=gp.querySelector(".dashletpin");let pinned=0;let dragdisabled=$(gp).hasClass("ui-draggable-disabled");if(dragdisabled==true){$(gp).draggable("enable");$(pinButton).find("i").removeClass("fa-rotate-180");$(pinButton).attr("data-original-title","Pin");$(gp).resizable("enable");pinned=0;}else{$(gp).draggable("disable");$(pinButton).find("i").addClass("fa-rotate- 180");$(pinButton).attr("data-original-title","Unpin");$(gp).resizable("disable");pinned=1;}
const currentDashletState={board:optsarr.board,dashlet:optsarr.dashlet,props:{type:optsarr.props.type,pinned:pinned,},};Mementos.push(currentDashletState);var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);redoMementos.pop();}else if(optsarr.props.type=="delete"){let dashlet=document.querySelector("#dashletcontainer-"+optsarr.dashlet);let dashlets=JSON.parse(localStorage.getItem("dashlets"));dashlets.push(optsarr);localStorage.setItem("dashlets",JSON.stringify(dashlets));$(dashlet).fadeOut("fast");let currentDashletState={board:optsarr.board,dashlet:optsarr.dashlet,props:{type:optsarr.props.type,},};toBeDeleted.push(currentDashletState);Mementos.push(currentDashletState);redoMementos.pop();}}}
function load_undo_button(){if(window.location.pathname.includes("dashboards")){if(!document.getElementById("undoButton")){var undoButton=document.createElement("div");undoButton.id="undoButton";undoButton.className="btn btn-sm btn-default tt-bind";undoButton.setAttribute("data-placement","left");undoButton.setAttribute("data-html","true");undoButton.setAttribute("data-toggle","tooltip");undoButton.setAttribute("title",getShortcutTextUndo("Undo"));undoButton.setAttribute("data-delay","300");undoButton.style.height="40px";undoButton.style.width="40px";undoButton.style.display="flex";undoButton.style.justifyContent="center";undoButton.style.alignItems="center";undoButton.innerHTML='<i class="fa fa-rotate-left" style="color:inherit; font-size:20px"></i>';undoButton.style.position="fixed";undoButton.style.bottom="20px";undoButton.style.right="80px";undoButton.style.zIndex="1000";var mediaQuery=window.matchMedia("(max-width: 768px)");if(mediaQuery.matches){undoButton.style.bottom="40px";}
$(document).ready(function(){setInterval(function(){var iframe=document.getElementById("maincontentframe");let activeElement=document.activeElement;if(iframe&&activeElement.tagName!=="BODY"&&activeElement.tagName!=="INPUT"){iframe.focus();var iframeDoc=iframe.contentDocument||iframe.contentWindow.document;if(!iframeDoc.getElementById("undoButton")&&iframeDoc.body){iframeDoc.body.appendChild(undoButton);}}},20);});}}}
function getDashletInteriorScaling(el){const containerClientWidth=el.clientWidth;const containerClientHeight=el.clientHeight;const dashletInterior=$(el).children(".dashboarddashlet");const dashletInteriorWidth=dashletInterior.width();const dashletInteriorHeight=dashletInterior.height();const differenceRatioWidth=(containerClientWidth-widthOffset)/dashletInteriorWidth;const differenceRatioHeight=(containerClientHeight-heightOffset)/dashletInteriorHeight;const newInteriorRatio=Math.min(differenceRatioWidth,differenceRatioHeight);return newInteriorRatio;}
function snapDashletContainerToDashletInterior(el){const dashletInterior=$(el).children(".dashboarddashlet");const dashletScale=parseFloat(dashletInterior.css("transform").split(",")[0].replace("matrix(",""))||1;const desirededWidth=dashletInterior.width()*dashletScale;const desirededHeight=dashletInterior.height()*dashletScale;const gridMatchedWidth=Math.ceil(desirededWidth/gridSize)*gridSize;const gridMatchedHeight=Math.ceil(desirededHeight/gridSize)*gridSize;const containerWidth=$(el).width();const containerHeight=$(el).height();if(containerWidth!=gridMatchedWidth){$(el).css('width',gridMatchedWidth+'px');}
if(containerHeight!=gridMatchedHeight){$(el).css('height',gridMatchedHeight+'px');}
return[$(el).height(),$(el).width()];}
function toggleDashletControlsDropdown(container){let controlElements=$(container).find(".dashlettopbox").find(".dashboarddashletcontrol").children();let controlIcons=controlElements.not(".dashletmore, .dashletcontrolsdropdown");let dashletDropdown=controlElements.filter(".dashletcontrolsdropdown");let moreIcon=dashletDropdown.find(".dashletmore");let widthToDisplayDropdown=300;if(parseInt($(container).css('width'),10)<=widthToDisplayDropdown){controlIcons.each(function(){$(this).addClass("dashleticonhidden");});moreIcon.removeClass("dashleticonhidden");}else{controlIcons.each(function(){$(this).removeClass("dashleticonhidden");});moreIcon.addClass("dashleticonhidden");}}
function toggleDashletTitle(container){var topbox=$(container).find(".dashlettopbox");var title=topbox.find(".dashlettitle");var titleDropdownOption=topbox.find(".dashlethidetitle-dropdown");let widthToHideTitleOption=200;if(parseInt($(container).css('width'),10)<=widthToHideTitleOption){title.addClass("disabledtitle");titleDropdownOption.css("display","none");}else{title.removeClass("disabledtitle");titleDropdownOption.css("display","block");}}
function getShortcutTextUndo(actionName){if(navigator.userAgent.indexOf("Mac OS X")!==-1){return"<span class='undo-tag'>Undo</span><span class ='undo-redo-spanners'>⌘</span><span class ='undo-redo-spanners'>Z</span>";}else{return"<span class ='undo-tag'>Undo</span><span class ='undo-redo-spanners'>Ctrl</span><span class ='undo-redo-spanners'>Z</span>";}}
function getShortcutTextRedo(actionName){if(navigator.userAgent.indexOf("Mac OS X")!==-1){return"<span class ='undo-tag'>Redo</span><span class ='undo-redo-spanners'>⌘</span><span class ='undo-redo-spanners'>Shift</span><span class ='undo-redo-spanners'>Z</span>";}else{return"<span class ='undo-tag'>Redo</span><span class ='undo-redo-spanners'>Ctrl</span><span class ='undo-redo-spanners'>Shift</span><span class ='undo-redo-spanners'>Z</span>";}}
function load_redo_button(){if(window.location.pathname.includes("dashboards")){if(!document.getElementById("redoButton")){var redoButton=document.createElement("div");redoButton.id="redoButton";redoButton.className="btn btn-sm btn-default tt-bind";redoButton.setAttribute("data-placement","left");redoButton.setAttribute("data-html","true");redoButton.setAttribute("data-toggle","tooltip");redoButton.setAttribute("title",getShortcutTextRedo("Redo"));redoButton.setAttribute("data-delay","200");redoButton.style.height="40px";redoButton.style.width="40px";redoButton.style.display="flex";redoButton.style.justifyContent="center";redoButton.style.alignItems="center";redoButton.innerHTML='<i class="fa fa-rotate-right"  style="color:inherit; font-size: 20px;"></i>';redoButton.style.position="fixed";redoButton.style.bottom="20px";redoButton.style.right="20px";redoButton.style.zIndex="1000";var mediaQuery=window.matchMedia("(max-width: 768px)");if(mediaQuery.matches){redoButton.style.bottom="40px";}
$(document).ready(function(){setInterval(function(){var iframe=document.getElementById("maincontentframe");let activeElement=document.activeElement;if(iframe&&activeElement.tagName!=="BODY"&&activeElement.tagName!=="INPUT"){iframe.focus();var iframeDoc=iframe.contentDocument||iframe.contentWindow.document;if(!iframeDoc.getElementById("redoButton")&&iframeDoc.body){iframeDoc.body.appendChild(redoButton);}}},20);});}}}
$(document).ready(function(){let fitContentsDashlet=['metrics_map_inboard','latestalerts_map_inboard','xicore_hostgroup_status_summary_inboard','xicore_servicegroup_status_summary_inboard','xicore_comments_inboard','xicore_network_outages_summary_inboard','xicore_hostgroup_status_overview_inboard'];if(!is_neptune()){fitContentsDashlet.push('xicore_getting_started_inboard','xicore_admin_tasks_inboard','xicore_component_status_inboard','xicore_server_stats_inboard','xicore_monitoring_stats_inboard','xicore_monitoring_process_inboard','xicore_perfdata_chart_inboard');}
$(".dashboarddashletcontainer").each(function(){let childDashlet=$(this).children(".dashboarddashlet");if(fitContentsDashlet.some(cls=>childDashlet.hasClass(cls))){setTimeout(()=>{$(this).find(".dashboarddashlet").each(function(){$(this).css({"height":"fit-content","width":"fit-content",});});},500);}else{$(childDashlet).css('opacity','1').show();}
const slowLoadingDashlets={"xicore_hostgroup_status_summary_inboard":1000,"latestalerts_dashlet":1000,};let timeout=500;Array.from(childDashlet[0].classList).forEach(className=>{if(slowLoadingDashlets[className]){timeout=slowLoadingDashlets[className];}});exception_auto_resize=["bbmap_map_inboard","minemap_map_inboard"];if(!exception_auto_resize.some(cls=>childDashlet.hasClass(cls))){$(childDashlet).ajaxComplete(function(event,xhr,settings){if(!$(this).data('resizeObserver')){const dashletContainer=$(this).parent();const observer=new MutationObserver(function(mutations){clearTimeout($(dashletContainer).data('resizeTimer'));$(dashletContainer).data('resizeTimer',setTimeout(function(){let triggersnap=$(childDashlet[0]).hasClass("newdashlet");$(childDashlet[0]).removeClass("newdashlet");triggerResizeOnDashboardDashlet(dashletContainer[0],timeout=timeout,addHeight=0,addWidth=0,triggerSnap=triggersnap);setTimeout(()=>{$(childDashlet).css('opacity','1').show();},timeout);},timeout));});observer.observe(this,{childList:true,subtree:true,attributes:false,characterData:true});$(this).data('resizeObserver',observer);}});}
setTimeout(()=>{$(this).find(".dashboarddashlet").each(function(){$(this).trigger('ajaxComplete');const observer=$(this).data('resizeObserver');if(observer){const tempElement=document.createElement('div');tempElement.style.display='none';this.appendChild(tempElement);setTimeout(()=>this.removeChild(tempElement),0);}});},timeout*10);toggleDashletControlsDropdown(this);});load_undo_button();load_redo_button();let undo=document.getElementById("undoButton");let redo=document.getElementById("redoButton");if(undo&&redo){if(!window.location.pathname.endsWith('dashboard.php')){undo.style.display="none";redo.style.display='none';}else{undo.style.display="flex";redo.style.display="flex";}}
var iframe=document.getElementById("maincontentframe");if(iframe){var iframeDoc=iframe.contentDocument||iframe.contentWindow.document;$(iframeDoc.body).tooltip({selector:'[rel=tooltip]',html:true});}});function triggerResizeOnDashboardDashlet(dashboardDashletContainer,timeout=350,addHeight=0,addWidth=0,triggerSnap=true){let currentScale=$(dashboardDashletContainer).find(".dashboarddashlet").css("transform");currentScale=currentScale?parseFloat(currentScale.split(",")[0].replace("matrix(","")):1;setTimeout(()=>{$("iframe").css("pointer-events","auto");$(".dashboarddashletcontainer").removeClass("dashboardragborder");var board=get_dashlet_dashboard_id();var dashletid=dashboardDashletContainer.id;var dashlet=dashletid.substr(17);var height=$(dashboardDashletContainer).height();var width=$(dashboardDashletContainer).width();var zindex=$(dashboardDashletContainer).css("z-index");var dashletInterior=$(dashboardDashletContainer).children(".dashboarddashlet");var fc=$(dashletInterior[0]);var pr=parseInt($(dashletInterior).css("padding-right"));var pl=parseInt($(dashletInterior).css("padding-left"));var mr=parseInt($(dashboardDashletContainer).css("margin-right"))+
parseInt($(dashletInterior).css("margin-right"));var ml=parseInt($(dashboardDashletContainer).css("margin-left"))+
parseInt($(dashletInterior).css("margin-left"));var pt=parseInt($(dashletInterior).css("padding-top"));var pb=parseInt($(dashletInterior).css("padding-bottom"));var mt=parseInt($(dashboardDashletContainer).css("margin-top"))+
parseInt($(dashletInterior).css("margin-top"));var mb=parseInt($(dashboardDashletContainer).css("margin-bottom"))+
parseInt($(dashletInterior).css("margin-bottom"));if(isNaN(ml))ml=0;if(isNaN(mr))mr=0;if(isNaN(mt))mt=0;if(isNaN(mb))mb=0;let isStaticDashlet=staticDashlets.some(cls=>$(dashboardDashletContainer).find("."+cls).length>0);if(isStaticDashlet){let snapTolerance=5;scale=getDashletInteriorScaling(dashboardDashletContainer);$(fc).css("transform","matrix("+scale+",0,0,"+scale+",0,0)");if(triggerSnap&&Math.max(Math.abs($(dashboardDashletContainer).width()-$(fc).width()-widthOffset),Math.abs($(dashboardDashletContainer).height()-$(fc).height()-heightOffset))>0){[height,width]=snapDashletContainerToDashletInterior(dashboardDashletContainer);}
let resizeContainerAfterSnapClasses=['.hostgroup_status_grid_dashlet'];let resizeContainerAfterSnap=resizeContainerAfterSnapClasses.some(cls=>$(dashboardDashletContainer).find(cls).length>0);if(resizeContainerAfterSnap){let dashlet=$(dashboardDashletContainer).find(".dashboarddashlet");const dashletScale=parseFloat(dashlet.css("transform").split(",")[0].replace("matrix(",""))||1;let dashletWidth=dashlet.width()*dashletScale+widthOffset;let dashletHeight=dashlet.height()*dashletScale+heightOffset;if(dashletWidth>$(dashboardDashletContainer).width()){$(dashboardDashletContainer).css('width',dashletWidth+'px');width=dashletWidth;}
if(dashletHeight>$(dashboardDashletContainer).height()){$(dashboardDashletContainer).css('height',dashletHeight+'px');height=dashletHeight;}}
var optsarr={board:board,dashlet:dashlet,props:{scale:scale,height:height,width:width,zindex:zindex,type:"resize",new:false,},};redoMementos.push(optsarr);for(let j=0;j<i-1;j++){Mementos.pop();}
i=0;delete optsarr.props.type;var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);toggleDashletTitle(dashboardDashletContainer);toggleDashletControlsDropdown(dashboardDashletContainer);}else{var neww=(width-pr-pl-mr-ml)+addWidth;var newh=(height-pt-pb-mt-mb)+addHeight;let oldButtonScale=['bbmap_map_inboard','minemap_map_inboard'];let scale=$(fc).css("transform").split(",")[0].replace("matrix(","")||1;let hasOldButtonScale=oldButtonScale.some(cls=>$(fc).hasClass(cls));if(neww>0){$(fc).css("width",hasOldButtonScale?neww/scale:neww);}
if(newh>0){$(fc).css("height",hasOldButtonScale?newh/scale:newh);}
var lastChild=$(dashletInterior).children().not("script").last();if(lastChild){$(lastChild).css("width",neww);var newLastChildHeight=newh-parseInt(lastChild.offsetTop);$(lastChild).css("height",newLastChildHeight);}
var optsarr={board:board,dashlet:dashlet,props:{height:height,width:width,zindex:zindex,type:"resize",new:false,},};redoMementos.push(optsarr);for(let j=0;j<i-1;j++){Mementos.pop();}
i=0;delete optsarr.props.type;var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);}},timeout);}
$("body").on("click","#undoButton",function(e){e.preventDefault();undo();});$("body").on("click","#redoButton",function(e){e.preventDefault();redo();});$("body").keydown(function(e){if(e.which===90&&(e.ctrlKey||e.metaKey)&&!e.shiftKey){e.preventDefault();if(document.activeElement.tagName!="IFRAME"){var iframe=document.getElementById("maincontentframe");if(iframe){iframe.focus();}}
undo();}else if((e.which===89&&e.ctrlKey)||(e.which===90&&(e.ctrlKey||e.metaKey)&&e.shiftKey)){e.preventDefault();if(document.activeElement.tagName!="IFRAME"){var iframe=document.getElementById("maincontentframe");if(iframe){iframe.focus();}}
redo();}});let i=0;$(".dashboarddashletcontainer").each(function(){let isStaticDashlet=staticDashlets.some(cls=>$(this).find("."+cls).length>0);scale=$(this).children(".dashboarddashlet").css("transform").split(",")[0].replace("matrix(","")||1;var c=$(this).children(".dashboarddashlet");var fc=$(c[0]);$(this).resizable({grid:gridSize,handles:isStaticDashlet?"se":"e, s, se",start:function(event,ui){$("iframe").css("pointer-events","none");Object.assign(this.style,{animation:"dashlet-pulse 2s ease-in-out infinite",animationDelay:"500ms",boxShadow:"oklch(0.6474 0.1771 261.54 / 30%) 0 0 5rem 0",});},resize:function(event,ui){$(".dashboarddashletcontainer").not(this).addClass("dashboardragborder");const padding=80;var requiredWidth=ui.position.left+ui.size.width+padding;var requiredHeight=ui.position.top+ui.size.height+padding;if(requiredWidth>$(window).width()&&requiredHeight>$(window).height()){$("body").width(requiredWidth);$("body").height(requiredHeight);window.scrollTo({left:requiredWidth-window.innerWidth+padding,top:requiredHeight-window.innerHeight+padding,behavior:"smooth"});}else if(requiredWidth>$(window).width()){$("body").width(requiredWidth);window.scrollTo({left:requiredWidth-window.innerWidth+padding,behavior:"smooth"});}else if(requiredHeight>$(window).height()){$("body").height(requiredHeight);window.scrollTo({top:requiredHeight-window.innerHeight+padding,behavior:"smooth"});}
var board=get_dashlet_dashboard_id();var dashletid=this.id;var dashlet=dashletid.substr(17);var height=ui.size.height;var width=ui.size.width;var zindex=$(this).css("z-index");if(isStaticDashlet){scale=getDashletInteriorScaling(this);$(fc).css("transform","matrix("+scale+",0,0,"+scale+",0,0)");var optsarr={board:board,dashlet:dashlet,props:{scale:scale,height:height,width:width,zindex:zindex,type:"resize",},};Mementos.push(optsarr);i++;}else{let oldButtonScale=['bbmap_map_inboard','minemap_map_inboard'];scale=$(fc).css("transform").split(",")[0].replace("matrix(","")||1;let hasOldButtonScale=oldButtonScale.some(cls=>$(fc).hasClass(cls));if(width>0){$(fc).css("width",hasOldButtonScale?width/scale:width);}
if(height>0){$(fc).css("height",hasOldButtonScale?height/scale:height);}
var lastChild=$(c).children().not("script").last();if(lastChild){$(lastChild).css("width",width);var newLastChildHeight=height-parseInt(lastChild.offsetTop);$(lastChild).css("height",newLastChildHeight);}
var optsarr={board:board,dashlet:dashlet,props:{height:height,width:width,zindex:zindex,type:"resize",},};Mementos.push(optsarr);i++;}
toggleDashletTitle(this);toggleDashletControlsDropdown(this);},stop:function(event,ui){triggerResizeOnDashboardDashlet(this,0);$("iframe").css("pointer-events","auto");Object.assign(this.style,{animation:"none",boxShadow:"none",});}});var sizeinfo=$(this).find(".size-info");const minHeightWidth=50;var minHeight=Math.max($(sizeinfo).data("min-height")||minHeightWidth,minHeightWidth);var minWidth=Math.max($(sizeinfo).data("min-width")||minHeightWidth,minHeightWidth);$(this).resizable("option","minHeight",minHeight);$(this).resizable("option","minWidth",minWidth);if($(sizeinfo).data("max-height")){$(this).resizable("option","maxHeight",$(sizeinfo).data("max-height"));}
if($(sizeinfo).data("max-width")){$(this).resizable("option","maxWidth",$(sizeinfo).data("max-width"));}
var gridSize=20;$(this).draggable({cursor:"move",iframeFix:true,snap:".dashboarddashletcontainer",snapMode:"outer",snapTolerance:30,grid:[gridSize,gridSize],containment:[0,0,100000,100000],cancel:'.hypermap_dashlet, .bbmap_map_inboard',start:function(event,ui){$(".dashboarddashletcontainer").not(this).addClass("dashboardragborder");var x=1;var board=get_dashlet_dashboard_id();var dashletid=this.id;var dashlet=dashletid.substr(17);var t=$(ui.helper);var topa=t.css("top");var lefta=t.css("left");var top=topa.replace("px","");var left=lefta.replace("px","");var zindex=$(this).css("zIndex");Object.assign(this.style,{animation:"dashlet-pulse 2s ease-in-out infinite",animationDelay:"500ms",boxShadow:"oklch(0.6474 0.1771 261.54 / 30%) 0 0 5rem 0",});var optsarrtyped={board:board,dashlet:dashlet,props:{type:"drag",top:top,left:left,zindex:zindex,},};Mementos.push(optsarrtyped);redoMementos.pop();updateDashletZIndex($(this));},stop:function(event,ui){$(".dashboarddashletcontainer").removeClass("dashboardragborder");var board=get_dashlet_dashboard_id();var dashletid=this.id;var dashlet=dashletid.substr(17);var t=$(ui.helper);var topa=t.css("top");var lefta=t.css("left");var top=topa.replace("px","");var left=lefta.replace("px","");var zindex=$(this).css("zIndex");Object.assign(this.style,{animation:'unset',});setTimeout(()=>{this.style.boxShadow='none';},10);var optsarr={board:board,dashlet:dashlet,props:{top:top,left:left,zindex:zindex,},};var opts=JSON.stringify(optsarr);var result=get_ajax_data("setdashletproperty",opts);var y=1;},});});$(".dashlet-pinned").each(function(){var p=this.parentNode.parentNode;var gp=p.parentNode;$(gp).draggable("disable");$(gp).resizable("disable");});function dashifyEffect(dashlet){var availabledashlet_well=dashlet.closest(".availabledashlet.well");if(!availabledashlet_well){availabledashlet_well=dashlet.closest(".dashlettable");}else{availabledashlet_well.style.filter=`brightness(115%)`;}
document.body.style.cursor="pointer";$(availabledashlet_well).addClass("dashlettablehover");}
function removeDashifyEffect(dashlet){var availabledashlet_well=dashlet.closest(".availabledashlet.well");if(!availabledashlet_well){availabledashlet_well=dashlet.closest(".dashlettable");}else{availabledashlet_well.style.filter=`brightness(100%)`;}
document.body.style.cursor="default";$(availabledashlet_well).removeClass("dashlettablehover");}
$("body").on("mouseenter","div.dashifybutton",function(){dashifyEffect(this);});$("body").on("mouseleave","div.dashifybutton",function(){removeDashifyEffect(this);});$("body").on("mouseenter","div.dashlettableinnercontent",function(){if(this.closest(".availabledashlet.well")){dashifyEffect(this);}});$("body").on("mouseleave","div.dashlettableinnercontent",function(){removeDashifyEffect(this);});$("body").on("click",".dashifybutton a",function(){addToDashboard(this.parentNode);});$("body").on("click",".dashlettableinnercontent",function(){var gp=this.parentNode.parentNode;if($(gp).hasClass("availabledashlet well")||($(gp).hasClass("thedashlet"))){addToDashboard(this);}});}
function addToDashboard(dashlettable){let defaultDashboardID=localStorage.getItem("defaultDashboardID");close_child_popup();$("#child_popup_layer").each(function(){$(this).stop(true,true);jQuery.timer.remove(this,"child_popuptimer");jQuery.timer.remove(this,"child_popuptimer2");});whiteout();show_throbber();var thegp=dashlettable.parentNode;var thecontent=$(thegp).find("div.dashlettablecontentargs");var params=thecontent[0].innerHTML;var d=get_ajax_data("getadddashletdata",params);var dashlet=JSON.parse(d);get_ajax_data_innerHTML("getdashboardselectmenuhtml","",true,"#addToDashboardBoardSelect");var theurl="";var content="<div id='popup_header' style='margin-bottom: 5px;'><b>"+
_("Add to Dashboard")+"</b></div><div id='popup_data'><p>"+
_("Add this powerful little dashlet to one of your dashboards for visual goodness.")+"</p></div><form id='addtodashboard_form' method='get' action='"+
ajax_helper_url+"'><input type='hidden' name='cmd' value='addtodashboard'><input type='hidden' name='params' value='"+
params+"'><input type='hidden' name='name' value='"+
dashlet.name+"'><div class='popup-form-box'><label for='addToDashboardTitleBox'>"+
_("Dashlet Title")+"</label><input type='text' size='30' name='title' id='addtoDashboardTitleBox' value='"+
dashlet.title+"' class='form-control'></div><div class='popup-form-box'><label for='addToDashboardBoardSelect'>"+
_("Select a Dashboard to Add To")+"</label><select name='board' id='addToDashboardBoardSelect' class='form-control'></select></div>"+
dashlet.confightml+"<div id='addToDashboardFormButtons'><input type='submit' class='btn btn-sm btn-primary' name='submitButton' value='"+
_("Add It")+"' id='submitAddToDashboardButton'></div></form>"+"<script>"+"var targetSelect = document.getElementById('addToDashboardBoardSelect');"+"if (targetSelect) {"+"var observer = new MutationObserver(function(mutations) {"+"mutations.forEach(function(mutation) {"+"mutation.addedNodes.forEach(function(node) {"+"if (node.nodeName === 'OPTION' && node.value === '"+defaultDashboardID+"') {"+"targetSelect.value = '"+defaultDashboardID+"';"+"observer.disconnect();"+"}"+"});"+"});"+"});"+"observer.observe(targetSelect, {childList: true});"+"}"+"<\/script>";hide_throbber();set_child_popup_content(content);display_child_popup();setTimeout(function(){const popupElement=document.getElementById('child_popup_layer');if(popupElement){const popupRect=popupElement.getBoundingClientRect();window.scrollTo({top:popupRect.top+window.scrollY-100,behavior:"smooth"});}},100);$("#addtodashboard_form").submit(function(){hide_throbber();var params={};$(this).find(":input, :password, :checkbox, :radio, :submit, :reset").each(function(){if(!$(this).is(":checked")&&($(this).is(":checkbox")||$(this).is(":radio"))){return;}
params[this.name||this.id||this.parentNode.name||this.parentNode.id]=$(this).val();});params["nsp"]=nsp_str;$.ajax({type:"POST",url:this.getAttribute("action"),data:params,beforeSend:function(XMLHttpRequest){$("#child_popup_container").each(function(){this.origHTML=this.innerHTML;this.innerHTML="<div id='child_popup_header' style='margin-bottom: 5px;'><b>"+
_("Please Wait")+"</b></div><div id='child_popup_data'><p>"+
_("Processing")+"...</p><div id='throbber' class='sk-spinner sk-spinner-center sk-spinner-three-bounce'><div class='sk-bounce1'></div><div class='sk-bounce2'></div><div class='sk-bounce3'></div></div></div>";});},success:function(msg){$("#child_popup_container").each(function(){this.innerHTML="<div id='child_popup_header' style='margin-bottom: 5px;'><b>"+
_("Dashlet Added")+"</b></div><div id='child_popup_data'><p>"+
_("The dashlet has been added and will now show up on your dashboard.")+"</p></div>";fade_child_popup("green");clear_whiteout();});if(window.parent&&window.parent!==window){window.parent.postMessage({type:'dashletAdded'},'*');}},error:function(msg){$("#child_popup_container").each(function(){this.innerHTML="<div id='child_popup_header' style='margin-bottom: 5px;'><b>"+
_("Error")+"</b></div><div id='child_popup_data'><p>"+
_("An error occurred processing your request.")+"</p></div>";clear_whiteout();});},});return false;});}
function show_dashlet_selection(option){var hostList=$("#host_select");var hostgroupList=$("#hostgroup_select");var servicegroupList=$("#servicegroup_select");switch(option){case"all":hostList.hide();hostgroupList.hide();servicegroupList.hide();break;case"host":hostList.show();hostgroupList.hide();servicegroupList.hide();break;case"hostgroup":hostList.hide();hostgroupList.show();servicegroupList.hide();break;case"servicegroup":hostList.hide();hostgroupList.hide();servicegroupList.show();break;}}