Commit 546d358b authored by Peter Achten's avatar Peter Achten
Browse files

revised module

parent 6fab2a6d
......@@ -5,6 +5,7 @@ definition module htmlFormData
import htmlDataDef
import StdMaybe, StdBool, htmlHandler
import GenEq
:: FormId d // properties one has to assign to any form
= { id :: !String // id *uniquely* identifying the form
......@@ -57,74 +58,75 @@ import StdMaybe, StdBool, htmlHandler
// **** easy creation of FormId's ****
// editable, string format
class (<@) infixl 4 att :: !(FormId d) !att -> FormId d
nFormId :: !String !d -> (FormId d) // page , editable, string format
sFormId :: !String !d -> (FormId d) // session , editable, string format
pFormId :: !String !d -> (FormId d) // persistent , editable, string format
rFormId :: !String !d -> (FormId d) // persistentRO , editable, string format
dbFormId :: !String !d -> (FormId d) // database , editable, string format
instance <@ String // formId <@ x = {formId & id = x}
instance <@ Lifespan // formId <@ x = {formId & lifespan = x}
instance <@ Mode // formId <@ x = {formId & mode = x}
instance <@ StorageFormat // formId <@ x = {formId & storage = x}
mkFormId :: !String !d -> FormId d // mkFormId str val = {id = str, ival = val} <@ Page <@ Edit <@ PlainString
// non-editable, string format
// editable, string format
tFormId :: !String !d -> FormId d // temp
nFormId :: !String !d -> FormId d // page
sFormId :: !String !d -> FormId d // session
pFormId :: !String !d -> FormId d // persistent
rFormId :: !String !d -> FormId d // persistent read only
dbFormId :: !String !d -> FormId d // database
ndFormId :: !String !d -> (FormId d) // page , displayed non-editable, string format
sdFormId :: !String !d -> (FormId d) // session , displayed non-editable, string format
pdFormId :: !String !d -> (FormId d) // persistent , displayed non-editable, string format
rdFormId :: !String !d -> (FormId d) // persistentRO , displayed non-editable, string format
dbdFormId :: !String !d -> (FormId d) // database , displayed non-editable, string format
// non-editable, string format
tdFormId :: !String !d -> FormId d // temp + display
ndFormId :: !String !d -> FormId d // page + display
sdFormId :: !String !d -> FormId d // session + display
pdFormId :: !String !d -> FormId d // persistent + display
rdFormId :: !String !d -> FormId d // persistent read only + display
dbdFormId :: !String !d -> FormId d // database + display
// noform, string format
xtFormId :: !String !d -> (FormId d) // temp , noform
xnFormId :: !String !d -> (FormId d) // page , noform, string format
xsFormId :: !String !d -> (FormId d) // session , noform, string format
xpFormId :: !String !d -> (FormId d) // persistent , noform, string format
xrFormId :: !String !d -> (FormId d) // persistentRO , noform, string format
xdbFormId :: !String !d -> (FormId d) // database , noform, string format
// temp forms
tFormId :: !String !d -> (FormId d) // temp , editable, string format
tdFormId :: !String !d -> (FormId d) // temp , displayed non-editable, string format
xtFormId :: !String !d -> FormId d // temp + no form
xnFormId :: !String !d -> FormId d // page + no form
xsFormId :: !String !d -> FormId d // session + no form
xpFormId :: !String !d -> FormId d // persistent + no form
xrFormId :: !String !d -> FormId d // persistent read only + no form
xdbFormId :: !String !d -> FormId d // database + no form
// editable, dynamic format also allows to store functions
nDFormId :: !String !d -> (FormId d) // page , editable, static dynamic format
sDFormId :: !String !d -> (FormId d) // session , editable, static dynamic format
pDFormId :: !String !d -> (FormId d) // persistent , editable, static dynamic format
rDFormId :: !String !d -> (FormId d) // persistentRO , editable, static dynamic format
dbDFormId :: !String !d -> (FormId d) // Database , editable, static dynamic format
nDFormId :: !String !d -> FormId d // page + static dynamic format
sDFormId :: !String !d -> FormId d // session + static dynamic format
pDFormId :: !String !d -> FormId d // persistent + static dynamic format
rDFormId :: !String !d -> FormId d // persistent read only + static dynamic format
dbDFormId :: !String !d -> FormId d // database + static dynamic format
// non-editable, dynamic format also allows to store functions
ndDFormId :: !String !d -> (FormId d) // page , displayed non-editable, static dynamic format
sdDFormId :: !String !d -> (FormId d) // session , displayed non-editable, static dynamic format
pdDFormId :: !String !d -> (FormId d) // persistent , displayed non-editable, static dynamic format
rdDFormId :: !String !d -> (FormId d) // persistentRO , displayed non-editable, static dynamic format
dbdDFormId :: !String !d -> (FormId d) // Database , displayed non-editable, static dynamic format
ndDFormId :: !String !d -> FormId d // page + static dynamic format + display
sdDFormId :: !String !d -> FormId d // session + static dynamic format + display
pdDFormId :: !String !d -> FormId d // persistent + static dynamic format + display
rdDFormId :: !String !d -> FormId d // persistent read only + static dynamic format + display
dbdDFormId :: !String !d -> FormId d // database + static dynamic format + display
// to create new FormId's ou of an existing one, handy for making unique identifiers
extidFormId :: !(FormId d) !String -> (FormId d) // make new id by adding sufix
subFormId :: !(FormId a) !String !d -> (FormId d) // make new id for a new type by adding suffix
subnFormId :: !(FormId a) !String !d -> (FormId d) // idem with lifespan Page
subsFormId :: !(FormId a) !String !d -> (FormId d) // idem with lifespan Session
subpFormId :: !(FormId a) !String !d -> (FormId d) // idem with lifespan Persitent
subtFormId :: !(FormId a) !String !d -> (FormId d) // idem with lifespan Temp
extidFormId :: !(FormId d) !String -> FormId d // make new id by adding sufix
subFormId :: !(FormId a) !String !d -> FormId d // make new id for a new type by adding suffix
subnFormId :: !(FormId a) !String !d -> FormId d // idem with lifespan Page
subsFormId :: !(FormId a) !String !d -> FormId d // idem with lifespan Session
subpFormId :: !(FormId a) !String !d -> FormId d // idem with lifespan Persitent
subtFormId :: !(FormId a) !String !d -> FormId d // idem with lifespan Temp
setFormId :: !(FormId d) !d -> (FormId d) // set new initial value in formid
reuseFormId :: !(FormId a) !d -> (FormId d) // reuse id for new type (only to be used in gform)
setFormId :: !(FormId d) !d -> FormId d // set new initial value in formid
reuseFormId :: !(FormId a) !d -> FormId d // reuse id for new type (only to be used in gform)
initID :: !(FormId d) -> InIDataId d // (Init,FormId a)
setID :: !(FormId d) !d -> InIDataId d // (Set,FormId a)
initID :: !(FormId d) -> InIDataId d // (Init,FormId a)
setID :: !(FormId d) !d -> InIDataId d // (Set,FormId a)
onMode :: !Mode a a a -> a // choose arg depending on Edit, Display, NoForm
onMode :: !Mode a a a -> a // choose arg depending on Edit, Display, NoForm
// manipulating initial values
toViewId :: !Init !d! (Maybe d) -> d // copy second on Set or if third is Nothing
toViewMap :: !(d -> v) !Init !d !(Maybe v) -> v // same, but convert to view domain
toViewId :: !Init !d! (Maybe d) -> d // copy second on Set or if third is Nothing
toViewMap :: !(d -> v) !Init !d !(Maybe v) -> v // same, but convert to view domain
instance toBool Init
instance < Lifespan
instance == Init, Mode, Lifespan
instance < Lifespan
derive gEq Init, Mode, Lifespan
......@@ -2,129 +2,89 @@ implementation module htmlFormData
import htmlDataDef, htmlSettings
import StdMaybe, StdBool, StdString, StdInt
import GenEq
// utility for creating FormId's
// editable, string format
nFormId :: !String !d -> (FormId d) // page formid
nFormId s d = {id = s, lifespan = Page, mode = Edit, storage = PlainString, ival = d}
sFormId :: !String !d -> (FormId d) // session formid
sFormId s d = {id = s, lifespan = Session, mode = Edit, storage = PlainString, ival = d}
pFormId :: !String !d -> (FormId d) // persistent formid
pFormId s d = {id = s, lifespan = Persistent, mode = Edit, storage = PlainString, ival = d}
rFormId :: !String !d -> (FormId d) // persistent formid
rFormId s d = {id = s, lifespan = PersistentRO, mode = Edit, storage = PlainString, ival = d}
dbFormId :: !String !d -> (FormId d) // database , editable, string format
dbFormId s d = {id = s, lifespan = Database, mode = Edit, storage = PlainString, ival = d}
ndFormId :: !String !d -> (FormId d) // page formid
ndFormId s d = {id = s, lifespan = Page, mode = Display, storage = PlainString, ival = d}
sdFormId :: !String !d -> (FormId d) // session formid
sdFormId s d = {id = s, lifespan = Session, mode = Display, storage = PlainString, ival = d}
pdFormId :: !String !d -> (FormId d) // persistent formid
pdFormId s d = {id = s, lifespan = Persistent, mode = Display, storage = PlainString, ival = d}
rdFormId :: !String !d -> (FormId d) // persistent formid
rdFormId s d = {id = s, lifespan = PersistentRO, mode = Display, storage = PlainString, ival = d}
dbdFormId :: !String !d -> (FormId d) // persistent formid
dbdFormId s d = {id = s, lifespan = Database, mode = Display, storage = PlainString, ival = d}
xtFormId :: !String !d -> (FormId d) // persistent formid
xtFormId s d = {id = s, lifespan = Temp, mode = NoForm, storage = PlainString, ival = d}
xnFormId :: !String !d -> (FormId d) // page formid
xnFormId s d = {id = s, lifespan = Page, mode = NoForm, storage = PlainString, ival = d}
class (<@) infixl 4 att :: !(FormId d) !att -> FormId d
xsFormId :: !String !d -> (FormId d) // session formid
xsFormId s d = {id = s, lifespan = Session, mode = NoForm, storage = PlainString, ival = d}
instance <@ String where <@ formId a = {formId & id = a}
instance <@ Lifespan where <@ formId a = {formId & lifespan = a}
instance <@ Mode where <@ formId a = {formId & mode = a}
instance <@ StorageFormat where <@ formId a = {formId & storage = a}
xpFormId :: !String !d -> (FormId d) // persistent formid
xpFormId s d = {id = s, lifespan = Persistent, mode = NoForm, storage = PlainString, ival = d}
mkFormId :: !String !d -> FormId d // Default FormId with given id and ival.
mkFormId s d = {id = s, lifespan = Page, mode = Edit, storage = PlainString, ival = d}
xrFormId :: !String !d -> (FormId d) // persistent formid
xrFormId s d = {id = s, lifespan = PersistentRO, mode = NoForm, storage = PlainString, ival = d}
xdbFormId :: !String !d -> (FormId d) // persistent formid
xdbFormId s d = {id = s, lifespan = Database, mode = NoForm, storage = PlainString, ival = d}
tFormId :: !String !d -> (FormId d) // persistent formid
tFormId s d = {id = s, lifespan = Temp, mode = Edit, storage = PlainString, ival = d}
tdFormId :: !String !d -> (FormId d) // persistent formid
tdFormId s d = {id = s, lifespan = Temp, mode = Display, storage = PlainString, ival = d}
nDFormId :: !String !d -> (FormId d) // page formid
nDFormId s d = {id = s, lifespan = Page, mode = Edit, storage = StaticDynamic, ival = d}
sDFormId :: !String !d -> (FormId d) // session formid
sDFormId s d = {id = s, lifespan = Session, mode = Edit, storage = StaticDynamic, ival = d}
pDFormId :: !String !d -> (FormId d) // persistent formid
pDFormId s d = {id = s, lifespan = Persistent, mode = Edit, storage = StaticDynamic, ival = d}
rDFormId :: !String !d -> (FormId d) // persistent formid
rDFormId s d = {id = s, lifespan = PersistentRO, mode = Edit, storage = StaticDynamic, ival = d}
dbDFormId :: !String !d -> (FormId d) // persistent formid
dbDFormId s d = {id = s, lifespan = Database, mode = Edit, storage = StaticDynamic, ival = d}
ndDFormId :: !String !d -> (FormId d) // page formid
ndDFormId s d = {id = s, lifespan = Page, mode = Display, storage = StaticDynamic, ival = d}
sdDFormId :: !String !d -> (FormId d) // session formid
sdDFormId s d = {id = s, lifespan = Session, mode = Display, storage = StaticDynamic, ival = d}
pdDFormId :: !String !d -> (FormId d) // persistent formid
pdDFormId s d = {id = s, lifespan = Persistent, mode = Display, storage = StaticDynamic, ival = d}
rdDFormId :: !String !d -> (FormId d) // persistent formid
rdDFormId s d = {id = s, lifespan = PersistentRO, mode = Display, storage = StaticDynamic, ival = d}
// editable, string format
dbdDFormId :: !String !d -> (FormId d) // persistent formid
dbdDFormId s d = {id = s, lifespan = Database, mode = Display, storage = StaticDynamic, ival = d}
tFormId :: !String !d -> FormId d; tFormId s d = mkFormId s d <@ Temp
nFormId :: !String !d -> FormId d; nFormId s d = mkFormId s d <@ Page
sFormId :: !String !d -> FormId d; sFormId s d = mkFormId s d <@ Session
pFormId :: !String !d -> FormId d; pFormId s d = mkFormId s d <@ Persistent
rFormId :: !String !d -> FormId d; rFormId s d = mkFormId s d <@ PersistentRO
dbFormId :: !String !d -> FormId d; dbFormId s d = mkFormId s d <@ Database
tdFormId :: !String !d -> FormId d; tdFormId s d = tFormId s d <@ Display
ndFormId :: !String !d -> FormId d; ndFormId s d = nFormId s d <@ Display
sdFormId :: !String !d -> FormId d; sdFormId s d = sFormId s d <@ Display
pdFormId :: !String !d -> FormId d; pdFormId s d = pFormId s d <@ Display
rdFormId :: !String !d -> FormId d; rdFormId s d = rFormId s d <@ Display
dbdFormId :: !String !d -> FormId d; dbdFormId s d = dbFormId s d <@ Display
xtFormId :: !String !d -> FormId d; xtFormId s d = tFormId s d <@ NoForm
xnFormId :: !String !d -> FormId d; xnFormId s d = nFormId s d <@ NoForm
xsFormId :: !String !d -> FormId d; xsFormId s d = sFormId s d <@ NoForm
xpFormId :: !String !d -> FormId d; xpFormId s d = pFormId s d <@ NoForm
xrFormId :: !String !d -> FormId d; xrFormId s d = rFormId s d <@ NoForm
xdbFormId :: !String !d -> FormId d; xdbFormId s d = dbFormId s d <@ NoForm
nDFormId :: !String !d -> FormId d; nDFormId s d = nFormId s d <@ StaticDynamic
sDFormId :: !String !d -> FormId d; sDFormId s d = sFormId s d <@ StaticDynamic
pDFormId :: !String !d -> FormId d; pDFormId s d = pFormId s d <@ StaticDynamic
rDFormId :: !String !d -> FormId d; rDFormId s d = rFormId s d <@ StaticDynamic
dbDFormId :: !String !d -> FormId d; dbDFormId s d = dbFormId s d <@ StaticDynamic
ndDFormId :: !String !d -> FormId d; ndDFormId s d = nDFormId s d <@ Display
sdDFormId :: !String !d -> FormId d; sdDFormId s d = sDFormId s d <@ Display
pdDFormId :: !String !d -> FormId d; pdDFormId s d = pDFormId s d <@ Display
rdDFormId :: !String !d -> FormId d; rdDFormId s d = rDFormId s d <@ Display
dbdDFormId :: !String !d -> FormId d; dbdDFormId s d = dbDFormId s d <@ Display
// create id's
(++/) infixr 5
(++/) infixr 5
(++/) s1 s2 = s1 +++ iDataIdSeparator +++ s2
extidFormId :: !(FormId d) !String -> (FormId d)
extidFormId formid s = {formid & id = formid.id ++/ s}
extidFormId :: !(FormId d) !String -> FormId d
extidFormId formid s = formid <@ formid.id ++/ s
subFormId :: !(FormId a) !String !d -> (FormId d) // make new formid of new type copying other old settinf
subFormId formid s d = {formid & id = formid.id ++/ s, ival = d}
subFormId :: !(FormId a) !String !d -> FormId d // make new formid of new type copying other old settinf
subFormId formid s d = reuseFormId (extidFormId formid s) d
subnFormId :: !(FormId a) !String !d -> (FormId d) // make new formid of new type copying other old settinf
subnFormId formid s d = {formid & id = formid.id ++/ s, ival = d, lifespan = Page}
subnFormId :: !(FormId a) !String !d -> FormId d // make new formid of new type copying other old settinf
subnFormId formid s d = subFormId formid s d <@ Page
subsFormId :: !(FormId a) !String !d -> (FormId d) // make new formid of new type copying other old settinf
subsFormId formid s d = {formid & id = formid.id ++/ s, ival = d, lifespan = Session}
subsFormId :: !(FormId a) !String !d -> FormId d // make new formid of new type copying other old settinf
subsFormId formid s d = subFormId formid s d <@ Session
subpFormId :: !(FormId a) !String !d -> (FormId d) // make new formid of new type copying other old settinf
subpFormId formid s d = {formid & id = formid.id ++/ s, ival = d, lifespan = Persistent}
subpFormId :: !(FormId a) !String !d -> FormId d // make new formid of new type copying other old settinf
subpFormId formid s d = subFormId formid s d <@ Persistent
subtFormId :: !(FormId a) !String !d -> (FormId d) // make new formid of new type copying other old settinf
subtFormId formid s d = {formid & id = formid.id ++/ s, ival = d, lifespan = Temp}
subtFormId :: !(FormId a) !String !d -> FormId d // make new formid of new type copying other old settinf
subtFormId formid s d = subFormId formid s d <@ Temp
setFormId :: !(FormId d) !d -> (FormId d) // set new initial value in formid
setFormId :: !(FormId d) !d -> FormId d // set new initial value in formid
setFormId formid d = {formid & ival = d}
reuseFormId :: !(FormId d) !v -> (FormId v)
reuseFormId :: !(FormId d) !v -> FormId v
reuseFormId formid v = {formid & ival = v}
initID :: !(FormId d) -> InIDataId d // (Init,FormId a)
initID :: !(FormId d) -> InIDataId d // (Init,FormId a)
initID formid = (Init,formid)
setID :: !(FormId d) !d -> InIDataId d // (Set,FormId a)
setID :: !(FormId d) !d -> InIDataId d // (Set,FormId a)
setID formid na = (Set,setFormId formid na)
onMode :: !Mode a a a -> a
......@@ -140,44 +100,18 @@ toViewId _ d _ = d
toViewMap :: !(d -> v) !Init !d !(Maybe v) -> v
toViewMap f init d mv = toViewId init (f d) mv
instance toBool Init
where
toBool Set = True
toBool _ = False
instance == Mode
where
(==) Display Display = True
(==) Edit Edit = True
(==) NoForm NoForm = True
(==) _ _ = False
instance == Init
where
(==) Init Init = True
(==) Set Set = True
(==) Const Const = True
(==) _ _ = False
instance == Lifespan
where
(==) Database Database = True
(==) Persistent Persistent = True
(==) PersistentRO PersistentRO = True
(==) Session Session = True
(==) Page Page = True
(==) Temp Temp = True
(==) _ _ = False
instance < Lifespan
where
(<) l1 l2 = toInt l1 < toInt l2
instance toInt Lifespan
where
toInt Temp = 0
toInt Page = 1
toInt Session = 2
toInt PersistentRO = 3
toInt Persistent = 4
toInt Database = 5
derive gEq Mode, Init, Lifespan
instance == Mode where == m1 m2 = m1 === m2
instance == Init where == i1 i2 = i1 === i2
instance == Lifespan where == l1 l2 = l1 === l2
instance < Lifespan where (<) l1 l2 = toInt l1 < toInt l2
instance toBool Init where toBool Set = True
toBool _ = False
instance toInt Lifespan where toInt Temp = 0
toInt Page = 1
toInt Session = 2
toInt PersistentRO = 3
toInt Persistent = 4
toInt Database = 5
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment