From 2bd0873598f032348264ca8138caf6fb35de01f2 Mon Sep 17 00:00:00 2001 From: totoro Date: Sat, 27 Jul 2019 02:18:52 +0200 Subject: [PATCH] [+] 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. --- view/view_table_renderer.anubis | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 95 insertions(+), 31 deletions(-) diff --git a/view/view_table_renderer.anubis b/view/view_table_renderer.anubis index 0d24cc4..014ee48 100644 --- a/view/view_table_renderer.anubis +++ b/view/view_table_renderer.anubis @@ -43,6 +43,28 @@ read calexium_lib/web/widgets/button.anubis read calexium_lib/web/widgets/specialized_elements.anubis read calexium_lib/web/CXM_urllib.anubis +public define List(CXM_Form_Field) + get_hidden + ( + List(Web_arg) lwa + )= + map_select((Web_arg warg) |-> + if warg is web_arg(name, value) then + if starts_with(name, "hidden_") then + with len_string = length(name), + if sub_string(name, 7, len_string - 7) is + { + failure then failure, + success(n) then success(hidden(html_Id(""), wan(n), wav(value))) + } + else + failure + else + failure + , + lwa) +. + public define Phone_Type convert ( @@ -135,9 +157,17 @@ define String String combo_uid, String f_table, //db table name String c_name, //column name in the table - Maybe(Int) init_value, // - List(String) s_fields //search fields + Maybe(Int) init_value, // + List(String) s_fields, //search fields + List(HK_Foreign_Key_Active_Filter) active_filters )= + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |-> + since a_filter is active_filter(column, fk_column), + "column '"+column+"' fk_column '"+fk_column+"\n" + , + active_filters + ))) + ; "$('#"+combo_uid+"').ajaxComboBox( '?aws_controller=hk_c&aws_action=combo_search', {" + @@ -149,6 +179,17 @@ if init_value is {failure then "", success(value) then db_table: '"+f_table+"', button_img: 'ajax-combobox/btn.png', field: '"+force_nth(0, s_fields, "name")+"', +" + +(if length(active_filters) > 0 then + "active_filters: ["+join(", ", map((HK_Foreign_Key_Active_Filter a_filter) |-> + since a_filter is active_filter(column, fk_column), + "['"+column+"', '"+fk_column+"']" + , + active_filters + ))+"]," +else +"") ++" search_field: '"+join(", ", s_fields)+"', hidden_name: '"+c_name+"', "+(if "__HK_SHOW_STRING__":s_fields then @@ -678,7 +719,17 @@ public define List(CXM_Form_Field) password_entries ], - foreign_text(s_name, c_name, _value, foreign_table_name, active_filter, select, help) then + foreign_text(s_name, c_name, _value, foreign_table_name, select, active_filters, help) then + with dummy = if length(active_filters) > 0 then + println("ACTIVE FILTER for "+c_name); + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |-> + since a_filter is active_filter(column, fk_column), + "column '"+column+"' fk_column '"+fk_column+"\n" + , + active_filters + ))) + else + unique, with uid = "_"+generate_random_string(20)+"_", with refresh_func = uid+foreign_table_name+"_"+c_name+"_selector_refresh", //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) ], - foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filter, help) then + foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filters, help) then + with dummy = if length(active_filters) > 0 then + println("ACTIVE FILTER for "+c_name); + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |-> + since a_filter is active_filter(column, fk_column), + "column '"+column+"' fk_column '"+fk_column+"\n" + , + active_filters + ))) + else + unique, with uid = "_"+generate_random_string(20)+"_", //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 with select = get_DB_id(lwa, c_name, _select), - with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields), + with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields, active_filters), [ partial(partial_content([ js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")), @@ -820,7 +881,8 @@ 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( form_id, lwa, + cxm_form( form_id, lwa, + get_hidden(lwa)+ //collect hidden value from lwa (if length(list_entries) > 5 then [ one_line_fields([ @@ -910,7 +972,17 @@ public define List(CXM_Form_Field) password_entries ], - foreign_text(s_name, c_name, _value, foreign_table_name, active_filter, select, help) then + foreign_text(s_name, c_name, _value, foreign_table_name, select, active_filters, help) then + with dummy = if length(active_filters) > 0 then + println("ACTIVE FILTER for "+c_name); + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |-> + since a_filter is active_filter(column, fk_column), + "column '"+column+"' fk_column '"+fk_column+"\n" + , + active_filters + ))) + else + unique, //[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)], with fk_clause = "", with uid = "_"+generate_random_string(20)+"_", @@ -930,11 +1002,23 @@ public define List(CXM_Form_Field) ]) ], - foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filer, help) then + foreign_text_search(s_name, c_name, _select, foreign_table_name, s_fields, active_filters, help) then + with dummy = if length(active_filters) > 0then + println("ACTIVE FILTER for "+c_name); + println(join("", map((HK_Foreign_Key_Active_Filter a_filter) |-> + since a_filter is active_filter(column, fk_column), + "column '"+column+"' fk_column '"+fk_column+"\n" + , + active_filters + ))) + else + unique, //[raw_in_form(literal(""))] with uid = "_"+generate_random_string(20)+"_", - with select = get_DB_id(lwa, c_name, _select), - with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields), + //if column name came with argument, we supersede the given _select by it. + with select = get_DB_id(lwa, c_name, _select), + + with combo_init = ajax_combo_init_parameter(uid, foreign_table_name, c_name, to_mb_Int(select), s_fields, active_filters), [ partial(partial_content([ js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")), @@ -1055,27 +1139,7 @@ public define List(CXM_Form_Field) map((HK_Form_Table_Attribute attr) |-> since attr is hidden(n, v), hidden(html_Id(""), wan(n), wav(v)), table_attrs) . -public define List(CXM_Form_Field) - get_hidden - ( - List(Web_arg) lwa - )= - map_select((Web_arg warg) |-> - if warg is web_arg(name, value) then - if starts_with(name, "hidden_") then - with len_string = length(name), - if sub_string(name, 7, len_string - 7) is - { - failure then failure, - success(n) then success(hidden(html_Id(""), wan(n), wav(value))) - } - else - failure - else - failure - , - lwa) -. + public define HTML_Partial_Content renderer_edit_table_form -- libgit2 0.21.4