Commit 187c20bf60effefc66d412cf4465f322e00bfa3f

Authored by totoro
1 parent 5f15d104

start to manage fk when creating edit table from (+) in list view. This means th…

…at the dialog filter the selector with that referer
Showing 2 changed files with 44 additions and 18 deletions   Show diff stats
types/hayamiki.anubis
@@ -10,3 +10,12 @@ @@ -10,3 +10,12 @@
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
  13 +
  14 +public type HK_Referer:
  15 + hk_referer(
  16 + String referer_table,
  17 + String referer_row_id,
  18 + String fk_table,
  19 + String fk_column
  20 + )
  21 +.
view/view_table_renderer.anubis
@@ -37,6 +37,10 @@ read calexium_lib/web/widgets/button.anubis @@ -37,6 +37,10 @@ read calexium_lib/web/widgets/button.anubis
37 read calexium_lib/web/CXM_urllib.anubis 37 read calexium_lib/web/CXM_urllib.anubis
38 38
39 define HTML_Off_Form 39 define HTML_Off_Form
  40 +/* create a selector for choosing the view name.
  41 + * The selector create an immediate action. This means when the entry is selected, the action is fired.
  42 + * If only one view exists, the selector is not created
  43 + */
40 table_view_selector 44 table_view_selector
41 ( 45 (
42 (String) -> String _T, //translator function 46 (String) -> String _T, //translator function
@@ -171,7 +175,7 @@ define String @@ -171,7 +175,7 @@ define String
171 autowidth:true, 175 autowidth:true,
172 shrinkToFit:true, 176 shrinkToFit:true,
173 rowNum:10, 177 rowNum:10,
174 - cellEdit: true, 178 + cellEdit: false,
175 cellsubmit: 'remote', 179 cellsubmit: 'remote',
176 cellurl: '?aws_controller=hk_c&aws_action=update_row&table_name="+rows.table_name+"', 180 cellurl: '?aws_controller=hk_c&aws_action=update_row&table_name="+rows.table_name+"',
177 pager: '#"+uid+"_pager', 181 pager: '#"+uid+"_pager',
@@ -247,20 +251,23 @@ public define HTML_Partial_Content @@ -247,20 +251,23 @@ public define HTML_Partial_Content
247 String action_name, 251 String action_name,
248 VTM_view vtm_v, 252 VTM_view vtm_v,
249 String view_name, 253 String view_name,
250 - String clause 254 + String f_clause, //filter for current table
  255 + String fk_clause //filter for foreign key of the table (one to many)
251 ) = 256 ) =
  257 + with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause),
  258 + with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause),
252 with current_view = vtm_v.get_view(view_name), 259 with current_view = vtm_v.get_view(view_name),
253 with uid = generate_random_string(20)+"_", 260 with uid = generate_random_string(20)+"_",
254 partial_content([ js(js_file("js/jscolor.min.js")) 261 partial_content([ js(js_file("js/jscolor.min.js"))
255 ]+jq_dialog_init + jq_datetimepicker_init(lang), 262 ]+jq_dialog_init + jq_datetimepicker_init(lang),
256 [html_wave_box_wide(_T(to_upper(current_view.table_name)), 263 [html_wave_box_wide(_T(to_upper(current_view.table_name)),
257 sequence([ 264 sequence([
258 - 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)))), 265 + 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)))),
259 div([class("inline")], sequence([ 266 div([class("inline")], sequence([
260 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), 267 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
261 table_view_selector(_T, vtm_v, view_name), 268 table_view_selector(_T, vtm_v, view_name),
262 ])), 269 ])),
263 - partial(jqGrid_table(db, uid, current_view, _T, lang, clause)) 270 + partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause))
264 //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)) 271 //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))
265 ]))]). 272 ]))]).
266 273
@@ -274,8 +281,11 @@ public define HTML_Partial_Content @@ -274,8 +281,11 @@ public define HTML_Partial_Content
274 String action_name, 281 String action_name,
275 VTM_view vtm_v, 282 VTM_view vtm_v,
276 String view_name, 283 String view_name,
277 - String clause 284 + String f_clause, //filter for current table
  285 + String fk_clause //filter for foreign key of the table (one to many)
