summaryrefslogtreecommitdiff
path: root/editor/actions/export.ml
diff options
context:
space:
mode:
Diffstat (limited to 'editor/actions/export.ml')
-rwxr-xr-xeditor/actions/export.ml46
1 files changed, 46 insertions, 0 deletions
diff --git a/editor/actions/export.ml b/editor/actions/export.ml
new file mode 100755
index 0000000..a97eeac
--- /dev/null
+++ b/editor/actions/export.ml
@@ -0,0 +1,46 @@
+module Js = Js_of_ocaml.Js
+
+module M = struct
+
+ type t = unit
+
+ let update
+ : t -> State.t -> State.t
+ = fun _ state ->
+
+ (* Save this as a json element. The text may contains UTF-16 characters,
+ which will raise an error in the btoa function.
+
+ As an easy solution, we convert them into UTF-8 through the native
+ OCaml representation of string.
+ *)
+ let json = State.Storage.to_json ()
+ |> Jstr.to_string (* Encode into UTF-8 *)
+ |> Obj.magic (* Then type the element again as a string. *)
+ in
+ Elements.Transfert.send
+ ~mime_type:(Jstr.v "application/json")
+ ~filename:(Jstr.v "export.json")
+ json;
+
+ (* The function does not actually update the state, and return it
+ unchanged *)
+ state
+
+end
+
+(** Create a new element *)
+let create
+ : unit -> State.event Note.event
+ = fun () ->
+ let title = Jstr.v "Confirmation"
+ and message = Jstr.v "Exporter les notes" in
+ let ev = Elements.Popup.create
+ ~title
+ ~form:(Some (Forms.Validation.create message ))
+ in
+ Note.E.map
+ (fun v -> State.E
+ ( v
+ , (module M : State.Event with type t = M.t )))
+ (Note.E.Option.on_some ev)