diff --git a/pkg/contacts.go b/pkg/contacts.go index 295fea8..830536b 100644 --- a/pkg/contacts.go +++ b/pkg/contacts.go @@ -48,7 +48,7 @@ func GetContactForm(w http.ResponseWriter, r *http.Request, params httprouter.Pa } func mustRenderNewContactForm(w http.ResponseWriter, r *http.Request, form *contactForm) { - mustRenderModalTemplate(w, r, "contacts/new.gohtml", form) + mustRenderMainTemplate(w, r, "contacts/new.gohtml", form) } type editContactPage struct { @@ -63,7 +63,7 @@ func mustRenderEditContactForm(w http.ResponseWriter, r *http.Request, slug stri ContactName: form.BusinessName.Val, Form: form, } - mustRenderModalTemplate(w, r, "contacts/edit.gohtml", page) + mustRenderMainTemplate(w, r, "contacts/edit.gohtml", page) } func HandleAddContact(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { @@ -87,13 +87,7 @@ func HandleAddContact(w http.ResponseWriter, r *http.Request, _ httprouter.Param } company := mustGetCompany(r) conn.MustExec(r.Context(), "select add_contact($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)", company.Id, form.BusinessName, form.VATIN, form.TradeName, form.Phone, form.Email, form.Web, form.Address, form.City, form.Province, form.PostalCode, form.Country, form.Tags) - if IsHTMxRequest(r) { - w.Header().Set(HxTrigger, "closeModal") - w.Header().Set(HxRefresh, "true") - w.WriteHeader(http.StatusNoContent) - } else { - http.Redirect(w, r, companyURI(company, "/contacts"), http.StatusSeeOther) - } + htmxRedirect(w, r, companyURI(company, "/contacts")) } func HandleUpdateContact(w http.ResponseWriter, r *http.Request, params httprouter.Params) { @@ -116,13 +110,7 @@ func HandleUpdateContact(w http.ResponseWriter, r *http.Request, params httprout if slug == "" { http.NotFound(w, r) } - if IsHTMxRequest(r) { - w.Header().Set(HxTrigger, "closeModal") - w.Header().Set(HxRefresh, "true") - w.WriteHeader(http.StatusNoContent) - } else { - http.Redirect(w, r, companyURI(mustGetCompany(r), "/contacts/"+slug), http.StatusSeeOther) - } + htmxRedirect(w, r, companyURI(mustGetCompany(r), "/contacts")) } func mustCollectContactEntries(ctx context.Context, conn *Conn, company *Company, tag string) []*ContactEntry { diff --git a/pkg/invoices.go b/pkg/invoices.go index be2d762..a1b3368 100644 --- a/pkg/invoices.go +++ b/pkg/invoices.go @@ -229,7 +229,6 @@ func ServeInvoice(w http.ResponseWriter, r *http.Request, params httprouter.Para if invoiceToDuplicate := r.URL.Query().Get("duplicate"); invoiceToDuplicate != "" { form.MustFillFromDatabase(r.Context(), conn, invoiceToDuplicate) form.InvoiceStatus.Selected = []string{"created"} - form.Location.Val = r.URL.Query().Get("location") } form.Date.Val = time.Now().Format("2006-01-02") w.WriteHeader(http.StatusOK) @@ -423,7 +422,7 @@ func mustRenderNewInvoiceForm(w http.ResponseWriter, r *http.Request, form *invo locale := getLocale(r) form.Customer.EmptyLabel = gettext("Select a customer to bill.", locale) page := newNewInvoicePage(form, r) - mustRenderModalTemplate(w, r, "invoices/new.gohtml", page) + mustRenderMainTemplate(w, r, "invoices/new.gohtml", page) } func mustRenderNewInvoiceProductsForm(w http.ResponseWriter, r *http.Request, action string, form *invoiceForm) { @@ -434,7 +433,7 @@ func mustRenderNewInvoiceProductsForm(w http.ResponseWriter, r *http.Request, ac Form: form, Products: mustGetProductChoices(r.Context(), conn, company), } - mustRenderModalTemplate(w, r, "invoices/products.gohtml", page) + mustRenderMainTemplate(w, r, "invoices/products.gohtml", page) } func mustGetProductChoices(ctx context.Context, conn *Conn, company *Company) []*productChoice { @@ -489,7 +488,7 @@ func HandleAddInvoice(w http.ResponseWriter, r *http.Request, _ httprouter.Param return } slug := conn.MustGetText(r.Context(), "", "select add_invoice($1, $2, $3, $4, $5, $6, $7)", company.Id, form.Date, form.Customer, form.Notes, form.PaymentMethod, form.Tags, NewInvoiceProductArray(form.Products)) - closeModalAndRedirect(w, r, form.Location.Val, "/invoices/"+slug, "/invoices") + htmxRedirect(w, r, companyURI(company, "/invoices/"+slug)) } func HandleNewInvoiceAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) { @@ -556,7 +555,6 @@ type invoiceForm struct { locale *Locale company *Company Number string - Location *InputField InvoiceStatus *SelectField Customer *SelectField Date *InputField @@ -570,10 +568,6 @@ func newInvoiceForm(ctx context.Context, conn *Conn, locale *Locale, company *Co return &invoiceForm{ locale: locale, company: company, - Location: &InputField{ - Name: "redirect", - Type: "hidden", - }, InvoiceStatus: &SelectField{ Name: "invoice_status", Required: true, @@ -616,7 +610,6 @@ func (form *invoiceForm) Parse(r *http.Request) error { if err := r.ParseForm(); err != nil { return err } - form.Location.FillValue(r) form.InvoiceStatus.FillValue(r) form.Customer.FillValue(r) form.Date.FillValue(r) @@ -932,22 +925,10 @@ func HandleUpdateInvoice(w http.ResponseWriter, r *http.Request, params httprout http.NotFound(w, r) return } - closeModalAndRedirect(w, r, form.Location.Val, "/invoices/"+slug, "/invoices") + htmxRedirect(w, r, companyURI(company, "/invoices/"+slug)) } } -func closeModalAndRedirect(w http.ResponseWriter, r *http.Request, selector string, viewUri string, indexUri string) { - company := mustGetCompany(r) - nextUri := companyURI(company, indexUri) - if IsHTMxRequest(r) { - w.Header().Set(HxTrigger, "closeModal") - if selector == "view" { - nextUri = companyURI(company, viewUri) - } - } - htmxRedirect(w, r, nextUri) -} - func htmxRedirect(w http.ResponseWriter, r *http.Request, uri string) { if IsHTMxRequest(r) { w.Header().Set(HxLocation, MustMarshalHTMxLocation(&HTMxLocation{ @@ -970,7 +951,6 @@ func ServeEditInvoice(w http.ResponseWriter, r *http.Request, params httprouter. http.NotFound(w, r) return } - form.Location.Val = r.URL.Query().Get("location") w.WriteHeader(http.StatusOK) mustRenderEditInvoiceForm(w, r, slug, form) } @@ -991,7 +971,7 @@ func newEditInvoicePage(slug string, form *invoiceForm, r *http.Request) *editIn func mustRenderEditInvoiceForm(w http.ResponseWriter, r *http.Request, slug string, form *invoiceForm) { page := newEditInvoicePage(slug, form, r) - mustRenderModalTemplate(w, r, "invoices/edit.gohtml", page) + mustRenderMainTemplate(w, r, "invoices/edit.gohtml", page) } func HandleEditInvoiceAction(w http.ResponseWriter, r *http.Request, params httprouter.Params) { diff --git a/pkg/products.go b/pkg/products.go index 093e797..500f65b 100644 --- a/pkg/products.go +++ b/pkg/products.go @@ -59,7 +59,7 @@ func GetProductForm(w http.ResponseWriter, r *http.Request, params httprouter.Pa } func mustRenderNewProductForm(w http.ResponseWriter, r *http.Request, form *productForm) { - mustRenderModalTemplate(w, r, "products/new.gohtml", form) + mustRenderMainTemplate(w, r, "products/new.gohtml", form) } type editProductPage struct { @@ -74,7 +74,7 @@ func mustRenderEditProductForm(w http.ResponseWriter, r *http.Request, slug stri ProductName: form.Name.Val, Form: form, } - mustRenderModalTemplate(w, r, "products/edit.gohtml", page) + mustRenderMainTemplate(w, r, "products/edit.gohtml", page) } func HandleAddProduct(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { @@ -99,13 +99,7 @@ func HandleAddProduct(w http.ResponseWriter, r *http.Request, _ httprouter.Param } taxes := mustSliceAtoi(form.Tax.Selected) conn.MustExec(r.Context(), "select add_product($1, $2, $3, $4, $5, $6)", company.Id, form.Name, form.Description, form.Price, taxes, form.Tags) - if IsHTMxRequest(r) { - w.Header().Set(HxTrigger, "closeModal") - w.Header().Set(HxRefresh, "true") - w.WriteHeader(http.StatusNoContent) - } else { - http.Redirect(w, r, companyURI(company, "/products"), http.StatusSeeOther) - } + htmxRedirect(w, r, companyURI(company, "/products")) } func sliceAtoi(s []string) ([]int, error) { @@ -151,13 +145,7 @@ func HandleUpdateProduct(w http.ResponseWriter, r *http.Request, params httprout if ok := conn.MustGetBool(r.Context(), "select edit_product($1, $2, $3, $4, $5, $6)", slug, form.Name, form.Description, form.Price, taxes, form.Tags); !ok { http.NotFound(w, r) } - if IsHTMxRequest(r) { - w.Header().Set(HxTrigger, "closeModal") - w.Header().Set(HxRefresh, "true") - w.WriteHeader(http.StatusNoContent) - } else { - http.Redirect(w, r, companyURI(company, "/products/"+slug), http.StatusSeeOther) - } + htmxRedirect(w, r, companyURI(company, "/products")) } type productFilterForm struct { diff --git a/web/template/contacts/edit.gohtml b/web/template/contacts/edit.gohtml index 7fd8eed..a4a3f0c 100644 --- a/web/template/contacts/edit.gohtml +++ b/web/template/contacts/edit.gohtml @@ -16,9 +16,9 @@ {{ define "content" }} {{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.editContactPage*/ -}} -
+

{{printf (pgettext "Edit Contact “%s”" "title") .ContactName }}

-
+ {{ csrfToken }} {{ putMethod }} diff --git a/web/template/contacts/index.gohtml b/web/template/contacts/index.gohtml index 5a4d7d2..92d1c92 100644 --- a/web/template/contacts/index.gohtml +++ b/web/template/contacts/index.gohtml @@ -4,14 +4,13 @@ {{ define "breadcrumbs" -}} {{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.ContactsIndexPage*/ -}} -