changeset 347:58eeeb3cbf40

Use checkbox in CRUD example
author Adam Chlipala <adamc@hcoop.net>
date Sat, 04 Oct 2008 16:15:13 -0400
parents a94a79820d49
children b88f4297167f
files lib/basis.urs src/monoize.sml tests/crud1.ur
diffstat 3 files changed, 52 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/lib/basis.urs	Sat Oct 04 15:54:03 2008 -0400
+++ b/lib/basis.urs	Sat Oct 04 16:15:13 2008 -0400
@@ -300,7 +300,7 @@
 val password : lformTag string [] []
 val ltextarea : lformTag string [] []
 
-val checkbox : lformTag bool [] []
+val checkbox : lformTag bool [] [Checked = bool]
 
 con radio = [Body, Radio]
 val radio : lformTag string radio []
--- a/src/monoize.sml	Sat Oct 04 15:54:03 2008 -0400
+++ b/src/monoize.sml	Sat Oct 04 16:15:13 2008 -0400
@@ -1247,27 +1247,55 @@
                             val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
                         in
                             foldl (fn ((x, e, t), (s, fm)) =>
-                                      let
-                                          val xp = " " ^ lowercaseFirst x ^ "=\""
+                                      case t of
+                                          (L'.TFfi ("Basis", "bool"), _) =>
+                                          let
+                                              val s' = " " ^ lowercaseFirst x
+                                          in
+                                              ((L'.ECase (e,
+                                                          [((L'.PCon (L'.Enum,
+                                                                      L'.PConFfi {mod = "Basis",
+                                                                                  datatyp = "bool",
+                                                                                  con = "True",
+                                                                                  arg = NONE},
+                                                                      NONE), loc),
+                                                            (L'.EStrcat (s,
+                                                                         (L'.EPrim (Prim.String s'), loc)), loc)),
+                                                           ((L'.PCon (L'.Enum,
+                                                                      L'.PConFfi {mod = "Basis",
+                                                                                  datatyp = "bool",
+                                                                                  con = "False",
+                                                                                  arg = NONE},
+                                                                      NONE), loc),
+                                                            s)],
+                                                          {disc = (L'.TFfi ("Basis", "bool"), loc),
+                                                           result = (L'.TFfi ("Basis", "string"), loc)}), loc),
+                                               fm)
+                                          end
+                                        | _ =>
+                                          let
+                                              val fooify =
+                                                  case x of
+                                                      "Href" => urlifyExp
+                                                    | "Link" => urlifyExp
+                                                    | "Action" => urlifyExp
+                                                    | _ => attrifyExp
 
-                                          val fooify =
-                                              case x of
-                                                  "Href" => urlifyExp
-                                                | "Link" => urlifyExp
-                                                | "Action" => urlifyExp
-                                                | _ => attrifyExp
+                                              val xp = " " ^ lowercaseFirst x ^ "=\""
 
-                                          val (e, fm) = fooify env fm (e, t)
-                                      in
-                                          ((L'.EStrcat (s,
-                                                        (L'.EStrcat ((L'.EPrim (Prim.String xp), loc),
-                                                                     (L'.EStrcat (e,
-                                                                                  (L'.EPrim (Prim.String "\""),
-                                                                                   loc)),
-                                                                      loc)),
-                                                         loc)), loc),
-                                           fm)
-                                      end)
+
+
+                                              val (e, fm) = fooify env fm (e, t)
+                                          in
+                                              ((L'.EStrcat (s,
+                                                            (L'.EStrcat ((L'.EPrim (Prim.String xp), loc),
+                                                                         (L'.EStrcat (e,
+                                                                                      (L'.EPrim (Prim.String "\""),
+                                                                                       loc)),
+                                                                          loc)),
+                                                             loc)), loc),
+                                               fm)
+                                          end)
                                   (s, fm) xes
                         end
                       | _ => raise Fail "Non-record attributes!"
--- a/tests/crud1.ur	Sat Oct 04 15:54:03 2008 -0400
+++ b/tests/crud1.ur	Sat Oct 04 16:15:13 2008 -0400
@@ -5,7 +5,7 @@
                 A = (int, string),
                 B = (string, string),
                 C = (float, string),
-                D = (bool, string)
+                D = (bool, bool)
         ]
 
         val tab = t1
@@ -40,9 +40,9 @@
                 D = {
                         Nam = "D",
                         Show = txt _,
-                        Widget = fn nm :: Name => <lform><textbox{nm}/></lform>,
-                        WidgetPopulated = fn (nm :: Name) b => <lform><textbox{nm} value={show _ b}/></lform>,
-                        Parse = readError _,
+                        Widget = fn nm :: Name => <lform><checkbox{nm}/></lform>,
+                        WidgetPopulated = fn (nm :: Name) b => <lform><checkbox{nm} checked={b}/></lform>,
+                        Parse = fn x => x,
                         Inject = sql_bool
                     }
         }