adamc@993
|
1 open Versioned.Make(struct
|
adamc@993
|
2 con key = [Id = int]
|
adamc@993
|
3 con data = [Nam = string, ShoeSize = int]
|
adamc@993
|
4
|
adamc@993
|
5 val key = {Id = _}
|
adamc@993
|
6 val data = {Nam = {Inj = _,
|
adamc@993
|
7 Eq = _},
|
adamc@993
|
8 ShoeSize = {Inj = _,
|
adamc@993
|
9 Eq = _}}
|
adamc@993
|
10 end)
|
adamc@993
|
11
|
adamc@993
|
12 fun expandKey k =
|
adamc@993
|
13 name <- source "";
|
adamc@993
|
14 shoeSize <- source "";
|
adamc@993
|
15 return {Key = k, Nam = name, ShoeSize = shoeSize}
|
adamc@993
|
16
|
adamc@993
|
17 fun main () =
|
adamc@993
|
18 ks0 <- keys;
|
adamc@993
|
19 ks0 <- List.mapM (fn r => expandKey r.Id) ks0;
|
adamc@993
|
20 ks <- source ks0;
|
adamc@993
|
21
|
adamc@993
|
22 id <- source "";
|
adamc@993
|
23 name <- source "";
|
adamc@993
|
24 shoeSize <- source "";
|
adamc@993
|
25
|
adamc@993
|
26 return <xml><body>
|
adamc@993
|
27 <dyn signal={ks <- signal ks;
|
adamc@993
|
28 return (List.mapX (fn kr => <xml><div>
|
adamc@993
|
29 {[kr.Key]}:
|
adamc@993
|
30 <ctextbox source={kr.Nam}/>
|
adamc@993
|
31 <ctextbox size={5} source={kr.ShoeSize}/>
|
adamc@993
|
32 <button value="Latest" onclick={ro <- rpc (current {Id = kr.Key});
|
adamc@993
|
33 case ro of
|
adamc@993
|
34 None => alert "Can't get it!"
|
adamc@993
|
35 | Some r =>
|
adamc@993
|
36 set kr.Nam r.Nam;
|
adamc@993
|
37 set kr.ShoeSize (show r.ShoeSize)}/>
|
adamc@993
|
38 <button value="Update" onclick={name <- get kr.Nam;
|
adamc@993
|
39 shoeSize <- get kr.ShoeSize;
|
adamc@993
|
40 rpc (update {Id = kr.Key,
|
adamc@993
|
41 Nam = name,
|
adamc@993
|
42 ShoeSize = readError shoeSize})
|
adamc@993
|
43 }/>
|
adamc@993
|
44 </div></xml>) ks)}/>
|
adamc@993
|
45
|
adamc@993
|
46 <h2>Add one:</h2>
|
adamc@993
|
47
|
adamc@993
|
48 <table>
|
adamc@993
|
49 <tr><th>Id:</th> <td><ctextbox size={5} source={id}/></td></tr>
|
adamc@993
|
50 <tr><th>Name:</th> <td><ctextbox source={name}/></td></tr>
|
adamc@993
|
51 <tr><th>Shoe size:</th> <td><ctextbox size={5} source={shoeSize}/></td></tr>
|
adamc@993
|
52 <tr><th><button value="Add" onclick={id <- get id;
|
adamc@993
|
53 name <- get name;
|
adamc@993
|
54 shoeSize <- get shoeSize;
|
adamc@993
|
55 rpc (insert {Id = readError id, Nam = name,
|
adamc@993
|
56 ShoeSize = readError shoeSize});
|
adamc@993
|
57
|
adamc@993
|
58 cur <- get ks;
|
adamc@993
|
59 kr <- expandKey (readError id);
|
adamc@993
|
60 set ks (kr :: cur)}/></th></tr>
|
adamc@993
|
61 </table>
|
adamc@993
|
62 </body></xml>
|