form.anubis.bak 31.9 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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
/*
 * Created by PyramIDE.
 * User: フランスのトトロ 
 * Date: 07/12/2014
 * Time: 16:49
 * © David RENÉ
 */

// *************************************************************************************
// *** Generic form
// *************************************************************************************
read tools/basis.anubis
read system/string.anubis
read xlib/web/common.anubis
read xlib/web/web_arg_utils.anubis
read xlib/web/making_a_web_site.anubis
read xlib/web/html_tooltip.anubis
read xlib/web/widgets.anubis
read xlib/web/widgets/specialized_elements.anubis

public type Mandatory:         // used to mark fields as mandatory. 
   mandatory,
   non_mandatory.
   
public type Width:
   small,           //10  char
   narrow_small,    //20  char
   narrow,          //50  char
   wide,            //70  char
   custom(Int). 
   
public type FormFieldWidth:
   auto,
   custom(Int).
  
public type CXM_Form_Field:
  no_field,  // empty field
   
   //--- title field ---------------------------------------------------------------------
  title(
    String  text
  ),

   //--- message field -------------------------------------------------------------------
  message(
    String text
  ),
   
   //--- text input field ----------------------------------------------------------------
  input(
    List(CoreAttrs) options,
    HTML_Label      label,
    HTML_Id         id,
    WebArgName      web_arg_name,   
    InitialValue    init_value,
    Width           width, 
    Mandatory       mandatory
  ),
  
  input_readonly(
    List(CoreAttrs) options,
    HTML_Label      label,         
    HTML_Id         id,
    WebArgName      web_arg_name, 
    InitialValue    init_value,   
    Width           width
  ),
   
   //--- text area field -----------------------------------------------------------------
  text_area(
    List(TextAreaOption)  options,
    HTML_Label            label,
    HTML_Id               id,
    WebArgName            web_arg_name,
    InitialValue          init_value,
    Width                 width, 
    Int                   height,
    Mandatory             mandatory
  ),
   
   //--- password input field ------------------------------------------------------------
  password_input(
    List(CoreAttrs) options,
    HTML_Label      label,
    HTML_Id         id,
    WebArgName     web_arg_name,
    InitialValue   init_value,
    Width           width, 
    Mandatory       mandatory),
  
   //--- phone field ------------------------------------------------------------
  phone_input(
    Maybe(List(CoreAttrs)) sms_icon_options,  //if there is sms available it's success with the options (generally the js call to edit sms)
    List(CoreAttrs) phone_icon_options,
    List(CoreAttrs) text_options,
    HTML_Label      label,
    HTML_Id         id,
    WebArgName      web_arg_name,
    InitialValue    init_value,
    Phone_Type      phone_type,
    Width           width, 
    Mandatory       mandatory),

   //--- email field ------------------------------------------------------------
  email_input(
    List(CoreAttrs) icon_options,
    List(CoreAttrs) options,
    HTML_Label      label,
    HTML_Id         id,
    WebArgName      web_arg_name,
    InitialValue    init_value,
    Width           width, 
    Mandatory       mandatory),

   //--- url field ------------------------------------------------------------
  url_input(
    List(CoreAttrs) icon_options,
    List(CoreAttrs) options,
    HTML_Label      label,
    HTML_Id         id,
    WebArgName      web_arg_name,
    InitialValue    init_value,
    Width           width, 
    Mandatory       mandatory),
    
   //--- hidden field ------------------------------------------------------------
  hidden(
    HTML_Id         id,
    WebArgName      web_arg_name,
    WebArgValue     init_value
  ),
   //--- explanation field ---------------------------------------------------------------
  explain(
    String text
  ),
   
   //--- selector field ------------------------------------------------------------------
  selector(
    List(CoreAttrs) options,
    HTML_Label    label, 
    HTML_Id         id,
    WebArgName     web_arg_name, 
    Int            size,
    List(String)   items,
    Maybe(InitialValue)  selected,
    Mandatory      mandatory
  ),
                   
  selector_c(
    List(CoreAttrs)  options,
    HTML_Label       label,
    HTML_Id            id,
    WebArgName        web_arg_name, 
    Int               size,
    List((List(CoreAttrs), WebArgValue, String))   items,
    Maybe(InitialValue) selected,
    Mandatory           mandatory
  ),
   
   selector_hide_show (List(CoreAttrs) options,
                   HTML_Label     label, 
                   HTML_Id         id,
                   WebArgName     web_arg_name, 
                   Int            size,
                   List((List(CoreAttrs), WebArgValue, String, HTML_Partial_Content))   items,
                   Maybe(InitialValue)  selected,
                   Mandatory      mandatory), 
   
   //--- checkbox field ------------------------------------------------------------------
   checkbox       (List(CoreAttrs) options,
                   HTML_Label      label, 
                   HTML_Id           id, 
                   WebArgName       web_arg_name, 
                   Bool             checked,
                   Mandatory        mandatory),
                   
   // the same one, but with the tag on the right of the checkbox
  checkboxr(
    List(CoreAttrs) options,
    HTML_Label      label, 
    HTML_Id           id, 
    WebArgName       web_arg_name, 
    Bool             checked,
    Mandatory        mandatory
  ),
                   
  //checkbox_hide_show
  checkbox_hide_show( 
    List(CoreAttrs)      options,
    HTML_Label           label,
    WebArgName            web_arg_name, 
    Bool                  checked,
    List(CXM_Form_Field)  fields
  ),
            
   //--- radio-button field --------------------------------------------------------------
  radio_button(
    List(CoreAttrs)  options,
    HTML_Label       label, 
    HTML_Id            id, 
    WebArgName        web_arg_name,
    WebArgValue       web_arg_value,
    Bool              checked,
    Mandatory         mandatory
  ),
  //radio_button_hide_show
  radio_button_hide_show(
    List(CoreAttrs)      options,
    HTML_Label           label,
    WebArgName            web_arg_name, 
    WebArgValue           web_arg_value,
    Bool                  checked,
    List(CXM_Form_Field)  fields
  ),
   // the same one, but with the tag on the right of the radio_button
   radio_buttonr  (List(CoreAttrs) options,
                   HTML_Label    label, 
                   HTML_Id         id, 
                   WebArgName     web_arg_name, 
                   WebArgValue    web_arg_value,
                   Bool           checked,
                   Mandatory      mandatory), 
   
  radio_button_list(
    List(CoreAttrs) options,
                      HTML_Label         label, 
                      HTML_Id         id,
                      WebArgName     web_arg_name, 
                      List((WebArgValue, String))    web_arg_value,
                      Maybe(InitialValue)  selected,
                      Mandatory      mandatory,
                      Bool           is_wide),

