Commit 1999078840a2bd6eb53e5b43448938dd2391e8bd

Authored by totoro
1 parent cd578a44

add the Web_arg as argument for cxm_form. This allow to get initial value for pr…

…evious web_arg (with help of the wan "web arg name"). If the value doesn't exist on that lwa (list web arg) the default value given in init(xx) is use instead.
Showing 1 changed file with 68 additions and 52 deletions   Show diff stats
web/CXM_form.anubis
... ... @@ -12,6 +12,7 @@
12 12 read tools/basis.anubis
13 13 read system/string.anubis
14 14 read calexium_lib/web/CXM_common.anubis
  15 +read calexium_lib/web/CXM_web_arg_utils.anubis
15 16 read calexium_lib/web/CXM_making_a_web_site.anubis
16 17 read calexium_lib/web/CXM_html_tooltip.anubis
17 18 read calexium_lib/web/CXM_widgets.anubis
... ... @@ -95,6 +96,7 @@ public type CXM_Form_Field:
95 96 List(String) items,
96 97 Maybe(InitialValue) selected,
97 98 Mandatory mandatory),
  99 +
98 100 selector_c (List(InputAttrs) options,
99 101 String label,
100 102 HtmlId id,
... ... @@ -314,7 +316,8 @@ public define CXM_Form_Field
314 316 public define HTML_In_Form
315 317 cxm_format_form_field
316 318 (
317   - CXM_Form_Field ff
  319 + CXM_Form_Field ff,
  320 + List(Web_arg) lwa
318 321 ) =
319 322 with star = (Mandatory m) |-> (String)
320 323 if m is
... ... @@ -364,14 +367,14 @@ public define HTML_In_Form
364 367 message(t) then
365 368 literal(t),
366 369  
367   - input(options, label, id, name, init, w, mand) then
368   - text_input([class("in") . options], label + star(mand), id, name, init, pixels(w)),
  370 + input(options, label, id, wan, default, w, mand) then
  371 + text_input([class("in") . options], label + star(mand), id, wan, init(get_String(lwa, wan.name, default.value)), pixels(w)),
369 372  
370 373 input_readonly(options, label, id, name, init, w) then
371 374 text_input_ro([class("in") . options], label, id, name, init, pixels(w)),
372 375  
373   - text_area(options, label, id, name, init, w, height, mand) then
374   - text_area([input_attrs([class("in")]) . options], label + star(mand), id, name, init, pixels(w), height),
  376 + text_area(options, label, id, wan, default, w, height, mand) then
  377 + text_area([input_attrs([class("in")]) . options], label + star(mand), id, wan, init(get_String(lwa, wan.name, default.value)), pixels(w), height),
375 378  
376 379 password_input(options, label, id, name, init, w, mand) then
377 380 password_input([class("in") . options], label + star(mand), id, name, init, pixels(w)),
... ... @@ -386,36 +389,43 @@ public define HTML_In_Form
386 389 if selected is
387 390 {
388 391 failure then selector(options, label + star(mand), id, wan, size, items),
389   - success(init) then selector(options, label + star(mand), id, wan, size, items, init),
  392 + success(default) then selector(options, label + star(mand), id, wan, size, items, init(get_String(lwa, wan.name, default.value))),
390 393 },
391 394  
392 395 selector_c(options, label, id, wan, size, items, selected, mand) then
393 396 if selected is
394 397 {
395 398 failure then selector_c(options, label + star(mand), id, wan, size, items),
396   - success(init) then selector_c(options, label + star(mand), id, wan, size, items, init),
  399 + success(default) then selector_c(options, label + star(mand), id, wan, size, items, init(get_String(lwa, wan.name, default.value))),
397 400 },
398 401  
399   - checkbox(options, label, id, name, val, checked, mand) then
400   - check_box(options, label + star(mand), id, name, val, checked),
  402 + checkbox(options, label, id, wan, val, checked, mand) then
  403 + check_box(options, label + star(mand), id, wan, val, get_Bool(lwa, wan.name, checked)),
401 404  
402   - checkboxr(options, label, id, name, val, checked, mand) then
403   - check_box_r(options, label + star(mand), id, name, val, checked),
  405 + checkboxr(options, label, id, wan, val, checked, mand) then
  406 + check_box_r(options, label + star(mand), id, wan, val, get_Bool(lwa, wan.name, checked)),
404 407  
405   - checkbox_hide_show(options, label, name, val, checked, fields) then
  408 + checkbox_hide_show(options, label, wan, val, checked, fields) then
406 409 with div_id = generate_random_string(15),
407 410 sequence([
408   - check_box([event(onclick, "checkbox_hide_show_element('"+div_id+"', this);")], label, htmlId(""), name, val, checked),
409   - div([id(div_id), style("display:"+if checked then "block" else "none")], sequence(map((CXM_Form_Field ff2) |-> div([class("form_field")], cxm_format_form_field(ff2)),fields)))
  411 + check_box([event(onclick, "checkbox_hide_show_element('"+div_id+"', this);")], label, htmlId(""), wan, val, get_Bool(lwa, wan.name, checked)),
  412 + div([id(div_id), style("display:"+if checked then "block" else "none")], sequence(map((CXM_Form_Field ff2) |-> div([class("form_field")], cxm_format_form_field(ff2, lwa)),fields)))
410 413 ]),
411 414  
412   - radio_button(options, label, id, name, val, checked, mand) then
413   - radio_button(options, label + star(mand), id, name, val, checked),
  415 + radio_button(options, label, id, wan, val, checked, mand) then
  416 + radio_button(options, label + star(mand), id, wan, val, get_Bool(lwa, wan.name, checked)),
414 417  
415   - radio_buttonr(options, label, id, name, val, checked, mand) then
416   - radio_button_r(options, label + star(mand), id, name, val, checked),
  418 + radio_buttonr(options, label, id, wan, val, checked, mand) then
  419 + radio_button_r(options, label + star(mand), id, wan, val, get_Bool(lwa, wan.name, checked)),
417 420  
418 421 radio_button_list (options, label, id, wan, items, selected, mand, wide) then
  422 + with new_selected =
  423 + if get_String(lwa, wan.name) is
  424 + {
  425 + failure then selected,
  426 + success(value) then success(init(value))
  427 + },
  428 +
419 429 sequence([
420 430 literal("<label for=\"" + wan.name + "\">" + label + star(mand) + "</label>"),
421 431 div( [class("radiolist")], sequence(
... ... @@ -426,13 +436,13 @@ public define HTML_In_Form
426 436 if item is (wav, item_label) then
427 437 with id = if id is htmlId(the_id) then htmlId(the_id + "_radio_" + *i),
428 438 div([class(itemclass)], radio_button_r(options, item_label, id, wan, wav,
429   - if selected is success(v) then wav.value = v.value else false)),
  439 + if new_selected is success(v) then wav.value = v.value else false)),
430 440 items))
431 441 ),
432 442 ]),
433 443 one_line_fields(fields) then
434 444 table([nude],[row([],
435   - map((CXM_Form_Field ff2) |-> cell([],cxm_format_form_field(ff2)),fields))])
  445 + map((CXM_Form_Field ff2) |-> cell([],cxm_format_form_field(ff2, lwa)),fields))])
