Commit 0f7b58068c85516089781d793834fedae66c743f

Authored by totoro
1 parent 9ade2a47

get and set HK_Referer for Web arg functions

Add argument HK_Referer in get_rows_json
rename web action view_table in list_view
controller/hk_sql_utils.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 02/04/2017
  5 + * Time: 19:23
  6 + * © Calexium
  7 + */
  8 +
  9 +read hayamiki_lib/types/hayamiki.anubis
  10 +
  11 +public define String
  12 + referer_to_sql_clause
  13 + (
  14 + HK_Referer referer,
  15 + String table_name,
  16 + List(String) table_columns
  17 + )=
  18 + if referer is
  19 + {
  20 + no_referer then "",
  21 + hk_referer(referer_table, referer_row_id, fk_table, fk_column) then
  22 + if referer_table = table_name then
  23 + "id = " +referer_row_id
  24 + else if fk_column:table_columns then
  25 + fk_column + " = " + referer_row_id
  26 + else
  27 + "",
  28 + }
  29 +.
types/hayamiki.anubis
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 * © Calexium 6 * © Calexium
7 */ 7 */
8 8
9 - 9 +read calexium_lib/web/CXM_web_arg_utils.anubis
10 transmit hayamiki_lib/model/fields.anubis 10 transmit hayamiki_lib/model/fields.anubis
11 transmit hayamiki_lib/model/database.anubis 11 transmit hayamiki_lib/model/database.anubis
12 transmit hayamiki_lib/model/columns.anubis 12 transmit hayamiki_lib/model/columns.anubis
@@ -20,3 +20,43 @@ public type HK_Referer: @@ -20,3 +20,43 @@ public type HK_Referer:
20 String fk_column 20 String fk_column
21 ) 21 )
22 . 22 .
  23 +
  24 +public define HK_Referer
  25 + get_HK_Referer_from_web_arg
  26 + (
  27 + List(Web_arg) lwa,
  28 + String __prefix__
  29 + )=
  30 + if get_Bool(lwa, __prefix__+"hk_referer") then
  31 + if get_String(lwa, __prefix__+"referer_table") is { failure then no_referer, success(referer_table) then
  32 + if get_String(lwa, __prefix__+"referer_row_id") is { failure then no_referer, success(referer_row_id) then
  33 + if get_String(lwa, __prefix__+"fk_table") is { failure then no_referer, success(fk_table) then
  34 + if get_String(lwa, __prefix__+"fk_column") is { failure then no_referer, success(fk_column) then
  35 + hk_referer(
  36 + referer_table,
  37 + referer_row_id,
  38 + fk_table,
  39 + fk_column
  40 + )
  41 + }}}}
  42 + else
  43 + no_referer
  44 +.
  45 +
  46 +public define String
  47 + to_Web_arg
  48 + (
  49 + HK_Referer referer,
  50 + String __prefix__
  51 + )=
  52 + if referer is
  53 + {
  54 + no_referer then __prefix__+"hk_referer=false",
  55 + hk_referer(referer_table, referer_row_id, fk_table, fk_column) then
  56 + __prefix__+"hk_referer=true&"+
  57 + __prefix__+"referer_table="+referer_table+"&"+
  58 + __prefix__+"referer_row_id="+referer_row_id+"&"+
  59 + __prefix__+"fk_table="+ fk_table+"&"+
  60 + __prefix__+"fk_column="+ fk_column
  61 + }
  62 +.
