-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForms.hs
More file actions
41 lines (33 loc) · 1.25 KB
/
Forms.hs
File metadata and controls
41 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Forms where
import Prelude hiding (writeFile, readFile, head, tail, init, last)
import Yesod hiding (Route(..))
import Foundation
import Data.Monoid (Monoid (mappend, mempty, mconcat), (<>))
import Control.Applicative ((<$>), (<*>), pure)
import Control.Arrow ((&&&))
import Data.Text (Text)
import qualified Data.Text as T
-- Enum系の型のドロップダウンのための関数
enumFieldList = selectFieldList enumPairs
enumPairs = map (T.pack . show &&& id ) $ [minBound..maxBound]
guestForm :: Form Guest
guestForm = guestForm' Nothing
guestForm' :: Maybe Guest -> Form Guest
guestForm' mguest = renderDivs $ Guest
<$> areq textField "Name" (guestName <$> mguest)
<*> areq intField "Age" (guestAge <$> mguest)
<*> areq boolField "Attend" (guestAttend <$> mguest)
<*> areq enumFieldList "Blood" (guestBlood <$> mguest)
data ItemForm = ItemForm
{ itemFormName :: Text
, itemFormPrice :: Int
, itemFormAvailable :: Bool
, itemFormMemo :: Maybe Text
}
deriving Show
itemForm :: Form ItemForm
itemForm = renderBootstrap $ ItemForm
<$> areq textField "Name" Nothing
<*> areq intField "Price" Nothing
<*> areq boolField "Available" Nothing
<*> aopt textField "Memo" Nothing