From 5a230ad07724dcd509fb2e128434ff670f88cb36 Mon Sep 17 00:00:00 2001 From: totoro Date: Thu, 13 Apr 2017 01:13:55 +0200 Subject: [PATCH] render form in table --- view/types/hk_form_entry.anubis | 1 + view/view_table_renderer.anubis | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 169 insertions(+), 6 deletions(-) diff --git a/view/types/hk_form_entry.anubis b/view/types/hk_form_entry.anubis index 5eb78c3..b76cef0 100644 --- a/view/types/hk_form_entry.anubis +++ b/view/types/hk_form_entry.anubis @@ -17,6 +17,7 @@ public type HK_Form_Selector: public type HK_Form_Entry: //legacy VT_Edit + empty, hidden (String name, String value), label (String s_name), primary_key (String idx), diff --git a/view/view_table_renderer.anubis b/view/view_table_renderer.anubis index 1146db7..554474f 100644 --- a/view/view_table_renderer.anubis +++ b/view/view_table_renderer.anubis @@ -390,7 +390,8 @@ public define List(CXM_Form_Field) with line = if h is { - hidden(name, value) then + empty then [empty], + hidden(name, value) then //print("hidden "+name+" = "+value); [hidden(html_Id(""), wan(name), wav(value))], label(name) then @@ -472,7 +473,7 @@ define List(HTML_Head_Tag) . public define HTML_Partial_Content - renderer_edit_form + renderer_edit_list_form ( SQLite3DataBase db, (String) -> String _T, @@ -526,7 +527,168 @@ public define HTML_Partial_Content //text("Foreign Key from table ["+fk_table_name+"] columns ["+fk_col_name+"] view to use ["+list_view_name+"]") ,list_tabs) )). + + //Edit table part +public define List(CXM_Form_Field) + edit_form_cell + ( + SQLite3DataBase db, + String fk_clause, + HK_Referer table_referer, + (String) -> String _T, + HK_Form_Entry cell, + Bool new_entry, + List(CXM_Form_Field) so_far + )= + + if cell is + { + empty then [empty], + hidden(name, value) then + //print("hidden "+name+" = "+value); + [hidden(html_Id(""), wan(name), wav(value))], + label(name) then + [div([],text(_T(name)))], + primary_key(idx) then + [hidden(html_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"), wav("on"), 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, select, help) then + [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)], + choices_text(s_name, c_name, value, select, help) then + [selector_c([],no_label, 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 id = if txt_editor is { none then "", rich_editor then c_name+"_editor"}, + [text_area([],no_label, 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([],no_label, html_Id(""), wan(c_name), wav(c_name),value, mandatory), help_line(help, _T)], + integer(s_name, c_name, value, help) then + [input(no_label, 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, 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(""), 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(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(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(value), custom(18), mandatory), help_line(help, _T)], + color( s_name, c_name, value, help) then + [input([class("jscolor")], no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)], + }. +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 + )= + div([], + table([], + 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(entry) then + cell(fieldset(lwa, edit_form_cell(db, "", table_referer, _T, entry, create, []))), + //construct table in one cell + hk_form_table_cell_table(lines) then + cell(fieldset(lwa, [construct_edit_form_table(db, table_referer, _T, lwa, lines, create)])) + }, + line.form_table_cells + ) + ), + form_lines + ) + ) + ) +. + +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 id = get_String(lwa, "id","none"), + with button_name = if create then _T("CREATE") else _T("UPDATE"), + with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"), + + partial_content( + [ js(js_file("js/jscolor.min.js")) + ]+ + jq_datetimepicker_init(lang), + //get_editor_header(list_entries), //add editor header if need. Like init ck_editor + sequence([ + cxm_form( table_name, lwa, + [construct_edit_form_table(db, table_referer, _T, lwa, table_form.form_lines, create)]+ + [ 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")) + ]) + ] + )] +// 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 ( @@ -550,10 +712,10 @@ public define Maybe(HTML_Partial_Content) since vtm_e is vtm_edit(_, get_edit), if get_edit(db, action, view_name) is { - hk_form_in_list(tb_name, view_name, list_form_entres, list_tabs) then - 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)), - hk_form_in_table(tb_name, view_name, form_in_table then , - + hk_form_in_list(tb_name, v_name, list_form_entries, list_tabs) then + 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)), + hk_form_in_table(tb_name, v_name, form_in_table) then + success(renderer_edit_table_form(db, _T, lang, web_site_directory, tb_name, v_name, form_in_table, lwa, vtm, clause, fk_clause, referer)) } }. -- libgit2 0.21.4