@yuneta/gobj-ui 7.26.7 → 7.26.9
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 +53 -0
- package/dist/gobj-ui.cjs.js +534 -232
- package/dist/gobj-ui.es.js +534 -232
- package/package.json +2 -2
- package/src/c_g6_nodes_tree.js +65 -31
- package/src/c_yui_form.js +230 -63
- package/src/c_yui_gclass.js +23 -22
- package/src/c_yui_gobj_tree_js.js +13 -9
- package/src/c_yui_json.js +7 -6
- package/src/c_yui_json_graph.js +8 -7
- package/src/c_yui_json_pad.js +2 -1
- package/src/c_yui_map.js +25 -1
- package/src/c_yui_nav.js +9 -8
- package/src/c_yui_schema_editor.js +25 -24
- package/src/c_yui_shell.js +64 -3
- package/src/c_yui_treedb_topic_with_form.js +26 -21
- package/src/c_yui_treedb_topics.js +17 -16
- package/src/c_yui_window.js +73 -32
- package/src/c_yui_window_manager.js +3 -2
- package/src/form_json_field.js +10 -3
- package/src/form_json_field.test.js +6 -0
- package/src/form_json_field.wiring.test.js +1 -1
- package/src/form_table_rearm.wiring.test.js +158 -0
- package/src/form_toolbar_plan.js +5 -5
- package/src/g6_event_kw.js +36 -0
- package/src/map_stop_windows.wiring.test.js +112 -0
- package/src/nav_cards_helpers.js +2 -1
- package/src/nav_cards_helpers.test.js +7 -3
- package/src/overlay_marker_after_back.wiring.test.js +212 -0
- package/src/schema_to_c.js +10 -0
- package/src/schema_to_c.test.js +8 -1
- package/src/shell_modals.js +7 -5
- package/src/shell_route_map.js +12 -13
- package/src/treedb_topics_transport.wiring.test.js +26 -0
- package/src/vite_plugin_yuneta_html.test.js +94 -0
- package/src/window_show.wiring.test.js +83 -0
- package/src/window_veto_back.wiring.test.js +35 -0
- package/src/yui_asset.js +3 -2
- package/src/yui_data_color.js +33 -0
- package/src/yui_data_color.test.js +27 -0
- package/src/yui_dev.js +15 -13
- package/src/yui_frontend_view.js +4 -4
- package/src/yui_gclass_view.js +3 -3
- package/src/yui_text.js +43 -0
- package/src/yui_text.test.js +67 -0
- package/vite-plugin-yuneta-html.js +24 -5
package/src/c_yui_form.js
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
refresh_language,
|
|
48
48
|
treedb_decoder_fkey,
|
|
49
49
|
gclass_find_by_name,
|
|
50
|
+
gobj_is_destroying,
|
|
50
51
|
} from "@yuneta/gobj-js";
|
|
51
52
|
|
|
52
53
|
import {t} from "i18next";
|
|
@@ -90,6 +91,7 @@ import "./tabulator.css";
|
|
|
90
91
|
import {is_time_field} from "./json_view_helpers.js";
|
|
91
92
|
import {date_to_datetime_local, datetime_local_to_epoch} from "./form_time_value.js";
|
|
92
93
|
import {parse_json_field, json_editor_value} from "./form_json_field.js";
|
|
94
|
+
import {text_node, text_title_formatter} from "./yui_text.js";
|
|
93
95
|
import { TabulatorFull as Tabulator } from "tabulator-tables"; // Import Full Tabulator JS
|
|
94
96
|
// import { Tabulator } from "tabulator-tables"; // Import light Tabulator JS
|
|
95
97
|
|
|
@@ -159,7 +161,15 @@ SDATA(data_type_t.DTP_BOOLEAN, "changes", 0, false, "Indicates if ch
|
|
|
159
161
|
SDATA_END()
|
|
160
162
|
];
|
|
161
163
|
|
|
162
|
-
let PRIVATE_DATA = {
|
|
164
|
+
let PRIVATE_DATA = {
|
|
165
|
+
/* The deferred re-wiring of the tables' dataChanged after a
|
|
166
|
+
* save/undo (see set_changed_stated): cancelled in destroy_ui. */
|
|
167
|
+
rearm_timer: null,
|
|
168
|
+
/* table_id -> WeakRef of its element: EV_ADD_TABLE_ROW names a
|
|
169
|
+
* table by id (a kw is plain json), see table_identity(). */
|
|
170
|
+
tables: null,
|
|
171
|
+
table_seq: 0,
|
|
172
|
+
};
|
|
163
173
|
|
|
164
174
|
let __gclass__ = null;
|
|
165
175
|
|
|
@@ -190,6 +200,7 @@ function mt_create(gobj)
|
|
|
190
200
|
let name = clean_name(gobj_name(gobj));
|
|
191
201
|
gobj_write_attr(gobj, "form_id", "form" + name);
|
|
192
202
|
|
|
203
|
+
gobj.priv.tables = new Map();
|
|
193
204
|
build_ui(gobj);
|
|
194
205
|
}
|
|
195
206
|
|
|
@@ -253,11 +264,11 @@ function set_changed_stated(gobj, changed)
|
|
|
253
264
|
let $form = $container.querySelector('form');
|
|
254
265
|
|
|
255
266
|
/*
|
|
256
|
-
*
|
|
257
|
-
* (`toolbar`),
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
267
|
+
* Either of the two may be MISSING: since the toolbar is configurable
|
|
268
|
+
* (`toolbar`), a one-action dialog asks for ["save"] and there is no
|
|
269
|
+
* undo to enable here. They used to be taken for granted, and leaving
|
|
270
|
+
* one out blew up with "can't access property setAttribute, a is null"
|
|
271
|
+
* at the first change in the form.
|
|
261
272
|
*/
|
|
262
273
|
const enable = ($btn, on, color) => {
|
|
263
274
|
if(!$btn) {
|
|
@@ -288,12 +299,12 @@ function set_changed_stated(gobj, changed)
|
|
|
288
299
|
enable($button_undo, true, "Magenta");
|
|
289
300
|
|
|
290
301
|
$form.querySelectorAll('.yui-tabulator-table').forEach($table => {
|
|
291
|
-
if(isEventSet($table.tabulator, "dataChanged")) {
|
|
302
|
+
if($table.tabulator && isEventSet($table.tabulator, "dataChanged")) {
|
|
292
303
|
$table.tabulator.off("dataChanged");
|
|
293
304
|
}
|
|
294
305
|
|
|
295
306
|
$table.querySelectorAll('.yui-tabulator-table-nested').forEach($table_nested => {
|
|
296
|
-
if(isEventSet($table_nested.tabulator, "dataChanged")) {
|
|
307
|
+
if($table_nested.tabulator && isEventSet($table_nested.tabulator, "dataChanged")) {
|
|
297
308
|
$table_nested.tabulator.off("dataChanged");
|
|
298
309
|
}
|
|
299
310
|
});
|
|
@@ -308,25 +319,37 @@ function set_changed_stated(gobj, changed)
|
|
|
308
319
|
enable($button_save, false, OFF_COLOR);
|
|
309
320
|
enable($button_undo, false, OFF_COLOR);
|
|
310
321
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
322
|
+
/*
|
|
323
|
+
* TODO improve. The tables are re-wired a moment later, once the
|
|
324
|
+
* data just loaded has settled. The timer is kept so that
|
|
325
|
+
* destroy_ui() cancels it: a form closed right after a save (what
|
|
326
|
+
* a dialog does) destroyed its widgets first, and the timer then
|
|
327
|
+
* called .on() on a null tabulator -- an uncaught TypeError.
|
|
328
|
+
*/
|
|
329
|
+
if(gobj.priv.rearm_timer) {
|
|
330
|
+
clearTimeout(gobj.priv.rearm_timer);
|
|
331
|
+
}
|
|
332
|
+
gobj.priv.rearm_timer = setTimeout(function() {
|
|
333
|
+
gobj.priv.rearm_timer = null;
|
|
334
|
+
if(gobj_is_destroying(gobj)) {
|
|
335
|
+
return; // destroy_ui() cancels it; this is the belt
|
|
336
|
+
}
|
|
337
|
+
const rearm = (tabulator) => {
|
|
338
|
+
if(!tabulator) {
|
|
339
|
+
return; // destroyed with its form
|
|
316
340
|
}
|
|
317
|
-
|
|
341
|
+
if(isEventSet(tabulator, "dataChanged")) {
|
|
342
|
+
tabulator.off("dataChanged");
|
|
343
|
+
}
|
|
344
|
+
tabulator.on("dataChanged", function(data) {
|
|
318
345
|
//data - the updated table data
|
|
319
346
|
gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
|
|
320
347
|
});
|
|
321
|
-
|
|
348
|
+
};
|
|
349
|
+
$form.querySelectorAll('.yui-tabulator-table').forEach($table => {
|
|
350
|
+
rearm($table.tabulator);
|
|
322
351
|
$table.querySelectorAll('.yui-tabulator-table-nested').forEach($table_nested => {
|
|
323
|
-
|
|
324
|
-
$table_nested.tabulator.off("dataChanged");
|
|
325
|
-
}
|
|
326
|
-
$table_nested.tabulator.on("dataChanged", function(data) {
|
|
327
|
-
//data - the updated table data
|
|
328
|
-
gobj_send_event(gobj, "EV_RECORD_CHANGED", {}, gobj);
|
|
329
|
-
});
|
|
352
|
+
rearm($table_nested.tabulator);
|
|
330
353
|
});
|
|
331
354
|
});
|
|
332
355
|
}, 200);
|
|
@@ -491,9 +514,16 @@ function build_ui(gobj)
|
|
|
491
514
|
************************************************************/
|
|
492
515
|
function destroy_ui(gobj)
|
|
493
516
|
{
|
|
517
|
+
if(gobj.priv && gobj.priv.rearm_timer) {
|
|
518
|
+
clearTimeout(gobj.priv.rearm_timer);
|
|
519
|
+
gobj.priv.rearm_timer = null;
|
|
520
|
+
}
|
|
494
521
|
let $container = gobj_read_attr(gobj, "$container");
|
|
495
522
|
if($container) {
|
|
496
523
|
destroy_widgets(gobj, $container);
|
|
524
|
+
if(gobj.priv && gobj.priv.tables) {
|
|
525
|
+
gobj.priv.tables.clear();
|
|
526
|
+
}
|
|
497
527
|
if($container.parentNode) {
|
|
498
528
|
$container.parentNode.removeChild($container);
|
|
499
529
|
}
|
|
@@ -509,13 +539,69 @@ function destroy_ui(gobj)
|
|
|
509
539
|
************************************************************/
|
|
510
540
|
function cell_icon(icon_class, key)
|
|
511
541
|
{
|
|
542
|
+
/* A control, not a picture: role, focus and the keys of a button. A
|
|
543
|
+
* key press clicks it, so it reaches the same Tabulator cellClick as
|
|
544
|
+
* the pointer. */
|
|
512
545
|
let $i = document.createElement('i');
|
|
513
546
|
$i.className = icon_class;
|
|
547
|
+
$i.setAttribute('role', 'button');
|
|
548
|
+
$i.setAttribute('tabindex', '0');
|
|
514
549
|
$i.setAttribute('title', t(key));
|
|
550
|
+
$i.setAttribute('data-i18n-title', key);
|
|
515
551
|
$i.setAttribute('aria-label', t(key));
|
|
552
|
+
$i.setAttribute('data-i18n-aria-label', key);
|
|
553
|
+
$i.addEventListener('keydown', function(evt) {
|
|
554
|
+
if(evt.key === 'Enter' || evt.key === ' ') {
|
|
555
|
+
evt.preventDefault();
|
|
556
|
+
$i.click();
|
|
557
|
+
}
|
|
558
|
+
});
|
|
516
559
|
return $i;
|
|
517
560
|
}
|
|
518
561
|
|
|
562
|
+
/************************************************************
|
|
563
|
+
* The identity of a table element, for the kw of
|
|
564
|
+
* EV_ADD_TABLE_ROW: a kw is plain json, and an element (with its
|
|
565
|
+
* `.tabulator`, circular) broke the `machine` trace that dumps it.
|
|
566
|
+
* Given on first use and kept on the element; the registry holds
|
|
567
|
+
* it weakly, so a nested table re-built by its row formatter is
|
|
568
|
+
* not kept alive by it.
|
|
569
|
+
************************************************************/
|
|
570
|
+
function table_identity(gobj, $table)
|
|
571
|
+
{
|
|
572
|
+
if(!$table.yui_table_id) {
|
|
573
|
+
let priv = gobj.priv;
|
|
574
|
+
/* The entries of tables the collector already took go first: a
|
|
575
|
+
* nested table rebuilt by its row formatter leaves one behind. */
|
|
576
|
+
for(let [id, ref] of priv.tables) {
|
|
577
|
+
if(!ref.deref()) {
|
|
578
|
+
priv.tables.delete(id);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
priv.table_seq += 1;
|
|
582
|
+
$table.yui_table_id = `t${priv.table_seq}`;
|
|
583
|
+
priv.tables.set($table.yui_table_id, new WeakRef($table));
|
|
584
|
+
}
|
|
585
|
+
return $table.yui_table_id;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/************************************************************
|
|
589
|
+
* The element of a table identity, or null when it is gone.
|
|
590
|
+
************************************************************/
|
|
591
|
+
function find_table(gobj, table_id)
|
|
592
|
+
{
|
|
593
|
+
let priv = gobj.priv;
|
|
594
|
+
let ref = priv.tables? priv.tables.get(table_id) : null;
|
|
595
|
+
let $table = ref? ref.deref() : null;
|
|
596
|
+
if(!$table) {
|
|
597
|
+
if(priv.tables) {
|
|
598
|
+
priv.tables.delete(table_id);
|
|
599
|
+
}
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
return $table;
|
|
603
|
+
}
|
|
604
|
+
|
|
519
605
|
/************************************************************
|
|
520
606
|
* Destroy the third-party widgets the form built. Removing
|
|
521
607
|
* their DOM is not enough: Tom Select keeps listeners on
|
|
@@ -528,16 +614,29 @@ function destroy_widgets(gobj, $container)
|
|
|
528
614
|
{
|
|
529
615
|
let destroy = (what, widget) => {
|
|
530
616
|
try {
|
|
531
|
-
|
|
617
|
+
/* vanilla-jsoneditor 3 destroys asynchronously: its failure
|
|
618
|
+
* is a rejected promise, which no try/catch sees. */
|
|
619
|
+
let r = widget.destroy();
|
|
620
|
+
if(r && typeof r.then === "function") {
|
|
621
|
+
r.catch((e) => {
|
|
622
|
+
log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
532
625
|
} catch(e) {
|
|
533
626
|
log_warning(`${gobj_short_name(gobj)}: cannot destroy ${what}: ${e}`);
|
|
534
627
|
}
|
|
535
628
|
};
|
|
629
|
+
let forget = ($el) => {
|
|
630
|
+
if($el.yui_table_id && gobj.priv && gobj.priv.tables) {
|
|
631
|
+
gobj.priv.tables.delete($el.yui_table_id);
|
|
632
|
+
}
|
|
633
|
+
};
|
|
536
634
|
$container.querySelectorAll('.yui-tabulator-table-nested').forEach(($el) => {
|
|
537
635
|
if($el.tabulator) {
|
|
538
636
|
destroy("nested table", $el.tabulator);
|
|
539
637
|
$el.tabulator = null;
|
|
540
638
|
}
|
|
639
|
+
forget($el);
|
|
541
640
|
});
|
|
542
641
|
$container.querySelectorAll('.yui-form-data-input').forEach(($el) => {
|
|
543
642
|
if($el.tom_select) {
|
|
@@ -552,6 +651,7 @@ function destroy_widgets(gobj, $container)
|
|
|
552
651
|
destroy("table", $el.tabulator);
|
|
553
652
|
$el.tabulator = null;
|
|
554
653
|
}
|
|
654
|
+
forget($el);
|
|
555
655
|
});
|
|
556
656
|
}
|
|
557
657
|
|
|
@@ -599,6 +699,31 @@ function name_form_control($field, conf)
|
|
|
599
699
|
$ts.setAttribute("aria-label", t(key));
|
|
600
700
|
$ts.setAttribute("data-i18n-aria-label", key);
|
|
601
701
|
}
|
|
702
|
+
|
|
703
|
+
/* The ✕ of the clear_button plugin is drawn by Tom Select too, with a
|
|
704
|
+
* title written once with t() and no key: named here, after the
|
|
705
|
+
* render, with its key, so it re-translates. */
|
|
706
|
+
let $clear = $field.querySelector(".ts-wrapper .clear-button");
|
|
707
|
+
if($clear) {
|
|
708
|
+
const CLEAR_KEY = "remove all selected options";
|
|
709
|
+
$clear.setAttribute("role", "button");
|
|
710
|
+
/* A button a keyboard can reach and press: a key press clicks
|
|
711
|
+
* it, so it reaches Tom Select's own click handler. */
|
|
712
|
+
$clear.setAttribute("tabindex", "0");
|
|
713
|
+
if(!$clear.yui_keys_wired) {
|
|
714
|
+
$clear.yui_keys_wired = true;
|
|
715
|
+
$clear.addEventListener("keydown", function(evt) {
|
|
716
|
+
if(evt.key === "Enter" || evt.key === " ") {
|
|
717
|
+
evt.preventDefault();
|
|
718
|
+
$clear.click();
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
$clear.setAttribute("title", t(CLEAR_KEY));
|
|
723
|
+
$clear.setAttribute("data-i18n-title", CLEAR_KEY);
|
|
724
|
+
$clear.setAttribute("aria-label", t(CLEAR_KEY));
|
|
725
|
+
$clear.setAttribute("data-i18n-aria-label", CLEAR_KEY);
|
|
726
|
+
}
|
|
602
727
|
}
|
|
603
728
|
|
|
604
729
|
function build_form(gobj)
|
|
@@ -1161,12 +1286,7 @@ function create_form_field(
|
|
|
1161
1286
|
*
|
|
1162
1287
|
*--------------------------------------*/
|
|
1163
1288
|
let $element;
|
|
1164
|
-
let
|
|
1165
|
-
$row: null, // not null if it's a nested table
|
|
1166
|
-
$table: null, // Element of tabulator
|
|
1167
|
-
record: {},
|
|
1168
|
-
loading: false,
|
|
1169
|
-
};
|
|
1289
|
+
let $add_table = null; // the table the field's "add" button adds a row to
|
|
1170
1290
|
|
|
1171
1291
|
switch (tag) {
|
|
1172
1292
|
case 'input':
|
|
@@ -1175,7 +1295,7 @@ function create_form_field(
|
|
|
1175
1295
|
$element = createElement2(
|
|
1176
1296
|
['div', {class: 'xfield field is-horizontal'}, [
|
|
1177
1297
|
['div', {class: 'field-label is-normal' }, [
|
|
1178
|
-
["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
|
|
1298
|
+
["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
|
|
1179
1299
|
]],
|
|
1180
1300
|
|
|
1181
1301
|
['div', {class: 'field-body'}, [
|
|
@@ -1192,7 +1312,7 @@ function create_form_field(
|
|
|
1192
1312
|
$element = createElement2(
|
|
1193
1313
|
['div', {class: 'xfield field is-horizontal'}, [
|
|
1194
1314
|
['div', {class: 'field-label is-normal' }, [
|
|
1195
|
-
["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
|
|
1315
|
+
["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
|
|
1196
1316
|
]],
|
|
1197
1317
|
|
|
1198
1318
|
['div', {class: 'field-body'}, [
|
|
@@ -1215,7 +1335,7 @@ function create_form_field(
|
|
|
1215
1335
|
$element = createElement2(
|
|
1216
1336
|
['div', {class: 'xfield field is-horizontal'}, [
|
|
1217
1337
|
['div', {class: 'field-label is-normal' }, [
|
|
1218
|
-
["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
|
|
1338
|
+
["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
|
|
1219
1339
|
]],
|
|
1220
1340
|
|
|
1221
1341
|
['div', {class: 'field-body'}, [
|
|
@@ -1231,7 +1351,7 @@ function create_form_field(
|
|
|
1231
1351
|
$element = createElement2(
|
|
1232
1352
|
['div', {class: 'xfield field is-horizontal'}, [
|
|
1233
1353
|
['div', {class: 'field-label is-normal' }, [
|
|
1234
|
-
["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
|
|
1354
|
+
["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
|
|
1235
1355
|
]],
|
|
1236
1356
|
|
|
1237
1357
|
['div', {class: 'field-body'}, [
|
|
@@ -1250,7 +1370,7 @@ function create_form_field(
|
|
|
1250
1370
|
$element = createElement2(
|
|
1251
1371
|
['div', {class: 'field is-horizontal tabulator-buttons'}, [
|
|
1252
1372
|
['div', {class: 'field-label is-normal' }, [
|
|
1253
|
-
['label', {class:'label', i18n:(label_i18n||label)}, label]
|
|
1373
|
+
['label', {class:'label', i18n:(label_i18n||label)}, text_node(label)]
|
|
1254
1374
|
]],
|
|
1255
1375
|
|
|
1256
1376
|
['div', {class: 'field-body'}, [
|
|
@@ -1265,8 +1385,18 @@ function create_form_field(
|
|
|
1265
1385
|
click: function(evt) {
|
|
1266
1386
|
evt.stopPropagation();
|
|
1267
1387
|
evt.preventDefault();
|
|
1388
|
+
if(!$add_table) {
|
|
1389
|
+
log_error(`${gobj_short_name(gobj)}: "add" of a field without a table`);
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1268
1392
|
gobj_send_event(gobj,
|
|
1269
|
-
"EV_ADD_TABLE_ROW",
|
|
1393
|
+
"EV_ADD_TABLE_ROW",
|
|
1394
|
+
{
|
|
1395
|
+
table_id: table_identity(gobj, $add_table),
|
|
1396
|
+
record: {},
|
|
1397
|
+
loading: false,
|
|
1398
|
+
},
|
|
1399
|
+
gobj
|
|
1270
1400
|
);
|
|
1271
1401
|
}
|
|
1272
1402
|
}]
|
|
@@ -1295,7 +1425,7 @@ function create_form_field(
|
|
|
1295
1425
|
$element = createElement2(
|
|
1296
1426
|
['div', {class: 'xfield field is-horizontal'}, [
|
|
1297
1427
|
['div', {class: 'field-label is-normal' }, [
|
|
1298
|
-
["label", {class:"label ", i18n:(label_i18n||label), for:name}, label]
|
|
1428
|
+
["label", {class:"label ", i18n:(label_i18n||label), for:name}, text_node(label)]
|
|
1299
1429
|
]],
|
|
1300
1430
|
|
|
1301
1431
|
['div', {class: 'field-body'}, [
|
|
@@ -1415,7 +1545,7 @@ function create_form_field(
|
|
|
1415
1545
|
},
|
|
1416
1546
|
opts.map(option =>
|
|
1417
1547
|
['option', {value:option, i18n:option},
|
|
1418
|
-
|
|
1548
|
+
text_node(option)] // data, not markup
|
|
1419
1549
|
),
|
|
1420
1550
|
{
|
|
1421
1551
|
'change': function (evt) {
|
|
@@ -1457,8 +1587,8 @@ function create_form_field(
|
|
|
1457
1587
|
multiple: true,
|
|
1458
1588
|
},
|
|
1459
1589
|
opts.map(option => is_icon
|
|
1460
|
-
? ['option', {value:option}, option]
|
|
1461
|
-
: ['option', {value:option, i18n:option}, option]
|
|
1590
|
+
? ['option', {value:option}, text_node(option)]
|
|
1591
|
+
: ['option', {value:option, i18n:option}, text_node(option)]
|
|
1462
1592
|
)
|
|
1463
1593
|
];
|
|
1464
1594
|
$extend = createElement2(extend);
|
|
@@ -1517,7 +1647,7 @@ function create_form_field(
|
|
|
1517
1647
|
$extend = createElement2(
|
|
1518
1648
|
['label', {class: 'radio'}, [
|
|
1519
1649
|
['input', {type: 'radio', name: name}],
|
|
1520
|
-
['span', {i18n: label_key}, label_key]
|
|
1650
|
+
['span', {i18n: label_key}, text_node(label_key)]
|
|
1521
1651
|
]]
|
|
1522
1652
|
);
|
|
1523
1653
|
$control.appendChild($extend);
|
|
@@ -1595,7 +1725,7 @@ function create_form_field(
|
|
|
1595
1725
|
$extend = createElement2(extend);
|
|
1596
1726
|
$control.appendChild($extend);
|
|
1597
1727
|
$extend.tabulator = create_tabulator(gobj, $extend, name, options);
|
|
1598
|
-
|
|
1728
|
+
$add_table = $extend;
|
|
1599
1729
|
break;
|
|
1600
1730
|
}
|
|
1601
1731
|
|
|
@@ -2105,6 +2235,7 @@ function template2columns(gobj, columns, template, sub_elements)
|
|
|
2105
2235
|
let column = {
|
|
2106
2236
|
field: field_desc.name,
|
|
2107
2237
|
title: t(field_desc.header || field_desc.name),
|
|
2238
|
+
titleFormatter: text_title_formatter,
|
|
2108
2239
|
editable: get_editable_state,
|
|
2109
2240
|
editor: false,
|
|
2110
2241
|
headerWordWrap: true,
|
|
@@ -2131,7 +2262,7 @@ function template2columns(gobj, columns, template, sub_elements)
|
|
|
2131
2262
|
switch(field_desc.type) {
|
|
2132
2263
|
case "object":
|
|
2133
2264
|
case "dict":
|
|
2134
|
-
// TODO
|
|
2265
|
+
// TODO it is another form: a button that opens it in a popup?
|
|
2135
2266
|
// Object.entries(value).forEach(([key, value]) => {
|
|
2136
2267
|
// build_html_form_field_conf_from_template(gobj, $form, key, value);
|
|
2137
2268
|
// });
|
|
@@ -2173,11 +2304,14 @@ function template2columns(gobj, columns, template, sub_elements)
|
|
|
2173
2304
|
evt.stopPropagation();
|
|
2174
2305
|
let $row = cell.getRow().getElement();
|
|
2175
2306
|
let $extend = $row.querySelector(`[name="${field_desc.name}"]`);
|
|
2307
|
+
if(!$extend) {
|
|
2308
|
+
log_error(`${gobj_short_name(gobj)}: nested table '${field_desc.name}' not found in its row`);
|
|
2309
|
+
return;
|
|
2310
|
+
}
|
|
2176
2311
|
gobj_send_event(gobj,
|
|
2177
2312
|
"EV_ADD_TABLE_ROW",
|
|
2178
2313
|
{
|
|
2179
|
-
|
|
2180
|
-
$table: $extend, // Element of tabulator
|
|
2314
|
+
table_id: table_identity(gobj, $extend),
|
|
2181
2315
|
record: {},
|
|
2182
2316
|
loading: false,
|
|
2183
2317
|
},
|
|
@@ -2408,15 +2542,29 @@ function template2columns(gobj, columns, template, sub_elements)
|
|
|
2408
2542
|
* out-of-range number is more precise than anything generic here.
|
|
2409
2543
|
************************************************************/
|
|
2410
2544
|
function field_validation_message($input)
|
|
2545
|
+
{
|
|
2546
|
+
let key = field_validation_key($input);
|
|
2547
|
+
if(key) {
|
|
2548
|
+
return t(key);
|
|
2549
|
+
}
|
|
2550
|
+
return $input.validationMessage;
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
/************************************************************
|
|
2554
|
+
* The i18n key of the message, when the message is ours ("" when
|
|
2555
|
+
* it is the browser's): written as the help line's data-i18n, so
|
|
2556
|
+
* a language change re-translates the line on screen.
|
|
2557
|
+
************************************************************/
|
|
2558
|
+
function field_validation_key($input)
|
|
2411
2559
|
{
|
|
2412
2560
|
if($input.yui_json_error) {
|
|
2413
|
-
return
|
|
2561
|
+
return $input.yui_json_error;
|
|
2414
2562
|
}
|
|
2415
2563
|
let v = $input.validity;
|
|
2416
2564
|
if(v && v.valueMissing) {
|
|
2417
|
-
return
|
|
2565
|
+
return "this field is required";
|
|
2418
2566
|
}
|
|
2419
|
-
return
|
|
2567
|
+
return "";
|
|
2420
2568
|
}
|
|
2421
2569
|
|
|
2422
2570
|
/************************************************************
|
|
@@ -2442,6 +2590,7 @@ function mark_field_validity($input)
|
|
|
2442
2590
|
$input.classList.remove('is-danger');
|
|
2443
2591
|
if($h) {
|
|
2444
2592
|
$h.textContent = '';
|
|
2593
|
+
$h.removeAttribute('data-i18n');
|
|
2445
2594
|
$h.style.display = 'none';
|
|
2446
2595
|
}
|
|
2447
2596
|
return true;
|
|
@@ -2449,6 +2598,12 @@ function mark_field_validity($input)
|
|
|
2449
2598
|
|
|
2450
2599
|
$input.classList.add('is-danger');
|
|
2451
2600
|
if($h) {
|
|
2601
|
+
let key = field_validation_key($input);
|
|
2602
|
+
if(key) {
|
|
2603
|
+
$h.setAttribute('data-i18n', key);
|
|
2604
|
+
} else {
|
|
2605
|
+
$h.removeAttribute('data-i18n'); // the browser's own sentence
|
|
2606
|
+
}
|
|
2452
2607
|
$h.textContent = field_validation_message($input);
|
|
2453
2608
|
$h.style.display = 'block';
|
|
2454
2609
|
}
|
|
@@ -2920,8 +3075,7 @@ function load_tabulator_data(gobj, $table, value)
|
|
|
2920
3075
|
gobj_send_event(gobj,
|
|
2921
3076
|
"EV_ADD_TABLE_ROW",
|
|
2922
3077
|
{
|
|
2923
|
-
|
|
2924
|
-
$table: $table, // Element of tabulator
|
|
3078
|
+
table_id: table_identity(gobj, $table),
|
|
2925
3079
|
record: row,
|
|
2926
3080
|
loading: true,
|
|
2927
3081
|
},
|
|
@@ -2934,8 +3088,7 @@ function load_tabulator_data(gobj, $table, value)
|
|
|
2934
3088
|
gobj_send_event(gobj,
|
|
2935
3089
|
"EV_ADD_TABLE_ROW",
|
|
2936
3090
|
{
|
|
2937
|
-
|
|
2938
|
-
$table: $table, // Element of tabulator
|
|
3091
|
+
table_id: table_identity(gobj, $table),
|
|
2939
3092
|
record: row,
|
|
2940
3093
|
loading: true,
|
|
2941
3094
|
},
|
|
@@ -3098,13 +3251,16 @@ function treedb_value_2_form_value(gobj, field_desc, value)
|
|
|
3098
3251
|
/************************************************************
|
|
3099
3252
|
* A json field's value, parsed. validate_form() refuses a field
|
|
3100
3253
|
* that does not parse, so reaching the error here is a path that
|
|
3101
|
-
* skipped it: logged,
|
|
3254
|
+
* skipped it: logged, and the value is handed on AS IT IS. An
|
|
3255
|
+
* empty `{}` / `[]` in its place is a value nobody wrote, and
|
|
3256
|
+
* saved it wipes the column.
|
|
3102
3257
|
************************************************************/
|
|
3103
3258
|
function parse_json_value(gobj, field_desc, value)
|
|
3104
3259
|
{
|
|
3105
3260
|
let r = parse_json_field(value, field_desc.type);
|
|
3106
3261
|
if(r.error) {
|
|
3107
|
-
log_error(`${gobj_short_name(gobj)}: field '${field_desc.name}' (${field_desc.type}) holds no valid json,
|
|
3262
|
+
log_error(`${gobj_short_name(gobj)}: field '${field_desc.name}' (${field_desc.type}) holds no valid json, handed on as it is`);
|
|
3263
|
+
return value;
|
|
3108
3264
|
}
|
|
3109
3265
|
return r.value;
|
|
3110
3266
|
}
|
|
@@ -3197,6 +3353,9 @@ function form_value_2_treedb_value(gobj, field_desc, value)
|
|
|
3197
3353
|
break;
|
|
3198
3354
|
case "object":
|
|
3199
3355
|
case "dict":
|
|
3356
|
+
/* Parsed like a list: it went out as the editor's TEXT, and a
|
|
3357
|
+
* backend that reads a bad text stores {} without a word. */
|
|
3358
|
+
value = parse_json_value(gobj, field_desc, value);
|
|
3200
3359
|
break;
|
|
3201
3360
|
case "array":
|
|
3202
3361
|
case "list":
|
|
@@ -3400,9 +3559,13 @@ function ac_set_file_preview(gobj, event, kw, src)
|
|
|
3400
3559
|
************************************************************/
|
|
3401
3560
|
function ac_add_table_row(gobj, event, kw, src)
|
|
3402
3561
|
{
|
|
3403
|
-
let
|
|
3404
|
-
let $table =
|
|
3405
|
-
let tabulator = $table.tabulator;
|
|
3562
|
+
let table_id = kw.table_id;
|
|
3563
|
+
let $table = find_table(gobj, table_id);
|
|
3564
|
+
let tabulator = $table? $table.tabulator : null;
|
|
3565
|
+
if(!tabulator) {
|
|
3566
|
+
log_error(`${gobj_short_name(gobj)}: EV_ADD_TABLE_ROW to a table that is gone: '${table_id}'`);
|
|
3567
|
+
return -1;
|
|
3568
|
+
}
|
|
3406
3569
|
let record = kw.record;
|
|
3407
3570
|
let loading = kw.loading;
|
|
3408
3571
|
|
|
@@ -3432,13 +3595,17 @@ function ac_add_table_row(gobj, event, kw, src)
|
|
|
3432
3595
|
|
|
3433
3596
|
// TODO improve, to use only once the timeout?
|
|
3434
3597
|
setTimeout(function() {
|
|
3435
|
-
if(
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3598
|
+
if(gobj_is_destroying(gobj)) {
|
|
3599
|
+
return; // the form went in the meantime: nothing to redraw
|
|
3600
|
+
}
|
|
3601
|
+
/* A row LOADED redraws the table that took it, nested or not; a
|
|
3602
|
+
* row ADDED by hand to a nested table redraws the table of the
|
|
3603
|
+
* row the nested one lives in, which is what grew (closest()
|
|
3604
|
+
* is the table itself for an outer one). Re-checked: it may be
|
|
3605
|
+
* destroyed by now. */
|
|
3606
|
+
let $target = loading? $table : $table.closest('.yui-tabulator-table');
|
|
3607
|
+
if($target && $target.tabulator) {
|
|
3608
|
+
$target.tabulator.redraw(); /* Delete double scrollbar */
|
|
3442
3609
|
}
|
|
3443
3610
|
}, 30);
|
|
3444
3611
|
|