<commit_before>(* Copyright <NAME>, <NAME> *)

(** This module defines generic widgets used by Myproject
    (but not generic enough to be in the widget library)
*)


{shared{
open Eliom_content
open Eliom_content.Html5
open Eliom_content.Html5.F

let (>>=) = Lwt.bind
let (>|=) = Lwt.(>|=)
}}

(********************************************)
(** Small widgets *)


{server{

module Eba_fm = Eba_flash_message

(** Login box *)

let connection_box service =
  let r = ref None in
  let f = D.post_form
    ~a:[a_id "ol_connectionbox"]
    ~service
    (fun (loginname, pwdname) ->
      let i = D.string_input
        ~a:[a_placeholder "e-mail address"]
        ~input_type:`Email ~name:loginname ()
      in
      r := Some i;
      [i;
       string_input
         ~a:[a_placeholder "password"]
         ~input_type:`Password ~name:pwdname ();
       string_input
         ~input_type:`Submit ~value:"connect" ();
      ])
    ()
  in
  f, match !r with Some i -> i | None -> failwith "connection_box"

let email_box service =
  let r = ref None in
  let f = D.post_form
    ~a:[a_id "ol_activationemail";
        a_style "display: none"]
    ~service
    (fun fieldname ->
      let i = D.string_input
         ~a:[a_placeholder "e-mail address"]
         ~input_type:`Email ~name:fieldname ()
      in
      r := Some i;
      [label [pcdata "Enter your e-mail address to receive an activation link"];
       i;
       string_input
         ~input_type:`Submit ~value:"confirm" ();
      ])
    ()
  in
  f, match !r with Some i -> i | None -> failwith "email_box"

 }}

{shared{
type restr_show_hide_focus =
  < press : unit Lwt.t;
    unpress : unit Lwt.t;
    on_press : unit Lwt.t;
    on_unpress : unit Lwt.t;
    on_pre_press : unit Lwt.t;
    on_pre_unpress : unit Lwt.t;
    on_post_press : unit Lwt.t;
    on_post_unpress : unit Lwt.t;
    switch: unit Lwt.t;
    pressed: bool;
    >
}}

{server{

let login_signin_box
      connection_service
      lost_password_service
      sign_up_service
      preregister_service
      ()
      =
  let id = "ol_login_signup_box" in
  if Eliom_reference.Volatile.get Eba_sessions.activationkey_created
  then
    Lwt.return
      (D.div ~a:[a_id id]
         [p [pcdata "An email has been sent to this address.";
             br();
             pcdata "Click on the link it contains to log in."]])
  else
    let set = {(Ew_button.radio_set_t){
      Ew_button.new_radio_set ()
    }} in
    let button1 = D.h2 [pcdata "Login"] in
    let form1, i1 = connection_box connection_service in
    let o1 = {restr_show_hide_focus{
      new Ew_button.show_hide
        ~pressed:true
        ~set:%set ~button:%button1
        ~button_closeable:false
        %form1
    }}
    in
    let button2 = D.h2 [pcdata "Lost password"] in
    let form2, i2 = email_box lost_password_service in
    let o2 = {restr_show_hide_focus{
      new Ew_button.show_hide
        ~set:%set ~button:%button2
        ~button_closeable:false
        %form2
    }}
    in
      (*
    let button3 = D.h2 [pcdata "Preregister"] in
    let form3, i3 = Eba_preregister.preregister_box preregister_service in
    let o3 = {restr_show_hide_focus{
      new show_hide_focus
        ~set:%set ~button:(To_dom.of_h2 %button3)
        ~button_closeable:false
        ~focused:(To_dom.of_input %i3) (To_dom.of_form %form3)
    }}
    in
       *)
    let button4 = D.h2 [pcdata "Register"] in
    let form4, i4 = email_box sign_up_service in
    let o4 = {restr_show_hide_focus{
      new Ew_button.show_hide
        ~set:%set ~button:%button4
        ~button_closeable:false
        %form4
    }}
    in
    (* function to press the corresponding button and display
     * the flash message error.
     * [d] is currently an server value, so we need to use % *)
    let press o d msg =
      ignore {unit{
        let d = To_dom.of_div %d in
        let msg = To_dom.of_p (p ~a:[a_class ["ol_error"]] [pcdata %msg]) in
          ignore ((%o)#press);
          Dom.appendChild d msg;
          ignore
            (lwt () = Lwt_js.sleep 2. in<commit_msg>Adapt to new ojwidgets<commit_after>(* Copyright <NAME>, <NAME> *)

(** This module defines generic widgets used by Myproject
    (but not generic enough to be in the widget library)
*)


{shared{
open Eliom_content
open Eliom_content.Html5
open Eliom_content.Html5.F

let (>>=) = Lwt.bind
let (>|=) = Lwt.(>|=)
}}

(********************************************)
(** Small widgets *)


{server{

module Eba_fm = Eba_flash_message

(** Login box *)

let connection_box service =
  let r = ref None in
  let f = D.post_form
    ~a:[a_id "ol_connectionbox"]
    ~service
    (fun (loginname, pwdname) ->
      let i = D.string_input
        ~a:[a_placeholder "e-mail address"]
        ~input_type:`Email ~name:loginname ()
      in
      r := Some i;
      [i;
       string_input
         ~a:[a_placeholder "password"]
         ~input_type:`Password ~name:pwdname ();
       string_input
         ~input_type:`Submit ~value:"connect" ();
      ])
    ()
  in
  f, match !r with Some i -> i | None -> failwith "connection_box"

let email_box service =
  let r = ref None in
  let f = D.post_form
    ~a:[a_id "ol_activationemail";
        a_style "display: none"]
    ~service
    (fun fieldname ->
      let i = D.string_input
         ~a:[a_placeholder "e-mail address"]
         ~input_type:`Email ~name:fieldname ()
      in
      r := Some i;
      [label [pcdata "Enter your e-mail address to receive an activation link"];
       i;
       string_input
         ~input_type:`Submit ~value:"confirm" ();
      ])
    ()
  in
  f, match !r with Some i -> i | None -> failwith "email_box"

 }}

