Reusing templates and saving me from some troubles
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
<div class="form-container form-inline">
|
<div class="form-container form-inline">
|
||||||
<div id="form-state" class="warning"></div><br>
|
<div id="form-state" class="warning"></div><br>
|
||||||
|
|
||||||
|
{{ if eq .method "put" }}
|
||||||
<p>
|
<p>
|
||||||
<label for="expense-desc">ID:</label>
|
<label for="expense-desc">ID:</label>
|
||||||
<input
|
<input
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
class="tui-input underline fullwidth" type="text" name="expense-id"
|
class="tui-input underline fullwidth" type="text" name="expense-id"
|
||||||
value="{{ .expense.ExpID }}" id="expense-id"><br>
|
value="{{ .expense.ExpID }}" id="expense-id"><br>
|
||||||
</p>
|
</p>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="expense-desc">Description:</label>
|
<label for="expense-desc">Description:</label>
|
||||||
@@ -70,10 +72,17 @@
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
class="subbutton"
|
class="subbutton"
|
||||||
|
{{ if eq .method "put" }}
|
||||||
hx-put="/expenses/{{ .expense.ExpID }}"
|
hx-put="/expenses/{{ .expense.ExpID }}"
|
||||||
|
{{ end }}
|
||||||
|
{{ if eq .method "post" }}
|
||||||
|
hx-post="/expenses/new"
|
||||||
|
{{ end }}
|
||||||
hx-swap="none"
|
hx-swap="none"
|
||||||
type="submit"
|
type="submit"
|
||||||
id="expense-submit-button">UPDATE</button>
|
id="expense-submit-button">
|
||||||
|
{{- if eq .method "put" }}UPDATE{{- end }}
|
||||||
|
{{- if eq .method "post" }}CREATE{{- end }}</button>
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
<div>
|
|
||||||
<form id="expense-form" action="submit">
|
|
||||||
<fieldset id="form-box-boundaries">
|
|
||||||
<legend>EXPENSE FORM</legend>
|
|
||||||
<div class="form-container form-inline">
|
|
||||||
<div id="form-state" class="warning"></div><br>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<label for="expense-desc">Description:</label>
|
|
||||||
<input
|
|
||||||
class="tui-input underline fullwidth" type="text" name="expense-desc"
|
|
||||||
id="expense-desc"><br>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<label for="expense-date">Date:</label>
|
|
||||||
<input
|
|
||||||
class="tui-input underline fullwidth" type="text" name="expense-date"
|
|
||||||
id="expense-date"><br>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<label for="expense-value">Value:</label>
|
|
||||||
<input
|
|
||||||
class="tui-input underline fullwidth" type="text" name="expense-value"
|
|
||||||
id="expense-value"><br>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<label for="newexp-type-dropdown">Type:</label>
|
|
||||||
<select name="newexp-type-dropdown" id="newexp-type-dropdown">
|
|
||||||
{{ range .types }}
|
|
||||||
<option value="{{ .TypeID}}">{{ .TypeName }}</option>
|
|
||||||
{{ end}}
|
|
||||||
</select>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<label for="newexp-cat-dropdown">Category:</label>
|
|
||||||
<select name="newexp-cat-dropdown" id="newexp-cat-dropdown">
|
|
||||||
{{ range .categories }}
|
|
||||||
<option value="{{ .CategoryID}}">{{ .CategoryName }}</option>
|
|
||||||
{{ end}}
|
|
||||||
</select>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<label for="newexp-store-dropdown">Store:</label>
|
|
||||||
<select name="newexp-store-dropdown" id="newexp-store-dropdown">
|
|
||||||
{{ range .stores }}
|
|
||||||
<option value="{{ .StoreID}}">{{ .StoreName }}</option>
|
|
||||||
{{ end}}
|
|
||||||
</select>
|
|
||||||
</p>
|
|
||||||
<br><br>
|
|
||||||
|
|
||||||
<button
|
|
||||||
class="subbutton"
|
|
||||||
hx-post="/expenses/new"
|
|
||||||
hx-swap="none"
|
|
||||||
type="submit"
|
|
||||||
id="expense-submit-button">CREATE</button>
|
|
||||||
<br>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -99,6 +99,7 @@ func expensePage(c *gin.Context) {
|
|||||||
content := templating.HtmlTemplate(
|
content := templating.HtmlTemplate(
|
||||||
fp.Join(cfg.AssetsDir, "/htmx/expense.html"),
|
fp.Join(cfg.AssetsDir, "/htmx/expense.html"),
|
||||||
map[string]any{
|
map[string]any{
|
||||||
|
"method": "put",
|
||||||
"expense": expense,
|
"expense": expense,
|
||||||
"categories": categories,
|
"categories": categories,
|
||||||
"stores": stores,
|
"stores": stores,
|
||||||
@@ -140,7 +141,8 @@ func newExpensePage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
content := templating.HtmlTemplate(
|
content := templating.HtmlTemplate(
|
||||||
fp.Join(cfg.AssetsDir, "/htmx/expenseNew.html"), map[string]any{
|
fp.Join(cfg.AssetsDir, "/htmx/expense.html"), map[string]any{
|
||||||
|
"method": "post",
|
||||||
"expense": expenses.NewExpense(),
|
"expense": expenses.NewExpense(),
|
||||||
"categories": categories,
|
"categories": categories,
|
||||||
"stores": stores,
|
"stores": stores,
|
||||||
@@ -175,7 +177,8 @@ func createExpense(c *gin.Context) {
|
|||||||
func updateExpense(c *gin.Context) {
|
func updateExpense(c *gin.Context) {
|
||||||
expenseID, err := strconv.Atoi(c.Param("id"))
|
expenseID, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Redirect(404, "/404")
|
c.Header("HX-Redirect", "/404")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newExp, err := expenseFromForm(c)
|
newExp, err := expenseFromForm(c)
|
||||||
@@ -183,6 +186,7 @@ func updateExpense(c *gin.Context) {
|
|||||||
// TODO
|
// TODO
|
||||||
// Change this to something the user can see
|
// Change this to something the user can see
|
||||||
c.Header("HX-Redirect", "/500")
|
c.Header("HX-Redirect", "/500")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
newExp.ExpID = expenseID
|
newExp.ExpID = expenseID
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user