delete comment confirm()

This commit is contained in:
Ryan Stafford 2023-10-04 13:31:49 -04:00
parent 352360218b
commit aaf0234e5b
3 changed files with 16 additions and 2 deletions

View file

@ -55,6 +55,11 @@ function commentClick(e) {
targ = form
} else { return }
e.target.disabled = "disabled"
if (data.get("op") == "delete_comment") {
if (!confirm("Are you sure you want to delete?")) {
return false
}
}
request(targ.action || "", data,
function(res){
if (data.get("op") == "block_user") {

View file

@ -1297,7 +1297,7 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
postid, _ := strconv.Atoi(ps.ByName("postid"))
state.PostID = postid
}
if r.FormValue("parentid") != "" {
if r.FormValue("parentid") != "" && r.FormValue("parentid") != "0" {
parentid, _ := strconv.Atoi(r.FormValue("parentid"))
state.GetComment(parentid)
}
@ -1428,6 +1428,13 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if err != nil {
fmt.Println(err)
} else {
if r.FormValue("xhr") != "" {
state.XHR = true
state.Comments = append(state.Comments, Comment{P: resp.CommentView, State: &state})
state.CommentID = commentid
Render(w, "index.html", state)
return
}
commentid := strconv.Itoa(resp.CommentView.Comment.ID)
r.URL.Fragment = "c" + commentid
r.URL.RawQuery = ""

View file

@ -61,13 +61,15 @@
{{ if .State.Session }}
{{ if and (eq .P.Comment.CreatorID .State.Session.UserID) (ne .Op "edit") }}
<li><a class="edit" for="c{{.P.Comment.ID}}" href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?edit">edit</a></li>
{{ if not .P.Comment.Deleted }}
<li>
<form class="delete" method="POST">
<input type="hidden" name="commentid" value="{{.P.Comment.ID}}">
<input type="hidden" name="op" value="delete_comment">
<input type="submit" value="delete">
<input type="submit" name="submit" value="delete">
</form>
</li>
{{ end }}
{{ end }}
<li>
<form class="link-btn" method="POST">