Commit 8116ce4b2b93a70d5459cbd6729e9846aac9912f

Authored by totoro
1 parent c35a0960

continuation of the refactoring, and gather database call back in hk_table_controller

implement, insert or update, and update to CSV import
make clickable the text on Apps view
Fix bug on list view with filter which was not applied at first draw
add reference to foreign table in foreign_text of HK_Form_Entry
controller/hk_rows_import.anubis
... ... @@ -111,20 +111,55 @@ define (Int, List(List(String)))
111 111 else
112 112 if cvs_line_reader(unique) is
113 113 {
114   - end_of_input then (offset, so_far)
  114 + end_of_input then println("END OF INPUT "+offset);(offset, so_far)
115 115 error(e) then
116 116 //TODO report that error in importation report
117 117 println("error ["+e+"]\n"); (offset, so_far),
118 118 ok(_offset, all_values) then
  119 + println("extracted line : \""+join("\", ", all_values)+"\"");
  120 +
119 121 //if line_data is (line, all_values) then
120 122 extract_lines(cvs_line_reader, max_count - 1, columns, _offset, [all_values . so_far])
121 123 }
122 124 .
123 125  
  126 +
  127 +define Result(String, One)
  128 + update_data_to_table
  129 + (
  130 + SQLite3Stmt update_data_stmt,
  131 + List(String) columns,
  132 + List(String) values
  133 + )=
  134 + if sqlite3_reset(update_data_stmt) is
  135 + {
  136 + error(err) then println(db_error(err, "Error reseting update data statement")); error("DB Error"),
  137 + ok then
  138 + //println("update reset ok");
  139 + if sqlite3_bind(update_data_stmt, map2_select(bind_column_value, columns, values)) is
  140 + {
  141 + error(err) then println(db_error(err, "Error binding update data statement"));error("DB Error"),
  142 + ok then
  143 + //println("update bind ok");
  144 + if sqlite3_step(update_data_stmt) is
  145 + {
  146 + error(err) then
  147 + println(db_error(err, "Error executing update data statement"));
  148 + error("DB Error"),
  149 + no_more_row then
  150 + ok(unique),
  151 + row(_) then
  152 + ok(unique)
  153 + }
  154 + }
  155 + }.
  156 +
124 157 define Result(String, One)
125   - insert_data_to_table
  158 + insert_or_update_data_to_table
