Commit 764acb4ef117c94b2e41bea46cf49392378dc2e1

Authored by David RENÉ
1 parent d3d2685b

add support of no add new entry when use the selector. This is useful when the u…

…ser is only allowed to select entry in selector
view/types/hk_form_entry.anubis
... ... @@ -32,7 +32,7 @@ public type HK_Form_Entry: //legacy VT_Edit
32 32 boolean (String s_name, String c_name, Bool value, HK_Help_Text help),
33 33 integer (String s_name, String c_name, Int value, HK_Help_Text help),
34 34 float (String s_name, String c_name, Float value, HK_Help_Text help),
35   - choices_int (String s_name, String c_name, Int selected, HK_Form_Selector selector, HK_Help_Text help),
  35 + choices_int (String s_name, String c_name, Int selected, HK_Form_Selector selector, HK_Help_Text help),
36 36 date (String s_name, String c_name, String value, HK_Help_Text help),
37 37 time (String s_name, String c_name, String value, HK_Help_Text help),
38 38 datetime (String s_name, String c_name, String value, HK_Help_Text help),
... ...
view/view_rows_import.anubis
... ... @@ -22,7 +22,7 @@ read calexium_lib/web/widgets/icons_set.anubis
22 22  
23 23 read hayamiki_lib/view/web_action.anubis
24 24  
25   -read web_pages/desktop.anubis
  25 + read web_pages/desktop.anubis
26 26 read app/app_constants.anubis
27 27 read version.anubis
28 28  
... ... @@ -184,7 +184,7 @@ public define HTML_Partial_Content
184 184 List((String,String)) target_columns_choices,
185 185 String separator,
186 186 String uploaded_file,
187   - WEB_Action_Name cancel_action, //
  187 + WEB_Action_Name cancel_action, //
188 188 (String) -> String _T // translator from dictionary
189 189 )=
190 190 partial_content([css(css_file("css/cxm/cxm_dnd.css")),
... ...
view/view_table_renderer.anubis
... ... @@ -639,6 +639,7 @@ public define List(CXM_Form_Field)
639 639 (String) -> String _T,
640 640 List(HK_Form_Entry) list,
641 641 Bool new_entry,
  642 + Bool no_add,
642 643 List(CXM_Form_Field) so_far
643 644 )=
644 645 if list is
... ... @@ -689,7 +690,10 @@ public define List(CXM_Form_Field)
689 690 one_line_fields([
690 691 partial(partial_content([js_inline(load_script)],empty)),
691 692 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("")), mandatory), help_line(help, _T),
692   - partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
  693 + if no_add then
  694 + empty
  695 + else
  696 + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
693 697 ])
694 698 ],
695 699  
... ... @@ -709,7 +713,10 @@ public define List(CXM_Form_Field)
709 713  
710 714 message(to_String(format_label(label(_T(s_name), no_help), html_Id("")))+
711 715 "<input class=\"in\" id=\""+uid+"\" data-init_record=\""+select+"\" size=\"50\" type=\"text\">"),
712   - partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
  716 + if no_add then
  717 + empty
  718 + else
  719 + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
713 720 ]),
714 721 help_line(help, _T)
715 722 ]
... ... @@ -761,7 +768,7 @@ public define List(CXM_Form_Field)
761 768 url( s_name, c_name, value, help) then
762 769 [url_input([event(onclick, "hk_go_url(this)")], [class("hk_input_url")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
763 770 },
764   - edit_form_lines(db, fk_clause, table_referer, lwa, _T, t, new_entry, reverse(line)+so_far)
  771 + edit_form_lines(db, fk_clause, table_referer, lwa, _T, t, new_entry, no_add, reverse(line)+so_far)
765 772 }.
766 773  
767 774  
... ... @@ -786,10 +793,11 @@ public define HTML_Partial_Content
786 793 ) =
787 794 //with table_name = vt_elist.table_name,
788 795 //true if need to create row or false for updating
789   - with create = if get_String(lwa, "id","none") = "none" then true else false,
790   - with id = get_String(lwa, "id","none"),
791   - with sub_dialog = get_String(lwa, "sub_dialog", "false"),
792   - with dialog_id = get_String(lwa, "dialog_id", ""),
  796 + with create = if get_String(lwa, "id","none") = "none" then true else false,
  797 + with no_add = get_Bool(lwa, "no_add", false),
  798 + with id = get_String(lwa, "id","none"),
  799 + with sub_dialog = get_String(lwa, "sub_dialog", "false"),
  800 + with dialog_id = get_String(lwa, "dialog_id", ""),