{shared{
type restr_show_hide_focus =
  < press : unit Lwt.t;
    unpress : unit Lwt.t;
    on_press : unit Lwt.t;
    on_unpress : unit Lwt.t;
    on_pre_press : unit Lwt.t;
    on_pre_unpress : unit Lwt.t;
    on_post_press : unit Lwt.t;
    on_post_unpress : unit Lwt.t;
    switch: unit Lwt.t;
    pressed: bool;
    >
}}

{server{

let login_signin_box
      connection_service
      lost_password_service
      sign_up_service
      preregister_service
      ()
      =
  let id = "ol_login_signup_box" in
  if Eliom_reference.Volatile.get Eba_sessions.activationkey_created
  then
    Lwt.return
      (D.div ~a:[a_id id]
         [p [pcdata "An email has been sent to this address.";
             br();
             pcdata "Click on the link it contains to log in."]])
  else
    let set = {(Ew_button.radio_set_t){
      Ew_button.new_radio_set ()
    }} in
    let button1 = D.h2 [pcdata "Login"] in
    let form1, i1 = connection_box connection_service in
    let o1 = {restr_show_hide_focus{
      new Ew_button.show_hide
        ~pressed:true
        ~set:%set ~button:%button1
        ~closeable_by_button:false
        %form1
    }}
    in
    let button2 = D.h2 [pcdata "Lost password"] in
    let form2, i2 = email_box lost_password_service in
    let o2 = {restr_show_hide_focus{
      new Ew_button.show_hide
        ~set:%set ~button:%button2
        ~closeable_by_button:false
        %form2
    }}
    in
      (*
    let button3 = D.h2 [pcdata "Preregister"] in
    let form3, i3 = Eba_preregister.preregister_box preregister_service in
    let o3 = {restr_show_hide_focus{
      new show_hide_focus
        ~set:%set ~button:(To_dom.of_h2 %button3)
        ~closeable_by_button:false
        ~focused:(To_dom.of_input %i3) (To_dom.of_form %form3)
    }}
    in
       *)
    let button4 = D.h2 [pcdata "Register"] in
    let form4, i4 = email_box sign_up_service in
    let o4 = {restr_show_hide_focus{
      new Ew_button.show_hide
        ~set:%set ~button:%button4
        ~closeable_by_button:false
        %form4
    }}
    in
    (* function to press the corresponding button and display
     * the flash message error.
     * [d] is currently an server value, so we need to use % *)
    let press o d msg =
      ignore {unit{
        let d = To_dom.of_div %d in
        let msg = To_dom.of_p (p ~a:[a_class ["ol_error"]] [pcdata %msg]) in
          ignore ((%o)#press);
          Dom.appendChild d msg;
          ignore
            (lwt () = Lwt_js.sleep 2. in
{'fraction_non_alphanumeric': 0.11921991904820312, 'fraction_numerical': 0.008095179688458236, 'mean_word_length': 2.406015037593985, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3356746', 'n_tokens_mistral': 2864, 'n_tokens_neox': 2808, 'n_words': 748}