webapp: moved serializeTableData() method to common js from dhcp js.

This commit is contained in:
Shreyas Zare
2021-07-31 19:01:13 +05:30
parent 97d5d1532c
commit f7c46150b4
2 changed files with 37 additions and 31 deletions

View File

@@ -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;
}

View File

@@ -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("");