definition:
|
listView :: ViewGenerator
listView erdname (Entity entityName attrlist) _ _ =
viewFunction
("Supplies a list view for a given list of "++entityName++" entities.\n"++
"Shows also show/edit/delete buttons if the user is logged in.\n"++
"The arguments are the session info and the list of "++entityName++
" entities.\n")
entityName "list" 1
-- function type
(userSessionInfoType ~> listType (baseType (model erdname,entityName))
~> viewBlockType)
[CRule
[CPVar infovar, CPVar entsvar]
(CSimpleRhs
(applyF (pre ":") [
applyF (html "h1")
[list2ac [applyF (html "htxt")
[string2ac $ entityName ++ " list"]]],
list2ac [
applyF (spiceyModule, "spTable") [
applyF (pre "++") [
list2ac [
applyF (pre "take") [
CLit (CIntc (length attrlist)),
constF (entitiesToHtmlModule erdname,
lowerFirst entityName ++ "LabelList")
]
],
applyF (pre "map") [
constF (viewModuleName entityName,"list" ++ entityName),
applyF (listModule,"sortBy") [
constF (viewModuleName entityName,"leq" ++ entityName),
CVar entsvar
]
]
]
]
]
]
)
[CLocalFunc (stFunc
(viewModuleName entityName, "list"++entityName) 2 Private
(ctvar entityName ~> listType viewBlockType)
[simpleRule [CPVar envar]
(applyF (pre "++") [
applyF (entitiesToHtmlModule erdname,
lowerFirst entityName++"ToListView")
[cvar $ lowerFirst entityName],
ifThenElseExp
(applyF (pre "==")
[applyF (sessionInfoModule,"userLoginOfSession")
[CVar infovar],
constF (pre "Nothing")])
(list2ac [])
(list2ac
[list2ac
[applyF hrefSmallButtonName
[applyF (spiceyModule,"showRoute") [CVar envar],
list2ac [applyF (html "htxt") [string2ac "Show"]]]],
list2ac
[applyF hrefSmallButtonName
[applyF (spiceyModule,"editRoute") [CVar envar],
list2ac [applyF (html "htxt") [string2ac "Edit"]]]],
list2ac
[applyF hrefSmallButtonName
[applyF (spiceyModule,"deleteRoute") [CVar envar],
list2ac [applyF (html "htxt") [string2ac "Delete"]]]]])
]
)])
])
]
where
infovar = (0, "sinfo")
entsvar = (1, lowerFirst entityName ++ "s")
envar = (2, lowerFirst entityName)
|