-
Notifications
You must be signed in to change notification settings - Fork 0
/
paramlist.html
128 lines (105 loc) · 3.43 KB
/
paramlist.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<head>
<style>
table, td, th {
border: 1px solid lightgray;
border-collapse: collapse;
}
td, th {
padding: 4px;
}
</style>
<script>
class Paramlist extends HTMLElement {
constructor()
{
super();
this._values = [];
this.change_list = [];
}
render(names, header)
{
let th = header.split(',');
if (th.length < 4)
{
th = ['Param', 'Value', 'New', 'Action'];
}
let html_str = `
<table>
<tr>
<th>${th[0].trim()}</th>
<th>${th[1].trim()}</th>
<th>${th[2].trim()}</th>
<th>${th[3].trim()}</th>
</tr>`;
for (const n of names.split(','))
{
const name = n.trim();
html_str += `<tr>
<td>${name}</td>
<td>0</td>
<td><input type="number"></td>
<td><button>Set</button></td>
</tr>`;
this.values.push(0);
}
html_str += '</table>';
this.innerHTML = html_str;
this.tbody = this.querySelector('table tbody');
this.add_event_listeners();
}
add_event_listeners()
{
for (let i=1; i<this.tbody.children.length; i++)
{
this.tbody.children[i].children[3].addEventListener('click', () => this.change(i));
}
}
change(i)
{
console.log(`request ${i} = ${this.tbody.children[i].children[2].firstChild.value}`);
this.change_list.push([i-1, this.tbody.children[i].children[2].firstChild.value]);
this.dispatchEvent(new CustomEvent('chgrequest'));
}
set changes(list)
{
this.change_list = list;
}
get changes()
{
const r = this.change_list;
this.change_list = [];
return r;
}
connectedCallback()
{
const names = this.attributes.names.value;
const header = this.attributes.header.value;
this.render(names, header);
}
update_values()
{
for (let i=1; i<this.tbody.children.length; i++)
{
this.tbody.children[i].children[1].textContent = this._values[i-1];
}
}
set values(v)
{
this._values = v;
this.update_values();
}
get values()
{
return this._values;
}
}
window.customElements.define('pwtk-paramlist', Paramlist);
</script>
</head>
<html>
<body>
<h1>Web component testing ground</h1>
<pwtk-paramlist id='pl-id' names='A, B, C, D' header='Name, Value, New, Action' ></pwtk-bitfield>
</body>
</html>