//   //--- fields table --------------------------------------------------------------------
//   fields_table   (String            tag,
//                   List(FormField)   fields),
//   
//   //--- fields line ---------------------------------------------------------------------
//   fields_line   (String            tag,
//                   List(FormField)   fields),
   one_line_fields   (List(CXM_Form_Field)   fields),

//   
//   //--- preview field -------------------------------------------------------------------
//   preview        (String         html_text), 
  
   //--- upload field -------------------------------------------------------------------
   upload           (List(CoreAttrs) options,
                    HTML_Label         label,
                    HTML_Id          id,
                    WebArgName      name,
                    Width           width,
                    Mandatory       mandatory),

   raw_in_form      (HTML_Off_Form   html),
   label_for        ( String          label,
                      HTML_Id          id,
                      HTML_Off_Form    input),
   div              (List(CoreAttrs), List(HTML_Off_Form)    contents),
   div              (List(CoreAttrs), List(CXM_Form_Field)  fields),
   partial          (HTML_Partial_Content p_content),
   br,
   hr               (List(CoreAttrs) options),
//   input_with_help  (CXM_Form_Field   field,
//                    Maybe(String)  help_title,
//                    String         help_text,
//                    Int          width),

   fieldset         (List(CoreAttrs)      options,
                    String                legend,
                    List(CXM_Form_Field)  fields),
   
   blank_space,
   blank_space     (HtmlClass class),

   //--- submit button -------------------------------------------------------------------
   submit         (List(CoreAttrs)          options,
                   HtmlClass                class,
                   WEB_Action_Name          action_name,
                   Maybe(String)            label, 
                   String                   button_text, 
                   List((String,String))    extra_operands),
   empty.

