module FlexTask.Form.Helpers (
anonymousRadioButtons,
labeledRadioButtons,
labeledCheckboxes,
) where
import Yesod (FieldSettings, SomeMessage)
import FlexTask.Form.Core (
Alignment,
ChoiceShape(..),
SimpleFormPiece,
multipleChoice,
singleChoice,
)
import FlexTask.Form.Util (showToUniversalLabel, universalLabel)
import FlexTask.InputTypes (
MultipleChoiceSelection,
SingleChoiceSelection,
)
import FlexTask.Form.Types (FlexForm)
labeledCheckboxes
:: Alignment
-> FieldSettings FlexForm
-> [String]
-> SimpleFormPiece t MultipleChoiceSelection
labeledCheckboxes :: forall t.
Alignment
-> FieldSettings FlexForm
-> [String]
-> SimpleFormPiece t MultipleChoiceSelection
labeledCheckboxes Alignment
alignment FieldSettings FlexForm
fSettings = ChoiceShape
-> FieldSettings FlexForm
-> [SomeMessage FlexForm]
-> SimpleFormPiece t MultipleChoiceSelection
forall t.
ChoiceShape
-> FieldSettings FlexForm
-> [SomeMessage FlexForm]
-> SimpleFormPiece t MultipleChoiceSelection
multipleChoice
(Alignment -> ChoiceShape
Buttons Alignment
alignment)
FieldSettings FlexForm
fSettings
([SomeMessage FlexForm]
-> SimpleFormPiece t MultipleChoiceSelection)
-> ([String] -> [SomeMessage FlexForm])
-> [String]
-> SimpleFormPiece t MultipleChoiceSelection
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Integer -> String -> SomeMessage FlexForm)
-> [Integer] -> [String] -> [SomeMessage FlexForm]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Integer
a String
b -> String -> SomeMessage FlexForm
universalLabel (String -> SomeMessage FlexForm) -> String -> SomeMessage FlexForm
forall a b. (a -> b) -> a -> b
$ Integer -> String
forall a. Show a => a -> String
show Integer
a String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
". " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
b) [Integer
1 :: Integer ..]
anonymousRadioButtons
:: Integral i
=> Alignment
-> FieldSettings FlexForm
-> i
-> SimpleFormPiece t SingleChoiceSelection
anonymousRadioButtons :: forall i t.
Integral i =>
Alignment
-> FieldSettings FlexForm
-> i
-> SimpleFormPiece t SingleChoiceSelection
anonymousRadioButtons Alignment
alignment FieldSettings FlexForm
fSettings i
amount = ChoiceShape
-> FieldSettings FlexForm
-> [SomeMessage FlexForm]
-> SimpleFormPiece t SingleChoiceSelection
forall t.
ChoiceShape
-> FieldSettings FlexForm
-> [SomeMessage FlexForm]
-> SimpleFormPiece t SingleChoiceSelection
singleChoice
(Alignment -> ChoiceShape
Buttons Alignment
alignment)
FieldSettings FlexForm
fSettings
([SomeMessage FlexForm] -> SimpleFormPiece t SingleChoiceSelection)
-> [SomeMessage FlexForm]
-> SimpleFormPiece t SingleChoiceSelection
forall a b. (a -> b) -> a -> b
$ (Integer -> SomeMessage FlexForm)
-> [Integer] -> [SomeMessage FlexForm]
forall a b. (a -> b) -> [a] -> [b]
map Integer -> SomeMessage FlexForm
forall a. Show a => a -> SomeMessage FlexForm
showToUniversalLabel [Integer
1.. i -> Integer
forall a. Integral a => a -> Integer
toInteger i
amount]
labeledRadioButtons
:: Alignment
-> FieldSettings FlexForm
-> [SomeMessage FlexForm]
-> SimpleFormPiece t SingleChoiceSelection
labeledRadioButtons :: forall t.
Alignment
-> FieldSettings FlexForm
-> [SomeMessage FlexForm]
-> SimpleFormPiece t SingleChoiceSelection
labeledRadioButtons Alignment
alignment = ChoiceShape
-> FieldSettings FlexForm
-> [SomeMessage FlexForm]
-> SimpleFormPiece t SingleChoiceSelection
forall t.
ChoiceShape
-> FieldSettings FlexForm
-> [SomeMessage FlexForm]
-> SimpleFormPiece t SingleChoiceSelection
singleChoice (Alignment -> ChoiceShape
Buttons Alignment
alignment)