-
Notifications
You must be signed in to change notification settings - Fork 38
/
wp-varnish.js
79 lines (67 loc) · 2.08 KB
/
wp-varnish.js
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
// our id for our rows, we can have rows added and removed
// so we need a base
var rowCount = 0;
function createRow(tableID, id, addr, port, secret) {
var row = document.createElement ('tr');
var td1 = document.createElement ('td');
var td2 = document.createElement ('td');
var td3 = document.createElement ('td');
var td4 = document.createElement ('td');
var wpv_addr = document.createElement ('input');
var wpv_port = document.createElement ('input');
var wpv_secret = document.createElement ('input');
var dRow = document.createElement ('input');
wpv_addr.className = "regular-text";
wpv_addr.type = "text";
wpv_addr.id = id;
wpv_addr.name = "wpvarnish_addr[]";
wpv_addr.value = addr || "";
wpv_port.className = "small-text";
wpv_port.type = "text";
wpv_port.id = id;
wpv_port.name = "wpvarnish_port[]";
wpv_port.value = port || "";
wpv_secret.className = "regular-text";
wpv_secret.type = "text";
wpv_secret.id = id;
wpv_secret.name = "wpvarnish_secret[]";
wpv_secret.value = secret || "";
dRow.className = "";
dRow.type = "button";
dRow.name = "deleteRow";
dRow.value = "-";
dRow.id = id;
dRow.onclick = function () { deleteRow(tableID, id); }
td1.appendChild (wpv_addr);
td2.appendChild (wpv_port);
td3.appendChild (wpv_secret);
td4.appendChild (dRow);
row.appendChild (td1);
row.appendChild (td2);
row.appendChild (td3);
row.appendChild (td4);
return row;
}
function addRow(tableID, id, addr, port, secret) {
var tbody = document.getElementById(tableID).getElementsByTagName ('tbody')[0];
rowCount++;
var row = createRow(tableID, id, addr, port, secret);
tbody.appendChild (row);
}
function deleteRow(tableID, rowID) {
try {
var tbody = document.getElementById(tableID).getElementsByTagName ('tbody')[0];
var trs = tbody.getElementsByTagName ('tr');
// the id = 0 we don't want to remove, as it is the header
for (var i = 1; i < trs.length; i++) {
// we use our own id, let's not mix up with table ids
var id = (trs[i].getElementsByTagName ('input')[0]).id;
if (id == rowID) {
tbody.deleteRow (i);
return;
}
}
} catch(e) {
alert(e);
}
}