all repos — honk @ 4dab83309b4fe450d38daf23392287c5f293ffc7

my fork of honk

add more kill controls
Ted Unangst tedu@tedunangst.com
Fri, 26 Apr 2019 09:07:13 -0400
commit

4dab83309b4fe450d38daf23392287c5f293ffc7

parent

6e229e99c7bdc26dd0f7cc6a0f891ae623da5b7d

4 files changed, 65 insertions(+), 10 deletions(-)

jump to
M honk.gohonk.go

@@ -789,11 +789,32 @@

} 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) {
M views/honk.htmlviews/honk.html

@@ -25,10 +25,24 @@ {{ end }}

{{ 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>
M views/honkpage.htmlviews/honkpage.html

@@ -24,11 +24,19 @@ </div>

<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 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 }}
M views/style.cssviews/style.css

@@ -46,7 +46,7 @@ .info div {

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;

@@ -149,6 +149,11 @@ text-decoration: line-through;

} .zonked .noise a { color: #a79; +} +.inlineform { + display: inline; +} +.inlineform select { } img { max-width: 100%