summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2016-10-30 13:47:56 -0400
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2016-10-30 13:47:56 -0400
commitd1d071462a0a1520d94a029886093b558b24267d (patch)
tree3c5544842289a2545386e1dd518dc64edf9faf88
parent9c9a28b92f55a8dd302cd964c66498d95c1b5bd3 (diff)
Support saving new actions
-rw-r--r--main.ur24
-rw-r--r--mdl/lib.urp2
-rw-r--r--mdl/mdl.ur21
-rw-r--r--mdl/mdlFfi.urs2
4 files changed, 38 insertions, 11 deletions
diff --git a/main.ur b/main.ur
index dd43f47..cf2a4a5 100644
--- a/main.ur
+++ b/main.ur
@@ -20,6 +20,8 @@ table nextAction : {
Done : bool,
} PRIMARY KEY Id
+sequence nextActionId
+
(* Forces JavaScript to be enabled on the given page, so as to pull in external
scripts specified in the .urp file. *)
val forceJavaScript = <xml><script code={return ()} /></xml>
@@ -47,6 +49,13 @@ fun renderNextAction action =
</li>
</xml>
+val renderNextActions = queryX1' (SELECT * FROM nextAction) renderNextAction
+
+fun newNextAction name =
+ id <- nextval nextActionId;
+ dml (INSERT INTO nextAction (Id, Nam, Done) VALUES ({[4 + id]}, {[name]}, FALSE));
+ renderNextActions
+
style hidden
style visible
@@ -54,7 +63,7 @@ style visible
datatype mode = NextActions | NewNextAction
val main =
- actionItems <- queryX1' (SELECT * FROM nextAction) renderNextAction;
+ actionItems <- bind renderNextActions source;
setHeader (blessResponseHeader "X-UA-Compatible") "IE=edge";
mode <- source NextActions;
newNextActionDescription <- Mdl.Textbox.make "Description";
@@ -95,11 +104,18 @@ val main =
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">New action</span>
<div class="mdl-layout-spacer" />
- (* <button class="mdl-button mdl-js-button" value="Save" /> *)
+ <button class="mdl-button mdl-js-button" value="Save" onclick={fn _ =>
+ name <- get newNextActionDescription.Source;
+ bind (rpc (newNextAction name)) (set actionItems);
+ sleep 0;
+ Mdl.upgradeAllRegistered;
+ set mode NextActions;
+ set newNextActionDescription.Source ""
+ } />
</div>
</header>
<div class="mdl-layout__content">
- {newNextActionDescription}
+ {newNextActionDescription.Xml}
</div>
</div>
</div>
@@ -117,7 +133,7 @@ val main =
</div>
<div class="mdl-layout__content">
<ul class="mdl-list">
- {actionItems}
+ <dyn signal={signal actionItems} />
</ul>
<button class="mdl-button mdl-js-button mdl-button--fab mdl-button--colored" onclick={fn _ => set mode NewNextAction}>
<i class="material-icons">add</i>
diff --git a/mdl/lib.urp b/mdl/lib.urp
index 0853cbe..e4447db 100644
--- a/mdl/lib.urp
+++ b/mdl/lib.urp
@@ -1,8 +1,10 @@
benignEffectful MdlFfi.showSnackbar
+benignEffectful MdlFfi.upgradeAllRegistered
ffi mdlFfi
file /zoBIS4V6.js mdlFfi.js
html5
jsFunc MdlFfi.showSnackbar=UrWeb.MdlFfi.showSnackbar
+jsFunc MdlFfi.upgradeAllRegistered=componentHandler.upgradeAllRegistered
library mdlClasses
script /zoBIS4V6.js
diff --git a/mdl/mdl.ur b/mdl/mdl.ur
index 5f68ab1..90f03a1 100644
--- a/mdl/mdl.ur
+++ b/mdl/mdl.ur
@@ -15,15 +15,22 @@ specific language governing permissions and limitations under the License. *)
structure Classes = MdlClasses
open Classes
+val upgradeAllRegistered = MdlFfi.upgradeAllRegistered
+
structure Textbox = struct
- fun make (placeholder : string) : transaction xbody =
+ fun make (placeholder : string) : transaction {Source : source string,
+ Xml : xbody} =
+ contents <- source "";
id <- fresh;
- return <xml>
- <div class="mdl-textfield mdl-js-textfield">
- <ctextbox class="mdl-textfield__input" id={id} />
- <label class="mdl-textfield__label" for={id}>{[placeholder]}</label>
- </div>
- </xml>
+ return {
+ Source = contents,
+ Xml = <xml>
+ <div class="mdl-textfield mdl-js-textfield">
+ <ctextbox class="mdl-textfield__input" id={id} source={contents} />
+ <label class="mdl-textfield__label" for={id}>{[placeholder]}</label>
+ </div>
+ </xml>
+ }
end
structure Toast = struct
diff --git a/mdl/mdlFfi.urs b/mdl/mdlFfi.urs
index 74dd636..6e8188a 100644
--- a/mdl/mdlFfi.urs
+++ b/mdl/mdlFfi.urs
@@ -12,4 +12,6 @@ under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. *)
+val upgradeAllRegistered : transaction unit
+
val showSnackbar : string (* id *) -> string (* text *) -> transaction unit