view_rows_import.anubis
8.35 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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 06/05/2017
* Time: 10:33
* © David RENÉ
*/
read locale/L3.anubis
read locale/L3LanguageInfo.anubis //date and time formating
read system/data_io.anubis
read tools/line_reader.anubis
read tools/basis.anubis
read calexium_lib/database/csv_tools.anubis
read calexium_lib/web/CXM_making_a_web_site.anubis
read calexium_lib/web/CXM_jquery.anubis
read calexium_lib/web/CXM_form.anubis
read calexium_lib/web/jQuery/CXM_jquery_button.anubis
read calexium_lib/web/widgets/css_helper.anubis
read calexium_lib/web/widgets/icons_set.anubis
read hayamiki_lib/view/web_action.anubis
read web_pages/desktop.anubis
read app/app_constants.anubis
read version.anubis
public define List((List(CoreAttrs), WebArgValue, String))
csv_delimiter_combo
(
(String) -> String _T
)
=
(List((List(CoreAttrs), WebArgValue, String)))[
([],wav(","), _T("COMA_SEP")),
([],wav(";"), _T("SEMICOLON_SEP")),
([],wav("\t"),_T("TAB"))].
public define List((List(CoreAttrs), WebArgValue, String))
csv_import_type_combo
(
(String) -> String _T
)
=
(List((List(CoreAttrs), WebArgValue, String)))[
([],wav("insert_or_update"), _T("INSERT_OR_UPDATE")),
([],wav("insert"), _T("INSERT")),
([],wav("update"), _T("UPDATE")),
].
public define HTML_Partial_Content
import_zone
(
String table_name,
(String) -> String _T
)=
html_wave_box(_T("CONTROL_PANEL"),
partial_content(
[ js(js_file("js/dropzone.js")),
js_inline(jquery_ready("Dropzone.options.myAwesomeDropzone = {
maxFiles: 1,
dictDefaultMessage : \""+_T("DROP_FILE_HERE")+"\",
dictFileTooBig : \""+_T("FILE_TOO_BIG")+"\",
};
$('#my-awesome-dropzone').dropzone(); ")),
],
sequence([
text([], _T("CSV_IMPORT_FOR")+" "+table_name),
form("my-awesome-dropzone",[class("dropzone")], hkc_import_file,
[("format","csv"), ("table_name",table_name)],
empty),
partial(jquery_button(jquery_img_button(icn16_cross, _T("CANCEL"), "", jQuery_actioner(same, jqlink(hkc_cancel)), left))),
partial(jquery_button(jquery_img_button(icn16_check, _T("IMPORT"), "", jQuery_actioner(same, jqlink(hkc_import_choose_col, [("format","csv"), ("table_name",table_name)])), left)))
])
)
)
.
define List(HTML_Row(HTML_In_Form))
source_lines
(
List(String) cols,
List(HTML_Row(HTML_In_Form)) so_far,
Int index,
(String) -> String _T
)=
if cols is
{
[] then reverse(so_far),
[ h . t ] then
source_lines( t, [ row([cell([style("display:none")], literal("")),
cell([core_attrs([id("col_"+index), class("dnd-src")])], text(_T("COLUMN")+ " "+index+" ("+h+")"))]) . so_far], index+1, _T)
}
.
public define HTML_In_Form
source_file_column_table
(
Word8 separator,
String uploaded_file,
(String) -> String _T
)=
if file(uploaded_file, read) is
{
failure then
//logError(debug_log, "Can't open CSV file '" + f_name + "'"); text(_T("CANT_OPEN_FILE")),
println("Can't open CSV file '" + uploaded_file + "'");
text(_T("CANT_OPEN_FILE"))
success(f) then
//logDebug(debug_log, "file opened, make_line_reader");
//Parse the first line
if csv_read_line(make_data_io(f), separator, false, "", [], []) is
{
failure then
//logError(debug_log, "Can't parse 1st line of CSV file '" + f_name + "'");
text(_T("PARSE_ERROR")),
success(col_data) then
//logDebug(debug_log, "read_line: read");
if col_data is (line, cols) then
sequence([
hidden(html_Id("hk_source_col"), wan("hk_source_col"), wav(to_String(length(cols)))),
table([core_attrs([class("changelist small"), id("table-src")])],
header_row([ header_cell([style("display:none")], literal("")),
header_cell(literal("CSV_FILE_FIELDS"))]),
source_lines(cols, [], 0, _T)
)
])
}
}.
.
define List(HTML_Row(HTML_In_Form))
target_lines
(
List((String,String)) cols,
List(HTML_Row(HTML_In_Form)) so_far,
Int index,
(String) -> String _T
)=
//if tb is tool_box(lang, _, _T, _, db, user, _, _) then
if cols is
{
[] then reverse(so_far),
[ h . t ] then
since h is (hidden_name, text_field),
target_lines( t,[ row([
cell([style("display:none")], empty),
cell([class("dnd-text ")], text(_T(text_field))),
cell([class("dnd-dst")], sequence([
text(_T("IGNORED_COLUMN")),
hidden(html_Id("hk_"+hidden_name+"_input"), wan(""), wav(hidden_name))
])),
cell(image([class("dnd-dst-btn")],"/icons/16x16/delete_cross.png",""))
])
. so_far], index+1, _T)
}.
define HTML_In_Form
target_column_table
(
List((String,String)) choices,
(String) -> String _T
)=
//since tb is tool_box(lang, _, _T, _, db, user, _, _),
table([core_attrs([class("changelist small"), id("table-dst")])],
header_row([ header_cell([style("display:none")], empty),
header_cell(text(_T("TABLE_FIELDS"))),
header_cell(text(_T("IMPORTED_FIELDS"))),
header_cell(literal(" "))]),
target_lines(choices, [], 0, _T)
)
.
public define HTML_Partial_Content
import_choose_col
(
String target_table_name,
List((String,String)) target_columns_choices,
String separator,
String uploaded_file,
WEB_Action_Name cancel_action, //
(String) -> String _T // translator from dictionary
)=
partial_content([css(css_file("css/cxm/cxm_dnd.css")),
css(css_file("css/changelists.css")),
js(js_file("js/cxm/cxm_dnd.js")),
js(js_file("js/data_import.js"))
],
sequence([
form("import_csv_form",[], hkc_import_execute, [("table_name", target_table_name), ("file",uploaded_file)], sequence([
table([class("changelist small")],
header_row([ header_cell(literal(" ")),
header_cell(text(_T("INFORMATION_OF_SOURCE_FILE"))),
header_cell(literal(" ")),
]),
[row([], [cell(image(icn16_mime_csv)), cell(text(_T("FILE_FORMAT"))), cell(text(_T("CSV_FILE")))]),
row([], [cell(image(icn16_mime_unknown)), cell(text(_T("SOURCE_FILE_TO_IMPORT"))), cell(text(uploaded_file))]),
row([], [cell(empty), cell(text(_T("DELIMITER"))), cell(selector_c([], no_label, html_Id("import_delimiter"), wan("csv_sep"), 1, csv_delimiter_combo(_T), init(separator)),)]),
row([], [cell(empty), cell(text(_T("FILE_ENCODING"))), cell(text("choose encoding"))]),
row([], [cell(empty), cell(text(_T("REMOVE_CSV_HEADER"))), cell(check_box([], no_label, html_Id(""), wan("hk_remove_csv_header"), true))]),
row([], [cell(empty), cell(text(_T("IMPORT_TYPE"))), cell(selector_c([], no_label, html_Id("import_type"), wan("import_type"), 1, csv_import_type_combo(_T), init(separator)),)]),
]),
br,
div([id("dragLists")], [
//SOURCE column
div([style("float: left; margin: 5px;")], div([class("dndContainer ")],
source_file_column_table(if explode(separator) is { [] then ';', [h . _] then h }, uploaded_file, _T))),
//TARGET column
div([style("float: left; margin: 5px;")], div([class("dndContainer ")],
target_column_table(target_columns_choices, _T))),
div_empty([class("clear")])
]),
])), //end of sequence in form
// )])
partial(jquery_button(jquery_img_button(icn16_cross, _T("CANCEL"), "", jQuery_actioner(same, jqlink(cancel_action)), left))),
partial(img_submit_button(_T("IMPORT"), "import_csv_form"))
]) //end of sequence
)
.