comparison calendar.ur @ 15:8300d5f0dc19

Replace ChangePoller with SourceL, plus some other rearrangements
author Adam Chlipala <adam@chlipala.net>
date Sun, 07 Aug 2011 14:38:52 -0400
parents 0827320b0f04
children 554e342665fe
comparison
equal deleted inserted replaced
14:0827320b0f04 15:8300d5f0dc19
19 19
20 type t = {Month : source {ThisMonth : int, Year : int, 20 type t = {Month : source {ThisMonth : int, Year : int,
21 ThisMonthLength : int, PrevMonthLength : int, 21 ThisMonthLength : int, PrevMonthLength : int,
22 MondayMonth : month, MondayDay : int, 22 MondayMonth : month, MondayDay : int,
23 PrevMonthName : string, ThisMonthName : string, NextMonthName : string}, 23 PrevMonthName : string, ThisMonthName : string, NextMonthName : string},
24 Day : ChangePoller.changePoller date} 24 Day : SourceL.t date}
25 25
26 fun pad len n = 26 fun pad len n =
27 let 27 let
28 val s = show n 28 val s = show n
29 29
106 fun create tm = 106 fun create tm =
107 year <- return (readError (timef "%Y" tm)); 107 year <- return (readError (timef "%Y" tm));
108 month <- return (readError (timef "%m" tm)); 108 month <- return (readError (timef "%m" tm));
109 minf <- source (monthInfo' {Month = month, Year = year}); 109 minf <- source (monthInfo' {Month = month, Year = year});
110 day <- return (readError (timef "%d" tm)); 110 day <- return (readError (timef "%d" tm));
111 day <- ChangePoller.create {Year = year, Month = month, Day = day}; 111 day <- SourceL.create {Year = year, Month = month, Day = day};
112 return {Month = minf, Day = day} 112 return {Month = minf, Day = day}
113 113
114 fun render' t = 114 fun render' t =
115 minf <- signal t.Month; 115 minf <- signal t.Month;
116 let 116 let
127 Prev => if minf.ThisMonth = 1 then 12 else minf.ThisMonth - 1 127 Prev => if minf.ThisMonth = 1 then 12 else minf.ThisMonth - 1
128 | This => minf.ThisMonth 128 | This => minf.ThisMonth
129 | Next => if minf.ThisMonth = 12 then 1 else minf.ThisMonth + 1, 129 | Next => if minf.ThisMonth = 12 then 1 else minf.ThisMonth + 1,
130 Day = day} 130 Day = day}
131 in 131 in
132 cday <- ChangePoller.value t.Day; 132 cday <- SourceL.value t.Day;
133 return (if Record.equal thisDate cday then 133 return (if Record.equal thisDate cday then
134 <xml><td class={selday}>{[day]}</td></xml> 134 <xml><td class={selday}>{[day]}</td></xml>
135 else case month of 135 else case month of
136 This => <xml><td class={curday} 136 This => <xml><td class={curday}
137 onclick={set (ChangePoller.ctl t.Day) thisDate}>{[day]}</td></xml> 137 onclick={SourceL.set t.Day thisDate}>{[day]}</td></xml>
138 | _ => <xml><td class={otherday}>{[day]}</td></xml>) 138 | _ => <xml><td class={otherday}>{[day]}</td></xml>)
139 end}/> 139 end}/>
140 {let 140 {let
141 val (year, month, day) = 141 val (year, month, day) =
142 case month of 142 case month of
201 minf.Year) minf.MondayMonth minf.MondayDay} 201 minf.Year) minf.MondayMonth minf.MondayDay}
202 </table> 202 </table>
203 </xml> 203 </xml>
204 end 204 end
205 205
206 fun addListener f ctl = 206 fun onChange ctl f =
207 ChangePoller.addChangeListener f 100 ctl.Day 207 SourceL.onChange ctl.Day f
208 208
209 val gui_t = Gui.mkGui 209 val gui_t = Gui.mkGui
210 (fn ctl => 210 (fn ctl =>
211 <xml> 211 <xml>
212 <dyn signal={render' ctl}/> 212 <dyn signal={render' ctl}/>
213 </xml>) 213 </xml>)
214 214
215 fun set ctl day = 215 fun set ctl day =
216 minf <- rpc (monthInfo (day -- #Day)); 216 minf <- rpc (monthInfo (day -- #Day));
217 Basis.set ctl.Month minf; 217 Basis.set ctl.Month minf;
218 Basis.set (ChangePoller.ctl ctl.Day) day 218 SourceL.set ctl.Day day
219 219
220 fun value ctl = ChangePoller.value ctl.Day 220 fun value ctl = SourceL.value ctl.Day