-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusedit.html
161 lines (120 loc) · 4.31 KB
/
statusedit.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<HTML>
<HEAD>
<TITLE>Status Config</TITLE>
<LINK rel='stylesheet' type='text/css' href='style.css'>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<script src="./Sortable.min.js"></script>
<h2>Status Config</h2>
<script type="text/javascript" src="links.js"></script>
<script type="text/javascript" src="recent.json"></script>
<script type="text/javascript" src="./makerow.js"></script>
<div id='title_area' class='block_container'>
<b>Title</b>
</div><br>
<div id='var_area' class='block_container'>
<b>Variables</b>
</div><br>
<div id='tail_area' class='block_container'>
<input type='submit' id='update_button' style="float: right;">
</div>
<script>
//
var sort_opts = {
filter: '.js-remove',
onFilter: function (evt) {
var el = editableList.closest(evt.item);
el && el.parentNode.removeChild(el);
}
};
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'init.json', false);
httpRequest.send();
var init = JSON.parse(httpRequest.responseText).init;
httpRequest.open('GET', 'status.json', false);
httpRequest.send();
var stat = JSON.parse(httpRequest.responseText).stat;
var title_text = JSON.parse(httpRequest.responseText).title;
console.log(stat);
var title_area = document.getElementById("title_area");
title_area.align = 'left';
var title_input = document.createElement('input');
title_input.type = 'text';
title_input.value = title_text;
title_area.appendChild(title_input);
//make table
table = document.createElement('table');
var sortableInputVals = Sortable.create(table, sort_opts);
header = table.createTHead();
header.appendChild( make_row(['Label','Name', 'Value']) );
for (i = 0; i < init.InputVals.length; i++) {
var cur_name = init.InputVals[i].Name;
//var cur_value = init.InputVals[i].Value;
var cur_label = (stat.hasOwnProperty(cur_name)) ? stat[cur_name].Label : '';
var cur_value = (stat.hasOwnProperty(cur_name)) ? JSON.stringify(stat[cur_name].Value) : '';
cur_value = (cur_value.length <= 2) ? '' : cur_value; // text is blank if "" returned above
var new_row = make_row( [
{'type': 'inputText', 'val': cur_label},
{'type': 'inputText', 'val': cur_name},
{'type': 'inputText', 'val': cur_value}
]);
table.appendChild(new_row);
}
for (i = 0; i < init.Evals.length; i++) {
var cur_name = init.Evals[i].Name;
//var cur_value = init.InputVals[i].Value;
var cur_label = (stat.hasOwnProperty(cur_name)) ? stat[cur_name].Label : '';
var cur_value = (stat.hasOwnProperty(cur_name)) ? JSON.stringify(stat[cur_name].Value) : '';
cur_value = (cur_value.length <= 2) ? '' : cur_value; // text is blank if "" returned above
var new_row = make_row( [
{'type': 'inputText', 'val': cur_label},
{'type': 'inputText', 'val': cur_name},
{'type': 'inputText', 'val': cur_value}
]);
table.appendChild(new_row);
}
var_area.appendChild(table);
var button = document.getElementById('update_button');
update_button.value = 'Update!';
update_button.onclick = function(){ update_page(); };
function update_page() {
dat = {};
titleText = title_input.value;
for (var i = 1; i < table.rows.length; i++) {
var r = {};
r.Label = table.rows[i].cells[0].children[0].value;
r.Name = table.rows[i].cells[1].children[0].value;
r.Value = table.rows[i].cells[2].children[0].value;
var val;
if (r.Label !== "") {
if (r.Value.length > 0) {
eval('val ='+ r.Value);
} else {
val = '';
}
dat[r.Name] = {"Label": r.Label, "Value": val};
}
}
//console.log(dat);
//var dataSend = JSON.stringify(dat, null, ' ');
//console.log(dataSend);
xhr = new XMLHttpRequest();
var url = "/statusedit.html";
xhr.open("POST", url);//, true);
xhr.setRequestHeader("Content-type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
//var json = JSON.parse(xhr.responseText);
console.log(xhr.responseText);
alert(xhr.responseText);
}
};
var dataSend = JSON.stringify({"stat": dat, "title": titleText}, null, ' ');
console.log(dataSend);
xhr.send(dataSend);
window.location.href = "statusedit.html";
}
</script>
<a href='status.html'>return to status</a>
</BODY>
</HTML>