Commit de8c94e9 authored by Stephane Glondu's avatar Stephane Glondu

Switch js_of_ocaml code to PPX syntax

parent ffaee65c
......@@ -3,7 +3,7 @@
<src/platform/native/*>: package(zarith), package(cryptokit)
<src/web/*.{ml,mli,byte,native,odoc}>: thread, package(eliom.server), package(lwt.ppx), package(calendar), package(csv)
<src/tool/tool_cmdline.*>: package(zarith), package(cryptokit), package(cmdliner), use_platform-native
<src/tool/tool_js*> or <src/platform/js/*> or <src/booth/*>: package(js_of_ocaml-lwt), syntax(camlp4o), package(js_of_ocaml.syntax), package(lwt.syntax), use_platform-js
<src/tool/tool_js*> or <src/platform/js/*> or <src/booth/*>: package(js_of_ocaml-lwt), package(js_of_ocaml-ppx), package(lwt.ppx), use_platform-js
<**/*serializable_j.ml>: warn(-32)
true: warn(A-4-6-29-44-45-48), safe_string
......@@ -92,7 +92,7 @@ eval `opam config env`
echo
echo "=-=-= Installation of Belenios build-dependencies =-=-="
echo
opam install --yes atdgen zarith cryptokit uuidm calendar cmdliner sqlite3 eliom=6.3.0 csv js_of_ocaml-camlp4
opam install --yes atdgen zarith cryptokit uuidm calendar cmdliner sqlite3 eliom=6.3.0 csv
echo
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
......
......@@ -25,7 +25,7 @@ open Serializable_j
open Signatures
open Common
let document = Dom_html.window##document
let document = Dom_html.window##.document
let withElementById x f =
Js.Opt.iter (document##getElementById (Js.string x)) f
......@@ -33,7 +33,7 @@ let withElementById x f =
let getHtmlById x =
let r = ref x in
withElementById x (fun x ->
Js.Opt.iter (x##textContent) (fun x -> r := Js.to_string x)
Js.Opt.iter (x##.textContent) (fun x -> r := Js.to_string x)
); !r
let alert s : unit =
......@@ -55,14 +55,14 @@ let runHandler handler () =
let installHandler id handler =
let f _ = runHandler handler () in
withElementById id (fun e -> e##onclick <- Dom_html.handler f)
withElementById id (fun e -> e##.onclick := Dom_html.handler f)
let getTextarea id =
let res = ref None in
withElementById id (fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> res := Some (Js.to_string (x##value)))
(fun x -> res := Some (Js.to_string (x##.value)))
);
match !res with
| None -> raise Not_found
......@@ -72,7 +72,7 @@ let setTextarea id z =
withElementById id (fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> x##value <- Js.string z)
(fun x -> x##.value := Js.string z)
)
let setNodeById id x =
......@@ -82,7 +82,7 @@ let setNodeById id x =
)
let setDisplayById id x =
withElementById id (fun e -> e##style##display <- Js.string x)
withElementById id (fun e -> e##.style##.display := Js.string x)
let prng = lazy (pseudo_rng (random_string secure_rng 16))
......@@ -95,7 +95,7 @@ module LwtJsRandom = struct
let random q =
let size = Z.bit_length q / 8 + 1 in
fun () ->
lwt () = Lwt_js.yield () in
let%lwt () = Lwt_js.yield () in
let r = random_string (Lazy.force prng) size in
Lwt.return Z.(of_bits r mod q)
end
......@@ -106,21 +106,21 @@ let encryptBallot params cred plaintext () =
let module E = Election.Make (P) (LwtJsRandom) in
let module CD = Credential.MakeDerive (G) in
let sk = CD.derive P.election.e_params.e_uuid cred in
lwt randomness = E.make_randomness () () in
lwt b = E.create_ballot ~sk randomness plaintext () in
let%lwt randomness = E.make_randomness () () in
let%lwt b = E.create_ballot ~sk randomness plaintext () in
let s = string_of_ballot G.write b in
setTextarea "ballot" s;
setNodeById "ballot_tracker" (sha256_b64 s);
setDisplayById "encrypting_div" "none";
setDisplayById "ballot_div" "block";
Dom_html.window##onbeforeunload <- Dom_html.no_handler;
Dom_html.window##.onbeforeunload := Dom_html.no_handler;
Lwt.return ()
let progress_step n =
let old_ = Printf.sprintf "progress%d" (n-1) in
let new_ = Printf.sprintf "progress%d" n in
withElementById old_ (fun e -> e##setAttribute (Js.string "style", Js.string ""));
withElementById new_ (fun e -> e##setAttribute (Js.string "style", Js.string "font-weight: bold;"))
withElementById old_ (fun e -> e##setAttribute (Js.string "style") (Js.string ""));
withElementById new_ (fun e -> e##setAttribute (Js.string "style") (Js.string "font-weight: bold;"))
let rec createQuestionNode sk params question_div num_questions i prev (q, answers) next =
(* Create div element for the current question. [i] and [(q,
......@@ -159,13 +159,13 @@ let rec createQuestionNode sk params question_div num_questions i prev (q, answe
| Some x -> x
| None -> failwith "error while casting checkbox"
in
if answers.(i) > 0 then cb##checked <- Js.bool true;
checkbox##setAttribute (Js.string "type", Js.string "checkbox");
checkbox##setAttribute (Js.string "style", Js.string "cursor: pointer;");
if answers.(i) > 0 then cb##.checked := Js.bool true;
checkbox##setAttribute (Js.string "type") (Js.string "checkbox");
checkbox##setAttribute (Js.string "style") (Js.string "cursor: pointer;");
Dom.appendChild div checkbox;
let t = document##createTextNode (Js.string a) in
checkbox##onclick <- Dom_html.handler (fun _ ->
answers.(i) <- if Js.to_bool cb##checked then 1 else 0;
checkbox##.onclick := Dom_html.handler (fun _ ->
answers.(i) <- if Js.to_bool cb##.checked then 1 else 0;
Js._true
);
Dom.appendChild div t;
......@@ -215,7 +215,7 @@ let rec createQuestionNode sk params question_div num_questions i prev (q, answe
let () =
(* previous button *)
let btns = document##createElement (Js.string "div") in
btns##setAttribute (Js.string "style", Js.string "text-align: center;");
btns##setAttribute (Js.string "style") (Js.string "text-align: center;");
let () =
match prev with
| [] ->
......@@ -224,7 +224,7 @@ let rec createQuestionNode sk params question_div num_questions i prev (q, answe
| r :: prev ->
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string @@ getHtmlById "str_previous") in
b##onclick <- Dom_html.handler (fun _ ->
b##.onclick := Dom_html.handler (fun _ ->
if check_constraints () then (
let ndiv = createQuestionNode sk params
question_div num_questions (i - 1) prev r ((q, answers) :: next)
......@@ -243,13 +243,13 @@ let rec createQuestionNode sk params question_div num_questions i prev (q, answe
(* last question, the button leads to encryption page *)
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string @@ getHtmlById "str_next") in
b##onclick <- Dom_html.handler (fun _ ->
b##.onclick := Dom_html.handler (fun _ ->
if check_constraints () then (
let all = (q, answers) :: prev in
let all_answers = List.rev_map snd all |> Array.of_list in
let all_questions = List.rev_map fst all |> Array.of_list in
setTextarea "choices" (string_of_plaintext all_answers);
question_div##style##display <- Js.string "none";
question_div##.style##.display := Js.string "none";
withElementById "pretty_choices" (fun e ->
Array.iteri (fun i a ->
let q = all_questions.(i) in
......@@ -290,7 +290,7 @@ let rec createQuestionNode sk params question_div num_questions i prev (q, answe
| r :: next ->
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string @@ getHtmlById "str_next") in
b##onclick <- Dom_html.handler (fun _ ->
b##.onclick := Dom_html.handler (fun _ ->
if check_constraints () then (
let ndiv = createQuestionNode sk params
question_div num_questions (i + 1) ((q, answers) :: prev) r next
......@@ -322,14 +322,14 @@ let addQuestions sk params qs =
let createStartButton params intro_div qs =
let b = document##createElement (Js.string "button") in
b##setAttribute (Js.string "style", Js.string "font-size:20px;");
b##setAttribute (Js.string "style") (Js.string "font-size:20px;");
let t = document##createTextNode (Js.string (getHtmlById "str_here")) in
b##onclick <- Dom_html.handler (fun _ ->
b##.onclick := Dom_html.handler (fun _ ->
(match prompt (getHtmlById "enter_cred") with
| Some cred when Credential.check cred ->
intro_div##style##display <- Js.string "none";
intro_div##.style##.display := Js.string "none";
setDisplayById "question_div" "block";
Dom_html.window##onbeforeunload <- Dom_html.handler (fun _ ->
Dom_html.window##.onbeforeunload := Dom_html.handler (fun _ ->
Js._false
);
progress_step 2;
......@@ -395,11 +395,11 @@ let load_url url =
(fun e ->
match transform_url url with
| None -> ()
| Some url -> e##action <- Js.string url)
| Some url -> e##.action := Js.string url)
);
let open Lwt_xmlHttpRequest in
Lwt.async (fun () ->
lwt raw = get (url ^ "election.json") in
let%lwt raw = get (url ^ "election.json") in
let () = setTextarea "election_params" raw.content in
Lwt.return (runHandler loadElection ())
)
......@@ -407,7 +407,7 @@ let load_url url =
let load_url_handler _ =
let url = getTextarea "url" in
let encoded = Url.encode_arguments ["url", url] in
Dom_html.window##location##hash <- Js.string encoded;
Dom_html.window##.location##.hash := Js.string encoded;
load_url url;
Js._false
......@@ -423,16 +423,16 @@ let load_params_handler _ =
let onload_handler _ =
let () =
withElementById "load_url"
(fun e -> e##onclick <- Dom_html.handler load_url_handler);
(fun e -> e##.onclick := Dom_html.handler load_url_handler);
withElementById "load_params"
(fun e -> e##onclick <- Dom_html.handler load_params_handler);
(fun e -> e##.onclick := Dom_html.handler load_params_handler);
in
let () =
match get_url (Js.to_string Dom_html.window##location##hash) with
match get_url (Js.to_string Dom_html.window##.location##.hash) with
| None ->
setDisplayById "wait_div" "none";
setDisplayById "election_loader" "block";
| Some url -> load_url url
in Js._false
let () = Dom_html.window##onload <- Dom_html.handler onload_handler
let () = Dom_html.window##.onload := Dom_html.handler onload_handler
......@@ -33,7 +33,7 @@ let install_handler (id, handler) =
in
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e -> e##onclick <- Dom_html.handler f)
(fun e -> e##.onclick := Dom_html.handler f)
module Tests = struct
......@@ -293,7 +293,7 @@ let install_handlers () =
List.iter install_handler cmds
let () =
Dom_html.window##onload <- Dom_html.handler (fun _ ->
Dom_html.window##.onload := Dom_html.handler (fun _ ->
install_handlers ();
Js._false
)
......@@ -19,7 +19,7 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
let document = Dom_html.window##document
let document = Dom_html.window##.document
let alert s : unit =
let open Js.Unsafe in
......@@ -32,7 +32,7 @@ let get_textarea id =
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> res := Some (Js.to_string (x##value)))
(fun x -> res := Some (Js.to_string (x##.value)))
);
match !res with
| None -> raise Not_found
......@@ -44,7 +44,7 @@ let set_textarea id z =
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> x##value <- Js.string z)
(fun x -> x##.value := Js.string z)
)
let get_input id =
......@@ -54,7 +54,7 @@ let get_input id =
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.input e)
(fun x -> res := Some (Js.to_string (x##value)))
(fun x -> res := Some (Js.to_string (x##.value)))
);
match !res with
| None -> raise Not_found
......@@ -63,7 +63,7 @@ let get_input id =
let set_element_display id x =
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e -> e##style##display <- Js.string x)
(fun e -> e##.style##.display := Js.string x)
let hide_element_by_id id = set_element_display id "none"
......@@ -72,6 +72,6 @@ let set_download id mime fn x =
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
e##setAttribute (Js.string "download", Js.string fn);
Js.Opt.iter (Dom_html.CoerceTo.a e) (fun e -> e##href <- x)
e##setAttribute (Js.string "download") (Js.string fn);
Js.Opt.iter (Dom_html.CoerceTo.a e) (fun e -> e##.href := x)
)
......@@ -64,11 +64,11 @@ let fill_interactivity _ =
Dom.appendChild e x;
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string "Generate") in
b##onclick <- Dom_html.handler generate;
b##.onclick := Dom_html.handler generate;
Dom.appendChild b t;
Dom.appendChild x b;
);
Js._false
let () =
Dom_html.window##onload <- Dom_html.handler fill_interactivity;
Dom_html.window##.onload := Dom_html.handler fill_interactivity;
......@@ -73,7 +73,7 @@ let compute_partial_decryption _ =
let encrypted_tally = encrypted_tally_of_string P.G.read e in
document##getElementById (Js.string "private_key") >>= fun e ->
Dom_html.CoerceTo.input e >>= fun e ->
let pk_str = Js.to_string e##value in
let pk_str = Js.to_string e##.value in
let private_key =
try
let epk = get_textarea "encrypted_private_key" in
......@@ -107,16 +107,16 @@ let compute_hash () =
let load_private_key_file _ =
document##getElementById (Js.string "private_key_file") >>= fun e ->
Dom_html.CoerceTo.input e >>= fun e ->
Js.Opt.option (Js.Optdef.to_option (e##files)) >>= fun e ->
Js.Opt.option (Js.Optdef.to_option (e##.files)) >>= fun e ->
e##item (0) >>= fun file ->
let reader = jsnew File.fileReader () in
reader##onload <-
let reader = new%js File.fileReader in
reader##.onload :=
Dom.handler (fun _ ->
let _ =
document##getElementById (Js.string "private_key") >>= fun e ->
Dom_html.CoerceTo.input e >>= fun e ->
File.CoerceTo.string (reader##result) >>= fun text ->
e##value <- text;
File.CoerceTo.string (reader##.result) >>= fun text ->
e##.value := text;
Js.some ()
in Js._false
);
......@@ -136,28 +136,28 @@ let main _ =
let _ =
document##getElementById (Js.string "compute") >>= fun e ->
Dom_html.CoerceTo.button e >>= fun e ->
e##onclick <- Dom_html.handler (wrap compute_partial_decryption);
e##.onclick := Dom_html.handler (wrap compute_partial_decryption);
Js.null
in
let _ =
document##getElementById (Js.string "private_key_file") >>= fun e ->
Dom_html.CoerceTo.input e >>= fun e ->
e##onchange <- Dom_html.handler (wrap load_private_key_file);
e##.onchange := Dom_html.handler (wrap load_private_key_file);
Js.null
in
let _ =
match get_uuid (Js.to_string Dom_html.window##location##search) with
match get_uuid (Js.to_string Dom_html.window##.location##.search) with
| None -> ()
| Some uuid ->
Lwt.async (fun () ->
let open Lwt_xmlHttpRequest in
lwt e = get ("../elections/" ^ uuid ^ "/encrypted_tally.json") in
let%lwt e = get ("../elections/" ^ uuid ^ "/encrypted_tally.json") in
encrypted_tally := Some (String.trim e.content);
lwt e = get ("../elections/" ^ uuid ^ "/election.json") in
let%lwt e = get ("../elections/" ^ uuid ^ "/election.json") in
election := Some e.content;
Lwt.return (compute_hash ()))
in
Js._false
let () =
Dom_html.window##onload <- Dom_html.handler main
Dom_html.window##.onload := Dom_html.handler main
......@@ -30,25 +30,25 @@ let handler f = Dom_html.handler (fun e -> ignore (f e); Js._false)
let extractAnswer a =
Dom_html.CoerceTo.input a >>= fun x ->
return (Js.to_string (x##value))
return (Js.to_string (x##.value))
let extractQuestion q =
Dom_html.CoerceTo.input q >>= fun x ->
let q_question = Js.to_string (x##value) in
q##parentNode >>= fun p1 ->
p1##parentNode >>= fun p2 ->
let q_question = Js.to_string (x##.value) in
q##.parentNode >>= fun p1 ->
p1##.parentNode >>= fun p2 ->
Dom.CoerceTo.element p2 >>= fun p2 ->
let p2 = Dom_html.element p2 in
let numeric selector error_msg =
p2##querySelector (Js.string selector) >>= fun x ->
Dom_html.CoerceTo.input x >>= fun x ->
let x = Js.to_string x##value in
let x = Js.to_string x##.value in
try return (int_of_string x)
with _ -> failwith (error_msg ^ ": " ^ x ^ ".")
in
p2##querySelector (Js.string ".question_blank") >>= fun q_blank ->
Dom_html.CoerceTo.input q_blank >>= fun q_blank ->
let q_blank = if Js.to_bool q_blank##checked then Some true else None in
let q_blank = if Js.to_bool q_blank##.checked then Some true else None in
numeric ".question_min" "Invalid minimum number of choices" >>= fun q_min ->
numeric ".question_max" "Invalid maximum number of choices" >>= fun q_max ->
if not (q_min <= q_max) then
......@@ -58,7 +58,7 @@ let extractQuestion q =
let answers = p2##querySelectorAll (Js.string ".question_answer") in
let q_answers =
Array.init
(answers##length)
(answers##.length)
(fun i ->
let a = answers##item (i) >>= extractAnswer in
Js.Opt.get a (fun () -> failwith "extractQuestion"))
......@@ -73,7 +73,7 @@ let extractTemplate () =
let questions = document##querySelectorAll (Js.string ".question_question") in
let t_questions =
Array.init
(questions##length)
(questions##.length)
(fun i ->
let q = questions##item (i) >>= extractQuestion in
Js.Opt.get q (fun () -> failwith "extractTemplate"))
......@@ -86,30 +86,30 @@ let rec createAnswer a =
let container = Dom_html.createDiv document in
let t = document##createTextNode (Js.string "Answer: ") in
let u = Dom_html.createInput document in
u##className <- Js.string "question_answer";
u##value <- Js.string a;
u##size <- 60;
u##.className := Js.string "question_answer";
u##.value := Js.string a;
u##.size := 60;
Dom.appendChild container t;
Dom.appendChild container u;
let btn_text = document##createTextNode (Js.string "Remove") in
let btn = Dom_html.createButton document in
let f _ =
container##parentNode >>= fun x ->
container##.parentNode >>= fun x ->
Dom.removeChild x container;
return ()
in
btn##onclick <- handler f;
btn##.onclick := handler f;
Dom.appendChild btn btn_text;
Dom.appendChild container btn;
let insert_text = document##createTextNode (Js.string "Insert") in
let insert_btn = Dom_html.createButton document in
let f _ =
let x = createAnswer "" in
container##parentNode >>= fun p ->
container##.parentNode >>= fun p ->
Dom.insertBefore p x (Js.some container);
return ()
in
insert_btn##onclick <- handler f;
insert_btn##.onclick := handler f;
Dom.appendChild insert_btn insert_text;
Dom.appendChild container insert_btn;
container
......@@ -122,28 +122,28 @@ let rec createQuestion q =
Dom.appendChild x t;
let h_question = Dom_html.createInput document in
Dom.appendChild x h_question;
h_question##className <- Js.string "question_question";
h_question##size <- 60;
h_question##value <- Js.string q.q_question;
h_question##.className := Js.string "question_question";
h_question##.size := 60;
h_question##.value := Js.string q.q_question;
let remove_text = document##createTextNode (Js.string "Remove") in
let remove_btn = Dom_html.createButton document in
let f _ =
container##parentNode >>= fun x ->
container##.parentNode >>= fun x ->
Dom.removeChild x container;
return ()
in
remove_btn##onclick <- handler f;
remove_btn##.onclick := handler f;
Dom.appendChild remove_btn remove_text;
Dom.appendChild x remove_btn;
let insert_text = document##createTextNode (Js.string "Insert") in
let insert_btn = Dom_html.createButton document in
let f _ =
let x = createQuestion {q_question=""; q_blank=None; q_min=0; q_max=1; q_answers=[||]} in
container##parentNode >>= fun p ->
container##.parentNode >>= fun p ->
Dom.insertBefore p x (Js.some container);
return ()
in
insert_btn##onclick <- handler f;
insert_btn##.onclick := handler f;
Dom.appendChild insert_btn insert_text;
Dom.appendChild x insert_btn;
Dom.appendChild container x;
......@@ -153,31 +153,31 @@ let rec createQuestion q =
Dom.appendChild x t;
let h_min = Dom_html.createInput document in
Dom.appendChild x h_min;
h_min##className <- Js.string "question_min";
h_min##size <- 5;
h_min##value <- Js.string (string_of_int q.q_min);
h_min##.className := Js.string "question_min";
h_min##.size := 5;
h_min##.value := Js.string (string_of_int q.q_min);
let t = document##createTextNode (Js.string " and ") in
Dom.appendChild x t;
let h_max = Dom_html.createInput document in
Dom.appendChild x h_max;
h_max##className <- Js.string "question_max";
h_max##size <- 5;
h_max##value <- Js.string (string_of_int q.q_max);
h_max##.className := Js.string "question_max";
h_max##.size := 5;
h_max##.value := Js.string (string_of_int q.q_max);
let t = document##createTextNode (Js.string " answers.") in
Dom.appendChild x t;
Dom.appendChild container x;
(* is blank allowed? *)
let x = Dom_html.createDiv document in
let h_blank = Dom_html.createInput ~_type:(Js.string "checkbox") document in
h_blank##className <- Js.string "question_blank";
h_blank##checked <- Js.(match q.q_blank with Some true -> _true | _ -> _false);
h_blank##.className := Js.string "question_blank";
h_blank##.checked := Js.(match q.q_blank with Some true -> _true | _ -> _false);
Dom.appendChild x h_blank;
let t = document##createTextNode (Js.string "Blank vote is allowed") in
Dom.appendChild x t;
Dom.appendChild container x;
(* answers *)
let h_answers = Dom_html.createDiv document in
h_answers##className <- Js.string "question_answers";
h_answers##.className := Js.string "question_answers";
Dom.appendChild container h_answers;
Array.iter
(fun a ->
......@@ -192,7 +192,7 @@ let rec createQuestion q =
let x = createAnswer "" in
Dom.appendChild h_answers x
in
b##onclick <- handler f;
b##.onclick := handler f;
Dom.appendChild b t;
Dom.appendChild x b;
Dom.appendChild container x;
......@@ -206,33 +206,33 @@ let createTemplate template =
let container = Dom_html.createDiv document in
(* name *)
let x = Dom_html.createDiv document in
x##style##display <- Js.string "none";
x##.style##.display := Js.string "none";
let t = document##createTextNode (Js.string "Name of the election: ") in
Dom.appendChild x t;
let h_name = Dom_html.createInput document in
h_name##id <- Js.string "election_name";
h_name##value <- Js.string template.t_name;
h_name##.id := Js.string "election_name";
h_name##.value := Js.string template.t_name;
Dom.appendChild x h_name;
Dom.appendChild container x;
(* description *)
let x = Dom_html.createDiv document in
x##style##display <- Js.string "none";
x##.style##.display := Js.string "none";
let y = Dom_html.createDiv document in
let t = document##createTextNode (Js.string "Description:") in
Dom.appendChild y t;
Dom.appendChild x y;
let y = Dom_html.createDiv document in
let h_description = Dom_html.createTextarea document in
h_description##id <- Js.string "election_description";
h_description##value <- Js.string template.t_description;
h_description##cols <- 80;
h_description##.id := Js.string "election_description";
h_description##.value := Js.string template.t_description;
h_description##.cols := 80;
Dom.appendChild y h_description;
Dom.appendChild x y;
Dom.appendChild container x;
(* questions *)
let x = Dom_html.createDiv document in
let h_questions_div = Dom_html.createDiv document in
h_questions_div##id <- Js.string "election_questions";
h_questions_div##.id := Js.string "election_questions";
Dom.appendChild x h_questions_div;
Dom.appendChild container x;
Array.iter
......@@ -248,7 +248,7 @@ let createTemplate template =
let x = createQuestion {q_question=""; q_blank=None; q_min=0; q_max=1; q_answers=[||]} in
Dom.appendChild h_questions_div x
in
b##onclick <- handler f;
b##.onclick := handler f;
Dom.appendChild b t;
Dom.appendChild x b;
Dom.appendChild container x;
......@@ -264,13 +264,13 @@ let createTemplate template =
set_textarea "questions" (string_of_template template);
document##querySelector (Js.string "form") >>= fun x ->
Dom_html.CoerceTo.form x >>= fun x ->
x##submit ();
let () = x##submit in
return ()
with Failure e ->
alert e;
return ()
in
b##onclick <- handler f;
b##.onclick := handler f;
Dom.appendChild b t;
Dom.appendChild x b;
Dom.appendChild container x;
......@@ -285,8 +285,8 @@ let fill_interactivity _ =
let div = createTemplate t in
Dom.appendChild e div;
document##querySelector (Js.string "form") >>= fun x ->
x##style##display <- Js.string "none";
x##.style##.display := Js.string "none";
return ()
let () =
Dom_html.window##onload <- handler fill_interactivity;
Dom_html.window##.onload := handler fill_interactivity;
......@@ -41,11 +41,11 @@ let fill_interactivity _ =
(fun e ->
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string "Generate a new keypair") in
b##onclick <- Dom_html.handler tkeygen;
b##.onclick := Dom_html.handler tkeygen;
Dom.appendChild b t;
Dom.appendChild e b;
);
Js._false
let () =
Dom_html.window##onload <- Dom_html.handler fill_interactivity;
Dom_html.window##.onload := Dom_html.handler fill_interactivity;
......@@ -33,7 +33,7 @@ let gen_cert e _ =
let module T = Trustees.MakePedersen (G) (DirectRandom) (P) (C) in
let key, cert = T.step1 () in
let id = sha256_hex cert.s_message in
e##innerHTML <- Js.string "";
e##.innerHTML := Js.string "";
let t = document##createTextNode (Js.string (Printf.sprintf "Certificate %s has been generated!" id)) in
Dom.appendChild e t;
set_download "private_key" "text/plain" "private_key.txt" key;
......@@ -46,7 +46,7 @@ let proceed step e textarea _ =
let group = get_textarea "group" in
let key =
let r = ref "" in
Js.Opt.iter (Dom_html.CoerceTo.textarea textarea) (fun x -> r := Js.to_string x##value);
Js.Opt.iter (Dom_html.CoerceTo.textarea textarea) (fun x -> r := Js.to_string x##.value);
!r
in
let certs = certs_of_string (get_textarea "certs") in
......@@ -58,14 +58,14 @@ let proceed step e textarea _ =
match step with
| 3 ->
let polynomial = T.step3 certs key threshold in
e##innerHTML <- Js.string "";
e##.innerHTML := Js.string "";
set_textarea "data" (string_of_polynomial polynomial);
Js._false
| 5 ->
let vinput = get_textarea "vinput" in
let vinput = vinput_of_string vinput in
let voutput = T.step5 certs key vinput in
e##innerHTML <- Js.string "";
e##.innerHTML := Js.string "";
set_textarea "data" (string_of_voutput G.write voutput);
Js._false
| _ ->
......@@ -93,7 +93,7 @@ let fill_interactivity _ =
| 1 ->
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string "Generate private key") in
b##onclick <- Dom_html.handler (gen_cert e);
b##.onclick := Dom_html.handler (gen_cert e);
Dom.appendChild b t;
Dom.appendChild e b;
| 3 | 5 ->
......@@ -101,13 +101,13 @@ let fill_interactivity _ =
let t = document##createTextNode (Js.string "Private key: ") in
Dom.appendChild div t;
let textarea = Dom_html.createTextarea document in
textarea##rows <- 1;
textarea##cols <- 25;
textarea##.rows := 1;
textarea##.cols := 25;
Dom.appendChild div textarea;
Dom.appendChild e div;
let b = document##createElement (Js.string "button") in
let t = document##createTextNode (Js.string "Proceed") in
b##onclick <- Dom_html.handler (proceed step e textarea);