1
0
forked from x/ContextOS
2018-08-25 12:07:09 +08:00

201 lines
4.7 KiB
HTML

{{define "head"}}
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{option .Meta "page_title"}}</title>
<style>
fieldset {
margin-top:8px;
}
legend {
font-size:16px;
font-weight:bold;
font-family:monospace;
}
th {
cursor:pointer;
background-color:lightgreen;
}
td {
padding-left: 10px;
padding-right: 20px;
}
pre {
border:solid 1px green;
padding:5px;
border-left:solid 5px green;
overflow:scroll;
}
code {
font-size:14px;
}
.command {
font-size:14px;
font-family:monospace;
}
html, body {
height:100%;
width:100%;
margin:0px;
}
</style>
<script src="/library/context.js"></script>
<script>
function update(event, module, details, key) {
if (event) {
window[key+"timer"] = !window[key+"timer"];
}
if (!window[key+"timer"]) {
return
}
console.log("update "+key)
setTimeout(function() {
action(event, module, details, key);
update(null, module, details, key);
}, parseInt({{conf . "refresh_time"}}));
}
function input(event, module, details, key) {
if (event.code == "Enter") {
action(event, module, details, key);
}
}
function action(event, module, details, key) {
var input = document.getElementsByClassName(key+"_input");
for (var i = 0; i < input.length; i++ ){
if (input[i].value != "") {
details.push(input[i].value)
}
}
ctx.POST("", {module:module, details:details}, function(msg) {
if (msg && msg.result) {
var result = document.getElementsByClassName(key+"_result")[0];
result.innerHTML = msg.result;
}
if (!msg || !msg.append || msg.append.length < 1) {
return
}
var append = document.getElementsByClassName(key+"_append")[0];
if (append.rows.length == msg[msg.append[0]].length+1) {
return
}
append.innerHTML = '';
var tr = append.insertRow(0);
for (var i in msg.append) {
var th = tr.appendChild(document.createElement("th"));
th.appendChild(document.createTextNode(msg.append[i]));
}
for (var i = 0; i < msg[msg.append[0]].length; i++) {
var tr = append.insertRow(1);
for (var j in msg.append) {
var td = tr.appendChild(document.createElement("td"));
td.appendChild(document.createTextNode(msg[msg.append[j]][i]));
}
}
var div = append.parent;
})
return false;
}
</script>
</head>
<body>
{{end}}
{{define "code"}}
<pre><code>{{.}}</code></pre>
{{end}}
{{define "notice"}}
<fieldset class="notice"><legend>[notice]</legend>
{{template "code" result .Meta}}
</fieldset>
<style>
.notice {color:red}
</style>
{{end}}
{{define "detail"}}
{{$msg := .}}
{{$key := append . "title"|meta}}
<fieldset><legend><a onclick="return action(event, '{{option .Meta "module"}}', ['{{detail .Meta}}'], '{{$key}}')" href="/">{{option . "title"}}</a></legend>
{{range option . "ninput"|meta|list}}
<input type="text" class="{{$key}}_input" value="" onkeyup="return input(event, '{{option $msg.Meta "module"}}', ['{{detail $msg.Meta}}'], '{{$key}}')"></input>
{{end}}
{{if option . "refresh"}}
<input type="button" class="{{$key}}_button" value="update" onclick="return update(event, '{{option $msg.Meta "module"}}', ['{{detail $msg.Meta}}'], '{{$key}}')"></input>
<input type="button" class="{{$key}}_button" value="cancel" onclick="return update(event, '{{option $msg.Meta "module"}}', ['{{detail $msg.Meta}}'], '{{$key}}')"></input>
{{end}}
<pre><code class="{{$key}}_result"></code></pre>
<div style="max-height:150px;overflow:auto">
<table class="{{$key}}_append"></table>
</div>
</fieldset>
<script>
{{if option . "auto_refresh"}}
update(true, '{{option $msg.Meta "module"}}', ['{{detail $msg.Meta}}'], '{{$key}}');
{{end}}
</script>
{{end}}
{{define "result"}}
<fieldset><legend>{{option . "title"}}</legend>
{{template "code" result .Meta|unscaped}}
</fieldset>
{{end}}
{{define "append_link"}}
<a onclick="return jump('{{.}}')" href="{{.}}">{{.}}</a>
<script>
function jump(to) {
location.href = location.href + "/" +to;
return false
}
</script>
{{end}}
{{define "append"}}
<fieldset><legend>{{option . "title"}}</legend>
<table class="append">
{{$msg := .}}
{{$ncol := append . |len}}
{{$nrow := append . 0|append .|len}}
<tr>{{range append .}}<th><code onclick="sort_table('{{.}}')">{{.}}</code></th>{{end}}</tr>
{{range $row, $val := append . 0|append .}}
<tr>
{{range append $msg}}
{{$value := append $msg . $row}}
<td><code>
{{if eq . "filename"}}
{{template "append_link" $value}}
{{else}}
{{$value}}
{{end}}
</code></td>
{{end}}
</tr>
{{end}}
</table>
</fieldset>
<script>
var sort_field="";
function sort_table(field) {
sort_field = field;
console.log(sort_field);
}
</script>
{{end}}
{{define "main"}}
welcome to context world!
{{end}}
{{define "tail"}}
</body>
{{end}}