Mercurial > urweb
comparison demo/more/grid.ur @ 940:e2be476673f2
Selection working, but switching it on isn't
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 15 Sep 2009 11:18:20 -0400 |
parents | 37dd42935dad |
children | b8d7a47b8e0c |
comparison
equal
deleted
inserted
replaced
939:38a376dc7401 | 940:e2be476673f2 |
---|---|
46 (map2 [fst] [colMeta M.row] [fn p :: (Type * Type) => transaction p.2] | 46 (map2 [fst] [colMeta M.row] [fn p :: (Type * Type) => transaction p.2] |
47 (fn [p] data meta => make row [_] (meta.Handlers data)) | 47 (fn [p] data meta => make row [_] (meta.Handlers data)) |
48 [_] M.folder cols M.cols) | 48 [_] M.folder cols M.cols) |
49 (@@Folder.mp [_] [_] M.folder) | 49 (@@Folder.mp [_] [_] M.folder) |
50 | 50 |
51 type grid = {Cols : $(map fst M.cols), | |
52 Rows : Dlist.dlist {Row : source M.row, | |
53 Cols : source ($(map snd M.cols)), | |
54 Updating : source bool, | |
55 Selected : source bool}, | |
56 Selection : source bool} | |
57 | |
51 fun addRow cols rows row = | 58 fun addRow cols rows row = |
52 rowS <- source row; | 59 rowS <- source row; |
53 cols <- makeAll cols row; | 60 cols <- makeAll cols row; |
54 colsS <- source cols; | 61 colsS <- source cols; |
55 ud <- source False; | 62 ud <- source False; |
63 sd <- source False; | |
56 Monad.ignore (Dlist.append rows {Row = rowS, | 64 Monad.ignore (Dlist.append rows {Row = rowS, |
57 Cols = colsS, | 65 Cols = colsS, |
58 Updating = ud}) | 66 Updating = ud, |
59 | 67 Selected = sd}) |
60 type grid = {Cols : $(map fst M.cols), | 68 |
61 Rows : Dlist.dlist {Row : source M.row, Cols : source ($(map snd M.cols)), Updating : source bool}} | |
62 | |
63 val createMetas = Monad.mapR [colMeta M.row] [fst] | 69 val createMetas = Monad.mapR [colMeta M.row] [fst] |
64 (fn [nm :: Name] [p :: (Type * Type)] meta => meta.Initialize) | 70 (fn [nm :: Name] [p :: (Type * Type)] meta => meta.Initialize) |
65 [_] M.folder M.cols | 71 [_] M.folder M.cols |
66 | 72 |
67 val grid = | 73 val grid = |
68 cols <- createMetas; | 74 cols <- createMetas; |
69 rows <- Dlist.create; | 75 rows <- Dlist.create; |
70 return {Cols = cols, Rows = rows} | 76 sel <- source False; |
71 | 77 return {Cols = cols, Rows = rows, Selection = sel} |
72 fun sync {Cols = cols, Rows = rows} = | 78 |
79 fun sync {Cols = cols, Rows = rows, ...} = | |
73 Dlist.clear rows; | 80 Dlist.clear rows; |
74 init <- rpc M.list; | 81 init <- rpc M.list; |
75 List.app (addRow cols rows) init | 82 List.app (addRow cols rows) init |
76 | 83 |
77 fun render grid = <xml> | 84 fun render grid = <xml> |
83 data (meta : colMeta M.row p) => | 90 data (meta : colMeta M.row p) => |
84 <xml><th class={th}>{[(meta.Handlers data).Header]}</th></xml>) | 91 <xml><th class={th}>{[(meta.Handlers data).Header]}</th></xml>) |
85 [_] M.folder grid.Cols M.cols} | 92 [_] M.folder grid.Cols M.cols} |
86 </tr> | 93 </tr> |
87 | 94 |
88 {Dlist.render (fn {Row = rowS, Cols = colsS, Updating = ud} pos => | 95 {Dlist.render (fn {Row = rowS, Cols = colsS, Updating = ud, Selected = sd} pos => |
89 let | 96 let |
90 val delete = | 97 val delete = |
91 Dlist.delete pos; | 98 Dlist.delete pos; |
92 row <- get rowS; | 99 row <- get rowS; |
93 rpc (M.delete (M.keyOf row)) | 100 rpc (M.delete (M.keyOf row)) |
132 | 139 |
133 cols <- makeAll grid.Cols row'; | 140 cols <- makeAll grid.Cols row'; |
134 set colsS cols | 141 set colsS cols |
135 in | 142 in |
136 <xml><tr class={tr}> | 143 <xml><tr class={tr}> |
144 <td> | |
145 <dyn signal={b <- signal grid.Selection; | |
146 return (if not b then | |
147 <xml><ccheckbox source={sd}/></xml> | |
148 else | |
149 <xml>No</xml>)}/> | |
150 </td> | |
151 | |
137 <td> | 152 <td> |
138 <dyn signal={b <- signal ud; | 153 <dyn signal={b <- signal ud; |
139 return (if b then | 154 return (if b then |
140 <xml><button value="Save" onclick={save}/></xml> | 155 <xml><button value="Save" onclick={save}/></xml> |
141 else | 156 else |
195 | 210 |
196 <button value="New row" onclick={row <- rpc M.new; | 211 <button value="New row" onclick={row <- rpc M.new; |
197 addRow grid.Cols grid.Rows row}/> | 212 addRow grid.Cols grid.Rows row}/> |
198 <button value="Refresh" onclick={sync grid}/> | 213 <button value="Refresh" onclick={sync grid}/> |
199 </xml> | 214 </xml> |
215 | |
216 fun showSelection grid = grid.Selection | |
217 | |
218 fun selection grid = Dlist.foldl (fn {Row = rowS, Selected = sd, ...} ls => | |
219 sd <- signal sd; | |
220 if sd then | |
221 row <- signal rowS; | |
222 return (row :: ls) | |
223 else | |
224 return ls) [] grid.Rows | |
200 end | 225 end |