@yuneta/gobj-ui 7.26.42 → 7.26.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +227 -36
  2. package/dist/gobj-ui.cjs.js +770 -192
  3. package/dist/gobj-ui.es.js +770 -192
  4. package/package.json +2 -2
  5. package/scripts/validate-locales.mjs +355 -63
  6. package/src/c_yui_form.js +268 -155
  7. package/src/c_yui_node.js +51 -7
  8. package/src/c_yui_schema_editor.js +49 -3
  9. package/src/c_yui_shell.css +4 -1
  10. package/src/c_yui_shell.js +28 -2
  11. package/src/c_yui_window.js +373 -62
  12. package/src/c_yui_window_manager.js +74 -2
  13. package/src/escape_taken.js +58 -0
  14. package/src/form_close_asks_for_edits.wiring.test.js +6 -3
  15. package/src/form_json_editor_names.js +3 -1
  16. package/src/form_json_editor_names.wiring.test.js +8 -4
  17. package/src/form_json_expand.wiring.test.js +6 -3
  18. package/src/form_json_field.wiring.test.js +8 -4
  19. package/src/form_label_i18n.wiring.test.js +10 -5
  20. package/src/form_table_edits_ask.wiring.test.js +18 -8
  21. package/src/form_table_rearm.wiring.test.js +13 -5
  22. package/src/form_table_rows.wiring.test.js +533 -0
  23. package/src/form_table_validator.wiring.test.js +8 -4
  24. package/src/form_template_field.wiring.test.js +6 -3
  25. package/src/g6_long_press_clock.test.js +8 -3
  26. package/src/i18n_key_functions.js +63 -25
  27. package/src/i18n_key_functions.test.js +230 -8
  28. package/src/modal_guard_back.wiring.test.js +53 -0
  29. package/src/named_controls.wiring.test.js +53 -13
  30. package/src/node_nav_events.wiring.test.js +93 -1
  31. package/src/schema_editor_diagram_click.wiring.test.js +277 -0
  32. package/src/shell_dialog_names.wiring.test.js +149 -0
  33. package/src/shell_escape_taken.wiring.test.js +142 -0
  34. package/src/shell_focus_trap.js +30 -2
  35. package/src/shell_focus_trap.test.js +90 -6
  36. package/src/shell_modals.js +90 -19
  37. package/src/table_editor_name.wiring.test.js +10 -5
  38. package/src/treedb_column_title.wiring.test.js +8 -4
  39. package/src/treedb_graph_writes.wiring.test.js +6 -3
  40. package/src/treedb_json_drill.wiring.test.js +6 -3
  41. package/src/uplot_add_serie.test.js +6 -3
  42. package/src/uplot_ink.test.js +8 -4
  43. package/src/window_dialog.wiring.test.js +486 -0
  44. package/src/window_dock_band.wiring.test.js +189 -0
  45. package/src/window_rect_rounding.wiring.test.js +121 -0
  46. package/src/yui_tabulator_i18n.js +31 -1
  47. package/src/yui_tabulator_i18n.test.js +46 -0