436 446 ,
437 447  
438 448 upload(options, label, id, name, w, mand) then
... ... @@ -449,7 +459,7 @@ public define HTML_In_Form
449 459 partial(p_content) then partial(p_content),
450 460 input_with_help(input, help_title, help_text, width) then
451 461 sequence([
452   - cxm_format_form_field(input),
  462 + cxm_format_form_field(input, lwa),
453 463 html_tooltip(force_String(help_title), help_text, width),
454 464 ]),
455 465  
... ... @@ -462,49 +472,53 @@ public define HTML_In_Form
462 472 div([class(htmlClass.class)], literal("&nbsp")),
463 473  
464 474 submit(attrs, htmlClass, action_name, mb_label, button_text, extra_operands) then
465   - actioner( same, // TODO change this to allow external URL
  475 + actioner( same, // TODO change this to allow external URL
466 476 if mb_label is
467 477 {
468   - failure then same,
469   - success(n) then same(n)
  478 + failure then same,
  479 + success(n) then same(n)
470 480 },
471 481 submit(attrs + [class(htmlClass.class)], button_text),
472 482 action_name,
473 483 extra_operands
474 484 ),
475   - empty then literal("")
476   - }.
  485 + empty then literal("")
  486 + }.
477 487  
478 488 public define HTML_In_Form
479   - cxm_fieldset
  489 + cxm_fieldset
