Commit 5a230ad07724dcd509fb2e128434ff670f88cb36

Authored by totoro
1 parent b0635c56

render form in table

view/types/hk_form_entry.anubis
... ... @@ -17,6 +17,7 @@ public type HK_Form_Selector:
17 17  
18 18  
19 19 public type HK_Form_Entry: //legacy VT_Edit
  20 + empty,
20 21 hidden (String name, String value),
21 22 label (String s_name),
22 23 primary_key (String idx),
... ...
view/view_table_renderer.anubis
... ... @@ -390,7 +390,8 @@ public define List(CXM_Form_Field)
390 390 with line =
391 391 if h is
392 392 {
393   - hidden(name, value) then
  393 + empty then [empty],
  394 + hidden(name, value) then
394 395 //print("hidden "+name+" = "+value);
395 396 [hidden(html_Id(""), wan(name), wav(value))],
396 397 label(name) then
... ... @@ -472,7 +473,7 @@ define List(HTML_Head_Tag)
472 473 .
473 474  
474 475 public define HTML_Partial_Content
475   - renderer_edit_form
  476 + renderer_edit_list_form
476 477 (
477 478 SQLite3DataBase db,
478 479 (String) -> String _T,
... ... @@ -526,7 +527,168 @@ public define HTML_Partial_Content
526 527 //text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]")
527 528 ,list_tabs)
528 529 )).
  530 +
  531 + //Edit table part
  532 +public define List(CXM_Form_Field)
  533 + edit_form_cell
  534 + (
  535 + SQLite3DataBase db,
  536 + String fk_clause,
  537 + HK_Referer table_referer,
  538 + (String) -> String _T,
  539 + HK_Form_Entry cell,
  540 + Bool new_entry,
  541 + List(CXM_Form_Field) so_far
  542 + )=
  543 +
  544 + if cell is
  545 + {
  546 + empty then [empty],
  547 + hidden(name, value) then
  548 + //print("hidden "+name+" = "+value);
  549 + [hidden(html_Id(""), wan(name), wav(value))],
  550 + label(name) then
  551 + [div([],text(_T(name)))],
  552 + primary_key(idx) then
  553 + [hidden(html_Id(""), wan("id"), wav(idx))],
  554 + information(s_name, c_name, value, width, help) then
  555 + [input_readonly(no_label, wan(c_name), init(not_null_String(value)), if width > 0 then custom(width) else narrow), help_line(help, _T)],
  556 + text(s_name, c_name, value, help) then
  557 + [input(no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
  558 + password(s_name, c_name, help) then
  559 + with password_entries =
  560 + [ password_input(no_label, wan(c_name+"_1"), init(""), narrow, non_mandatory),
  561 + password_input(no_label, wan(c_name+"_2"), init(""), narrow, non_mandatory),
  562 + help_line(help, _T)
  563 + ],
  564 +
  565 + if new_entry = false then
  566 + [ checkbox_hide_show([], label(_T("CLICK_TO_CHANGE_PASSWORD")), wan(c_name+"_pwd_change"), wav("on"), false, //not checked at first
  567 + password_entries),
  568 + hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("true"))
  569 + ]
  570 + else
  571 + [ hidden(html_Id(""), wan(c_name+"_pwd_change_option"), wav("false")) .
  572 + password_entries
  573 + ],
  574 +
  575 + foreign_text(s_name, c_name, value, select, help) then
  576 + [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)],
  577 + choices_text(s_name, c_name, value, select, help) then
  578 + [selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
  579 + text_area(s_name, c_name, value, txt_editor, help) then
  580 + with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"},
  581 + [text_area([],no_label, html_Id(id), wan(c_name), init(not_null_String(value)), narrow, (Int)5, mandatory), help_line(help, _T)],
  582 + boolean(s_name, c_name, value, help) then
  583 + [checkboxr([],no_label, html_Id(""), wan(c_name), wav(c_name),value, mandatory), help_line(help, _T)],
  584 + integer(s_name, c_name, value, help) then
  585 + [input(no_label, wan(c_name), init(abs_to_decimal(value)), small, mandatory), help_line(help, _T)],
  586 + float(s_name, c_name, value, help) then
  587 + [input(no_label, wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)],
  588 + choices_int(s_name, c_name, value, select, help) then
  589 + [selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(to_String(value))), mandatory), help_line(help, _T)],
  590 + date(s_name, c_name, value, help) then
  591 + [input([class("datepicker")], no_label, html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)],
  592 + time(s_name, c_name, value, help) then
  593 + [input([class("timepicker")], no_label, html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)],
  594 + datetime(s_name, c_name, value, help) then
  595 + [input([class("datetimepicker")], no_label, html_Id(c_name), wan(c_name), init(value), custom(18), mandatory), help_line(help, _T)],
  596 + color( s_name, c_name, value, help) then
  597 + [input([class("jscolor")], no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
  598 + }.
529 599  
  600 +define CXM_Form_Field
  601 + construct_edit_form_table
  602 + (
  603 + SQLite3DataBase db,
  604 + HK_Referer table_referer,
  605 + (String) -> String _T,
  606 + List(Web_arg) lwa,
  607 + List(HK_Form_Table_Line) form_lines,
  608 + Bool create
  609 + )=
  610 + div([],
  611 + table([],
  612 + map((HK_Form_Table_Line line)
  613 + |-> //construct line
  614 + row(
  615 + map((HK_Form_Table_Cell cell_content)
  616 + |->
  617 +
  618 +
  619 + if cell_content is
  620 + {
  621 + //construct one cell
  622 + hk_form_table_cell(entry) then
  623 + cell(fieldset(lwa, edit_form_cell(db, "", table_referer, _T, entry, create, []))),
  624 + //construct table in one cell
  625 + hk_form_table_cell_table(lines) then
  626 + cell(fieldset(lwa, [construct_edit_form_table(db, table_referer, _T, lwa, lines, create)]))
  627 + },
  628 + line.form_table_cells
  629 + )
  630 + ),
  631 + form_lines
  632 + )
  633 + )
  634 + )
  635 +.
  636 +
  637 +public define HTML_Partial_Content
  638 + renderer_edit_table_form
  639 + (
  640 + SQLite3DataBase db,
  641 + (String) -> String _T,
  642 + String lang,
  643 + String web_site_directory,
  644 + String table_name,
  645 + String view_name,
  646 + HK_Form_Table table_form,
  647 + List(Web_arg) lwa,
  648 + VTM vtm,
  649 + String clause,
  650 + String fk_clause,
  651 + HK_Referer table_referer //from which table and row id that editor is called
  652 + ) =
  653 + //with table_name = vt_elist.table_name,
  654 + //true if need to create row or false for updating
  655 + with create = if get_String(lwa, "id","none") = "none" then true else false,
  656 + with id = get_String(lwa, "id","none"),
  657 + with button_name = if create then _T("CREATE") else _T("UPDATE"),
  658 + with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"),
  659 +
  660 + partial_content(
  661 + [ js(js_file("js/jscolor.min.js"))
  662 + ]+
  663 + jq_datetimepicker_init(lang),
  664 + //get_editor_header(list_entries), //add editor header if need. Like init ck_editor
  665 + sequence([
  666 + cxm_form( table_name, lwa,
  667 + [construct_edit_form_table(db, table_referer, _T, lwa, table_form.form_lines, create)]+
  668 + [ one_line_fields([
  669 + submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]),
  670 + submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
  671 + submit(hkc_cancel, failure, _T("CANCEL"))
  672 + ])
  673 + ]
  674 + )]
  675 +// if id = "none" then
  676 +// []
  677 +// else
  678 +// map( (HK_Form_Tab tab)
  679 +// |->
  680 +// since tab is hk_form_tab(fk_table_name, fk_col_name, list_view_name),
  681 +// with referer = hk_referer(table_name, id, fk_table_name, fk_col_name),
  682 +// if table_in_list_view_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is
  683 +// {
  684 +// failure then empty,
  685 +// success(p_content) then partial(p_content)
  686 +// }
  687 +// //text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]")
  688 +// ,list_tabs)
  689 + ))
  690 +.
  691 +
530 692 public define Maybe(HTML_Partial_Content)
531 693 edit_table_content
532 694 (
... ... @@ -550,10 +712,10 @@ public define Maybe(HTML_Partial_Content)
550 712 since vtm_e is vtm_edit(_, get_edit),
551 713 if get_edit(db, action, view_name) is
552 714 {
553   - hk_form_in_list(tb_name, view_name, list_form_entres, list_tabs) then
554   - success(render_edit_form(db, _T, lang, web_site_directory, lwa, vtm, tb_name, view_name, list_form_entries, list_tabs, clause, fk_clause, referer)),
555   - hk_form_in_table(tb_name, view_name, form_in_table then ,
556   -
  715 + hk_form_in_list(tb_name, v_name, list_form_entries, list_tabs) then
  716 + success(renderer_edit_list_form(db, _T, lang, web_site_directory, tb_name, v_name, list_form_entries, list_tabs, lwa, vtm, clause, fk_clause, referer)),
  717 + hk_form_in_table(tb_name, v_name, form_in_table) then
  718 + success(renderer_edit_table_form(db, _T, lang, web_site_directory, tb_name, v_name, form_in_table, lwa, vtm, clause, fk_clause, referer))
557 719 }
558 720 }.
559 721  
... ...