package/src/c_yui_form.js CHANGED
@@ -30,7 +30,6 @@ import {
30
30
  kwid_new_dict,
31
31
  sprintf,
32
32
  template_get_field_desc,
33
- str_in_list,
34
33
  gobj_write_bool_attr,
35
34
  gobj_short_name,
36
35
  empty_string,
@@ -180,8 +179,9 @@ let PRIVATE_DATA = {
180
179
  * filled): what a table says then is no change of the reader's
181
180
  * (see create_tabulator's dataChanged). */
182
181
  loading_rows: 0,
183
- /* table_id -> WeakRef of its element: EV_ADD_TABLE_ROW names a
184
- * table by id (a kw is plain json), see table_identity(). */
182
+ /* table_id -> WeakRef of its element: EV_ADD_TABLE_ROW and
183
+ * EV_LOAD_TABLE_ROWS name a table by id (a kw is plain json), see
184
+ * table_identity(). */
185
185
  tables: null,
186
186
  table_seq: 0,
187
187
  /* The menus of the json editors are to be named: posted once, and
@@ -554,18 +554,17 @@ function cell_icon(icon_class, key)
554
554
 
555
555
  /************************************************************
556
556
  * The identity of a table element, for the kw of
557
- * EV_ADD_TABLE_ROW: a kw is plain json, and an element (with its
558
- * `.tabulator`, circular) broke the `machine` trace that dumps it.
559
- * Given on first use and kept on the element; the registry holds
560
- * it weakly, so a nested table re-built by its row formatter is
561
- * not kept alive by it.
557
+ * EV_ADD_TABLE_ROW and EV_LOAD_TABLE_ROWS: a kw is plain json,
558
+ * and an element (with its `.tabulator`, circular) broke the
559
+ * `machine` trace that dumps it. Given on first use and kept on
560
+ * the element; the registry holds it weakly, so a nested table
561
+ * whose row is gone is not kept alive by it.
562
562
  ************************************************************/
563
563
  function table_identity(gobj, $table)
564
564
  {
565
565
  if(!$table.yui_table_id) {
566
566
  let priv = gobj.priv;
567
- /* The entries of tables the collector already took go first: a
568
- * nested table rebuilt by its row formatter leaves one behind. */
567
+ /* The entries of tables the collector already took go first. */
569
568
  for(let [id, ref] of priv.tables) {
570
569
  if(!ref.deref()) {
571
570
  priv.tables.delete(id);
@@ -595,6 +594,69 @@ function find_table(gobj, table_id)
595
594
  return $table;
596
595
  }
597
596
 
597
+ /************************************************************
598
+ * Destroy one third-party widget, saying why it could not be.
599
+ ************************************************************/
600
+ function destroy_widget(gobj, what, widget)
601
+ {
602
+ try {
603
+ /* vanilla-jsoneditor 3 destroys asynchronously: its failure
604
+ * is a rejected promise, which no try/catch sees. */
605
+ let r = widget.destroy();
606
+ if(r && typeof r.then === "function") {
607
+ r.catch((e) => {
608
+ log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
609
+ });
610
+ }
611
+ } catch(e) {
612
+ log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
613
+ }
614
+ }
615
+
616
+ /************************************************************
617
+ * A table element that is gone: its identity is no table now,
618
+ * and what was waiting to be loaded in it never will be.
619
+ ************************************************************/
620
+ function forget_table(gobj, $table)
621
+ {
622
+ $table.yui_pending_rows = null;
623
+ if($table.yui_table_id && gobj.priv && gobj.priv.tables) {
624
+ gobj.priv.tables.delete($table.yui_table_id);
625
+ }
626
+ }
627
+
628
+ /************************************************************
629
+ * Destroy the nested tables a row of a table built (its row
630
+ * formatter keeps them on the row's element), theirs first.
631
+ * Tabulator takes the row's DOM away when the row goes -- a
632
+ * reload, an undo, a deleted row -- and destroys nothing in it:
633
+ * each nested table stayed in Tabulator's registry, with its
634
+ * observers, for the life of the page.
635
+ ************************************************************/
636
+ function destroy_row_tables(gobj, $row)
637
+ {
638
+ let nested = $row.yui_nested || [];
639
+ $row.yui_nested = null;
640
+ for(let $nested of nested) {
641
+ if($nested.tabulator) {
642
+ destroy_rows_tables(gobj, $nested.tabulator);
643
+ destroy_widget(gobj, "nested table", $nested.tabulator);
644
+ $nested.tabulator = null;
645
+ }
646
+ forget_table(gobj, $nested);
647
+ }
648
+ }
649
+
650
+ /************************************************************
651
+ * Destroy the nested tables of every row of a table.
652
+ ************************************************************/
653
+ function destroy_rows_tables(gobj, tabulator)
654
+ {
655
+ for(let row of tabulator.getRows()) {
656
+ destroy_row_tables(gobj, row.getElement());
657
+ }
658
+ }
659
+
598
660
  /************************************************************
599
661
  * Destroy the third-party widgets the form built. Removing
600
662
  * their DOM is not enough: Tom Select keeps listeners on
@@ -605,46 +667,21 @@ function find_table(gobj, table_id)
605
667
  ************************************************************/
606
668
  function destroy_widgets(gobj, $container)
607
669
  {
608
- let destroy = (what, widget) => {
609
- try {
610
- /* vanilla-jsoneditor 3 destroys asynchronously: its failure
611
- * is a rejected promise, which no try/catch sees. */
612
- let r = widget.destroy();
613
- if(r && typeof r.then === "function") {
614
- r.catch((e) => {
615
- log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
616
- });
617
- }
618
- } catch(e) {
619
- log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
620
- }
621
- };
622
- let forget = ($el) => {
623
- if($el.yui_table_id && gobj.priv && gobj.priv.tables) {
624
- gobj.priv.tables.delete($el.yui_table_id);
625
- }
626
- };
627
- $container.querySelectorAll('.yui-tabulator-table-nested').forEach(($el) => {
628
- if($el.tabulator) {
629
- destroy("nested table", $el.tabulator);
630
- $el.tabulator = null;
631
- }
632
- forget($el);
633
- });
634
670
  $container.querySelectorAll('.yui-form-data-input').forEach(($el) => {
635
671
  if($el.tom_select) {
636
- destroy("select", $el.tom_select);
672
+ destroy_widget(gobj, "select", $el.tom_select);
637
673
  $el.tom_select = null;
638
674
  }
639
675
  if($el.jsoneditor) {
640
- destroy("json editor", $el.jsoneditor);
676
+ destroy_widget(gobj, "json editor", $el.jsoneditor);
641
677
  $el.jsoneditor = null;
642
678
  }
643
679
  if($el.tabulator) {
644
- destroy("table", $el.tabulator);
680
+ destroy_rows_tables(gobj, $el.tabulator);
681
+ destroy_widget(gobj, "table", $el.tabulator);
645
682
  $el.tabulator = null;
683
+ forget_table(gobj, $el);
646
684
  }
647
- forget($el);
648
685
  });
649
686
  }
650
687
 
@@ -1481,7 +1518,6 @@ function create_form_field(
1481
1518
  {
1482
1519
  table_id: table_identity(gobj, $add_table),
1483
1520
  record: {},
1484
- loading: false,
1485
1521
  },
1486
1522
  gobj
1487
1523
  );
@@ -2184,11 +2220,30 @@ function create_coordinates(gobj, attrs)
2184
2220
 
2185
2221
  /******************************************************************
2186
2222
  * Create tabulator
2223
+ *
2224
+ * A row builds its nested tables the first time it is drawn, each
2225
+ * loaded from the row's own data, and keeps them on its element
2226
+ * (`yui_nested`) until the row goes (destroy_row_tables). A row
2227
+ * drawn AGAIN -- a forced redraw, a column rebuilt -- has its
2228
+ * children taken off by Tabulator before its formatter runs: they
2229
+ * are put back as they are. Built anew, they came back empty, and
2230
+ * the old ones stayed alive in Tabulator's registry.
2231
+ *
2232
+ * A load that comes before the table is built waits for its
2233
+ * `tableBuilt`, ONE per table (`yui_pending_rows`): a later load
2234
+ * replaces it, a clear drops it. Each load used to hang a listener
2235
+ * of its own, so two loads before the build drew the rows twice.
2187
2236
  ******************************************************************/
2188
2237
  function create_tabulator(gobj, $extend, name, template)
2189
2238
  {
2239
+ /* A click selects a row only when the form is `selectable` AND its
2240
+ * table selects rows (`selectableRows`, off unless a host sets it in
2241
+ * `tabulator_settings`): toggleSelect() on a table that does not
2242
+ * select throws. */
2190
2243
  function get_selectable_state(row) {
2191
- return gobj_write_bool_attr(gobj, "selectable");
2244
+ let selectable_rows = tabulator.options.selectableRows;
2245
+ return gobj_read_bool_attr(gobj, "selectable") &&
2246
+ (selectable_rows === true || typeof selectable_rows === "number");
2192
2247
  }
2193
2248
 
2194
2249
  $extend.template = template;
@@ -2222,6 +2277,15 @@ function create_tabulator(gobj, $extend, name, template)
2222
2277
 
2223
2278
  if(sub_elements.length > 0) {
2224
2279
  tabulator_settings.rowFormatter = function(row) {
2280
+ let $row = row.getElement();
2281
+ if($row.yui_nested) { // drawn again: its tables, rows and all
2282
+ for(let $nested of $row.yui_nested) {
2283
+ $row.appendChild($nested);
2284
+ }
2285
+ return;
2286
+ }
2287
+ $row.yui_nested = [];
2288
+ let data = row.getData() || {};
2225
2289
  for(let sub_element of sub_elements) {
2226
2290
  let extend = ['div',
2227
2291
  {
@@ -2233,9 +2297,10 @@ function create_tabulator(gobj, $extend, name, template)
2233
2297
  $extend.tabulator = create_tabulator(
2234
2298
  gobj, $extend, sub_element.name, sub_element.template
2235
2299
  );
2236
-
2237
- // Append the container to the row's element
2238
- row.getElement().appendChild($extend);
2300
+ $row.appendChild($extend);
2301
+ $row.yui_nested.push($extend);
2302
+ let rows = data[sub_element.name];
2303
+ load_tabulator_data(gobj, $extend, is_array(rows)? rows : []);
2239
2304
  }
2240
2305
  };
2241
2306
  }
@@ -2280,19 +2345,38 @@ function create_tabulator(gobj, $extend, name, template)
2280
2345
  /* What the READER does to a table -- edits a cell, adds or deletes a
2281
2346
  * row -- reaches the form only through `dataChanged`. Wired here, on
2282
2347
  * every table, nested ones included (a row's formatter builds them
2283
- * whenever the row is drawn), and never switched off: until 7.26.40
2284
- * it was unwired whenever the form was CHANGED and re-wired only by a
2285
- * save, an undo or a load of what is stored, so a form that opened
2286
- * changed (a field its record lacks, filled with its default) never
2287
- * heard its tables -- an edit there was not `edited`, and closing lost
2288
- * it without a question. The rows the form adds itself say nothing
2289
- * (`loading_rows`, ac_add_table_row). */
2348
+ * the first time the row is drawn), and never switched off: until
2349
+ * 7.26.40 it was unwired whenever the form was CHANGED and re-wired
2350
+ * only by a save, an undo or a load of what is stored, so a form that
2351
+ * opened changed (a field its record lacks, filled with its default)
2352
+ * never heard its tables -- an edit there was not `edited`, and
2353
+ * closing lost it without a question. The rows the form loads itself
2354
+ * say nothing (`loading_rows`, ac_load_table_rows). */
2290
2355
  tabulator.on("dataChanged", function() {
2291
2356
  if(gobj.priv.loading_rows > 0) {
2292
2357
  return;
2293
2358
  }
2294
2359
  gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
2295
2360
  });
2361
+ $extend.yui_pending_rows = null;
2362
+ tabulator.on("tableBuilt", function() {
2363
+ let rows = $extend.yui_pending_rows;
2364
+ $extend.yui_pending_rows = null;
2365
+ if(rows && !gobj_is_destroying(gobj)) {
2366
+ gobj_send_event(gobj,
2367
+ "EV_LOAD_TABLE_ROWS",
2368
+ {
2369
+ table_id: table_identity(gobj, $extend),
2370
+ rows: rows
2371
+ },
2372
+ gobj
2373
+ );
2374
+ }
2375
+ });
2376
+ /* A row the reader deletes takes its nested tables with it. */
2377
+ tabulator.on("rowDeleted", function(row) {
2378
+ destroy_row_tables(gobj, row.getElement());
2379
+ });
2296
2380
  /* Tabulator hard-codes `aria-label="Select Row"` on the box its
2297
2381
  * rowSelection formatter draws, and it draws a fresh one on EVERY
2298
2382
  * render -- so this hangs off `renderComplete`, not `tableBuilt`:
@@ -2459,7 +2543,6 @@ function template2columns(gobj, columns, template, sub_elements)
2459
2543
  {
2460
2544
  table_id: table_identity(gobj, $extend),
2461
2545
  record: {},
2462
- loading: false,
2463
2546
  },
2464
2547
  gobj
2465
2548
  );
@@ -2857,6 +2940,27 @@ function getInputValue($input) {
2857
2940
  }
2858
2941
  }
2859
2942
 
2943
+ /************************************************************
2944
+ * The rows of a table as the form saves them: copies, each with
2945
+ * the rows of the nested tables its row holds. A row's
2946
+ * getData() is the row's OWN object: handed out in the save, a
2947
+ * later edit wrote into what the host had been given.
2948
+ ************************************************************/
2949
+ function table_values(tabulator)
2950
+ {
2951
+ let value = [];
2952
+ for(let row of tabulator.getRows()) {
2953
+ let d = json_deep_copy(row.getData());
2954
+ for(let $nested of (row.getElement().yui_nested || [])) {
2955
+ if($nested.tabulator) {
2956
+ d[$nested.getAttribute("name")] = table_values($nested.tabulator);
2957
+ }
2958
+ }
2959
+ value.push(d);
2960
+ }
2961
+ return value;
2962
+ }
2963
+
2860
2964
  /************************************************************
2861
2965
  * Function to get input value based on its type
2862
2966
  ************************************************************/
@@ -2934,18 +3038,7 @@ function get_form_values(gobj, $form)
2934
3038
  case "table":
2935
3039
  let template = gobj_read_attr(gobj, "template");
2936
3040
  if(!empty_string(name) && kw_has_key(template, name)) {
2937
- value = [];
2938
- let rows = $input.tabulator.getRows();
2939
-
2940
- for(let row of rows) {
2941
- let d = row.getData();
2942
- value.push(d);
2943
- let $row = row.getElement();
2944
- $row.querySelectorAll('.yui-tabulator-table-nested').forEach($nested => {
2945
- let name_n = $nested.getAttribute("name");
2946
- d[name_n] = $nested.tabulator.getData();
2947
- });
2948
- }
3041
+ value = table_values($input.tabulator);
2949
3042
  }
2950
3043
  break;
2951
3044
 
@@ -2986,7 +3079,10 @@ function get_form_values(gobj, $form)
2986
3079
  }
2987
3080
 
2988
3081
  /************************************************************
2989
- *
3082
+ * Empty the form. A table not built yet has no rows to clear
3083
+ * but may have a load waiting for its build: it is dropped too,
3084
+ * or the rows cleared here came back when the table was built.
3085
+ * The nested tables go with the rows that hold them.
2990
3086
  ************************************************************/
2991
3087
  function clear_data(gobj, $form)
2992
3088
  {
@@ -3044,15 +3140,11 @@ function clear_data(gobj, $form)
3044
3140
  });
3045
3141
 
3046
3142
  $form.querySelectorAll('.yui-tabulator-table').forEach($table => {
3143
+ $table.yui_pending_rows = null;
3047
3144
  if($table.tabulator.initialized) {
3145
+ destroy_rows_tables(gobj, $table.tabulator);
3048
3146
  $table.tabulator.clearData();
3049
3147
  }
3050
-
3051
- $table.querySelectorAll('.yui-tabulator-table-nested').forEach($table_nested => {
3052
- if($table_nested.tabulator.initialized) {
3053
- $table_nested.tabulator.clearData();
3054
- }
3055
- });
3056
3148
  });
3057
3149
  }
3058
3150
 
@@ -3259,43 +3351,49 @@ function set_form_values(gobj, template, $form, record)
3259
3351
  }
3260
3352
 
3261
3353
  /************************************************************
3262
- * loading data from backend to tabulator,
3263
- * check if the table is built
3354
+ * Load the rows of a record in a table: all of them at once
3355
+ * (EV_LOAD_TABLE_ROWS), now if the table is built, else when it
3356
+ * is (create_tabulator's `tableBuilt`).
3264
3357
  ************************************************************/
3265
3358
  function load_tabulator_data(gobj, $table, value)
3266
3359
  {
3267
- if(!value) {
3360
+ if(!is_array(value)) {
3268
3361
  log_error(sprintf("%s: no data to load_tabulator_data()", gobj_short_name(gobj)));
3269
3362
  return;
3270
3363
  }
3271
3364
  let tabulator = $table.tabulator;
3272
- if(tabulator.initialized) {
3273
- for(let row of value) {
3274
- gobj_send_event(gobj,
3275
- "EV_ADD_TABLE_ROW",
3276
- {
3277
- table_id: table_identity(gobj, $table),
3278
- record: row,
3279
- loading: true,
3280
- },
3281
- gobj
3282
- );
3283
- }
3284
- } else {
3285
- tabulator.on("tableBuilt", function() {
3286
- for(let row of value) {
3287
- gobj_send_event(gobj,
3288
- "EV_ADD_TABLE_ROW",
3289
- {
3290
- table_id: table_identity(gobj, $table),
3291
- record: row,
3292
- loading: true,
3293
- },
3294
- gobj
3295
- );
3296
- }
3297
- });
3365
+ if(!tabulator.initialized) {
3366
+ $table.yui_pending_rows = value.length > 0? value : null;
3367
+ return;
3298
3368
  }
3369
+ $table.yui_pending_rows = null;
3370
+ if(value.length === 0) {
3371
+ return;
3372
+ }
3373
+ gobj_send_event(gobj,
3374
+ "EV_LOAD_TABLE_ROWS",
3375
+ {
3376
+ table_id: table_identity(gobj, $table),
3377
+ rows: value
3378
+ },
3379
+ gobj
3380
+ );
3381
+ }
3382
+
3383
+ /************************************************************
3384
+ * Redraw a table once what was added to it is drawn: the
3385
+ * "double scrollbar" Tabulator leaves when its rows grow.
3386
+ ************************************************************/
3387
+ function redraw_table_later(gobj, $table)
3388
+ {
3389
+ setTimeout(function() {
3390
+ if(gobj_is_destroying(gobj)) {
3391
+ return; // the form went in the meantime: nothing to redraw
3392
+ }
3393
+ if($table && $table.tabulator) { // it may be destroyed by now
3394
+ $table.tabulator.redraw();
3395
+ }
3396
+ }, 30);
3299
3397
  }
3300
3398
 
3301
3399
  /************************************************************
@@ -3761,8 +3859,16 @@ function ac_set_file_preview(gobj, event, kw, src)
3761
3859
  }
3762
3860
 
3763
3861
  /************************************************************
3764
- * From internal form button for new rows
3765
- * or from load_tabulator_data() to load data from backend
3862
+ * From the add button of a table, outer or nested: the
3863
+ * reader's new row. A change of the reader's (`dataChanged`).
3864
+ * Tabulator keeps the object it is given and writes the
3865
+ * reader's edits into it: it is given a copy. A row added to a
3866
+ * nested table makes the row it lives in grow: the outer table
3867
+ * is the one redrawn.
3868
+ * {
3869
+ * table_id: the table (table_identity())
3870
+ * record: the new row, {} from the button
3871
+ * }
3766
3872
  ************************************************************/
3767
3873
  function ac_add_table_row(gobj, event, kw, src)
3768
3874
  {
@@ -3773,64 +3879,69 @@ function ac_add_table_row(gobj, event, kw, src)
3773
3879
  log_error(`${gobj_short_name(gobj)}: EV_ADD_TABLE_ROW to a table that is gone: '${table_id}'`);
3774
3880
  return -1;
3775
3881
  }
3776
- let record = kw.record;
3777
- let loading = kw.loading;
3778
3882
 
3779
- /* Tabulator says `dataChanged` INSIDE addRow(), synchronously: a row
3780
- * loaded from the record is muted there, whenever it lands -- also
3781
- * from a `tableBuilt` that comes after the load returned, which is
3782
- * why no timer can tell the two apart. */
3783
- let added;
3784
- if(loading) {
3785
- gobj.priv.loading_rows++;
3883
+ tabulator.addRow(json_deep_copy(is_object(kw.record)? kw.record : {}))
3884
+ .catch(function(error){
3885
+ log_error(`${gobj_short_name(gobj)}: cannot add a table row: ${error}`);
3886
+ });
3887
+
3888
+ redraw_table_later(gobj, $table.closest('.yui-tabulator-table')); // itself, if outer
3889
+
3890
+ return 0;
3891
+ }
3892
+
3893
+ /************************************************************
3894
+ * From load_tabulator_data(): the rows of the record a table
3895
+ * shows, all of them in ONE call and one redraw. A row at a time
3896
+ * redrew every row of the table after each one: 300 rows took
3897
+ * 20 s, 300 with a nested table each 39 s.
3898
+ *
3899
+ * Tabulator keeps the objects it is given (Row.setData() copies
3900
+ * nothing) and a cell edit writes into them: handed the
3901
+ * `record`'s own, an edit wrote into the record, and Undo --
3902
+ * which loads the record again -- loaded the edit. It is given
3903
+ * a copy.
3904
+ *
3905
+ * And it says `dataChanged` INSIDE addData(), synchronously,
3906
+ * once per row: rows the FORM loads are muted there, whenever
3907
+ * they land -- also from a `tableBuilt` that comes after the
3908
+ * load returned, which is why no timer can tell them from the
3909
+ * reader's.
3910
+ * {
3911
+ * table_id: the table (table_identity())
3912
+ * rows: [record, ...]
3913
+ * }
3914
+ ************************************************************/
3915
+ function ac_load_table_rows(gobj, event, kw, src)
3916
+ {
3917
+ let table_id = kw.table_id;
3918
+ let $table = find_table(gobj, table_id);
3919
+ let tabulator = $table? $table.tabulator : null;
3920
+ if(!tabulator) {
3921
+ log_error(`${gobj_short_name(gobj)}: EV_LOAD_TABLE_ROWS to a table that is gone: '${table_id}'`);
3922
+ return -1;
3923
+ }
3924
+ if(!is_array(kw.rows)) {
3925
+ log_error(`${gobj_short_name(gobj)}: EV_LOAD_TABLE_ROWS without rows: '${table_id}'`);
3926
+ return -1;
3786
3927
  }
3928
+ if(kw.rows.length === 0) {
3929
+ return 0;
3930
+ }
3931
+
3932
+ let rows = json_deep_copy(kw.rows);
3933
+ let added;
3934
+ gobj.priv.loading_rows++;
3787
3935
  try {
3788
- added = tabulator.addRow(record);
3936
+ added = tabulator.addData(rows);
3789
3937
  } finally {
3790
- if(loading) {
3791
- gobj.priv.loading_rows--;
3792
- }
3938
+ gobj.priv.loading_rows--;
3793
3939
  }
3940
+ added.catch(function(error){
3941
+ log_error(`${gobj_short_name(gobj)}: cannot load the rows of a table: ${error}`);
3942
+ });
3794
3943
 
3795
- added
3796
- .then(function(row) {
3797
- if(loading) {
3798
- /*
3799
- * Loading from backend, can have nested tables
3800
- */
3801
- let template = $table.template;
3802
- Object.entries(template).forEach(([key, template_value]) => {
3803
- if(str_in_list(template_value.flag, "table")) {
3804
- let $row_nested = row.getElement();
3805
- let $table_nested = $row_nested.querySelector(`.yui-tabulator-table-nested[name="${key}"]`);
3806
- if($table_nested) {
3807
- load_tabulator_data(gobj, $table_nested, record[key]);
3808
- } else {
3809
- log_error(sprintf("%s: nested table not found '%s'", gobj_short_name(gobj), key));
3810
- }
3811
- }
3812
- });
3813
- }
3814
- })
3815
- .catch(function(error){
3816
- log_error(`${gobj_short_name(gobj)}: cannot add a table row: ${error}`);
3817
- });
3818
-
3819
- // TODO improve, to use only once the timeout?
3820
- setTimeout(function() {
3821
- if(gobj_is_destroying(gobj)) {
3822
- return; // the form went in the meantime: nothing to redraw
3823
- }
3824
- /* A row LOADED redraws the table that took it, nested or not; a
3825
- * row ADDED by hand to a nested table redraws the table of the
3826
- * row the nested one lives in, which is what grew (closest()
3827
- * is the table itself for an outer one). Re-checked: it may be
3828
- * destroyed by now. */
3829
- let $target = loading? $table : $table.closest('.yui-tabulator-table');
3830
- if($target && $target.tabulator) {
3831
- $target.tabulator.redraw(); /* Delete double scrollbar */
3832
- }
3833
- }, 30);
3944
+ redraw_table_later(gobj, $table);
3834
3945
 
3835
3946
  return 0;
3836
3947
  }
@@ -4074,6 +4185,7 @@ function create_gclass(gclass_name)
4074
4185
  ["EV_UNDO_RECORD", ac_undo_record, null],
4075
4186
  ["EV_CLEAR_RECORD", ac_clear_record, null],
4076
4187
  ["EV_ADD_TABLE_ROW", ac_add_table_row, null],
4188
+ ["EV_LOAD_TABLE_ROWS", ac_load_table_rows, null],
4077
4189
  ["EV_RECORD_CHANGED", ac_record_changed, null],
4078
4190
  ["EV_COPY_RECORD", ac_copy_record, null],
4079
4191
  ["EV_PASTE_RECORD", ac_paste_record, null],
@@ -4100,6 +4212,7 @@ function create_gclass(gclass_name)
4100
4212
  ["EV_UNDO_RECORD", 0],
4101
4213
  ["EV_CLEAR_RECORD", 0],
4102
4214
  ["EV_ADD_TABLE_ROW", 0],
4215
+ ["EV_LOAD_TABLE_ROWS", 0],
4103
4216
  ["EV_RECORD_CHANGED", 0],
4104
4217
  ["EV_COPY_RECORD", 0],
4105
4218
  ["EV_PASTE_RECORD", 0],