From f7c46150b4ff4c874004a30ddee1ce2f8f2f04c2 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 31 Jul 2021 19:01:13 +0530 Subject: [PATCH] webapp: moved serializeTableData() method to common js from dhcp js. --- DnsServerCore/www/js/common.js | 38 +++++++++++++++++++++++++++++++++- DnsServerCore/www/js/dhcp.js | 30 --------------------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/DnsServerCore/www/js/common.js b/DnsServerCore/www/js/common.js index f99371d5..79c72032 100644 --- a/DnsServerCore/www/js/common.js +++ b/DnsServerCore/www/js/common.js @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2020 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2021 Shreyas Zare (shreyas@technitium.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -314,3 +314,39 @@ function sortTable(tableId, n) { } } } + +function serializeTableData(table, columns) { + + var data = table.find('input:text'); + var output = ""; + + for (var i = 0; i < data.length; i += columns) { + if (i > 0) + output += "|"; + + for (var j = 0; j < columns; j++) { + if (j > 0) + output += "|"; + + var cell = $(data[i + j]); + var cellValue = cell.val(); + var optional = (cell.attr("data-optional") === "true"); + + if ((cellValue === "") && !optional) { + showAlert("warning", "Missing!", "Please enter a valid value in the text field in focus."); + cell.focus(); + return false; + } + + if (cellValue.includes("|")) { + showAlert("warning", "Invalid Character!", "Please edit the value in the text field in focus to remove '|' character."); + cell.focus(); + return false; + } + + output += htmlDecode(cellValue); + } + } + + return output; +} diff --git a/DnsServerCore/www/js/dhcp.js b/DnsServerCore/www/js/dhcp.js index df603e83..4f013428 100644 --- a/DnsServerCore/www/js/dhcp.js +++ b/DnsServerCore/www/js/dhcp.js @@ -232,36 +232,6 @@ function addDhcpScopeReservedLeaseRow(hostName, hardwareAddress, address, commen $("#tableDhcpScopeReservedLeases").append(tableHtmlRows); } -function serializeTableData(table, columns) { - - var data = table.find('input:text'); - var output = ""; - - for (var i = 0; i < data.length; i += columns) { - if (i > 0) - output += "|"; - - for (var j = 0; j < columns; j++) { - if (j > 0) - output += "|"; - - var cell = $(data[i + j]); - var cellValue = cell.val(); - var optional = (cell.attr("data-optional") === "true"); - - if ((cellValue === "") && !optional) { - showAlert("warning", "Missing!", "Please enter a valid value in the text field in focus."); - cell.focus(); - return false; - } - - output += htmlDecode(cellValue); - } - } - - return output; -} - function clearDhcpScopeForm() { $("#txtDhcpScopeName").attr("data-name", ""); $("#txtDhcpScopeName").val("");