126 159 (
127 160 SQLite3Stmt insert_data_stmt,
  161 + SQLite3Stmt update_data_stmt,
  162 + Bool update, //if true make update on constraint violation
128 163 List(String) columns,
129 164 List(String) values
130 165 )=
... ... @@ -138,9 +173,20 @@ define Result(String, One)
138 173 ok then
139 174 if sqlite3_step(insert_data_stmt) is
140 175 {
141   - error(err) then println(db_error(err, "Error executing insert data statement")); error("DB Error"),
142   - no_more_row then ok(unique),
  176 + error(err) then
  177 + //println(db_error(err, "Error executing insert data statement"));
  178 + forget(sqlite3_reset(insert_data_stmt));
  179 +
  180 + if err.code = 19 & update then
  181 + update_data_to_table(update_data_stmt, columns, values)
  182 + else
  183 + error("DB Error"),
  184 + no_more_row then ok(unique)
  185 + //println("insert no more row");
  186 + //update_data_to_table(update_data_stmt, columns, values),
143 187 row(_) then ok(unique)
  188 + //println("insert row");
  189 + //update_data_to_table(update_data_stmt, columns, values)
144 190 }
145 191 }
146 192 }.
... ... @@ -148,28 +194,33 @@ define Result(String, One)
148 194 define Maybe(One)
149 195 store_data
150 196 (
151   - SQLite3Stmt insert_data_stmt,
152   - SQLite3Stmt update_data_stmt,
  197 +// SQLite3Stmt insert_data_stmt,
  198 +// SQLite3Stmt update_data_stmt,
  199 +// Bool update,
  200 + List(String) -> Result(String, One) import_line_values,
153 201 // SQLite3Stmt select_contact_id_opt_out_stmt,
154 202 // SQLite3Stmt select_stmt,
155 203 // SQLite3Stmt insert_list_contact_stmt,
156 204 // SQLite3Stmt count_stmt,
157   - List(String) columns, //list of column's name
  205 +
  206 +// List(String) columns, //list of column's name
158 207 List(List(String)) rows //list of list of real data to store
159 208 ) =
160 209 if rows is
161 210 {
162   - [] then success(unique),
  211 + [] then
  212 + println("store data row empty");
  213 + success(unique),
163 214 [row . t] then
164   - if insert_data_to_table(insert_data_stmt, columns, row) is
  215 + if import_line_values(row) is //insert_or_update_data_to_table(insert_data_stmt, update_data_stmt, update, columns, row) is
165 216 {
166 217 error(msg) then
167 218 println("data can't be added "+msg);
168 219 //TODO as Julien's idea, copy error line in new csv file
169   - store_data(insert_data_stmt, update_data_stmt, columns, t),
  220 + store_data(import_line_values, t),
170 221  
171 222 ok(_) then
172   - store_data(insert_data_stmt, update_data_stmt, columns, t)
  223 + store_data(import_line_values, t)
173 224 }
174 225 }
175 226 .
... ... @@ -179,9 +230,9 @@ define CSV_Import_Status
179 230 (
180 231 SQLite3DataBase db,
181 232 // Int import_id, */
182   - SQLite3Stmt insert_data_stmt,
183   - SQLite3Stmt update_data_stmt,
184   -
  233 +// SQLite3Stmt insert_data_stmt,
  234 +// SQLite3Stmt update_data_stmt,
  235 + List(String) -> Result(String, One) import_line_values,
185 236 One -> ReadCsvResult csv_line_reader,
186 237 //One -> Int progression,
187 238 UTime start_time,
... ... @@ -201,22 +252,25 @@ define CSV_Import_Status
201 252 //get 500 lines from cvs
202 253 since extract_lines(csv_line_reader, 500, columns, _offset, []) is (offset, so_far),
203 254 with extract_length = length(so_far),
204   - println("Extracted lines : "+extract_length);
  255 + //println("extraction: offset "+offset+" #lines "+extract_length);
205 256  
206 257 if extract_length = 0 then
207 258 csv_finished
208 259 else
209 260 if db_do_transaction(
210 261 db,
211   - (One _) |-> store_data(insert_data_stmt, update_data_stmt, columns, so_far),
  262 + (One _) |-> store_data(import_line_values, so_far),
212 263 success((SQLite3Error err) |-> println(db_error(err,"import_csv_to_db"))),
213 264 //success((SQLite3Error err) |-> logError("DB", db_error(err,"import_csv_to_db"))),
214 265 60000, // max 60s
215 266 100 // retry every 100 ms
216 267 ) is
217 268 {
218   - error(_) then csv_db_error,
219   - ok(_) then main_loop(db, insert_data_stmt, update_data_stmt, csv_line_reader, new_time, columns, line_num + extract_length, offset, offset_base)
  269 + error(_) then
  270 + println("main loop db_do_transaction csv_db_error");
  271 + csv_db_error,
  272 + ok(_) then
  273 + main_loop(db, import_line_values, csv_line_reader, new_time, columns, line_num + extract_length, offset, offset_base)
220 274 }
221 275 .
222 276  
... ... @@ -228,17 +282,17 @@ define CSV_Import_Status
228 282 // Import_Task import_task,
229 283 One -> ReadCsvResult csv_line_reader,
230 284 //(One) -> Int progression,
  285 + String import_type,
231 286 List(String) columns, //columns selected for importation in same order from CSV file
  287 + String column_key,
232 288 UTime start_time,
233 289 Int offset_base
234 290 )=
235 291 //since import_task is import_task(import_task_id, list_id, filename, file_size, csv_db_columns, separator, charset, amount_time, offset, current_line, lines_count, status, status_details, update_contact, opt_out_import),
236 292 with current_line = (Int)0,
237 293 with offset = (Int)0,
238   -// if get_domain_id_from_mailing(db, list_id) is
239   -// {
240   -// failure then logError(debug_log, "domain_id not found in import_csv_to_mailing_list"); csv_error,
241   -// success(domain_id) then
  294 + with key = if column_key = "" then "id" else column_key,
  295 +