view/view_apps_renderer.anubis
@@ -34,7 +34,7 @@ define List(HTML_Row(HTML_Off_Form)) @@ -34,7 +34,7 @@ define List(HTML_Row(HTML_Off_Form))
34 cell( 34 cell(
35 sequence([ 35 sequence([
36 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id("edit_table_dlg_ajax"), "'table_name="+table_name+"'"))], "", [])), 36 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id("edit_table_dlg_ajax"), "'table_name="+table_name+"'"))], "", [])),
37 - partial(img_button(icn16_view_list, hkc_view_table, [("table_name",table_name)])) 37 + partial(img_button(icn16_view_list, hkc_list_view, [("table_name",table_name)]))
38 ]) 38 ])
39 ) 39 )
40 ]) 40 ])
view/view_table_renderer.anubis
@@ -59,7 +59,7 @@ define HTML_Off_Form @@ -59,7 +59,7 @@ define HTML_Off_Form
59 success(init(current_view)), 59 success(init(current_view)),
60 "" 60 ""
61 ), 61 ),
62 - hkc_view_table, 62 + hkc_list_view,
63 [("table_name", vtm_v.table_name)], [])) 63 [("table_name", vtm_v.table_name)], []))
64 . 64 .
65 65
@@ -214,8 +214,9 @@ public define HTML_Partial_Content @@ -214,8 +214,9 @@ public define HTML_Partial_Content
214 HK_Referer table_referer 214 HK_Referer table_referer
215 )= 215 )=
216 with filter_clause = if clause = "" then "" else "&clause="+url_quote(clause), 216 with filter_clause = if clause = "" then "" else "&clause="+url_quote(clause),
  217 + with referer_arg = "&"+to_Web_arg(table_referer, ""),
217 with js = js_inline(jquery_ready("$(\"#"+uid+"_grid\").jqGrid({\n"+ 218 with js = js_inline(jquery_ready("$(\"#"+uid+"_grid\").jqGrid({\n"+
218 - "url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+filter_clause+"',"+ 219 + "url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+filter_clause+referer_arg+"',"+
219 "datatype: \"json\","+ 220 "datatype: \"json\","+
220 to_jqGrid_ColModel(db, table_referer, _T, rows.view_model.list)+","+ 221 to_jqGrid_ColModel(db, table_referer, _T, rows.view_model.list)+","+
221 // rows.json_data_string+ 222 // rows.json_data_string+
@@ -253,28 +254,34 @@ public define HTML_Partial_Content @@ -253,28 +254,34 @@ public define HTML_Partial_Content
253 VTM_view vtm_v, 254 VTM_view vtm_v,
254 String view_name, 255 String view_name,
255 String f_clause, //filter for current table 256 String f_clause, //filter for current table
256 - HK_Referer referer, 257 + HK_Referer table_referer,
257 String fk_clause //filter for foreign key of the table (one to many) 258 String fk_clause //filter for foreign key of the table (one to many)
258 ) = 259 ) =
259 with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause), 260 with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause),
260 - with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause), 261 + //with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause),
  262 + with referer_arg = "&"+to_Web_arg(table_referer, ""),
  263 +
261 with current_view = vtm_v.get_view(view_name), 264 with current_view = vtm_v.get_view(view_name),
262 with uid = generate_random_string(20)+"_", 265 with uid = generate_random_string(20)+"_",
263 partial_content([ js(js_file("js/jscolor.min.js")) 266 partial_content([ js(js_file("js/jscolor.min.js"))
264 ]+jq_dialog_init + jq_datetimepicker_init(lang), 267 ]+jq_dialog_init + jq_datetimepicker_init(lang),
265 [html_wave_box_wide(_T(to_upper(current_view.table_name)), 268 [html_wave_box_wide(_T(to_upper(current_view.table_name)),
266 sequence([ 269 sequence([
267 - 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)))), 270 + //create the dialog
  271 + 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)))),
268 div([class("inline")], sequence([ 272 div([class("inline")], sequence([
  273 + // (+) icon for adding new entry
269 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), 274 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
  275 + // view selector if there is more than one view name
270 table_view_selector(_T, vtm_v, view_name), 276 table_view_selector(_T, vtm_v, view_name),
271 ])), 277 ])),
272 - partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause, referer)) 278 + //grid with data
  279 + partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause, table_referer))
273 //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)) 280 //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))
274 ]))]). 281 ]))]).
275 282
276 public define HTML_Partial_Content 283 public define HTML_Partial_Content
277 - list_view 284 + table_in_list_view
278 ( 285 (
279 SQLite3DataBase db, 286 SQLite3DataBase db,
280 (String) -> String _T, 287 (String) -> String _T,
@@ -284,11 +291,12 @@ public define HTML_Partial_Content @@ -284,11 +291,12 @@ public define HTML_Partial_Content
284 VTM_view vtm_v, 291 VTM_view vtm_v,
285 String view_name, 292 String view_name,
286 String f_clause, //filter for current table 293 String f_clause, //filter for current table
287 - HK_Referer referer, 294 + HK_Referer table_referer,
288 String fk_clause //filter for foreign key of the table (one to many) 295 String fk_clause //filter for foreign key of the table (one to many)
289 ) = 296 ) =
290 with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause), 297 with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause),
291 with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause), 298 with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause),
  299 + with referer_arg = "&"+to_Web_arg(table_referer, ""),
