view_table_renderer.anubis
8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* 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 calexium_lib/database/model/db_model.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
define CXM_Form_Field
help_line
(
DB_Help_Text help,
(String) -> String _T
)=
if help is
{
no_help_text then empty,
help_text_TAG(tag) then explain(_T(tag)),
help_text(str) then explain(str)
}.
//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, help) then
[input_readonly(_T(s_name), wan(c_name), init(value), narrow), help_line(help, _T)],
text(s_name, c_name, value, help) then
[input(_T(s_name), wan(c_name), init(value), narrow, mandatory), help_line(help, _T)],
foreign_text(s_name, c_name, value, select, help) then
[selector_c([],_T(s_name), htmlId(""), wan(c_name), 1, select.get(db), success(init(to_String(value))), mandatory), help_line(help, _T)],
text_area(s_name, c_name, value, help) then
[text_area([],_T(s_name), htmlId(""), wan(c_name), init(value), narrow, (Int)5, mandatory), help_line(help, _T)],
boolean(s_name, c_name, value, help) then
[checkboxr([],_T(s_name), htmlId(""), wan(c_name), wav(c_name),value, mandatory), help_line(help, _T)],
integer(s_name, c_name, value, help) then
[input(_T(s_name), wan(c_name), init(abs_to_decimal(value)), small, mandatory), help_line(help, _T)],
date(s_name, c_name, value, help) then
[input([class("datepicker")], _T(s_name), htmlId(c_name), wan(c_name), init(value), narrow, non_mandatory), help_line(help, _T)],
datetime(s_name, c_name, value, help) then
[input([class("datetimepicker")], _T(s_name), htmlId(c_name), wan(c_name), init(value), narrow, mandatory), help_line(help, _T)],
},
edit_form_lines(db, _T, t, reverse(line)+so_far)
}.
public define HTML_Partial_Content
edit_table_page
(
SQLite3DataBase db,
(String) -> String _T,
String lang,
List(Web_arg) lwa,
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), lwa,
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,
List(Web_arg) lwa,
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, lwa, 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)))
}.