changeset 3:6ad01456dc2e

Change interface to allow setting submit button text
author Adam Chlipala <adam@chlipala.net>
date Thu, 29 Dec 2011 15:46:15 -0500
parents df095eecba63
children cf3ff3dc306f
files examples/server.ur src/ur/ajaxUpload.ur src/ur/ajaxUpload.urs src/ur/lib.urp
diffstat 4 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/examples/server.ur	Thu Dec 29 15:42:15 2011 -0500
+++ b/examples/server.ur	Thu Dec 29 15:46:15 2011 -0500
@@ -5,7 +5,7 @@
 
 fun choice b =
     status <- source <xml/>;
-    au <- AjaxUpload.render {AutoSubmit = b,
+    au <- AjaxUpload.render {SubmitLabel = if b then None else Some "Upload it!",
                              OnBegin = set status <xml>Uploading</xml>,
                              OnSuccess = fn h =>
                                             let
--- a/src/ur/ajaxUpload.ur	Thu Dec 29 15:42:15 2011 -0500
+++ b/src/ur/ajaxUpload.ur	Thu Dec 29 15:46:15 2011 -0500
@@ -40,7 +40,7 @@
                 None => NotFound
               | Some r => Found r)
 
-fun render {AutoSubmit = as, OnBegin = ob, OnSuccess = os} =
+fun render {SubmitLabel = sl, OnBegin = ob, OnSuccess = os} =
     iframeId <- fresh;
     submitId <- fresh;
     submitId' <- return (AjaxUploadFfi.idToString submitId);
@@ -56,8 +56,8 @@
         return <xml>
           <form>
             <upload{#File}/>
-            <submit action={upload} id={submitId} onmousedown={ob} onkeydown={os}/>
+            <submit value={Option.get "" sl} action={upload} id={submitId} onmousedown={ob} onkeydown={os}/>
           </form>
-          {AjaxUploadFfi.tweakForm as iframeId submitId}
+          {AjaxUploadFfi.tweakForm (Option.isNone sl) iframeId submitId}
         </xml>
     end
--- a/src/ur/ajaxUpload.urs	Thu Dec 29 15:42:15 2011 -0500
+++ b/src/ur/ajaxUpload.urs	Thu Dec 29 15:46:15 2011 -0500
@@ -15,8 +15,8 @@
 val peek : handle -> transaction claim_result
 (* Like [claim], but keeps the file in temporary storage.  Beware that files older than 30 minutes may be removed automatically! *)
 
-val render : {AutoSubmit : bool,
-              (* If [True], no extra form submit button is included, and file is uploaded once file selection dialog is closed. *)
+val render : {SubmitLabel : option string,
+              (* Text for submit button, or [None] to auto-submit when selected file changes *)
               OnBegin : transaction {},
               (* Run this when an upload begins. *)
               OnSuccess : handle -> transaction {}
--- a/src/ur/lib.urp	Thu Dec 29 15:42:15 2011 -0500
+++ b/src/ur/lib.urp	Thu Dec 29 15:46:15 2011 -0500
@@ -3,4 +3,5 @@
 link -lurweb_ajaxUpload
 jsFunc AjaxUploadFfi.getHandle=getHandle
 
+$/option
 ajaxUpload