From 0a3b5fb134307526981ed6818f36f2cf69f402c1 Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 5 Dec 2021 21:33:55 +0100 Subject: [PATCH] [+] add left_menu_entry_js to call javascript when a click event occur on menu entry. Add also variant function as helper without all the arguments --- web/widgets/left_menu.anubis | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ web/widgets/left_menu_html.anubis | 5 +++++ 2 files changed, 57 insertions(+), 0 deletions(-) diff --git a/web/widgets/left_menu.anubis b/web/widgets/left_menu.anubis index 8a9e61d..29eb90d 100644 --- a/web/widgets/left_menu.anubis +++ b/web/widgets/left_menu.anubis @@ -20,6 +20,14 @@ public type Left_Menu_Entry: List((String, String)) extra, //extra web arguments to send when click Maybe(String) target_id //target_id use during load_content ), + left_menu_entry_js( //MENU entry with call to js + String entry_id, //it's also use as icon prefix + Bool sub_entry, + List(String) classes, //additional classes if need (for disabling entry, change background color, etc.) + String js_call, //javascript to call on click event + String text //text to show + ), + title( //TITLE entry hence no selectable String title_id, //it's also use as icon prefix Bool subtitle, @@ -298,3 +306,47 @@ public define Left_Menu_Entry )= title(title_id, true, [], text) . + +public define Left_Menu_Entry + left_menu_entry_js + ( + String entry_id, //it's also use as icon prefix + //Bool sub_entry, + //List(String) classes, //additional classes if need (for disabling entry, change background color, etc.) + String js_call, //javascript to call on click event + String text //text to show + )= + left_menu_entry_js(entry_id, false, [], js_call, text). + +public define Left_Menu_Entry + left_menu_sub_entry_js + ( + String entry_id, //it's also use as icon prefix + //Bool sub_entry, + //List(String) classes, //additional classes if need (for disabling entry, change background color, etc.) + String js_call, //javascript to call on click event + String text //text to show + )= + left_menu_entry_js(entry_id, true, [], js_call, text). + +public define Left_Menu_Entry + left_menu_entry_js + ( + String entry_id, //it's also use as icon prefix + //Bool sub_entry, + List(String) classes, //additional classes if need (for disabling entry, change background color, etc.) + String js_call, //javascript to call on click event + String text //text to show + )= + left_menu_entry_js(entry_id, false, classes, js_call, text). + +public define Left_Menu_Entry + left_menu_sub_entry_js + ( + String entry_id, //it's also use as icon prefix + //Bool sub_entry, + List(String) classes, //additional classes if need (for disabling entry, change background color, etc.) + String js_call, //javascript to call on click event + String text //text to show + )= + left_menu_entry_js(entry_id, true, classes, js_call, text). diff --git a/web/widgets/left_menu_html.anubis b/web/widgets/left_menu_html.anubis index dee6a9e..11d8c4f 100644 --- a/web/widgets/left_menu_html.anubis +++ b/web/widgets/left_menu_html.anubis @@ -36,6 +36,11 @@ define List(HTML_Off_Form) event(onclick, load_content(target_id, _action, _extra))],text(_T(_text))), } + left_menu_entry_js(_menu_id, subentry, _classes, _js_to_call, _text) then + with item_class = if subentry then "subitem " else "item ", + p([class(item_class+"clickable "+_menu_id+"_icon"+(if _menu_id=selected then " selected" else "")+ " "+join(" ", _classes)), + event(onclick, _js_to_call)],text(_T(_text))), + title(_title_id, subtitle, _classes, _text) then p([class(if subtitle then "menu_subtitle" else "menu_title"), class((if _title_id=selected then " selected" else "")+ " "+join(" ", _classes))], text([],_T(_text))) // p([class("menu_title"), class("item "+_title_id+"_icon"+if _title_id=selected then " selected" else ""+ " "+join(" ", _classes))], text([],_T(_text))) -- libgit2 0.21.4