278 ) = 286 ) =
  287 + with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause),
  288 + with foreign_clause = if fk_clause = "" then "" else "&fk_clause="+url_quote(fk_clause),
279 with current_view = vtm_v.get_view(view_name), 289 with current_view = vtm_v.get_view(view_name),
280 with uid = generate_random_string(20)+"_", 290 with uid = generate_random_string(20)+"_",
281 partial_content([ js(js_file("js/jscolor.min.js")) 291 partial_content([ js(js_file("js/jscolor.min.js"))
@@ -283,10 +293,10 @@ public define HTML_Partial_Content @@ -283,10 +293,10 @@ public define HTML_Partial_Content
283 jq_dialog_init + 293 jq_dialog_init +
284 jq_datetimepicker_init(lang), 294 jq_datetimepicker_init(lang),
285 [ 295 [
286 - 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)))), 296 + 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)))),
287 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), 297 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])),
288 //table_view_selector(_T, vtm_v, view_name), 298 //table_view_selector(_T, vtm_v, view_name),
289 - partial(jqGrid_table(db, uid, current_view, _T, lang, clause)), 299 + partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause)),
290 //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)) 300 //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))
291 ]). 301 ]).
292 302
@@ -300,14 +310,15 @@ public define Maybe(HTML_Partial_Content) @@ -300,14 +310,15 @@ public define Maybe(HTML_Partial_Content)
300 String table, 310 String table,
301 String view_name, 311 String view_name,
302 String action_name, 312 String action_name,
303 - String clause, 313 + String f_clause,
  314 + String fk_clause,
304 VTM vtm 315 VTM vtm
305 ) = 316 ) =
306 if vtm_get_view(table, vtm.view_list) is 317 if vtm_get_view(table, vtm.view_list) is
307 { 318 {
308 failure then failure, 319 failure then failure,
309 success(vtm_v) then 320 success(vtm_v) then
310 - success(view_table_page(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, clause)) 321 + success(view_table_page(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, fk_clause))
311 }. 322 }.
312 323
313 public define Maybe(HTML_Partial_Content) 324 public define Maybe(HTML_Partial_Content)
@@ -320,14 +331,15 @@ public define Maybe(HTML_Partial_Content) @@ -320,14 +331,15 @@ public define Maybe(HTML_Partial_Content)
320 String table, 331 String table,
321 String view_name, 332 String view_name,
322 String action_name, 333 String action_name,
323 - String clause, 334 + String f_clause,
  335 + String fk_clause,
324 VTM vtm 336 VTM vtm
325 ) = 337 ) =
326 if vtm_get_view(table, vtm.view_list) is 338 if vtm_get_view(table, vtm.view_list) is
327 { 339 {
328 failure then failure, 340 failure then failure,
329 success(vtm_v) then 341 success(vtm_v) then
330 - success(view_table(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, clause)) 342 + success(view_table(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, fk_clause))
331 }. 343 }.
332 344
333 define CXM_Form_Field 345 define CXM_Form_Field
@@ -349,6 +361,7 @@ public define List(CXM_Form_Field) @@ -349,6 +361,7 @@ public define List(CXM_Form_Field)
349 edit_form_lines 361 edit_form_lines
350 ( 362 (
351 SQLite3DataBase db, 363 SQLite3DataBase db,
  364 + String fk_clause,
352 (String) -> String _T, 365 (String) -> String _T,
353 List(VT_edit_entry) list, 366 List(VT_edit_entry) list,
354 Bool new_entry, 367 Bool new_entry,
@@ -388,7 +401,7 @@ public define List(CXM_Form_Field) @@ -388,7 +401,7 @@ public define List(CXM_Form_Field)
388 ], 401 ],
389 402
390 foreign_text(s_name, c_name, value, select, help) then 403 foreign_text(s_name, c_name, value, select, help) then
391 - [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, ""), success(init(to_String(value))), mandatory), help_line(help, _T)], 404 + [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, fk_clause), success(init(to_String(value))), mandatory), help_line(help, _T)],
392 choices_text(s_name, c_name, value, select, help) then 405 choices_text(s_name, c_name, value, select, help) then
393 [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, ""), success(init(value)), mandatory), help_line(help, _T)], 406 [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, ""), success(init(value)), mandatory), help_line(help, _T)],
394 text_area(s_name, c_name, value, txt_editor, help) then 407 text_area(s_name, c_name, value, txt_editor, help) then
@@ -411,7 +424,7 @@ public define List(CXM_Form_Field) @@ -411,7 +424,7 @@ public define List(CXM_Form_Field)
411 color( s_name, c_name, value, help) then 424 color( s_name, c_name, value, help) then
412 [input([class("jscolor")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)], 425 [input([class("jscolor")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
413 }, 426 },
414 - edit_form_lines(db, _T, t, new_entry, reverse(line)+so_far) 427 + edit_form_lines(db, fk_clause, _T, t, new_entry, reverse(line)+so_far)
415 }. 428 }.
416 429
417 define HTML_Head_Tag 430 define HTML_Head_Tag
@@ -449,7 +462,9 @@ public define HTML_Partial_Content @@ -449,7 +462,9 @@ public define HTML_Partial_Content
449 String web_site_directory, 462 String web_site_directory,
450 List(Web_arg) lwa, 463 List(Web_arg) lwa,
451 VT_edit vt_elist, 464 VT_edit vt_elist,
452 - VTM vtm 465 + VTM vtm,
  466 + String clause,
  467 + String fk_clause
