From 4ea3a099b05fa910498bfbf1b2d7387118355472 Mon Sep 17 00:00:00 2001 From: "Ole Mathias Aa. Heggem" Date: Sun, 13 Apr 2025 07:18:45 +0200 Subject: Upgrade bootstrap and rewrite API (#230) --- web/js/nms-info-box.js | 1851 ++++++++++++++++++++++++------------------------ 1 file changed, 929 insertions(+), 922 deletions(-) (limited to 'web/js/nms-info-box.js') diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index 1a15e6c..f79fc7a 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -29,220 +29,224 @@ * Basic configuration */ var nmsInfoBox = nmsInfoBox || { - stats: {}, - _container: false, //Container window - _windowHandler: false, //Window handler - _sw: false, //Name of last switch opened, used for toggle-click - _windowTypes: [ - { - 'id': 'switchInfo', - 'title': 'Switch info', - 'views': { - 'initial': { - 'name': 'Summary', - 'panels': ['switchLatency','switchSummary','switchComments'], - 'public': true - }, - 'ports': { - 'name': 'Ports', - 'panels': ['switchPorts'] - }, - 'misc': { - 'name': 'SNMP', - 'panels': ['switchSNMP:misc'] - }, - 'links': { - 'name': 'Links', - 'panels': ['switchLinks'] - }, - 'edit': { - 'name': 'Edit settings', - 'panels': ['switchEdit'] - } - } - }, - { - 'id': 'networkInfo', - 'title': 'Network info', - 'views': { - 'initial': { - 'name': 'Summary', - 'panels': ['networkSummary'] - }, - 'edit': { - 'name': 'Edit settings', - 'panels': ['networkEdit'] - } - } - }, - { - 'id': 'addSwitch', - 'title': 'Add new switch(es)', - 'views': { - 'initial': { - 'name': 'Add switch', - 'panels': ['switchAdd'] - } - } - }, - { - 'id': 'addNetwork', - 'title': 'Add new network(s)', - 'views': { - 'initial': { - 'name': 'Add network', - 'panels': ['networkAdd'] - } - } - }, - { - 'id': 'searchHelp', - 'title': 'Search help', - 'views': { - 'initial': { - 'name': 'Search help', - 'panels': ['searchHelp'] - } - } - }, - { - 'id': 'searchResults', - 'title': 'Search Results', - 'views': { - 'initial': { - 'name': 'Search Results', - 'panels': ['searchResults'] - } - } - }, - { - 'id': 'listNetwork', - 'title': 'Networks', - 'views': { - 'initial': { - 'name': 'List all networks', - 'panels': ['listNetworks'] - } - } - }, -], - _panelTypes: {} //Populate by using the nmsInfoBox.addPanelType method + stats: {}, + _container: false, //Container window + _windowHandler: false, //Window handler + _sw: false, //Name of last switch opened, used for toggle-click + _windowTypes: [ + { + id: "switchInfo", + title: "Switch info", + views: { + initial: { + name: "Summary", + panels: ["switchLatency", "switchSummary", "switchLinks", "switchComments"], + public: true, + }, + ports: { + name: "Ports", + panels: ["switchPorts"], + }, + misc: { + name: "SNMP", + panels: ["switchSNMP:misc"], + }, + edit: { + name: "Settings", + panels: ["switchEdit"], + }, + }, + }, + { + id: "networkInfo", + title: "Network info", + views: { + initial: { + name: "Summary", + panels: ["networkSummary"], + }, + edit: { + name: "Settings", + panels: ["networkEdit"], + }, + }, + }, + { + id: "addSwitch", + title: "Add new switch(es)", + views: { + initial: { + name: "Add switch", + panels: ["switchAdd"], + }, + }, + }, + { + id: "addNetwork", + title: "Add new network(s)", + views: { + initial: { + name: "Add network", + panels: ["networkAdd"], + }, + }, + }, + { + id: "searchHelp", + title: "Search help", + views: { + initial: { + name: "Search help", + panels: ["searchHelp"], + }, + }, + }, + { + id: "searchResults", + title: "Search Results", + views: { + initial: { + name: "Search Results", + panels: ["searchResults"], + }, + }, + }, + { + id: "listNetwork", + title: "Networks", + views: { + initial: { + name: "List all networks", + panels: ["listNetworks"], + }, + }, + }, + { + id: "debug", + title: "Debug", + views: { + initial: { + name: "Debug", + panels: ["debugInfo"], + }, + stats: { + name: "Stats", + panels: ["debugStats"], + }, + }, + }, + ], + _panelTypes: {}, //Populate by using the nmsInfoBox.addPanelType method }; /* * Shows a window, and triggers initial load if needed */ -nmsInfoBox.showWindow = function (windowName,argument) { - if(windowName == "switchInfo" && argument != '' && argument == this._sw) { - nmsInfoBox.hide(); - return; - } - - if(!this._container) - this._load(); - if(!windowName) - windowName = 'switchInfo'; - - this._sw = argument; - - this._windowHandler.showWindow(windowName,argument) - - $(this._windowHandler.getTitleObj()).on('mousedown', function(e) { - var cont = $(nmsInfoBox._container); - var dimensions = nmsInfoBox._container.getBoundingClientRect(); - var startLeft = dimensions.left; - var startTop = dimensions.top; - nmsInfoBox.startDrag(e.screenX, e.screenY, startLeft, startTop); - }); - $(this._windowHandler.getTitleObj()).on('mouseup',nmsInfoBox.stopDrag); +nmsInfoBox.showWindow = function (windowName, argument) { + if (windowName == "switchInfo" && argument != "" && argument == this._sw) { + nmsInfoBox.hide(); + return; + } + + if (!this._container) this._load(); + if (!windowName) windowName = "switchInfo"; + + this._sw = argument; + + this._windowHandler.showWindow(windowName, argument); }; /* * Internal function to load and register the initial html objects */ -nmsInfoBox._load = function() { - var infoBox = document.createElement("div"); - infoBox.classList.add("panel", "panel-default"); - var title = document.createElement("div"); - title.id = "info-box-title"; - title.classList.add("panel-heading"); - var nav = document.createElement("div"); - nav.id = "info-box-nav"; - nav.classList.add("panel-body"); - var body = document.createElement("div"); - body.id = "info-box-body"; - body.classList.add("panel-body"); - - infoBox.appendChild(title); - infoBox.appendChild(nav); - infoBox.appendChild(body); - - this._container = document.getElementById("info-box-container"); - this._container.appendChild(infoBox); - - this._windowHandler = new windowHandler(); - this._windowHandler.setContainerObj(document.getElementById("info-box-container")); - this._windowHandler.setTitleObj(document.getElementById("info-box-title")); - this._windowHandler.setBodyObj(document.getElementById("info-box-body")); - this._windowHandler.setNavObj(document.getElementById("info-box-nav")); - this._windowHandler.setPanelTypes(this._panelTypes); - this._windowHandler.setWindowTypes(this._windowTypes); +nmsInfoBox._load = function () { + var modalBox = document.createElement("div"); + modalBox.classList.add("modal", "show"); + modalBox.style = "display: block;"; + // did not work + // modalBox.setAttribute('data-bs-backdrop', "false"); + + var dialogBox = document.createElement("div"); + dialogBox.classList.add( + "modal-dialog", + "modal-lg", + "modal-dialog-scrollable" + ); + + var dialogContentBox = document.createElement("div"); + dialogContentBox.classList.add("modal-content"); + + var dialogHeader = document.createElement("div"); + dialogHeader.classList.add("modal-header"); + + modalBox.appendChild(dialogBox); + + dialogBox.appendChild(dialogContentBox); + + var title = document.createElement("div"); + title.id = "info-box-title"; + title.classList.add("modal-title"); + + var nav = document.createElement("div"); + nav.id = "info-box-nav"; + + var body = document.createElement("div"); + body.id = "info-box-body"; + body.classList.add("modal-body"); + + var closeButton = document.createElement("button"); + // + closeButton.classList.add("btn-close"); + closeButton.onclick = function () { + nmsInfoBox.hide(); + }; + + dialogContentBox.appendChild(dialogHeader); + dialogContentBox.appendChild(body); + dialogHeader.appendChild(title); + dialogHeader.appendChild(nav); + dialogHeader.appendChild(closeButton); + + this._container = document.getElementById("info-box-container"); + this._container.appendChild(modalBox); + + this._windowHandler = new windowHandler(); + this._windowHandler.setContainerObj( + document.getElementById("info-box-container") + ); + this._windowHandler.setTitleObj(document.getElementById("info-box-title")); + this._windowHandler.setBodyObj(document.getElementById("info-box-body")); + this._windowHandler.setNavObj(document.getElementById("info-box-nav")); + this._windowHandler.setPanelTypes(this._panelTypes); + this._windowHandler.setWindowTypes(this._windowTypes); }; /* * Adds a panel type to _panelTypes for usage in windows and views */ nmsInfoBox.addPanelType = function (id, obj) { - this._panelTypes[id] = obj; + this._panelTypes[id] = obj; }; - /* * Hide the active window and tell it to unload */ -nmsInfoBox.hide = function() { - this._sw = false; - if (this._windowHandler != undefined && this._windowHandler.hide != undefined) { - this._windowHandler.hide(); - this._windowHandler.unloadWindow(); - } - nmsInfoBox.resetDrag(); -}; - -/* - * Start window drag - */ -nmsInfoBox.startDrag = function(mouseStartX, mouseStartY, startLeft, startTop) { - document.onmousemove = function(e) { - var mouseOffsetX = e.screenX - mouseStartX; - var mouseOffsetY = e.screenY - mouseStartY; - $(nmsInfoBox._container).css('left', startLeft + mouseOffsetX + 'px'); - $(nmsInfoBox._container).css('top', startTop + mouseOffsetY + 'px'); - }; -}; - -/* - * Reset drag - */ -nmsInfoBox.resetDrag = function() { - nmsInfoBox.stopDrag(); - $(nmsInfoBox._container).css('left',''); - $(nmsInfoBox._container).css('top',''); -}; - -/* - * Stop window drag - */ -nmsInfoBox.stopDrag = function() { - document.onmousemove = null; +nmsInfoBox.hide = function () { + this._sw = false; + if ( + this._windowHandler != undefined && + this._windowHandler.hide != undefined + ) { + this._windowHandler.hide(); + this._windowHandler.unloadWindow(); + } }; /* * Click a switch and display it. */ -nmsInfoBox.click = function(sw) -{ - this.showWindow("switchInfo",sw); +nmsInfoBox.click = function (sw) { + this.showWindow("switchInfo", sw); }; /* @@ -262,159 +266,163 @@ nmsInfoBox.click = function(sw) * */ var windowHandler = function () { - this.containerObj = false; - this.titleObj = false; - this.navObj = false; - this.bodyObj = false; - this._panels = {}; - this._view = ""; - this._viewId = {}; - this._window = {}; - this.windowTypes = false; - this.panelTypes = false; - this.argument = false; - this.show = function () { - this.containerObj.classList.remove("hidden"); - }; - this.hide = function () { - this.containerObj.classList.add("hidden"); - }; - this.setContainerObj = function (containerObj) { - this.containerObj = containerObj; - }; - this.setTitleObj = function (titleObj) { - this.titleObj = titleObj; - }; - this.getTitleObj = function (titleObj) { - return this.titleObj; - }; - this.setNavObj = function (navObj) { - this.navObj = navObj; - }; - this.setBodyObj = function (bodyObj) { - this.bodyObj = bodyObj; - }; - this.setPanelTypes = function (panelTypes) { - this.panelTypes = panelTypes; - }; - this.setWindowTypes = function (windowTypes) { - this.windowTypes = {}; - for(var i in windowTypes) { - this.windowTypes[windowTypes[i].id] = windowTypes[i]; - } - }; - this.setArgument = function (argument) { - if(this.argument != argument) { - this.argument = argument; - this.showView(this._view); - } - }; - this.showPanel = function (panelName) { - var panelArray = panelName.split(":"); - var panelName = panelArray[0]; - var panelMode = panelArray[1]; - if(this.panelTypes[panelName]) { - var id = (Math.random().toString(36)+'00000000000000000').slice(2, 10+2); - var panel = new this.panelTypes[panelName]; - panel.setId(id); - if(!!panelMode) - panel.setMode(panelMode); - panel.load(this.bodyObj,this.argument); - this._panels[id] = panel; - } - }; - this.showTitle = function (title) { - this.titleObj.innerHTML = '

' + title + '

'; - }; - this.showNav = function () { - if(!this._window.views) - this.navObj.innerHTML = ''; - var output = ''; - if(i < 2) { - this.navObj.innerHTML = ''; - } else { - this.navObj.innerHTML = output; - } - }; - this.addWindow = function (windowObj) { - this.windowTypes[windowObj.id] = windowObj; - }; - this.showWindow = function (windowName,argument) { - if(!this.windowTypes[windowName]) - return; - this.unloadWindow(); - this.argument = argument; - this._window = this.windowTypes[windowName]; - this.showTitle(this._window.title + " " + (argument ? argument : "")); - this.showView(); - this.show(); - }; - this.showView = function (viewId) { - if(!viewId || viewId == '') { - if (this._viewId[this._window.id] == undefined) - viewId = "initial"; - else - viewId = this._viewId[this._window.id]; - } else { - this._viewId[this._window.id] = viewId; - } - if(!this._window.views || !this._window.views[viewId]) - return; - this.unloadView(); - for(var panel in this._window.views[viewId].panels) { - this.showPanel(this._window.views[viewId].panels[panel]); - } - this._view = viewId; - this.showNav(); - }; - this.removePanel = function (panelId) { - if(!!panelId) - this.unloadPanel(panelId); - }; - this.unloadView = function () { - this.unloadPanel(); - }; - this.unloadWindow = function() { - this.hide(); - this.unloadPanel(); - }; - this.unloadPanel = function (panelId) { - if(!panelId) { - for(var i in this._panels) { - this._panels[i].unload(); - } - this._panels = {}; - } else { - try { - this._panels[panelId].unload(); - } catch (e) {} - delete this._panels[panelId]; - } - }; - //Method for triggering a function in an active panel - this.doInPanel = function (panelId, action, argument) { - if(!this._panels[panelId]) - return; - if(typeof this._panels[panelId][action] === "function") { - if(!argument) { - this._panels[panelId][action](); - } else { - this._panels[panelId][action](argument); - } - } - }; + this.containerObj = false; + this.titleObj = false; + this.navObj = false; + this.bodyObj = false; + this._panels = {}; + this._view = ""; + this._viewId = {}; + this._window = {}; + this.windowTypes = false; + this.panelTypes = false; + this.argument = false; + this.show = function () { + this.containerObj.classList.remove("d-none"); + }; + this.hide = function () { + this.containerObj.classList.add("d-none"); + }; + this.setContainerObj = function (containerObj) { + this.containerObj = containerObj; + }; + this.setTitleObj = function (titleObj) { + this.titleObj = titleObj; + }; + this.getTitleObj = function (titleObj) { + return this.titleObj; + }; + this.setNavObj = function (navObj) { + this.navObj = navObj; + }; + this.setBodyObj = function (bodyObj) { + this.bodyObj = bodyObj; + }; + this.setPanelTypes = function (panelTypes) { + this.panelTypes = panelTypes; + }; + this.setWindowTypes = function (windowTypes) { + this.windowTypes = {}; + for (var i in windowTypes) { + this.windowTypes[windowTypes[i].id] = windowTypes[i]; + } + }; + this.setArgument = function (argument) { + if (this.argument != argument) { + this.argument = argument; + this.showView(this._view); + } + }; + this.showPanel = function (panelName) { + var panelArray = panelName.split(":"); + var panelName = panelArray[0]; + var panelMode = panelArray[1]; + if (this.panelTypes[panelName]) { + var id = (Math.random().toString(36) + "00000000000000000").slice( + 2, + 10 + 2 + ); + var panel = new this.panelTypes[panelName](); + panel.setId(id); + if (!!panelMode) panel.setMode(panelMode); + panel.load(this.bodyObj, this.argument); + this._panels[id] = panel; + } + }; + this.showTitle = function (title) { + this.titleObj.innerHTML = '

' + title + "

"; + }; + this.showNav = function () { + if (!this._window.views) this.navObj.innerHTML = ""; + var output = '