480 490 (
481   - List(CoreAttrs) options,
482   - String legend,
483   - List(CXM_Form_Field)fields
484   - ) =
  491 + List(CoreAttrs) options,
  492 + String legend,
  493 + List(Web_arg) lwa,
  494 + List(CXM_Form_Field) fields
  495 + )=
485 496 sequence([
486 497 literal("<fieldset" + format_attrs(options) + ">"),
487 498 literal(if length(legend) > 0 then "<legend>" + legend + "</legend>" else ""),
488   - sequence( map((CXM_Form_Field ff) |-> div([class("form_field")], cxm_format_form_field(ff)), fields) ),
489   - literal("</fieldset>")]).
  499 + sequence( map((CXM_Form_Field ff) |-> div([class("form_field")], cxm_format_form_field(ff, lwa)), fields) ),
  500 + literal("</fieldset>")]
  501 + )
  502 + .
490 503  
491 504 public define HTML_In_Form
492 505 cxm_fieldset
493 506 (
494   - HtmlId fieldSetId,
495   - List(CXM_Form_Field)fields
  507 + HtmlId fieldSetId,
  508 + List(Web_arg) lwa,
  509 + List(CXM_Form_Field) fields
496 510 ) =
497   - cxm_fieldset([id(fieldSetId.id), class("aligned")], "", fields).
  511 + cxm_fieldset([id(fieldSetId.id), class("aligned")], "", lwa, fields).
498 512  
499 513 public define HTML_Off_Form
500 514 cxm_form
501 515 (
502   - String form_name,
503   - List(CoreAttrs) options,
504   - String action_name,
  516 + String form_name,
  517 + List(CoreAttrs) options,
  518 + String action_name,
505 519 List((String,String)) extra_ops,
506   - List(HTML_In_Form) fieldSets
507   - ) =
  520 + List(HTML_In_Form) fieldSets
  521 + )=
508 522 //div([class("formulaire")],
509 523 form( form_name,
510 524 [class("formulaire") . options],
... ... @@ -534,27 +548,28 @@ public define HTML_Off_Form
534 548 String form_name,
535 549 List(CoreAttrs) options,
536 550 HtmlId fieldSetId,
537   - String action_name,
  551 + String action_name,
538 552 List((String,String)) extra_ops,
539   -
  553 + List(Web_arg) lwa,
540 554 List(CXM_Form_Field) fields
541 555 ) =
542 556 cxm_form(form_name, options, action_name, extra_ops,
543 557 [
544   - cxm_fieldset([id(fieldSetId.id), class("aligned")], "", fields)
  558 + cxm_fieldset([id(fieldSetId.id), class("aligned")], "", lwa, fields)
545 559 ]).
546 560  
547 561 public define HTML_Off_Form
548 562 cxm_form
549 563 (
550   - String form_name,
551   - List(CoreAttrs) options,
552   - HtmlId fieldSetId,
553   - List(CXM_Form_Field) fields
  564 + String form_name,
  565 + List(CoreAttrs) options,
  566 + HtmlId fieldSetId,
  567 + List(Web_arg) lwa,
  568 + List(CXM_Form_Field) fields
554 569 ) =
555 570 cxm_form(form_name, options,
556 571 [
557   - cxm_fieldset([id(fieldSetId.id), class("aligned")], "", fields)
  572 + cxm_fieldset([id(fieldSetId.id), class("aligned")], "", lwa, fields)
558 573 ]).
559 574  
560 575 public define HTML_Off_Form
... ... @@ -568,9 +583,10 @@ public define HTML_Off_Form
568 583 public define HTML_Off_Form
569 584 cxm_form
570 585 (
571   - String form_name,
572   - HtmlId fieldSetId,
  586 + String form_name,
  587 + HtmlId fieldSetId,
  588 + List(Web_arg) lwa,
573 589 List(CXM_Form_Field) fields
574 590 ) =
575   - cxm_form(form_name, [], fieldSetId, fields).
  591 + cxm_form(form_name, [], fieldSetId, lwa, fields).
576 592  
... ...