242 296 with filter_columns = map_select((String s) |-> if s = "" then failure else success(s), columns),
243 297 sql_columns = join(", ", filter_columns),
244 298 sql_values = join(", ", map((String s) |-> ":"+s, filter_columns)),
... ... @@ -246,25 +300,36 @@ define CSV_Import_Status
246 300  
247 301 if sqlite3_prepare(db, "INSERT INTO "+table_name+" ("+sql_columns+") VALUES ("+sql_values+");") is
248 302 {
249   - error(err) then //logError(debug_log, db_error(err, "preparing insert contact statement for import_csv_to_mailing_list"));
  303 + error(err) then //logError(debug_log, db_error(err, "preparing insert contact statement for import _csv_to_mailing_list"));
250 304 println(db_error(err, "preparing insert data statement for import_csv_to_mailing_list"));
251 305 csv_db_error,
252 306 ok(insert_data_stmt) then
253   -
254   - if sqlite3_prepare(db, "UPDATE "+table_name+" SET " + sql_update_values + " WHERE id=:id;") is
  307 +// with update_query = "UPDATE "+table_name+" SET " + sql_update_values + " WHERE changes()=0 AND "+key+"=:"+key+";",
  308 + with update_query = "UPDATE "+table_name+" SET " + sql_update_values + " WHERE "+key+"=:"+key+";",
  309 + println(" update query : "+update_query);
  310 + if sqlite3_prepare(db, update_query) is
255 311 {
256 312 error(err) then //logError(debug_log, db_error(err, "preparing update contact statement for import_csv_to_mailing_list"));
257 313 println(db_error(err, "preparing update data statement for import_csv_to_db_transaction"));
258 314 csv_db_error,
259 315 ok(update_data_stmt) then
260 316 /* run the main loop */
261   - main_loop(db, /*import_task_id, */ insert_data_stmt, update_data_stmt, csv_line_reader, start_time, columns, current_line, offset, offset_base)
  317 + with import_line_values =
  318 + if import_type = "insert_or_update" then
  319 + (List(String) row) |-> insert_or_update_data_to_table(insert_data_stmt, update_data_stmt, true, columns, row)
  320 + else if import_type = "insert" then
  321 + (List(String) row) |-> insert_or_update_data_to_table(insert_data_stmt, update_data_stmt, false, columns, row)
  322 + else if import_type = "update" then
  323 + (List(String) row) |-> update_data_to_table(update_data_stmt, columns, row)
  324 + else
  325 + (List(String) row) |-> insert_or_update_data_to_table(insert_data_stmt, update_data_stmt, true, columns, row),
  326 +
  327 + main_loop(db, import_line_values, csv_line_reader, start_time, columns, current_line, offset, offset_base)
262 328 }
263 329 }
264 330 // }
265 331 .
266 332  
267   -
268 333 public define Result(String, String)
269 334 hkc_import_execute
270 335 (
... ... @@ -282,7 +347,9 @@ public define Result(String, String)
282 347 with separator = get_String(lwa, "csv_sep", ";"),
283 348 with csv_db_columns = get_columns_list(lwa),
284 349 with columns = get_db_columns(csv_db_columns, []),
  350 + column_key = get_String(lwa, "column_key", ""),
285 351 table_name = get_String(lwa, "table_name", ""),
  352 + import_type = get_String(lwa, "import_type", "insert_or_update"),
286 353 with start_time = unow,
287 354 offset_base = (Int)0,
288 355 skip_first_line = get_Bool(lwa, "hk_remove_csv_header", true),
... ... @@ -306,9 +373,8 @@ public define Result(String, String)
306 373 forget(csv_line_reader(unique))
307 374 else
308 375 unique);
309   - with status = import_csv_to_db_transaction(db, table_name, csv_line_reader, columns, start_time, offset_base),
  376 + with status = import_csv_to_db_transaction(db, table_name, csv_line_reader, import_type, columns, column_key, start_time, offset_base),
310 377 ok("imported")
311   -
312 378 }
313 379 }
314 380 .
... ...
view/types/hk_form_entry.anubis
... ... @@ -24,7 +24,7 @@ public type HK_Form_Entry: //legacy VT_Edit
24 24 information (String s_name, String c_name, String v_name, Int width, HK_Help_Text help), //s_name = show_name for translation, v_name = string to show
25 25 text (String s_name, String c_name, String value, HK_Help_Text help), //s_name = show_name for translation, c_name = table column name
26 26 password (String s_name, String c_name, HK_Help_Text help), //s_name = show_name for translation, c_name = table column name
27   - foreign_text(String s_name, String c_name, DB_id selected, HK_Form_Selector selector, HK_Help_Text help),
  27 + foreign_text(String s_name, String c_name, DB_id selected, String f_table_name, HK_Form_Selector selector, HK_Help_Text help),
28 28 foreign_text_search(String s_name, String c_name, DB_id selected, String f_table_name, List(String) search_fields, HK_Help_Text help),
29 29 choices_text(String s_name, String c_name, String selected, HK_Form_Selector selector, HK_Help_Text help),
30 30 text_area (String s_name, String c_name, String value, HK_Text_Field_Attr area_att, HK_Help_Text help), //s_name = show_name for translate, c_name = table column name
... ... @@ -41,7 +41,7 @@ public type HK_Form_Entry: //legacy VT_Edit
41 41 .
42 42  
43 43 public define HK_Form_Entry text (String s_name, String c_name, String value) = text (s_name, c_name, value, no_help_text).
44   -public define HK_Form_Entry foreign_text(String s_name, String c_name, DB_id selected, HK_Form_Selector selector) = foreign_text(s_name, c_name, selected, selector, no_help_text).
  44 +public define HK_Form_Entry foreign_text(String s_name, String c_name, DB_id selected, String foreign_table_name, HK_Form_Selector selector) = foreign_text(s_name, c_name, selected, foreign_table_name, selector, no_help_text).
