XL_web_stepper.anubis
9.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 24/04/2020
* Time: 15:12
* © 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/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
(
String _uid,
List(WEB_Stepper) steppers
)=
if steppers is
{
[] 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)
}
.
public define Maybe(WEB_Stepper)
get_stepper
(
List(Web_arg) _lwa,
List(WEB_Stepper) steppers
)=
if get_String(_lwa, "stepper_uid") is
{
failure then
println("get_stepper: stepper_uid not found");
failure
success(stepper_uid) then get_stepper_by_uid(stepper_uid, steppers)
}
.
public define Maybe(WEB_Step)
get_current_step
(
List(WEB_Step) steps,
String current_step
)=
if steps is
{
[] then
println("get_current_step ["+current_step+"] not found");
failure,
[h . t] then
if h.name = current_step then
success(h)
else
if get_current_step(h.childs, current_step) is
{
failure then get_current_step(t, current_step),
success(step) then success(step)
}
}
.
public define Maybe(WEB_Step)
get_step
(
List(Web_arg) _lwa,
List(WEB_Step) steps,
)=
if get_String(_lwa, "step") is
{
failure then failure
success(step) then get_current_step(steps, step)
}
.
public define HTML_Partial_Content
web_stepper_button
(
WEB_Step _step,
WEB_Step_Session stp_session,
(String)->String _T
)=
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,
(String)->String _T
)=
partial_content(
div(class("stepper_main_view"),
_step.view(stp_session, _T)))
.
public define HTML_Partial_Content
web_stepper_message
(
WEB_Step_Session stp_session,
(String)->String _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_full_description
(
WEB_Step current_step,
(String)->String _T
)=
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 current_step
)=
current_step.name = step.name
.
public define Bool
is_active
(
WEB_Step step,
WEB_Step current_step
)=
step.index < current_step.index
.
public define HTML_Partial_Content
web_stepper_crumble
(
WEB_Stepper _stepper,
WEB_Step _current_step,
(String) -> String _T
)=
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, _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(_T(to_upper(step.name)))
)
)
)
,
_stepper.steps
)
)
)
)
)
.
public define HTML_Partial_Content
web_stepper_view
(
WEB_Stepper _stepper,
WEB_Step _current_step,
WEB_Step_Session stp_session,
(String)->String _T
)=
println("web_stepper_view _current_step.name ["+_current_step.name+"]");
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")], [
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, _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, _T)), //OK
partial(web_stepper_button(_current_step, stp_session, _T))
])
])
])
.
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 _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
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 = "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
ajax(_web_session, no_content)
.
public define WEB_Controller_Result
manage_stepper
(
WEB_Session _web_session,
List(WEB_Stepper) _steppers
)=
with _lwa = *_web_session.web_request.lwa,
println("manage_stepper");
if get_stepper(_lwa, _steppers) is
{
failure then
println("stepper not found");
ajax(_web_session, no_content),
success(stepper) then
//get session of the stepper
if get_String(_lwa, "step") is
{
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
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(_web_session, no_content),
success(step) then
manage_stepper_action(_lwa, _web_session, stepper, step)
}
}
}
.
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, [])
.