From b1ffa9d461748cdf8109b293942e0d59ded2180a Mon Sep 17 00:00:00 2001 From: totoro Date: Wed, 21 Jun 2017 23:19:15 +0200 Subject: [PATCH] write from type now return maybe int which is the row_id of the updated or inserted row some cleanup in view_table_renderer. replace form_id name from table_name to dialog_id + suffix "_form". This allow to have multiple form with the same table. --- controller/hk_controller.anubis | 6 +++--- view/view_table_renderer.anubis | 168 ++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 files changed, 11 insertions(+), 163 deletions(-) diff --git a/controller/hk_controller.anubis b/controller/hk_controller.anubis index 55792ef..c871971 100644 --- a/controller/hk_controller.anubis +++ b/controller/hk_controller.anubis @@ -27,7 +27,7 @@ public type HK_Table_controller: hk_table_controller( String table_name, //Create - (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write_from_type, + (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(Int) write_from_type, (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(Int) write_from_fields, //Read (SQLite3DataBase db, String clause) -> Int get_count, @@ -78,8 +78,8 @@ public define One since trigger_to_add is hk_trigger(name, t_type, call_back), if t_type is { - before_update then add_trigger(ctrl.triggers.before_update, trigger_to_add), - after_update then add_trigger(ctrl.triggers.after_update, trigger_to_add) + before_update then println(">>> ADD TRIGGER 'before_update' to table "+_table_name);add_trigger(ctrl.triggers.before_update, trigger_to_add), + after_update then println(">>> ADD TRIGGER 'after_update' to table "+_table_name);add_trigger(ctrl.triggers.after_update, trigger_to_add) } } . diff --git a/view/view_table_renderer.anubis b/view/view_table_renderer.anubis index facc5cd..6bfa90f 100644 --- a/view/view_table_renderer.anubis +++ b/view/view_table_renderer.anubis @@ -656,7 +656,6 @@ public define List(CXM_Form_Field) with uid = "_"+generate_random_string(20)+"_", with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh", 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+"(); "), - //with load_script_b64 = base64_encode(load_script, false), [ 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([ @@ -666,16 +665,6 @@ public define List(CXM_Form_Field) ]) ], -// with uid = generate_random_string(20)+"_", -// with load_script = "CalexiumToolBox.ajax_load_content('"+uid+foreign_table_name+c_name+"_selector', '?aws_controller=hkc&aws_action=selector&table_name="+foreign_table_name+"&fk_filter="+fk_clause+"');", -// [ -// 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(jquery_ready(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(to_String(value))), mandatory), help_line(help, _T), -// 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, help) then with uid = "_"+generate_random_string(20)+"_", @@ -708,7 +697,6 @@ public define List(CXM_Form_Field) [ js(js_file("ckeditor/ckeditor.js")), js_inline(jquery_ready( " var cke_instance = CKEDITOR.replace( '"+id+"' ); - //cxm_cke('"+id+"'); cke_instance.on('blur', function() { cke_instance.updateElement(); }); "))],empty)) }, @@ -739,147 +727,8 @@ public define List(CXM_Form_Field) edit_form_lines(db, fk_clause, table_referer, _T, t, new_entry, reverse(line)+so_far) }. -//define List(String) -// get_rich_editor_inline -// ( -// List(HK_Form_Entry) list -// )= -// map_select((HK_Form_Entry entry) |-> -// if entry is text_area(s_name, c_name, value, txt_editor, help) then -// if txt_editor is { none then failure, -// rich_editor then success(" CKEDITOR.replace( '"+c_name+"_editor' );") -// } -// else -// failure, list) -//. - -// define List(HTML_Head_Tag) -// get_editor_header -// ( -// List(HK_Form_Entry) _list -// )= -// with result = get_rich_editor_inline(_list), -// if length(result) > 0 then -// [ -// js_inline(jquery_ready(join("",result))) -// ] -// else -// [] -// . - -//define List(String) -// _get_editor_header -// ( -// List(HK_Form_Table_Line) _lines -// )= -// map_append((HK_Form_Table_Line line) -// |-> -// map_append((HK_Form_Table_Cell cell) -// |-> -// if cell is -// { -// hk_form_table_cell(_, form_entry) then -// if form_entry is text_area(s_name, c_name, value, txt_editor, help) then -// if txt_editor is { -// none then [], -// rich_editor then [" CKEDITOR.replace( '"+c_name+"_editor' );"] -// } -// else -// [], -// hk_form_table_cell_table(_, t_lines) then -// _get_editor_header(t_lines) -// }, -// line.form_table_cells), -// _lines) -//. - -//define List(String) -// _get_combo_header -// ( -// String table_name, -// List(HK_Form_Table_Line) _lines -// )= -// map_append((HK_Form_Table_Line line) -// |-> -// map_append((HK_Form_Table_Cell cell) -// |-> -// if cell is -// { -// hk_form_table_cell(_, form_entry) then -// if form_entry is foreign_text_search(s_name, c_name, select, f_table, s_fields, help) then -// [ajax_combo_init_parameter(f_table, c_name, s_fields)] -// else -// [], -// hk_form_table_cell_table(_, t_lines) then -// _get_combo_header(table_name, t_lines) -// }, -// line.form_table_cells), -// _lines) -//. - -//define List(HTML_Head_Tag) -// get_editor_header -// ( -// List(HK_Form_Table_Line) _lines -// )= -// with result = _get_editor_header(_lines), -// if length(result) > 0 then -// [js(js_file("ckeditor/ckeditor.js")), -// js_inline(jquery_ready(join("",result))) -// ] -// else -// [] -// . - -//define List(HTML_Head_Tag) -// get_combo_header -// ( -// String table_name, -// List(HK_Form_Table_Line) _lines -// )= -// with result = _get_combo_header(table_name, _lines), -// if length(result) > 0 then -// [js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")), -// css(css_file("ajax-combobox/css/jquery.ajax-combobox.css")), -// js_inline(jquery_ready(join("",result))) -// ] -// else -// [] -// . - -//define List(String) -// _get_combo_header -// ( -// String table_name, -// List(HK_Form_Entry) _entries -// )= -// map_append((HK_Form_Entry entry) -// |-> -// if entry is foreign_text_search(s_name, c_name, select, f_table, s_fields, help) then -// [] -// else -// [] -// , -// _entries) -//. - -//define List(HTML_Head_Tag) -// get_combo_header -// ( -// String table_name, -// List(HK_Form_Entry) _lines -// )= -// with result = _get_combo_header(table_name, _lines), -// if length(result) > 0 then -// [js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")), -// css(css_file("ajax-combobox/css/jquery.ajax-combobox.css")), -// js_inline(jquery_ready(join("",result))) -// ] -// else -// [] -// . public define HTML_Partial_Content renderer_edit_list_form @@ -910,7 +759,7 @@ public define HTML_Partial_Content 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")), @@ -926,11 +775,11 @@ public define HTML_Partial_Content //get_editor_header(list_entries)+ //add editor header if need. Like init ck_editor //get_combo_header(table_name, list_entries), sequence([ - cxm_form( table_name, lwa, + cxm_form( form_id, lwa, (if length(list_entries) > 19 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, table_name, hkc_update_row, [("table_name", table_name), ("sub_dialog", sub_dialog)], after_close_cb)))))), + 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 @@ -958,8 +807,8 @@ public define HTML_Partial_Content [ hr, 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, table_name, 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')"))))), + 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)]), @@ -1059,7 +908,6 @@ public define List(CXM_Form_Field) [js(js_file("ckeditor/ckeditor.js")), js_inline(jquery_ready( " var cke_instance = CKEDITOR.replace( '"+id+"' ); - //cxm_cke('"+id+"'); cke_instance.on('blur', function() { cke_instance.updateElement(); }); "))],empty)) }, @@ -1172,7 +1020,7 @@ public define HTML_Partial_Content 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")) ]+ @@ -1180,14 +1028,14 @@ public define HTML_Partial_Content //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( table_name, [], lwa, + cxm_form( form_id, [], lwa, get_hidden(table_form.table_attr)+ [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")) - 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, table_name, hkc_update_row, [("table_name", table_name), ("sub_dialog", sub_dialog)], after_close_cb)))))), + 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')"))))), ]) -- libgit2 0.21.4