Commit 5dc2618dc6862d54638c73cbe106c1b60b03528e

Authored by totoro
1 parent b947f1f0

add hk_controller to replace little by little old controllers in VTM (virtual table manager)

start to implement the combo search, still not finished
view/types/hk_form_entry.anubis
@@ -25,6 +25,7 @@ public type HK_Form_Entry: //legacy VT_Edit @@ -25,6 +25,7 @@ public type HK_Form_Entry: //legacy VT_Edit
25 text (String s_name, String c_name, String value, HK_Help_Text help), //s_name = show_name for translation, c_name = table column name 25 text (String s_name, String c_name, String value, HK_Help_Text help), //s_name = show_name for translation, c_name = table column name
26 password (String s_name, String c_name, HK_Help_Text help), //s_name = show_name for translation, c_name = table column name 26 password (String s_name, String c_name, HK_Help_Text help), //s_name = show_name for translation, c_name = table column name
27 foreign_text(String s_name, String c_name, DB_id selected, HK_Form_Selector selector, HK_Help_Text help), 27 foreign_text(String s_name, String c_name, DB_id selected, HK_Form_Selector selector, HK_Help_Text help),
  28 + foreign_text_search(String s_name, String c_name, DB_id selected, String f_table_name, List(String) search_fields, HK_Help_Text help),
28 choices_text(String s_name, String c_name, String selected, HK_Form_Selector selector, HK_Help_Text help), 29 choices_text(String s_name, String c_name, String selected, HK_Form_Selector selector, HK_Help_Text help),
29 text_area (String s_name, String c_name, String value, HK_Text_Field_Attr area_att, HK_Help_Text help), //s_name = show_name for translate, c_name = table column name 30 text_area (String s_name, String c_name, String value, HK_Text_Field_Attr area_att, HK_Help_Text help), //s_name = show_name for translate, c_name = table column name
30 boolean (String s_name, String c_name, Bool value, HK_Help_Text help), 31 boolean (String s_name, String c_name, Bool value, HK_Help_Text help),
view/view_table_manager.anubis
@@ -108,3 +108,20 @@ public define Maybe((SQLite3DataBase db, List(Int) l_int) -> Maybe(One)) @@ -108,3 +108,20 @@ public define Maybe((SQLite3DataBase db, List(Int) l_int) -> Maybe(One))
108 TM_delete_list tm_dlist 108 TM_delete_list tm_dlist
109 ) = 109 ) =
110 _tm_get_delete(table_name, tm_dlist.list). 110 _tm_get_delete(table_name, tm_dlist.list).
  111 +
  112 +public define Maybe(HK_Table_controller)
  113 + get_hk_controller
  114 + (
  115 + String _table_name,
  116 + List(HK_Table_controller) controllers
  117 + )=
  118 + if controllers is
  119 + {
  120 + [] then failure,
  121 + [h . t ] then
  122 + if h.table_name = _table_name then
  123 + success(h)
  124 + else
  125 + get_hk_controller(_table_name, t)
  126 + }
  127 +.
view/view_table_manager_types.anubis
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 read hayamiki_lib/view/types/hk_form.anubis 9 read hayamiki_lib/view/types/hk_form.anubis
10 read hayamiki_lib/view/types/hk_view.anubis 10 read hayamiki_lib/view/types/hk_view.anubis
11 read hayamiki_lib/view/types/hk_filter.anubis 11 read hayamiki_lib/view/types/hk_filter.anubis
  12 +read hayamiki_lib/types/hayamiki.anubis
  13 +
