add more kill controls

This commit is contained in:
Ted Unangst 2019-04-26 09:07:13 -04:00
parent 5183a83124
commit c9075e46ff
4 changed files with 65 additions and 10 deletions

27
honk.go
View File

@ -789,11 +789,32 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
}
func zonkit(w http.ResponseWriter, r *http.Request) {
xid := r.FormValue("xid")
wherefore := r.FormValue("wherefore")
var what string
switch wherefore {
case "this honk":
what = r.FormValue("honk")
wherefore = "zonk"
case "this honker":
what = r.FormValue("honker")
wherefore = "zonker"
case "this convoy":
what = r.FormValue("convoy")
wherefore = "zonvoy"
}
if what == "" {
return
}
log.Printf("zonking %s", xid)
log.Printf("zonking %s %s", wherefore, what)
userinfo := login.GetUserInfo(r)
stmtZonkIt.Exec(userinfo.UserID, xid)
if wherefore == "zonk" {
stmtZonkIt.Exec(userinfo.UserID, what)
} else {
db := opendatabase()
db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)",
userinfo.UserID, what, wherefore)
}
}
func savehonk(w http.ResponseWriter, r *http.Request) {

View File

@ -25,10 +25,24 @@ convoy: <a href="/t?c={{ .Convoy }}">{{ .Convoy }}</a>
{{ end }}
</div>
{{ end }}
{{ if and .Bonk (not (eq .Honk.What "zonked")) }}
{{ if and .BonkCSRF (not (eq .Honk.What "zonked")) }}
<p>
<div>
<button onclick="bonk(this, '{{ .Honk.XID }}'); return false;"><a href="/bonk">bonk</a></button>
<button onclick="showhonkform('{{ .Honk.XID }}', '{{ .Honk.Username }}'); return false;"><a href="/newhonk">tonk</a></button>
<button onclick="zonkit(this, '{{ .Honk.XID }}'); return false;"><a href="/zonkit">zonk</a></button>
<form class="inlineform" action="/zonkit" method="POST">
<input type="hidden" name="CSRF" value="{{ .BonkCSRF }}">
<input type="hidden" name="honk" value="{{ .Honk.XID }}">
<input type="hidden" name="honker" value="{{ .Honk.Honker }}">
<input type="hidden" name="convoy" value="{{ .Honk.Convoy }}">
<select name="wherefore">
<option>this honk</option>
<option>this honker</option>
<option>this convoy</option>
</select>
<button onclick="zonkit(this); return false;"><a href="/zonkit">zonk</a></button>
</form>
</div>
<p>
{{ end }}
</div>

View File

@ -24,11 +24,19 @@
<div>
{{ $BonkCSRF := .HonkCSRF }}
{{ range .Honks }}
{{ template "honk.html" map "Honk" . "Bonk" $BonkCSRF }}
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
{{ end }}
</div>
{{ if $BonkCSRF }}
<script>
function encode(hash) {
var s = []
for (var key in hash) {
var val = hash[key]
s.push(escape(key) + "=" + escape(val))
}
return s.join("&")
}
function post(url, data) {
var x = new XMLHttpRequest()
x.open("POST", url)
@ -38,12 +46,19 @@ function post(url, data) {
function bonk(el, xid) {
el.innerHTML = "bonked"
el.disabled = true
post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + xid)
post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + escape(xid))
}
function zonkit(el, xid) {
function zonkit(el) {
el.innerHTML = "zonked"
el.disabled = true
post("/zonkit", "CSRF={{ $BonkCSRF }}&xid=" + xid)
var data = { }
for (var i in el.parentElement.elements) {
var e = el.parentElement.elements[i]
if (e.name) {
data[e.name] = e.value
}
}
post("/zonkit", encode(data))
}
</script>
{{ end }}

View File

@ -46,7 +46,7 @@ input {
margin-top 1em;
margin-bottom: 1em;
}
button, form input[type=submit] {
button, form input[type=submit], select {
font-size: 0.8em;
font-family: monospace;
color: #dde;
@ -150,6 +150,11 @@ button a {
.zonked .noise a {
color: #a79;
}
.inlineform {
display: inline;
}
.inlineform select {
}
img {
max-width: 100%
}