diff --git a/database/vtm/view_table_manager.anubis b/database/vtm/view_table_manager.anubis new file mode 100644 index 0000000..baf7aa8 --- /dev/null +++ b/database/vtm/view_table_manager.anubis @@ -0,0 +1,86 @@ +/* + * Created by PyramIDE. + * User: Totoro + * Date: 16/11/2011 + * Time: 23:53 + */ + +read tools/basis.anubis +read calexium_lib/database/vtm/view_table_types.anubis +read calexium_lib/database/vtm/view_table_manager_types.anubis + +public define Maybe(VTM_view) + _vtm_get_view + ( + String table_name, + List(VTM_view) list + ) = + if list is + { + [] then println("_vtm_get_view "+table_name+" not found"); failure, + [ h . t ] then + if h is vtm_view(tb_name, get_view) then + if tb_name = table_name then + success(h) + else + _vtm_get_view(table_name, t) + }. + +public define Maybe(VTM_view) + vtm_get_view + ( + String table_name, + VTM_view_list vtm_vlist + ) = + _vtm_get_view(table_name, vtm_vlist.list). + + +public define Maybe(VTM_edit) + _vtm_get_edit + ( + String table_name, + List(VTM_edit) list + ) = + if list is + { + [] then failure, + [ h . t ] then + if h is vtm_edit(tb_name, get_edit) then + if tb_name = table_name then + success(h) + else + _vtm_get_edit(table_name, t) + }. + +public define Maybe(VTM_edit) + vtm_get_edit + ( + String table_name, + VTM_edit_list vtm_vlist + ) = + _vtm_get_edit(table_name, vtm_vlist.list). + +public define Maybe(TM_writer) + _tm_get_writer + ( + String table_name, + List(TM_writer) list + ) = + if list is + { + [] then failure, + [ h . t ] then + if h is tm_writer(tb_name, get_writer) then + if tb_name = table_name then + success(h) + else + _tm_get_writer(table_name, t) + }. + +public define Maybe(TM_writer) + tm_get_writer + ( + String table_name, + TM_writer_list tm_wlist + ) = + _tm_get_writer(table_name, tm_wlist.list). diff --git a/database/vtm/view_table_manager_types.anubis b/database/vtm/view_table_manager_types.anubis new file mode 100644 index 0000000..ef05133 --- /dev/null +++ b/database/vtm/view_table_manager_types.anubis @@ -0,0 +1,32 @@ +/* + * Created by PyramIDE. + * User: Totoro + * Date: 17/11/2011 + * Time: 00:32 + * + */ + +read calexium_lib/database/vtm/view_table_types.anubis +read calexium_lib/web/CXM_common.anubis + +public type VTM_edit: + vtm_edit(String table_name, (SQLite3DataBase db, VT_action action) -> VT_edit get_edit). + +public type VTM_edit_list: + vtm_edit_list(List(VTM_edit) list). + +public type TM_writer: + tm_writer(String table_name, (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write). + +public type TM_writer_list: + tm_writer_list(List(TM_writer) list). + + +public type VTM_view: + vtm_view(String table_name, (SQLite3DataBase db) -> VT_view get_view). + +public type VTM_view_list: + vtm_view_list(List(VTM_view) list). + +public type VTM: + vtm(VTM_view_list view_list, VTM_edit_list edit_list, TM_writer_list writer_list). diff --git a/database/vtm/view_table_renderer.anubis b/database/vtm/view_table_renderer.anubis new file mode 100644 index 0000000..dae67a9 --- /dev/null +++ b/database/vtm/view_table_renderer.anubis @@ -0,0 +1,223 @@ +/* + * Created by PyramIDE. + * User: Totoro + * Date: 30/11/2011 + * Time: 21:22 + * + */ + +read calexium_lib/database/vtm/view_table_types.anubis +read calexium_lib/database/vtm/view_table_manager_types.anubis +read calexium_lib/database/vtm/view_table_manager.anubis + +read system/string.anubis +read locale/L3.anubis +read tools/basis.anubis + +read system_colors/rgb.anubis +read system/convert.anubis + +//read utils.anubis +read locale/L3LanguageInfo.anubis +read calexium_lib/web/CXM_common.anubis +read calexium_lib/web/CXM_making_a_web_site.anubis +read calexium_lib/web/CXM_multihost_http_server.anubis +read calexium_lib/web/jQuery/CXM_jquery_datatable.anubis +read calexium_lib/web/jQuery/CXM_jquery_datatable_types.anubis +read calexium_lib/web/jQuery/ui-addon/datetimepicker.anubis +read calexium_lib/web/CXM_form.anubis +read calexium_lib/web/widgets/css_helper.anubis + + + //Edit table part +public define List(CXM_Form_Field) + edit_form_lines + ( + SQLite3DataBase db, + (String) -> String _T, + List(VT_edit_entry) list, + List(CXM_Form_Field) so_far + )= + if list is + { + [] then reverse(so_far), + [ h . t] then + with line = + if h is + { + hidden(name, value) then + print("hidden "+name+" = "+value); + hidden(htmlId(""), wan(name), init(value)), + primary_key(idx) then + hidden(htmlId(""), wan("id"), init(idx)), + information(s_name, c_name, value) then + input_readonly(_T(s_name), wan(c_name), init(value), narrow), + text(s_name, c_name, value) then + input(_T(s_name), wan(c_name), init(value), narrow, mandatory), + foreign_text(s_name, c_name, value, select) then + selector_c([],_T(s_name), htmlId(""), wan(c_name), 1, select.get(db), success(init(to_String(value))), mandatory), + text_area(s_name, c_name, value) then + text_area([],_T(s_name), htmlId(""), wan(c_name), init(value), narrow, (Int)5, mandatory), + boolean(s_name, c_name, value) then + checkboxr([],_T(s_name), htmlId(""), wan(c_name), wav(c_name),value, mandatory), + integer(s_name, c_name, value) then + input(_T(s_name), wan(c_name), init(abs_to_decimal(value)), small, mandatory) + date(s_name, c_name, value) then + input([class("datepicker")], _T(s_name), htmlId(c_name), wan(c_name), init(value), narrow, non_mandatory), + datetime(s_name, c_name, value) then + input([class("datetimepicker")], _T(s_name), htmlId(c_name), wan(c_name), init(value), narrow, mandatory), + }, + edit_form_lines(db, _T, t, [line . so_far]) + }. + +public define HTML_Partial_Content + edit_table_page + ( + SQLite3DataBase db, + (String) -> String _T, + String lang, + VT_edit vt_elist + ) = + //if tb is tool_box(lang, _T, _, _, db, _) then + with table_name = vt_elist.table_name, + partial_content(jq_datetimepicker_init(lang), + partial(html_wave_box( + _T(to_upper(table_name)), + cxm_form( table_name, htmlId(table_name), + edit_form_lines(db, _T, vt_elist.list, [])+ + [ submit("create", failure, _T("CREATE"), [("table_name", table_name)]) ] + )))). + +public define Maybe(HTML_Partial_Content) + edit_table_content + ( + SQLite3DataBase db, + (String) -> String _T, + String lang, + String table, + VT_action action, + VTM vtm + ) = + if vtm_get_edit(table, vtm.edit_list) is + { + failure then failure, + success(vtm_e) then + since vtm_e is vtm_edit(_, get_edit), + success(edit_table_page(db, _T, lang, get_edit(db, action))) + }. + + + // View table part +define HTML_Row(HTML_Off_Form) make_line + ( + //ToolBox tb, + String table_name, + String action_name, //default is "edit_table", but can be surcharged for own use + List(VT_view_entry) entries, + List(HTML_Cell(HTML_Off_Form)) so_far, + Int odd_even + )= + if entries is + { + [] then + with line = if odd_even = 0 then "tr_even" else "tr_odd", + row( [core_attrs([class(line)])], reverse(so_far)), + [h . t] then + with cell = if h is + { + text(string) then cell((HTML_Off_Form)text(string)), + link(id, string) then cell((HTML_Off_Form)actioner(same,same, link(string), action_name, [("table_name", table_name),("id",id)])) + }, + make_line(table_name, action_name, t, [cell . so_far], odd_even) + }. + +define List(HTML_Row(HTML_Off_Form)) make_lines + ( +// ToolBox tb, + String table_name, + String action_name, + List(VT_view_row) entries, + List(HTML_Row(HTML_Off_Form)) so_far, + Int odd_even + )= + if entries is + { + [] then reverse(so_far), + [h . t] then make_lines(table_name, action_name, t, [make_line(table_name, action_name, h.list, [], odd_even). so_far], 1 - odd_even ) + }. + + // View table part +define HTML_Header_Row(HTML_Off_Form) + make_header + ( + (String) -> String _T, //translator + List(VT_view_entry) entries, + List(HTML_Header_Cell(HTML_Off_Form)) so_far + )= + //if tb is tool_box(lang, _T, _, _, db, _) then + if entries is + { + [] then header_row( [], reverse(so_far)), + [h . t] then + with cell = if h is + { + text(string) then header_cell((HTML_Off_Form)text(_T(string))), + link(id, string) then header_cell((HTML_Off_Form)actioner(same,same, link(string),"edit_table",[])) //TODO + }, + make_header(_T, t, [cell . so_far]) + }. + + +public define HTML_Partial_Content view_table_form + ( + (String) -> String _T, + String action_name, + VT_view rows + )= + //if tb is tool_box(_, _T, _, _, db, _) then + partial_content(div( [class("tableau")], + sequence( + [ actioner(same,same, link([class("my_button")],_T("NEW")),"edit_table",[("table_name", rows.table_name)]), + table([core_attrs([id("table_view"), class("display compact nowrap")])], + make_header(_T, rows.header.list, []), + make_lines(rows.table_name, action_name, rows.list, [], 0)) + ] + ) + )) + . + +public define HTML_Partial_Content + view_table_page + ( + (String) -> String _T, + String lang, + String web_site_directory, + String action_name, + VT_view rows + ) = + +// if tb is tool_box(lang, _T, _, _, db, _) then +// println("view_table_page - lang : "+lang); +// println("view_table_page - web_site_directory : "+web_site_directory); + partial_content( + [html_wave_box_wide(_T(to_upper(rows.table_name)), + jquery_datatable("table_view", view_table_form(_T, action_name, rows), true, false, jq_dt_pt_full_numbers, scrollY(500), true, true, true, lang, no_extra, web_site_directory))]). + +public define Maybe(HTML_Partial_Content) + view_table_content + ( + SQLite3DataBase db, + (String) -> String _T, + String lang, + String web_site_directory, + String table, + String action_name, + VTM vtm + ) = + if vtm_get_view(table, vtm.view_list) is + { + failure then failure, + success(vtm_v) then + since vtm_v is vtm_view(_, get_view), + success(view_table_page(_T, lang, web_site_directory, action_name, get_view(db))) + }. diff --git a/database/vtm/view_table_types.anubis b/database/vtm/view_table_types.anubis new file mode 100644 index 0000000..cbd8fec --- /dev/null +++ b/database/vtm/view_table_types.anubis @@ -0,0 +1,44 @@ +/* + * Created by PyramIDE. + * User: Totoro + * Date: 15/11/2011 + * Time: 20:32 + */ + +read calexium_lib/web/CXM_making_a_web_site.anubis + +public type VT_edit_selector: + vt_edit_selector((SQLite3DataBase db) -> List((List(CoreAttrs), WebArgValue, String)) get). + +public type VT_edit_entry: + hidden(String name, String value), + primary_key(String idx), + information(String s_name, String c_name, String v_name), //s_name = show_name for translation, v_name = string to show + text(String s_name, String c_name, String value), //s_name = show_name for translation, c_name = table column name + foreign_text(String s_name, String c_name, Int selected, VT_edit_selector selector), + text_area(String s_name, String c_name, String value), //s_name = show_name for translate, c_name = table column name + boolean(String s_name, String c_name, Bool value), + integer(String s_name, String c_name, Int value), + date(String s_name, String c_name, String value), + datetime(String s_name, String c_name, String value). + +public type VT_edit: + vt_edit(String table_name, List(VT_edit_entry) list). + +public type VT_view_entry: + text(String text), + link(String id, String text). + +public type VT_view_row: + vt_view_row(List(VT_view_entry) list). + +public type VT_view: + vt_view(String table_name, VT_view_row header, List(VT_view_row) list). + + +public type VT_action: + new_entry, + edit_entry(String idx). + +public define String default_select = "--------------------". //20 dash +public define (List(CoreAttrs),WebArgValue,String) selector_default_entry = ([], wav("0"),default_select). -- libgit2 0.21.4