45 45 public define HK_Form_Entry text_area (String s_name, String c_name, String value) = text_area (s_name, c_name, value, none, no_help_text).
46 46 public define HK_Form_Entry boolean (String s_name, String c_name, Bool value) = boolean (s_name, c_name, value, no_help_text).
47 47 public define HK_Form_Entry integer (String s_name, String c_name, Int value) = integer (s_name, c_name, value, no_help_text).
... ...
view/types/hk_view.anubis
... ... @@ -91,16 +91,17 @@ public type VT_view_row_header:
91 91 public type VT_view_row:
92 92 vt_view_row(Int db_id, List(VT_view_entry) list).
93 93  
  94 +/*
94 95 public type VT_View_DB_Calls:
95 96 vt_view_db_calls(
96   - (SQLite3DataBase db, String clause) -> Int get_count,
97   - (SQLite3DataBase db, HK_Referer referer, String clause, String order_by) -> JsonMember get_rows_json
  97 + (SQLite3DataBase db, String clause) -> Int get_count,
  98 + (SQLite3DataBase db, HK_Referer referer, String clause, String order_by) -> JsonValue get_rows_json
98 99 // (SQLite3DataBase db, String clause) -> List(VT_view_row) get_rows
99 100 )
100   -.
  101 +. */
101 102  
102 103 public type VT_view:
103   - vt_view(String table_name, String view_name, VT_view_model view_model, VT_view_row_header header, VT_View_DB_Calls db_calls).
  104 + vt_view(String table_name, String view_name, VT_view_model view_model, VT_view_row_header header).
104 105  
105 106  
106 107 public type HK_Form_action:
... ...
view/view_apps_renderer.anubis
... ... @@ -35,19 +35,19 @@ define List(HTML_Row(HTML_Off_Form))
35 35 cell(
36 36 sequence([
37 37 partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id("edit_table_dlg_ajax"), "'table_name="+table_name+"'"))], "", [])),
38   - text(_T("ADD")),
  38 + actioner(link([core_attrs([event(onclick, jq_dialog_open(dialog_id("edit_table_dlg_ajax"), "'table_name="+table_name+"'"))])],_T("ADD")), no_action, [])
39 39 ])
40 40 ),
41 41 cell(
42 42 sequence([
43 43 partial(img_button(icn16_view_list, hkc_list_view, [("table_name",table_name)])),
44   - text(_T("LIST"))
  44 + actioner(link(_T("LIST")), hkc_list_view, [("table_name",table_name)])
45 45 ])
46 46 ),
47 47 cell(
48 48 sequence([
49 49 partial(img_button("icons/16x16/table_import.png", hkc_import_dropzone, [("table_name",table_name)])),
50   - text(_T("CSV_IMPORT"))
  50 + actioner(link(_T("CSV_IMPORT")), hkc_import_dropzone, [("table_name",table_name)])
51 51 ])
52 52 ),
53 53 cell(text(_T("RECORDS_COUNT")+" ")),
... ...
view/view_rows_import.anubis
... ... @@ -10,10 +10,12 @@ read locale/L3.anubis
10 10 read locale/L3LanguageInfo.anubis //date and time formating
11 11 read system/data_io.anubis
12 12 read tools/line_reader.anubis
  13 +read tools/basis.anubis
13 14  
14 15 read calexium_lib/database/csv_tools.anubis
15 16 read calexium_lib/web/CXM_making_a_web_site.anubis
16 17 read calexium_lib/web/CXM_jquery.anubis
  18 +read calexium_lib/web/CXM_form.anubis
17 19 read calexium_lib/web/jQuery/CXM_jquery_button.anubis
18 20 read calexium_lib/web/widgets/css_helper.anubis
19 21 read calexium_lib/web/widgets/icons_set.anubis
... ... @@ -36,6 +38,18 @@ public define List((List(CoreAttrs), WebArgValue, String))
36 38  
37 39  
38 40  
  41 +public define List((List(CoreAttrs), WebArgValue, String))
  42 + csv_import_type_combo
  43 + (
  44 + (String) -> String _T
  45 + )
  46 + =
  47 + (List((List(CoreAttrs), WebArgValue, String)))[
  48 + ([],wav("insert_or_update"), _T("INSERT_OR_UPDATE")),
  49 + ([],wav("insert"), _T("INSERT")),
  50 + ([],wav("update"), _T("UPDATE")),
  51 + ].
  52 +
