|
definition: |
newController :: ControllerGenerator
newController erdname (Entity entityName attrList) relationships allEntities =
controllerFunction
("Shows a form to create a new " ++ entityName ++ " entity.")
entityName "new" 0
controllerType -- function type
[simpleRule [] $ -- no arguments
applyF (pre "$")
[applyF checkAuthorizationFunc
[applyF (enauthModName, lowerFirst entityName ++ "OperationAllowed")
[constF (authorizationModule,"NewEntity")]],
CLambda [CPVar infovar] $
doExpr (
map
(\ ((ename,erel), num) ->
CSPat (CPVar (num,"all" ++ erel ++ ename ++ "s"))
(applyF (model erdname,"runQ")
[constF (model erdname,"queryAll" ++ ename ++ "s")])
)
(zip (map (\n -> (n,"")) manyToOneEntities ++ manyToManyEntities)
[2..]) ++
(if hasDateAttribute attrList
then [CSPat (CPVar ctimevar) (constF (timeModule,"getClockTime"))]
else []) ++
(if null manyToOneEntities
then setParCallAndReturn
else [CSExpr $ ifThenElseExp
(foldr1 (\e1 e2 -> applyF (pre "||") [e1,e2])
(map (\ (name, varId) -> applyF (pre "null")
[CVar (varId, "all" ++ name ++ "s")])
(zip manyToOneEntities [2..])))
(applyF (pre "return")
[ list2ac [applyF (html "h2")
[list2ac [applyF (html "htxt")
[string2ac missingError]]]]])
(doExpr setParCallAndReturn)]
))]]
where
manyToManyEntities = manyToMany allEntities (Entity entityName attrList)
manyToOneEntities = manyToOne (Entity entityName attrList) relationships
missingError = "Some related entities are required but not yet undefined"
infovar = (0,"sinfo")
ctimevar = (1,"ctime")
setParCall =
applyF (wuiModule "setParWuiStore")
[constF (controllerStoreName entityName "new"),
tupleExpr
([CVar infovar] ++
map (\ ((ename,erel), i) -> CVar (i, "all" ++ erel ++ ename ++ "s"))
(zip (map (\n -> (n,"")) manyToOneEntities ++ manyToManyEntities)
[2 ..])),
tupleExpr $
attrDefaultValues (CVar ctimevar) attrList ++
map (\ (name, varId) -> applyF (pre "head")
[CVar (varId, "all" ++ name ++ "s")])
(zip manyToOneEntities [2..]) ++
map (\_ -> list2ac [])
(zip manyToManyEntities [2..])
]
setParCallAndReturn =
[CSExpr setParCall,
CSExpr $ applyF (pre "return")
[list2ac [applyF (html "formElem")
[constF (controllerFormName entityName "new")]]]]
|
|
demand: |
argument 2 |
|
deterministic: |
deterministic operation |
|
documentation: |
--------------------------------------------------------------------------- generates a controller to show a form to create a new entity the input is then passed to the create controller only has to call the blank entry form and pass the create controller |
|
failfree: |
<FAILING> |
|
indeterministic: |
referentially transparent operation |
|
infix: |
no fixity defined |
|
iotype: |
{(_,{Entity},_,_) |-> _}
|
|
name: |
newController |
|
precedence: |
no precedence defined |
|
result-values: |
_ |
|
signature: |
String -> Database.ERD.Entity -> [Database.ERD.Relationship] -> [Database.ERD.Entity] -> AbstractCurry.Types.CFuncDecl |
|
solution-complete: |
operation might suspend on free variables |
|
terminating: |
possibly non-terminating |
|
totally-defined: |
possibly non-reducible on same data term |