Add the inline form for product tags
This commit is contained in:
parent
f0f98e200c
commit
856ddde00e
|
@ -352,3 +352,36 @@ func HandleProductSearch(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
|
||||||
}
|
}
|
||||||
mustRenderStandaloneTemplate(w, r, "products/search.gohtml", products)
|
mustRenderStandaloneTemplate(w, r, "products/search.gohtml", products)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ServeEditProductTags(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
||||||
|
conn := getConn(r)
|
||||||
|
locale := getLocale(r)
|
||||||
|
company := getCompany(r)
|
||||||
|
slug := params[0].Value
|
||||||
|
form := newTagsForm(companyURI(company, "/products/"+slug+"/tags"), slug, locale)
|
||||||
|
if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select array_to_string(tags, ',') from product where slug = $1`, form.Slug).Scan(&form.Tags)) {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mustRenderStandaloneTemplate(w, r, "tags/edit.gohtml", form)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleUpdateProductTags(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
||||||
|
locale := getLocale(r)
|
||||||
|
conn := getConn(r)
|
||||||
|
company := getCompany(r)
|
||||||
|
slug := params[0].Value
|
||||||
|
form := newTagsForm(companyURI(company, "/products/"+slug+"/tags/edit"), slug, locale)
|
||||||
|
if err := form.Parse(r); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := verifyCsrfTokenValid(r); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if conn.MustGetText(r.Context(), "", "update product set tags = $1 where slug = $2 returning slug", form.Tags, form.Slug) == "" {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
mustRenderStandaloneTemplate(w, r, "tags/view.gohtml", form)
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ func NewRouter(db *Db) http.Handler {
|
||||||
companyRouter.POST("/products", HandleAddProduct)
|
companyRouter.POST("/products", HandleAddProduct)
|
||||||
companyRouter.GET("/products/:slug", GetProductForm)
|
companyRouter.GET("/products/:slug", GetProductForm)
|
||||||
companyRouter.PUT("/products/:slug", HandleUpdateProduct)
|
companyRouter.PUT("/products/:slug", HandleUpdateProduct)
|
||||||
|
companyRouter.PUT("/products/:slug/tags", HandleUpdateProductTags)
|
||||||
|
companyRouter.GET("/products/:slug/tags/edit", ServeEditProductTags)
|
||||||
companyRouter.GET("/invoices", IndexInvoices)
|
companyRouter.GET("/invoices", IndexInvoices)
|
||||||
companyRouter.POST("/invoices", HandleAddInvoice)
|
companyRouter.POST("/invoices", HandleAddInvoice)
|
||||||
companyRouter.GET("/invoices/:slug", ServeInvoice)
|
companyRouter.GET("/invoices/:slug", ServeInvoice)
|
||||||
|
|
|
@ -47,10 +47,14 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td><a href="{{ companyURI "/products/"}}{{ .Slug }}" data-hx-target="main" data-hx-boost="true">{{ .Name }}</a></td>
|
<td><a href="{{ companyURI "/products/"}}{{ .Slug }}" data-hx-target="main" data-hx-boost="true">{{ .Name }}</a></td>
|
||||||
<td>
|
<td
|
||||||
|
data-hx-get="{{companyURI "/products/"}}{{ .Slug }}/tags/edit"
|
||||||
|
data-hx-target="this"
|
||||||
|
data-hx-swap="outerHTML"
|
||||||
|
>
|
||||||
{{- range $index, $tag := .Tags }}
|
{{- range $index, $tag := .Tags }}
|
||||||
{{- if gt $index 0 }}, {{ end -}}
|
{{- if gt $index 0 }}, {{ end -}}
|
||||||
<a href="?tags={{ . }}" data-hx-target="main" data-hx-boost="true">{{ . }}</a>
|
{{ . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</td>
|
</td>
|
||||||
<td class="numeric">{{ .Price | formatPrice }}</td>
|
<td class="numeric">{{ .Price | formatPrice }}</td>
|
||||||
|
|
Loading…
Reference in New Issue