CXM_generic_form.anubis
18.3 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
*Project* The Anubis Project
*Title*
*Copyright* Copyright (c) Alain Prouté 2005.
*Author* Alain Prouté
In this file we rationalize the construction of forms.
read CXM_making_a_web_site.anubis
read tools/basis.anubis
public type Mandatory: // used to mark fields as mandatory.
mandatory,
non_mandatory.
public type Width:
small,
narrow,
wide,
custom(Int).
public type FormFieldWidth:
auto,
custom(Int).
Sorts of fields that you can put in a form:
public type FormField:
//--- title field ---------------------------------------------------------------------
title (String text),
title (Int text_size,
String text),
title_f (List(Text_Option) -> HTML_In_Form),
//--- message field -------------------------------------------------------------------
message (Result(String,String) msg),
message_f (Result(List(Text_Option) -> HTML_In_Form,List(Text_Option) -> HTML_In_Form)),
//--- text input field ----------------------------------------------------------------
input (WebArgName web_arg_name,
String tag,
Width width,
InitialValue init_value,
Mandatory mandatory),
input (WebArgName web_arg_name,
Width width,
InitialValue init_value),
input_f (WebArgName web_arg_name,
List(Text_Option) -> HTML_In_Form tag,
Width width,
InitialValue init_value,
Mandatory mandatory),
//--- password input field ------------------------------------------------------------
password_input (WebArgName web_arg_name,
String tag,
Mandatory mandatory),
password_input_f (WebArgName web_arg_name,
List(Text_Option) -> HTML_In_Form tag,
Mandatory mandatory),
//--- explanation field ---------------------------------------------------------------
explain (String text),
explain (String text,
FormFieldWidth width),
explain_f (List(Text_Option) -> HTML_In_Form),
//--- selector field ------------------------------------------------------------------
selector (WebArgName web_arg_name,
String tag,
List(String) items,
Maybe(InitialValue) selected,
Mandatory mandatory),
selector_f (WebArgName web_arg_name,
List(Text_Option) -> HTML_In_Form,
List(String) items,
Maybe(InitialValue) selected,
Mandatory mandatory),
selector_c (WebArgName web_arg_name,
String tag,
List((List(CoreAttrs), WebArgValue, String)) items,
Maybe(InitialValue) selected,
Mandatory mandatory),
//--- checkbox field ------------------------------------------------------------------
checkbox (WebArgName web_arg_name,
String tag,
Bool checked,
Mandatory mandatory),
// the same one, but with the tag on the right of the checkbox
checkboxr (WebArgName web_arg_name,
String tag,
Bool checked,
Mandatory mandatory),
checkbox_f (WebArgName web_arg_name,
List(Text_Option) -> HTML_In_Form,
Bool checked,
Mandatory mandatory),
//--- radio-button field --------------------------------------------------------------
radio_button (WebArgName web_arg_name,
WebArgValue web_arg_value,
String tag,
Bool checked,
Mandatory mandatory),
// the same one, but with the tag on the right of the radio_button
radio_buttonr (WebArgName web_arg_name,
WebArgValue web_arg_value,
String tag,
Bool checked,
Mandatory mandatory),
//--- text area field -----------------------------------------------------------------
text_area (WebArgName web_arg_name,
InitialValue initial_text),
text_area (WebArgName web_arg_name,
String tag,
InitialValue initial_text),
text_area (WebArgName web_arg_name,
String tag,
InitialValue initial_text,
Int width,
Int height),
//--- fields table --------------------------------------------------------------------
fields_table (String tag,
List(FormField) fields),
//--- fields line ---------------------------------------------------------------------
fields_line (String tag,
List(FormField) fields),
fields_line (List(FormField) fields),
//--- preview field -------------------------------------------------------------------
preview (String html_text),
//--- submit button -------------------------------------------------------------------
submit (String action_name,
Maybe(String) label,
String button_text,
List((String,String)) extra_operands).
Convenience functions:
public define FormField title(List(Text_Option) -> HTML_In_Form f) = title_f(f).
public define FormField
message(Result(List(Text_Option) -> HTML_In_Form,List(Text_Option) -> HTML_In_Form) f) = message_f(f).
public define FormField input(WebArgName web_arg_name,
List(Text_Option) -> HTML_In_Form tag,
Width width,
InitialValue init_value,
Mandatory mandatory)
= input_f(web_arg_name,tag,width,init_value,mandatory).
public define FormField password_input(WebArgName web_arg_name,
List(Text_Option) -> HTML_In_Form tag,
Mandatory mandatory)
= password_input_f(web_arg_name,tag,mandatory).
public define FormField explain(List(Text_Option) -> HTML_In_Form f) = explain_f(f).
public define FormField selector(WebArgName web_arg_name,
List(Text_Option) -> HTML_In_Form f,
List(String) items,
Maybe(InitialValue) selected,
Mandatory mandatory)
= selector_f(web_arg_name,f,items,selected,mandatory).
public define FormField checkbox(WebArgName web_arg_name,
List(Text_Option) -> HTML_In_Form f,
Bool checked,
Mandatory mandatory)
= checkbox_f(web_arg_name,f,checked,mandatory).
Make the form itself with:
public define HTML_Off_Form
generic_form
(
String form_name,
RGB background_color,
Int width,
List(FormField) fields
).
--- That's all for the public part ! --------------------------------------------------
// TO DO update code of CXM generic form
define HTML_Row(HTML_In_Form)
format_form_field
(
FormField ff
) =
with star = (Mandatory m) |-> (HTML_In_Form)text([color(rgb(255,0,0)),size(12)],
if m is
{
mandatory then "*",
non_mandatory then ""
}),
row(
if ff is
{
title(t) then (List(HTML_Cell(HTML_In_Form)))
[
cell([columns(3),h_center],text([size(16),bold,color(rgb(0,0,0))],t))
],
title(s,t) then (List(HTML_Cell(HTML_In_Form)))
[
cell([columns(3),h_center],text([size(s),bold,color(rgb(0,0,0))],t))
],
title_f(t) then (List(HTML_Cell(HTML_In_Form)))
[
cell([columns(3),h_center],t([size(16),bold,color(rgb(0,0,0))]))
],
message(r) then (List(HTML_Cell(HTML_In_Form))) if r is
{
error(msg) then [cell([columns(3),h_center],
text([size(10),color(rgb(240,0,0))],msg))]
ok(msg) then [cell([columns(3),h_center],
text([size(10),color(rgb(0,150,0))],msg))]
},
message_f(r) then (List(HTML_Cell(HTML_In_Form))) if r is
{
error(msg) then [cell([columns(3),h_center],
msg([size(10),color(rgb(240,0,0))]))]
ok(msg) then [cell([columns(3),h_center],
msg([size(10),color(rgb(0,150,0))]))]
},
input(wan,tag,w,init,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], text([size(10)],tag)),
cell([width(7) ], star(mand)),
cell([left ], text_input([], "",htmlId(""), wan, init,if w is
{
small then 10,
narrow then 50,
wide then 70,
custom(n) then n
}))
],
input(wan,w,init) then (List(HTML_Cell(HTML_In_Form)))
[
cell([left,columns(3) ], text_input([], "", htmlId(""), wan,init,if w is
{
small then 10,
narrow then 30,
wide then 70,
custom(n) then n
}))
],
input_f(wan,tag,w,init,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], tag([size(10)])),
cell([width(7) ], star(mand)),
cell([left ], text_input([], "", htmlId(""),wan,init,if w is
{
small then 15,
narrow then 30,
wide then 70,
custom(n) then n
}))
],
password_input(wan,tag,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], text([size(10)],tag)),
cell([width(7) ], star(mand)),
cell([left ], password_input([], "",htmlId(""), wan, init(""), 30))
],
password_input_f(wan,tag,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], tag([size(10)])),
cell([width(7) ], star(mand)),
cell([left ], password_input([], "",htmlId(""), wan, init(""), 30))
],
explain(t) then (List(HTML_Cell(HTML_In_Form)))
[
cell([columns(3),h_center],
table([nude],[row(cell([width(500)],
paragraph([/*justified,*/size(10),color(rgb(0,100,0))],literal(t))))]))
],
explain(t,w) then (List(HTML_Cell(HTML_In_Form)))
[
cell([columns(3),h_center],
table([nude],[row(cell(
if w is
{
auto then [],
custom(i) then [width(i)]
},
paragraph([/*justified,*/size(10),color(rgb(0,100,0))], literal(t))))]))
],
explain_f(t) then (List(HTML_Cell(HTML_In_Form)))
[
cell([columns(3),h_center],
table([nude],[row(cell([width(500)],
t([/*justified,*/size(10),color(rgb(0,100,0))])))]))
],
selector(wan,tag,items,selected,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], text([size(10)],tag)),
cell([width(7)], star(mand)),
cell([left ], if selected is
{
failure then selector([], "", htmlId(""), wan,1,items)
success(sel) then selector([], "", htmlId(""), wan,1,items, sel)
})
],
selector_f(wan,tag,items,selected,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], tag([size(10)])),
cell([width(7)], star(mand)),
cell([left ], if selected is
{
failure then selector([], "", htmlId(""), wan,1,items)
success(sel) then selector([], "", htmlId(""), wan,1,items, sel)
})
],
selector_c(wan,tag,items,selected,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], text([size(10)],tag)),
cell([width(7)], star(mand)),
cell([left ], if selected is
{
failure then selector_c([], "", htmlId(""), wan,1,items)
success(sel) then selector_c([], "", htmlId(""), wan,1,items,sel)
})
],
checkbox(wan,tag,checked,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], text([size(10)],tag)),
cell([width(7)], star(mand)),
cell([left ], check_box([], "",htmlId(""),wan, wav(wan.name),checked))
],
checkboxr(wan,tag,checked,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], check_box([], "",htmlId(""),wan, wav(wan.name),checked)),
cell([width(7)], star(mand)),
cell([left ], text([size(10)],tag))
],
checkbox_f(wan,tag,checked,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], tag([size(10)])),
cell([width(7)], star(mand)),
cell([left ], check_box([], "",htmlId(""),wan,wav(wan.name),checked))
],
radio_button(wan,wav,tag,checked,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], text([size(10)],tag)),
cell([width(7)], star(mand)),
cell([left ], radio_button([], "", htmlId(""), wan, wav, checked))
],
radio_buttonr(wan,wav,tag,checked,mand) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right ], radio_button([], "", htmlId(""), wan, wav, checked)),
cell([width(7)], star(mand)),
cell([left ], text([size(10)],tag))
],
text_area(wan,tx) then (List(HTML_Cell(HTML_In_Form)))
[
cell([h_center,columns(3)],text_area([wrap_lines],wan,tx,75,10))
],
text_area(wan,tag,tx) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right,top], text([size(10)],tag)),
cell([width(7)], text([],"")),
cell([h_center],text_area([wrap_lines],wan,tx,75,10))
],
text_area(wan,tag,tx,w,h) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right,top], text([size(10)],tag)),
cell([width(7)], text([],"")),
cell([h_center],text_area([wrap_lines],wan,tx,w,h))
],
fields_table(tag,fields) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right,top], text([size(10)],tag)),
cell([width(7)], text([],"")),
cell([left,top], table([],map((FormField ff2) |-> format_form_field(ff2),fields)))
],
fields_line(tag,fields) then (List(HTML_Cell(HTML_In_Form)))
[
cell([right,top], text([size(10)],tag)),
cell([width(7)], text([],"")),
cell([left,top], table([nude],[row([], //border(0,0,3,rgb(0,0,0))
map((FormField ff2) |-> cell([top],table([nude],[format_form_field(ff2)])),fields))]))
],
fields_line(fields) then (List(HTML_Cell(HTML_In_Form)))
[
cell([left,top,columns(3)], table([nude],[row([],
map((FormField ff2) |-> cell([top],table([nude],[format_form_field(ff2)])),fields))]))
],
preview(html_text) then (List(HTML_Cell(HTML_In_Form)))
[
cell([top,left,columns(3),background_color(rgb(255,255,255))],
table([border(0,8,0,rgb(0,0,0))],
[row(cell([left,top,height(200)],literal(html_text)))]))
],
submit(action_name,mb_label,button_text,extra_operands) then (List(HTML_Cell(HTML_In_Form)))
[
cell([columns(3),right],actioner(same,
if mb_label is
{
failure then same,
success(n) then same(n)
},
submit([], button_text),
action_name,
extra_operands))
]
}).
// TO DO update code of CXM generic form
public define HTML_Off_Form
generic_form
(
String form_name,
RGB bg_color,
Int w,
List(FormField) fields
) =
table([border(0,0,5,bg_color),percentage_width(100),
background_color(bg_color)],[row(cell([h_center],
form(form_name,[],table([border(0,2,0,bg_color)],
map(format_form_field, fields)))))]).