forked from janek/compareware
50 lines
1.5 KiB
Haskell
50 lines
1.5 KiB
Haskell
module Web.View.Items.New where
|
|
|
|
import Web.View.Prelude
|
|
import Text.Blaze.Html.Renderer.Text
|
|
|
|
data NewView = NewView { item :: Include "tags" Item }
|
|
|
|
instance View NewView where
|
|
html NewView { .. } = [hsx|
|
|
{breadcrumb}
|
|
<h1>New Item</h1>
|
|
|
|
{renderForm item}
|
|
|]
|
|
where
|
|
breadcrumb = renderBreadcrumb
|
|
[ breadcrumbLink "Items" ItemsAction
|
|
, breadcrumbText "New Item"
|
|
]
|
|
|
|
renderForm :: Include "tags" Item -> Html
|
|
renderForm item = formFor item [hsx|
|
|
{textField #wikidataId}
|
|
{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>
|
|
|
|
{submitButton}
|
|
|]
|
|
|
|
prototypeFor :: _ => _ -> _ -> Text
|
|
prototypeFor field record =
|
|
cs $ renderHtml prototype
|
|
where
|
|
parentFormContext = ?formContext
|
|
prototype :: Html
|
|
prototype = let ?formContext = parentFormContext { model = parentFormContext.model |> set field [record] } in nestedFormFor field renderTagForm
|
|
|
|
renderTagForm :: (?formContext :: FormContext Tag) => Html
|
|
renderTagForm = [hsx|
|
|
{(textField #name) { disableLabel = True, placeholder = "Tag name" } }
|
|
{(textField #value) { disableLabel = True, placeholder = "Tag value" } }
|
|
|]
|