eliminate need for js in various places

This commit is contained in:
Ted Unangst 2019-10-13 22:59:02 -04:00
parent ecdaa8d8dd
commit 77617e06fb
5 changed files with 51 additions and 11 deletions

View File

@ -2,6 +2,8 @@ changelog
-- next
+ More JS free fallbacks for some basic functions.
+ Add chpass command.
+ Improved honker management.

View File

@ -92,25 +92,25 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
<p>
{{ if .Honk.Public }}
{{ if .Honk.IsBonked }}
<button onclick="unbonk(this, '{{ .Honk.XID }}');">unbonk</button>
<button onclick="return unbonk(this, '{{ .Honk.XID }}');">unbonk</button>
{{ else }}
<button onclick="bonk(this, '{{ .Honk.XID }}');">bonk</button>
<button onclick="return bonk(this, '{{ .Honk.XID }}');"><a href="/bonk?xid={{ .Honk.XID }}&CSRF={{ $bonkcsrf }}">bonk</a></button>
{{ end }}
{{ else }}
<button disabled>nope</button>
{{ end }}
<button onclick="showhonkform(this, '{{ .Honk.XID }}', '{{ .Honk.Handle }}');">honk back</button>
<button onclick="muteit(this, '{{ .Honk.Convoy }}');">mute</button>
<button onclick="zonkit(this, '{{ .Honk.XID }}');">zonk</button>
<button onclick="return showhonkform(this, '{{ .Honk.XID }}', '{{ .Honk.Handle }}');"><a href="/newhonk?rid={{ .Honk.XID }}">honk back</a></button>
<button onclick="return muteit(this, '{{ .Honk.Convoy }}');">mute</button>
<button onclick="return zonkit(this, '{{ .Honk.XID }}');">zonk</button>
{{ if .Honk.IsAcked }}
<button onclick="flogit(this, 'deack', '{{ .Honk.XID }}');">deack</button>
<button onclick="return flogit(this, 'deack', '{{ .Honk.XID }}');">deack</button>
{{ else }}
<button onclick="flogit(this, 'ack', '{{ .Honk.XID }}');">ack</button>
<button onclick="return flogit(this, 'ack', '{{ .Honk.XID }}');">ack</button>
{{ end }}
{{ if .Honk.IsSaved }}
<button onclick="flogit(this, 'unsave', '{{ .Honk.XID }}');">unsave</button>
<button onclick="return flogit(this, 'unsave', '{{ .Honk.XID }}');">unsave</button>
{{ else }}
<button onclick="flogit(this, 'save', '{{ .Honk.XID }}');">save</button>
<button onclick="return flogit(this, 'save', '{{ .Honk.XID }}');">save</button>
{{ end }}
<button><a href="/edit?xid={{ .Honk.XID }}">edit</a></button>
</div>

View File

@ -1,5 +1,5 @@
<p id="honkformhost">
<button onclick="showhonkform(); return false"><a href="/newhonk">it's honking time</a></button>
<button onclick="return showhonkform();"><a href="/newhonk">it's honking time</a></button>
<form id="honkform" action="/honk" method="POST" enctype="multipart/form-data" {{ if not .IsPreview }}style="display: none"{{ end }}>
<input type="hidden" name="CSRF" value="{{ .HonkCSRF }}">
<input type="hidden" name="updatexid" value = "{{ .UpdateXID }}">

View File

@ -22,7 +22,8 @@ function get(url, whendone) {
function bonk(el, xid) {
el.innerHTML = "bonked"
el.disabled = true
post("/bonk", encode({"CSRF": csrftoken, "xid": xid}))
post("/bonk", encode({"js": "2", "CSRF": csrftoken, "xid": xid}))
return false
}
function unbonk(el, xid) {
el.innerHTML = "unbonked"
@ -238,6 +239,7 @@ function showhonkform(elem, rid, hname) {
honknoise.value = "@" + hname + " "
}
document.getElementById("honknoise").focus()
return false
}
function showelement(id) {
var el = document.getElementById(id)

36
web.go
View File

@ -848,6 +848,15 @@ func submitbonk(w http.ResponseWriter, r *http.Request) {
}
go honkworldwide(user, &bonk)
if r.FormValue("js") != "1" {
templinfo := getInfo(r)
templinfo["ServerMessage"] = "Bonked!"
err = readviews.Execute(w, "msg.html", templinfo)
if err != nil {
log.Print(err)
}
}
}
func sendzonkofsorts(xonk *Honk, user *WhatAbout, what string) {
@ -983,6 +992,31 @@ func edithonkpage(w http.ResponseWriter, r *http.Request) {
}
}
func newhonkpage(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
rid := r.FormValue("rid")
noise := ""
xonk := getxonk(u.UserID, rid)
if xonk != nil {
_, replto := handles(xonk.Honker)
if replto != "" {
noise = "@" + replto + " "
}
}
templinfo := getInfo(r)
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
templinfo["InReplyTo"] = rid
templinfo["Noise"] = noise
templinfo["ServerMessage"] = "compose honk"
templinfo["IsPreview"] = true
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
}
}
func canedithonk(user *WhatAbout, honk *Honk) bool {
if honk == nil || honk.Honker != user.URL || honk.What == "bonk" {
return false
@ -1686,6 +1720,7 @@ func serve() {
"views/funzone.html",
"views/login.html",
"views/xzone.html",
"views/msg.html",
"views/header.html",
"views/onts.html",
"views/honkpage.js",
@ -1743,6 +1778,7 @@ func serve() {
loggedin.HandleFunc("/atme", homepage)
loggedin.HandleFunc("/hfcs", hfcspage)
loggedin.HandleFunc("/xzone", xzone)
loggedin.HandleFunc("/newhonk", newhonkpage)
loggedin.HandleFunc("/edit", edithonkpage)
loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(submithonk)))
loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitbonk)))