Show the duplicate invoice form in a dialog
Had to add a new hidden field to the form to know whether, when the
request is HTMx-triggered, to refresh the page, as i do when duplicating
from the index, or redirect the client to the new invoice’s view page,
but only if i was duplicating from that same page, not the index.
Since i now have to target main when redirecting to the view page, so
i had to add a location structure with the required json fields and all
that, when “refreshing” i actually tell HTMx to open the index page
again, which seems faster, now that i am used to boosted links.
2023-04-04 12:39:55 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2023-04-06 10:07:20 +00:00
|
|
|
const (
|
2023-04-24 00:00:38 +00:00
|
|
|
HxLocation = "HX-Location"
|
|
|
|
HxRefresh = "HX-Refresh"
|
|
|
|
HxRequest = "HX-Request"
|
|
|
|
HxTrigger = "HX-Trigger"
|
|
|
|
HxTriggerAfterSettle = "HX-Trigger-After-Settle"
|
2023-04-06 10:07:20 +00:00
|
|
|
)
|
|
|
|
|
Show the duplicate invoice form in a dialog
Had to add a new hidden field to the form to know whether, when the
request is HTMx-triggered, to refresh the page, as i do when duplicating
from the index, or redirect the client to the new invoice’s view page,
but only if i was duplicating from that same page, not the index.
Since i now have to target main when redirecting to the view page, so
i had to add a location structure with the required json fields and all
that, when “refreshing” i actually tell HTMx to open the index page
again, which seems faster, now that i am used to boosted links.
2023-04-04 12:39:55 +00:00
|
|
|
type HTMxLocation struct {
|
|
|
|
Path string `json:"path"`
|
|
|
|
Target string `json:"target"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsHTMxRequest(r *http.Request) bool {
|
2023-04-06 10:07:20 +00:00
|
|
|
return r.Header.Get(HxRequest) == "true"
|
Show the duplicate invoice form in a dialog
Had to add a new hidden field to the form to know whether, when the
request is HTMx-triggered, to refresh the page, as i do when duplicating
from the index, or redirect the client to the new invoice’s view page,
but only if i was duplicating from that same page, not the index.
Since i now have to target main when redirecting to the view page, so
i had to add a location structure with the required json fields and all
that, when “refreshing” i actually tell HTMx to open the index page
again, which seems faster, now that i am used to boosted links.
2023-04-04 12:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func MustMarshalHTMxLocation(location *HTMxLocation) string {
|
|
|
|
data, err := json.Marshal(location)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|