Compare commits
No commits in common. "41ce5af2edd62c88af0038efacdcefbb2a63a8be" and "b07fe6cfa2d48be563ad60a8fab894a4f91ddd91" have entirely different histories.
41ce5af2ed
...
b07fe6cfa2
|
@ -24,7 +24,7 @@ func IndexContacts(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
|
||||||
page := &ContactsIndexPage{
|
page := &ContactsIndexPage{
|
||||||
Contacts: mustGetContactEntries(r.Context(), conn, company),
|
Contacts: mustGetContactEntries(r.Context(), conn, company),
|
||||||
}
|
}
|
||||||
mustRenderMainTemplate(w, r, "contacts/index.gohtml", page)
|
mustRenderAppTemplate(w, r, "contacts/index.gohtml", page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetContactForm(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
func GetContactForm(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
||||||
|
@ -42,26 +42,15 @@ func GetContactForm(w http.ResponseWriter, r *http.Request, params httprouter.Pa
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
mustRenderEditContactForm(w, r, slug, form)
|
mustRenderEditContactForm(w, r, form)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustRenderNewContactForm(w http.ResponseWriter, r *http.Request, form *contactForm) {
|
func mustRenderNewContactForm(w http.ResponseWriter, r *http.Request, form *contactForm) {
|
||||||
mustRenderModalTemplate(w, r, "contacts/new.gohtml", form)
|
mustRenderModalTemplate(w, r, "contacts/new.gohtml", form)
|
||||||
}
|
}
|
||||||
|
|
||||||
type editContactPage struct {
|
func mustRenderEditContactForm(w http.ResponseWriter, r *http.Request, form *contactForm) {
|
||||||
Slug string
|
mustRenderAppTemplate(w, r, "contacts/edit.gohtml", form)
|
||||||
ContactName string
|
|
||||||
Form *contactForm
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustRenderEditContactForm(w http.ResponseWriter, r *http.Request, slug string, form *contactForm) {
|
|
||||||
page := &editContactPage{
|
|
||||||
Slug: slug,
|
|
||||||
ContactName: form.BusinessName.Val,
|
|
||||||
Form: form,
|
|
||||||
}
|
|
||||||
mustRenderModalTemplate(w, r, "contacts/edit.gohtml", page)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleAddContact(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func HandleAddContact(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||||
|
@ -107,21 +96,15 @@ func HandleUpdateContact(w http.ResponseWriter, r *http.Request, params httprout
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !form.Validate(r.Context(), conn) {
|
if !form.Validate(r.Context(), conn) {
|
||||||
mustRenderEditContactForm(w, r, params[0].Value, form)
|
mustRenderEditContactForm(w, r, form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
slug := conn.MustGetText(r.Context(), "", "update contact set business_name = $1, vatin = ($11 || $2)::vatin, trade_name = $3, phone = parse_packed_phone_number($4, $11), email = $5, web = $6, address = $7, city = $8, province = $9, postal_code = $10, country_code = $11 where slug = $12 returning slug", form.BusinessName, form.VATIN, form.TradeName, form.Phone, form.Email, form.Web, form.Address, form.City, form.Province, form.PostalCode, form.Country, params[0].Value)
|
slug := conn.MustGetText(r.Context(), "", "update contact set business_name = $1, vatin = ($11 || $2)::vatin, trade_name = $3, phone = parse_packed_phone_number($4, $11), email = $5, web = $6, address = $7, city = $8, province = $9, postal_code = $10, country_code = $11 where slug = $12 returning slug", form.BusinessName, form.VATIN, form.TradeName, form.Phone, form.Email, form.Web, form.Address, form.City, form.Province, form.PostalCode, form.Country, params[0].Value)
|
||||||
if slug == "" {
|
if slug == "" {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
if IsHTMxRequest(r) {
|
|
||||||
w.Header().Set("HX-Trigger", "closeModal")
|
|
||||||
w.Header().Set("HX-Refresh", "true")
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
|
||||||
} else {
|
|
||||||
http.Redirect(w, r, companyURI(mustGetCompany(r), "/contacts/"+slug), http.StatusSeeOther)
|
http.Redirect(w, r, companyURI(mustGetCompany(r), "/contacts/"+slug), http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func mustGetContactEntries(ctx context.Context, conn *Conn, company *Company) []*ContactEntry {
|
func mustGetContactEntries(ctx context.Context, conn *Conn, company *Company) []*ContactEntry {
|
||||||
rows, err := conn.Query(ctx, "select slug, business_name, email, phone from contact where company_id = $1 order by business_name", company.Id)
|
rows, err := conn.Query(ctx, "select slug, business_name, email, phone from contact where company_id = $1 order by business_name", company.Id)
|
||||||
|
|
|
@ -46,7 +46,7 @@ func IndexInvoices(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
|
||||||
Invoices: mustCollectInvoiceEntries(r.Context(), conn, mustGetCompany(r), locale, tag),
|
Invoices: mustCollectInvoiceEntries(r.Context(), conn, mustGetCompany(r), locale, tag),
|
||||||
InvoiceStatuses: mustCollectInvoiceStatuses(r.Context(), conn, locale),
|
InvoiceStatuses: mustCollectInvoiceStatuses(r.Context(), conn, locale),
|
||||||
}
|
}
|
||||||
mustRenderMainTemplate(w, r, "invoices/index.gohtml", page)
|
mustRenderAppTemplate(w, r, "invoices/index.gohtml", page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustCollectInvoiceEntries(ctx context.Context, conn *Conn, company *Company, locale *Locale, tag string) []*InvoiceEntry {
|
func mustCollectInvoiceEntries(ctx context.Context, conn *Conn, company *Company, locale *Locale, tag string) []*InvoiceEntry {
|
||||||
|
|
|
@ -26,7 +26,7 @@ func IndexProducts(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
|
||||||
page := &productsIndexPage{
|
page := &productsIndexPage{
|
||||||
Products: mustGetProductEntries(r.Context(), conn, company),
|
Products: mustGetProductEntries(r.Context(), conn, company),
|
||||||
}
|
}
|
||||||
mustRenderMainTemplate(w, r, "products/index.gohtml", page)
|
mustRenderAppTemplate(w, r, "products/index.gohtml", page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetProductForm(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
func GetProductForm(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ func NewRouter(db *Db) http.Handler {
|
||||||
companyRouter.GET("/invoices/:slug/edit", ServeEditInvoice)
|
companyRouter.GET("/invoices/:slug/edit", ServeEditInvoice)
|
||||||
companyRouter.POST("/invoices/:slug/edit", HandleEditInvoiceAction)
|
companyRouter.POST("/invoices/:slug/edit", HandleEditInvoiceAction)
|
||||||
companyRouter.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
companyRouter.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||||
mustRenderMainTemplate(w, r, "dashboard.gohtml", nil)
|
mustRenderAppTemplate(w, r, "dashboard.gohtml", nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
|
|
|
@ -100,19 +100,11 @@ func mustRenderAppTemplate(w io.Writer, r *http.Request, filename string, data i
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustRenderModalTemplate(w io.Writer, r *http.Request, filename string, data interface{}) {
|
func mustRenderModalTemplate(w io.Writer, r *http.Request, filename string, data interface{}) {
|
||||||
|
layout := "app.gohtml"
|
||||||
if IsHTMxRequest(r) {
|
if IsHTMxRequest(r) {
|
||||||
mustRenderTemplate(w, r, "modal.gohtml", filename, data)
|
layout = "modal.gohtml"
|
||||||
} else {
|
|
||||||
mustRenderAppTemplate(w, r, filename, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustRenderMainTemplate(w io.Writer, r *http.Request, filename string, data interface{}) {
|
|
||||||
if IsHTMxRequest(r) {
|
|
||||||
mustRenderTemplate(w, r, "main.gohtml", filename, data)
|
|
||||||
} else {
|
|
||||||
mustRenderAppTemplate(w, r, filename, data)
|
|
||||||
}
|
}
|
||||||
|
mustRenderTemplate(w, r, layout, filename, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustRenderWebTemplate(w io.Writer, r *http.Request, filename string, data interface{}) {
|
func mustRenderWebTemplate(w io.Writer, r *http.Request, filename string, data interface{}) {
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
</header>
|
</header>
|
||||||
<nav aria-label="{{( pgettext "Main" "title" )}}" data-hx-target="main" data-hx-boost="true">
|
<nav aria-label="{{( pgettext "Main" "title" )}}">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ companyURI "/" }}">{{( pgettext "Dashboard" "nav" )}}</a></li>
|
<li><a href="{{ companyURI "/" }}">{{( pgettext "Dashboard" "nav" )}}</a></li>
|
||||||
<li><a href="{{ companyURI "/invoices" }}">{{( pgettext "Invoices" "nav" )}}</a></li>
|
<li><a href="{{ companyURI "/invoices" }}">{{( pgettext "Invoices" "nav" )}}</a></li>
|
||||||
|
|
|
@ -1,28 +1,26 @@
|
||||||
{{ define "title" -}}
|
{{ define "title" -}}
|
||||||
{{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.editContactPage*/ -}}
|
{{printf (pgettext "Edit Contact “%s”" "title") .BusinessName.Val }}
|
||||||
{{printf (pgettext "Edit Contact “%s”" "title") .ContactName }}
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{ define "breadcrumbs" -}}
|
{{ define "breadcrumbs" -}}
|
||||||
{{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.editContactPage*/ -}}
|
{{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.contactForm*/ -}}
|
||||||
<nav>
|
<nav>
|
||||||
<p>
|
<p>
|
||||||
<a href="{{ companyURI "/" }}">{{( pgettext "Home" "title" )}}</a> /
|
<a href="{{ companyURI "/" }}">{{( pgettext "Home" "title" )}}</a> /
|
||||||
<a href="{{ companyURI "/contacts"}}">{{( pgettext "Contacts" "title" )}}</a> /
|
<a href="{{ companyURI "/contacts"}}">{{( pgettext "Contacts" "title" )}}</a> /
|
||||||
<a>{{ .ContactName }}</a>
|
<a>{{ .BusinessName.Val }}</a>
|
||||||
</p>
|
</p>
|
||||||
</nav>
|
</nav>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
{{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.editContactPage*/ -}}
|
{{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.contactForm*/ -}}
|
||||||
<section class="dialog-content" id="edit-contact-dialog-content" data-hx-target="this">
|
<section class="dialog-content">
|
||||||
<h2>{{printf (pgettext "Edit Contact “%s”" "title") .ContactName }}</h2>
|
<h2>{{printf (pgettext "Edit Contact “%s”" "title") .BusinessName.Val }}</h2>
|
||||||
<form method="POST" action="{{ companyURI "/contacts/" }}{{ .Slug }}" data-hx-boost="true" data-hx-select="#edit-contact-dialog-content">
|
<form method="POST">
|
||||||
{{ csrfToken }}
|
{{ csrfToken }}
|
||||||
{{ putMethod }}
|
{{ putMethod }}
|
||||||
|
|
||||||
{{ with .Form }}
|
|
||||||
{{ template "input-field" .BusinessName }}
|
{{ template "input-field" .BusinessName }}
|
||||||
{{ template "input-field" .VATIN }}
|
{{ template "input-field" .VATIN }}
|
||||||
{{ template "input-field" .TradeName }}
|
{{ template "input-field" .TradeName }}
|
||||||
|
@ -34,7 +32,6 @@
|
||||||
{{ template "input-field" .Province }}
|
{{ template "input-field" .Province }}
|
||||||
{{ template "input-field" .PostalCode }}
|
{{ template "input-field" .PostalCode }}
|
||||||
{{ template "select-field" .Country | addSelectAttr `class="width-fixed"` }}
|
{{ template "select-field" .Country | addSelectAttr `class="width-fixed"` }}
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<button class="primary" type="submit">{{( pgettext "Update contact" "action" )}}</button>
|
<button class="primary" type="submit">{{( pgettext "Update contact" "action" )}}</button>
|
||||||
|
|
|
@ -28,12 +28,12 @@
|
||||||
<th>{{( pgettext "Phone" "title" )}}</th>
|
<th>{{( pgettext "Phone" "title" )}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody data-hx-push-url="false" data-hx-swap="beforeend">
|
<tbody>
|
||||||
{{ with .Contacts }}
|
{{ with .Contacts }}
|
||||||
{{- range $contact := . }}
|
{{- range $contact := . }}
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td><a href="{{ companyURI "/contacts/"}}{{ .Slug }}" data-hx-boost="true">{{ .Name }}</a></td>
|
<td><a href="{{ companyURI "/contacts/"}}{{ .Slug }}">{{ .Name }}</a></td>
|
||||||
<td><a href="mailto:{{ .Email }}">{{ .Email }}</a></td>
|
<td><a href="mailto:{{ .Email }}">{{ .Email }}</a></td>
|
||||||
<td><a href="tel:{{ .Phone }}">{{ .Phone }}</a></td>
|
<td><a href="tel:{{ .Phone }}">{{ .Phone }}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
{{- template "breadcrumbs" . }}
|
|
||||||
{{- template "content" . }}
|
|
Loading…
Reference in New Issue