Commit 85496d9ff3cacf322513b9e210d95636f0c1030c
1 parent
2ddf90af
beginning of multi-step management. In very early stage, subject to change soon
Showing
2 changed files
with
145 additions
and
40 deletions
Show diff stats
web/XL_web_stepper.anubis
| ... | ... | @@ -6,8 +6,11 @@ |
| 6 | 6 | * © David RENÉ |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | +transmit xlib/web/CXM_jquery.anubis | |
| 9 | 10 | transmit xlib/web/types/XL_web_stepper.anubis |
| 10 | 11 | transmit xlib/web/controllers_web_site.anubis |
| 12 | +read xlib/web/CXM_page_message.anubis | |
| 13 | +read xlib/web_controllers/language/language_management.anubis | |
| 11 | 14 | |
| 12 | 15 | public define Maybe(WEB_Stepper) |
| 13 | 16 | get_stepper_by_uid |
| ... | ... | @@ -17,9 +20,12 @@ public define Maybe(WEB_Stepper) |
| 17 | 20 | )= |
| 18 | 21 | if steppers is |
| 19 | 22 | { |
| 20 | - [] then failure, | |
| 23 | + [] then | |
| 24 | + println("get_stepper_by_uid: stepper uid ["+_uid+"] not found"); | |
| 25 | + failure, | |
| 21 | 26 | [h . t] then |
| 22 | 27 | if h.uid = _uid then |
| 28 | + println("get_stepper_by_uid: stepper uid ["+_uid+"] FOUND"); | |
| 23 | 29 | success(h) |
| 24 | 30 | else |
| 25 | 31 | get_stepper_by_uid(_uid, t) |
| ... | ... | @@ -34,7 +40,9 @@ public define Maybe(WEB_Stepper) |
| 34 | 40 | )= |
| 35 | 41 | if get_String(_lwa, "stepper_uid") is |
| 36 | 42 | { |
| 37 | - failure then failure | |
| 43 | + failure then | |
| 44 | + println("get_stepper: stepper_uid not found"); | |
| 45 | + failure | |
| 38 | 46 | success(stepper_uid) then get_stepper_by_uid(stepper_uid, steppers) |
| 39 | 47 | } |
| 40 | 48 | . |
| ... | ... | @@ -47,7 +55,9 @@ public define Maybe(WEB_Step) |
| 47 | 55 | )= |
| 48 | 56 | if steps is |
| 49 | 57 | { |
| 50 | - [] then failure, | |
| 58 | + [] then | |
| 59 | + println("get_current_step ["+current_step+"] not found"); | |
| 60 | + failure, | |
| 51 | 61 | [h . t] then |
| 52 | 62 | if h.name = current_step then |
| 53 | 63 | success(h) |
| ... | ... | @@ -76,25 +86,30 @@ public define Maybe(WEB_Step) |
| 76 | 86 | public define HTML_Partial_Content |
| 77 | 87 | web_stepper_button |
| 78 | 88 | ( |
| 89 | + WEB_Step _step, | |
| 79 | 90 | WEB_Step_Session stp_session |
| 80 | 91 | )= |
| 81 | - partial_content(empty) | |
| 92 | + partial_content(div(class("steppers_buttons"), _step.buttons(stp_session))) | |
| 82 | 93 | . |
| 83 | 94 | |
| 84 | 95 | public define HTML_Partial_Content |
| 85 | 96 | web_stepper_main_view |
| 86 | 97 | ( |
| 98 | + WEB_Step _step, | |
| 87 | 99 | WEB_Step_Session stp_session |
| 88 | 100 | )= |
| 89 | - partial_content(empty) | |
| 101 | + partial_content( | |
| 102 | + div(class("stepper_main_view"), | |
| 103 | + _step.view(stp_session))) | |
| 90 | 104 | . |
| 91 | 105 | |
| 92 | 106 | public define HTML_Partial_Content |
| 93 | 107 | web_stepper_message |
| 94 | 108 | ( |
| 95 | - WEB_Step_Session stp_session | |
| 109 | + WEB_Step_Session stp_session, | |
| 110 | + (String)->String _T | |
| 96 | 111 | )= |
| 97 | - partial_content(empty) | |
| 112 | + partial_content(div(class("stepper_message"), show_page_message(get_Page_Message(stp_session.session.fields, _T)))) | |
| 98 | 113 | . |
| 99 | 114 | |
| 100 | 115 | public define HTML_Partial_Content |
| ... | ... | @@ -105,75 +120,164 @@ public define HTML_Partial_Content |
| 105 | 120 | partial_content(empty) |
| 106 | 121 | . |
| 107 | 122 | |
| 123 | +public define Bool | |
| 124 | + is_current | |
| 125 | + ( | |
| 126 | + WEB_Step step, | |
| 127 | + WEB_Step_Session stp_session | |
| 128 | + )= | |
| 129 | + stp_session.current_step = step.name | |
| 130 | +. | |
| 131 | + | |
| 132 | +public define Bool | |
| 133 | + is_active | |
| 134 | + ( | |
| 135 | + WEB_Step step, | |
| 136 | + WEB_Step_Session stp_session | |
| 137 | + )= | |
| 138 | + true | |
| 139 | +. | |
| 140 | + | |
| 108 | 141 | public define HTML_Partial_Content |
| 109 | 142 | web_stepper_crumble |
| 110 | 143 | ( |
| 111 | 144 | WEB_Stepper stepper, |
| 112 | 145 | WEB_Step_Session stp_session |
| 113 | 146 | )= |
| 114 | - partial_content(empty) | |
| 147 | + partial_content( | |
| 148 | + div(class("stepper_crumble"), | |
| 149 | + div(class("multi-step"), | |
| 150 | + ul(class("multi-step-list"), | |
| 151 | + | |
| 152 | + map((WEB_Step step) |-> | |
| 153 | + with active = if is_active(step, stp_session) then " active" else "", | |
| 154 | + current = if is_current(step, stp_session) then " current" else "", | |
| 155 | + | |
| 156 | + li(class("multi-step-item"+active+current), | |
| 157 | + div(class("item-wrap"), | |
| 158 | + p(class("item-title"), | |
| 159 | + text(step.name) | |
| 160 | + ) | |
| 161 | + ) | |
| 162 | + ) | |
| 163 | + , | |
| 164 | + stepper.steps | |
| 165 | + ) | |
| 166 | + | |
| 167 | + ) | |
| 168 | + ) | |
| 169 | + ) | |
| 170 | + ) | |
| 115 | 171 | . |
| 116 | 172 | |
| 117 | 173 | public define HTML_Partial_Content |
| 118 | 174 | web_stepper_view |
| 119 | 175 | ( |
| 120 | - WEB_Stepper stepper, | |
| 121 | - WEB_Step_Session stp_session | |
| 176 | + WEB_Stepper _stepper, | |
| 177 | + WEB_Step _current_step, | |
| 178 | + WEB_Step_Session stp_session, | |
| 179 | + (String)->String _T | |
| 122 | 180 | )= |
| 123 | - with _current_step = get_current_step(stepper.steps, stp_session.current_step), | |
| 124 | - | |
| 125 | - partial_content([ | |
| 126 | - div(id("stepper"), [ | |
| 127 | - partial(web_stepper_crumble(stepper, stp_session)), | |
| 128 | - partial(web_stepper_name(stp_session)), | |
| 129 | - partial(web_stepper_message(stp_session)), | |
| 130 | - partial(web_stepper_main_view(stp_session)), | |
| 131 | - partial(web_stepper_button(stp_session)) | |
| 181 | + println("web_stepper_view _current_step.name ["+_current_step.name+"]"); | |
| 182 | + | |
| 183 | + partial_content([css(css_file("xlib/css/stepper.css")), | |
| 184 | + js_inline(jquery_ready("$('#stepper_form').on('submit', function(e) { e.stopPropagation(); return false; });")) | |
| 185 | + ], [ | |
| 186 | + div([id("stepper"), class("stepper")], [ | |
| 187 | + form([id("stepper_form")],[ | |
| 188 | + hidden("step", _current_step.name), //add current step name as hidden argument | |
| 189 | + hidden("stepper_uid",_stepper.uid), //add stepper_uid as hidden argument | |
| 190 | + //construct bread crumb line | |
| 191 | + partial(web_stepper_crumble(_stepper, stp_session)), | |
| 192 | + partial(web_stepper_name(stp_session)), | |
| 193 | + partial(web_stepper_message(stp_session, _T)), | |
| 194 | + partial(web_stepper_main_view(_current_step, stp_session)), //OK | |
| 195 | + partial(web_stepper_button(_current_step, stp_session)) | |
| 196 | + ]) | |
| 132 | 197 | ]) |
| 133 | 198 | ]) |
| 199 | + | |
| 200 | +. | |
| 201 | + | |
| 202 | +public define HTML_Partial_Content | |
| 203 | + web_stepper_view | |
| 204 | + ( | |
| 205 | + WEB_Stepper stepper, | |
| 206 | + WEB_Step_Session stp_session, | |
| 207 | + (String)->String _T | |
| 208 | + )= | |
| 209 | + println("web_stepper_view without step. stp_session.current_step ["+stp_session.current_step+"]"); | |
| 210 | + if get_current_step(stepper.steps, stp_session.current_step) is | |
| 211 | + { | |
| 212 | + failure then partial_content(empty) | |
| 213 | + success(_current_step) then web_stepper_view(stepper, _current_step, stp_session, _T) | |
| 214 | + } | |
| 134 | 215 | . |
| 135 | 216 | |
| 136 | 217 | public define WEB_Controller_Result |
| 137 | 218 | manage_stepper_action |
| 138 | 219 | ( |
| 139 | 220 | List(Web_arg) _lwa, |
| 140 | - WEB_Session _session, | |
| 221 | + WEB_Session _web_session, | |
| 222 | + WEB_Stepper _stepper, | |
| 141 | 223 | WEB_Step _step |
| 142 | 224 | )= |
| 225 | + with stepper_session = web_step_session(_step.name, get_Session(_web_session.fields, _stepper.uid, session(_stepper.uid, empty_fields_list))), | |
| 226 | + _T = make_translate_function(_web_session), | |
| 227 | + println("manage_stepper_action step_session\n"+dump_Session_Field_list(*stepper_session.session.fields,"")); | |
| 228 | + | |
| 143 | 229 | with action = get_String(_lwa, "step_a", "N/A"), |
| 230 | + println("manage_stepper_action ["+action+"]"); | |
| 144 | 231 | if action = "submit" then |
| 145 | - ajax(_session, no_content) | |
| 232 | + println("manage_stepper_action submit step["+_step.name+"]"); | |
| 233 | + with new_session = _step.submit(stepper_session, _web_session), | |
| 234 | + //TODO must store new session in WEB session | |
| 235 | + println("store new_session\n"+dump_Session(new_session.session,"")); | |
| 236 | + replace_Session(_web_session.fields, _stepper.uid, new_session.session); | |
| 237 | + ajax(_web_session, web_stepper_view(_stepper, new_session, _T)) | |
| 238 | + | |
| 239 | +// ajax(_session, no_content) | |
| 146 | 240 | else if action = "init" then |
| 147 | - ajax(_session, no_content) | |
| 241 | + ajax(_web_session, no_content) | |
| 148 | 242 | else |
| 149 | - ajax(_session, no_content) | |
| 243 | + ajax(_web_session, no_content) | |
| 150 | 244 | . |
| 151 | 245 | |
| 152 | 246 | public define WEB_Controller_Result |
| 153 | 247 | manage_stepper |
| 154 | 248 | ( |
| 155 | - WEB_Session _session, | |
| 249 | + WEB_Session _web_session, | |
| 156 | 250 | List(WEB_Stepper) _steppers |
| 157 | 251 | )= |
| 158 | - with _lwa = *_session.web_request.lwa, | |
| 252 | + with _lwa = *_web_session.web_request.lwa, | |
| 253 | + println("manage_stepper"); | |
| 159 | 254 | if get_stepper(_lwa, _steppers) is |
| 160 | 255 | { |
| 161 | - failure then ajax(_session, no_content), | |
| 256 | + failure then | |
| 257 | + println("stepper not found"); | |
| 258 | + ajax(_web_session, no_content), | |
| 162 | 259 | success(stepper) then |
| 163 | 260 | //get session of the stepper |
| 164 | - with stepper_session = get_Session(_session.fields, stepper.uid, session(stepper.uid, empty_fields_list)), | |
| 165 | 261 | if get_String(_lwa, "step") is |
| 166 | 262 | { |
| 167 | - failure then ajax(_session, no_content) | |
| 263 | + failure then | |
| 264 | + println("manage_stepper step not found "); | |
| 265 | + ajax(_web_session, no_content) | |
| 168 | 266 | success(step_name) then |
| 267 | + println("manage_stepper step_name = "+step_name); | |
| 169 | 268 | if step_name = "start" then |
| 170 | - ajax(_session, web_stepper_view(stepper, stepper.start(_session))) | |
| 269 | + with _T = make_translate_function(_web_session), | |
| 270 | + with initial_step_session = stepper.start(_web_session), | |
| 271 | + println("store initial_step_session\n"+dump_Session(initial_step_session.session,"")); | |
| 272 | + replace_Session(_web_session.fields, stepper.uid, initial_step_session.session); | |
| 273 | + ajax(_web_session, web_stepper_view(stepper, initial_step_session, _T)) | |
| 171 | 274 | else |
| 275 | + | |
| 172 | 276 | if get_current_step(stepper.steps, step_name) is |
| 173 | 277 | { |
| 174 | - failure then ajax(_session, no_content), | |
| 278 | + failure then ajax(_web_session, no_content), | |
| 175 | 279 | success(step) then |
| 176 | - manage_stepper_action(_lwa, _session, step) | |
| 280 | + manage_stepper_action(_lwa, _web_session, stepper, step) | |
| 177 | 281 | } |
| 178 | 282 | } |
| 179 | 283 | ... | ... |
web/types/XL_web_stepper.anubis
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | |
| 10 | -read web_session.anubis | |
| 10 | +transmit web_session.anubis | |
| 11 | 11 | transmit xlib/generic/types/stepper.anubis |
| 12 | 12 | // |
| 13 | 13 | //public type Step_status: |
| ... | ... | @@ -54,9 +54,9 @@ public type WEB_Step_Status: |
| 54 | 54 | |
| 55 | 55 | public type WEB_Step_Session: |
| 56 | 56 | web_step_session( |
| 57 | - List(WEB_Step_Status) web_steps_status, | |
| 57 | + //List(WEB_Step_Status) web_steps_status, | |
| 58 | 58 | String current_step, |
| 59 | - Session step_session | |
| 59 | + Session session | |
| 60 | 60 | ) |
| 61 | 61 | . |
| 62 | 62 | |
| ... | ... | @@ -65,19 +65,20 @@ public type WEB_Step: |
| 65 | 65 | String name, //step name |
| 66 | 66 | String index, //step number |
| 67 | 67 | String thread, //thread name like general, VoIP, etc. |
| 68 | - List(WEB_Step) childs, | |
| 68 | + List(WEB_Step) childs, | |
| 69 | 69 | (One) -> WEB_Step_Status init, //return the initial step status |
| 70 | - (WEB_Step_Session stp_session) -> HTML_Partial_Content view, | |
| 70 | + (WEB_Step_Session stp_session) -> HTML_Partial_Content view, //return the view according to WEB_Step_Session | |
| 71 | + (WEB_Step_Session stp_session) -> HTML_Partial_Content buttons, | |
| 71 | 72 | (WEB_Step_Session stp_session, WEB_Session web_session) -> WEB_Step_Session submit, |
| 72 | 73 | ) |
| 73 | 74 | . |
| 74 | 75 | |
| 75 | 76 | public type WEB_Stepper: |
| 76 | 77 | web_stepper( |
| 77 | - String name, | |
| 78 | - String uid, | |
| 79 | - (WEB_Session web_session) -> WEB_Step_Session start, | |
| 80 | - List(WEB_Step) steps | |
| 78 | + String name, //name of the stepper | |
| 79 | + String uid, //uid of the stepper (currently same as name) | |
| 80 | + (WEB_Session web_session) -> WEB_Step_Session start, //start function to call at very first time | |
| 81 | + List(WEB_Step) steps //All available steps in stepper | |
| 81 | 82 | //Step_Session session |
| 82 | 83 | ) |
| 83 | 84 | . | ... | ... |