39 53 public define HTML_Partial_Content
40 54 import_zone
41 55 (
... ... @@ -140,7 +154,7 @@ define List(HTML_Row(HTML_In_Form))
140 154 text(_T("IGNORED_COLUMN")),
141 155 hidden(html_Id("hk_"+hidden_name+"_input"), wan(""), wav(hidden_name))
142 156 ])),
143   - cell([class("icon ")],image([class("dnd-dst-btn")],"/icons/16x16/delete_cross.png",""))
  157 + cell(image([class("dnd-dst-btn")],"/icons/16x16/delete_cross.png",""))
144 158 ])
145 159 . so_far], index+1, _T)
146 160 }.
... ... @@ -173,6 +187,7 @@ public define HTML_Partial_Content
173 187 (String) -> String _T,
174 188 )=
175 189 partial_content([css(css_file("css/cxm/cxm_dnd.css")),
  190 + css(css_file("css/changelists.css")),
176 191 js(js_file("js/cxm/cxm_dnd.js")),
177 192 js(js_file("js/data_import.js"))
178 193 ],
... ... @@ -188,6 +203,8 @@ public define HTML_Partial_Content
188 203 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)),)]),
189 204 row([], [cell(empty), cell(text(_T("FILE_ENCODING"))), cell(text("choose encoding"))]),
190 205 row([], [cell(empty), cell(text(_T("REMOVE_CSV_HEADER"))), cell(check_box([], no_label, html_Id(""), wan("hk_remove_csv_header"), wav("1"), true))]),
  206 + 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)),)]),
  207 +
191 208 // row([], [cell(empty), cell(text(_T("OPT_OUT"))), cell(check_box([], no_label, html_Id(""), wan("import_opt_out"), wav("1"), false))])] //end of row
192 209 ]),
193 210 br,
... ... @@ -202,10 +219,7 @@ public define HTML_Partial_Content
202 219  
203 220 div_empty([class("clear")])
204 221 ])),
205   - //partial(jquery_button(jquery_img_button(icn16_cross, _T("CANCEL"), "", jQuery_actioner(same, jqlink, "go_edit_mailing_list&list_id="+list_id.id), left))),
206   - //partial(jquery_button(jquery_img_button(icn16_check, _T("IMPORT"), "", jQuery_actioner(same, jqform, "import_csv_form"), left)))
207   -
208   - ])), //end of sequence in form
  222 + ])), //end of sequence in form
209 223 // )])
210 224 partial(jquery_button(jquery_img_button(icn16_cross, _T("CANCEL"), "", jQuery_actioner(same, jqlink(cancel_action)), left))),
211 225 partial(img_submit_button(_T("IMPORT"), "import_csv_form"))
... ...
view/view_table_manager_types.anubis
... ... @@ -12,6 +12,10 @@ transmit hayamiki_lib/view/types/hk_filter.anubis
12 12 transmit calexium_lib/web/CXM_common.anubis
13 13 read hayamiki_lib/types/hayamiki.anubis
14 14  
  15 +
  16 +read calexium_lib/web/CXM_common.anubis
  17 +read calexium_lib/database/db_types.anubis
  18 +
15 19 public type VTM_edit:
16 20 vtm_edit(String table_name, (SQLite3DataBase db, HK_Form_action action, String edit_view_name) -> HK_Form get_edit).
17 21  
... ... @@ -40,8 +44,8 @@ public type HK_Table_controller:
40 44 (SQLite3DataBase db, List(Web_arg) lwa) -> Maybe(One) write_from_fields,
41 45 //Read
42 46 (SQLite3DataBase db, String clause) -> Int get_count,
43   - (SQLite3DataBase db, HK_Referer referer, String clause, String order_by) -> JsonMember get_rows_json,
44   -
  47 + (SQLite3DataBase db, List(String) columns, DB_id) -> JsonValue get_one_json,
  48 + (SQLite3DataBase db, List(String) columns, HK_Referer referer, String clause, String order_by) -> JsonValue get_rows_json,
45 49 //Update
46 50 //Delete
47 51 (SQLite3DataBase db, List(Int) l_int) -> Maybe(One) delete
... ...
view/view_table_renderer.anubis
... ... @@ -18,6 +18,7 @@ read system/string.anubis
18 18 read locale/L3.anubis
19 19 read tools/basis.anubis
20 20 read tools/list.anubis
  21 +read tools/printable_tree.anubis