// //////////////////////////////////////////////   
// Alternate constructors:

public define CXM_Form_Field
  fieldset
  (
    HTML_Id                fieldSetId,
    List(CXM_Form_Field)  fields
  ) =
  fieldset([id(fieldSetId.id)], "", fields).

public define CXM_Form_Field
  fieldset
  (
    List(CXM_Form_Field)  fields
  ) =
  fieldset([], "", fields).

public define CXM_Form_Field
  fieldset
  (
    String                legend,
    List(CXM_Form_Field)  fields
  ) =
  fieldset([], legend, fields).
  
public define CXM_Form_Field
  input(WebArgName n, InitialValue init_value, Width width)
  =  input([], no_label, html_Id(n.name), n, init_value, width, non_mandatory).

public define CXM_Form_Field
  input(HTML_Label label, WebArgName n, InitialValue init_value, Width width)
  =  input([], label, html_Id(n.name), n, init_value, width, non_mandatory).

public define CXM_Form_Field
  input(HTML_Label label, WebArgName n, InitialValue init_value, Width width, Mandatory mand)
  =  input([], label, html_Id(n.name), n, init_value, width, mand).

public define CXM_Form_Field
  input(HTML_Label label, HTML_Id id, WebArgName n, InitialValue init_value, Width width, Mandatory mand)
  =  input([], label, id, n, init_value, width, mand).

public define CXM_Form_Field
  input(List(CoreAttrs) options, HTML_Label label, WebArgName n, InitialValue init_value, Width width, Mandatory mand)
  =  input(options, label, html_Id(n.name), n, init_value, width, mand).
  
public define CXM_Form_Field
  input_readonly(HTML_Label label, WebArgName n, InitialValue init_value, Width width)
  =  input_readonly([], label, html_Id(n.name), n, init_value, width).

public define CXM_Form_Field
  password_input(HTML_Label label, WebArgName n, InitialValue init_value, Width width, Mandatory mand)
  =  password_input([], label, html_Id(n.name), n, init_value, width, mand).

public define CXM_Form_Field
  checkbox(HTML_Label label, WebArgName n, Bool checked, Mandatory mand)
  = checkbox([], label, html_Id(n.name), n, checked, mand).
  
public define CXM_Form_Field
  checkboxr(HTML_Label label, WebArgName n, Bool checked, Mandatory mand)
  = checkboxr([], label, html_Id(n.name), n, checked, mand).

public define CXM_Form_Field
  radio_button(HTML_Label label, WebArgName n, WebArgValue  value, Bool checked, Mandatory mand)
  = radio_button([], label, html_Id(n.name), n, value, checked, mand).

public define CXM_Form_Field
  radio_buttonr(HTML_Label label, WebArgName n, WebArgValue  value, Bool checked, Mandatory mand)
  = radio_buttonr([], label, html_Id(n.name), n, value, checked, mand).

public define CXM_Form_Field
  submit(WEB_Action_Name action_name, HtmlClass class, Maybe(String) label, String button_text, List((String,String)) extra_operands)
  = submit([], class, action_name, label, button_text, extra_operands).

public define CXM_Form_Field
  submit(WEB_Action_Name action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands)
  = submit([], htmlClass(""), action_name, label, button_text, extra_operands).

public define CXM_Form_Field
  submit(WEB_Action_Name action_name, Maybe(String) label, String button_text)
  = submit([], htmlClass(""), action_name, label, button_text, []).
  
