Commit 9ade2a47e122002e841a7da1514d9474b3182e34
1 parent
187c20bf
add no_referer as alternative in HK_Referer
begin to manage the referer
Showing
4 changed files
with
39 additions
and
25 deletions
Show diff stats
types/hayamiki.anubis
view/jqgrid.anubis
| ... | ... | @@ -24,9 +24,11 @@ define String |
| 24 | 24 | to_jqGrid_ColModel |
| 25 | 25 | ( |
| 26 | 26 | SQLite3DataBase db, |
| 27 | + HK_Referer table_referer, | |
| 27 | 28 | VT_view_model_entry model, |
| 28 | 29 | (String) -> String _T |
| 29 | 30 | )= |
| 31 | + with empty_referer = hk_referer("","","",""), | |
| 30 | 32 | if model is |
| 31 | 33 | { |
| 32 | 34 | primary_key then "{ name: \"id\", hidden:true }", |
| ... | ... | @@ -34,22 +36,22 @@ define String |
| 34 | 36 | text(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true }", |
| 35 | 37 | password(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\" }", |
| 36 | 38 | foreign_text(label,column_name,selector,help) then |
| 37 | - "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 39 | + "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db,table_referer,""))+"},"+ | |
| 38 | 40 | " formatter: \"select\","+ |
| 39 | - " formatoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 41 | + " formatoptions:{value: "+to_jqGrid_selector(selector.get(db, table_referer, ""))+"},"+ | |
| 40 | 42 | "}", |
| 41 | 43 | choices_text(label,column_name,selector,help) then |
| 42 | - "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 44 | + "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db, empty_referer, ""))+"},"+ | |
| 43 | 45 | " formatter: \"select\","+ |
| 44 | - " formatoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 46 | + " formatoptions:{value: "+to_jqGrid_selector(selector.get(db, empty_referer, ""))+"},"+ | |
| 45 | 47 | "}", |
| 46 | 48 | text_area(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\" }", |
| 47 | 49 | boolean(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, template: \"booleanCheckboxFa\" }", |
| 48 | 50 | integer(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, template: \"integer\" }", |
| 49 | 51 | float(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, template: \"number\" }", |
| 50 | - choices_int(label,column_name,selector,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 52 | + choices_int(label,column_name,selector,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db, empty_referer, ""))+"},"+ | |
| 51 | 53 | " formatter: \"select\","+ |
| 52 | - " formatoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 54 | + " formatoptions:{value: "+to_jqGrid_selector(selector.get(db, empty_referer, ""))+"},"+ | |
| 53 | 55 | "}", |
| 54 | 56 | date(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true, formatter: \"date\", formatoptions: { newformat: \"Y-M-d\" }}", |
| 55 | 57 | time(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+_T(label)+"\", editable:true }", |
| ... | ... | @@ -62,13 +64,14 @@ public define String |
| 62 | 64 | to_jqGrid_ColModel |
| 63 | 65 | ( |
| 64 | 66 | SQLite3DataBase db, |
| 67 | + HK_Referer table_referer, | |
| 65 | 68 | (String) -> String _T, |
| 66 | 69 | List(VT_view_model_entry) models |
| 67 | 70 | )= |
| 68 | 71 | "colModel: [\n"+ |
| 69 | 72 | join(",\n ", |
| 70 | 73 | [ "{name: 'myac', label: 'Action', width:65, fixed:true, sortable:false, resize:false, formatter:'actions', formatoptions:{keys:true}}" . |
| 71 | - map((VT_view_model_entry col_model) |-> to_jqGrid_ColModel(db, col_model, _T), models) | |
| 74 | + map((VT_view_model_entry col_model) |-> to_jqGrid_ColModel(db, table_referer, col_model, _T), models) | |
| 72 | 75 | ] |
| 73 | 76 | )+ |
| 74 | 77 | "]" | ... | ... |
view/view_table_renderer.anubis
| ... | ... | @@ -210,13 +210,14 @@ public define HTML_Partial_Content |
| 210 | 210 | VT_view rows, |
| 211 | 211 | (String) -> String _T, |
| 212 | 212 | String lang, |
| 213 | - String clause | |
| 213 | + String clause, | |
| 214 | + HK_Referer table_referer | |
| 214 | 215 | )= |
| 215 | 216 | with filter_clause = if clause = "" then "" else "&clause="+url_quote(clause), |
| 216 | 217 | with js = js_inline(jquery_ready("$(\"#"+uid+"_grid\").jqGrid({\n"+ |
| 217 | 218 | "url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+filter_clause+"',"+ |
| 218 | 219 | "datatype: \"json\","+ |
| 219 | - to_jqGrid_ColModel(db, _T, rows.view_model.list)+","+ | |
| 220 | + to_jqGrid_ColModel(db, table_referer, _T, rows.view_model.list)+","+ | |
| 220 | 221 | // rows.json_data_string+ |
| 221 | 222 | jqGrid_options(uid, rows, _T)+ |
| 222 | 223 | ",loadComplete: function () { |
| ... | ... | @@ -252,6 +253,7 @@ public define HTML_Partial_Content |
| 252 | 253 | VTM_view vtm_v, |
| 253 | 254 | String view_name, |
| 254 | 255 | String f_clause, //filter for current table |
| 256 | + HK_Referer referer, | |
| 255 | 257 | String fk_clause //filter for foreign key of the table (one to many) |
| 256 | 258 | ) = |
| 257 | 259 | with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause), |
| ... | ... | @@ -267,12 +269,12 @@ public define HTML_Partial_Content |
| 267 | 269 | partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), |
| 268 | 270 | table_view_selector(_T, vtm_v, view_name), |
| 269 | 271 | ])), |
| 270 | - partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause)) | |
| 272 | + partial(jqGrid_table(db, uid, current_view, _T, lang, f_clause, referer)) | |
| 271 | 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)) |
| 272 | 274 | ]))]). |
| 273 | 275 | |
| 274 | 276 | public define HTML_Partial_Content |
| 275 | - view_table | |
| 277 | + list_view | |
| 276 | 278 | ( |
| 277 | 279 | SQLite3DataBase db, |
| 278 | 280 | (String) -> String _T, |
| ... | ... | @@ -282,6 +284,7 @@ public define HTML_Partial_Content |
| 282 | 284 | VTM_view vtm_v, |
| 283 | 285 | String view_name, |
| 284 | 286 | String f_clause, //filter for current table |
| 287 | + HK_Referer referer, | |
| 285 | 288 | String fk_clause //filter for foreign key of the table (one to many) |
| 286 | 289 | ) = |
| 287 | 290 | with filter_clause = if f_clause = "" then "" else "&clause="+url_quote(f_clause), |
| ... | ... | @@ -296,7 +299,7 @@ public define HTML_Partial_Content |
| 296 | 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)))), |
| 297 | 300 | partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), |
| 298 | 301 | //table_view_selector(_T, vtm_v, view_name), |
| 299 | - partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause)), | |
| 302 | + partial(jqGrid_table(db, uid, current_view, _T, lang, fk_clause, referer)), | |
| 300 | 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)) |
| 301 | 304 | ]). |
| 302 | 305 | |
| ... | ... | @@ -311,6 +314,7 @@ public define Maybe(HTML_Partial_Content) |
| 311 | 314 | String view_name, |
| 312 | 315 | String action_name, |
| 313 | 316 | String f_clause, |
| 317 | + HK_Referer table_referer, | |
| 314 | 318 | String fk_clause, |
| 315 | 319 | VTM vtm |
| 316 | 320 | ) = |
| ... | ... | @@ -318,7 +322,7 @@ public define Maybe(HTML_Partial_Content) |
| 318 | 322 | { |
| 319 | 323 | failure then failure, |
| 320 | 324 | success(vtm_v) then |
| 321 | - success(view_table_page(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, fk_clause)) | |
| 325 | + success(view_table_page(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_clause)) | |
| 322 | 326 | }. |
| 323 | 327 | |
| 324 | 328 | public define Maybe(HTML_Partial_Content) |
| ... | ... | @@ -332,14 +336,15 @@ public define Maybe(HTML_Partial_Content) |
| 332 | 336 | String view_name, |
| 333 | 337 | String action_name, |
| 334 | 338 | String f_clause, |
| 335 | - String fk_clause, | |
| 339 | + HK_Referer table_referer, | |
| 340 | + String fk_filter, | |
| 336 | 341 | VTM vtm |
| 337 | 342 | ) = |
| 338 | 343 | if vtm_get_view(table, vtm.view_list) is |
| 339 | 344 | { |
| 340 | 345 | failure then failure, |
| 341 | 346 | success(vtm_v) then |
| 342 | - success(view_table(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, fk_clause)) | |
| 347 | + success(view_table(db, _T, lang, web_site_directory, action_name, vtm_v, view_name, f_clause, table_referer, fk_filter)) | |
| 343 | 348 | }. |
| 344 | 349 | |
| 345 | 350 | define CXM_Form_Field |
| ... | ... | @@ -362,11 +367,13 @@ public define List(CXM_Form_Field) |
| 362 | 367 | ( |
| 363 | 368 | SQLite3DataBase db, |
| 364 | 369 | String fk_clause, |
| 370 | + HK_Referer table_referer, | |
| 365 | 371 | (String) -> String _T, |
| 366 | 372 | List(VT_edit_entry) list, |
| 367 | 373 | Bool new_entry, |
| 368 | 374 | List(CXM_Form_Field) so_far |
| 369 | 375 | )= |
| 376 | + with empty_referer = hk_referer("","","",""), | |
| 370 | 377 | if list is |
| 371 | 378 | { |
| 372 | 379 | [] then reverse(so_far), |
| ... | ... | @@ -401,9 +408,9 @@ public define List(CXM_Form_Field) |
| 401 | 408 | ], |
| 402 | 409 | |
| 403 | 410 | foreign_text(s_name, c_name, value, select, help) then |
| 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)], | |
| 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)], | |
| 405 | 412 | choices_text(s_name, c_name, value, select, help) then |
| 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)], | |
| 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)], | |
| 407 | 414 | text_area(s_name, c_name, value, txt_editor, help) then |
| 408 | 415 | with id = if txt_editor is { none then "", rich_editor then c_name+"_editor"}, |
| 409 | 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)], |
| ... | ... | @@ -414,7 +421,7 @@ public define List(CXM_Form_Field) |
| 414 | 421 | float(s_name, c_name, value, help) then |
| 415 | 422 | [input(label(_T(s_name), no_help), wan(c_name), init(float_to_string(value, 5)), small, mandatory), help_line(help, _T)], |
| 416 | 423 | choices_int(s_name, c_name, value, select, help) then |
| 417 | - [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)], | |
| 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)], | |
| 418 | 425 | date(s_name, c_name, value, help) then |
| 419 | 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)], |
| 420 | 427 | time(s_name, c_name, value, help) then |
| ... | ... | @@ -424,7 +431,7 @@ public define List(CXM_Form_Field) |
| 424 | 431 | color( s_name, c_name, value, help) then |
| 425 | 432 | [input([class("jscolor")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)], |
| 426 | 433 | }, |
| 427 | - edit_form_lines(db, fk_clause, _T, t, new_entry, reverse(line)+so_far) | |
| 434 | + edit_form_lines(db, fk_clause, table_referer, _T, t, new_entry, reverse(line)+so_far) | |
| 428 | 435 | }. |
| 429 | 436 | |
| 430 | 437 | define HTML_Head_Tag |
| ... | ... | @@ -464,7 +471,8 @@ public define HTML_Partial_Content |
| 464 | 471 | VT_edit vt_elist, |
| 465 | 472 | VTM vtm, |
| 466 | 473 | String clause, |
| 467 | - String fk_clause | |
| 474 | + String fk_clause, | |
| 475 | + HK_Referer table_referer //from which table and row id that editor is called | |
| 468 | 476 | ) = |
| 469 | 477 | with table_name = vt_elist.table_name, |
| 470 | 478 | //true if need to create row or false for updating |
| ... | ... | @@ -480,7 +488,7 @@ public define HTML_Partial_Content |
| 480 | 488 | get_editor_header(vt_elist.list), //add editor header if need. Like init ck_editor |
| 481 | 489 | sequence([ |
| 482 | 490 | cxm_form( table_name, lwa, |
| 483 | - edit_form_lines(db, fk_clause, _T, vt_elist.list, create, [])+ | |
| 491 | + edit_form_lines(db, "", table_referer, _T, vt_elist.list, create, [])+ | |
| 484 | 492 | [ one_line_fields([ |
| 485 | 493 | submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]), |
| 486 | 494 | submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]), |
| ... | ... | @@ -494,7 +502,8 @@ public define HTML_Partial_Content |
| 494 | 502 | map( (HK_V_Edit_Tab tab) |
| 495 | 503 | |-> |
| 496 | 504 | since tab is hk_v_edit_tab(fk_table_name, fk_col_name, list_view_name), |
| 497 | - if view_table_only(db, _T, lang, web_site_directory, fk_table_name, list_view_name, "edit", "", fk_col_name+" = "+id, vtm) is | |
| 505 | + 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 | |
| 498 | 507 | { |
| 499 | 508 | failure then empty, |
| 500 | 509 | success(p_content) then partial(p_content) |
| ... | ... | @@ -516,14 +525,15 @@ public define Maybe(HTML_Partial_Content) |
| 516 | 525 | VT_action action, //new_entry or edit an existing record |
| 517 | 526 | VTM vtm, |
| 518 | 527 | String clause, |
| 519 | - String fk_clause | |
| 528 | + String fk_clause, | |
| 529 | + HK_Referer referer | |
| 520 | 530 | ) = |
| 521 | 531 | if vtm_get_edit(table, vtm.edit_list) is |
| 522 | 532 | { |
| 523 | 533 | failure then failure, |
| 524 | 534 | success(vtm_e) then |
| 525 | 535 | since vtm_e is vtm_edit(_, get_edit), |
| 526 | - success(edit_table_page(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm, clause, fk_clause)) | |
| 536 | + success(edit_table_page(db, _T, lang, web_site_directory, lwa, get_edit(db, action, view_name), vtm, clause, fk_clause, referer)) | |
| 527 | 537 | }. |
| 528 | 538 | |
| 529 | 539 | ... | ... |
view/view_table_types.anubis
| ... | ... | @@ -10,7 +10,7 @@ transmit calexium_lib/web/CXM_common.anubis |
| 10 | 10 | read hayamiki_lib/types/hayamiki.anubis |
| 11 | 11 | |
| 12 | 12 | public type VT_edit_selector: |
| 13 | - vt_edit_selector((SQLite3DataBase db, String clause) -> List((List(CoreAttrs), WebArgValue, String)) get). | |
| 13 | + vt_edit_selector((SQLite3DataBase db, HK_Referer referer, String filter) -> List((List(CoreAttrs), WebArgValue, String)) get). | |
| 14 | 14 | |
| 15 | 15 | |
| 16 | 16 | public type VT_edit_entry: | ... | ... |