renamed cake editor
This commit is contained in:
parent
331f3080f9
commit
353dffdd82
4 changed files with 4 additions and 4 deletions
|
|
@ -18,7 +18,7 @@ func (c *controller) LoadRouter(pub fs.FS) {
|
||||||
serveMux.HandleFunc("POST /order/new", c.postNewOrder)
|
serveMux.HandleFunc("POST /order/new", c.postNewOrder)
|
||||||
serveMux.HandleFunc("GET /available_cakes", c.cakeOptions)
|
serveMux.HandleFunc("GET /available_cakes", c.cakeOptions)
|
||||||
serveMux.HandleFunc("GET /edit_cakes", c.cakeOptions)
|
serveMux.HandleFunc("GET /edit_cakes", c.cakeOptions)
|
||||||
serveMux.HandleFunc("GET /cake_editor", c.editCakes)
|
serveMux.HandleFunc("GET /cake_editor", c.cakeEditor)
|
||||||
serveMux.HandleFunc("POST /new_cake", c.newCake)
|
serveMux.HandleFunc("POST /new_cake", c.newCake)
|
||||||
|
|
||||||
c.Handler = serveMux
|
c.Handler = serveMux
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,13 @@ func (c *controller) cakeOptions(w http.ResponseWriter, r *http.Request) {
|
||||||
c.tmpl[template].Execute(w, struct{ Cakes []cake }{Cakes: []cake{{"Hello", 1}, {"World", 2}}})
|
c.tmpl[template].Execute(w, struct{ Cakes []cake }{Cakes: []cake{{"Hello", 1}, {"World", 2}}})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) editCakes(w http.ResponseWriter, r *http.Request) {
|
func (c *controller) cakeEditor(w http.ResponseWriter, r *http.Request) {
|
||||||
type cake struct {
|
type cake struct {
|
||||||
Name string
|
Name string
|
||||||
ID int
|
ID int
|
||||||
Price int
|
Price int
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
c.tmpl["cake_editor"].Execute(w, cake{"Hello", 1, 120})
|
c.tmpl["cake_editor"].Execute(w, cake{"Hello", 1, 120})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
<form hx-post="new_cake" hx-swap="outerHTML">
|
<form hx-post="new_cake" hx-swap="outerHTML">
|
||||||
<label>{{.ID}}</label>
|
|
||||||
<div>
|
<div>
|
||||||
<label for="name">Name</label>
|
<label for="name">Name</label>
|
||||||
<input type="text" id="name" name="name" required value="{{.Name}}">
|
<input type="text" id="name" name="name" required value="{{.Name}}">
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<button hx-get="cake_editor" hx-swap="innerHTML" hx-target="#cake_editor">New</button>
|
<button hx-get="cake_editor" hx-swap="innerHTML" hx-target="#cake_editor">New</button>
|
||||||
<div id="cakes">
|
<div id="cakes">
|
||||||
{{range .Cakes}}
|
{{range .Cakes}}
|
||||||
<button>{{.Name}}</button>
|
<button hx-get="cake_editor/{{.ID}}" hx-swap="innerHTML" hx-target="#cake_editor">{{.Name}}</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div id="cake_editor"></div>
|
<div id="cake_editor"></div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue