Commit 229894d6c467a8a79b9ab9b5561d59c91bc6a3ac
1 parent
7c694bdb
manage hayamiki view with jQgrid
Showing
5 changed files
with
182 additions
and
17 deletions
Show diff stats
| 1 | +/* | |
| 2 | + * Created by PyramIDE. | |
| 3 | + * User: フランスのトトロ aka (David RENÉ) | |
| 4 | + * Date: 21/03/2017 | |
| 5 | + * Time: 22:49 | |
| 6 | + * © Calexium | |
| 7 | + */ | |
| 8 | + | |
| 9 | +read calexium_lib/web/CXM_making_a_web_site.anubis | |
| 10 | +read hayamiki_lib/types/hayamiki.anubis | |
| 11 | +read view_table_types.anubis | |
| 12 | + | |
| 13 | +define String | |
| 14 | + to_jqGrid_selector | |
| 15 | + ( | |
| 16 | + List((List(CoreAttrs), WebArgValue, String)) from_hk_selector | |
| 17 | + )= | |
| 18 | + "\""+ | |
| 19 | + join(";",map(((List(CoreAttrs), WebArgValue, String) select) |-> since select is (_, wav, show), wav.value+":"+show, from_hk_selector))+ | |
| 20 | + "\"" | |
| 21 | +. | |
| 22 | + | |
| 23 | +define String | |
| 24 | + to_jqGrid_ColModel | |
| 25 | + ( | |
| 26 | + SQLite3DataBase db, | |
| 27 | + VT_view_model_entry model | |
| 28 | + )= | |
| 29 | + if model is | |
| 30 | + { | |
| 31 | + primary_key then "{ name: \"id\" }", | |
| 32 | + information(label,column_name,width,help) then "{ name: \""+column_name+"\", label: \""+label+"\" }", | |
| 33 | + text(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\", editable:true }", | |
| 34 | + password(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\" }", | |
| 35 | + foreign_text(label,column_name,selector,help) then | |
| 36 | + "{ name: \""+column_name+"\", label: \""+label+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 37 | + " formatter: \"select\","+ | |
| 38 | + " formatoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 39 | + "}", | |
| 40 | + choices_text(label,column_name,selector,help) then | |
| 41 | + "{ name: \""+column_name+"\", label: \""+label+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 42 | + " formatter: \"select\","+ | |
| 43 | + " formatoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 44 | + "}", | |
| 45 | + text_area(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\" }", | |
| 46 | + boolean(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\", editable:true, template: \"booleanCheckboxFa\" }", | |
| 47 | + integer(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\", editable:true, template: \"integer\" }", | |
| 48 | + float(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\", editable:true, template: \"number\" }", | |
| 49 | + choices_int(label,column_name,selector,help) then "{ name: \""+column_name+"\", label: \""+label+"\", editable:true, edittype:\"select\", editoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 50 | + " formatter: \"select\","+ | |
| 51 | + " formatoptions:{value: "+to_jqGrid_selector(selector.get(db,""))+"},"+ | |
| 52 | + "}", | |
| 53 | + date(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\", editable:true, formatter: \"date\", formatoptions: { newformat: \"Y-M-d\" }}", | |
| 54 | + time(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\", editable:true }", | |
| 55 | + datetime(label,column_name,help) then "{ name: \""+column_name+"\", label: \""+label+"\", editable:true }", | |
| 56 | + } | |
| 57 | +. | |
| 58 | + | |
| 59 | +public define String | |
| 60 | + to_jqGrid_ColModel | |
| 61 | + ( | |
| 62 | + SQLite3DataBase db, | |
| 63 | + List(VT_view_model_entry) models | |
| 64 | + )= | |
| 65 | + "colModel: [\n"+ | |
| 66 | + join(",\n ", | |
| 67 | + [ "{name: 'myac', label: 'Action', width:60, fixed:true, sortable:false, resize:false, formatter:'actions', formatoptions:{keys:true}}" . | |
| 68 | + map((VT_view_model_entry col_model) |-> to_jqGrid_ColModel(db, col_model), models) | |
| 69 | + ] | |
| 70 | + )+ | |
| 71 | + "]" | |
| 72 | +. | ... | ... |
view/view_table_manager_types.anubis
| ... | ... | @@ -33,7 +33,7 @@ public type TM_delete_list: |
| 33 | 33 | tm_delete_list(List(TM_delete) list). |
| 34 | 34 | |
| 35 | 35 | public type VTM_view: |
| 36 | - vtm_view(String table_name, (SQLite3DataBase db, String view_name, String clause) -> VT_view get_view). | |
| 36 | + vtm_view(String table_name, (String view_name) -> VT_view get_view). | |
| 37 | 37 | |
| 38 | 38 | public type VTM_view_list: |
| 39 | 39 | vtm_view_list(List(VTM_view) list). | ... | ... |
view/view_table_renderer.anubis
| ... | ... | @@ -7,6 +7,7 @@ |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | read hayamiki_lib/view/view_table_types.anubis |
| 10 | +read hayamiki_lib/view/jqgrid.anubis | |
| 10 | 11 | read hayamiki_lib/view/view_table_manager_types.anubis |
| 11 | 12 | read hayamiki_lib/view/view_table_manager.anubis |
| 12 | 13 | read hayamiki_lib/view/web_action.anubis |
| ... | ... | @@ -32,6 +33,7 @@ read calexium_lib/web/jQuery/ui-addon/datetimepicker.anubis |
| 32 | 33 | read calexium_lib/web/CXM_form.anubis |
| 33 | 34 | read calexium_lib/web/widgets/css_helper.anubis |
| 34 | 35 | read calexium_lib/web/widgets/button.anubis |
| 36 | +read calexium_lib/web/CXM_urllib.anubis | |
| 35 | 37 | |
| 36 | 38 | |
| 37 | 39 | |
| ... | ... | @@ -123,23 +125,76 @@ public define HTML_Partial_Content |
| 123 | 125 | sequence( |
| 124 | 126 | [ |
| 125 | 127 | |
| 126 | - partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))), | |
| 127 | - table([core_attrs([id(uid+"table_view"), class("tableau display compact nowrap")])], | |
| 128 | - make_header(_T, rows.header.list, [action_header_cell]), | |
| 129 | - make_lines(_T, uid, rows.table_name, action_name, rows.list, [])) | |
| 128 | + //partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))), | |
| 129 | + //table([core_attrs([id(uid+"table_view"), class("tableau display compact nowrap")])], | |
| 130 | + // make_header(_T, rows.header.list, [action_header_cell]) | |
| 131 | + // make_lines(_T, uid, rows.table_name, action_name, rows.list, []) | |
| 132 | + //) | |
| 130 | 133 | ] |
| 131 | 134 | ) |
| 132 | 135 | )) |
| 133 | 136 | . |
| 134 | 137 | |
| 138 | +define String | |
| 139 | + jqGrid_options | |
| 140 | + ( | |
| 141 | + String uid, | |
| 142 | + VT_view rows, | |
| 143 | + (String) -> String _T | |
| 144 | + )= | |
| 145 | + " | |
| 146 | + iconSet: \"fontAwesome\", | |
| 147 | + autowidth:true, | |
| 148 | + shrinkToFit:true, | |
| 149 | + rowNum:10, | |
| 150 | + cellEdit: true, | |
| 151 | + cellsubmit: 'remote', | |
| 152 | + cellurl: '?aws_controller=hk_c&aws_action=update_row&table_name="+rows.table_name+"', | |
| 153 | + pager: '#"+uid+"_pager', | |
| 154 | + caption:"+to_JSON_String(_T(to_upper(rows.table_name)))+", | |
| 155 | + ondblClickRow: function( rowid) {"+ | |
| 156 | + jq_dialog_open(dialog_id(uid+"edit_table_dlg_ajax"), "'id='+rowid")+ | |
| 157 | + "}" | |
| 158 | +. | |
| 159 | + | |
| 160 | +public define HTML_Partial_Content | |
| 161 | + jqGrid_table | |
| 162 | + ( | |
| 163 | + SQLite3DataBase db, | |
| 164 | + String uid, | |
| 165 | + VT_view rows, | |
| 166 | + (String) -> String _T, | |
| 167 | + String clause | |
| 168 | + )= | |
| 169 | + with filter_clause = if clause = "" then "" else "&clause="+url_quote(clause), | |
| 170 | + with js = js_inline(jquery_ready("$(\"#"+uid+"_grid\").jqGrid({\n"+ | |
| 171 | + "url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&view_name="+rows.view_name+filter_clause+"',"+ | |
| 172 | + "datatype: \"json\","+ | |
| 173 | + to_jqGrid_ColModel(db, rows.view_model.list)+","+ | |
| 174 | +// rows.json_data_string+ | |
| 175 | + jqGrid_options(uid, rows, _T)+ | |
| 176 | + "})")), | |
| 177 | + | |
| 178 | + partial_content([js], | |
| 179 | + div([], | |
| 180 | + sequence([ | |
| 181 | + table([core_attrs([id(uid+"_grid")])],[]), | |
| 182 | + div_empty([id(uid+"_pager")]) | |
| 183 | + ]) | |
| 184 | + ) | |
| 185 | + ) | |
| 186 | +. | |
| 187 | + | |
| 135 | 188 | public define HTML_Partial_Content |
| 136 | 189 | view_table_page |
| 137 | 190 | ( |
| 138 | - (String) -> String _T, | |
| 139 | - String lang, | |
| 140 | - String web_site_directory, | |
| 141 | - String action_name, | |
| 142 | - VT_view rows | |
| 191 | + SQLite3DataBase db, | |
| 192 | + (String) -> String _T, | |
| 193 | + String lang, | |
| 194 | + String web_site_directory, | |
| 195 | + String action_name, | |
| 196 | + VT_view rows, | |
| 197 | + String clause | |
| 143 | 198 | ) = |
| 144 | 199 | |
| 145 | 200 | // if tb is tool_box(lang, _T, _, _, db, _) then |
| ... | ... | @@ -149,18 +204,22 @@ public define HTML_Partial_Content |
| 149 | 204 | partial_content(jq_dialog_init + jq_datetimepicker_init(lang), |
| 150 | 205 | [html_wave_box_wide(_T(to_upper(rows.table_name)), |
| 151 | 206 | sequence([ |
| 152 | - partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), | |
| 153 | - 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)) | |
| 207 | + partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))), | |
| 208 | + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), | |
| 209 | + partial(jqGrid_table(db, uid, rows, _T, clause)) | |
| 210 | + //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)) | |
| 154 | 211 | ]))]). |
| 155 | 212 | |
| 156 | 213 | public define HTML_Partial_Content |
| 157 | 214 | view_table |
| 158 | 215 | ( |
| 216 | + SQLite3DataBase db, | |
| 159 | 217 | (String) -> String _T, |
| 160 | 218 | String lang, |
| 161 | 219 | String web_site_directory, |
| 162 | 220 | String action_name, |
| 163 | - VT_view rows | |
| 221 | + VT_view rows, | |
| 222 | + String clause | |
| 164 | 223 | ) = |
| 165 | 224 | |
| 166 | 225 | // if tb is tool_box(lang, _T, _, _, db, _) then |
| ... | ... | @@ -168,7 +227,12 @@ public define HTML_Partial_Content |
| 168 | 227 | // println("view_table_page - web_site_directory : "+web_site_directory); |
| 169 | 228 | with uid = generate_random_string(20)+"_", |
| 170 | 229 | partial_content(jq_dialog_init + jq_datetimepicker_init(lang), |
| 171 | - [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))]). | |
| 230 | + [ | |
| 231 | + partial(jq_dialog_create(dialog_id(uid+action_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&table_name="+rows.table_name)))), | |
| 232 | + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+action_name+"_dlg_ajax")))], "", [])), | |
| 233 | + partial(jqGrid_table(db, uid, rows, _T, clause)), | |
| 234 | + //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)) | |
| 235 | + ]). | |
| 172 | 236 | |
| 173 | 237 | public define Maybe(HTML_Partial_Content) |
| 174 | 238 | view_table_content |
| ... | ... | @@ -188,7 +252,7 @@ public define Maybe(HTML_Partial_Content) |
| 188 | 252 | failure then failure, |
| 189 | 253 | success(vtm_v) then |
| 190 | 254 | since vtm_v is vtm_view(_, get_view), |
| 191 | - success(view_table_page(_T, lang, web_site_directory, action_name, get_view(db, view_name, clause))) | |
| 255 | + success(view_table_page(db, _T, lang, web_site_directory, action_name, get_view(view_name), clause)) | |
| 192 | 256 | }. |
| 193 | 257 | |
| 194 | 258 | public define Maybe(HTML_Partial_Content) |
| ... | ... | @@ -209,7 +273,8 @@ public define Maybe(HTML_Partial_Content) |
| 209 | 273 | failure then failure, |
| 210 | 274 | success(vtm_v) then |
| 211 | 275 | since vtm_v is vtm_view(_, get_view), |
| 212 | - success(view_table(_T, lang, web_site_directory, action_name, get_view(db, view_name, clause))) | |
| 276 | +// success(view_table(_T, lang, web_site_directory, action_name, get_view(db, view_name, clause))) | |
| 277 | + success(view_table(db, _T, lang, web_site_directory, action_name, get_view(view_name), clause)) | |
| 213 | 278 | }. |
| 214 | 279 | |
| 215 | 280 | define CXM_Form_Field | ... | ... |
view/view_table_types.anubis
| ... | ... | @@ -47,6 +47,25 @@ public type VT_edit: |
| 47 | 47 | vt_edit(String table_name, String view_name, List(VT_edit_entry) list, List(HK_V_Edit_Tab) tabs). |
| 48 | 48 | |
| 49 | 49 | |
| 50 | +public type VT_view_model_entry: | |
| 51 | + //hidden (String name, String value), | |
| 52 | + primary_key , | |
| 53 | + information (String label, String column_name, Int width, HK_Help_Text help), //s_name = show_name for translation, v_name = string to show | |
| 54 | + text (String label, String column_name, HK_Help_Text help), //s_name = show_name for translation, c_name = table column name | |
| 55 | + password (String label, String column_name, HK_Help_Text help), //s_name = show_name for translation, c_name = table column name | |
| 56 | + foreign_text(String label, String column_name, VT_edit_selector selector, HK_Help_Text help), | |
| 57 | + choices_text(String label, String column_name, VT_edit_selector selector, HK_Help_Text help), | |
| 58 | + text_area (String label, String column_name, HK_Help_Text help), //s_name = show_name for translate, c_name = table column name | |
| 59 | + boolean (String label, String column_name, HK_Help_Text help), | |
| 60 | + integer (String label, String column_name, HK_Help_Text help), | |
| 61 | + float (String label, String column_name, HK_Help_Text help), | |
| 62 | + choices_int (String label, String column_name, VT_edit_selector selector, HK_Help_Text help), | |
| 63 | + date (String label, String column_name, HK_Help_Text help), | |
| 64 | + time (String label, String column_name, HK_Help_Text help), | |
| 65 | + datetime (String label, String column_name, HK_Help_Text help). | |
| 66 | + | |
| 67 | +public type VT_view_model: | |
| 68 | + vt_view_model(List(VT_view_model_entry) list). | |
| 50 | 69 | |
| 51 | 70 | public type VT_view_entry: |
| 52 | 71 | text(String text), |
| ... | ... | @@ -59,9 +78,17 @@ public type VT_view_row_header: |
| 59 | 78 | |
| 60 | 79 | public type VT_view_row: |
| 61 | 80 | vt_view_row(Int db_id, List(VT_view_entry) list). |
| 81 | + | |
| 82 | +public type VT_View_DB_Calls: | |
| 83 | + vt_view_db_calls( | |
| 84 | + (SQLite3DataBase db, String clause) -> Int get_count, | |
| 85 | + (SQLite3DataBase db, String clause) -> JsonMember get_rows_json | |
| 86 | +// (SQLite3DataBase db, String clause) -> List(VT_view_row) get_rows | |
| 87 | + ) | |
| 88 | +. | |
| 62 | 89 | |
| 63 | 90 | public type VT_view: |
| 64 | - vt_view(String table_name, String view_name, VT_view_row_header header, List(VT_view_row) list). | |
| 91 | + vt_view(String table_name, String view_name, VT_view_model view_model, VT_view_row_header header, VT_View_DB_Calls db_calls). , List(VT_view_row) list). | |
| 65 | 92 | |
| 66 | 93 | |
| 67 | 94 | public type VT_action: | ... | ... |
view/web_action.anubis
| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | read calexium_lib/web/CXM_making_a_web_site.anubis |
| 10 | 10 | |
| 11 | 11 | public define WEB_Action_Name edit_table = controller_action("hk_c", "edit_table"). |
| 12 | +public define WEB_Action_Name grid_view = controller_action("hk_c", "grid_view"). | |
| 12 | 13 | public define WEB_Action_Name view_table = controller_action("hk_c", "view_table"). |
| 13 | 14 | public define WEB_Action_Name save_row = controller_action("hk_c", "save_row"). |
| 14 | 15 | public define WEB_Action_Name save_row_and_new = controller_action("hk_c", "save_row_and_new"). | ... | ... |