Commit 187c20bf60effefc66d412cf4465f322e00bfa3f
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 | 10 | transmit hayamiki_lib/model/fields.anubis |
| 11 | 11 | transmit hayamiki_lib/model/database.anubis |
| 12 | 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 | 37 | read calexium_lib/web/CXM_urllib.anubis |
| 38 | 38 | |
| 39 | 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 | 44 | table_view_selector |
| 41 | 45 | ( |
| 42 | 46 | (String) -> String _T, //translator function |
| ... | ... | @@ -171,7 +175,7 @@ define String |
| 171 | 175 | autowidth:true, |
| 172 | 176 | shrinkToFit:true, |
| 173 | 177 | rowNum:10, |
| 174 | - cellEdit: true, | |
| 178 | + cellEdit: false, | |
| 175 | 179 | cellsubmit: 'remote', |
| 176 | 180 | cellurl: '?aws_controller=hk_c&aws_action=update_row&table_name="+rows.table_name+"', |
| 177 | 181 | pager: '#"+uid+"_pager', |
| ... | ... | @@ -247,20 +251,23 @@ public define HTML_Partial_Content |
| 247 | 251 | String action_name, |
| 248 | 252 | VTM_view vtm_v, |
| 249 | 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 | 259 | with current_view = vtm_v.get_view(view_name), |
| 253 | 260 | with uid = generate_random_string(20)+"_", |
| 254 | 261 | partial_content([ js(js_file("js/jscolor.min.js")) |
| 255 | 262 | ]+jq_dialog_init + jq_datetimepicker_init(lang), |
| 256 | 263 | [html_wave_box_wide(_T(to_upper(current_view.table_name)), |
| 257 | 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 | 266 | div([class("inline")], sequence([ |
| 260 | 267 | partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), |
| 261 | 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 | 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 | 281 | String action_name, |
| 275 | 282 | VTM_view vtm_v, |
| 276 | 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 | 289 | with current_view = vtm_v.get_view(view_name), |
| 280 | 290 | with uid = generate_random_string(20)+"_", |
| 281 | 291 | partial_content([ js(js_file("js/jscolor.min.js")) |
| ... | ... | @@ -283,10 +293,10 @@ public define HTML_Partial_Content |
| 283 | 293 | jq_dialog_init + |
| 284 | 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 | 297 | partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), |
| 288 | 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 | 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 | 310 | String table, |
| 301 | 311 | String view_name, |
| 302 | 312 | String action_name, |
| 303 | - String clause, | |
| 313 | + String f_clause, | |
| 314 | + String fk_clause, | |
| 304 | 315 | VTM vtm |
| 305 | 316 | ) = |
| 306 | 317 | if vtm_get_view(table, vtm.view_list) is |
| 307 | 318 | { |
| 308 | 319 | failure then failure, |
| 309 | 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 | 324 | public define Maybe(HTML_Partial_Content) |
| ... | ... | @@ -320,14 +331,15 @@ public define Maybe(HTML_Partial_Content) |
| 320 | 331 | String table, |
| 321 | 332 | String view_name, |
| 322 | 333 | String action_name, |
| 323 | - String clause, | |
| 334 | + String f_clause, | |
| 335 | + String fk_clause, | |
| 324 | 336 | VTM vtm |
| 325 | 337 | ) = |
| 326 | 338 | if vtm_get_view(table, vtm.view_list) is |
| 327 | 339 | { |
| 328 | 340 | failure then failure, |
| 329 | 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 | 345 | define CXM_Form_Field |
| ... | ... | @@ -349,6 +361,7 @@ public define List(CXM_Form_Field) |
| 349 | 361 | edit_form_lines |
| 350 | 362 | ( |
| 351 | 363 | SQLite3DataBase db, |
| 364 | + String fk_clause, | |
| 352 | 365 | (String) -> String _T, |
| 353 | 366 | List(VT_edit_entry) list, |
| 354 | 367 | Bool new_entry, |
| ... | ... | @@ -388,7 +401,7 @@ public define List(CXM_Form_Field) |
| 388 | 401 | ], |
| 389 | 402 | |
| 390 | 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 | 405 | choices_text(s_name, c_name, value, select, help) then |
| 393 | 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 | 407 | text_area(s_name, c_name, value, txt_editor, help) then |
| ... | ... | @@ -411,7 +424,7 @@ public define List(CXM_Form_Field) |
| 411 | 424 | color( s_name, c_name, value, help) then |
| 412 | 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 | 430 | define HTML_Head_Tag |
| ... | ... | @@ -449,7 +462,9 @@ public define HTML_Partial_Content |
| 449 | 462 | String web_site_directory, |
| 450 | 463 | List(Web_arg) lwa, |
| 451 | 464 | VT_edit vt_elist, |
| 452 | - VTM vtm | |
| 465 | + VTM vtm, | |
| 466 | + String clause, | |
| 467 | + String fk_clause | |
| 453 | 468 | ) = |
| 454 | 469 | with table_name = vt_elist.table_name, |
| 455 | 470 | //true if need to create row or false for updating |
| ... | ... | @@ -465,7 +480,7 @@ public define HTML_Partial_Content |
| 465 | 480 | get_editor_header(vt_elist.list), //add editor header if need. Like init ck_editor |
| 466 | 481 | sequence([ |
| 467 | 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 | 484 | [ one_line_fields([ |
| 470 | 485 | submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]), |
| 471 | 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 | 494 | map( (HK_V_Edit_Tab tab) |
| 480 | 495 | |-> |
| 481 | 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 | 499 | failure then empty, |
| 485 | 500 | success(p_content) then partial(p_content) |
| ... | ... | @@ -499,14 +514,16 @@ public define Maybe(HTML_Partial_Content) |
| 499 | 514 | String table, //table name |
| 500 | 515 | String view_name, //view name to use |
| 501 | 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 | 521 | if vtm_get_edit(table, vtm.edit_list) is |
| 505 | 522 | { |
| 506 | 523 | failure then failure, |
| 507 | 524 | success(vtm_e) then |
| 508 | 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 | ... | ... |