Commit 2bd0873598f032348264ca8138caf6fb35de01f2

Authored by David RENÉ
1 parent f3910a95

[+] manage the active filter in ajax combo box only for the moment

[+] get hidden to add in form as value. if there is web arg with name starting with "hidden_", the name after "hidden_" will be add as hidden value in form. This allow to add necessaries values which are not especially exposed as editable but mandatory in database record. For example if there is database record editable by user and that user is not allowed to change or set some important information reserved to company's staff.
Showing 1 changed file with 95 additions and 31 deletions   Show diff stats
view/view_table_renderer.anubis
... ... @@ -43,6 +43,28 @@ read calexium_lib/web/widgets/button.anubis
43 43 read calexium_lib/web/widgets/specialized_elements.anubis
44 44 read calexium_lib/web/CXM_urllib.anubis
45 45  
  46 +public define List(CXM_Form_Field)
  47 + get_hidden
  48 + (
  49 + List(Web_arg) lwa
  50 + )=
  51 + map_select((Web_arg warg) |->
  52 + if warg is web_arg(name, value) then
  53 + if starts_with(name, "hidden_") then
  54 + with len_string = length(name),
  55 + if sub_string(name, 7, len_string - 7) is
  56 + {
  57 + failure then failure,
  58 + success(n) then success(hidden(html_Id(""), wan(n), wav(value)))
  59 + }
  60 + else
  61 + failure
  62 + else
  63 + failure
  64 + ,
  65 + lwa)
  66 +.
  67 +
46 68 public define Phone_Type
47 69 convert
48 70 (
... ... @@ -135,9 +157,17 @@ define String
135 157 String combo_uid,
136 158 String f_table, //db table name
137 159 String c_name, //column name in the table
138   - Maybe(Int) init_value, //
139   - List(String) s_fields //search fields
  160 + Maybe(Int) init_value, //
  161 + List(String) s_fields, //search fields
  162 + List(HK_Foreign_Key_Active_Filter) active_filters
140 163 )=
  164 + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
  165 + since a_filter is active_filter(column, fk_column),
  166 + "column '"+column+"' fk_column '"+fk_column+"\n"
  167 + ,
  168 + active_filters
  169 + )))
  170 + ;
141 171 "$('#"+combo_uid+"').ajaxComboBox( '?aws_controller=hk_c&aws_action=combo_search',
142 172 {"
143 173 +
... ... @@ -149,6 +179,17 @@ if init_value is {failure then "", success(value) then
149 179 db_table: '"+f_table+"',
150 180 button_img: 'ajax-combobox/btn.png',
151 181 field: '"+force_nth(0, s_fields, "name")+"',
  182 +" +
  183 +(if length(active_filters) > 0 then
  184 + "active_filters: ["+join(", ", map((HK_Foreign_Key_Active_Filter a_filter) |->
  185 + since a_filter is active_filter(column, fk_column),
  186 + "['"+column+"', '"+fk_column+"']"
  187 + ,
  188 + active_filters
  189 + ))+"],"
  190 +else
  191 +"")
  192 ++"
152 193 search_field: '"+join(", ", s_fields)+"',
153 194 hidden_name: '"+c_name+"',
154 195 "+(if "__HK_SHOW_STRING__":s_fields then
... ... @@ -678,7 +719,17 @@ public define List(CXM_Form_Field)
678 719 password_entries
679 720 ],
680 721  
681   - foreign_text(s_name, c_name, _value, foreign_table_name, active_filter, select, help) then
  722 + foreign_text(s_name, c_name, _value, foreign_table_name, select, active_filters, help) then
  723 + with dummy = if length(active_filters) > 0 then
  724 + println("ACTIVE FILTER for "+c_name);
  725 + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
  726 + since a_filter is active_filter(column, fk_column),
  727 + "column '"+column+"' fk_column '"+fk_column+"\n"
  728 + ,
  729 + active_filters
  730 + )))
  731 + else
  732 + unique,
682 733 with uid = "_"+generate_random_string(20)+"_",
683 734 with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh",
684 735 //Get the priority of the web argument content for the value, this means the value already set by the user or called with programmaticaly with it
... ... @@ -698,11 +749,21 @@ public define List(CXM_Form_Field)
698 749 ],
699 750  
700 751  
701   - foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filter, help) then
  752 + foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filters, help) then
  753 + with dummy = if length(active_filters) > 0 then
  754 + println("ACTIVE FILTER for "+c_name);
  755 + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
  756 + since a_filter is active_filter(column, fk_column),
  757 + "column '"+column+"' fk_column '"+fk_column+"\n"
  758 + ,
  759 + active_filters
  760 + )))
  761 + else
  762 + unique,
