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

50 lines
1.5 KiB
Haskell
Raw Normal View History

2024-04-11 16:25:09 +00:00
module Web.View.Items.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
2024-04-11 16:25:09 +00:00
data NewView = NewView { item :: Include "tags" Item }
2023-04-16 10:33:20 +00:00
instance View NewView where
html NewView { .. } = [hsx|
{breadcrumb}
2024-04-11 16:25:09 +00:00
<h1>New Item</h1>
2023-04-16 13:54:20 +00:00
2024-04-11 16:25:09 +00:00
{renderForm item}
2023-04-16 10:33:20 +00:00
|]
where
breadcrumb = renderBreadcrumb
2024-04-11 16:25:09 +00:00
[ breadcrumbLink "Items" ItemsAction
, breadcrumbText "New Item"
2023-04-16 10:33:20 +00:00
]
2024-04-06 15:47:37 +00:00
2024-04-11 16:25:09 +00:00
renderForm :: Include "tags" Item -> Html
renderForm item = formFor item [hsx|
{textField #wikidataId}
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
|]