-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglue.js
85 lines (70 loc) · 2.24 KB
/
glue.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
80
81
82
83
84
85
$( document ).ready(glue);
function glue() {
const cjs = $('#configjson');
const ips = $('#imagepullsecret');
function credsChanged() {
const creds = {};
const auths = {}
creds.auths = auths;
const rows = $('#credsrowsholder').children();
rows.each(function(ridx, row) {
const cols = row.children;
const registry = $(cols[0].children[0]).val();
const username = $(cols[1].children[0]).val();
const password = $(cols[2].children[0]).val();
const email = $(cols[3].children[0]).val();
auths[registry] = {
Username: username,
Password: password,
Email: email
};
});
cjs.val(credsToConfigJson(creds));
ips.val(configJsonToImagePullSecret(cjs.val()));
}
$("#addcredrow").click(function() {
addChangeDetectedRow("", "", "", "", credsChanged);
credsChanged();
});
cjs.keyup(function() {
ips.val(configJsonToImagePullSecret(cjs.val()));
createCredRows(cjs.val(), credsChanged)
})
ips.keyup(function() {
cjs.val(imagePullSecretToConfigJson(ips.val()));
createCredRows(cjs.val(), credsChanged)
})
}
function createCredRows(configJson, callback) {
const creds = configJsonToCreds(configJson);
const crh = $('#credsrowsholder');
crh.empty();
for (let registry in creds) {
addChangeDetectedRow(registry, creds[registry].Username, creds[registry].Password, creds[registry].Email, callback);
}
}
function addChangeDetectedRow(registry, username, password, email, callback) {
const crh = $('#credsrowsholder');
const row = $('<tr>');
row.append(wrapInTd(addChangeDetectedInput(registry, callback)));
row.append(wrapInTd(addChangeDetectedInput(username, callback)));
row.append(wrapInTd(addChangeDetectedInput(password, callback)));
row.append(wrapInTd(addChangeDetectedInput(email, callback)));
const removeBtn = $('<input type="button" value="X">');
row.append(wrapInTd(removeBtn));
removeBtn.click(function() {
row.remove();
callback();
})
crh.append(row);
}
function wrapInTd(elem) {
const td = $("<td/>");
td.append(elem);
return td;
}
function addChangeDetectedInput(value, callback) {
const input = $('<input type="text" value="' + value + '"/>');
input.keyup(callback);
return input
}