diff options
Diffstat (limited to 'editor/forms')
-rwxr-xr-x | editor/forms/add_page.ml | 40 | ||||
-rwxr-xr-x | editor/forms/add_page.mli | 5 | ||||
-rwxr-xr-x | editor/forms/delete_page.ml | 27 | ||||
-rwxr-xr-x | editor/forms/delete_page.mli | 5 | ||||
-rwxr-xr-x | editor/forms/events.ml | 15 | ||||
-rwxr-xr-x | editor/forms/ui.ml | 58 |
6 files changed, 51 insertions, 99 deletions
diff --git a/editor/forms/add_page.ml b/editor/forms/add_page.ml index edcbc37..08fb5d7 100755 --- a/editor/forms/add_page.ml +++ b/editor/forms/add_page.ml @@ -1,34 +1,10 @@ open Brr open Brr_note -open Note -module Js = Js_of_ocaml.Js - -module Handler = struct - - type t = { title : Jstr.t } - - let key_of_title - : Jstr.t -> Jstr.t - = fun title -> - title - - let on_close - : t -> State.t -> State.t - = fun {title} state -> - let page_id = key_of_title title in - let new_date = (new%js Js.date_now)##getTime in - let content_obj = object%js - val content = Js.null - val title = Js.some title - val date = Js.some new_date - end in - State.load_page (Some page_id) state content_obj - -end +type t = { title : Jstr.t } let create - : unit -> Events.t + : unit -> t Note.signal * El.t = fun () -> (* The element which contains the information *) @@ -37,18 +13,14 @@ let create in let init = - Events.Event - ( Handler.{ title = Jstr.empty } - , (module Handler : Events.Handler with type t = Handler.t)) in + ( { title = Jstr.empty } + ) in let state = - S.hold init + Note.S.hold init @@ Evr.on_el (Ev.input) - (fun _ -> - Events.Event - ( Handler.{ title = El.prop El.Prop.value input } - , (module Handler : Events.Handler with type t = Handler.t)) ) + (fun _ -> { title = El.prop El.Prop.value input }) input in ( state diff --git a/editor/forms/add_page.mli b/editor/forms/add_page.mli index 8a4ff6f..10badd6 100755 --- a/editor/forms/add_page.mli +++ b/editor/forms/add_page.mli @@ -1,2 +1,5 @@ +type t = { title : Jstr.t } + val create - : unit -> Events.t + : unit -> t Note.signal * Brr.El.t + diff --git a/editor/forms/delete_page.ml b/editor/forms/delete_page.ml index eb36560..37b1c32 100755 --- a/editor/forms/delete_page.ml +++ b/editor/forms/delete_page.ml @@ -1,34 +1,17 @@ open Brr open Note -module Handler = struct - - type t = Jstr.t - - let on_close - : t -> State.t -> State.t - = fun id state -> - State.Storage.delete (fun () -> Some id); - let json = State.Storage.load None in - State.load_page None state json -end +type t = unit let create - : Jstr.t -> Events.t - = fun name -> - - let state = - S.const - (Events.Event - ( name - , (module Handler: Events.Handler with type t = Handler.t))) in + : unit -> t Note.signal * El.t + = fun () -> + let state = S.const () in let message = begin let open Jstr in - (v "La page ") - + name - + (v " sera définitivement supprimée") + (v "La page sera définitivement supprimée") end in ( state diff --git a/editor/forms/delete_page.mli b/editor/forms/delete_page.mli new file mode 100755 index 0000000..0a3d9f9 --- /dev/null +++ b/editor/forms/delete_page.mli @@ -0,0 +1,5 @@ +type t = unit + +val create + : unit -> t Note.signal * Brr.El.t + diff --git a/editor/forms/events.ml b/editor/forms/events.ml deleted file mode 100755 index 28780d9..0000000 --- a/editor/forms/events.ml +++ /dev/null @@ -1,15 +0,0 @@ -module type Handler = sig - - type t - - val on_close: t -> State.t -> State.t - -end - -type event = Event : 'a * (module Handler with type t = 'a) -> event - -(* 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 index d8a259a..53039c4 100755 --- a/editor/forms/ui.ml +++ b/editor/forms/ui.ml @@ -3,8 +3,8 @@ 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 -> + : ?form:('a Note.signal * El.t) option -> title:Jstr.t -> 'a option Note.event + = fun ?(form = None) ~title -> (* Ensure we keep a track for the signal event. @@ -17,15 +17,10 @@ let popup let close_btn = El.span ~at:At.[class' (Jstr.v "modal-close")] - [ El.txt' "×"] in + [ El.txt' "×"] - Evr.endless_listen - (El.as_target close_btn) - Ev.click - (fun _ -> - Option.iter Note.Logr.destroy log_opt; - send None - ); + and submit_btn = El.input () + ~at:At.[type' (Jstr.v "submit")] in let container = match form with | None -> El.div @@ -37,23 +32,12 @@ let popup and footer = match form with | None -> El.txt Jstr.empty - | Some (values, _) -> + | Some _ -> - 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 ] + El.div [ submit_btn ] ~at:At.[class' (Jstr.v "row")] in + (* HTML Element creation *) let el = El.div ~at:At.[class' (Jstr.v "modal")] [ container @@ -70,6 +54,26 @@ let popup ~at:At.[class' (Jstr.v "modal-footer")] [ footer ]]] in - El.append_children (Document.body G.document) - [ el ] - ; el + let () = El.append_children (Document.body G.document) + [ el ] in + + (* Event handler *) + let close_event = Evr.on_el + Ev.click + (fun _ -> + El.remove el; + Option.iter Note.Logr.destroy log_opt; + None) + close_btn + + and submit_event = Evr.on_el + Ev.click + (fun _ -> + El.remove el; + Option.iter Note.Logr.destroy log_opt; + Option.map (fun v -> Note.S.value (fst v)) form) + submit_btn in + + Note.E.select + [ close_event + ; submit_event ] |