12 read calexium_lib/web/CXM_common.anubis 14 read calexium_lib/web/CXM_common.anubis
13 15
14 public type VTM_edit: 16 public type VTM_edit:
@@ -25,6 +27,28 @@ public type TM_writer: @@ -25,6 +27,28 @@ public type TM_writer:
25 ) 27 )
26 . 28 .
27 29
  30 + //CRUD basis function +
  31 + //Create
  32 + //Read
  33 + //Update
  34 + //Delete
  35 +
  36 +public type HK_Table_controller:
  37 + hk_table_controller(
  38 + String table_name,
  39 + //Create
  40 + (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write_from_type,
  41 + (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write_from_fields,
  42 + //Read
  43 + (SQLite3DataBase db, String clause) -> Int get_count,
  44 + (SQLite3DataBase db, HK_Referer referer, String clause, String order_by) -> JsonMember get_rows_json,
  45 +
  46 + //Update
  47 + //Delete
  48 + (SQLite3DataBase db, List(Int) l_int) -> Maybe(One) delete
  49 + )
  50 +.
  51 +
28 public type TM_writer_list: 52 public type TM_writer_list:
29 tm_writer_list(List(TM_writer) list). 53 tm_writer_list(List(TM_writer) list).
30 54
@@ -44,4 +68,5 @@ public type VTM: @@ -44,4 +68,5 @@ public type VTM:
44 vtm(VTM_view_list view_list, 68 vtm(VTM_view_list view_list,
45 VTM_edit_list edit_list, 69 VTM_edit_list edit_list,
46 TM_writer_list writer_list, 70 TM_writer_list writer_list,
47 - TM_delete_list delete_list). 71 + TM_delete_list delete_list,
  72 + List(HK_Table_controller) hk_controllers).
view/view_table_renderer.anubis
@@ -120,7 +120,6 @@ define HTML_In_Form @@ -120,7 +120,6 @@ define HTML_In_Form
120 )= 120 )=
121 with filters = get_view_filters(current_view, all_view_name), 121 with filters = get_view_filters(current_view, all_view_name),
122 filter_len = length(filters), 122 filter_len = length(filters),
123 - println("filter length "+filter_len);  
124 123
125 if filter_len = 0 then 124 if filter_len = 0 then
126 hidden(wan("filter_name"), wav("no_filter")) 125 hidden(wan("filter_name"), wav("no_filter"))
@@ -132,7 +131,7 @@ define HTML_In_Form @@ -132,7 +131,7 @@ define HTML_In_Form
132 immediate_selector([id("select_view")], 131 immediate_selector([id("select_view")],
133 wan("filter_name"), //web arg name of the selected entry 132 wan("filter_name"), //web arg name of the selected entry
134 1, 133 1,
135 - map(((HK_Filter) filter) |-> println("selector filter_name "+filter.filter_name); ([], wav(filter.filter_name), _T(filter.filter_name)), filters), 134 + map(((HK_Filter) filter) |-> ([], wav(filter.filter_name), _T(filter.filter_name)), filters),
136 success(init(current_filter)), 135 success(init(current_filter)),
137 "" 136 ""
138 ), 137 ),
@@ -611,7 +610,9 @@ public define List(CXM_Form_Field) @@ -611,7 +610,9 @@ public define List(CXM_Form_Field)
611 ], 610 ],
612 611
613 foreign_text(s_name, c_name, value, select, help) then 612 foreign_text(s_name, c_name, value, select, help) then
614 - [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, table_referer, fk_clause), success(init(to_String(value))), mandatory), help_line(help, _T)], 613 + [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, table_referer, fk_clause), success(init(to_String(value))), mandatory), help_line(help, _T)],
  614 + foreign_text_search(s_name, c_name, select, table_name, fields, help) then
  615 + [raw_in_form(literal("<input id=\"acb_"+c_name+"\" type=\"text\">"))]
615 choices_text(s_name, c_name, value, select, help) then 616 choices_text(s_name, c_name, value, select, help) then
616 [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)], 617 [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
617 text_area(s_name, c_name, value, txt_editor, help) then 618 text_area(s_name, c_name, value, txt_editor, help) then
@@ -695,6 +696,38 @@ define List(String) @@ -695,6 +696,38 @@ define List(String)
695 _lines) 696 _lines)
696 . 697 .
697 698
  699 +
  700 +define List(String)
  701 + _get_combo_header
  702 + (
  703 + String table_name,
  704 + List(HK_Form_Table_Line) _lines
  705 + )=
  706 + map_append((HK_Form_Table_Line line)
  707 + |->
  708 + map_append((HK_Form_Table_Cell cell)
  709 + |->
  710 + if cell is
  711 + {
  712 + hk_form_table_cell(_, form_entry) then
  713 + if form_entry is foreign_text(s_name, c_name, value, select, help) then
  714 + with result =
  715 +"$('#acb_"+c_name+"').ajaxComboBox( '?aws_controller=hkc&aws_action=combo_action',
  716 + {
  717 + lang: 'fr',
  718 + db_table: '"+table_name+"',
  719 + button_img: 'ajax-combobox/btn.png'
  720 + });",
  721 + [result]
  722 + else
  723 + [],
  724 + hk_form_table_cell_table(_, t_lines) then
  725 + _get_combo_header(table_name, t_lines)
  726 + },
  727 + line.form_table_cells),
  728 + _lines)
  729 +.
  730 +