public define CXM_Form_Field  //Helper for older project wich use only String as Action name
  submit(String _action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands)
  = submit([], htmlClass(""), action_name(_action_name), label, button_text, extra_operands).


public define CXM_Form_Field
  upload(HTML_Label label, HTML_Id id, WebArgName name, Width width)
  = upload([], label, id, name, width, non_mandatory).

public define CXM_Form_Field
  upload(HTML_Label label, HTML_Id id, WebArgName name, Width width, Mandatory mand)
  = upload([], label, id, name, width, mand).

public define CXM_Form_Field
  ip_input
  (
    String      label,
    HTML_Id      id,
    WebArgName  wan_prefix,
    String      ip
  )=
  label_for(
    label,
    id,
    ip_input(id, wan_prefix, ip)
  ).


public define CXM_Form_Field
  partial_ip_input
  (
    String        label,
    HTML_Id        id,
    WebArgName    wan_prefix,
    List(String)  ip_fixed_part,
    String        ip
  )=
  label_for(
    label,
    id,
    partial_ip_input(id, wan_prefix, ip_fixed_part, ip)
  ).

public define CXM_Form_Field
  hidden
  (
    WebArgName    web_arg_name,
    WebArgValue   value
  )=
  hidden(html_Id(""), web_arg_name, value).
  
public define CXM_Form_Field
  hr
  =
  hr([])
.

public define CXM_Form_Field
  div
  ( 
    List(CoreAttrs) attrs, 
    HTML_Off_Form   content
  )=
  div(attrs, [content])
.

public define CXM_Form_Field
  div
  ( 
    HTML_Off_Form    content
  )=
  div([], [content])
.  
   //--- explanation field ---------------------  
  
// //////////////////////////////////////////////////////////

define (List((List(CoreAttrs), WebArgValue, String)), List(HTML_Partial_Content))
  construct_selector_hide_show
  (
    String div_id,
    List((List(CoreAttrs), WebArgValue, String, HTML_Partial_Content)) items,
    List((List(CoreAttrs), WebArgValue, String)) so_far_1,
    List(HTML_Partial_Content) so_far_2,
    Int n
  ) =
    if items is
    {
      [] then (so_far_1, so_far_2),
      [h . t] then
        since h is (cores, wav, label, content),
          with linked_element = div_id + n,
          construct_selector_hide_show(div_id, t, [([data("linked_element", linked_element) . cores], wav, label) . so_far_1], [ partial_content([], div([id(linked_element), style("display: none")], content)) . so_far_2 ], n + 1)
    }.  
    
define (List((List(CoreAttrs), WebArgValue, String)), List(HTML_Partial_Content))
  construct_selector_hide_show
  (
    String div_id,
    List((List(CoreAttrs), WebArgValue, String, HTML_Partial_Content)) items
  ) = construct_selector_hide_show(div_id, items, [], [], 0).

public define HTML_Off_Form
  format_div_CXM_Form_Field
  (
    List(CXM_Form_Field)  field,
    List(Web_arg)         lwa,
    String                _class,
    Bool                  b_with_label
  ).


