"use strict"; /* * Handle the info-box for switches (e.g.: what's shown when a switch is * clicked). * * Interfaces: show(switch), hide(), click(switch). */ var nmsInfoBox = nmsInfoBox || { stats: {}, _showing:"" // Which switch we are displaying (if any). } /* * Show the infobox for a switch. * * Just a wrapper for _show, but adds a handler for comments. Could easily * add a handler for other events too. E.g.: switches. */ nmsInfoBox.show = function(x) { nmsData.addHandler("comments","switchshower",nmsInfoBox._show,x); nmsInfoBox._show(x); } /* * Hide switch info-box and remove handler. */ nmsInfoBox.hide = function() { nmsInfoBox._hide(); nmsData.unregisterHandler("comments","switchshower"); } /* * Click a switch: If it's currently showing: hide it, otherwise display * it. */ nmsInfoBox.click = function(sw) { if (nmsInfoBox._showing == sw) nmsInfoBox.hide(); else nmsInfoBox.show(sw); } nmsInfoBox._hide = function() { var swtop = document.getElementById("info-switch-parent"); var switchele = document.getElementById("info-switch-table"); var comments = document.getElementById("info-switch-comments-table"); var commentbox; if (switchele != undefined) switchele.parentNode.removeChild(switchele); if (comments != undefined) comments.parentNode.removeChild(comments); commentbox = document.getElementById("commentbox"); if (commentbox != undefined) commentbox.parentNode.removeChild(commentbox); swtop.style.display = 'none'; nmsInfoBox._showing = ""; } /* * General-purpose table-maker? * * Takes an array of arrays as input, and an optional caption. * * E.g.: _makeTable([["name","Kjell"],["Age","five"]], "Age list"); */ nmsInfoBox._makeTable = function(content, caption) { var table = document.createElement("table"); var tr; var td1; var td2; table.className = "table"; table.classList.add("table"); table.classList.add("table-condensed"); if (caption != undefined) { var cap = document.createElement("caption"); cap.textContent = caption; table.appendChild(cap); } for (var v in content) { tr = table.insertRow(-1); td1 = tr.insertCell(0); td2 = tr.insertCell(1); td1.innerHTML = content[v][0]; td2.innerHTML = content[v][1]; } return table; } /* * Create and return a table for comments. * * Input is an array of comments. */ nmsInfoBox._makeCommentTable = function(content) { var table = document.createElement("table"); table.className = "table"; table.classList.add("table"); table.classList.add("table-condensed"); var cap = document.createElement("caption"); cap.textContent = "Comments" table.appendChild(cap); for (var commentid in content) { var tr; var td1; var td2; var comment = content[commentid]; var col; if (comment["state"] == "active") col = "danger"; else if (comment["state"] == "inactive") col = false; else col = "info"; tr = table.insertRow(-1); tr.id = "commentRow" + comment["id"]; tr.className = col; td1 = tr.insertCell(0); td1.style.whiteSpace = "nowrap"; td1.style.width = "8em"; td2 = tr.insertCell(1); var txt = '