698 define List(HTML_Head_Tag) 731 define List(HTML_Head_Tag)
699 get_editor_header 732 get_editor_header
700 ( 733 (
@@ -708,7 +741,21 @@ define List(HTML_Head_Tag) @@ -708,7 +741,21 @@ define List(HTML_Head_Tag)
708 else 741 else
709 [] 742 []
710 . 743 .
711 - 744 +define List(HTML_Head_Tag)
  745 + get_combo_header
  746 + (
  747 + String table_name,
  748 + List(HK_Form_Table_Line) _lines
  749 + )=
  750 + with result = _get_combo_header(table_name, _lines),
  751 + if length(result) > 0 then
  752 + [js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")),
  753 + css(css_file("ajax-combobox/css/jquery.ajax-combobox.css")),
  754 + js_inline(jquery_ready(join("",result)))
  755 + ]
  756 + else
  757 + []
  758 + .
712 759
713 public define HTML_Partial_Content 760 public define HTML_Partial_Content
714 renderer_edit_list_form 761 renderer_edit_list_form
@@ -828,6 +875,10 @@ public define List(CXM_Form_Field) @@ -828,6 +875,10 @@ public define List(CXM_Form_Field)
828 875
829 foreign_text(s_name, c_name, value, select, help) then 876 foreign_text(s_name, c_name, value, select, help) then
830 [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)], 877 [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)],
  878 + //[selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, table_referer, fk_clause), success(init(to_String(value))), mandatory), help_line(help, _T)],
  879 + foreign_text_search(s_name, c_name, select, f_table, s_fields, help) then
  880 + [raw_in_form(literal("<input id=\"acb_"+c_name+"\" type=\"text\">"))],
  881 +
831 choices_text(s_name, c_name, value, select, help) then 882 choices_text(s_name, c_name, value, select, help) then
832 [selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)], 883 [selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
833 text_area(s_name, c_name, value, txt_editor, help) then 884 text_area(s_name, c_name, value, txt_editor, help) then
@@ -941,7 +992,8 @@ public define HTML_Partial_Content @@ -941,7 +992,8 @@ public define HTML_Partial_Content
941 [ js(js_file("js/jscolor.min.js")) 992 [ js(js_file("js/jscolor.min.js"))
942 ]+ 993 ]+
943 jq_datetimepicker_init(lang) + 994 jq_datetimepicker_init(lang) +
944 - get_editor_header(table_form.form_lines), //add editor header if need. Like init ck_editor 995 + get_editor_header(table_form.form_lines)+ //add editor header if need. Like init ck_editor
  996 + get_combo_header(table_name, table_form.form_lines), //add editor header if need. Like init ck_editor
945 sequence([ 997 sequence([
946 cxm_form( table_name, [], lwa, 998 cxm_form( table_name, [], lwa,
947 get_hidden(table_form.table_attr)+ 999 get_hidden(table_form.table_attr)+
view/web_action.anubis
@@ -14,6 +14,7 @@ public define WEB_Action_Name hkc_edit_table = controller_action(&quot;hk_c&quot; @@ -14,6 +14,7 @@ public define WEB_Action_Name hkc_edit_table = controller_action(&quot;hk_c&quot;
14 public define WEB_Action_Name hkc_view_editor = controller_action("hk_c", "view_editor"). 14 public define WEB_Action_Name hkc_view_editor = controller_action("hk_c", "view_editor").
15 public define WEB_Action_Name hkc_grid_view = controller_action("hk_c", "grid_view"). 15 public define WEB_Action_Name hkc_grid_view = controller_action("hk_c", "grid_view").
16 public define WEB_Action_Name hkc_grid_action = controller_action("hk_c", "grid_action"). 16 public define WEB_Action_Name hkc_grid_action = controller_action("hk_c", "grid_action").
  17 +public define WEB_Action_Name hkc_combo_search = controller_action("hk_c", "combo_search").
17 public define WEB_Action_Name hkc_list_view = controller_action("hk_c", "view_table"). 18 public define WEB_Action_Name hkc_list_view = controller_action("hk_c", "view_table").
18 public define WEB_Action_Name hkc_list_view_name = controller_action("hk_c", "hkc_list_view_name"). 19 public define WEB_Action_Name hkc_list_view_name = controller_action("hk_c", "hkc_list_view_name").
19 public define WEB_Action_Name hkc_list_view_filter = controller_action("hk_c", "hkc_list_view_filter"). 20 public define WEB_Action_Name hkc_list_view_filter = controller_action("hk_c", "hkc_list_view_filter").