702 763 with uid = "_"+generate_random_string(20)+"_",
703 764 //Get the priority of the web argument content for the select, this means the value already set by the user or called with programmaticaly with it
704 765 with select = get_DB_id(lwa, c_name, _select),
705   - with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields),
  766 + with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields, active_filters),
706 767 [
707 768  
708 769 partial(partial_content([ js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")),
... ... @@ -820,7 +881,8 @@ public define HTML_Partial_Content
820 881 //get_editor_header(list_entries)+ //add editor header if need. Like init ck_editor
821 882 //get_combo_header(table_name, list_entries),
822 883 sequence([
823   - cxm_form( form_id, lwa,
  884 + cxm_form( form_id, lwa,
  885 + get_hidden(lwa)+ //collect hidden value from lwa
824 886 (if length(list_entries) > 5 then
825 887 [
826 888 one_line_fields([
... ... @@ -910,7 +972,17 @@ public define List(CXM_Form_Field)
910 972 password_entries
911 973 ],
912 974  
913   - foreign_text(s_name, c_name, _value, foreign_table_name, active_filter, select, help) then
  975 + foreign_text(s_name, c_name, _value, foreign_table_name, select, active_filters, help) then
  976 + with dummy = if length(active_filters) > 0 then
  977 + println("ACTIVE FILTER for "+c_name);
  978 + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
  979 + since a_filter is active_filter(column, fk_column),
  980 + "column '"+column+"' fk_column '"+fk_column+"\n"
  981 + ,
  982 + active_filters
  983 + )))
  984 + else
  985 + unique,
914 986 //[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)],
915 987 with fk_clause = "",
916 988 with uid = "_"+generate_random_string(20)+"_",
... ... @@ -930,11 +1002,23 @@ public define List(CXM_Form_Field)
930 1002 ])
931 1003 ],
932 1004  
933   - foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filer, help) then
  1005 + foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filters, help) then
  1006 + with dummy = if length(active_filters) > 0then
  1007 + println("ACTIVE FILTER for "+c_name);
  1008 + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |->
  1009 + since a_filter is active_filter(column, fk_column),
  1010 + "column '"+column+"' fk_column '"+fk_column+"\n"
  1011 + ,
  1012 + active_filters
  1013 + )))
  1014 + else
  1015 + unique,
934 1016 //[raw_in_form(literal("<input class=\"in\" id=\"acb_"+c_name+"\" data-init_record=\""+select+"\" size=\"50\" type=\"text\">"))]
935 1017 with uid = "_"+generate_random_string(20)+"_",
936   - with select = get_DB_id(lwa, c_name, _select),
937   - with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields),
  1018 + //if column name came with argument, we supersede the given _select by it.
  1019 + with select = get_DB_id(lwa, c_name, _select),
  1020 +
  1021 + with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields, active_filters),
938 1022 [
939 1023 partial(partial_content([
940 1024 js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")),
... ... @@ -1055,27 +1139,7 @@ public define List(CXM_Form_Field)
1055 1139 map((HK_Form_Table_Attribute attr) |-> since attr is hidden(n, v), hidden(html_Id(""), wan(n), wav(v)), table_attrs)
1056 1140 .
1057 1141  
1058   -public define List(CXM_Form_Field)
1059   - get_hidden
1060   - (
1061   - List(Web_arg) lwa
1062   - )=
1063   - map_select((Web_arg warg) |->
1064   - if warg is web_arg(name, value) then
1065   - if starts_with(name, "hidden_") then
1066   - with len_string = length(name),
1067   - if sub_string(name, 7, len_string - 7) is
1068   - {
1069   - failure then failure,
1070   - success(n) then success(hidden(html_Id(""), wan(n), wav(value)))
1071   - }
1072   - else
1073   - failure
1074   - else
1075   - failure
1076   - ,
1077   - lwa)
1078   -.
  1142 +
1079 1143  
1080 1144 public define HTML_Partial_Content
1081 1145 renderer_edit_table_form
... ...