Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
achlipala committed Jul 29, 2020
2 parents 399b452 + f7b0280 commit fb31664
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
4 changes: 1 addition & 3 deletions examples/client.ur
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
(* Note that this will only work if you get the file src/js/ajaxUpload.js to appear in the root of http://localhost/ ! *)

sequence ids

table images : { Id : int, MimeType : string, Content : blob }
Expand All @@ -13,7 +11,7 @@ fun choice b =
<button value="Create new widget"
onclick={fn _ => au <- AjaxUpload.render {SubmitLabel = if b then None else Some "Upload it!",
OnBegin = set status <xml>Uploading</xml>,
OnError = set status <xml><b>Upload failed!</b></xml>,
OnError = set status <xml><strong>Upload failed!</strong></xml>,
OnSuccess = fn h =>
let
fun addImage () =
Expand Down
2 changes: 1 addition & 1 deletion examples/client.urp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library ../src/ur
library $/ajaxUpload
rewrite url Client/*
database dbname=test
sql client.sql
Expand Down
2 changes: 1 addition & 1 deletion examples/server.urp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library ../src/ur
library $/ajaxUpload
rewrite url Server/*
database dbname=test
sql server.sql
Expand Down
5 changes: 3 additions & 2 deletions src/c/ajaxUpload.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ uw_Basis_string uw_AjaxUploadFfi_tweakForm(uw_context ctx, uw_Basis_bool autoSub
submitId,
"\"); subm.parentNode.target = \"",
iframeId,
"\"; var onSub = subm.onmousedown; subm.onmousedown = undefined; subm.parentNode.onsubmit = function() { window.top.event = {}; onSub(); return true; }; subm.withHandle = subm.onkeydown; subm.onkeydown = undefined; subm.withError = subm.onmouseup; subm.onmouseup = undefined; ",
"\"; var onSub = subm.onblur; subm.onblur = undefined; subm.parentNode.onsubmit = function() { window.top.event = {}; onSub(); return true; }; subm.withHandle = subm.onkeydown; subm.onkeydown = undefined; subm.withError = subm.onfocus; subm.onfocus = undefined; ",
autoSubmit
? "subm.style.visibility = \"hidden\"; for (var node = subm.previousSibling; node.tagName != \"INPUT\"; node = node.previousSibling); node.onchange = function() { subm.parentNode.submit(); }; "
: "",
Expand All @@ -21,13 +21,14 @@ uw_Basis_string uw_AjaxUploadFfi_tweakForm(uw_context ctx, uw_Basis_bool autoSub
}

uw_Basis_string uw_AjaxUploadFfi_notifySuccess(uw_context ctx, uw_Basis_string submitId, uw_Basis_int handle) {
return uw_Basis_mstrcat(ctx,
uw_Basis_string r = uw_Basis_mstrcat(ctx,
"<script type=\"text/javascript\">var subm = window.top.document.getElementById(\"",
submitId,
"\"); window.top.event = {keyCode : ",
uw_Basis_htmlifyInt(ctx, handle),
"}; subm.withHandle(); </script>",
NULL);
return r;
}

uw_Basis_string uw_AjaxUploadFfi_notifyError(uw_context ctx, uw_Basis_string submitId) {
Expand Down
8 changes: 4 additions & 4 deletions src/js/ajaxUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function tweakFormCode(autoSubmit, iframeId, submitId) {
subm.parentNode.target = iframeId;

if (subm.begin == undefined) {
subm.begin = subm.onmousedown;
subm.onmousedown = undefined;
subm.begin = subm.onblur;
subm.onblur = undefined;
}

subm.parentNode.onsubmit = function() {
Expand All @@ -28,8 +28,8 @@ function tweakFormCode(autoSubmit, iframeId, submitId) {
}

if (subm.withError == undefined) {
subm.withError = subm.onmouseup;
subm.onmouseup = undefined;
subm.withError = subm.onfocus;
subm.onfocus = undefined;
}

if (autoSubmit) {
Expand Down
2 changes: 1 addition & 1 deletion src/ur/ajaxUpload.ur
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun render {SubmitLabel = sl, OnBegin = ob, OnSuccess = os, OnError = oe} =
return <xml>
<form>
<upload{#File}/>
<submit value={Option.get "" sl} action={uploadAction} id={submitId} onmousedown={fn _ => ob} onkeydown={fn ev => os ev.KeyCode} onmouseup={fn _ => oe}/>
<submit value={Option.get "" sl} action={uploadAction} id={submitId} onblur={ob} onkeydown={fn ev => os ev.KeyCode} onfocus={oe}/>
</form>
{AjaxUploadFfi.tweakForm (Option.isNone sl) iframeId submitId}
</xml>
Expand Down

0 comments on commit fb31664

Please sign in to comment.