21 22 read data_base/sqlite.anubis
22 23 read system_colors/rgb.anubis
23 24 read system/convert.anubis
... ... @@ -97,12 +98,17 @@ public define HK_Filter
97 98 get_filter_from_name
98 99 (
99 100 VTM_view vtm_v, //virtual table manager view
100   - String view_name, //
101   - String filter_name
  101 + String view_name, //view name where belonging the filters
  102 + String filter_name //the filter name to get
102 103 )=
103 104 with all_view_name = vtm_v.get_all_view_name(unique),
104 105 with filters = get_view_filters(view_name, all_view_name),
105   -
  106 +
  107 + //we don't have any filter name to search for, hence we get the first entry
  108 + if filter_name = "" then
  109 + force_nth(0, filters, hk_filter("", ""))
  110 + else
  111 + //else try to get the filter according to his name
106 112 get_filter_from_name(filters, filter_name)
107 113 .
108 114  
... ... @@ -287,9 +293,8 @@ define String
287 293 autoResizing: { compact: true, resetWidthOrg: true },
288 294 autoresizeOnLoad: true,
289 295 autowidth:true,
290   - /*idPrefix: '_g_"+uid+"_',*/
291   - pager: '#"+uid+"_pager',
292   - pager: true,
  296 + viewrecords: true,
  297 + /*pager: true,*/
293 298 toppager: true,
294 299  
295 300 /*shrinkToFit:false,*/
... ... @@ -400,7 +405,7 @@ url:'?aws_controller=hk_c&aws_action=grid_view&table_name="+rows.table_name+"&vi
400 405 return $(cellObject.html()).css(\"backgroundColor\").substring(1);
401 406 }
402 407 function formatPhone(cellValue, options, rowObject) {
403   - var phoneInput = '<span class=\"hk_phone_call\"><img src=\\"/icons/16x16/phone.png\\" onclick=\"hk_phone_call(this);\">' + cellValue + '</span>';
  408 + var phoneInput = '<span class=\"hk_phone_call\"><img data-phone-number=\"'+cellValue+'\" src=\\"/icons/16x16/phone.png\\" onclick=\"hk_phone_call(this);\">' + cellValue + '</span>';
404 409 return phoneInput;
405 410 }
406 411 function unformatPhone(cellValue, options, cellObject) {
... ... @@ -409,7 +414,7 @@ url:&#39;?aws_controller=hk_c&amp;aws_action=grid_view&amp;table_name=&quot;+rows.table_name+&quot;&amp;vi
409 414 return ret;
410 415 }
411 416 function formatEmail(cellValue, options, rowObject) {
412   - var phoneInput = '<span class=\"hk_send_email\"><img src=\\"/icons/16x16/email_edit.png\\" onclick=\"hk_send_email(this);\">' + cellValue + '</span>';
  417 + var phoneInput = '<span class=\"hk_send_email\"><img data-email=\"'+cellValue+'\" src=\\"/icons/16x16/email_edit.png\\" onclick=\"hk_send_email(this);\">' + cellValue + '</span>';
413 418 return phoneInput;
414 419 }
415 420 function unformatEmail(cellValue, options, cellObject) {
... ... @@ -422,7 +427,7 @@ url:&#39;?aws_controller=hk_c&amp;aws_action=grid_view&amp;table_name=&quot;+rows.table_name+&quot;&amp;vi
422 427 div([],
423 428 sequence([
424 429 table([core_attrs([id(uid+"_grid")])],[]),
425   - div_empty([id(uid+"_pager")])
  430 + //DR 20170528 div_empty([id(uid+"_pager")])
426 431 ])
427 432 )
428 433 )
... ... @@ -623,10 +628,26 @@ public define List(CXM_Form_Field)
623 628 password_entries
624 629 ],
625 630  
626   - foreign_text(s_name, c_name, value, select, help) then
627   - [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)],
628   - foreign_text_search(s_name, c_name, select, table_name, fields, help) then
629   - [raw_in_form(literal("<input id=\"acb_"+c_name+"\" type=\"text\">"))]
  631 + foreign_text(s_name, c_name, value, foreign_table_name, select, help) then
  632 + with uid = generate_random_string(20)+"_",
  633 +
  634 + [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),
  635 +
  636 + partial(jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&sub_dialog=true&table_name="+foreign_table_name)))),
  637 + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
  638 + ],
  639 + foreign_text_search(s_name, c_name, select, foreign_table_name, fields, help) then
  640 + with uid = generate_random_string(20)+"_",
  641 + [
  642 + raw_in_form(sequence([
  643 + literal(to_String(format_label(label(_T(s_name), no_help), html_Id("")))+
  644 + "<input class=\"in\" id=\"acb_"+c_name+"\" data-init_record=\""+select+"\" size=\"50\" type=\"text\">"),
  645 + partial(jq_dialog_create(dialog_id(uid+foreign_table_name+"_dlg_ajax"), ajax(controller_action("hk_c", "ajax_edit_table&sub_dialog=true&table_name="+foreign_table_name)))),
  646 + partial(img_button(icn16_add, [event(onclick, jq_dialog_open(dialog_id(uid+foreign_table_name+"_dlg_ajax")))], "", [])),
  647 + ])
  648 + ),
  649 + help_line(help, _T)]
  650 +