453 ) = 468 ) =
454 with table_name = vt_elist.table_name, 469 with table_name = vt_elist.table_name,
455 //true if need to create row or false for updating 470 //true if need to create row or false for updating
@@ -465,7 +480,7 @@ public define HTML_Partial_Content @@ -465,7 +480,7 @@ public define HTML_Partial_Content
465 get_editor_header(vt_elist.list), //add editor header if need. Like init ck_editor 480 get_editor_header(vt_elist.list), //add editor header if need. Like init ck_editor
466 sequence([ 481 sequence([
467 cxm_form( table_name, lwa, 482 cxm_form( table_name, lwa,
468 - edit_form_lines(db, _T, vt_elist.list, create, [])+ 483 + edit_form_lines(db, fk_clause, _T, vt_elist.list, create, [])+
469 [ one_line_fields([ 484 [ one_line_fields([
470 submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]), 485 submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]),
471 submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]), 486 submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
@@ -479,7 +494,7 @@ public define HTML_Partial_Content @@ -479,7 +494,7 @@ public define HTML_Partial_Content
479 map( (HK_V_Edit_Tab tab) 494 map( (HK_V_Edit_Tab tab)
480 |-> 495 |->
481 since tab is hk_v_edit_tab(fk_table_name, fk_col_name, list_view_name), 496 since tab is hk_v_edit_tab(fk_table_name, fk_col_name, list_view_name),
482 - if view_table_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", fk_col_name+" = "+id, vtm) is 497 + if view_table_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", fk_col_name+" = "+id, vtm) is
483 { 498 {
484 failure then empty, 499 failure then empty,
485 success(p_content) then partial(p_content) 500 success(p_content) then partial(p_content)
@@ -499,14 +514,16 @@ public define Maybe(HTML_Partial_Content) @@ -499,14 +514,16 @@ public define Maybe(HTML_Partial_Content)
499 String table, //table name 514 String table, //table name
500 String view_name, //view name to use 515 String view_name, //view name to use
501 VT_action action, //new_entry or edit an existing record 516 VT_action action, //new_entry or edit an existing record
502 - VTM vtm 517 + VTM vtm,
  518 + String clause,
  519 + String fk_clause
503 ) = 520 ) =
504 if vtm_get_edit(table, vtm.edit_list) is 521 if vtm_get_edit(table, vtm.edit_list) is
505 { 522 {
506 failure then failure, 523 failure then failure,
507 success(vtm_e) then 524 success(vtm_e) then
508 since vtm_e is vtm_edit(_, get_edit), 525 since vtm_e is vtm_edit(_, get_edit),
509 - success(edit_table_page(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm)) 526 + success(edit_table_page(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm, clause, fk_clause))
510 }. 527 }.
511 528
512 529