aboutsummaryrefslogtreecommitdiff
path: root/editor/forms
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-05-23 22:09:50 +0200
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:43:33 +0100
commit1eeaf137bd30aff1bef34d05eeec686f6da8959d (patch)
tree63589546a32b72382e94f1ee16cf671cec911648 /editor/forms
parent97f3ac8054de22b94e4ae169dae33ed5b1b41a52 (diff)
Update editor
Diffstat (limited to 'editor/forms')
-rwxr-xr-xeditor/forms/add_page.ml1
-rwxr-xr-xeditor/forms/delete_page.ml6
-rwxr-xr-xeditor/forms/events.ml5
-rwxr-xr-xeditor/forms/ui.ml75
4 files changed, 81 insertions, 6 deletions
diff --git a/editor/forms/add_page.ml b/editor/forms/add_page.ml
index 9786f47..edcbc37 100755
--- a/editor/forms/add_page.ml
+++ b/editor/forms/add_page.ml
@@ -62,4 +62,3 @@ let create
[ input ]
]
] )
-
diff --git a/editor/forms/delete_page.ml b/editor/forms/delete_page.ml
index 7c973c2..eb36560 100755
--- a/editor/forms/delete_page.ml
+++ b/editor/forms/delete_page.ml
@@ -26,12 +26,10 @@ let create
let message = begin
let open Jstr in
- (v "La page " )
+ (v "La page ")
+ name
+ (v " sera définitivement supprimée")
end in
( state
- , El.txt message
- )
-
+ , El.txt message )
diff --git a/editor/forms/events.ml b/editor/forms/events.ml
index a88aa76..28780d9 100755
--- a/editor/forms/events.ml
+++ b/editor/forms/events.ml
@@ -8,5 +8,8 @@ end
type event = Event : 'a * (module Handler with type t = 'a) -> event
-(** The signal has to be log in order to be completely working *)
+(* The type is both the form handler, the form value, and the HTML element
+ which contains the form.
+
+ The signal has to be log in order to be completely working. *)
type t = event Note.signal * Brr.El.t
diff --git a/editor/forms/ui.ml b/editor/forms/ui.ml
new file mode 100755
index 0000000..d8a259a
--- /dev/null
+++ b/editor/forms/ui.ml
@@ -0,0 +1,75 @@
+open Brr
+open Brr_note
+module Js = Js_of_ocaml.Js
+
+let popup
+ : title:Jstr.t -> ?form:Events.t option -> Events.event option Note.E.send -> El.t
+ = fun ~title ?(form = None) send ->
+
+ (* Ensure we keep a track for the signal event.
+
+ This looks a bit like the old memory magment in C, as it require to
+ destroy the logger each time the popup is removed. *)
+ let log_opt = Option.map
+ (fun (values, _) -> Note.S.log values (fun _ -> ()))
+ form in
+
+ let close_btn =
+ El.span
+ ~at:At.[class' (Jstr.v "modal-close")]
+ [ El.txt' "×"] in
+
+ Evr.endless_listen
+ (El.as_target close_btn)
+ Ev.click
+ (fun _ ->
+ Option.iter Note.Logr.destroy log_opt;
+ send None
+ );
+
+ let container = match form with
+ | None -> El.div
+ | Some _ -> El.form
+
+ and body = match form with
+ | None -> El.div []
+ | Some (_, content) -> content
+
+ and footer = match form with
+ | None -> El.txt Jstr.empty
+ | Some (values, _) ->
+
+ let btn = El.input ()
+ ~at:At.[type' (Jstr.v "submit")] in
+
+ Evr.endless_listen
+ (El.as_target btn)
+ Ev.click
+ (fun _ ->
+ Option.iter Note.Logr.force log_opt;
+ let form_content = (Note.S.value values) in
+ Option.iter Note.Logr.destroy log_opt;
+ send (Some form_content));
+
+ El.div [ btn ]
+ ~at:At.[class' (Jstr.v "row")] in
+
+ let el = El.div
+ ~at:At.[class' (Jstr.v "modal")]
+ [ container
+ ~at:At.[class' (Jstr.v "modal-content")]
+ [ El.div
+ ~at:At.[class' (Jstr.v "modal-header")]
+ [ close_btn
+ ; El.h3
+ [ El.txt title ]]
+ ; El.div
+ ~at:At.[class' (Jstr.v "modal-body")]
+ [ body ]
+ ; El.div
+ ~at:At.[class' (Jstr.v "modal-footer")]
+ [ footer ]]] in
+
+ El.append_children (Document.body G.document)
+ [ el ]
+ ; el