diff --git a/controller/hk_sql_utils.anubis b/controller/hk_sql_utils.anubis new file mode 100644 index 0000000..aa47cdb --- /dev/null +++ b/controller/hk_sql_utils.anubis @@ -0,0 +1,29 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 02/04/2017 + * Time: 19:23 + * © Calexium + */ + +read hayamiki_lib/types/hayamiki.anubis + +public define String + referer_to_sql_clause + ( + HK_Referer referer, + String table_name, + List(String) table_columns + )= + if referer is + { + no_referer then "", + hk_referer(referer_table, referer_row_id, fk_table, fk_column) then + if referer_table = table_name then + "id = " +referer_row_id + else if fk_column:table_columns then + fk_column + " = " + referer_row_id + else + "", + } +. diff --git a/types/hayamiki.anubis b/types/hayamiki.anubis index a86c7bc..839c9f3 100644 --- a/types/hayamiki.anubis +++ b/types/hayamiki.anubis @@ -6,7 +6,7 @@ * © Calexium */ - +read calexium_lib/web/CXM_web_arg_utils.anubis transmit hayamiki_lib/model/fields.anubis transmit hayamiki_lib/model/database.anubis transmit hayamiki_lib/model/columns.anubis @@ -20,3 +20,43 @@ public type HK_Referer: String fk_column ) . + +public define HK_Referer + get_HK_Referer_from_web_arg + ( + List(Web_arg) lwa, + String __prefix__ + )= + if get_Bool(lwa, __prefix__+"hk_referer") then + if get_String(lwa, __prefix__+"referer_table") is { failure then no_referer, success(referer_table) then + if get_String(lwa, __prefix__+"referer_row_id") is { failure then no_referer, success(referer_row_id) then + if get_String(lwa, __prefix__+"fk_table") is { failure then no_referer, success(fk_table) then + if get_String(lwa, __prefix__+"fk_column") is { failure then no_referer, success(fk_column) then + hk_referer( + referer_table, + referer_row_id, + fk_table, + fk_column + ) + }}}} + else + no_referer +. + +public define String + to_Web_arg + ( + HK_Referer referer, + String __prefix__ + )= + if referer is + { + no_referer then __prefix__+"hk_referer=false", + hk_referer(referer_table, referer_row_id, fk_table, fk_column) then + __prefix__+"hk_referer=true&"+ + __prefix__+"referer_table="+referer_table+"&"+ + __prefix__+"referer_row_id="+referer_row_id+"&"+ + __prefix__+"fk_table="+ fk_table+"&"+ + __prefix__+"fk_column="+ fk_column + } +. diff --git a/view/view_apps_renderer.anubis b/view/view_apps_renderer.anubis index 9ba8404..a066423 100644 --- a/view/view_apps_renderer.anubis +++ b/view/view_apps_renderer.anubis @@ -34,7 +34,7 @@ define List(HTML_Row(HTML_Off_Form)) cell( sequence([ partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id("edit_table_dlg_ajax"), "'table_name="+table_name+"'"))], "", [])), - partial(img_button(icn16_view_list, hkc_view_table, [("table_name",table_name)])) + partial(img_button(icn16_view_list, hkc_list_view, [("table_name",table_name)])) ]) ) ]) diff --git a/view/view_table_renderer.anubis b/view/view_table_renderer.anubis index 647823f..2ef01c9 100644 --- a/view/view_table_renderer.anubis +++ b/view/view_table_renderer.anubis @@ -59,7 +59,7 @@ define HTML_Off_Form success(init(current_view)), "" ), - hkc_view_table, + hkc_list_view, [("table_name", vtm_v.table_name)], [])) . @@ -214,8 +214,9 @@ public define HTML_Partial_Content HK_Referer table_referer )= with filter_clause = if clause = "" then "" else "&clause="+url_quote(clause), + with referer_arg = "&"+to_Web_arg(table_referer, ""), with js = js_inline(jquery_ready("$(\"#"+uid+"_grid\").jqGrid({\n"+ - "url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+filter_clause+"',"+ + "url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+filter_clause+referer_arg+"',"+ "datatype: \"json\","+ to_jqGrid_ColModel(db, table_referer, _T, rows.view_model.list)+","+ // rows.json_data_string+ @@ -253,28 +254,34 @@ public define HTML_Partial_Content VTM_view vtm_v, String view_name, String f_clause, //filter for current table - HK_Referer referer, + HK_Referer table_referer, String fk_clause //filter for foreign key of the table (one to many) ) = with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause), - with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause), + //with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause), + with referer_arg = "&"+to_Web_arg(table_referer, ""), + with current_view = vtm_v.get_view(view_name), with uid = generate_random_string(20)+"_", partial_content([ js(js_file("js/jscolor.min.js")) ]+jq_dialog_init + jq_datetimepicker_init(lang), [html_wave_box_wide(_T(to_upper(current_view.table_name)), sequence([ - partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+current_view.table_name+filter_clause+foreign_clause)))), + //create the dialog + partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+current_view.table_name+filter_clause+referer_arg)))), div([class("inline")], sequence([ + // (+) icon for adding new entry partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), + // view selector if there is more than one view name table_view_selector(_T, vtm_v, view_name), ])), - partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause, referer)) + //grid with data + partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause, table_referer)) //partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(500), true, true, true, lang, no_extra, web_site_directory)) ]))]). public define HTML_Partial_Content - list_view + table_in_list_view ( SQLite3DataBase db, (String) -> String _T, @@ -284,11 +291,12 @@ public define HTML_Partial_Content VTM_view vtm_v, String view_name, String f_clause, //filter for current table - HK_Referer referer, + HK_Referer table_referer, String fk_clause //filter for foreign key of the table (one to many) ) = with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause), with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause), + with referer_arg = "&"+to_Web_arg(table_referer, ""), with current_view = vtm_v.get_view(view_name), with uid = generate_random_string(20)+"_", partial_content([ js(js_file("js/jscolor.min.js")) @@ -296,10 +304,10 @@ public define HTML_Partial_Content jq_dialog_init + jq_datetimepicker_init(lang), [ - partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+current_view.table_name+filter_clause+foreign_clause)))), + partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+current_view.table_name+filter_clause+referer_arg)))), partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), //table_view_selector(_T, vtm_v, view_name), - partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause, referer)), + partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause, table_referer)), //partial(jquery_datatable(uid+"table_view", view_table_form(_T, uid, action_name, rows), true, false, jq_dt_pt_full_numbers, false, scrollY(200), true, true, true, lang, no_extra, web_site_directory)) ]). @@ -326,7 +334,7 @@ public define Maybe(HTML_Partial_Content) }. public define Maybe(HTML_Partial_Content) - view_table_only + table_in_list_view_only ( SQLite3DataBase db, (String) -> String _T, @@ -344,7 +352,7 @@ public define Maybe(HTML_Partial_Content) { failure then failure, success(vtm_v) then - success(view_table(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_filter)) + success(table_in_list_view(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_filter)) }. define CXM_Form_Field @@ -373,7 +381,6 @@ public define List(CXM_Form_Field) Bool new_entry, List(CXM_Form_Field) so_far )= - with empty_referer = hk_referer("","","",""), if list is { [] then reverse(so_far), @@ -410,7 +417,7 @@ public define List(CXM_Form_Field) foreign_text(s_name, c_name, value, select, help) then [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)], choices_text(s_name, c_name, value, select, help) then - [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, empty_referer, ""), success(init(value)), mandatory), help_line(help, _T)], + [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)], text_area(s_name, c_name, value, txt_editor, help) then with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"}, [text_area([],label(_T(s_name), no_help), html_Id(id), wan(c_name), init(not_null_String(value)), narrow, (Int)5, mandatory), help_line(help, _T)], @@ -421,7 +428,7 @@ public define List(CXM_Form_Field) float(s_name, c_name, value, help) then [input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)], choices_int(s_name, c_name, value, select, help) then - [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, empty_referer, ""), success(init(to_String(value))), mandatory), help_line(help, _T)], + [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(to_String(value))), mandatory), help_line(help, _T)], date(s_name, c_name, value, help) then [input([class("datepicker")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(value), small, non_mandatory), help_line(help, _T)], time(s_name, c_name, value, help) then @@ -461,7 +468,7 @@ define List(HTML_Head_Tag) . public define HTML_Partial_Content - edit_table_page + edit_table_form ( SQLite3DataBase db, (String) -> String _T, @@ -503,7 +510,7 @@ public define HTML_Partial_Content |-> since tab is hk_v_edit_tab(fk_table_name, fk_col_name, list_view_name), with referer = hk_referer(table_name, id, fk_table_name, fk_col_name), - if view_table_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is + if table_in_list_view_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is { failure then empty, success(p_content) then partial(p_content) @@ -533,7 +540,7 @@ public define Maybe(HTML_Partial_Content) failure then failure, success(vtm_e) then since vtm_e is vtm_edit(_, get_edit), - success(edit_table_page(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm, clause, fk_clause, referer)) + success(edit_table_form(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm, clause, fk_clause, referer)) }. diff --git a/view/view_table_types.anubis b/view/view_table_types.anubis index 07b0036..4a84841 100644 --- a/view/view_table_types.anubis +++ b/view/view_table_types.anubis @@ -86,7 +86,7 @@ public type VT_view_row: public type VT_View_DB_Calls: vt_view_db_calls( (SQLite3DataBase db, String clause) -> Int get_count, - (SQLite3DataBase db, String clause) -> JsonMember get_rows_json + (SQLite3DataBase db, HK_Referer referer, String clause) -> JsonMember get_rows_json // (SQLite3DataBase db, String clause) -> List(VT_view_row) get_rows ) . diff --git a/view/web_action.anubis b/view/web_action.anubis index 148ad46..b357a70 100644 --- a/view/web_action.anubis +++ b/view/web_action.anubis @@ -13,7 +13,7 @@ read calexium_lib/web/CXM_making_a_web_site.anubis public define WEB_Action_Name hkc_edit_table = controller_action("hk_c", "edit_table"). public define WEB_Action_Name hkc_grid_view = controller_action("hk_c", "grid_view"). public define WEB_Action_Name hkc_grid_action = controller_action("hk_c", "grid_action"). -public define WEB_Action_Name hkc_view_table = controller_action("hk_c", "view_table"). +public define WEB_Action_Name hkc_list_view = controller_action("hk_c", "view_table"). public define WEB_Action_Name hkc_save_row = controller_action("hk_c", "save_row"). public define WEB_Action_Name hkc_save_row_and_new = controller_action("hk_c", "save_row_and_new"). public define WEB_Action_Name hkc_update_row = controller_action("hk_c", "update_row"). -- libgit2 0.21.4