630 651 choices_text(s_name, c_name, value, select, help) then
631 652 [selector_c([],label(_T(s_name), no_help), html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
632 653 text_area(s_name, c_name, value, txt_editor, help) then
... ... @@ -649,9 +670,9 @@ public define List(CXM_Form_Field)
649 670 color( s_name, c_name, value, help) then
650 671 [input([class("jscolor")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
651 672 phone( s_name, c_name, value, help) then
652   - [input([class("hk_input_phone")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
  673 + [phone_input([event(onclick, "hk_phone_call(this)")], [class("hk_input_phone")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
653 674 email( s_name, c_name, value, help) then
654   - [input([class("hk_input_email")], label(_T(s_name), no_help), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
  675 + [email_input([event(onclick, "hk_send_email(this)")], [class("hk_input_email")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
655 676 },
656 677 edit_form_lines(db, fk_clause, table_referer, _T, t, new_entry, reverse(line)+so_far)
657 678 }.
... ... @@ -710,6 +731,26 @@ define List(String)
710 731 _lines)
711 732 .
712 733  
  734 +define String
  735 + ajax_combo_init_parameter
  736 + (
  737 + String f_table, //db table name
  738 + String c_name, //column name in the table
  739 + List(String) s_fields //search fields
  740 + )=
  741 +"$('#acb_"+c_name+"').ajaxComboBox( '?aws_controller=hk_c&aws_action=combo_search',
  742 + {
  743 + lang: 'fr',
  744 + per_page: 15,
  745 + db_table: '"+f_table+"',
  746 + button_img: 'ajax-combobox/btn.png',
  747 + field: '"+force_nth(0, s_fields, "name")+"',
  748 + search_field: '"+join(", ", s_fields)+"',
  749 + hidden_name: '"+c_name+"',
  750 + show_string: '"+join(", ", s_fields)+"',
  751 + and_or: 'OR'
  752 + });"
  753 +.
713 754  
714 755 define List(String)
715 756 _get_combo_header
... ... @@ -724,15 +765,8 @@ define List(String)
724 765 if cell is
725 766 {
726 767 hk_form_table_cell(_, form_entry) then
727   - if form_entry is foreign_text(s_name, c_name, value, select, help) then
728   - with result =
729   -"$('#acb_"+c_name+"').ajaxComboBox( '?aws_controller=hkc&aws_action=combo_action',
730   - {
731   - lang: 'fr',
732   - db_table: '"+table_name+"',
733   - button_img: 'ajax-combobox/btn.png'
734   - });",
735   - [result]
  768 + if form_entry is foreign_text_search(s_name, c_name, select, f_table, s_fields, help) then
  769 + [ajax_combo_init_parameter(f_table, c_name, s_fields)]
736 770 else
737 771 [],
738 772 hk_form_table_cell_table(_, t_lines) then
... ... @@ -755,6 +789,7 @@ define List(HTML_Head_Tag)
755 789 else
756 790 []
757 791 .
  792 +
758 793 define List(HTML_Head_Tag)
759 794 get_combo_header
760 795 (
... ... @@ -770,6 +805,38 @@ define List(HTML_Head_Tag)
770 805 else
771 806 []
772 807 .
  808 +
  809 +define List(String)
  810 + _get_combo_header
  811 + (
  812 + String table_name,
  813 + List(HK_Form_Entry) _entries
  814 + )=
  815 + map_append((HK_Form_Entry entry)
  816 + |->
  817 + if entry is foreign_text_search(s_name, c_name, select, f_table, s_fields, help) then
  818 + [ajax_combo_init_parameter(f_table, c_name, s_fields)]
  819 + else
  820 + []
  821 + ,
  822 + _entries)
  823 +.
  824 +
  825 +define List(HTML_Head_Tag)
  826 + get_combo_header
  827 + (
  828 + String table_name,
  829 + List(HK_Form_Entry) _lines
  830 + )=
  831 + with result = _get_combo_header(table_name, _lines),
  832 + if length(result) > 0 then
  833 + [js(js_file("ajax-combobox/js/jquery.ajax-combobox.js")),
  834 + css(css_file("ajax-combobox/css/jquery.ajax-combobox.css")),
  835 + js_inline(jquery_ready(join("",result)))
  836 + ]
  837 + else
  838 + []
  839 + .
773 840  
774 841 public define HTML_Partial_Content
775 842 renderer_edit_list_form
... ... @@ -793,6 +860,8 @@ public define HTML_Partial_Content
793 860 //true if need to create row or false for updating
794 861 with create = if get_String(lwa, "id","none") = "none" then true else false,
795 862 with id = get_String(lwa, "id","none"),
  863 + with sub_dialog = get_String(lwa, "sub_dialog", "false"),
  864 +
796 865 with button_name = if create then _T("CREATE") else _T("UPDATE"),
797 866 with button_name_and_new = if create then _T("CREATE_AND_EDIT_NEW") else _T("UPDATE_AND_EDIT_NEW"),
798 867  
... ... @@ -807,13 +876,14 @@ public define HTML_Partial_Content
807 876 $('#my-awesome-dropzone').dropzone(); ")),
808 877 ]+
809 878 jq_datetimepicker_init(lang) +
810   - get_editor_header(list_entries), //add editor header if need. Like init ck_editor
  879 + get_editor_header(list_entries)+ //add editor header if need. Like init ck_editor
  880 + get_combo_header(table_name, list_entries),
811 881 sequence([
812 882 cxm_form( table_name, lwa,
813 883 [ one_line_fields([
814   - submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]),
815   - submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
816   - submit(hkc_cancel, failure, _T("CANCEL"))
  884 + submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name), ("sub_dialog", sub_dialog)]),
  885 + submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name), ("sub_dialog", sub_dialog)]),
  886 + submit(hkc_cancel, failure, _T("CANCEL"), [("sub_dialog", sub_dialog)])
817 887 ]),
818 888 hr
819 889 ]+edit_form_lines(db, "", table_referer, _T, list_entries, create, [])
... ... @@ -834,9 +904,9 @@ public define HTML_Partial_Content
834 904 ,list_tabs))+
835 905 [ hr,
836 906 one_line_fields([
837   - submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name)]),
838   - submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name)]),
839   - submit(hkc_cancel, failure, _T("CANCEL"))
  907 + submit(if create then hkc_save_row else hkc_update_row, failure, button_name, [("table_name", table_name), ("sub_dialog", sub_dialog)]),
  908 + submit(if create then hkc_save_row_and_new else hkc_update_row_and_new, failure, button_name_and_new, [("table_name", table_name), ("sub_dialog", sub_dialog)]),
  909 + submit(hkc_cancel, failure, _T("CANCEL"), [("sub_dialog", sub_dialog)])
840 910 ])
841 911 ]
842 912 ),
... ... @@ -887,11 +957,12 @@ public define List(CXM_Form_Field)
887 957 password_entries
888 958 ],
889 959  
890   - foreign_text(s_name, c_name, value, select, help) then
  960 + foreign_text(s_name, c_name, value, foreign_table_name, select, help) then