public define HTML_Off_Form
  format_CXM_Form_Field
  (
    CXM_Form_Field  ff,           //CXM_Form_Field to format
    List(Web_arg)   lwa,          //web arguments of the session, can be useful for the current drawing
    String          _class,
    Bool            b_with_label  //if false, no need to show/generate label
  ) =
  with star = (HTML_Label l, Mandatory m) 
              |->
                (HTML_Label)
                if b_with_label then
                  if m is 
                  {
                  mandatory      then
                    if l is 
                    {
                      no_label         then l,
                      label(str, help) then label(str + "<span>*</span>", help),
                    }
                  non_mandatory  then l
                  }
                else
                  no_label
                ,
     pixels = (Width width)
              |->
                if width is
                {
                  small         then 10,
                  narrow_small  then 20,
                  narrow        then 50, 
                  wide          then 70,
                  custom(n)     then n
                },


  if ff is 
  {
    no_field    then empty,
    
    title(t)    then h3(t),
  
    message(t)  then literal(t),
 
    input(options, _label, id, wan, default, w, mand) then
      text_input([class("in") . options], star(_label, mand), id, wan, init(get_String(lwa, wan.name, default.value)), pixels(w)),

    input_readonly(options, _label, id, name, init, w) then
      text_input_ro([class("in") . options], _label, id, name, init, pixels(w)),
      
    text_area(options, _label, id, wan, default, w, height, mand) then  
      text_area([input_attrs([class("in")]) . options], star(_label, mand), id, wan, init(get_String(lwa, wan.name, default.value)), pixels(w), height),

    password_input(options, _label, id, name, init, w, mand) then
      password_input([class("in") . options], star(_label, mand), id, name, init, pixels(w)),

    phone_input(mb_sms_options, icon_options, options, _label, _id, wan, default, phone_type, w, mand) then
      sequence([
        if mb_sms_options is
        {
          failure               then  empty,
          success(sms_options)  then  img([event(onmouseover, "/icons/16x16/send_sms.png")]+sms_options, "/icons/16x16/sms.png")
        },
        img(icon_options, "/icons/16x16/"+to_Icon(phone_type)),
        input([class("in"), id(_id.id), name(wan.name), init(get_String(lwa, wan.name, default.value)), size(pixels(w)). options]),
      ]),

    email_input(icon_options, options, _label, id, wan, default, w, mand) then
      sequence([
        img(icon_options, "/icons/16x16/email_edit.png"),
        text_input([class("in") . options], star(_label, mand), id, wan, init(get_String(lwa, wan.name, default.value)), pixels(w)),
      ]),

    url_input(icon_options, options, _label, id, wan, default, w, mand) then
      sequence([
        img(icon_options, "/icons/16x16/url.png"),
        text_input([class("in") . options], star(_label, mand), id, wan, init(get_String(lwa, wan.name, default.value)), pixels(w)),
      ]),
      
    hidden(h_id, name, init) then  hidden(name, init),

    explain(t) then
      div([class("sub")], literal(t)),

    selector(options, _label, id, wan, size, items, selected, mand) then  
      if selected is
      {
        failure          then selector([class("in") . options], star(_label, mand), id, wan, size, items),
        success(default) then selector([class("in") . options], star(_label, mand), id, wan, size, items, init(get_String(lwa, wan.name, default.value))),
      },
    
    selector_c(options, _label, id, wan, size, items, selected, mand) then 
      if selected is
      {
        failure          then selector_c([class("in") . options], star(_label, mand), id, wan, size, items),
        success(default) then selector_c([class("in") . options], star(_label, mand), id, wan, size, items, init(get_String(lwa, wan.name, default.value))),
      },
    
    selector_hide_show(options, _label, id, wan, size, items_with_partial, selected, mand) then   
      with div_id = generate_random_string(15),
      since construct_selector_hide_show(div_id, items_with_partial) is (items, partial_content_list), 
      sequence([
          selector_c([class("in"), class("cxm_selector_hide_show"), event(onchange, "select_hide_show('" + div_id + "', this);")], star(_label, mand), id, wan, size, reverse(items), if selected is { failure then init(""), success(default) then init(get_String(lwa, wan.name, default.value)) } ),
              partial(partial_content(partial_content_list))
            ]),
    
    checkbox(options, _label, id, wan, checked, mand) then
      check_box([class("in") . options], star(_label, mand), id, wan, get_Bool(lwa, wan.name, checked)),
 
    checkboxr(options, _label, id, wan, checked, mand) then
      check_box_r([class("in") . options], star(_label, mand), id, wan, get_Bool(lwa, wan.name, checked)),
      
    checkbox_hide_show(options, _label, wan, checked, fields)  then  
      with div_id = generate_random_string(15),
      sequence([
        check_box([data("show_id", div_id), class("in cxm_checkbox_hide_show"), event(onclick, "checked_hide_show_element('"+div_id+"', this);")], _label, html_Id("checkbox_"+div_id), wan, get_Bool(lwa, wan.name, checked)),
        div([id(div_id), style("display:"+if checked then "block" else "none")], format_div_CXM_Form_Field(fields, lwa, _class, b_with_label))
      ]),
              
    radio_button(options, _label, id, wan, val, checked, mand) then
      radio_button([class("in"), event(onclick, "radio_hide_show_group('"+wan.name+"', this);") . options], star(_label, mand), id, wan, val, get_Bool(lwa, wan.name, checked)),

    radio_button_hide_show(options, _label, wan, val, checked, fields)  then  
      with div_id = generate_random_string(15),
      sequence([
        radio_button([data("show_id", div_id), class("in"), class("cxm_radio_hide_show"), event(onclick, "radio_hide_show_group('"+wan.name+"', this);")], _label, html_Id("radio_button_hide_show_"+div_id), wan, val, get_Bool(lwa, wan.name, checked)),
        div([id(div_id), style("display:"+if checked then "block" else "none")], format_div_CXM_Form_Field(fields, lwa, _class, b_with_label))
              ]),
 
    radio_buttonr(options, _label, id, wan, val, checked, mand) then
      radio_button_r([class("in") . options], star(_label, mand), id, wan, val, get_Bool(lwa, wan.name, checked)),
 
    radio_button_list (options, _label, id, wan, items, selected, mand, wide) then
      with new_selected = 
        if get_String(lwa, wan.name) is
        {
          failure         then selected,
          success(value)  then success(init(value))
        },
        
      sequence([
        //literal("<label for=\"" + wan.name + "\">" + label + star(_label, mand) + "</label>"),
        div( [class("radiolist")], sequence(
          with i = var((Int)-1),
               itemclass = if wide then "radiolistitem_wide" else "radiolistitem",
          map( ((WebArgValue, String) item) |->
                  i <- *i + 1;
                  if item is (wav, item_label) then
                  with _id = if id is html_Id(the_id) then html_Id(the_id + "_radio_" + *i),
                  div([class(itemclass)], radio_button_r(options, label(item_label), _id, wan, wav, 
                                                         if new_selected is success(v) then wav.value = v.value else false)),
               items))
        ),
      ]),
    one_line_fields(fields) then
      table([nude, class("form_one_line")],[row([], 
             map((CXM_Form_Field ff2) |-> cell([],format_CXM_Form_Field(ff2, lwa, _class, b_with_label)),fields))])
    ,
      
    upload(options, _label, id, name, w, mand) then
      file_upload([class("in") . options], star(_label, mand), id, name, pixels(w)),
     
    raw_in_form(html)   then  html,
//      div([class("in")], html),
    label_for(label, id, input) then
      sequence([
        if id is html_Id(_id) then
          literal("<label for=\"" + _id + "\">" + label + "</label>"),
          input
      ]),
      
    div(options, e)     then  div(options, e),
    div(options, fields)then  div(options, format_div_CXM_Form_Field(fields, lwa, _class, b_with_label)),
    partial(p_content)  then partial(p_content),
    br                  then br,
    hr(opts)            then hr(opts),
//    input_with_help(input, help_title, help_text, width) then 
//      sequence([
//        format_CXM_Form_Field(input, lwa, html_tooltip(force_String(help_title), help_text, width)),
//      ]),

    fieldset(options, legend, fields) then
      sequence([
        literal("<fieldset" + format_attrs(options) + ">"),
        literal(if length(legend) > 0 then "<legend>" + legend + "</legend>" else ""),
          format_div_CXM_Form_Field(fields, lwa, _class, b_with_label),
        literal("</fieldset>")
      ]),
      
    blank_space then
      div([class("blank_space")], literal("&nbsp")),
          
    blank_space(htmlClass) then
      div([class(htmlClass.class)], literal("&nbsp")),
      
    submit(attrs, htmlClass, action_name, Maybe(String) mb_label, button_text, extra_operands) then
      actioner( same, // TODO change this to allow external URL
                if mb_label is
                {
                  failure     then same,
                  success(n)  then same(n)
                },
                submit(attrs + [class(htmlClass.class + " cxm_submit")], button_text),
                action_name,
                extra_operands
              ),
    empty  then  literal("")
  }.

    
