let frontend_resource_types : enum_type list = [
mk_enum_type
~enum_prefix:"Button"
~type_name:"user_buttons"
[
"Logout", FtUserLogin;
"ChangePasswordShowDialog", FtUserSettings;
"ChangePasswordComplete", FtUserSettings;
];
...
]
type user_buttons =
| ButtonLogout
| ButtonChangePasswordShowDialog
| ButtonChangePasswordComplete
let all_user_buttons = [
ButtonLogout;
ButtonChangePasswordShowDialog;
ButtonChangePasswordComplete;
]
let user_button_to_name =
function
| ButtonLogout -> "Logout"
| ButtonChangePasswordShowDialog -> "Change password"
| ButtonChangePasswordComplete -> "Password change complete"
...
let user_button_to_html
?(enabled = true)
?(data_id = "")
?(custom_callback = _blank_custom_callback)
(btn: user_buttons) =
...
let default_template () =
Printf.sprintf {|
<a %s data-class="%s" data-tag="%s" onclick="callbacks.onButtonClick(this, '%s', '%s')"
class="waves-effect waves-light btn %s">%s</a>
|} maybe_id btn_id data_id btn_id data_id disabled_class name
in
match btn with
| ButtonLikeMessage ->
Printf.sprintf {|
<a data-class="%s" data-tag="%s" href="#!" onclick="callbacks.onButtonClick(this, '%s', '%s')" class="%s">%s</a>
|} btn_id data_id btn_id data_id disabled_class name
let on_button_click (dom_elem: Js_of_ocaml.Dom_html.element Js.t) the_btn the_id = (
...
match the_btn with
| ButtonLogout -> (
clear_session_cookies_and_refresh ()
)
str_gen_basic (fun append_string ->
user_button_to_html ButtonLogout |> append_string
)