diff demo/more/decision.ur @ 1032:5d9f47124c4c

Saving paper decisions
author Adam Chlipala <adamc@hcoop.net>
date Sat, 07 Nov 2009 11:06:38 -0500
parents 5dccff15fa62
children
line wrap: on
line diff
--- a/demo/more/decision.ur	Mon Nov 02 15:54:22 2009 -0500
+++ b/demo/more/decision.ur	Sat Nov 07 11:06:38 2009 -0500
@@ -12,37 +12,53 @@
                  include Conference.INPUT
                          where con paper = [Decision = option bool] ++ paperOther
 
-                 val status : ctx ::: {Unit} -> [[Body] ~ ctx] => $paperOther -> xml ([Body] ++ ctx) [] []
+                 val status : ctx ::: {Unit} -> [[Body] ~ ctx] => $([Id = paperId] ++ paperOther)
+                                                                  -> transaction (xml ([Body] ++ ctx) [] [])
              end) = struct
     open M
 
     val linksForChair =
         let
             fun makeDecisions () =
-                ps <- queryX (SELECT paper.Id, paper.Decision, paper.{{M.paperOther}}
-                              FROM paper
-                              ORDER BY paper.Id)
-                      (fn r => <xml><tr>
-                        <td>{useMore (summarizePaper (r.Paper -- #Id))}</td>
-                        <td>{useMore (status (r.Paper -- #Id -- #Decision))}</td>
-                        <td><entry>
-                          <hidden{#Paper} value={show r.Paper.Id}/>
-                          <select{#Decision}>
-                            <option selected={r.Paper.Decision = None}>?</option>
-                            <option selected={r.Paper.Decision = Some True}>Accept</option>
-                            <option selected={r.Paper.Decision = Some False}>Reject</option>
-                        </select></entry></td>
-                      </tr></xml>);
+                ps <- queryX' (SELECT paper.Id, paper.Decision, paper.{{M.paperOther}}
+                               FROM paper
+                               ORDER BY paper.Id)
+                              (fn r => st <- status (r.Paper -- #Decision);
+                                  return <xml><tr>
+                                    <td>{useMore (summarizePaper (r.Paper -- #Id))}</td>
+                                    <td>{useMore st}</td>
+                                    <td><entry>
+                                      <hidden{#Paper} value={show r.Paper.Id}/>
+                                      <select{#Decision}>
+                                        <option selected={r.Paper.Decision = None}>?</option>
+                                        <option selected={r.Paper.Decision = Some True}>Accept</option>
+                                        <option selected={r.Paper.Decision = Some False}>Reject</option>
+                                    </select></entry></td>
+                                  </tr></xml>);
                 return <xml><body>
                   <h1>Make acceptance decisions</h1>
 
-                  <form><subforms{#Papers}>
-                    <table>
-                      <tr> <th>Paper</th> <th>Status</th> <th>Decision</th> </tr>
-                      {ps}
-                    </table>
-                  </subforms></form>
+                  <form>
+                    <subforms{#Papers}>
+                      <table>
+                        <tr> <th>Paper</th> <th>Status</th> <th>Decision</th> </tr>
+                        {ps}
+                      </table>
+                    </subforms>
+                    <submit value="Save" action={saveDecisions}/>
+                  </form>
                 </body></xml>
+
+            and saveDecisions r =
+                List.app (fn {Paper = pid, Decision = dec} =>
+                             dml (UPDATE paper
+                                  SET Decision = {[case dec of
+                                                       "?" => None
+                                                     | "Accept" => Some True
+                                                     | "Reject" => Some False
+                                                     | _ => error <xml>Invalid decision code</xml>]}
+                                  WHERE Id = {[readError pid]})) r.Papers;
+                makeDecisions ()
         in
             <xml>
               <li><a link={makeDecisions ()}>Make acceptance decisions</a></li>