diff options
Diffstat (limited to 'editor/actions')
-rwxr-xr-x | editor/actions/delete_page.ml | 7 | ||||
-rwxr-xr-x | editor/actions/dune | 3 | ||||
-rwxr-xr-x | editor/actions/editor_actions.ml (renamed from editor/actions/actions.ml) | 59 | ||||
-rwxr-xr-x | editor/actions/export.ml | 46 |
4 files changed, 90 insertions, 25 deletions
diff --git a/editor/actions/delete_page.ml b/editor/actions/delete_page.ml index 9086fc3..fb600bd 100755 --- a/editor/actions/delete_page.ml +++ b/editor/actions/delete_page.ml @@ -17,10 +17,13 @@ end let create : unit -> State.event Note.event = fun () -> - let title = Jstr.v "Confirmation" in + let title = Jstr.v "Confirmation" + and message = + Jstr.v "La page sera définitivement supprimée" + in let ev = Elements.Popup.create ~title - ~form:(Some (Forms.Delete_page.create () )) + ~form:(Some (Forms.Validation.create message )) in Note.E.map (fun v -> State.E diff --git a/editor/actions/dune b/editor/actions/dune index 5d269c4..4044b52 100755 --- a/editor/actions/dune +++ b/editor/actions/dune @@ -1,11 +1,10 @@ (library - (name actions) + (name editor_actions) (libraries brr brr.note elements blog - js_lib forms state ) diff --git a/editor/actions/actions.ml b/editor/actions/editor_actions.ml index f35beef..8c47363 100755 --- a/editor/actions/actions.ml +++ b/editor/actions/editor_actions.ml @@ -3,14 +3,8 @@ open Js_of_ocaml open Brr open Brr_note -type button_actions = - { delete : State.event Note.event - ; redirect : State.event Note.event - ; add: State.event Note.event - } - let populate_menu - : unit -> button_actions option + : unit -> State.event Note.event option = fun () -> match Blog.Sidebar.get () with | None -> None @@ -38,6 +32,24 @@ let populate_menu ~at:At.[ class' (Jstr.v "fa") ; class' (Jstr.v "fa-2x") ; class' (Jstr.v "fa-plus") ] ] + + and export_button = El.button + ~at:At.[class' (Jstr.v "action-button")] + [ El.i + [] + ~at:At.[ class' (Jstr.v "fa") + ; class' (Jstr.v "fa-2x") + ; class' (Jstr.v "fa-download") ] + ] + + and load_button = El.button + ~at:At.[class' (Jstr.v "action-button")] + [ El.i + [] + ~at:At.[ class' (Jstr.v "fa") + ; class' (Jstr.v "fa-2x") + ; class' (Jstr.v "fa-upload") ] + ] in (* We are waiting for event inside another event ( form validation inside @@ -57,7 +69,15 @@ let populate_menu Evr.on_el Ev.click (fun _ -> Add_page.create ()) - add_button) in + add_button) + + and export_event = + Note.E.join ( + Evr.on_el + Ev.click + (fun _ -> Export.create ()) + export_button) + in let stored_pages = State.Storage.get_ids () in @@ -103,14 +123,8 @@ let populate_menu let childs = [ home_button ; add_button - ; El.button - ~at:At.[class' (Jstr.v "action-button")] - [ El.i - [] - ~at:At.[ class' (Jstr.v "fa") - ; class' (Jstr.v "fa-2x") - ; class' (Jstr.v "fa-download") ] - ] + ; export_button + ; load_button ; delete_button ; El.button ~at:At.[class' (Jstr.v "action-button")] @@ -126,8 +140,11 @@ let populate_menu ] in let () = El.append_children element childs in - Some - { delete = delete_event - ; redirect = redirect_event - ; add = add_event - } + + Some ( + Note.E.select + [ delete_event + ; redirect_event + ; add_event + ; export_event + ]) 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) |