-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
133 lines (117 loc) · 2.59 KB
/
index.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
129
130
131
132
133
<!DOCTYPE html>
<html>
<head>
<script>
var components = {};
function init(root) {
var initCmd = {
type: 0
};
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
var cmds = resp["cmds"];
for(var cmd of cmds) {
exeCmd(cmd);
}
}
};
xhttp.open("POST", "r", true);
xhttp.send(JSON.stringify(initCmd));
}
function sendCmd(cmd){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
var cmds = resp["cmds"];
for(var cmd of cmds) {
exeCmd(cmd);
}
}
};
xhttp.open("POST", "r", true);
xhttp.send(JSON.stringify(cmd));
}
function exeCmd(cmd) {
switch(cmd["cmdType"]){
case 0: // CREATE
if(cmd["type"] == 1) {
createButton(cmd["id"], cmd["subCmds"], cmd["custom"]);
}
break;
case 1: // UPDATE
if(cmd["type"] == 1){
if(cmd.propId == 0){
updateButton(cmd["id"], cmd["subCmds"]);
} else {
var btn = components[cmd["id"]];
if(btn == undefined){
return;
}
updateButtonProperty(btn, cmd);
}
}
break;
case 3: // RELATION
relateComponent(cmd["id"], cmd["custom"]);
break;
}
}
function createButton(id, subCmds, custom){
//console.log(custom);
//var customValues = JSON.parse(custom);
//console.log(customValues);
var btn = document.createElement("BUTTON");
btn["id"] = id;
// btn.innerHTML = customValues["caption"];
btn.onclick = function(){
var cmd = {};
cmd["type"] = 1;
cmd["cmds"] = [];
cmd["cmds"][0] = {};
cmd["cmds"][0]["id"] = id;
cmd["cmds"][0]["cmdType"] = 0;
sendCmd(cmd);
};
updateButtonProperties(btn, subCmds);
components[id] = btn;
}
function updateButton(id, subCmds){
var btn = components[id];
if(btn == undefined){
return;
}
updateButtonProperties(btn, subCmds);
}
function updateButtonProperties(btn, subCmds){
for(var subCmd of subCmds) {
updateButtonProperty(btn, subCmd);
}
}
function updateButtonProperty(btn, cmd){
switch(cmd.propId){
case 1:
btn.innerHTML = cmd.custom;
break;
}
}
function relateComponent(id, custom){
console.log(custom);
var customValues = JSON.parse(custom);
console.log(customValues);
var srcComp = components[id];
var targetCompId = customValues["target"];
if(targetCompId == 0){
document.getElementById("root").appendChild(srcComp);
} else {
var trgComp = components[targetCompId];
trgComp.appendChild(srcComp);
}
}
</script>
</head>
<body id="root" onload="init(this);">
</body>
</html>