mirror of https://github.com/jlelse/GoBlog
Extra step to confirm deletion of posts
This commit is contained in:
parent
705f02b7ef
commit
abbd79d8a9
22
editor.go
22
editor.go
|
@ -25,6 +25,14 @@ func serveEditorPost(w http.ResponseWriter, r *http.Request) {
|
|||
blog := r.Context().Value(blogContextKey).(string)
|
||||
if action := r.FormValue("editoraction"); action != "" {
|
||||
switch action {
|
||||
case "loaddelete":
|
||||
render(w, r, templateEditor, &renderData{
|
||||
BlogString: blog,
|
||||
Data: map[string]interface{}{
|
||||
"DeleteURL": r.FormValue("url"),
|
||||
"Drafts": loadDrafts(blog),
|
||||
},
|
||||
})
|
||||
case "loadupdate":
|
||||
parsedURL, err := url.Parse(r.FormValue("url"))
|
||||
if err != nil {
|
||||
|
@ -36,28 +44,24 @@ func serveEditorPost(w http.ResponseWriter, r *http.Request) {
|
|||
serveError(w, r, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
mf := post.toMfItem()
|
||||
render(w, r, templateEditor, &renderData{
|
||||
BlogString: blog,
|
||||
Data: map[string]interface{}{
|
||||
"UpdatePostURL": parsedURL.String(),
|
||||
"UpdatePostContent": mf.Properties.Content[0],
|
||||
"UpdatePostContent": post.toMfItem().Properties.Content[0],
|
||||
"Drafts": loadDrafts(blog),
|
||||
},
|
||||
})
|
||||
case "updatepost":
|
||||
urlValue := r.FormValue("url")
|
||||
content := r.FormValue("content")
|
||||
mf := map[string]interface{}{
|
||||
jsonBytes, err := json.Marshal(map[string]interface{}{
|
||||
"action": actionUpdate,
|
||||
"url": urlValue,
|
||||
"url": r.FormValue("url"),
|
||||
"replace": map[string][]string{
|
||||
"content": {
|
||||
content,
|
||||
r.FormValue("content"),
|
||||
},
|
||||
},
|
||||
}
|
||||
jsonBytes, err := json.Marshal(mf)
|
||||
})
|
||||
if err != nil {
|
||||
serveError(w, r, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
|
4
go.mod
4
go.mod
|
@ -58,9 +58,9 @@ require (
|
|||
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf // indirect
|
||||
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
|
||||
golang.org/x/mod v0.4.1 // indirect
|
||||
golang.org/x/net v0.0.0-20210505214959-0714010a04ed
|
||||
golang.org/x/net v0.0.0-20210508051633-16afe75a6701
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||
golang.org/x/sys v0.0.0-20210507014357-30e306a8bba5 // indirect
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 // indirect
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -415,8 +415,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
|
|||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
|
||||
golang.org/x/net v0.0.0-20210505214959-0714010a04ed h1:V9kAVxLvz1lkufatrpHuUVyJ/5tR3Ms7rk951P4mI98=
|
||||
golang.org/x/net v0.0.0-20210505214959-0714010a04ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210508051633-16afe75a6701 h1:lQVgcB3+FoAXOb20Dp6zTzAIrpj1k/yOOBN7s+Zv1rA=
|
||||
golang.org/x/net v0.0.0-20210508051633-16afe75a6701/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/oauth2 v0.0.0-20170912212905-13449ad91cb2/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
@ -453,8 +453,8 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210507014357-30e306a8bba5 h1:cez+MEm4+A0CG7ik1Qzj3bmK9DFoouuLom9lwM+Ijow=
|
||||
golang.org/x/sys v0.0.0-20210507014357-30e306a8bba5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 h1:5PbJGn5Sp3GEUjJ61aYbUP6RIo3Z3r2E4Tv9y2z8UHo=
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
|
|
|
@ -20,8 +20,8 @@ tags:
|
|||
</textarea>
|
||||
<input class="fw" type="submit" value="{{ string .Blog.Lang "create" }}">
|
||||
</form>
|
||||
<h2>{{ string .Blog.Lang "update" }}</h2>
|
||||
<form class="fw-form p" method="post">
|
||||
<h2 id="update">{{ string .Blog.Lang "update" }}</h2>
|
||||
<form class="fw-form p" method="post" action="#update">
|
||||
{{ if .Data.UpdatePostURL }}
|
||||
<input type="hidden" name="editoraction" value="updatepost">
|
||||
<input type="hidden" name="url" value="{{ .Data.UpdatePostURL }}">
|
||||
|
@ -32,11 +32,17 @@ tags:
|
|||
{{ end }}
|
||||
<input class="fw" type="submit" value="{{ string .Blog.Lang "update" }}">
|
||||
</form>
|
||||
<h2>{{ string .Blog.Lang "delete" }}</h2>
|
||||
<form class="fw-form p" method="post">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="url" name="url" placeholder="URL">
|
||||
<input class="fw" type="submit" value="{{ string .Blog.Lang "delete" }}">
|
||||
<h2 id="delete">{{ string .Blog.Lang "delete" }}</h2>
|
||||
<form class="fw-form p" method="post" action="#delete">
|
||||
{{ if .Data.DeleteURL }}
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="url" name="url" placeholder="URL" value="{{ .Data.DeleteURL }}">
|
||||
<input class="fw" type="submit" value="{{ string .Blog.Lang "confirmdelete" }}">
|
||||
{{ else }}
|
||||
<input type="hidden" name="editoraction" value="loaddelete">
|
||||
<input type="url" name="url" placeholder="URL">
|
||||
<input class="fw" type="submit" value="{{ string .Blog.Lang "delete" }}">
|
||||
{{ end }}
|
||||
</form>
|
||||
<h2>{{ string .Blog.Lang "upload" }}</h2>
|
||||
<form class="fw-form p" method="post" enctype="multipart/form-data">
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
</main>
|
||||
{{ if .LoggedIn }}
|
||||
<div class="p">
|
||||
<form class="in" method="post" action="{{ blogrelative .Blog "/editor" }}">
|
||||
<form class="in" method="post" action="{{ blogrelative .Blog "/editor" }}#update">
|
||||
<input type="hidden" name="editoraction" value="loadupdate">
|
||||
<input type="hidden" name="url" value="{{ .Canonical }}">
|
||||
<input type="submit" value="{{ string .Blog.Lang "update" }}">
|
||||
</form>
|
||||
<form class="in" method="post" action="{{ blogrelative .Blog "/editor" }}">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<form class="in" method="post" action="{{ blogrelative .Blog "/editor" }}#delete">
|
||||
<input type="hidden" name="editoraction" value="loaddelete">
|
||||
<input type="hidden" name="url" value="{{ .Canonical }}">
|
||||
<input type="submit" value="{{ string .Blog.Lang "delete" }}">
|
||||
</form>
|
||||
|
|
|
@ -2,6 +2,7 @@ acommentby: "Ein Kommentar von"
|
|||
chars: "Buchstaben"
|
||||
comment: "Kommentar"
|
||||
comments: "Kommentare"
|
||||
confirmdelete: "Löschen bestätigen"
|
||||
create: "Erstellen"
|
||||
delete: "Löschen"
|
||||
docomment: "Kommentieren"
|
||||
|
|
|
@ -7,6 +7,7 @@ captchainstructions: "Please enter the digits from the image above"
|
|||
chars: "Characters"
|
||||
comment: "Comment"
|
||||
comments: "Comments"
|
||||
confirmdelete: "Confirm deletion"
|
||||
create: "Create"
|
||||
delete: "Delete"
|
||||
docomment: "Comment"
|
||||
|
|
Loading…
Reference in New Issue