public define HTML_Off_Form
  format_div_CXM_Form_Field
  (
    List(CXM_Form_Field)  fields,
    List(Web_arg)         lwa,
    String                _class,
    Bool                  b_with_label
  )=
  //println("format_div_CXM_Form_Field");
  sequence( map((CXM_Form_Field field) 
    |->
    //with css_line = if line = 0 then " odd_line" else " even_line",
    //println("class "+css_line+" line "+line);    
      if field is empty then
        empty   
      else if field is no_field then 
        empty 
      else if field is hidden(_id, name, init) then
        format_CXM_Form_Field(field, lwa, _class, b_with_label)
      else if field is br then
        format_CXM_Form_Field(field, lwa, _class, b_with_label)
      else if field is text_area(options, _label, id, wan, default, w, height, mand) then
        div([class(_class)], format_CXM_Form_Field(field, lwa, _class, b_with_label))
      else       
        div([class(_class)], format_CXM_Form_Field(field, lwa, _class, b_with_label))
    , fields))
.

public define HTML_Off_Form
  to_HTML_Off_Form
  (
    List(CXM_Form_Field)  fields,
    List(Web_arg)         lwa,    
    String                _class,
    Bool                  b_with_label
  )=
  format_div_CXM_Form_Field(fields, lwa, _class, b_with_label)
.

public define HTML_Off_Form
  to_HTML_Off_Form
  (
    List(CXM_Form_Field)  fields,
    String                _class,
    Bool                  b_with_label
  )=
  to_HTML_Off_Form(fields, [], _class, b_with_label).

public define HTML_Off_Form
  to_HTML_Off_Form
  (
    List(CXM_Form_Field)  fields,
    List(Web_arg)         lwa
  )=
  to_HTML_Off_Form(fields, lwa, "form_field aligned", true)
.

public define HTML_Off_Form
  to_HTML_Off_Form
  (
    CXM_Form_Field        field,
    List(Web_arg)         lwa
  )=
  to_HTML_Off_Form([field], lwa, "form_field aligned", true)
.
  
public define HTML_Off_Form
  to_HTML_Off_Form
  (
    List(CXM_Form_Field)  fields
  )=
  to_HTML_Off_Form(fields, [], "form_field aligned", true)
.

public define HTML_Off_Form
  cxm_form
  (
    HTML_Id               form_Id,
    List(CoreAttrs)       options,
    WEB_Action_Name                action,
    List((String,String)) extra_ops,
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  fields,
    String                _class,
    Bool                  b_with_label
  ) =
  form(  
    //form_Id,
    [class("cxm_form"), id(form_Id.id) . options],
    action,
    extra_ops,
    format_div_CXM_Form_Field(fields, lwa, _class, b_with_label)
  ).
  
public define HTML_Off_Form
/* older manner to call CXM_form with action as String.
 * this function only exists for compatibility with older projects. Please consider
 * to use the above function with WEB_Action_Name instead of String
*/
  cxm_form
  (
    HTML_Id               form_Id,
    List(CoreAttrs)       options,
    String                action,     //older manner to call action with String
    List((String,String)) extra_ops,
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  fields,
    String                _class,
    Bool                  b_with_label
  ) =
  
  form(  
    //form_Id,
    [class("cxm_form"), id(form_Id.id) . options],
    action_name(action),
    extra_ops,
    format_div_CXM_Form_Field(fields, lwa, _class, b_with_label)
  ).
      
