diff --git a/web/XL_web_stepper.anubis b/web/XL_web_stepper.anubis index 4313791..31dc999 100644 --- a/web/XL_web_stepper.anubis +++ b/web/XL_web_stepper.anubis @@ -6,8 +6,11 @@ * © David RENÉ */ +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_controllers/language/language_management.anubis public define Maybe(WEB_Stepper) get_stepper_by_uid @@ -17,9 +20,12 @@ public define Maybe(WEB_Stepper) )= if steppers is { - [] then failure, + [] then + println("get_stepper_by_uid: stepper uid ["+_uid+"] not found"); + failure, [h . t] then if h.uid = _uid then + println("get_stepper_by_uid: stepper uid ["+_uid+"] FOUND"); success(h) else get_stepper_by_uid(_uid, t) @@ -34,7 +40,9 @@ public define Maybe(WEB_Stepper) )= if get_String(_lwa, "stepper_uid") is { - failure then failure + failure then + println("get_stepper: stepper_uid not found"); + failure success(stepper_uid) then get_stepper_by_uid(stepper_uid, steppers) } . @@ -47,7 +55,9 @@ public define Maybe(WEB_Step) )= if steps is { - [] then failure, + [] then + println("get_current_step ["+current_step+"] not found"); + failure, [h . t] then if h.name = current_step then success(h) @@ -76,25 +86,30 @@ public define Maybe(WEB_Step) public define HTML_Partial_Content web_stepper_button ( + WEB_Step _step, WEB_Step_Session stp_session )= - partial_content(empty) + partial_content(div(class("steppers_buttons"), _step.buttons(stp_session))) . public define HTML_Partial_Content web_stepper_main_view ( + WEB_Step _step, WEB_Step_Session stp_session )= - partial_content(empty) + partial_content( + div(class("stepper_main_view"), + _step.view(stp_session))) . public define HTML_Partial_Content web_stepper_message ( - WEB_Step_Session stp_session + WEB_Step_Session stp_session, + (String)->String _T )= - partial_content(empty) + partial_content(div(class("stepper_message"), show_page_message(get_Page_Message(stp_session.session.fields, _T)))) . public define HTML_Partial_Content @@ -105,75 +120,164 @@ public define HTML_Partial_Content partial_content(empty) . +public define Bool + is_current + ( + WEB_Step step, + WEB_Step_Session stp_session + )= + stp_session.current_step = step.name +. + +public define Bool + is_active + ( + WEB_Step step, + WEB_Step_Session stp_session + )= + true +. + public define HTML_Partial_Content web_stepper_crumble ( WEB_Stepper stepper, WEB_Step_Session stp_session )= - partial_content(empty) + partial_content( + div(class("stepper_crumble"), + div(class("multi-step"), + 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), + div(class("item-wrap"), + p(class("item-title"), + text(step.name) + ) + ) + ) + , + stepper.steps + ) + + ) + ) + ) + ) . public define HTML_Partial_Content web_stepper_view ( - WEB_Stepper stepper, - WEB_Step_Session stp_session + WEB_Stepper _stepper, + WEB_Step _current_step, + WEB_Step_Session stp_session, + (String)->String _T )= - with _current_step = get_current_step(stepper.steps, stp_session.current_step), - - partial_content([ - div(id("stepper"), [ - partial(web_stepper_crumble(stepper, stp_session)), - partial(web_stepper_name(stp_session)), - partial(web_stepper_message(stp_session)), - partial(web_stepper_main_view(stp_session)), - partial(web_stepper_button(stp_session)) + println("web_stepper_view _current_step.name ["+_current_step.name+"]"); + + partial_content([css(css_file("xlib/css/stepper.css")), + js_inline(jquery_ready("$('#stepper_form').on('submit', function(e) { e.stopPropagation(); return false; });")) + ], [ + div([id("stepper"), class("stepper")], [ + form([id("stepper_form")],[ + 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_message(stp_session, _T)), + partial(web_stepper_main_view(_current_step, stp_session)), //OK + partial(web_stepper_button(_current_step, stp_session)) + ]) ]) ]) + +. + +public define HTML_Partial_Content + web_stepper_view + ( + WEB_Stepper stepper, + WEB_Step_Session stp_session, + (String)->String _T + )= + println("web_stepper_view without step. stp_session.current_step ["+stp_session.current_step+"]"); + if get_current_step(stepper.steps, stp_session.current_step) is + { + failure then partial_content(empty) + success(_current_step) then web_stepper_view(stepper, _current_step, stp_session, _T) + } . public define WEB_Controller_Result manage_stepper_action ( List(Web_arg) _lwa, - WEB_Session _session, + WEB_Session _web_session, + WEB_Stepper _stepper, WEB_Step _step )= + with stepper_session = web_step_session(_step.name, get_Session(_web_session.fields, _stepper.uid, session(_stepper.uid, empty_fields_list))), + _T = make_translate_function(_web_session), + println("manage_stepper_action step_session\n"+dump_Session_Field_list(*stepper_session.session.fields,"")); + with action = get_String(_lwa, "step_a", "N/A"), + println("manage_stepper_action ["+action+"]"); if action = "submit" then - ajax(_session, no_content) + println("manage_stepper_action submit step["+_step.name+"]"); + with new_session = _step.submit(stepper_session, _web_session), + //TODO must store new session in WEB session + println("store new_session\n"+dump_Session(new_session.session,"")); + replace_Session(_web_session.fields, _stepper.uid, new_session.session); + ajax(_web_session, web_stepper_view(_stepper, new_session, _T)) + +// ajax(_session, no_content) else if action = "init" then - ajax(_session, no_content) + ajax(_web_session, no_content) else - ajax(_session, no_content) + ajax(_web_session, no_content) . public define WEB_Controller_Result manage_stepper ( - WEB_Session _session, + WEB_Session _web_session, List(WEB_Stepper) _steppers )= - with _lwa = *_session.web_request.lwa, + with _lwa = *_web_session.web_request.lwa, + println("manage_stepper"); if get_stepper(_lwa, _steppers) is { - failure then ajax(_session, no_content), + failure then + println("stepper not found"); + ajax(_web_session, no_content), success(stepper) then //get session of the stepper - with stepper_session = get_Session(_session.fields, stepper.uid, session(stepper.uid, empty_fields_list)), if get_String(_lwa, "step") is { - failure then ajax(_session, no_content) + failure then + println("manage_stepper step not found "); + ajax(_web_session, no_content) success(step_name) then + println("manage_stepper step_name = "+step_name); if step_name = "start" then - ajax(_session, web_stepper_view(stepper, stepper.start(_session))) + with _T = make_translate_function(_web_session), + with initial_step_session = stepper.start(_web_session), + println("store initial_step_session\n"+dump_Session(initial_step_session.session,"")); + replace_Session(_web_session.fields, stepper.uid, initial_step_session.session); + ajax(_web_session, web_stepper_view(stepper, initial_step_session, _T)) else + if get_current_step(stepper.steps, step_name) is { - failure then ajax(_session, no_content), + failure then ajax(_web_session, no_content), success(step) then - manage_stepper_action(_lwa, _session, step) + manage_stepper_action(_lwa, _web_session, stepper, step) } } diff --git a/web/types/XL_web_stepper.anubis b/web/types/XL_web_stepper.anubis index ab8870e..e0e919d 100644 --- a/web/types/XL_web_stepper.anubis +++ b/web/types/XL_web_stepper.anubis @@ -7,7 +7,7 @@ */ -read web_session.anubis +transmit web_session.anubis transmit xlib/generic/types/stepper.anubis // //public type Step_status: @@ -54,9 +54,9 @@ public type WEB_Step_Status: public type WEB_Step_Session: web_step_session( - List(WEB_Step_Status) web_steps_status, + //List(WEB_Step_Status) web_steps_status, String current_step, - Session step_session + Session session ) . @@ -65,19 +65,20 @@ public type WEB_Step: String name, //step name String index, //step number String thread, //thread name like general, VoIP, etc. - List(WEB_Step) childs, + List(WEB_Step) childs, (One) -> WEB_Step_Status init, //return the initial step status - (WEB_Step_Session stp_session) -> HTML_Partial_Content view, + (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_Session web_session) -> WEB_Step_Session submit, ) . public type WEB_Stepper: web_stepper( - String name, - String uid, - (WEB_Session web_session) -> WEB_Step_Session start, - List(WEB_Step) steps + String name, //name of the stepper + String uid, //uid of the stepper (currently same as name) + (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