From 3b01c02a44ca5cb94ff2fe3d7ca7f658dd2eaefc Mon Sep 17 00:00:00 2001 From: totoro Date: Mon, 8 Jun 2020 11:51:14 +0900 Subject: [PATCH] working version of the Stepper --- web/XL_web_stepper.anubis | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- web/types/XL_web_stepper.anubis | 15 ++++++++++----- 2 files changed, 91 insertions(+), 32 deletions(-) diff --git a/web/XL_web_stepper.anubis b/web/XL_web_stepper.anubis index 31dc999..7b4fde5 100644 --- a/web/XL_web_stepper.anubis +++ b/web/XL_web_stepper.anubis @@ -10,7 +10,9 @@ transmit xlib/web/CXM_jquery.anubis transmit xlib/web/types/XL_web_stepper.anubis transmit xlib/web/controllers_web_site.anubis read xlib/web/CXM_page_message.anubis +read xlib/web/jQuery/CXM_jquery_button.anubis read xlib/web_controllers/language/language_management.anubis +read xlib/web/widgets/icons_set.anubis public define Maybe(WEB_Stepper) get_stepper_by_uid @@ -87,20 +89,24 @@ public define HTML_Partial_Content web_stepper_button ( WEB_Step _step, - WEB_Step_Session stp_session + WEB_Step_Session stp_session, + (String)->String _T )= - partial_content(div(class("steppers_buttons"), _step.buttons(stp_session))) + partial_content( + div(class("stepper_buttons"), + _step.buttons(stp_session, _T))) . public define HTML_Partial_Content web_stepper_main_view ( WEB_Step _step, - WEB_Step_Session stp_session + WEB_Step_Session stp_session, + (String)->String _T )= partial_content( div(class("stepper_main_view"), - _step.view(stp_session))) + _step.view(stp_session, _T))) . public define HTML_Partial_Content @@ -109,40 +115,54 @@ public define HTML_Partial_Content WEB_Step_Session stp_session, (String)->String _T )= - partial_content(div(class("stepper_message"), show_page_message(get_Page_Message(stp_session.session.fields, _T)))) + with page_msg = get_Page_Message(stp_session.session.fields, _T), + //if there is no message return empty to avoid to have an empty div with padding + if page_msg = no_message then + partial_empty + else + partial_content( + div(class("stepper_message"), + show_page_message(page_msg))) . public define HTML_Partial_Content - web_stepper_name + web_stepper_full_description ( - WEB_Step_Session stp_session + WEB_Step current_step, + (String)->String _T )= - partial_content(empty) + if current_step.full_description = "" then + partial_content(empty) + else + partial_content( + div(class("stepper_full_description"), + text(_T(current_step.full_description)))) . public define Bool is_current ( - WEB_Step step, - WEB_Step_Session stp_session + WEB_Step step, + WEB_Step current_step )= - stp_session.current_step = step.name + current_step.name = step.name . public define Bool is_active ( - WEB_Step step, - WEB_Step_Session stp_session + WEB_Step step, + WEB_Step current_step )= - true + step.index < current_step.index . public define HTML_Partial_Content web_stepper_crumble ( - WEB_Stepper stepper, - WEB_Step_Session stp_session + WEB_Stepper _stepper, + WEB_Step _current_step, + (String) -> String _T )= partial_content( div(class("stepper_crumble"), @@ -150,18 +170,24 @@ public define HTML_Partial_Content ul(class("multi-step-list"), map((WEB_Step step) |-> - with active = if is_active(step, stp_session) then " active" else "", - current = if is_current(step, stp_session) then " current" else "", - - li(class("multi-step-item"+active+current), + with active = if is_active(step, _current_step) then " active" else "", + current = if is_current(step, _current_step) then " current" else "", + with go = if is_active(step, _current_step) then + with url = format_web_action_name_to_js(_stepper.web_controller, [("stepper_uid",_stepper.uid), ("step",step.name), ("step_a", "go")]), + event(onclick, "stepper_go("+url+");") + else + empty, + + li([class("multi-step-item"+active+current), + go], div(class("item-wrap"), p(class("item-title"), - text(step.name) + text(_T(to_upper(step.name))) ) ) ) , - stepper.steps + _stepper.steps ) ) @@ -180,7 +206,9 @@ public define HTML_Partial_Content )= println("web_stepper_view _current_step.name ["+_current_step.name+"]"); - partial_content([css(css_file("xlib/css/stepper.css")), + partial_content([ + css(css_file("xlib/css/stepper.css")), + js(js_file("xlib/js/stepper.js")), js_inline(jquery_ready("$('#stepper_form').on('submit', function(e) { e.stopPropagation(); return false; });")) ], [ div([id("stepper"), class("stepper")], [ @@ -188,11 +216,11 @@ public define HTML_Partial_Content hidden("step", _current_step.name), //add current step name as hidden argument hidden("stepper_uid",_stepper.uid), //add stepper_uid as hidden argument //construct bread crumb line - partial(web_stepper_crumble(_stepper, stp_session)), - partial(web_stepper_name(stp_session)), + partial(web_stepper_crumble(_stepper, _current_step, _T)), + partial(web_stepper_full_description(_current_step, _T)), partial(web_stepper_message(stp_session, _T)), - partial(web_stepper_main_view(_current_step, stp_session)), //OK - partial(web_stepper_button(_current_step, stp_session)) + partial(web_stepper_main_view(_current_step, stp_session, _T)), //OK + partial(web_stepper_button(_current_step, stp_session, _T)) ]) ]) ]) @@ -237,6 +265,10 @@ public define WEB_Controller_Result ajax(_web_session, web_stepper_view(_stepper, new_session, _T)) // ajax(_session, no_content) + else if action = "go" then + set_Page_Message(stepper_session.session.fields, no_message); + replace_Session(_web_session.fields, _stepper.uid, stepper_session.session); + ajax(_web_session, web_stepper_view(_stepper, stepper_session, _T)) else if action = "init" then ajax(_web_session, no_content) else @@ -283,3 +315,25 @@ public define WEB_Controller_Result } . + +public define HTML_Partial_Content + stepper_submit_button + ( + String label, + WEB_Action_Name wan, + String submit_action, + List((String, String)) extra_args + )= + with url = format_web_action_name_to_js(wan,[("step_a", "submit"), ("submit_a",submit_action) . extra_args]), + jquery_button(jquery_img_button(icn16_check, label, "", jQuery_actioner(same, jqscript("stepper_submit("+url+");")), left)) +. + +public define HTML_Partial_Content + stepper_submit_button + ( + String label, + WEB_Action_Name wan, + String submit_action, + )= + stepper_submit_button(label, wan, submit_action, []) +. diff --git a/web/types/XL_web_stepper.anubis b/web/types/XL_web_stepper.anubis index e0e919d..8cd6715 100644 --- a/web/types/XL_web_stepper.anubis +++ b/web/types/XL_web_stepper.anubis @@ -9,6 +9,9 @@ transmit web_session.anubis transmit xlib/generic/types/stepper.anubis + +public type WEB_Step:... + // //public type Step_status: // initial, @@ -46,7 +49,7 @@ public type Step_View_Status: public type WEB_Step_Status: web_step_status( String step_name, - String index, + Int index, Step_Status status, Step_View_Status v_status ) @@ -63,12 +66,13 @@ public type WEB_Step_Session: public type WEB_Step: web_step( String name, //step name - String index, //step number + String full_description, + Int index, //step index String thread, //thread name like general, VoIP, etc. List(WEB_Step) childs, - (One) -> WEB_Step_Status init, //return the initial step status - (WEB_Step_Session stp_session) -> HTML_Partial_Content view, //return the view according to WEB_Step_Session - (WEB_Step_Session stp_session) -> HTML_Partial_Content buttons, + (WEB_Step_Session stp_session) -> WEB_Step_Status status, //return the step status + (WEB_Step_Session stp_session, (String)->String _T) -> HTML_Partial_Content view, //return the view according to WEB_Step_Session + (WEB_Step_Session stp_session, (String)->String _T) -> HTML_Partial_Content buttons, (WEB_Step_Session stp_session, WEB_Session web_session) -> WEB_Step_Session submit, ) . @@ -77,6 +81,7 @@ public type WEB_Stepper: web_stepper( String name, //name of the stepper String uid, //uid of the stepper (currently same as name) + WEB_Action_Name web_controller, (WEB_Session web_session) -> WEB_Step_Session start, //start function to call at very first time List(WEB_Step) steps //All available steps in stepper //Step_Session session -- libgit2 0.21.4