comparison tests/crud.ur @ 362:24a31b35e08f

Reusable column handlers for Crud
author Adam Chlipala <adamc@hcoop.net>
date Tue, 14 Oct 2008 17:18:59 -0400
parents 260b680a6a04
children 28d3d7210687
comparison
equal deleted inserted replaced
361:260b680a6a04 362:24a31b35e08f
5 WidgetPopulated : nm :: Name -> t_formT.1 -> xml form [] [nm = t_formT.2], 5 WidgetPopulated : nm :: Name -> t_formT.1 -> xml form [] [nm = t_formT.2],
6 Parse : t_formT.2 -> t_formT.1, 6 Parse : t_formT.2 -> t_formT.1,
7 Inject : sql_injectable t_formT.1 7 Inject : sql_injectable t_formT.1
8 } 8 }
9 con colsMeta = fn cols :: {(Type * Type)} => $(Top.mapT2T colMeta cols) 9 con colsMeta = fn cols :: {(Type * Type)} => $(Top.mapT2T colMeta cols)
10
11 fun default (t ::: Type) (sh : show t) (rd : read t) (inj : sql_injectable t)
12 name : colMeta (t, string) =
13 {Nam = name,
14 Show = txt _,
15 Widget = fn nm :: Name => <xml><textbox{nm}/></xml>,
16 WidgetPopulated = fn (nm :: Name) n =>
17 <xml><textbox{nm} value={show _ n}/></xml>,
18 Parse = readError _,
19 Inject = _}
20
21 val int = default _ _ _
22 val float = default _ _ _
23 val string = default _ _ _
24
25 fun bool name = {Nam = name,
26 Show = txt _,
27 Widget = fn nm :: Name => <xml><checkbox{nm}/></xml>,
28 WidgetPopulated = fn (nm :: Name) b =>
29 <xml><checkbox{nm} checked={b}/></xml>,
30 Parse = fn x => x,
31 Inject = _}
10 32
11 functor Make(M : sig 33 functor Make(M : sig
12 con cols :: {(Type * Type)} 34 con cols :: {(Type * Type)}
13 constraint [Id] ~ cols 35 constraint [Id] ~ cols
14 val tab : sql_table ([Id = int] ++ mapT2T fstTT cols) 36 val tab : sql_table ([Id = int] ++ mapT2T fstTT cols)