1
0
Fork 0
compareware/Web/View/Tasks/New.hs

49 lines
1.4 KiB
Haskell
Raw Normal View History

2023-04-16 10:33:20 +00:00
module Web.View.Tasks.New where
2024-04-06 15:47:37 +00:00
2023-04-16 10:33:20 +00:00
import Web.View.Prelude
2023-04-16 13:54:20 +00:00
import Text.Blaze.Html.Renderer.Text
2023-04-16 10:33:20 +00:00
2023-04-16 13:54:20 +00:00
data NewView = NewView { task :: Include "tags" Task }
2023-04-16 10:33:20 +00:00
instance View NewView where
html NewView { .. } = [hsx|
{breadcrumb}
<h1>New Task</h1>
2023-04-16 13:54:20 +00:00
2023-04-16 10:33:20 +00:00
{renderForm task}
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbLink "Tasks" TasksAction
, breadcrumbText "New Task"
]
2024-04-06 15:47:37 +00:00
2023-04-16 13:54:20 +00:00
renderForm :: Include "tags" Task -> Html
2023-04-16 10:33:20 +00:00
renderForm task = formFor task [hsx|
2023-04-16 13:54:20 +00:00
{textField #description}
<fieldset>
<legend>Tags</legend>
{nestedFormFor #tags renderTagForm}
</fieldset>
<button type="button" class="btn btn-light" data-prototype={prototypeFor #tags (newRecord @Tag)} onclick="this.insertAdjacentHTML('beforebegin', this.dataset.prototype)">Add Tag</button>
2023-04-16 10:33:20 +00:00
{submitButton}
2023-04-16 13:54:20 +00:00
|]
prototypeFor :: _ => _ -> _ -> Text
prototypeFor field record =
cs $ renderHtml prototype
where
parentFormContext = ?formContext
prototype :: Html
2023-04-17 19:06:26 +00:00
prototype = let ?formContext = parentFormContext { model = parentFormContext.model |> set field [record] } in nestedFormFor field renderTagForm
2023-04-16 10:33:20 +00:00
2023-04-16 13:54:20 +00:00
renderTagForm :: (?formContext :: FormContext Tag) => Html
renderTagForm = [hsx|
{(textField #name) { disableLabel = True, placeholder = "Tag name" } }
2024-04-06 15:47:37 +00:00
{(textField #value) { disableLabel = True, placeholder = "Tag value" } }
2023-04-17 19:06:26 +00:00
|]