Make checking boxes not require full page reload
This commit is contained in:
parent
cb24ab18c5
commit
1772e57ee8
3 changed files with 46 additions and 13 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package views
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
|
@ -181,18 +182,25 @@ func togglebox(w http.ResponseWriter, r *http.Request) {
|
|||
nthBox, err := strconv.Atoi(r.FormValue("box"))
|
||||
if err != nil {
|
||||
log.Fatal("You fucked up boy")
|
||||
http.Error(w, "Box not provided as numeric value", 400)
|
||||
return
|
||||
}
|
||||
|
||||
note, ok := notes.Notes.GetOne(user, uid)
|
||||
if !ok {
|
||||
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": uid}), http.StatusFound)
|
||||
http.Error(w, "Note not found", 404)
|
||||
return
|
||||
}
|
||||
|
||||
note.ToggleBox(nthBox)
|
||||
toggled, checked := note.ToggleBox(nthBox)
|
||||
|
||||
http.Redirect(w, r, myurls.Reverse("view", urls.Repl{"note": note.Uid}), http.StatusFound)
|
||||
if !toggled {
|
||||
http.Error(w, "Failed to toggle box", 500)
|
||||
} else {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]any{"checked": checked})
|
||||
}
|
||||
}
|
||||
|
||||
type titleAndURL struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue