view_table_renderer.anubis 54.5 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 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
/*
 * Created by PyramIDE.
 * User: Totoro
 * Date: 30/11/2011
 * Time: 21:22
 * 
 */

read hayamiki_lib/view/types/hk_form_entry.anubis
read hayamiki_lib/view/types/hk_form.anubis
read hayamiki_lib/view/types/hk_view.anubis
read hayamiki_lib/view/jqgrid.anubis
read hayamiki_lib/view/view_table_manager_types.anubis
read hayamiki_lib/view/view_table_manager.anubis
read hayamiki_lib/view/web_action.anubis
read hayamiki_lib/types/hayamiki.anubis
read system/string.anubis
read locale/L3.anubis
read tools/basis.anubis
read tools/base64.anubis
read tools/list.anubis
read tools/printable_tree.anubis
read data_base/sqlite.anubis
read system_colors/rgb.anubis
read system/convert.anubis

//read utils.anubis
read locale/L3LanguageInfo.anubis
read calexium_lib/web/CXM_common.anubis
read calexium_lib/web/CXM_web_arg_utils.anubis
read calexium_lib/web/CXM_making_a_web_site.anubis
read calexium_lib/web/CXM_multihost_http_server.anubis
read calexium_lib/web/jQuery/CXM_jquery_datatable.anubis
read calexium_lib/web/jQuery/CXM_jquery_datatable_types.anubis
read calexium_lib/web/jQuery/CXM_jquery_dialog.anubis      
read calexium_lib/web/jQuery/CXM_jquery_button.anubis
read calexium_lib/web/jQuery/CXM_jq_form.anubis
read calexium_lib/web/jQuery/ui-addon/datetimepicker.anubis
read calexium_lib/web/jQuery/jqgrid.anubis
read calexium_lib/web/CXM_form.anubis
read calexium_lib/web/widgets/css_helper.anubis
read calexium_lib/web/widgets/button.anubis
read calexium_lib/web/widgets/specialized_elements.anubis
read calexium_lib/web/CXM_urllib.anubis

public define List(CXM_Form_Field)
  get_hidden
  (
    List(Web_arg)         lwa
  )=
  map_select((Web_arg warg) |-> 
    if warg is web_arg(name, value) then
    if starts_with(name, "hidden_") then
      with len_string = length(name),
        if sub_string(name, 7, len_string - 7) is
        {
          failure     then failure,
          success(n)  then success(hidden(html_Id(""), wan(n), wav(value)))
        }
    else
      failure
    else
      failure
    ,
    lwa)
.

public define Phone_Type
  convert
  (
    HK_Phone_Field_Attr phone_attr
  )=
  if phone_attr is
  {
    generic   then  generic,
    landline  then  landline,
    cellphone then  cellphone,
    fax       then  fax
  }
.

public define List(HK_Filter)
  get_view_filters
  (
    String                          view_name,
    List((String, List(HK_Filter))) all_view_name
  )=
  if all_view_name is
  {
    []      then [],
    [h . t] then
      since h is (v_name, filters),
      if v_name = view_name then
        filters
      else
        get_view_filters(view_name, t)
  }
.

public define HK_Filter
  get_default_filter
  (
    VTM_view  vtm_v,      //virtual table manager view
    String    view_name   //
  )=
  with all_view_name = vtm_v.get_all_view_name(unique),
  with filters = get_view_filters(view_name, all_view_name),
    filter_len = length(filters),
    
  if filter_len = 0 then
    hk_filter("", "")
  else 
    if filters is 
    {   []      then  hk_filter("", ""),
        [h . _] then  h
    }
.

public define HK_Filter
  get_filter_from_name
  (
    List(HK_Filter) filters,  
    String          _filter_name
  )=
  if filters is
  {
    []      then hk_filter("", ""),
    [h . t] then
      if h.filter_name = _filter_name then
        h
      else
        get_filter_from_name(t, _filter_name)
  }
.
  
public define HK_Filter
  get_filter_from_name
  (
    VTM_view  vtm_v,      //virtual table manager view
    String    view_name,  //view name where belonging the filters
    String    filter_name //the filter name to get
  )=
  with all_view_name = vtm_v.get_all_view_name(unique),
  with filters = get_view_filters(view_name, all_view_name),
  
  //we don't have any filter name to search for, hence we get the first entry
  if filter_name = "" then
    force_nth(0, filters, hk_filter("", ""))
  else
    //else try to get the filter according to his name
    get_filter_from_name(filters, filter_name)
.

define String
  ajax_combo_init_parameter
  (
    String        combo_uid,
    String        f_table,    //db table name
    String        c_name,     //column name in the table
    Maybe(Int) init_value,    //
    List(String)  s_fields,   //search fields
    List(HK_Foreign_Key_Active_Filter) active_filters
  )=
        println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
          since a_filter is active_filter(column, fk_column),
          "column '"+column+"' fk_column '"+fk_column+"\n" 
          ,
          active_filters
        )))
        ;
"$('#"+combo_uid+"').ajaxComboBox( '?aws_controller=hk_c&aws_action=combo_search',
 {"
+
if init_value is {failure then "", success(value) then
"  init_record: "+value+",\n"}
+
"  lang: 'fr',
  per_page: 15,
  db_table: '"+f_table+"',
  button_img: 'ajax-combobox/btn.png',
  field: '"+force_nth(0, s_fields, "name")+"',
" +
(if length(active_filters) > 0 then
  "active_filters: ["+join(", ", map((HK_Foreign_Key_Active_Filter a_filter) |->
          since a_filter is active_filter(column, fk_column),
          "['"+column+"', '"+fk_column+"']"
          ,
          active_filters
        ))+"],"
else
"")
+" 
  search_field: '"+join(", ", s_fields)+"',
  hidden_name: '"+c_name+"',
"+(if "__HK_SHOW_STRING__":s_fields then
"  show_string: '__HK_SHOW_STRING__',\n"
  else
"  show_string: '"+join(", ", s_fields)+"',\n")
+
"  and_or: 'OR'\n
 });"
.

define HTML_In_Form
/* create a selector for choosing the view name.
 * The selector create an immediate action. This means when the entry is selected, the action is fired.
 * If only one view exists, the selector is not created
 */
  table_filter_selector
  (
    (String)  ->  String  _T,           //translator function
    List((String, List(HK_Filter)))   all_view_name,        //virtual table manager view
    String                current_view, //
    String                current_filter
  )=
  with filters = get_view_filters(current_view, all_view_name),
    filter_len = length(filters),
  
  if filter_len = 0 then
    hidden(wan("filter_name"), wav("no_filter"))
  else if filter_len = 1 then
    with filter_name = if filters is { [] then "", [h . _] then h.filter_name },
    hidden(wan("filter_name"), wav(filter_name))
  else
    actioner(same, same,
      immediate_selector([id("select_view")],
      wan("filter_name"), //web arg name of the selected entry
      1,
      map(((HK_Filter) filter) |-> ([], wav(filter.filter_name), _T(filter.filter_name)), filters),
      success(init(current_filter)),
      ""
    ),
    hkc_list_view_filter, //web_actioner
    [], [])
.

define HTML_Off_Form
/* create a selector for choosing the view name.
 * The selector create an immediate action. This means when the entry is selected, the action is fired.
 * If only one view exists, the selector is not created
 */
  table_view_filter_selector
  (
    (String)  ->  String  _T,           //translator function
    VTM_view              vtm_v,        //virtual table manager view
    String                current_view,  //
    String                current_filter
  )=
  with all_view_name = vtm_v.get_all_view_name(unique),
  form( "table_view_filter_selector", [], "", [],
    sequence([
      hidden(wan("table_name"), wav(vtm_v.table_name)),
      (if length(all_view_name) = 1 then 
        empty
      else
        actioner(same, same,
          immediate_selector([id("select_view")],
            wan("view_name"), //web arg name of the selected entry
            1,
            map(((String, List(HK_Filter)) name_and_filters) |-> since name_and_filters is (view_name, filters), ([], wav(view_name), _T(view_name)), all_view_name),
            success(init(current_view)),
            ""
          ),
          hkc_list_view_name,  //web_actioner
          [], []
        )),  //!actionner
      table_filter_selector(_T, all_view_name, current_view, current_filter)
    ])
  )//!form
.


  // View table part
define HTML_Row(HTML_Off_Form)  make_line
  (
    String              uid,
    String              table_name,
    String              _action_name,            //default is "edit_table", but can be surcharged for own use
    List(VT_view_entry) entries,
    List(HTML_Cell(HTML_Off_Form)) so_far
  )=
  if entries is
  {
    []      then  row( [], reverse(so_far)),
    [h . t] then
      with cell = if h is
                  {
                    text(string)     then cell((HTML_Off_Form)text(not_null_String(string))),
//                    link(id, string) then cell((HTML_Off_Form)actioner(same,same, link(string), action_name, [("table_name", table_name),("id",id)])),
                    link(id, string)                  then cell((HTML_Off_Form)literal(jq_dialog_open(string, dialog_id(uid+_action_name+"_dlg_ajax"), "'id="+id+"'"))),
                    link_id_action(id, name, action)  then cell((HTML_Off_Form)actioner(same,same, link(name), action, [("id",id)])),
                    icon(icon_path)                   then cell((HTML_Off_Form)img(icon_path))
                  },
      make_line(uid, table_name, _action_name, t, [cell . so_far])
  }.

define List(HTML_Row(HTML_Off_Form))  
  make_lines
  (
    (String) -> String  _T,       //translator
    String            uid,
    String            table_name,
    String            action_name,
    List(VT_view_row) entries,
    List(HTML_Row(HTML_Off_Form))  so_far
  )=
  if entries is
  {
    []      then  reverse(so_far),
    [h . t] then  
      //compute each line
      //prepare here the first cell for actioner
      with actions_cell = (HTML_Cell(HTML_Off_Form))
        cell([],
          sequence([
            partial(img_button_confirm(icn16_cross, _T("CONFIRMATION_REQUEST"), _T("CONFIRM_LINE_DELETION") , _T("OK"), _T("CANCEL"), jQuery_actioner(same, jqlink(controller_action("hk_c", "delete_row" + format_extra_operands([("table_name", table_name),("id",to_String(h.db_id))])))))),
            partial(img_button(icn16_edit, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax"), "'id="+to_String(h.db_id)+"'"))], "", [])),           
          ])
        ),
      make_lines(_T, uid, table_name, action_name, t, [make_line(uid, table_name, action_name, h.list, [actions_cell]). so_far] )
  }.
  
  // View table part
define HTML_Header_Row(HTML_Off_Form)  
  make_header
  (
    (String) -> String                    _T,       //translator
    List(VT_view_entry)                   entries,
    List(HTML_Header_Cell(HTML_Off_Form)) so_far
  )=
  if entries is
  {
    []      then  header_row( [], reverse(so_far)),
    [h . t] then
      with cell = if h is
                  {
                    text(string)      then header_cell((HTML_Off_Form)text(_T(string))),
                    link(id, string)  then header_cell((HTML_Off_Form)actioner(same, same, link(string), hkc_edit_table,[])), //TODO
                    link_id_action(id, text, action)  then header_cell((HTML_Off_Form)actioner(same,same, link(text), action,[("id",id)])), //TODO
                    icon(icon_path)   then header_cell((HTML_Off_Form)img(icon_path))
                  },
      make_header(_T, t, [cell . so_far])
  }.


 
public define HTML_Partial_Content  
  view_table_form
  (
    (String) -> String    _T,
    String                uid,
    String                action_name,
    VT_view               rows
  )=
 with action_header_cell = header_cell((HTML_Off_Form)text(_T("ACTION"))),
  partial_content(
      div( [/*class("tableau")*/],
          sequence(
           [ 

              //partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))),
              //table([core_attrs([id(uid+"table_view"), class("tableau display compact nowrap")])],
               //     make_header(_T, rows.header.list, [action_header_cell])
               //     make_lines(_T, uid, rows.table_name, action_name, rows.list, [])
               //)
           ]
           )
      ))
 .

define String
  jqGrid_options
  (
    String              uid,
    VT_view             rows,
    (String) -> String  _T
  )=
  "
  editurl: '?aws_controller=hk_c&aws_action=grid_action&table_name="+rows.table_name+"',  
  iconSet: \"fontAwesome\",
  cmTemplate: { autoResizable: true},
  autoResizing: { compact: true, resetWidthOrg: true },
  autoresizeOnLoad: true,  
  autowidth:true,
  viewrecords: true,
  /*pager: true,*/
  toppager: true,
  
  /*shrinkToFit:false,*/
  rowNum:30,
  rowList:[5,10,20,30,50],
  cellEdit: false,
  cellsubmit: 'remote',
  cellurl: '?aws_controller=hk_c&aws_action=grid_action&table_name="+rows.table_name+"',
  editurl: '?aws_controller=hk_c&aws_action=grid_action&table_name="+rows.table_name+"',
  onSelectRow: function (rowid, status, e) {
    var $self = $(this), savedRow = $self.jqGrid(\"getGridParam\", \"savedRow\");
    if (savedRow.length > 0 && savedRow[0].id !== rowid) {
      $self.jqGrid(\"restoreRow\", savedRow[0].id);
    }
  },  
  ondblClickRow: function (rowid, iRow, iCol, e) {
    var $self = $(this), savedRow = $self.jqGrid(\"getGridParam\", \"savedRow\");
    if (savedRow.length > 0 && savedRow[0].id !== rowid) {
      $self.jqGrid(\"restoreRow\", savedRow[0].id);
    }
    $self.jqGrid(\"editRow\", rowid, { focusField: e.target });
  },
  
  afterAddRow: function () {
    recreateFilterToolbar.call(this);
                //updateAutocompleteSource.call(this, \"name\");
  },
  afterSetRow: function () {
    recreateFilterToolbar.call(this);
                //updateAutocompleteSource.call(this, \"name\");
  },
  afterDelRow: function () {
            	//updateAutocompleteSource.call(this, \"name\");
    recreateFilterToolbar.call(this);
  },
  caption:"+to_JSON_String(_T(to_upper(rows.table_name)))+",
  actionsNavOptions: {
    openicon: \"fa-folder-open-o\",
    opentitle: \"Open (Enter)\",
    isDisplayButtons: function (options, rowData) {
      if (options.rowData.closed) { // or rowData.closed
        return { post: { hidden: true }, del: { display: false } };
      }
    },
      custom: [
          { action: \"open\", position: \"first\",
              onClick: function (options) {"+
    jq_dialog_open(dialog_id(uid+"edit_table_dlg_ajax"), "'id='+options.rowid")+
"
              }
          }
      ]
  }
  "
//  ondblClickRow: function( rowid) {"+
//    jq_dialog_open(dialog_id(uid+"edit_table_dlg_ajax"), "'id='+rowid")+
.

public define HTML_Partial_Content
  jqGrid_table
  (
    SQLite3DataBase     db,  
    String              uid,
    VT_view             rows,
    String              filter_name,
    (String) -> String  _T,
    String              lang,
    String              clause,
    HK_Referer          table_referer
  )=
  with filter_clause = if clause = "" then "" else "&clause="+url_quote(clause),
  with referer_arg = "&"+to_Web_arg(table_referer, ""),
  with js = js_inline(jquery_ready(
"var lastSel;
  initAutocomplete = function (elem, cmName) {
    $(elem).autocomplete({
      source: $(this).jqGrid(\"getUniqueValueFromColumnIndex\", cmName),
      delay: 0,
      minLength: 0
    });
  }, 
  recreateFilterToolbar = function () {
    $(this)
      .jqGrid(\"destroyFilterToolbar\")
      .jqGrid(\"filterToolbar\");
  },
  updateAutocompleteSource = function (cmName) {
    var newUniqueValues = $(this).jqGrid(\"getUniqueValueFromColumnIndex\", cmName);
    $(\"#gs_\" + this.id + \"_\" + cmName)
      .autocomplete(\"option\", \"source\", newUniqueValues);
  };
$(\"#"+uid+"_grid\").jqGrid({
url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+"&filter_name="+filter_name+filter_clause+referer_arg+"',"+
  "datatype: \"json\",
  "+
   to_jqGrid_ColModel(db, table_referer, _T, rows.view_model.list)+","+
//   rows.json_data_string+
   jqGrid_options(uid, rows, _T)+
   ",loadComplete: function () {

   }
   }).jqGrid(\"gridResize\");
   function formatColor(cellValue, options, rowObject) {
            var color_container = \"<div class=\\\"hk_jscolor\\\" data-color=\\\"\"+ cellValue + \"\\\" style=\\\"background-color:#\"+ cellValue + \"\\\"></div>\";
            return color_container;
        }
   function unformatColor(cellValue, options, cellObject) {
            return $(cellObject).find('.hk_jscolor').data('color');
        }
   function formatPhone(cellValue, options, rowObject) {
            var phoneInput = '<span class=\"hk_phone_call\"><img data-phone-number=\"'+cellValue+'\" src=\\\"/icons/16x16/phone.png\\\" onclick=\"hk_phone_call(this);\">' + cellValue + '</span>';
            return phoneInput;
        }
   function unformatPhone(cellValue, options, cellObject) {
            var jqo = $(cellObject);
            var ret = jqo.text();
            return ret;
        }
   function formatEmail(cellValue, options, rowObject) {
            var phoneInput = '<span class=\"hk_send_email\"><img data-email=\"'+cellValue+'\" src=\\\"/icons/16x16/email_edit.png\\\" onclick=\"hk_send_email(this);\">' + cellValue + '</span>';
            return phoneInput;
        }
   function unformatEmail(cellValue, options, cellObject) {
            var jqo = $(cellObject);
            var ret = jqo.text();
            return ret;
        }")),
  
  partial_content(jqgrid_init(lang) + [js, css(css_file("hayamiki/hayamiki.css"))],
    div([],
      sequence([
        table([core_attrs([id(uid+"_grid")])],[]),
        //DR 20170528 div_empty([id(uid+"_pager")])
      ])
    )
  )
.

public define HTML_Partial_Content 
  view_table_page
  (
    SQLite3DataBase     db,
    (String) -> String  _T,
    String              lang,
    //String              web_site_directory,
    String              action_name,
    VTM_view            vtm_v,
    String              view_name,
    String              filter_name,
    String              f_clause,     //filter for current table
    HK_Referer          table_referer,
    String              fk_clause     //filter for foreign key of the table (one to many)
  ) =
  with current_view = vtm_v.get_view(view_name),  
  //with _filter = get_filter_from_name(vtm_v, view_name, filter_name),
  //with f_clause = if _filter.filter_string = "" then "" else if _f_clause = "" then _filter.filter_string else "("+_filter.filter_string+") AND "+_f_clause,
  with filter_clause  = if f_clause = "" then "" else "&clause="+url_quote(f_clause),
  //with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause),
  with referer_arg = "&"+to_Web_arg(table_referer, ""),
  

  with uid = "_"+generate_random_string(15)+"_",
  partial_content([ js(js_file("js/jscolor.min.js"))
    ]+jq_dialog_init + jq_datetimepicker_init(lang),
    [html_wave_box_wide(_T(to_upper(current_view.table_name)), 
      sequence([
        //create the dialog
        partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+action_name+"_dlg_ajax&table_name="+current_view.table_name+filter_clause+referer_arg)))),      
        div([class("inline")], sequence([
          // (+) icon for adding new entry
          partial(img_button(icn16_add, [class("icon_in_text"), event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
          // view selector if there is more than one view name
          table_view_filter_selector(_T, vtm_v, view_name, filter_name),
        ])),
        //grid with data
        partial(jqGrid_table(db, uid, current_view, filter_name, _T, lang, f_clause, table_referer))
        //partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(500), true, true, true, lang, no_extra, web_site_directory))
      ]))]).

public define HTML_Partial_Content 
  table_in_list_view
  (
    SQLite3DataBase       db,
    (String) -> String    _T,
    String                lang,
    //String                web_site_directory,
    String                action_name,
    VTM_view              vtm_v,
    String                view_name,    //requested view name
    String                filter_name,
    String                f_clause,     //filter for current table
    HK_Referer            table_referer,//refer to caller table, useful for foreign key
    String                fk_clause     //filter for foreign key of the table (one to many)
  ) =
  with filter_clause  = if f_clause = "" then "" else "&clause="+url_quote(f_clause),
  with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause),
  with referer_arg = "&"+to_Web_arg(table_referer, ""),
  with current_view = vtm_v.get_view(view_name),
  with uid = generate_random_string(20)+"_",
  partial_content([ js(js_file("js/jscolor.min.js"))
    ]+
      jq_dialog_init +
      jq_datetimepicker_init(lang),
    [
      partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+action_name+"_dlg_ajax&table_name="+current_view.table_name+filter_clause+referer_arg)))),
      partial(img_button(icn16_add, [class("icon_in_text"), event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
      //table_view_selector(_T, vtm_v, view_name),
      partial(jqGrid_table(db, uid, current_view, filter_name, _T, lang, /*fk_clause*/ f_clause, table_referer)),
      //partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(200), true, true, true, lang, no_extra, web_site_directory))
    ]).
    
public define Maybe(HTML_Partial_Content)
  view_table_content
  (
    SQLite3DataBase       db,  
    (String) -> String    _T,
    String                lang,
    //String                web_site_directory,
    String                table_name,
    String                view_name,
    String                action_name,
    String                filter_name,
    String                f_clause,
    HK_Referer            table_referer,    
    String                fk_clause,
    VTM                   vtm       
  ) =
  if vtm_get_view(table_name, vtm.view_list) is
  {
    failure        then failure,
    success(vtm_v) then 
      success(view_table_page(db, _T, lang, /*web_site_directory, */action_name, vtm_v, view_name, filter_name, f_clause, table_referer, fk_clause))
  }.

public define Maybe(HTML_Partial_Content)
  view_table_content
  (
    SQLite3DataBase       db,  
    (String) -> String    _T,
    String                lang,
    //String                web_site_directory,
    String                table_name,
    String                view_name,
    String                action_name,
    VTM                   vtm       
  ) =
  view_table_content(db, _T, lang, /*web_site_directory,*/ table_name, view_name, action_name, "", "", no_referer, "", vtm).
  
public define Maybe(HTML_Partial_Content)
  table_in_list_view_only
  (
    SQLite3DataBase       db,  
    (String) -> String    _T,
    String                lang,
    String                table,
    String                view_name,
    String                filter_name,
    String                action_name,
    String                f_clause,
    HK_Referer            table_referer,
    String                fk_filter,
    VTM                   vtm       
  ) =
  if vtm_get_view(table, vtm.view_list) is
  {
    failure        then failure,
    success(vtm_v) then 
      success(table_in_list_view(db, _T, lang, action_name, vtm_v, view_name, filter_name, f_clause, table_referer, fk_filter))
  }.
  
define CXM_Form_Field
  help_line
  (
    HK_Help_Text  help,
    (String) -> String    _T
  )=
  if help is
  {
    no_help_text        then  empty,
    help_text_TAG(tag)  then  explain(_T(tag)),
    help_text(str)      then  explain(str)
  }.
  
  
  //Edit table part
public define List(CXM_Form_Field)
  edit_form_lines
  (
    SQLite3DataBase       db,
    String                fk_clause,
    HK_Referer            table_referer,
    List(Web_arg)         lwa,            //web arguments of the request    
    (String) -> String    _T,
    List(HK_Form_Entry)   list,
    Bool                  new_entry,
    Bool                  no_add,
    List(CXM_Form_Field)  so_far
  )=
  if list is
  {
    []        then reverse(so_far),
    [ h . t]  then
      with line = 
        if h is
        {
          empty                     then [empty],
          hidden(name, value)       then
            //print("hidden "+name+" = "+value);
            [hidden(html_Id(""), wan(name), wav(value))],
          label(name)               then
            [div([],text(name))],
          primary_key(idx)          then 
            [hidden(html_Id(""), wan("id"), wav(idx))],
          information(s_name, c_name, value, width, help) then
            [input_readonly(label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), if width > 0 then custom(width) else narrow), help_line(help, _T)],
          text(s_name, c_name, value, help) then  
            [input(label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
          password(s_name, c_name, help) then
            with password_entries = 
              [ password_input(label(_T(s_name), no_help), wan(c_name+"_1"), init(""), narrow, non_mandatory),
                password_input(label(_T(s_name), no_help), wan(c_name+"_2"), init(""), narrow, non_mandatory),
                help_line(help, _T)
              ],
                
            if new_entry = false then
              [ checkbox_hide_show([], label(_T("CLICK_TO_CHANGE_PASSWORD")), wan(c_name+"_pwd_change"), false, //not checked at first
                password_entries),
                hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("true"))
              ]  
            else
              [ hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("false")) .
                password_entries
              ],

          foreign_text(s_name, c_name, _value, foreign_table_name, select, active_filters, help) then
            with dummy = if length(active_filters) > 0 then
              println("ACTIVE FILTER for "+c_name);
              println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
                since a_filter is active_filter(column, fk_column),
                "column '"+column+"' fk_column '"+fk_column+"\n" 
                ,
                active_filters
              )))
            else
              unique,
            with uid = "_"+generate_random_string(20)+"_",
            with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh",
                         //Get the priority of the web argument content for the value, this means the value already set by the user or called with programmaticaly with it
            with value = get_DB_id(lwa, c_name, _value),
            //create refresh function and call it first to construct the dropdown
            with load_script = script("text/javascript","function "+refresh_func+"() { CalexiumToolBox.ajax_load_content('"+uid+foreign_table_name+"_"+c_name+"_selector', '?aws_controller=hk_c&aws_action=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"&selected="+value+"&"+to_Web_arg(table_referer, "")+"');} "+refresh_func+"(); "),
            [
              partial(jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+foreign_table_name+"_dlg_ajax&sub_dialog=true&table_name="+foreign_table_name+"&after_close_cb="+refresh_func)))),
              one_line_fields([
                partial(partial_content([js_inline(load_script)],empty)),
                selector_c([],label(_T(s_name), no_help), html_Id(uid+foreign_table_name+"_"+c_name+"_selector"), wan(c_name), 1, [],/*select.get(db, table_referer, fk_clause), */ success(init("")), mandatory), help_line(help, _T),
                if no_add then
                  empty
                else
                  partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
              ])
            ],

             
          foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filters, help) then
            with dummy = if length(active_filters) > 0 then
              println("ACTIVE FILTER for "+c_name);
              println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
                since a_filter is active_filter(column, fk_column),
                "column '"+column+"' fk_column '"+fk_column+"\n" 
                ,
                active_filters
              )))
            else
              unique,
            with        uid = "_"+generate_random_string(20)+"_",
                         //Get the priority of the web argument content for the select, this means the value already set by the user or called with programmaticaly with it
            with select = get_DB_id(lwa, c_name, _select),            
            with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields, active_filters),            
            [

              partial(partial_content([ js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")),
                        css(css_file("ajax-combobox/css/jquery.ajax-combobox.css")),
                        js_inline(jquery_ready(combo_init))],
                      jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+foreign_table_name+"_dlg_ajax&sub_dialog=true&table_name="+foreign_table_name))))),
              one_line_fields([
                
                message(to_String(format_label(label(_T(s_name), no_help), html_Id("")))+
                "<input class=\"in\" id=\""+uid+"\" data-init_record=\""+select+"\" size=\"50\" type=\"text\">"),
                if no_add then
                  empty
                else
                  partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
              ]),
              help_line(help, _T)
            ]
             
          choices_text(s_name, c_name, value, select, help) then 
            [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
            
          text_area(s_name, c_name, value, txt_editor, help)  then
            with uid = "_"+generate_random_string(20),
            with id = if txt_editor is { none then "", rich_editor then uid+"_editor"},
            [
              if txt_editor is {
                none        then empty,
                rich_editor then partial(partial_content(
                  [ js(js_file("ckeditor/ckeditor.js")),
                    js_inline(jquery_ready(
                      " var cke_instance = CKEDITOR.replace( '"+id+"' );
                      cke_instance.on('blur', function() { cke_instance.updateElement(); });
                    "))],empty))
              },
              text_area([],label(_T(s_name), no_help), html_Id(id), wan(c_name), init(not_null_String(value)), narrow, (Int)5, mandatory), help_line(help, _T)
            ],
            
          boolean(s_name, c_name, value, help)  then
            [checkboxr([],label(_T(s_name), no_help), html_Id(""), wan(c_name), value, mandatory), help_line(help, _T)],
          integer(s_name, c_name, value, help) then  
            [input(label(_T(s_name), no_help), wan(c_name), init(abs_to_decimal(value)), small, mandatory), help_line(help, _T)],
          float(s_name, c_name, value, help) then
            [input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)],            
          choices_int(s_name, c_name, value, select, help) then 
            [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(to_String(value))), mandatory), help_line(help, _T)],
          date(s_name, c_name, value, help) then  
            [input([class("datepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), small, non_mandatory), help_line(help, _T)],
          time(s_name, c_name, value, help) then  
            [input([class("timepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), small, non_mandatory), help_line(help, _T)],
          datetime(s_name, c_name, value, help) then  
            [input([class("datetimepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), custom(18), mandatory), help_line(help, _T)],
          color( s_name, c_name, value, help) then
            [input([class("jscolor"), style("background-color: #"+value+";")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
          phone( s_name, c_name, value, phone_type, help) then
            with sms_options = (Maybe(List(CoreAttrs)))if phone_type = cellphone then success([event(onclick, "hk_send_sms(this)"), class("clickable")]) else failure,
            with event = (List(CoreAttrs))if phone_type = fax then [] else [event(onclick, "hk_phone_call(this)"), class("clickable")],
            //with class = (List(CoreAttrs))if phone_type = fax then [] else [class("clickable")],
            [phone_input(sms_options, event, [], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), convert(phone_type), narrow, mandatory), help_line(help, _T)],

          email( s_name, c_name, value, help) then
            [email_input([event(onclick, "hk_send_email(this)")], [class("clickable")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],

          url( s_name, c_name, value, help) then
            [url_input([event(onclick, "hk_go_url(this)")], [class("hk_input_url")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
        },
     edit_form_lines(db, fk_clause, table_referer, lwa, _T, t, new_entry, no_add, reverse(line)+so_far)
  }.



  
public define HTML_Partial_Content 
  renderer_edit_list_form
  (
    SQLite3DataBase       db,
    (String) -> String    _T,
    String                lang,
    //String                web_site_directory,
    String                table_name,
    //String                view_name,
    List(HK_Form_Entry)   list_entries,
    List(HK_Form_Tab)     list_tabs,
    List(Web_arg)         lwa,
    VTM                   vtm,
    //String                clause,
    String                fk_clause,
    HK_Referer            table_referer   //from which table and row id that editor is called
  ) =
  //with table_name  = vt_elist.table_name,
                     //true if need to create row or false for updating
  with create         = if get_String(lwa, "id","none") = "none" then true else false,
  with no_add         = get_Bool(lwa,   "no_add", false), 
  with id             = get_String(lwa, "id","none"),
  with sub_dialog     = get_String(lwa, "sub_dialog", "false"),
  with dialog_id      = get_String(lwa, "dialog_id", ""),
  with after_close_cb = get_String(lwa, "after_close_cb", ""),   //call back
  with button_label   = if create then _T("CREATE") else _T("UPDATE"),
  with button_name    = if create then "create" else "update",
  with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"),
  with form_id        = dialog_id+"_form",
  //println("renderer_edit_list_form dialog_id ["+dialog_id+"]");
  partial_content(
    [ js(js_file("js/jscolor.min.js")),
      js(js_file("js/dropzone.js")),
      js_inline(jquery_ready("Dropzone.options.myAwesomeDropzone = {
                      maxFiles: 100,
                      dictDefaultMessage : \""+_T("DROP_FILE_HERE")+"\",
                      dictFileTooBig : \""+_T("FILE_TOO_BIG")+"\",
                      };
                      $('#my-awesome-dropzone').dropzone();
                      jscolor.installByClassName('jscolor');
")),
    ]+
    jq_datetimepicker_init(lang),
    //get_editor_header(list_entries)+ //add editor header if need. Like init ck_editor
    //get_combo_header(table_name, list_entries),
    sequence([
      cxm_form( form_id, lwa,
        get_hidden(lwa)+                    //collect hidden value from lwa
        (if length(list_entries) > 5 then
          [
            one_line_fields([
              partial(jquery_button(jQuery_button(button, dialog_id+button_name, button_name, button_label, jQuery_actioner(same, jqscript(jq_form_submit_and_close(dialog_id, form_id, hkc_update_row, [("table_name", table_name), ("sub_dialog", sub_dialog)], after_close_cb)))))),
              partial(jquery_button(jQuery_button(button, dialog_id+"cancel", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))),
            ]),
            hr
          ]
        else
          []
      )
      +
      edit_form_lines(db, "", table_referer, lwa, _T, list_entries, create, no_add, [])
      +
     (if id = "none" then
      []
     else
      map( (HK_Form_Tab tab)
          |->
          since tab is hk_form_tab(fk_table_name, fk_col_name, list_view_name),
          with referer = hk_referer(table_name, id, fk_table_name, fk_col_name),
          if table_in_list_view_only(db, _T, lang, /* web_site_directory, */ fk_table_name, list_view_name, "", "edit", "", referer, fk_clause, vtm) is
          {
            failure             then empty,
            success(p_content)  then partial(p_content)
          }
          //text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]")
     ,list_tabs))+

     [  hr,
        one_line_fields([
          partial(jquery_button(jQuery_button(button, dialog_id+button_name+"_bt", button_name, button_label, jQuery_actioner(same, jqscript(jq_form_submit_and_close(dialog_id, form_id, hkc_update_row, [("table_name", table_name), ("sub_dialog", sub_dialog)], after_close_cb)))))),
          partial(jquery_button(jQuery_button(button, dialog_id+"cancel_bt", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))),
        ])
     ]
//          submit(if create then hkc_save_row else hkc_update_row,                 failure, button_name,         [("table_name", table_name), ("sub_dialog", sub_dialog)]),
//          submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name), ("sub_dialog", sub_dialog)]),
//          submit(hkc_cancel, failure, _T("CANCEL"), [("sub_dialog", sub_dialog)])


     ) //end of the form
     ])).

  //Edit table part
public define List(CXM_Form_Field)  
  edit_form_cell
  (
    SQLite3DataBase       db,
    //String                fk_clause,
    HK_Referer            table_referer,
    List(Web_arg)         lwa,            //web arguments of the request        
    (String) -> String    _T,
    HK_Form_Entry         cell,
    Bool                  new_entry,
    Bool                  no_add,
    List(CXM_Form_Field)  so_far
  )=
 
  if cell is
  {
    empty                     then [empty],
    hidden(name, value)       then
      //print("hidden "+name+" = "+value);
      [hidden(html_Id(name), wan(name), wav(value))],
    label(name)               then
      [div([],text(_T(name)))],
    primary_key(idx)          then 
      [hidden(html_Id("id"), wan("id"), wav(idx))],
    information(s_name, c_name, value, width, help) then
      [input_readonly(no_label, wan(c_name), init(not_null_String(value)), if width > 0 then custom(width) else narrow), help_line(help, _T)],
    text(s_name, c_name, value, help) then  
      [input(no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
    password(s_name, c_name, help) then
      with password_entries = 
        [ password_input(no_label, wan(c_name+"_1"), init(""), narrow, non_mandatory),
          password_input(no_label, wan(c_name+"_2"), init(""), narrow, non_mandatory),
          help_line(help, _T)
        ],
          
      if new_entry = false then
        [ checkbox_hide_show([], label(_T("CLICK_TO_CHANGE_PASSWORD")), wan(c_name+"_pwd_change"), false, //not checked at first
          password_entries),
          hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("true"))
        ]  
      else
        [ hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("false")) .
          password_entries
        ],

    foreign_text(s_name, c_name, _value, foreign_table_name, select, active_filters, help) then
      with dummy = if length(active_filters) > 0 then
        println("ACTIVE FILTER for "+c_name);
        println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
          since a_filter is active_filter(column, fk_column),
          "column '"+column+"' fk_column '"+fk_column+"\n" 
          ,
          active_filters
        )))
      else
        unique,
      //[selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, table_referer, fk_clause), success(init(to_String(value))), mandatory), help_line(help, _T)],
      with fk_clause = "",
      with uid = "_"+generate_random_string(20)+"_",
      with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh",
      with value = get_DB_id(lwa, c_name, _value),      
      //with load_script = "CalexiumToolBox.ajax_load_content('"+uid+foreign_table_name+"_"+c_name+"_selector', '?aws_controller=hk_c&aws_action=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"&selected="+value+"');",
      with load_script = script("text/javascript","function "+refresh_func+"() { CalexiumToolBox.ajax_load_content('"+uid+foreign_table_name+"_"+c_name+"_selector', '?aws_controller=hk_c&aws_action=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"&selected="+value+"');} "+refresh_func+"(); "),
      [
        partial(jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+foreign_table_name+"_dlg_ajax&sub_dialog=true&table_name="+foreign_table_name)))),
        one_line_fields([
          partial(partial_content([js_inline(load_script)],empty)),
          selector_c([],label(_T(s_name), no_help), html_Id(uid+foreign_table_name+"_"+c_name+"_selector"), wan(c_name), 1, /*select.get(db, table_referer, fk_clause)*/ [], success(init("")), mandatory), help_line(help, _T),
          if no_add then
            empty
          else
            partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
        ])
      ],

    foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filters, help) then
      with dummy = if length(active_filters) > 0then
        println("ACTIVE FILTER for "+c_name);
        println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
          since a_filter is active_filter(column, fk_column),
          "column '"+column+"' fk_column '"+fk_column+"\n" 
          ,
          active_filters
        )))
      else
        unique,
      //[raw_in_form(literal("<input class=\"in\" id=\"acb_"+c_name+"\" data-init_record=\""+select+"\" size=\"50\" type=\"text\">"))]
      with        uid = "_"+generate_random_string(20)+"_",
      //if column name came with argument, we supersede the given _select by it.
      with select = get_DB_id(lwa, c_name, _select),
      
      with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields, active_filters),
      [
        partial(partial_content([ 
          js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")),
          css(css_file("ajax-combobox/css/jquery.ajax-combobox.css")),
          js_inline(jquery_ready(combo_init))],
          jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&dialog_id="+uid+foreign_table_name+"_dlg_ajax&sub_dialog=true&table_name="+foreign_table_name))))),
        one_line_fields([
          message("<input class=\"in\" id=\""+uid+"\" data-init_record=\""+select+"\" size=\"50\" type=\"text\">"),
          if no_add then
            empty
          else
            partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
        ]),
        help_line(help, _T)
      ]

    choices_text(s_name, c_name, value, select, help) then 
      [selector_c([],no_label, html_Id(c_name), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
      
    text_area(s_name, c_name, value, txt_editor, help)  then
      //with uid = "_"+generate_random_string(20),
      //with id = if txt_editor is { none then "", rich_editor then uid+"_editor"},
      [
        if txt_editor is {
          none        then empty,
          rich_editor then partial(partial_content(
            [js(js_file("ckeditor/ckeditor.js")),
                js_inline(jquery_ready(
                " var cke_instance = CKEDITOR.replace( '"+c_name+"' );"+
                //" var cke_instance = CKEDITOR.replace( '"+id+"' );
                "  cke_instance.on('blur', function() { cke_instance.updateElement(); });
                  "))],empty))
        },
      text_area([],no_label, html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, (Int)5, mandatory), help_line(help, _T)],

    boolean(s_name, c_name, value, help)  then
      [checkboxr([],label(_T(s_name), no_help), html_Id(c_name), wan(c_name), value, mandatory), help_line(help, _T)],
    integer(s_name, c_name, value, help) then  
      [input(no_label, html_Id(c_name), wan(c_name), init(abs_to_decimal(value)), small, mandatory), help_line(help, _T)],
    float(s_name, c_name, value, help) then
      [input(no_label, html_Id(c_name), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)],            
    choices_int(s_name, c_name, value, select, help) then 
      [selector_c([],no_label, html_Id(c_name), wan(c_name), 1, select.get(db, no_referer, ""), success(init(to_String(value))), mandatory), help_line(help, _T)],
    date(s_name, c_name, value, help) then  
      [input([class("datepicker")], no_label, html_Id(c_name), wan(c_name), init(not_null_String(value)), small, non_mandatory), help_line(help, _T)],
    time(s_name, c_name, value, help) then  
      [input([class("timepicker")], no_label, html_Id(c_name), wan(c_name), init(not_null_String(value)), small, non_mandatory), help_line(help, _T)],
    datetime(s_name, c_name, value, help) then  
      [input([class("datetimepicker")], no_label, html_Id(c_name), wan(c_name), init(not_null_String(value)), custom(18), mandatory), help_line(help, _T)],
    color( s_name, c_name, value, help) then
      [input([class("jscolor"), style("background-color: #"+value+";")], no_label, html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
    phone( s_name, c_name, value, phone_type, help) then
      with  sms_options = (Maybe(List(CoreAttrs)))if phone_type = cellphone then success([event(onclick, "hk_send_sms(this)"), class("clickable")]) else failure,
      with        event = (List(CoreAttrs))if phone_type = fax then [] else [event(onclick, "hk_phone_call(this)"), class("clickable")],
      [phone_input(sms_options, event, [], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), convert(phone_type), narrow, mandatory), help_line(help, _T)],
    email( s_name, c_name, value, help) then
      [email_input([event(onclick, "hk_send_email(this)"), class("clickable")], [class("hk_input_email")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
    url( s_name, c_name, value, help) then
      [url_input([event(onclick, "hk_go_url(this)"), class("clickable")], [class("hk_input_url")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
  }.

define List(Cell_Option)
  make_cell_option
  (
    List(HK_Form_Table_Cell_Attribute)  attributes
  )=
  map((HK_Form_Table_Cell_Attribute attr) 
    |->
    if attr is
    {
      colspan(number)  then columns(number), 
      rowspan(number)  then rows(number)     
    },
    attributes
 )
.

define CXM_Form_Field
  construct_edit_form_table
  (
    SQLite3DataBase           db, 
    HK_Referer                table_referer,
    (String) -> String        _T,
    List(Web_arg)             lwa,    
    List(HK_Form_Table_Line)  form_lines, 
    Bool                      create,     //this is new entry, db_id = none
    Bool                      no_add      //not allow to add new entry in dropdown
  )=
  div([],
  table([class("striped")],
    map((HK_Form_Table_Line line) 
      |-> //construct line
      row(  
        map((HK_Form_Table_Cell cell_content)
          |->
          if cell_content is 
          {
            //construct one cell
            hk_form_table_cell(cell_attributes, entry)       then 
              cell(make_cell_option(cell_attributes), to_HTML_In_Form(edit_form_cell(db, table_referer, lwa, _T, entry, create, no_add, []), lwa, "form_field table", false)),
            //construct table in one cell
            hk_form_table_cell_table(cell_attributes, lines) then
              cell(make_cell_option(cell_attributes), to_HTML_In_Form([construct_edit_form_table(db, table_referer, _T, lwa, lines, create, no_add)], lwa, "form_field table", false))
          },
        line.form_table_cells
        )
      ),
    form_lines
    )
  )
 )
.
public define List(CXM_Form_Field)
  get_hidden
  (
    List(HK_Form_Table_Attribute)  table_attrs
  )=
  map((HK_Form_Table_Attribute attr) |-> since attr is hidden(n, v), hidden(html_Id(""), wan(n), wav(v)), table_attrs)
.



public define HTML_Partial_Content
  renderer_edit_table_form
  (
    SQLite3DataBase       db,
    (String) -> String    _T,
    String                lang,
    //String                web_site_directory,
    String                table_name,
    //String                view_name,
    HK_Form_Table         table_form,
    List(Web_arg)         lwa,
    //VTM                   vtm,
    //String                clause,
    String                fk_clause,
    HK_Referer            table_referer   //from which table and row id that editor is called
  ) =
  //with table_name  = vt_elist.table_name,
                     //true if need to create row or false for updating
  with create         = if get_String(lwa, "id","none") = "none" then true else false,
  with no_add         = get_Bool(lwa,   "no_add", false), 
  with id             = get_String(lwa, "id","none"),
  with sub_dialog     = get_String(lwa, "sub_dialog", "false"),
  with dialog_id      = get_String(lwa, "dialog_id", ""),
  with after_close_cb = get_String(lwa, "after_close_cb", ""),   //call back  
  with button_label   = if create then _T("CREATE") else _T("UPDATE"),
  with button_name    = if create then "create" else "update",
  with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"),
  with form_id        = dialog_id+"_form",
  partial_content(
    [ js(js_file("js/jscolor.min.js")),
      js_script("jscolor.installByClassName('jscolor');")
      //js_script("jscolor.init;")
      
    ]+
    jq_datetimepicker_init(lang),
    //get_editor_header(table_form.form_lines)+ //add editor header if need. Like init ck_editor
    //get_combo_header(table_name, table_form.form_lines), //add editor header if need. Like init ck_editor    
    sequence([
      cxm_form( form_id, [], lwa,
        get_hidden(table_form.table_attr)+  //collect hidden value from table form
        get_hidden(lwa)+                    //collect hidden value from lwa
        [construct_edit_form_table(db, table_referer, _T, lwa, table_form.form_lines, create, no_add)]+
        [ one_line_fields([
//          submit(if create then hkc_save_row else hkc_update_row,                 failure, button_name,         [("table_name", table_name)]),
//          submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
//          submit(hkc_cancel, failure, _T("CANCEL"))
          partial(jquery_button(jQuery_button(button, dialog_id+button_name, button_name, button_label, jQuery_actioner(same, jqscript(jq_form_submit_and_close(dialog_id, form_id, hkc_update_row, [("table_name", table_name), ("sub_dialog", sub_dialog)], after_close_cb)))))),
          partial(jquery_button(jQuery_button(button, dialog_id+"cancel", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))),
          
          ])
        ],
        "form_field table",
        false
      )]
//     if id = "none" then
//      []
//     else
//      map( (HK_Form_Tab tab)
//          |-> 
//          since tab is hk_form_tab(fk_table_name, fk_col_name, list_view_name),
//          with referer = hk_referer(table_name, id, fk_table_name, fk_col_name),
//          if table_in_list_view_only(db, _T, lang,  web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is
//          {
//            failure             then empty,
//            success(p_content)  then partial(p_content)
//          }
//          //text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]")
//     ,list_tabs)
     ))
.
     
public define Maybe(HTML_Partial_Content) 
  edit_table_content 
  (
    SQLite3DataBase       db,
    (String) -> String    _T,
    String                lang, 
    List(Web_arg)         lwa,
    String                table_name, //table name
    String                view_name,  //view name to use
    HK_Form_action        action,     //new_entry or edit an existing record
    VTM                   vtm,
    String                fk_clause,
    HK_Referer            referer
  ) =
  if vtm_get_edit(table_name, vtm.edit_list) is
  {
    failure        then failure,
    success(vtm_e) then 
      since vtm_e is vtm_edit(_, get_edit),
        //get editor by his view name
        if get_edit(db, action, view_name) is
        {
            hk_form_in_list(_,  v_name, list_form_entries, list_tabs) then  
              success(renderer_edit_list_form(db, _T, lang, table_name, /*v_name,*/ list_form_entries, list_tabs, lwa, vtm, /*clause,*/ fk_clause, referer)),
            hk_form_in_table(_, v_name, form_in_table)          then
              success(renderer_edit_table_form(db, _T, lang, table_name, /*v_name,*/ form_in_table, lwa, /*vtm,*/ /*clause,*/ fk_clause, referer))
        }
  }.

public define Maybe(HTML_Partial_Content) 
  edit_table_content 
  (
    SQLite3DataBase       db,
    (String) -> String    _T,
    String                lang, 
    List(Web_arg)         lwa,
    String                table,      //table name
    String                view_name,  //view name to use
    HK_Form_action        action,     //new_entry or edit an existing record
    VTM                   vtm
  ) =
  edit_table_content(db, _T, lang, lwa, table, view_name, action, vtm, "", no_referer)
.