Match table - select and textarea

This commit is contained in:
Balakrishnan Balasubramanian 2023-07-03 17:52:28 -04:00
parent 117c93deaf
commit e4752fd039

View File

@ -2,6 +2,7 @@
<html> <html>
<head> <head>
<title>Mail4one Web config</title> <title>Mail4one Web config</title>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<script type="application/json" id="m41config"> <script type="application/json" id="m41config">
{ {
"matches": [ "matches": [
@ -63,43 +64,41 @@
} }
</script> </script>
<script type="application/javascript"> <script type="application/javascript">
var matches_table
var match_row_template
function main() { function main() {
console.log("hello world !!!")
var config = JSON.parse(document.getElementById('m41config').text);
matches_table = document.getElementById("web-cfg-matches") matches_table = document.getElementById("web-cfg-matches")
console.log(matches_table) match_row_template = document.getElementById("web-cfg-matches-row")
const config = JSON.parse(document.getElementById('m41config').text);
matches_table = document.getElementById("web-cfg-matches")
for (match of config["matches"]) { for (match of config["matches"]) {
vals = [] let vals = []
matchType = "" let matchType = ""
if ("addr_rexs" in match) { const {
vals = match["addr_rexs"] "name": match_name,
matchType = "addr_rexs" "addrs" : addrs,
"addr_rexs" : addr_rexs,
} = match
}else if ("addrs" in match) { if (addrs != undefined) {
vals = match["addrs"] vals = addrs
matchType = "addrs" matchType = "addrs"
} else {
vals = addr_rexs
matchType = "addr_rexs"
} }
row = matches_table.insertRow(-1)
name_cell = row.insertCell(-1) addMatchRow()
name_cell.innerText = match["name"] const rows = matches_table.tBodies[0].rows
type_cell = row.insertCell(-1) const lrow = rows.item(rows.length -1 )
type_cell.innerText = matchType const [ nameCell, typeCell, valCell ] = lrow.cells
value_cell = row.insertCell(-1) nameCell.innerText = match_name
value_cell.contentEditable = true typeCell.firstElementChild.value = matchType
for (val of vals) { valCell.firstElementChild.value = vals.join("\n")
const node = document.createElement("p");
const textnode = document.createTextNode(val);
node.appendChild(textnode);
value_cell.appendChild(node);
}
vt = value_cell.innerText
console.log(vt.split("\n"))
} }
} }
function addMatchRow() { function addMatchRow() {
matches_table = document.getElementById("web-cfg-matches") row_copy = match_row_template.content.cloneNode(true)
row_tmpl = document.getElementById("web-cfg-matches-row")
row_copy = row_tmpl.content.cloneNode(true)
tb = matches_table.tBodies[0] tb = matches_table.tBodies[0]
tb.appendChild(row_copy) tb.appendChild(row_copy)
} }
@ -108,9 +107,16 @@
<body onload="main()"> <body onload="main()">
<template id="web-cfg-matches-row"> <template id="web-cfg-matches-row">
<tr> <tr>
<td>Name</td> <td contentEditable="true" >Name</td>
<td>Type</td> <td>
<td>Values</td> <select>
<option value="addrs">List of addresses</option>
<option value="addr_rexs">List of regexes for addresses</option>
</select>
</td>
<td>
<textarea></textarea>
</td>
</tr> </tr>
</template> </template>
<h1>Mail4one Web config</h1> <h1>Mail4one Web config</h1>