From 193e13734de816f4603cdcb96c59aecfd2537da8 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 29 Jun 2019 12:16:42 +0530 Subject: [PATCH] dhcp.js: updated js code with minor enhancements. --- DnsServerCore/www/js/dhcp.js | 55 +++++++++++++++--------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/DnsServerCore/www/js/dhcp.js b/DnsServerCore/www/js/dhcp.js index 2d0d09ff..c4da7c68 100644 --- a/DnsServerCore/www/js/dhcp.js +++ b/DnsServerCore/www/js/dhcp.js @@ -39,22 +39,17 @@ function refreshDhcpLeases() { url: "/api/listDhcpLeases?token=" + token, success: function (responseJSON) { var dhcpLeases = responseJSON.response.leases; - var tableHtmlRows; + var tableHtmlRows = ""; - if (dhcpLeases.length < 1) { - tableHtmlRows = "No Lease Found"; - } - else { - tableHtmlRows = ""; + for (var i = 0; i < dhcpLeases.length; i++) + tableHtmlRows += "" + htmlEncode(dhcpLeases[i].scope) + "" + dhcpLeases[i].hardwareAddress + "" + dhcpLeases[i].address + "" + dhcpLeases[i].type + "" + htmlEncode(dhcpLeases[i].hostName) + "" + dhcpLeases[i].leaseObtained + "" + dhcpLeases[i].leaseExpires + ""; - for (var i = 0; i < dhcpLeases.length; i++) { - tableHtmlRows += "" + htmlEncode(dhcpLeases[i].scope) + "" + dhcpLeases[i].hardwareAddress + "" + dhcpLeases[i].address + "" + dhcpLeases[i].type + "" + htmlEncode(dhcpLeases[i].hostName) + "" + dhcpLeases[i].leaseObtained + "" + dhcpLeases[i].leaseExpires + ""; - } + $("#tableDhcpLeasesBody").html(tableHtmlRows); - tableHtmlRows += "Total Leases: " + dhcpLeases.length + ""; - } - - $("#tableDhcpLeases").html(tableHtmlRows); + if (dhcpLeases.length > 0) + $("#tableDhcpLeasesFooter").html("Total Leases: " + dhcpLeases.length + ""); + else + $("#tableDhcpLeasesFooter").html("No Lease Found"); divDhcpLeasesLoader.hide(); divDhcpLeases.show(); @@ -87,30 +82,26 @@ function refreshDhcpScopes(checkDisplay) { url: "/api/listDhcpScopes?token=" + token, success: function (responseJSON) { var dhcpScopes = responseJSON.response.scopes; - var tableHtmlRows; + var tableHtmlRows = ""; - if (dhcpScopes.length < 1) { - tableHtmlRows = "No Scope Found"; - } - else { - tableHtmlRows = ""; + for (var i = 0; i < dhcpScopes.length; i++) { + tableHtmlRows += "" + htmlEncode(dhcpScopes[i].name) + "" + dhcpScopes[i].startingAddress + " - " + dhcpScopes[i].endingAddress + "
" + dhcpScopes[i].subnetMask + "" + dhcpScopes[i].networkAddress + "
" + dhcpScopes[i].broadcastAddress + "" + (dhcpScopes[i].interfaceAddress == null ? "" : dhcpScopes[i].interfaceAddress) + ""; + tableHtmlRows += ""; - for (var i = 0; i < dhcpScopes.length; i++) { - tableHtmlRows += "" + htmlEncode(dhcpScopes[i].name) + "" + dhcpScopes[i].startingAddress + " - " + dhcpScopes[i].endingAddress + "
" + dhcpScopes[i].subnetMask + "" + dhcpScopes[i].networkAddress + "
" + dhcpScopes[i].broadcastAddress + "" + (dhcpScopes[i].interfaceAddress == null ? "" : dhcpScopes[i].interfaceAddress) + ""; - tableHtmlRows += ""; + if (dhcpScopes[i].enabled) + tableHtmlRows += ""; + else + tableHtmlRows += ""; - if (dhcpScopes[i].enabled) - tableHtmlRows += ""; - else - tableHtmlRows += ""; - - tableHtmlRows += ""; - } - - tableHtmlRows += "Total Scopes: " + dhcpScopes.length + ""; + tableHtmlRows += ""; } - $("#tableDhcpScopes").html(tableHtmlRows); + $("#tableDhcpScopesBody").html(tableHtmlRows); + + if (dhcpScopes.length > 0) + $("#tableDhcpScopesFooter").html("Total Scopes: " + dhcpScopes.length + ""); + else + $("#tableDhcpScopesFooter").html("No Scope Found"); divDhcpViewScopesLoader.hide(); divDhcpViewScopes.show();