Commit b1ffa9d461748cdf8109b293942e0d59ded2180a
1 parent
2e229c53
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.
Showing
2 changed files
with
11 additions
and
163 deletions
Show diff stats
controller/hk_controller.anubis
| @@ -27,7 +27,7 @@ public type HK_Table_controller: | @@ -27,7 +27,7 @@ public type HK_Table_controller: | ||
| 27 | hk_table_controller( | 27 | hk_table_controller( |
| 28 | String table_name, | 28 | String table_name, |
| 29 | //Create | 29 | //Create |
| 30 | - (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write_from_type, | 30 | + (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(Int) write_from_type, |
| 31 | (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(Int) write_from_fields, | 31 | (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(Int) write_from_fields, |
| 32 | //Read | 32 | //Read |
| 33 | (SQLite3DataBase db, String clause) -> Int get_count, | 33 | (SQLite3DataBase db, String clause) -> Int get_count, |
| @@ -78,8 +78,8 @@ public define One | @@ -78,8 +78,8 @@ public define One | ||
| 78 | since trigger_to_add is hk_trigger(name, t_type, call_back), | 78 | since trigger_to_add is hk_trigger(name, t_type, call_back), |
| 79 | if t_type is | 79 | if t_type is |
| 80 | { | 80 | { |
| 81 | - before_update then add_trigger(ctrl.triggers.before_update, trigger_to_add), | ||
| 82 | - after_update then add_trigger(ctrl.triggers.after_update, trigger_to_add) | 81 | + before_update then println(">>> ADD TRIGGER 'before_update' to table "+_table_name);add_trigger(ctrl.triggers.before_update, trigger_to_add), |
| 82 | + after_update then println(">>> ADD TRIGGER 'after_update' to table "+_table_name);add_trigger(ctrl.triggers.after_update, trigger_to_add) | ||
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | . | 85 | . |
view/view_table_renderer.anubis
| @@ -656,7 +656,6 @@ public define List(CXM_Form_Field) | @@ -656,7 +656,6 @@ public define List(CXM_Form_Field) | ||
| 656 | with uid = "_"+generate_random_string(20)+"_", | 656 | with uid = "_"+generate_random_string(20)+"_", |
| 657 | with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh", | 657 | with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh", |
| 658 | 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+"(); "), | 658 | 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+"(); "), |
| 659 | - //with load_script_b64 = base64_encode(load_script, false), | ||
| 660 | [ | 659 | [ |
| 661 | 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)))), | 660 | 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)))), |
| 662 | one_line_fields([ | 661 | one_line_fields([ |
| @@ -666,16 +665,6 @@ public define List(CXM_Form_Field) | @@ -666,16 +665,6 @@ public define List(CXM_Form_Field) | ||
| 666 | ]) | 665 | ]) |
| 667 | ], | 666 | ], |
| 668 | 667 | ||
| 669 | -// with uid = generate_random_string(20)+"_", | ||
| 670 | -// 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+"');", | ||
| 671 | -// [ | ||
| 672 | -// 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)))), | ||
| 673 | -// one_line_fields([ | ||
| 674 | -// partial(partial_content([js_inline(jquery_ready(load_script))],empty)), | ||
| 675 | -// 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), | ||
| 676 | -// partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])), | ||
| 677 | -// ]) | ||
| 678 | -// ], | ||
| 679 | 668 | ||
| 680 | foreign_text_search(s_name, c_name, select, foreign_table_name, s_fields, help) then | 669 | foreign_text_search(s_name, c_name, select, foreign_table_name, s_fields, help) then |
| 681 | with uid = "_"+generate_random_string(20)+"_", | 670 | with uid = "_"+generate_random_string(20)+"_", |
| @@ -708,7 +697,6 @@ public define List(CXM_Form_Field) | @@ -708,7 +697,6 @@ public define List(CXM_Form_Field) | ||
| 708 | [ js(js_file("ckeditor/ckeditor.js")), | 697 | [ js(js_file("ckeditor/ckeditor.js")), |
| 709 | js_inline(jquery_ready( | 698 | js_inline(jquery_ready( |
| 710 | " var cke_instance = CKEDITOR.replace( '"+id+"' ); | 699 | " var cke_instance = CKEDITOR.replace( '"+id+"' ); |
| 711 | - //cxm_cke('"+id+"'); | ||
| 712 | cke_instance.on('blur', function() { cke_instance.updateElement(); }); | 700 | cke_instance.on('blur', function() { cke_instance.updateElement(); }); |
| 713 | "))],empty)) | 701 | "))],empty)) |
| 714 | }, | 702 | }, |
| @@ -739,147 +727,8 @@ public define List(CXM_Form_Field) | @@ -739,147 +727,8 @@ public define List(CXM_Form_Field) | ||
| 739 | edit_form_lines(db, fk_clause, table_referer, _T, t, new_entry, reverse(line)+so_far) | 727 | edit_form_lines(db, fk_clause, table_referer, _T, t, new_entry, reverse(line)+so_far) |
| 740 | }. | 728 | }. |
| 741 | 729 | ||
| 742 | -//define List(String) | ||
| 743 | -// get_rich_editor_inline | ||
| 744 | -// ( | ||
| 745 | -// List(HK_Form_Entry) list | ||
| 746 | -// )= | ||
| 747 | -// map_select((HK_Form_Entry entry) |-> | ||
| 748 | -// if entry is text_area(s_name, c_name, value, txt_editor, help) then | ||
| 749 | -// if txt_editor is { none then failure, | ||
| 750 | -// rich_editor then success(" CKEDITOR.replace( '"+c_name+"_editor' );") | ||
| 751 | -// } | ||
| 752 | -// else | ||
| 753 | -// failure, list) | ||
| 754 | -//. | ||
| 755 | - | ||
| 756 | -// define List(HTML_Head_Tag) | ||
| 757 | -// get_editor_header | ||
| 758 | -// ( | ||
| 759 | -// List(HK_Form_Entry) _list | ||
| 760 | -// )= | ||
| 761 | -// with result = get_rich_editor_inline(_list), | ||
| 762 | -// if length(result) > 0 then | ||
| 763 | -// [ | ||
| 764 | -// js_inline(jquery_ready(join("",result))) | ||
| 765 | -// ] | ||
| 766 | -// else | ||
| 767 | -// [] | ||
| 768 | -// . | ||
| 769 | - | ||
| 770 | -//define List(String) | ||
| 771 | -// _get_editor_header | ||
| 772 | -// ( | ||
| 773 | -// List(HK_Form_Table_Line) _lines | ||
| 774 | -// )= | ||
| 775 | -// map_append((HK_Form_Table_Line line) | ||
| 776 | -// |-> | ||
| 777 | -// map_append((HK_Form_Table_Cell cell) | ||
| 778 | -// |-> | ||
| 779 | -// if cell is | ||
| 780 | -// { | ||
| 781 | -// hk_form_table_cell(_, form_entry) then | ||
| 782 | -// if form_entry is text_area(s_name, c_name, value, txt_editor, help) then | ||
| 783 | -// if txt_editor is { | ||
| 784 | -// none then [], | ||
| 785 | -// rich_editor then [" CKEDITOR.replace( '"+c_name+"_editor' );"] | ||
| 786 | -// } | ||
| 787 | -// else | ||
| 788 | -// [], | ||
| 789 | -// hk_form_table_cell_table(_, t_lines) then | ||
| 790 | -// _get_editor_header(t_lines) | ||
| 791 | -// }, | ||
| 792 | -// line.form_table_cells), | ||
| 793 | -// _lines) | ||
| 794 | -//. | ||
| 795 | - | ||
| 796 | 730 | ||
| 797 | 731 | ||
| 798 | -//define List(String) | ||
| 799 | -// _get_combo_header | ||
| 800 | -// ( | ||
| 801 | -// String table_name, | ||
| 802 | -// List(HK_Form_Table_Line) _lines | ||
| 803 | -// )= | ||
| 804 | -// map_append((HK_Form_Table_Line line) | ||
| 805 | -// |-> | ||
| 806 | -// map_append((HK_Form_Table_Cell cell) | ||
| 807 | -// |-> | ||
| 808 | -// if cell is | ||
| 809 | -// { | ||
| 810 | -// hk_form_table_cell(_, form_entry) then | ||
| 811 | -// if form_entry is foreign_text_search(s_name, c_name, select, f_table, s_fields, help) then | ||
| 812 | -// [ajax_combo_init_parameter(f_table, c_name, s_fields)] | ||
| 813 | -// else | ||
| 814 | -// [], | ||
| 815 | -// hk_form_table_cell_table(_, t_lines) then | ||
| 816 | -// _get_combo_header(table_name, t_lines) | ||
| 817 | -// }, | ||
| 818 | -// line.form_table_cells), | ||
| 819 | -// _lines) | ||
| 820 | -//. | ||
| 821 | - | ||
| 822 | -//define List(HTML_Head_Tag) | ||
| 823 | -// get_editor_header | ||
| 824 | -// ( | ||
| 825 | -// List(HK_Form_Table_Line) _lines | ||
| 826 | -// )= | ||
| 827 | -// with result = _get_editor_header(_lines), | ||
| 828 | -// if length(result) > 0 then | ||
| 829 | -// [js(js_file("ckeditor/ckeditor.js")), | ||
| 830 | -// js_inline(jquery_ready(join("",result))) | ||
| 831 | -// ] | ||
| 832 | -// else | ||
| 833 | -// [] | ||
| 834 | -// . | ||
| 835 | - | ||
| 836 | -//define List(HTML_Head_Tag) | ||
| 837 | -// get_combo_header | ||
| 838 | -// ( | ||
| 839 | -// String table_name, | ||
| 840 | -// List(HK_Form_Table_Line) _lines | ||
| 841 | -// )= | ||
| 842 | -// with result = _get_combo_header(table_name, _lines), | ||
| 843 | -// if length(result) > 0 then | ||
| 844 | -// [js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")), | ||
| 845 | -// css(css_file("ajax-combobox/css/jquery.ajax-combobox.css")), | ||
| 846 | -// js_inline(jquery_ready(join("",result))) | ||
| 847 | -// ] | ||
| 848 | -// else | ||
| 849 | -// [] | ||
| 850 | -// . | ||
| 851 | - | ||
| 852 | -//define List(String) | ||
| 853 | -// _get_combo_header | ||
| 854 | -// ( | ||
| 855 | -// String table_name, | ||
| 856 | -// List(HK_Form_Entry) _entries | ||
| 857 | -// )= | ||
| 858 | -// map_append((HK_Form_Entry entry) | ||
| 859 | -// |-> | ||
| 860 | -// if entry is foreign_text_search(s_name, c_name, select, f_table, s_fields, help) then | ||
| 861 | -// [] | ||
| 862 | -// else | ||
| 863 | -// [] | ||
| 864 | -// , | ||
| 865 | -// _entries) | ||
| 866 | -//. | ||
| 867 | - | ||
| 868 | -//define List(HTML_Head_Tag) | ||
| 869 | -// get_combo_header | ||
| 870 | -// ( | ||
| 871 | -// String table_name, | ||
| 872 | -// List(HK_Form_Entry) _lines | ||
| 873 | -// )= | ||
| 874 | -// with result = _get_combo_header(table_name, _lines), | ||
| 875 | -// if length(result) > 0 then | ||
| 876 | -// [js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")), | ||
| 877 | -// css(css_file("ajax-combobox/css/jquery.ajax-combobox.css")), | ||
| 878 | -// js_inline(jquery_ready(join("",result))) | ||
| 879 | -// ] | ||
| 880 | -// else | ||
| 881 | -// [] | ||
| 882 | -// . | ||
| 883 | 732 | ||
| 884 | public define HTML_Partial_Content | 733 | public define HTML_Partial_Content |
| 885 | renderer_edit_list_form | 734 | renderer_edit_list_form |
| @@ -910,7 +759,7 @@ public define HTML_Partial_Content | @@ -910,7 +759,7 @@ public define HTML_Partial_Content | ||
| 910 | with button_label = if create then _T("CREATE") else _T("UPDATE"), | 759 | with button_label = if create then _T("CREATE") else _T("UPDATE"), |
| 911 | with button_name = if create then "create" else "update", | 760 | with button_name = if create then "create" else "update", |
| 912 | with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"), | 761 | with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"), |
| 913 | - | 762 | + with form_id = dialog_id+"_form", |
| 914 | println("renderer_edit_list_form dialog_id ["+dialog_id+"]"); | 763 | println("renderer_edit_list_form dialog_id ["+dialog_id+"]"); |
| 915 | partial_content( | 764 | partial_content( |
| 916 | [ js(js_file("js/jscolor.min.js")), | 765 | [ js(js_file("js/jscolor.min.js")), |
| @@ -926,11 +775,11 @@ public define HTML_Partial_Content | @@ -926,11 +775,11 @@ public define HTML_Partial_Content | ||
| 926 | //get_editor_header(list_entries)+ //add editor header if need. Like init ck_editor | 775 | //get_editor_header(list_entries)+ //add editor header if need. Like init ck_editor |
| 927 | //get_combo_header(table_name, list_entries), | 776 | //get_combo_header(table_name, list_entries), |
| 928 | sequence([ | 777 | sequence([ |
| 929 | - cxm_form( table_name, lwa, | 778 | + cxm_form( form_id, lwa, |
| 930 | (if length(list_entries) > 19 then | 779 | (if length(list_entries) > 19 then |
| 931 | [ | 780 | [ |
| 932 | one_line_fields([ | 781 | one_line_fields([ |
| 933 | - 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)))))), | 782 | + 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)))))), |
| 934 | partial(jquery_button(jQuery_button(button, dialog_id+"cancel", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))), | 783 | partial(jquery_button(jQuery_button(button, dialog_id+"cancel", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))), |
| 935 | ]), | 784 | ]), |
| 936 | hr | 785 | hr |
| @@ -958,8 +807,8 @@ public define HTML_Partial_Content | @@ -958,8 +807,8 @@ public define HTML_Partial_Content | ||
| 958 | 807 | ||
| 959 | [ hr, | 808 | [ hr, |
| 960 | one_line_fields([ | 809 | one_line_fields([ |
| 961 | - 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)))))), | ||
| 962 | - partial(jquery_button(jQuery_button(button, dialog_id+"cancel", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))), | 810 | + 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)))))), |
| 811 | + partial(jquery_button(jQuery_button(button, dialog_id+"cancel_bt", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))), | ||
| 963 | ]) | 812 | ]) |
| 964 | ] | 813 | ] |
| 965 | // submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name), ("sub_dialog", sub_dialog)]), | 814 | // 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) | @@ -1059,7 +908,6 @@ public define List(CXM_Form_Field) | ||
| 1059 | [js(js_file("ckeditor/ckeditor.js")), | 908 | [js(js_file("ckeditor/ckeditor.js")), |
| 1060 | js_inline(jquery_ready( | 909 | js_inline(jquery_ready( |
| 1061 | " var cke_instance = CKEDITOR.replace( '"+id+"' ); | 910 | " var cke_instance = CKEDITOR.replace( '"+id+"' ); |
| 1062 | - //cxm_cke('"+id+"'); | ||
| 1063 | cke_instance.on('blur', function() { cke_instance.updateElement(); }); | 911 | cke_instance.on('blur', function() { cke_instance.updateElement(); }); |
| 1064 | "))],empty)) | 912 | "))],empty)) |
| 1065 | }, | 913 | }, |
| @@ -1172,7 +1020,7 @@ public define HTML_Partial_Content | @@ -1172,7 +1020,7 @@ public define HTML_Partial_Content | ||
| 1172 | with button_label = if create then _T("CREATE") else _T("UPDATE"), | 1020 | with button_label = if create then _T("CREATE") else _T("UPDATE"), |
| 1173 | with button_name = if create then "create" else "update", | 1021 | with button_name = if create then "create" else "update", |
| 1174 | with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"), | 1022 | with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"), |
| 1175 | - | 1023 | + with form_id = dialog_id+"_form", |
| 1176 | partial_content( | 1024 | partial_content( |
| 1177 | [ js(js_file("js/jscolor.min.js")) | 1025 | [ js(js_file("js/jscolor.min.js")) |
| 1178 | ]+ | 1026 | ]+ |
| @@ -1180,14 +1028,14 @@ public define HTML_Partial_Content | @@ -1180,14 +1028,14 @@ public define HTML_Partial_Content | ||
| 1180 | //get_editor_header(table_form.form_lines)+ //add editor header if need. Like init ck_editor | 1028 | //get_editor_header(table_form.form_lines)+ //add editor header if need. Like init ck_editor |
| 1181 | //get_combo_header(table_name, table_form.form_lines), //add editor header if need. Like init ck_editor | 1029 | //get_combo_header(table_name, table_form.form_lines), //add editor header if need. Like init ck_editor |
| 1182 | sequence([ | 1030 | sequence([ |
| 1183 | - cxm_form( table_name, [], lwa, | 1031 | + cxm_form( form_id, [], lwa, |
| 1184 | get_hidden(table_form.table_attr)+ | 1032 | get_hidden(table_form.table_attr)+ |
| 1185 | [construct_edit_form_table(db, table_referer, _T, lwa, table_form.form_lines, create)]+ | 1033 | [construct_edit_form_table(db, table_referer, _T, lwa, table_form.form_lines, create)]+ |
| 1186 | [ one_line_fields([ | 1034 | [ one_line_fields([ |
| 1187 | // submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]), | 1035 | // submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]), |
| 1188 | // submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]), | 1036 | // submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]), |
| 1189 | // submit(hkc_cancel, failure, _T("CANCEL")) | 1037 | // submit(hkc_cancel, failure, _T("CANCEL")) |
| 1190 | - 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)))))), | 1038 | + 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)))))), |
| 1191 | partial(jquery_button(jQuery_button(button, dialog_id+"cancel", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))), | 1039 | partial(jquery_button(jQuery_button(button, dialog_id+"cancel", "cancel", _T("CANCEL"), jQuery_actioner(same, jqscript("$('#"+dialog_id+"').dialog('close')"))))), |
| 1192 | 1040 | ||
| 1193 | ]) | 1041 | ]) |