From c6fff2c0fe605fb6e10c2ba38844a19af49c0b83 Mon Sep 17 00:00:00 2001 From: totoro Date: Sat, 18 Mar 2017 03:29:31 +0100 Subject: [PATCH] the tm_writer has now 2 functions for writing row. One with complete Type given from web args and one with list of available fields of that type. This make update or insert with only available columns from web args. Manage that previous behavior by adding new controller action "update_row" and "update_row_and_new" but the last one is not already managed --- view/view_table_manager.anubis | 2 +- view/view_table_manager_types.anubis | 7 ++++++- view/view_table_renderer.anubis | 13 +++++++------ view/web_action.anubis | 18 ++++++++++-------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/view/view_table_manager.anubis b/view/view_table_manager.anubis index c14cb6f..506263b 100644 --- a/view/view_table_manager.anubis +++ b/view/view_table_manager.anubis @@ -70,7 +70,7 @@ public define Maybe(TM_writer) { [] then failure, [ h . t ] then - if h is tm_writer(tb_name, get_writer) then + if h is tm_writer(tb_name, get_writer_from_type, get_writer_from_fields) then if tb_name = table_name then success(h) else diff --git a/view/view_table_manager_types.anubis b/view/view_table_manager_types.anubis index fffbbb9..4813b29 100644 --- a/view/view_table_manager_types.anubis +++ b/view/view_table_manager_types.anubis @@ -16,7 +16,12 @@ public type VTM_edit_list: vtm_edit_list(List(VTM_edit) list). public type TM_writer: - tm_writer(String table_name, (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write). + tm_writer( + String table_name, + (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write_from_type, + (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write_from_fields + ) +. public type TM_writer_list: tm_writer_list(List(TM_writer) list). diff --git a/view/view_table_renderer.anubis b/view/view_table_renderer.anubis index 2632b50..1588273 100644 --- a/view/view_table_renderer.anubis +++ b/view/view_table_renderer.anubis @@ -154,18 +154,19 @@ public define HTML_Partial_Content VT_edit vt_elist ) = with table_name = vt_elist.table_name, - with button_name = if get_String(lwa, "id","none") = "none" then _T("CREATE") else _T("UPDATE"), - with button_name_and_new = if get_String(lwa, "id","none") = "none" then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"), - with new_entry = if get_String(lwa, "id", "none") = "none" then true else false, + //true if need to create row or false for updating + with create = if get_String(lwa, "id","none") = "none" then true else false, + 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( jq_datetimepicker_init(lang) + get_editor_header(vt_elist.list), //add editor header if need. Like init ck_editor cxm_form( table_name, lwa, - edit_form_lines(db, _T, vt_elist.list, new_entry, [])+ + edit_form_lines(db, _T, vt_elist.list, create, [])+ [ one_line_fields([ - submit(save_row, failure, button_name, [("table_name", table_name)]), - submit(save_row_and_new, failure, button_name_and_new, [("table_name", table_name)]), + submit(if create then save_row else update_row, failure, button_name, [("table_name", table_name)]), + submit(if create then save_row_and_new else update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]), submit(hk_cancel, failure, _T("CANCEL")) ]) ] diff --git a/view/web_action.anubis b/view/web_action.anubis index 165fd9c..7fba68d 100644 --- a/view/web_action.anubis +++ b/view/web_action.anubis @@ -8,11 +8,13 @@ read calexium_lib/web/CXM_making_a_web_site.anubis -public define WEB_Action_Name edit_table = controller_action("hk_c", "edit_table"). -public define WEB_Action_Name view_table = controller_action("hk_c", "view_table"). -public define WEB_Action_Name save_row = controller_action("hk_c", "save_row"). -public define WEB_Action_Name save_row_and_new = controller_action("hk_c", "save_row_and_new"). -public define WEB_Action_Name delete_row = controller_action("hk_c", "delete_row"). -public define WEB_Action_Name hk_cancel = controller_action("hk_c", "cancel"). -public define WEB_Action_Name ajax_edit_table = controller_action("hk_c", "ajax_edit_table"). -public define WEB_Action_Name show_apps = controller_action("hk_c", "show_apps"). +public define WEB_Action_Name edit_table = controller_action("hk_c", "edit_table"). +public define WEB_Action_Name view_table = controller_action("hk_c", "view_table"). +public define WEB_Action_Name save_row = controller_action("hk_c", "save_row"). +public define WEB_Action_Name save_row_and_new = controller_action("hk_c", "save_row_and_new"). +public define WEB_Action_Name update_row = controller_action("hk_c", "update_row"). +public define WEB_Action_Name update_row_and_new = controller_action("hk_c", "update_row_and_new"). +public define WEB_Action_Name delete_row = controller_action("hk_c", "delete_row"). +public define WEB_Action_Name hk_cancel = controller_action("hk_c", "cancel"). +public define WEB_Action_Name ajax_edit_table = controller_action("hk_c", "ajax_edit_table"). +public define WEB_Action_Name show_apps = controller_action("hk_c", "show_apps"). -- libgit2 0.21.4