monfront - add select all

This commit adds a select all function to select all rows of a list to
mark them all.
This could be used to send a refresh to all these checks or acknowledge
them or whatever.

Also the referrer handling in checkAction() was moved to the start so
that even with an error the same thing happens.
This commit is contained in:
Gibheer 2019-01-24 15:37:43 +01:00
parent b1746c6626
commit aff501bebc

View File

@ -154,10 +154,15 @@ func checkAction(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "could not parse parameters: %s", err)
return
}
ref, found := r.Header["Referer"]
if found {
w.Header()["Location"] = ref
} else {
w.Header()["Location"] = []string{"/"}
}
checks := r.PostForm["checks"]
action := r.PostForm["action"]
if len(action) == 0 || action[0] == "" || len(checks) == 0 {
w.Header()["Location"] = []string{"/"}
w.WriteHeader(http.StatusSeeOther)
return
}
@ -216,7 +221,6 @@ func checkAction(w http.ResponseWriter, r *http.Request) {
log.Printf("could not adjust checks %#v: %s", checks, err)
return
}
w.Header()["Location"] = []string{"/"}
w.WriteHeader(http.StatusSeeOther)
return
default:
@ -236,12 +240,6 @@ func checkAction(w http.ResponseWriter, r *http.Request) {
log.Printf("could not adjust checks %#v: %s", checks, err)
return
}
ref, found := r.Header["Referer"]
if found {
w.Header()["Location"] = ref
} else {
w.Header()["Location"] = []string{"/"}
}
w.WriteHeader(http.StatusSeeOther)
return
}
@ -639,35 +637,61 @@ var (
</nav>
{{ if .Error }}<div class="error">{{ .Error }}</div>{{ end }}`,
"footer": `<script>
function select_row(event) {
function row_head_click_event(event) {
check = false;
current = event.target;
while (current != null) {
if (current.nodeName == 'TABLE') {
break;
}
if (current.nodeName == 'TR') {
check = !current.children[0].children[0].checked;
current.children[0].children[0].checked = check;
}
current = current.parentNode;
}
lines = current.children[1].children
for (i = 0; i < lines.length; i++) {
select_row(event, lines[i], lines[i].children[0].children[0], check);
}
}
function row_click_event(event) {
if (event.target.nodeName == 'INPUT') {
return;
}
current = event.target;
while (current = current.parentNode) {
if (current,nodeName == 'BODY') {
if (current.nodeName == 'BODY') {
break;
}
if (current.nodeName != 'TR') {
continue;
}
e = current.children[0].children[0];
if (e != event.target) {
e.checked = !e.checked;
}
if (e.checked) {
current.classList.add("selected");
} else {
current.classList.remove("selected");
}
e.focus();
check = !e.checked;
select_row(event, current, e, check);
break;
}
}
function select_row(event, row, input, check) {
if (input != event.target) {
input.checked = check;
}
if (input.checked) {
row.classList.add("selected");
} else {
row.classList.remove("selected");
}
input.focus();
}
els = document.getElementsByTagName('tr');
els = document.querySelectorAll('thead > tr');
for (i = 0; i < els.length; i++) {
els[i].addEventListener('click', {handleEvent: select_row});
els[i].addEventListener('click', {handleEvent: row_head_click_event});
}
els = document.querySelectorAll('tbody > tr');
for (i = 0; i < els.length; i++) {
els[i].addEventListener('click', {handleEvent: row_click_event});
}</script></body></html>`,
"checklist": `{{ template "header" . }}
<form method="post" action="/action">
@ -693,7 +717,7 @@ var (
</nav>
<content>
<table>
<thead><tr><th></th><th>host</th><th>status</th><th>next check</th><th>message</th></tr></thead>
<thead><tr><th><input type="checkbox" title="select all" /></th><th>host</th><th>status</th><th>next check</th><th>message</th></tr></thead>
<tbody>
{{ $current := "" }}
{{ $mapping := .Mappings }}