793 801 with after_close_cb = get_String(lwa, "after_close_cb", ""), //call back
794 802 with button_label = if create then _T("CREATE") else _T("UPDATE"),
795 803 with button_name = if create then "create" else "update",
... ... @@ -825,7 +833,7 @@ public define HTML_Partial_Content
825 833 []
826 834 )
827 835 +
828   - edit_form_lines(db, "", table_referer, lwa, _T, list_entries, create, [])
  836 + edit_form_lines(db, "", table_referer, lwa, _T, list_entries, create, no_add, [])
829 837 +
830 838 (if id = "none" then
831 839 []
... ... @@ -867,6 +875,7 @@ public define List(CXM_Form_Field)
867 875 (String) -> String _T,
868 876 HK_Form_Entry cell,
869 877 Bool new_entry,
  878 + Bool no_add,
870 879 List(CXM_Form_Field) so_far
871 880 )=
872 881  
... ... @@ -913,7 +922,10 @@ public define List(CXM_Form_Field)
913 922 one_line_fields([
914 923 partial(partial_content([js_inline(load_script)],empty)),
915 924 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("")), mandatory), help_line(help, _T),
916   - partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
  925 + if no_add then
  926 + empty
  927 + else
  928 + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
917 929 ])
918 930 ],
919 931  
... ... @@ -930,7 +942,10 @@ public define List(CXM_Form_Field)
930 942 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))))),
931 943 one_line_fields([
932 944 message("<input class=\"in\" id=\""+uid+"\" data-init_record=\""+select+"\" size=\"50\" type=\"text\">"),
933   - partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
  945 + if no_add then
  946 + empty
  947 + else
  948 + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
934 949 ]),
935 950 help_line(help, _T)
936 951 ]
... ... @@ -998,12 +1013,13 @@ define List(Cell_Option)
998 1013 define CXM_Form_Field
999 1014 construct_edit_form_table
1000 1015 (
1001   - SQLite3DataBase db,
1002   - HK_Referer table_referer,
1003   - (String) -> String _T,
1004   - List(Web_arg) lwa,
1005   - List(HK_Form_Table_Line) form_lines,
1006   - Bool create
  1016 + SQLite3DataBase db,
  1017 + HK_Referer table_referer,
  1018 + (String) -> String _T,
  1019 + List(Web_arg) lwa,
  1020 + List(HK_Form_Table_Line) form_lines,
  1021 + Bool create, //this is new entry, db_id = none
  1022 + Bool no_add //not allow to add new entry in dropdown
1007 1023 )=
1008 1024 div([],
1009 1025 table([class("striped")],
... ... @@ -1016,10 +1032,10 @@ define CXM_Form_Field
1016 1032 {
1017 1033 //construct one cell
1018 1034 hk_form_table_cell(cell_attributes, entry) then
1019   - cell(make_cell_option(cell_attributes), to_HTML_In_Form(edit_form_cell(db, "", table_referer, lwa, _T, entry, create, []), lwa, "form_field table", false)),
  1035 + cell(make_cell_option(cell_attributes), to_HTML_In_Form(edit_form_cell(db, "", table_referer, lwa, _T, entry, create, no_add, []), lwa, "form_field table", false)),
1020 1036 //construct table in one cell
1021 1037 hk_form_table_cell_table(cell_attributes, lines) then
1022   - cell(make_cell_option(cell_attributes), to_HTML_In_Form([construct_edit_form_table(db, table_referer, _T, lwa, lines, create)], lwa, "form_field table", false))
  1038 + cell(make_cell_option(cell_attributes), to_HTML_In_Form([construct_edit_form_table(db, table_referer, _T, lwa, lines, create, no_add)], lwa, "form_field table", false))
1023 1039 },
1024 1040 line.form_table_cells
1025 1041 )
... ... @@ -1037,6 +1053,28 @@ public define List(CXM_Form_Field)
1037 1053 map((HK_Form_Table_Attribute attr) |-> since attr is hidden(n, v), hidden(html_Id(""), wan(n), wav(v)), table_attrs)
1038 1054 .
1039 1055  
  1056 +public define List(CXM_Form_Field)
  1057 + get_hidden
  1058 + (
  1059 + List(Web_arg) lwa
  1060 + )=
  1061 + map_select((Web_arg warg) |->
  1062 + if warg is web_arg(name, value) then
  1063 + if starts_with(name, "hidden_") then
  1064 + with len_string = length(name),
  1065 + if sub_string(name, 7, len_string - 7) is
  1066 + {
  1067 + failure then failure,
  1068 + success(n) then success(hidden(html_Id(""), wan(n), wav(value)))
  1069 + }
  1070 + else
  1071 + failure
  1072 + else
  1073 + failure
  1074 + ,
  1075 + lwa)
  1076 +.
  1077 +
1040 1078 public define HTML_Partial_Content
1041 1079 renderer_edit_table_form
1042 1080 (
... ... @@ -1055,10 +1093,11 @@ public define HTML_Partial_Content
1055 1093 ) =
1056 1094 //with table_name = vt_elist.table_name,
1057 1095 //true if need to create row or false for updating
1058   - with create = if get_String(lwa, "id","none") = "none" then true else false,
1059   - with id = get_String(lwa, "id","none"),
1060   - with sub_dialog = get_String(lwa, "sub_dialog", "false"),
1061   - with dialog_id = get_String(lwa, "dialog_id", ""),
  1096 + with create = if get_String(lwa, "id","none") = "none" then true else false,
  1097 + with no_add = get_Bool(lwa, "no_add", false),
  1098 + with id = get_String(lwa, "id","none"),
  1099 + with sub_dialog = get_String(lwa, "sub_dialog", "false"),
  1100 + with dialog_id = get_String(lwa, "dialog_id", ""),
1062 1101 with after_close_cb = get_String(lwa, "after_close_cb", ""), //call back
1063 1102 with button_label = if create then _T("CREATE") else _T("UPDATE"),
1064 1103 with button_name = if create then "create" else "update",
... ... @@ -1075,8 +1114,9 @@ public define HTML_Partial_Content
1075 1114 //get_combo_header(table_name, table_form.form_lines), //add editor header if need. Like init ck_editor
1076 1115 sequence([
1077 1116 cxm_form( form_id, [], lwa,
1078   - get_hidden(table_form.table_attr)+
1079   - [construct_edit_form_table(db, table_referer, _T, lwa, table_form.form_lines, create)]+
  1117 + get_hidden(table_form.table_attr)+ //collect hidden value from table form
  1118 + get_hidden(lwa)+ //collect hidden value from lwa
  1119 + [construct_edit_form_table(db, table_referer, _T, lwa, table_form.form_lines, create, no_add)]+
1080 1120 [ one_line_fields([
1081 1121 // submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]),
1082 1122 // submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
... ... @@ -1111,15 +1151,12 @@ public define Maybe(HTML_Partial_Content)
1111 1151 (
1112 1152 SQLite3DataBase db,
1113 1153 (String) -> String _T,
1114   - String lang,
1115   - //String web_site_directory,
  1154 + String lang,
1116 1155 List(Web_arg) lwa,
1117   - //String dialog_id,
1118 1156 String table, //table name
1119 1157 String view_name, //view name to use
1120 1158 HK_Form_action action, //new_entry or edit an existing record
1121 1159 VTM vtm,
1122   - //String clause,
1123 1160 String fk_clause,
1124 1161 HK_Referer referer
1125 1162 ) =
... ... @@ -1143,15 +1180,13 @@ public define Maybe(HTML_Partial_Content)
1143 1180 (
1144 1181 SQLite3DataBase db,
1145 1182 (String) -> String _T,
1146   - String lang,
1147   - //String web_site_directory,
  1183 + String lang,
1148 1184 List(Web_arg) lwa,
1149   - //String dialog_id,
1150 1185 String table, //table name
1151 1186 String view_name, //view name to use
1152 1187 HK_Form_action action, //new_entry or edit an existing record
1153 1188 VTM vtm
1154 1189 ) =
1155   - edit_table_content(db, _T, lang, /*web_site_directory,*/ lwa, /*dialog_id,*/ table, view_name, action, vtm, "", /*"",*/ no_referer)
  1190 + edit_table_content(db, _T, lang, lwa, table, view_name, action, vtm, "", no_referer)
1156 1191 .
1157 1192  
... ...