@yuneta/gobj-ui 7.26.42 → 7.26.43
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.
- package/README.md +227 -36
- package/dist/gobj-ui.cjs.js +768 -191
- package/dist/gobj-ui.es.js +768 -191
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +355 -63
- package/src/c_yui_form.js +261 -154
- package/src/c_yui_node.js +51 -7
- package/src/c_yui_schema_editor.js +49 -3
- package/src/c_yui_shell.css +4 -1
- package/src/c_yui_shell.js +28 -2
- package/src/c_yui_window.js +373 -62
- package/src/c_yui_window_manager.js +74 -2
- package/src/escape_taken.js +58 -0
- package/src/form_close_asks_for_edits.wiring.test.js +6 -3
- package/src/form_json_editor_names.js +3 -1
- package/src/form_json_editor_names.wiring.test.js +8 -4
- package/src/form_json_expand.wiring.test.js +6 -3
- package/src/form_json_field.wiring.test.js +8 -4
- package/src/form_label_i18n.wiring.test.js +10 -5
- package/src/form_table_edits_ask.wiring.test.js +18 -8
- package/src/form_table_rearm.wiring.test.js +13 -5
- package/src/form_table_rows.wiring.test.js +489 -0
- package/src/form_table_validator.wiring.test.js +8 -4
- package/src/form_template_field.wiring.test.js +6 -3
- package/src/g6_long_press_clock.test.js +8 -3
- package/src/i18n_key_functions.js +63 -25
- package/src/i18n_key_functions.test.js +230 -8
- package/src/modal_guard_back.wiring.test.js +53 -0
- package/src/named_controls.wiring.test.js +53 -13
- package/src/node_nav_events.wiring.test.js +93 -1
- package/src/schema_editor_diagram_click.wiring.test.js +277 -0
- package/src/shell_dialog_names.wiring.test.js +149 -0
- package/src/shell_escape_taken.wiring.test.js +142 -0
- package/src/shell_focus_trap.js +30 -2
- package/src/shell_focus_trap.test.js +90 -6
- package/src/shell_modals.js +90 -19
- package/src/table_editor_name.wiring.test.js +10 -5
- package/src/treedb_column_title.wiring.test.js +8 -4
- package/src/treedb_graph_writes.wiring.test.js +6 -3
- package/src/treedb_json_drill.wiring.test.js +6 -3
- package/src/uplot_add_serie.test.js +6 -3
- package/src/uplot_ink.test.js +8 -4
- package/src/window_dialog.wiring.test.js +486 -0
- package/src/window_dock_band.wiring.test.js +189 -0
- package/src/window_rect_rounding.wiring.test.js +121 -0
- package/src/yui_tabulator_i18n.js +31 -1
- 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
|
|
184
|
-
* table by id (a kw is plain json), see
|
|
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,
|
|
558
|
-
* `.tabulator`, circular) broke the
|
|
559
|
-
* Given on first use and kept on
|
|
560
|
-
* it weakly, so a nested table
|
|
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
|
|
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
|
-
|
|
672
|
+
destroy_widget(gobj, "select", $el.tom_select);
|
|
637
673
|
$el.tom_select = null;
|
|
638
674
|
}
|
|
639
675
|
if($el.jsoneditor) {
|
|
640
|
-
|
|
676
|
+
destroy_widget(gobj, "json editor", $el.jsoneditor);
|
|
641
677
|
$el.jsoneditor = null;
|
|
642
678
|
}
|
|
643
679
|
if($el.tabulator) {
|
|
644
|
-
|
|
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,6 +2220,19 @@ 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
|
{
|
|
@@ -2222,6 +2271,15 @@ function create_tabulator(gobj, $extend, name, template)
|
|
|
2222
2271
|
|
|
2223
2272
|
if(sub_elements.length > 0) {
|
|
2224
2273
|
tabulator_settings.rowFormatter = function(row) {
|
|
2274
|
+
let $row = row.getElement();
|
|
2275
|
+
if($row.yui_nested) { // drawn again: its tables, rows and all
|
|
2276
|
+
for(let $nested of $row.yui_nested) {
|
|
2277
|
+
$row.appendChild($nested);
|
|
2278
|
+
}
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
2281
|
+
$row.yui_nested = [];
|
|
2282
|
+
let data = row.getData() || {};
|
|
2225
2283
|
for(let sub_element of sub_elements) {
|
|
2226
2284
|
let extend = ['div',
|
|
2227
2285
|
{
|
|
@@ -2233,9 +2291,10 @@ function create_tabulator(gobj, $extend, name, template)
|
|
|
2233
2291
|
$extend.tabulator = create_tabulator(
|
|
2234
2292
|
gobj, $extend, sub_element.name, sub_element.template
|
|
2235
2293
|
);
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2294
|
+
$row.appendChild($extend);
|
|
2295
|
+
$row.yui_nested.push($extend);
|
|
2296
|
+
let rows = data[sub_element.name];
|
|
2297
|
+
load_tabulator_data(gobj, $extend, is_array(rows)? rows : []);
|
|
2239
2298
|
}
|
|
2240
2299
|
};
|
|
2241
2300
|
}
|
|
@@ -2280,19 +2339,38 @@ function create_tabulator(gobj, $extend, name, template)
|
|
|
2280
2339
|
/* What the READER does to a table -- edits a cell, adds or deletes a
|
|
2281
2340
|
* row -- reaches the form only through `dataChanged`. Wired here, on
|
|
2282
2341
|
* every table, nested ones included (a row's formatter builds them
|
|
2283
|
-
*
|
|
2284
|
-
* it was unwired whenever the form was CHANGED and re-wired
|
|
2285
|
-
* save, an undo or a load of what is stored, so a form that
|
|
2286
|
-
* changed (a field its record lacks, filled with its default)
|
|
2287
|
-
* heard its tables -- an edit there was not `edited`, and
|
|
2288
|
-
* it without a question. The rows the form
|
|
2289
|
-
* (`loading_rows`,
|
|
2342
|
+
* the first time the row is drawn), and never switched off: until
|
|
2343
|
+
* 7.26.40 it was unwired whenever the form was CHANGED and re-wired
|
|
2344
|
+
* only by a save, an undo or a load of what is stored, so a form that
|
|
2345
|
+
* opened changed (a field its record lacks, filled with its default)
|
|
2346
|
+
* never heard its tables -- an edit there was not `edited`, and
|
|
2347
|
+
* closing lost it without a question. The rows the form loads itself
|
|
2348
|
+
* say nothing (`loading_rows`, ac_load_table_rows). */
|
|
2290
2349
|
tabulator.on("dataChanged", function() {
|
|
2291
2350
|
if(gobj.priv.loading_rows > 0) {
|
|
2292
2351
|
return;
|
|
2293
2352
|
}
|
|
2294
2353
|
gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
|
|
2295
2354
|
});
|
|
2355
|
+
$extend.yui_pending_rows = null;
|
|
2356
|
+
tabulator.on("tableBuilt", function() {
|
|
2357
|
+
let rows = $extend.yui_pending_rows;
|
|
2358
|
+
$extend.yui_pending_rows = null;
|
|
2359
|
+
if(rows && !gobj_is_destroying(gobj)) {
|
|
2360
|
+
gobj_send_event(gobj,
|
|
2361
|
+
"EV_LOAD_TABLE_ROWS",
|
|
2362
|
+
{
|
|
2363
|
+
table_id: table_identity(gobj, $extend),
|
|
2364
|
+
rows: rows
|
|
2365
|
+
},
|
|
2366
|
+
gobj
|
|
2367
|
+
);
|
|
2368
|
+
}
|
|
2369
|
+
});
|
|
2370
|
+
/* A row the reader deletes takes its nested tables with it. */
|
|
2371
|
+
tabulator.on("rowDeleted", function(row) {
|
|
2372
|
+
destroy_row_tables(gobj, row.getElement());
|
|
2373
|
+
});
|
|
2296
2374
|
/* Tabulator hard-codes `aria-label="Select Row"` on the box its
|
|
2297
2375
|
* rowSelection formatter draws, and it draws a fresh one on EVERY
|
|
2298
2376
|
* render -- so this hangs off `renderComplete`, not `tableBuilt`:
|
|
@@ -2459,7 +2537,6 @@ function template2columns(gobj, columns, template, sub_elements)
|
|
|
2459
2537
|
{
|
|
2460
2538
|
table_id: table_identity(gobj, $extend),
|
|
2461
2539
|
record: {},
|
|
2462
|
-
loading: false,
|
|
2463
2540
|
},
|
|
2464
2541
|
gobj
|
|
2465
2542
|
);
|
|
@@ -2857,6 +2934,27 @@ function getInputValue($input) {
|
|
|
2857
2934
|
}
|
|
2858
2935
|
}
|
|
2859
2936
|
|
|
2937
|
+
/************************************************************
|
|
2938
|
+
* The rows of a table as the form saves them: copies, each with
|
|
2939
|
+
* the rows of the nested tables its row holds. A row's
|
|
2940
|
+
* getData() is the row's OWN object: handed out in the save, a
|
|
2941
|
+
* later edit wrote into what the host had been given.
|
|
2942
|
+
************************************************************/
|
|
2943
|
+
function table_values(tabulator)
|
|
2944
|
+
{
|
|
2945
|
+
let value = [];
|
|
2946
|
+
for(let row of tabulator.getRows()) {
|
|
2947
|
+
let d = json_deep_copy(row.getData());
|
|
2948
|
+
for(let $nested of (row.getElement().yui_nested || [])) {
|
|
2949
|
+
if($nested.tabulator) {
|
|
2950
|
+
d[$nested.getAttribute("name")] = table_values($nested.tabulator);
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
value.push(d);
|
|
2954
|
+
}
|
|
2955
|
+
return value;
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2860
2958
|
/************************************************************
|
|
2861
2959
|
* Function to get input value based on its type
|
|
2862
2960
|
************************************************************/
|
|
@@ -2934,18 +3032,7 @@ function get_form_values(gobj, $form)
|
|
|
2934
3032
|
case "table":
|
|
2935
3033
|
let template = gobj_read_attr(gobj, "template");
|
|
2936
3034
|
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
|
-
}
|
|
3035
|
+
value = table_values($input.tabulator);
|
|
2949
3036
|
}
|
|
2950
3037
|
break;
|
|
2951
3038
|
|
|
@@ -2986,7 +3073,10 @@ function get_form_values(gobj, $form)
|
|
|
2986
3073
|
}
|
|
2987
3074
|
|
|
2988
3075
|
/************************************************************
|
|
2989
|
-
*
|
|
3076
|
+
* Empty the form. A table not built yet has no rows to clear
|
|
3077
|
+
* but may have a load waiting for its build: it is dropped too,
|
|
3078
|
+
* or the rows cleared here came back when the table was built.
|
|
3079
|
+
* The nested tables go with the rows that hold them.
|
|
2990
3080
|
************************************************************/
|
|
2991
3081
|
function clear_data(gobj, $form)
|
|
2992
3082
|
{
|
|
@@ -3044,15 +3134,11 @@ function clear_data(gobj, $form)
|
|
|
3044
3134
|
});
|
|
3045
3135
|
|
|
3046
3136
|
$form.querySelectorAll('.yui-tabulator-table').forEach($table => {
|
|
3137
|
+
$table.yui_pending_rows = null;
|
|
3047
3138
|
if($table.tabulator.initialized) {
|
|
3139
|
+
destroy_rows_tables(gobj, $table.tabulator);
|
|
3048
3140
|
$table.tabulator.clearData();
|
|
3049
3141
|
}
|
|
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
3142
|
});
|
|
3057
3143
|
}
|
|
3058
3144
|
|
|
@@ -3259,43 +3345,49 @@ function set_form_values(gobj, template, $form, record)
|
|
|
3259
3345
|
}
|
|
3260
3346
|
|
|
3261
3347
|
/************************************************************
|
|
3262
|
-
*
|
|
3263
|
-
*
|
|
3348
|
+
* Load the rows of a record in a table: all of them at once
|
|
3349
|
+
* (EV_LOAD_TABLE_ROWS), now if the table is built, else when it
|
|
3350
|
+
* is (create_tabulator's `tableBuilt`).
|
|
3264
3351
|
************************************************************/
|
|
3265
3352
|
function load_tabulator_data(gobj, $table, value)
|
|
3266
3353
|
{
|
|
3267
|
-
if(!value) {
|
|
3354
|
+
if(!is_array(value)) {
|
|
3268
3355
|
log_error(sprintf("%s: no data to load_tabulator_data()", gobj_short_name(gobj)));
|
|
3269
3356
|
return;
|
|
3270
3357
|
}
|
|
3271
3358
|
let tabulator = $table.tabulator;
|
|
3272
|
-
if(tabulator.initialized) {
|
|
3273
|
-
|
|
3274
|
-
|
|
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
|
-
});
|
|
3359
|
+
if(!tabulator.initialized) {
|
|
3360
|
+
$table.yui_pending_rows = value.length > 0? value : null;
|
|
3361
|
+
return;
|
|
3298
3362
|
}
|
|
3363
|
+
$table.yui_pending_rows = null;
|
|
3364
|
+
if(value.length === 0) {
|
|
3365
|
+
return;
|
|
3366
|
+
}
|
|
3367
|
+
gobj_send_event(gobj,
|
|
3368
|
+
"EV_LOAD_TABLE_ROWS",
|
|
3369
|
+
{
|
|
3370
|
+
table_id: table_identity(gobj, $table),
|
|
3371
|
+
rows: value
|
|
3372
|
+
},
|
|
3373
|
+
gobj
|
|
3374
|
+
);
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
/************************************************************
|
|
3378
|
+
* Redraw a table once what was added to it is drawn: the
|
|
3379
|
+
* "double scrollbar" Tabulator leaves when its rows grow.
|
|
3380
|
+
************************************************************/
|
|
3381
|
+
function redraw_table_later(gobj, $table)
|
|
3382
|
+
{
|
|
3383
|
+
setTimeout(function() {
|
|
3384
|
+
if(gobj_is_destroying(gobj)) {
|
|
3385
|
+
return; // the form went in the meantime: nothing to redraw
|
|
3386
|
+
}
|
|
3387
|
+
if($table && $table.tabulator) { // it may be destroyed by now
|
|
3388
|
+
$table.tabulator.redraw();
|
|
3389
|
+
}
|
|
3390
|
+
}, 30);
|
|
3299
3391
|
}
|
|
3300
3392
|
|
|
3301
3393
|
/************************************************************
|
|
@@ -3761,8 +3853,16 @@ function ac_set_file_preview(gobj, event, kw, src)
|
|
|
3761
3853
|
}
|
|
3762
3854
|
|
|
3763
3855
|
/************************************************************
|
|
3764
|
-
* From
|
|
3765
|
-
*
|
|
3856
|
+
* From the add button of a table, outer or nested: the
|
|
3857
|
+
* reader's new row. A change of the reader's (`dataChanged`).
|
|
3858
|
+
* Tabulator keeps the object it is given and writes the
|
|
3859
|
+
* reader's edits into it: it is given a copy. A row added to a
|
|
3860
|
+
* nested table makes the row it lives in grow: the outer table
|
|
3861
|
+
* is the one redrawn.
|
|
3862
|
+
* {
|
|
3863
|
+
* table_id: the table (table_identity())
|
|
3864
|
+
* record: the new row, {} from the button
|
|
3865
|
+
* }
|
|
3766
3866
|
************************************************************/
|
|
3767
3867
|
function ac_add_table_row(gobj, event, kw, src)
|
|
3768
3868
|
{
|
|
@@ -3773,64 +3873,69 @@ function ac_add_table_row(gobj, event, kw, src)
|
|
|
3773
3873
|
log_error(`${gobj_short_name(gobj)}: EV_ADD_TABLE_ROW to a table that is gone: '${table_id}'`);
|
|
3774
3874
|
return -1;
|
|
3775
3875
|
}
|
|
3776
|
-
let record = kw.record;
|
|
3777
|
-
let loading = kw.loading;
|
|
3778
3876
|
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3877
|
+
tabulator.addRow(json_deep_copy(is_object(kw.record)? kw.record : {}))
|
|
3878
|
+
.catch(function(error){
|
|
3879
|
+
log_error(`${gobj_short_name(gobj)}: cannot add a table row: ${error}`);
|
|
3880
|
+
});
|
|
3881
|
+
|
|
3882
|
+
redraw_table_later(gobj, $table.closest('.yui-tabulator-table')); // itself, if outer
|
|
3883
|
+
|
|
3884
|
+
return 0;
|
|
3885
|
+
}
|
|
3886
|
+
|
|
3887
|
+
/************************************************************
|
|
3888
|
+
* From load_tabulator_data(): the rows of the record a table
|
|
3889
|
+
* shows, all of them in ONE call and one redraw. A row at a time
|
|
3890
|
+
* redrew every row of the table after each one: 300 rows took
|
|
3891
|
+
* 20 s, 300 with a nested table each 39 s.
|
|
3892
|
+
*
|
|
3893
|
+
* Tabulator keeps the objects it is given (Row.setData() copies
|
|
3894
|
+
* nothing) and a cell edit writes into them: handed the
|
|
3895
|
+
* `record`'s own, an edit wrote into the record, and Undo --
|
|
3896
|
+
* which loads the record again -- loaded the edit. It is given
|
|
3897
|
+
* a copy.
|
|
3898
|
+
*
|
|
3899
|
+
* And it says `dataChanged` INSIDE addData(), synchronously,
|
|
3900
|
+
* once per row: rows the FORM loads are muted there, whenever
|
|
3901
|
+
* they land -- also from a `tableBuilt` that comes after the
|
|
3902
|
+
* load returned, which is why no timer can tell them from the
|
|
3903
|
+
* reader's.
|
|
3904
|
+
* {
|
|
3905
|
+
* table_id: the table (table_identity())
|
|
3906
|
+
* rows: [record, ...]
|
|
3907
|
+
* }
|
|
3908
|
+
************************************************************/
|
|
3909
|
+
function ac_load_table_rows(gobj, event, kw, src)
|
|
3910
|
+
{
|
|
3911
|
+
let table_id = kw.table_id;
|
|
3912
|
+
let $table = find_table(gobj, table_id);
|
|
3913
|
+
let tabulator = $table? $table.tabulator : null;
|
|
3914
|
+
if(!tabulator) {
|
|
3915
|
+
log_error(`${gobj_short_name(gobj)}: EV_LOAD_TABLE_ROWS to a table that is gone: '${table_id}'`);
|
|
3916
|
+
return -1;
|
|
3917
|
+
}
|
|
3918
|
+
if(!is_array(kw.rows)) {
|
|
3919
|
+
log_error(`${gobj_short_name(gobj)}: EV_LOAD_TABLE_ROWS without rows: '${table_id}'`);
|
|
3920
|
+
return -1;
|
|
3786
3921
|
}
|
|
3922
|
+
if(kw.rows.length === 0) {
|
|
3923
|
+
return 0;
|
|
3924
|
+
}
|
|
3925
|
+
|
|
3926
|
+
let rows = json_deep_copy(kw.rows);
|
|
3927
|
+
let added;
|
|
3928
|
+
gobj.priv.loading_rows++;
|
|
3787
3929
|
try {
|
|
3788
|
-
added = tabulator.
|
|
3930
|
+
added = tabulator.addData(rows);
|
|
3789
3931
|
} finally {
|
|
3790
|
-
|
|
3791
|
-
gobj.priv.loading_rows--;
|
|
3792
|
-
}
|
|
3932
|
+
gobj.priv.loading_rows--;
|
|
3793
3933
|
}
|
|
3934
|
+
added.catch(function(error){
|
|
3935
|
+
log_error(`${gobj_short_name(gobj)}: cannot load the rows of a table: ${error}`);
|
|
3936
|
+
});
|
|
3794
3937
|
|
|
3795
|
-
|
|
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);
|
|
3938
|
+
redraw_table_later(gobj, $table);
|
|
3834
3939
|
|
|
3835
3940
|
return 0;
|
|
3836
3941
|
}
|
|
@@ -4074,6 +4179,7 @@ function create_gclass(gclass_name)
|
|
|
4074
4179
|
["EV_UNDO_RECORD", ac_undo_record, null],
|
|
4075
4180
|
["EV_CLEAR_RECORD", ac_clear_record, null],
|
|
4076
4181
|
["EV_ADD_TABLE_ROW", ac_add_table_row, null],
|
|
4182
|
+
["EV_LOAD_TABLE_ROWS", ac_load_table_rows, null],
|
|
4077
4183
|
["EV_RECORD_CHANGED", ac_record_changed, null],
|
|
4078
4184
|
["EV_COPY_RECORD", ac_copy_record, null],
|
|
4079
4185
|
["EV_PASTE_RECORD", ac_paste_record, null],
|
|
@@ -4100,6 +4206,7 @@ function create_gclass(gclass_name)
|
|
|
4100
4206
|
["EV_UNDO_RECORD", 0],
|
|
4101
4207
|
["EV_CLEAR_RECORD", 0],
|
|
4102
4208
|
["EV_ADD_TABLE_ROW", 0],
|
|
4209
|
+
["EV_LOAD_TABLE_ROWS", 0],
|
|
4103
4210
|
["EV_RECORD_CHANGED", 0],
|
|
4104
4211
|
["EV_COPY_RECORD", 0],
|
|
4105
4212
|
["EV_PASTE_RECORD", 0],
|