public define HTML_Off_Form
  cxm_form
  (
    String                form_name, 
    List(CoreAttrs)       options,
    WEB_Action_Name       action, 
    List((String,String)) extra_ops,
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  form_fields,
    String                _class,
    Bool                  b_with_label
  )=
  cxm_form(html_Id(form_name), options, action, extra_ops, lwa, form_fields, _class, b_with_label).

public define HTML_Off_Form
  cxm_form
  (
    String                form_name, 
    List(CoreAttrs)       options,
    WEB_Action_Name       action, 
    List((String,String)) extra_ops,
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  form_fields
  )=
  cxm_form(form_name, options, action, extra_ops, lwa, form_fields, "form_field aligned", true)
.
  
public define HTML_Off_Form
  cxm_form
  (
    String                form_name, 
    List(CoreAttrs)       options,
    String                action, 
    List((String,String)) extra_ops,
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  form_fields,
    
    Bool                  b_with_label
  )=
  cxm_form(html_Id(form_name), options, action_name(action), extra_ops, lwa, form_fields, "form_field aligned", b_with_label)
.

public define HTML_Off_Form
  cxm_form
  (
    String                form_name,
    List(CoreAttrs)       options,
    String                action,
    List((String,String)) extra_ops,
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  form_fields
  )=
  cxm_form(html_Id(form_name), options, action_name(action), extra_ops, lwa, form_fields, "form_field aligned", true)
.

public define HTML_Off_Form
  cxm_form
  (
    String              form_id, 
    List(CoreAttrs)     options,
    List(HTML_Off_Form)  fields,
    String              _class
  ) =
  cxm_form(html_Id(form_id), options, action_name(""), [], [], map((HTML_Off_Form field) |-> raw_in_form(field), fields), _class, true )
.

public define HTML_Off_Form
  cxm_form
  (
    String              form_id, 
    List(CoreAttrs)      options,
    List(HTML_Off_Form)  fields
  ) =
  cxm_form(options, action_name(""), [], [], map((HTML_Off_Form field) |-> raw_in_form(field), fields), "form_field aligned", true )
.

public define HTML_Off_Form
  cxm_form
  (
    String                form_id,
    List(CoreAttrs)       options,
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  fields,
    String                _class,
    Bool                  b_with_label
  ) =
  cxm_form(html_Id(form_id), options, action_name(""), [], lwa, fields, _class, b_with_label).
  
public define HTML_Off_Form
  cxm_form
  (
    String              form_id,
    List(HTML_Off_Form)  fields,
    String              _class
  ) =
  cxm_form(html_Id(form_id), [], action_name(""), [], [], map((HTML_Off_Form field) |-> raw_in_form(field), fields), _class, true ).

public define HTML_Off_Form
  cxm_form
  (
    String                form_id, 
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  fields,
    String                _class
  ) =
  cxm_form(form_id, [], lwa, fields, _class, true).

public define HTML_Off_Form
  cxm_form
  (
    String                form_id, 
    List(Web_arg)         lwa,
    List(CXM_Form_Field)  fields,
  ) =
  cxm_form(form_id, [], lwa, fields, "form_field aligned", true).

public define HTML_Off_Form
  cxm_form
  (
    String                form_id, 
    List(CoreAttrs)       options,
    List(CXM_Form_Field)  fields,
  ) =
  cxm_form(form_id, options, [], fields, "form_field aligned", true).  

public define HTML_Off_Form
  cxm_form
  (
    String                form_id, 
    List(CXM_Form_Field)  fields,
    String                _class
  ) =
  cxm_form(html_Id(form_id), [], action_name(""), [], [], fields, _class, true).
  
public define HTML_Off_Form
  cxm_form
  (
    String                form_id, 
    List(CXM_Form_Field)  fields
  ) =
  cxm_form(html_Id(form_id), [], action_name(""), [], [], fields, "form_field aligned", true).