Add the new service form

This commit is contained in:
jordi fita mas 2023-09-26 16:51:35 +02:00
parent cdea3e59de
commit d4cabce7f5
4 changed files with 49 additions and 16 deletions

View File

@ -45,6 +45,16 @@ func (h *AdminHandler) Handler(user *auth.User, company *auth.Company, conn *dat
switch r.Method {
case http.MethodGet:
serveHomeIndex(w, r, user, company, conn)
case http.MethodPost:
addService(w, r, user, company, conn)
default:
httplib.MethodNotAllowed(w, r, http.MethodGet, http.MethodPost)
}
case "new":
switch r.Method {
case http.MethodGet:
f := newServiceForm(r.Context(), conn)
f.MustRender(w, r, user, company)
default:
httplib.MethodNotAllowed(w, r, http.MethodGet)
}
@ -172,6 +182,18 @@ func collectServiceEntries(ctx context.Context, company *auth.Company, conn *dat
return services, nil
}
func addService(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn) {
f := newServiceForm(r.Context(), conn)
if ok, err := form.Handle(f, w, r, user); err != nil {
return
} else if !ok {
f.MustRender(w, r, user, company)
return
}
conn.MustExec(r.Context(), "select add_service($1, $2, $3, $4)", company.ID, f.Icon, f.Name, f.Description)
httplib.Redirect(w, r, "/admin/services", http.StatusSeeOther)
}
func editService(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn, f *serviceForm) {
if ok, err := form.Handle(f, w, r, user); err != nil {
return

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: camper\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
"POT-Creation-Date: 2023-09-25 20:03+0200\n"
"POT-Creation-Date: 2023-09-26 16:50+0200\n"
"PO-Revision-Date: 2023-07-22 23:45+0200\n"
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
"Language-Team: Catalan <ca@dodds.net>\n"
@ -338,7 +338,7 @@ msgstr "Nom"
#: web/templates/admin/campsite/type/index.gohtml:18
#: web/templates/admin/services/index.gohtml:19
#: web/templates/admin/services/index.gohtml:56
#: web/templates/admin/services/index.gohtml:57
#: web/templates/admin/home/index.gohtml:19
msgctxt "campsite type"
msgid "Translations"
@ -473,14 +473,14 @@ msgid "Caption"
msgstr "Llegenda"
#: web/templates/admin/services/index.gohtml:20
#: web/templates/admin/services/index.gohtml:57
#: web/templates/admin/services/index.gohtml:58
#: web/templates/admin/home/index.gohtml:20
msgctxt "campsite type"
msgid "Actions"
msgstr "Accions"
#: web/templates/admin/services/index.gohtml:39
#: web/templates/admin/services/index.gohtml:73
#: web/templates/admin/services/index.gohtml:74
#: web/templates/admin/home/index.gohtml:39
msgctxt "action"
msgid "Delete"
@ -491,12 +491,17 @@ msgstr "Esborra"
msgid "No slides added yet."
msgstr "No sha afegit cap diapositiva encara."
#: web/templates/admin/services/index.gohtml:55
#: web/templates/admin/services/index.gohtml:51
msgctxt "action"
msgid "Add service"
msgstr "Afegeix servei"
#: web/templates/admin/services/index.gohtml:56
msgctxt "header"
msgid "Service"
msgstr "Servei"
#: web/templates/admin/services/index.gohtml:81
#: web/templates/admin/services/index.gohtml:82
msgid "No services added yet."
msgstr "No sha afegit cap servei encara."
@ -748,7 +753,7 @@ msgstr "Automàtic"
#: pkg/app/user.go:249 pkg/campsite/types/l10n.go:82
#: pkg/campsite/types/admin.go:274 pkg/season/admin.go:203
#: pkg/services/l10n.go:73 pkg/services/admin.go:232
#: pkg/services/l10n.go:73 pkg/services/admin.go:255
msgid "Name can not be empty."
msgstr "No podeu deixar el nom en blanc."
@ -802,7 +807,7 @@ msgstr "No podeu deixar el color en blanc."
msgid "This color is not valid. It must be like #123abc."
msgstr "Aquest color no és vàlid. Hauria de ser similar a #123abc."
#: pkg/services/admin.go:231
#: pkg/services/admin.go:254
msgid "Selected icon is not valid."
msgstr "La icona escollida no és vàlida."

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: camper\n"
"Report-Msgid-Bugs-To: jordi@tandem.blog\n"
"POT-Creation-Date: 2023-09-25 20:03+0200\n"
"POT-Creation-Date: 2023-09-26 16:50+0200\n"
"PO-Revision-Date: 2023-07-22 23:46+0200\n"
"Last-Translator: jordi fita mas <jordi@tandem.blog>\n"
"Language-Team: Spanish <es@tp.org.es>\n"
@ -338,7 +338,7 @@ msgstr "Nombre"
#: web/templates/admin/campsite/type/index.gohtml:18
#: web/templates/admin/services/index.gohtml:19
#: web/templates/admin/services/index.gohtml:56
#: web/templates/admin/services/index.gohtml:57
#: web/templates/admin/home/index.gohtml:19
msgctxt "campsite type"
msgid "Translations"
@ -473,14 +473,14 @@ msgid "Caption"
msgstr "Leyenda"
#: web/templates/admin/services/index.gohtml:20
#: web/templates/admin/services/index.gohtml:57
#: web/templates/admin/services/index.gohtml:58
#: web/templates/admin/home/index.gohtml:20
msgctxt "campsite type"
msgid "Actions"
msgstr "Acciones"
#: web/templates/admin/services/index.gohtml:39
#: web/templates/admin/services/index.gohtml:73
#: web/templates/admin/services/index.gohtml:74
#: web/templates/admin/home/index.gohtml:39
msgctxt "action"
msgid "Delete"
@ -491,12 +491,17 @@ msgstr "Borrar"
msgid "No slides added yet."
msgstr "No se ha añadido ninguna diapositiva todavía."
#: web/templates/admin/services/index.gohtml:55
#: web/templates/admin/services/index.gohtml:51
msgctxt "action"
msgid "Add service"
msgstr "Añadir servicio"
#: web/templates/admin/services/index.gohtml:56
msgctxt "header"
msgid "Service"
msgstr "Servicio"
#: web/templates/admin/services/index.gohtml:81
#: web/templates/admin/services/index.gohtml:82
msgid "No services added yet."
msgstr "No se ha añadido ningún servicio todavía."
@ -748,7 +753,7 @@ msgstr "Automático"
#: pkg/app/user.go:249 pkg/campsite/types/l10n.go:82
#: pkg/campsite/types/admin.go:274 pkg/season/admin.go:203
#: pkg/services/l10n.go:73 pkg/services/admin.go:232
#: pkg/services/l10n.go:73 pkg/services/admin.go:255
msgid "Name can not be empty."
msgstr "No podéis dejar el nombre en blanco."
@ -802,7 +807,7 @@ msgstr "No podéis dejar el color en blanco."
msgid "This color is not valid. It must be like #123abc."
msgstr "Este color no es válido. Tiene que ser parecido a #123abc."
#: pkg/services/admin.go:231
#: pkg/services/admin.go:254
msgid "Selected icon is not valid."
msgstr "El icono escogido no es válido."

View File

@ -48,6 +48,7 @@
{{- end }}
<h2>{{( pgettext "Services" "title" )}}</h2>
<a href="/admin/services/new">{{( pgettext "Add service" "action" )}}</a>
{{ if .Services -}}
<table class="services">
<thead>