comparison tests/crud.ur @ 341:389399d65331

Crud update form
author Adam Chlipala <adamc@hcoop.net>
date Sun, 14 Sep 2008 19:03:55 -0400
parents 075b36dbb1a4
children f55034419a07
comparison
equal deleted inserted replaced
340:5ccb1c6412e4 341:389399d65331
1 con colMeta = fn t_formT :: (Type * Type) => { 1 con colMeta = fn t_formT :: (Type * Type) => {
2 Nam : string, 2 Nam : string,
3 Show : t_formT.1 -> xbody, 3 Show : t_formT.1 -> xbody,
4 Widget : nm :: Name -> xml form [] [nm = t_formT.2], 4 Widget : nm :: Name -> xml form [] [nm = t_formT.2],
5 WidgetPopulated : nm :: Name -> t_formT.1 -> xml form [] [nm = t_formT.2],
5 Parse : t_formT.2 -> t_formT.1, 6 Parse : t_formT.2 -> t_formT.1,
6 Inject : sql_injectable t_formT.1 7 Inject : sql_injectable t_formT.1
7 } 8 }
8 con colsMeta = fn cols :: {(Type * Type)} => $(Top.mapT2T colMeta cols) 9 con colsMeta = fn cols :: {(Type * Type)} => $(Top.mapT2T colMeta cols)
9 10
34 with #Id = (SQL {id}))); 35 with #Id = (SQL {id})));
35 return <html><body> 36 return <html><body>
36 Inserted with ID {txt _ id}. 37 Inserted with ID {txt _ id}.
37 </body></html> 38 </body></html>
38 39
40 fun save (id : int) _ =
41 return <html><body>
42 Under Construction
43 </body></html>
44
45 fun update (id : int) =
46 fso <- oneOrNoRows (SELECT tab.{{mapT2T fstTT M.cols}} FROM tab WHERE tab.Id = {id});
47 case fso : (Basis.option {Tab : $(mapT2T fstTT M.cols)}) of
48 None => return <html><body>Not found!</body></html>
49 | Some fs => return <html><body><lform>
50 {foldT2R2 [fstTT] [colMeta] [fn cols :: {(Type * Type)} => xml form [] (mapT2T sndTT cols)]
51 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) =>
52 [[nm] ~ rest] =>
53 fn (v : t.1) (col : colMeta t) (acc : xml form [] (mapT2T sndTT rest)) => <lform>
54 <li> {cdata col.Nam}: {col.WidgetPopulated [nm] v}</li>
55 {useMore acc}
56 </lform>)
57 <lform></lform>
58 [M.cols] fs.Tab M.cols}
59
60 <submit action={save id}/>
61 </lform></body></html>
62
39 fun delete (id : int) = 63 fun delete (id : int) =
40 () <- dml (DELETE FROM tab WHERE Id = {id}); 64 () <- dml (DELETE FROM tab WHERE Id = {id});
41 return <html><body> 65 return <html><body>
42 The deed is done. 66 The deed is done.
43 </body></html> 67 </body></html>
58 [[nm] ~ rest] => 82 [[nm] ~ rest] =>
59 fn v col => <tr> 83 fn v col => <tr>
60 <td>{col.Show v}</td> 84 <td>{col.Show v}</td>
61 </tr>) 85 </tr>)
62 [M.cols] (fs.T -- #Id) M.cols} 86 [M.cols] (fs.T -- #Id) M.cols}
63 <td><a link={confirm fs.T.Id}>[Delete]</a></td> 87 <td><a link={update fs.T.Id}>[Update]</a> <a link={confirm fs.T.Id}>[Delete]</a></td>
64 </tr> 88 </tr>
65 </body>); 89 </body>);
66 return <html><head> 90 return <html><head>
67 <title>{cdata M.title}</title> 91 <title>{cdata M.title}</title>
68 92