891 961 [selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, table_referer, fk_clause), success(init(to_String(value))), mandatory), help_line(help, _T)],
892   - //[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)],
893   - foreign_text_search(s_name, c_name, select, f_table, s_fields, help) then
894   - [raw_in_form(literal("<input id=\"acb_"+c_name+"\" type=\"text\">"))],
  962 +
  963 + foreign_text_search(s_name, c_name, select, foreign_table_name, s_fields, help) then
  964 + [raw_in_form(literal("<input class=\"in\" id=\"acb_"+c_name+"\" data-init_record=\""+select+"\" size=\"50\" type=\"text\">"))]
  965 +// [raw_in_form(literal("<input class=\"in\" id=\"acb_"+c_name+"\" type=\"text\">"))],
895 966  
896 967 choices_text(s_name, c_name, value, select, help) then
897 968 [selector_c([],no_label, html_Id(""), wan(c_name), 1, select.get(db, no_referer, ""), success(init(value)), mandatory), help_line(help, _T)],
... ... @@ -915,9 +986,9 @@ public define List(CXM_Form_Field)
915 986 color( s_name, c_name, value, help) then
916 987 [input([class("jscolor")], no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
917 988 phone( s_name, c_name, value, help) then
918   - [input([class("hk_input_phone")], no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
  989 + [phone_input([event(onclick, "hk_phone_call(this)"), class("phone_click")], [class("hk_input_phone")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
919 990 email( s_name, c_name, value, help) then
920   - [input([class("hk_input_email")], no_label, wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
  991 + [email_input([event(onclick, "hk_send_email(this)"), class("email_click")], [class("hk_input_email")], label(_T(s_name), no_help), html_Id(c_name), wan(c_name), init(not_null_String(value)), narrow, mandatory), help_line(help, _T)],
921 992  
922 993 }.
923 994  
... ...