292 with current_view = vtm_v.get_view(view_name), 300 with current_view = vtm_v.get_view(view_name),
293 with uid = generate_random_string(20)+"_", 301 with uid = generate_random_string(20)+"_",
294 partial_content([ js(js_file("js/jscolor.min.js")) 302 partial_content([ js(js_file("js/jscolor.min.js"))
@@ -296,10 +304,10 @@ public define HTML_Partial_Content @@ -296,10 +304,10 @@ public define HTML_Partial_Content
296 jq_dialog_init + 304 jq_dialog_init +
297 jq_datetimepicker_init(lang), 305 jq_datetimepicker_init(lang),
298 [ 306 [
299 - 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)))), 307 + 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)))),
300 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), 308 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
301 //table_view_selector(_T, vtm_v, view_name), 309 //table_view_selector(_T, vtm_v, view_name),
302 - partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause, referer)), 310 + partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause, table_referer)),
303 //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)) 311 //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))
304 ]). 312 ]).
305 313
@@ -326,7 +334,7 @@ public define Maybe(HTML_Partial_Content) @@ -326,7 +334,7 @@ public define Maybe(HTML_Partial_Content)
326 }. 334 }.
327 335
328 public define Maybe(HTML_Partial_Content) 336 public define Maybe(HTML_Partial_Content)
329 - view_table_only 337 + table_in_list_view_only
330 ( 338 (
331 SQLite3DataBase db, 339 SQLite3DataBase db,
332 (String) -> String _T, 340 (String) -> String _T,
@@ -344,7 +352,7 @@ public define Maybe(HTML_Partial_Content) @@ -344,7 +352,7 @@ public define Maybe(HTML_Partial_Content)
344 { 352 {
345 failure then failure, 353 failure then failure,
346 success(vtm_v) then 354 success(vtm_v) then
347 - success(view_table(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_filter)) 355 + success(table_in_list_view(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_filter))
348 }. 356 }.
349 357
350 define CXM_Form_Field 358 define CXM_Form_Field
@@ -373,7 +381,6 @@ public define List(CXM_Form_Field) @@ -373,7 +381,6 @@ public define List(CXM_Form_Field)
373 Bool new_entry, 381 Bool new_entry,
374 List(CXM_Form_Field) so_far 382 List(CXM_Form_Field) so_far
375 )= 383 )=
376 - with empty_referer = hk_referer("","","",""),  
377 if list is 384 if list is
378 { 385 {
379 [] then reverse(so_far), 386 [] then reverse(so_far),
@@ -410,7 +417,7 @@ public define List(CXM_Form_Field) @@ -410,7 +417,7 @@ public define List(CXM_Form_Field)
410 foreign_text(s_name, c_name, value, select, help) then 417 foreign_text(s_name, c_name, value, select, help) then
411 [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)], 418 [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)],
412 choices_text(s_name, c_name, value, select, help) then 419 choices_text(s_name, c_name, value, select, help) then
413 - [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)], 420 + [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)],
414 text_area(s_name, c_name, value, txt_editor, help) then 421 text_area(s_name, c_name, value, txt_editor, help) then
415 with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"}, 422 with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"},
416 [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)], 423 [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) @@ -421,7 +428,7 @@ public define List(CXM_Form_Field)
421 float(s_name, c_name, value, help) then 428 float(s_name, c_name, value, help) then
422 [input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)], 429 [input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)],
423 choices_int(s_name, c_name, value, select, help) then 430 choices_int(s_name, c_name, value, select, help) then
424 - [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)], 431 + [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)],
425 date(s_name, c_name, value, help) then 432 date(s_name, c_name, value, help) then
426 [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)], 433 [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)],
427 time(s_name, c_name, value, help) then 434 time(s_name, c_name, value, help) then
@@ -461,7 +468,7 @@ define List(HTML_Head_Tag) @@ -461,7 +468,7 @@ define List(HTML_Head_Tag)
461 . 468 .
462 469
463 public define HTML_Partial_Content 470 public define HTML_Partial_Content
464 - edit_table_page 471 + edit_table_form
465 ( 472 (
466 SQLite3DataBase db, 473 SQLite3DataBase db,
467 (String) -> String _T, 474 (String) -> String _T,
@@ -503,7 +510,7 @@ public define HTML_Partial_Content @@ -503,7 +510,7 @@ public define HTML_Partial_Content
503 |-> 510 |->
504 since tab is hk_v_edit_tab(fk_table_name, fk_col_name, list_view_name), 511 since tab is hk_v_edit_tab(fk_table_name, fk_col_name, list_view_name),
505 with referer = hk_referer(table_name, id, fk_table_name, fk_col_name), 512 with referer = hk_referer(table_name, id, fk_table_name, fk_col_name),
506 - if view_table_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is 513 + if table_in_list_view_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", referer, fk_clause, vtm) is
507 { 514 {
508 failure then empty, 515 failure then empty,
509 success(p_content) then partial(p_content) 516 success(p_content) then partial(p_content)
@@ -533,7 +540,7 @@ public define Maybe(HTML_Partial_Content) @@ -533,7 +540,7 @@ public define Maybe(HTML_Partial_Content)
533 failure then failure, 540 failure then failure,
534 success(vtm_e) then 541 success(vtm_e) then
535 since vtm_e is vtm_edit(_, get_edit), 542 since vtm_e is vtm_edit(_, get_edit),
536 - success(edit_table_page(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm, clause, fk_clause, referer)) 543 + success(edit_table_form(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm, clause, fk_clause, referer))
537 }. 544 }.
538 545
539 546
view/view_table_types.anubis
@@ -86,7 +86,7 @@ public type VT_view_row: @@ -86,7 +86,7 @@ public type VT_view_row:
86 public type VT_View_DB_Calls: 86 public type VT_View_DB_Calls:
87 vt_view_db_calls( 87 vt_view_db_calls(
88 (SQLite3DataBase db, String clause) -> Int get_count, 88 (SQLite3DataBase db, String clause) -> Int get_count,
89 - (SQLite3DataBase db, String clause) -> JsonMember get_rows_json 89 + (SQLite3DataBase db, HK_Referer referer, String clause) -> JsonMember get_rows_json
90 // (SQLite3DataBase db, String clause) -> List(VT_view_row) get_rows 90 // (SQLite3DataBase db, String clause) -> List(VT_view_row) get_rows
91 ) 91 )
92 . 92 .
view/web_action.anubis
@@ -13,7 +13,7 @@ read calexium_lib/web/CXM_making_a_web_site.anubis @@ -13,7 +13,7 @@ read calexium_lib/web/CXM_making_a_web_site.anubis
13 public define WEB_Action_Name hkc_edit_table = controller_action("hk_c", "edit_table"). 13 public define WEB_Action_Name hkc_edit_table = controller_action("hk_c", "edit_table").
14 public define WEB_Action_Name hkc_grid_view = controller_action("hk_c", "grid_view"). 14 public define WEB_Action_Name hkc_grid_view = controller_action("hk_c", "grid_view").
15 public define WEB_Action_Name hkc_grid_action = controller_action("hk_c", "grid_action"). 15 public define WEB_Action_Name hkc_grid_action = controller_action("hk_c", "grid_action").
16 -public define WEB_Action_Name hkc_view_table = controller_action("hk_c", "view_table"). 16 +public define WEB_Action_Name hkc_list_view = controller_action("hk_c", "view_table").
17 public define WEB_Action_Name hkc_save_row = controller_action("hk_c", "save_row"). 17 public define WEB_Action_Name hkc_save_row = controller_action("hk_c", "save_row").
18 public define WEB_Action_Name hkc_save_row_and_new = controller_action("hk_c", "save_row_and_new"). 18 public define WEB_Action_Name hkc_save_row_and_new = controller_action("hk_c", "save_row_and_new").
19 public define WEB_Action_Name hkc_update_row = controller_action("hk_c", "update_row"). 19 public define WEB_Action_Name hkc_update_row = controller_action("hk_c", "update_row").