@yuneta/gobj-ui 7.26.38 → 7.26.39
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 +20 -0
- package/dist/gobj-ui.cjs.js +24 -3
- package/dist/gobj-ui.es.js +24 -3
- package/package.json +1 -1
- package/src/c_yui_form.js +26 -3
- package/src/form_close_asks_for_edits.wiring.test.js +197 -0
package/README.md
CHANGED
|
@@ -3394,6 +3394,26 @@ the middle, and **a toolbar left with a single group is centred**. An unknown
|
|
|
3394
3394
|
name is reported, not silently dropped: a typo would otherwise remove the save
|
|
3395
3395
|
button with no trace of why.
|
|
3396
3396
|
|
|
3397
|
+
### `C_YUI_FORM` — what closing it asks about
|
|
3398
|
+
|
|
3399
|
+
`changes` says the form is not what is stored: the reader changed it, or the
|
|
3400
|
+
record lacks a field that has a default, and the form shows the default. The
|
|
3401
|
+
save lights with it. **`edited`** (7.26.39+) says the READER changed it --
|
|
3402
|
+
typed, cleared, pasted -- since it was loaded, saved or undone, and it is the
|
|
3403
|
+
only thing a close asks about: the form answers `EV_WINDOW_TO_CLOSE` with
|
|
3404
|
+
`abort_close` and the warning *"all changes will be lost"* when `edited` is
|
|
3405
|
+
true. A record that lacks a defaulted field opens changed and closes without
|
|
3406
|
+
a question; until 7.26.39 it asked on every close, about nothing the reader
|
|
3407
|
+
would lose.
|
|
3408
|
+
|
|
3409
|
+
```js
|
|
3410
|
+
const kw = {abort_close: false};
|
|
3411
|
+
gobj_send_event(form, "EV_WINDOW_TO_CLOSE", kw, gobj);
|
|
3412
|
+
if(kw.abort_close) {
|
|
3413
|
+
// the reader changed it: ask kw.warning before closing
|
|
3414
|
+
}
|
|
3415
|
+
```
|
|
3416
|
+
|
|
3397
3417
|
### `C_YUI_FORM` — which field is editable, and the one `writable` does not govern
|
|
3398
3418
|
|
|
3399
3419
|
A form opened to LOOK at a record has no editable field: that is a property of
|
package/dist/gobj-ui.cjs.js
CHANGED
|
@@ -9483,6 +9483,7 @@ var attrs_table$17 = [
|
|
|
9483
9483
|
(0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_STRING, "form_id", 0, "", "Form identifier"),
|
|
9484
9484
|
(0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "initialized", 0, false, "Indicates if it is initialized"),
|
|
9485
9485
|
(0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "changes", 0, false, "Indicates if changes have been made"),
|
|
9486
|
+
(0, _yuneta_gobj_js.SDATA)(_yuneta_gobj_js.data_type_t.DTP_BOOLEAN, "edited", 0, false, "The reader changed the form (typed, cleared, pasted) since it was loaded, saved or undone: what closing it would lose. A field the record lacks, filled with its default, is a change of the form (`changes`) and not of the reader"),
|
|
9486
9487
|
(0, _yuneta_gobj_js.SDATA_END)()
|
|
9487
9488
|
];
|
|
9488
9489
|
var PRIVATE_DATA$17 = {
|
|
@@ -9576,6 +9577,7 @@ function set_changed_stated(gobj, changed) {
|
|
|
9576
9577
|
});
|
|
9577
9578
|
} else {
|
|
9578
9579
|
(0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "changes", false);
|
|
9580
|
+
(0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "edited", false);
|
|
9579
9581
|
enable($button_save, false, OFF_COLOR);
|
|
9580
9582
|
enable($button_undo, false, OFF_COLOR);
|
|
9581
9583
|
if (gobj.priv.rearm_timer) clearTimeout(gobj.priv.rearm_timer);
|
|
@@ -9599,6 +9601,16 @@ function set_changed_stated(gobj, changed) {
|
|
|
9599
9601
|
}
|
|
9600
9602
|
}
|
|
9601
9603
|
/************************************************************
|
|
9604
|
+
* A change the READER made -- typed, cleared, pasted: what
|
|
9605
|
+
* closing the form would lose (ac_window_to_close). Clearing
|
|
9606
|
+
* and pasting wrote their values and marked nothing, so a form
|
|
9607
|
+
* cleared or pasted into kept its save off.
|
|
9608
|
+
************************************************************/
|
|
9609
|
+
function set_edited_by_reader(gobj) {
|
|
9610
|
+
set_changed_stated(gobj, true);
|
|
9611
|
+
(0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "edited", true);
|
|
9612
|
+
}
|
|
9613
|
+
/************************************************************
|
|
9602
9614
|
*
|
|
9603
9615
|
************************************************************/
|
|
9604
9616
|
async function readClipboard$1(gobj) {
|
|
@@ -11980,10 +11992,16 @@ function form_value_2_treedb_value(gobj, field_desc, value) {
|
|
|
11980
11992
|
* Actions
|
|
11981
11993
|
***************************/
|
|
11982
11994
|
/************************************************************
|
|
11983
|
-
* From Window parent, is going to close
|
|
11995
|
+
* From Window parent, is going to close.
|
|
11996
|
+
*
|
|
11997
|
+
* It asks only for what the READER changed (`edited`). A record
|
|
11998
|
+
* that lacks a field opens CHANGED -- the default fills it, and
|
|
11999
|
+
* the save lights to store it -- but the reader did nothing, and
|
|
12000
|
+
* the question asked of every such record, on every close, was
|
|
12001
|
+
* about nothing they would lose.
|
|
11984
12002
|
************************************************************/
|
|
11985
12003
|
function ac_window_to_close(gobj, event, kw, src) {
|
|
11986
|
-
if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "
|
|
12004
|
+
if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "edited")) {
|
|
11987
12005
|
kw.abort_close = true;
|
|
11988
12006
|
kw.warning = "all changes will be lost";
|
|
11989
12007
|
}
|
|
@@ -11999,6 +12017,7 @@ function ac_load_record(gobj, event, kw, src) {
|
|
|
11999
12017
|
let modified = set_form_values(gobj, (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "template"), $form, kw);
|
|
12000
12018
|
apply_form_mode(gobj, $form);
|
|
12001
12019
|
set_changed_stated(gobj, modified);
|
|
12020
|
+
(0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "edited", false);
|
|
12002
12021
|
(0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "initialized", true);
|
|
12003
12022
|
return 0;
|
|
12004
12023
|
}
|
|
@@ -12042,6 +12061,7 @@ function ac_clear_record(gobj, event, kw, src) {
|
|
|
12042
12061
|
let $form = (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "$container").querySelector("form");
|
|
12043
12062
|
clear_validation(gobj, $form);
|
|
12044
12063
|
clear_data(gobj, $form);
|
|
12064
|
+
set_edited_by_reader(gobj);
|
|
12045
12065
|
return 0;
|
|
12046
12066
|
}
|
|
12047
12067
|
/************************************************************
|
|
@@ -12120,7 +12140,7 @@ function ac_add_table_row(gobj, event, kw, src) {
|
|
|
12120
12140
|
* Internal event
|
|
12121
12141
|
************************************************************/
|
|
12122
12142
|
function ac_record_changed(gobj, event, kw, src) {
|
|
12123
|
-
if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "initialized"))
|
|
12143
|
+
if ((0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "initialized")) set_edited_by_reader(gobj);
|
|
12124
12144
|
return 0;
|
|
12125
12145
|
}
|
|
12126
12146
|
/************************************************************
|
|
@@ -12143,6 +12163,7 @@ function ac_paste_record(gobj, event, kw, src) {
|
|
|
12143
12163
|
if ((0, _yuneta_gobj_js.is_object)(record)) {
|
|
12144
12164
|
(0, _yuneta_gobj_js.gobj_write_bool_attr)(gobj, "initialized", true);
|
|
12145
12165
|
set_form_values(gobj, (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "template"), $form, record);
|
|
12166
|
+
set_edited_by_reader(gobj);
|
|
12146
12167
|
}
|
|
12147
12168
|
return 0;
|
|
12148
12169
|
}
|
package/dist/gobj-ui.es.js
CHANGED
|
@@ -9478,6 +9478,7 @@ var attrs_table$17 = [
|
|
|
9478
9478
|
SDATA(data_type_t.DTP_STRING, "form_id", 0, "", "Form identifier"),
|
|
9479
9479
|
SDATA(data_type_t.DTP_BOOLEAN, "initialized", 0, false, "Indicates if it is initialized"),
|
|
9480
9480
|
SDATA(data_type_t.DTP_BOOLEAN, "changes", 0, false, "Indicates if changes have been made"),
|
|
9481
|
+
SDATA(data_type_t.DTP_BOOLEAN, "edited", 0, false, "The reader changed the form (typed, cleared, pasted) since it was loaded, saved or undone: what closing it would lose. A field the record lacks, filled with its default, is a change of the form (`changes`) and not of the reader"),
|
|
9481
9482
|
SDATA_END()
|
|
9482
9483
|
];
|
|
9483
9484
|
var PRIVATE_DATA$17 = {
|
|
@@ -9571,6 +9572,7 @@ function set_changed_stated(gobj, changed) {
|
|
|
9571
9572
|
});
|
|
9572
9573
|
} else {
|
|
9573
9574
|
gobj_write_bool_attr(gobj, "changes", false);
|
|
9575
|
+
gobj_write_bool_attr(gobj, "edited", false);
|
|
9574
9576
|
enable($button_save, false, OFF_COLOR);
|
|
9575
9577
|
enable($button_undo, false, OFF_COLOR);
|
|
9576
9578
|
if (gobj.priv.rearm_timer) clearTimeout(gobj.priv.rearm_timer);
|
|
@@ -9594,6 +9596,16 @@ function set_changed_stated(gobj, changed) {
|
|
|
9594
9596
|
}
|
|
9595
9597
|
}
|
|
9596
9598
|
/************************************************************
|
|
9599
|
+
* A change the READER made -- typed, cleared, pasted: what
|
|
9600
|
+
* closing the form would lose (ac_window_to_close). Clearing
|
|
9601
|
+
* and pasting wrote their values and marked nothing, so a form
|
|
9602
|
+
* cleared or pasted into kept its save off.
|
|
9603
|
+
************************************************************/
|
|
9604
|
+
function set_edited_by_reader(gobj) {
|
|
9605
|
+
set_changed_stated(gobj, true);
|
|
9606
|
+
gobj_write_bool_attr(gobj, "edited", true);
|
|
9607
|
+
}
|
|
9608
|
+
/************************************************************
|
|
9597
9609
|
*
|
|
9598
9610
|
************************************************************/
|
|
9599
9611
|
async function readClipboard$1(gobj) {
|
|
@@ -11975,10 +11987,16 @@ function form_value_2_treedb_value(gobj, field_desc, value) {
|
|
|
11975
11987
|
* Actions
|
|
11976
11988
|
***************************/
|
|
11977
11989
|
/************************************************************
|
|
11978
|
-
* From Window parent, is going to close
|
|
11990
|
+
* From Window parent, is going to close.
|
|
11991
|
+
*
|
|
11992
|
+
* It asks only for what the READER changed (`edited`). A record
|
|
11993
|
+
* that lacks a field opens CHANGED -- the default fills it, and
|
|
11994
|
+
* the save lights to store it -- but the reader did nothing, and
|
|
11995
|
+
* the question asked of every such record, on every close, was
|
|
11996
|
+
* about nothing they would lose.
|
|
11979
11997
|
************************************************************/
|
|
11980
11998
|
function ac_window_to_close(gobj, event, kw, src) {
|
|
11981
|
-
if (gobj_read_bool_attr(gobj, "
|
|
11999
|
+
if (gobj_read_bool_attr(gobj, "edited")) {
|
|
11982
12000
|
kw.abort_close = true;
|
|
11983
12001
|
kw.warning = "all changes will be lost";
|
|
11984
12002
|
}
|
|
@@ -11994,6 +12012,7 @@ function ac_load_record(gobj, event, kw, src) {
|
|
|
11994
12012
|
let modified = set_form_values(gobj, gobj_read_attr(gobj, "template"), $form, kw);
|
|
11995
12013
|
apply_form_mode(gobj, $form);
|
|
11996
12014
|
set_changed_stated(gobj, modified);
|
|
12015
|
+
gobj_write_bool_attr(gobj, "edited", false);
|
|
11997
12016
|
gobj_write_bool_attr(gobj, "initialized", true);
|
|
11998
12017
|
return 0;
|
|
11999
12018
|
}
|
|
@@ -12037,6 +12056,7 @@ function ac_clear_record(gobj, event, kw, src) {
|
|
|
12037
12056
|
let $form = gobj_read_attr(gobj, "$container").querySelector("form");
|
|
12038
12057
|
clear_validation(gobj, $form);
|
|
12039
12058
|
clear_data(gobj, $form);
|
|
12059
|
+
set_edited_by_reader(gobj);
|
|
12040
12060
|
return 0;
|
|
12041
12061
|
}
|
|
12042
12062
|
/************************************************************
|
|
@@ -12115,7 +12135,7 @@ function ac_add_table_row(gobj, event, kw, src) {
|
|
|
12115
12135
|
* Internal event
|
|
12116
12136
|
************************************************************/
|
|
12117
12137
|
function ac_record_changed(gobj, event, kw, src) {
|
|
12118
|
-
if (gobj_read_bool_attr(gobj, "initialized"))
|
|
12138
|
+
if (gobj_read_bool_attr(gobj, "initialized")) set_edited_by_reader(gobj);
|
|
12119
12139
|
return 0;
|
|
12120
12140
|
}
|
|
12121
12141
|
/************************************************************
|
|
@@ -12138,6 +12158,7 @@ function ac_paste_record(gobj, event, kw, src) {
|
|
|
12138
12158
|
if (is_object(record)) {
|
|
12139
12159
|
gobj_write_bool_attr(gobj, "initialized", true);
|
|
12140
12160
|
set_form_values(gobj, gobj_read_attr(gobj, "template"), $form, record);
|
|
12161
|
+
set_edited_by_reader(gobj);
|
|
12141
12162
|
}
|
|
12142
12163
|
return 0;
|
|
12143
12164
|
}
|
package/package.json
CHANGED
package/src/c_yui_form.js
CHANGED
|
@@ -167,6 +167,7 @@ SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "Container eleme
|
|
|
167
167
|
SDATA(data_type_t.DTP_STRING, "form_id", 0, "", "Form identifier"),
|
|
168
168
|
SDATA(data_type_t.DTP_BOOLEAN, "initialized", 0, false, "Indicates if it is initialized"),
|
|
169
169
|
SDATA(data_type_t.DTP_BOOLEAN, "changes", 0, false, "Indicates if changes have been made"),
|
|
170
|
+
SDATA(data_type_t.DTP_BOOLEAN, "edited", 0, false, "The reader changed the form (typed, cleared, pasted) since it was loaded, saved or undone: what closing it would lose. A field the record lacks, filled with its default, is a change of the form (`changes`) and not of the reader"),
|
|
170
171
|
SDATA_END()
|
|
171
172
|
];
|
|
172
173
|
|
|
@@ -349,6 +350,7 @@ function set_changed_stated(gobj, changed)
|
|
|
349
350
|
* Data not changed, disable buttons to save/undo
|
|
350
351
|
*/
|
|
351
352
|
gobj_write_bool_attr(gobj, "changes", false);
|
|
353
|
+
gobj_write_bool_attr(gobj, "edited", false);
|
|
352
354
|
|
|
353
355
|
enable($button_save, false, OFF_COLOR);
|
|
354
356
|
enable($button_undo, false, OFF_COLOR);
|
|
@@ -390,6 +392,18 @@ function set_changed_stated(gobj, changed)
|
|
|
390
392
|
}
|
|
391
393
|
}
|
|
392
394
|
|
|
395
|
+
/************************************************************
|
|
396
|
+
* A change the READER made -- typed, cleared, pasted: what
|
|
397
|
+
* closing the form would lose (ac_window_to_close). Clearing
|
|
398
|
+
* and pasting wrote their values and marked nothing, so a form
|
|
399
|
+
* cleared or pasted into kept its save off.
|
|
400
|
+
************************************************************/
|
|
401
|
+
function set_edited_by_reader(gobj)
|
|
402
|
+
{
|
|
403
|
+
set_changed_stated(gobj, true);
|
|
404
|
+
gobj_write_bool_attr(gobj, "edited", true);
|
|
405
|
+
}
|
|
406
|
+
|
|
393
407
|
/************************************************************
|
|
394
408
|
*
|
|
395
409
|
************************************************************/
|
|
@@ -3606,11 +3620,17 @@ function form_value_2_treedb_value(gobj, field_desc, value)
|
|
|
3606
3620
|
|
|
3607
3621
|
|
|
3608
3622
|
/************************************************************
|
|
3609
|
-
* From Window parent, is going to close
|
|
3623
|
+
* From Window parent, is going to close.
|
|
3624
|
+
*
|
|
3625
|
+
* It asks only for what the READER changed (`edited`). A record
|
|
3626
|
+
* that lacks a field opens CHANGED -- the default fills it, and
|
|
3627
|
+
* the save lights to store it -- but the reader did nothing, and
|
|
3628
|
+
* the question asked of every such record, on every close, was
|
|
3629
|
+
* about nothing they would lose.
|
|
3610
3630
|
************************************************************/
|
|
3611
3631
|
function ac_window_to_close(gobj, event, kw, src)
|
|
3612
3632
|
{
|
|
3613
|
-
if(gobj_read_bool_attr(gobj, "
|
|
3633
|
+
if(gobj_read_bool_attr(gobj, "edited")) {
|
|
3614
3634
|
kw.abort_close = true; // Don't close the window until fields repaired
|
|
3615
3635
|
/* An i18n KEY, not a sentence: the dialog renders its message with
|
|
3616
3636
|
* `i18n: message`. The English sentence that was here was a key
|
|
@@ -3634,6 +3654,7 @@ function ac_load_record(gobj, event, kw, src)
|
|
|
3634
3654
|
let modified = set_form_values(gobj, gobj_read_attr(gobj, "template"), $form, kw);
|
|
3635
3655
|
apply_form_mode(gobj, $form);
|
|
3636
3656
|
set_changed_stated(gobj, modified);
|
|
3657
|
+
gobj_write_bool_attr(gobj, "edited", false);
|
|
3637
3658
|
gobj_write_bool_attr(gobj, "initialized", true);
|
|
3638
3659
|
|
|
3639
3660
|
return 0;
|
|
@@ -3707,6 +3728,7 @@ function ac_clear_record(gobj, event, kw, src)
|
|
|
3707
3728
|
let $form = $container.querySelector('form');
|
|
3708
3729
|
clear_validation(gobj, $form);
|
|
3709
3730
|
clear_data(gobj, $form);
|
|
3731
|
+
set_edited_by_reader(gobj);
|
|
3710
3732
|
return 0;
|
|
3711
3733
|
}
|
|
3712
3734
|
|
|
@@ -3820,7 +3842,7 @@ function ac_add_table_row(gobj, event, kw, src)
|
|
|
3820
3842
|
function ac_record_changed(gobj, event, kw, src)
|
|
3821
3843
|
{
|
|
3822
3844
|
if(gobj_read_bool_attr(gobj, "initialized")) {
|
|
3823
|
-
|
|
3845
|
+
set_edited_by_reader(gobj);
|
|
3824
3846
|
}
|
|
3825
3847
|
return 0;
|
|
3826
3848
|
}
|
|
@@ -3854,6 +3876,7 @@ function ac_paste_record(gobj, event, kw, src)
|
|
|
3854
3876
|
if(is_object(record)) {
|
|
3855
3877
|
gobj_write_bool_attr(gobj, "initialized", true);
|
|
3856
3878
|
set_form_values(gobj, gobj_read_attr(gobj, "template"), $form, record);
|
|
3879
|
+
set_edited_by_reader(gobj);
|
|
3857
3880
|
}
|
|
3858
3881
|
return 0;
|
|
3859
3882
|
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* form_close_asks_for_edits.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* Closing a C_YUI_FORM asks "all changes will be lost" only for what
|
|
5
|
+
* the READER changed. A field the record lacks is filled with its
|
|
6
|
+
* default when the record is loaded: the form then differs from what
|
|
7
|
+
* is stored, and its save lights (`changes`) -- but the reader did
|
|
8
|
+
* nothing, and the close asked all the same. In estadodelaire that
|
|
9
|
+
* was every device whose alarm colours a save had wiped (16 of 19),
|
|
10
|
+
* on every close of its settings. What the reader does -- types,
|
|
11
|
+
* clears, pastes -- is `edited`, and that is what the close asks
|
|
12
|
+
* about.
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2026, ArtGins.
|
|
15
|
+
* All Rights Reserved.
|
|
16
|
+
***********************************************************************/
|
|
17
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
18
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
19
|
+
|
|
20
|
+
install_dom_double();
|
|
21
|
+
|
|
22
|
+
if(typeof globalThis.ResizeObserver === "undefined") {
|
|
23
|
+
globalThis.ResizeObserver = class {
|
|
24
|
+
observe() {}
|
|
25
|
+
unobserve() {}
|
|
26
|
+
disconnect() {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
SDATA_END, gclass_create,
|
|
32
|
+
gobj_start_up, gobj_create_yuno, gobj_create_pure_child,
|
|
33
|
+
gobj_start, gobj_send_event, gobj_read_attr,
|
|
34
|
+
set_log_callback,
|
|
35
|
+
} = await import("@yuneta/gobj-js");
|
|
36
|
+
const {register_c_yui_form} = await import("./c_yui_form.js");
|
|
37
|
+
|
|
38
|
+
const logged = [];
|
|
39
|
+
let yuno = null;
|
|
40
|
+
|
|
41
|
+
/* The settings template of an estadodelaire device type, cut down: a
|
|
42
|
+
* field with a default beside a sub-form of three. */
|
|
43
|
+
const TEMPLATE = {
|
|
44
|
+
template_version: {
|
|
45
|
+
type: "integer",
|
|
46
|
+
default: 7,
|
|
47
|
+
flag: ["hidden", "persistent"]
|
|
48
|
+
},
|
|
49
|
+
alarm_colors: {
|
|
50
|
+
type: "object",
|
|
51
|
+
flag: ["writable", "persistent", "template"],
|
|
52
|
+
template: {
|
|
53
|
+
active_not_validated: {
|
|
54
|
+
type: "string",
|
|
55
|
+
default: "red",
|
|
56
|
+
flag: ["writable", "persistent", "color"]
|
|
57
|
+
},
|
|
58
|
+
active_validated: {
|
|
59
|
+
type: "string",
|
|
60
|
+
default: "#e5a50a",
|
|
61
|
+
flag: ["writable", "persistent", "color"]
|
|
62
|
+
},
|
|
63
|
+
not_active_not_validated: {
|
|
64
|
+
type: "string",
|
|
65
|
+
default: "Fuchsia",
|
|
66
|
+
flag: ["writable", "persistent", "color"]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const COMPLETE = {
|
|
73
|
+
template_version: 7,
|
|
74
|
+
alarm_colors: {
|
|
75
|
+
active_not_validated: "#ff0000",
|
|
76
|
+
active_validated: "#e5a50a",
|
|
77
|
+
not_active_not_validated: "#ff00ff"
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
beforeAll(async () => {
|
|
82
|
+
const i18next = (await import("i18next")).default;
|
|
83
|
+
await i18next.init({lng: "en", resources: {}});
|
|
84
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
85
|
+
set_log_callback((level, msg) => {
|
|
86
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
87
|
+
});
|
|
88
|
+
gclass_create("C_TEST_CLOSE_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
89
|
+
gclass_create(
|
|
90
|
+
"C_TEST_CLOSE_APP",
|
|
91
|
+
[["EV_SAVE_RECORD", 0]],
|
|
92
|
+
[["ST_IDLE", [
|
|
93
|
+
["EV_SAVE_RECORD", () => 0, null],
|
|
94
|
+
]]],
|
|
95
|
+
{}, 0, [SDATA_END()], {}, 0, 0, 0, 0
|
|
96
|
+
);
|
|
97
|
+
register_c_yui_form();
|
|
98
|
+
yuno = gobj_create_yuno("form_close_yuno", "C_TEST_CLOSE_HOST", {});
|
|
99
|
+
gobj_start(yuno);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
logged.length = 0;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
let seq = 0;
|
|
107
|
+
|
|
108
|
+
function build(record)
|
|
109
|
+
{
|
|
110
|
+
const app = gobj_create_pure_child(`capp${++seq}`, "C_TEST_CLOSE_APP", {}, yuno);
|
|
111
|
+
gobj_start(app);
|
|
112
|
+
const form = gobj_create_pure_child(`cform${seq}`, "C_YUI_FORM", {
|
|
113
|
+
template: TEMPLATE,
|
|
114
|
+
record: record,
|
|
115
|
+
editable: true,
|
|
116
|
+
}, app);
|
|
117
|
+
gobj_start(form);
|
|
118
|
+
return form;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* What a window or a sheet asks the form before it closes. */
|
|
122
|
+
function close_asks(form)
|
|
123
|
+
{
|
|
124
|
+
const kw = {abort_close: false};
|
|
125
|
+
gobj_send_event(form, "EV_WINDOW_TO_CLOSE", kw, form);
|
|
126
|
+
return kw.abort_close ? (kw.warning || "(no warning)") : "";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function errors()
|
|
130
|
+
{
|
|
131
|
+
return logged.filter(l => /error/i.test(l.level) || /ERROR/.test(l.msg));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
describe("the close of a form asks for what the reader changed", () => {
|
|
135
|
+
test("a record that lacks a defaulted field opens changed, and closes without asking", () => {
|
|
136
|
+
const form = build({template_version: 7, alarm_colors: null});
|
|
137
|
+
expect(gobj_read_attr(form, "changes")).toBe(true);
|
|
138
|
+
expect(gobj_read_attr(form, "edited")).toBe(false);
|
|
139
|
+
expect(close_asks(form)).toBe("");
|
|
140
|
+
expect(errors()).toEqual([]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("a change of the reader makes it ask", () => {
|
|
144
|
+
const form = build(COMPLETE);
|
|
145
|
+
expect(gobj_read_attr(form, "changes")).toBe(false);
|
|
146
|
+
expect(close_asks(form)).toBe("");
|
|
147
|
+
|
|
148
|
+
gobj_send_event(form, "EV_RECORD_CHANGED", {}, form);
|
|
149
|
+
expect(gobj_read_attr(form, "changes")).toBe(true);
|
|
150
|
+
expect(gobj_read_attr(form, "edited")).toBe(true);
|
|
151
|
+
expect(close_asks(form)).toBe("all changes will be lost");
|
|
152
|
+
expect(errors()).toEqual([]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("an undo, a save or a record loaded end what the close would lose", () => {
|
|
156
|
+
const form = build(COMPLETE);
|
|
157
|
+
|
|
158
|
+
gobj_send_event(form, "EV_RECORD_CHANGED", {}, form);
|
|
159
|
+
gobj_send_event(form, "EV_UNDO_RECORD", {}, form);
|
|
160
|
+
expect(gobj_read_attr(form, "edited")).toBe(false);
|
|
161
|
+
expect(close_asks(form)).toBe("");
|
|
162
|
+
|
|
163
|
+
gobj_send_event(form, "EV_RECORD_CHANGED", {}, form);
|
|
164
|
+
gobj_send_event(form, "EV_SAVE_RECORD", {}, form);
|
|
165
|
+
expect(gobj_read_attr(form, "edited")).toBe(false);
|
|
166
|
+
expect(close_asks(form)).toBe("");
|
|
167
|
+
|
|
168
|
+
gobj_send_event(form, "EV_RECORD_CHANGED", {}, form);
|
|
169
|
+
gobj_send_event(form, "EV_LOAD_RECORD", {template_version: 7, alarm_colors: null}, form);
|
|
170
|
+
expect(gobj_read_attr(form, "changes")).toBe(true); // the defaults again
|
|
171
|
+
expect(gobj_read_attr(form, "edited")).toBe(false);
|
|
172
|
+
expect(close_asks(form)).toBe("");
|
|
173
|
+
expect(errors()).toEqual([]);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("clearing and pasting are changes of the reader", () => {
|
|
177
|
+
const cleared = build(COMPLETE);
|
|
178
|
+
gobj_send_event(cleared, "EV_CLEAR_RECORD", {}, cleared);
|
|
179
|
+
expect(gobj_read_attr(cleared, "changes")).toBe(true);
|
|
180
|
+
expect(gobj_read_attr(cleared, "edited")).toBe(true);
|
|
181
|
+
expect(close_asks(cleared)).toBe("all changes will be lost");
|
|
182
|
+
|
|
183
|
+
const pasted = build(COMPLETE);
|
|
184
|
+
gobj_send_event(pasted, "EV_PASTE_RECORD", {record: {
|
|
185
|
+
template_version: 7,
|
|
186
|
+
alarm_colors: {
|
|
187
|
+
active_not_validated: "#00ff00",
|
|
188
|
+
active_validated: "#e5a50a",
|
|
189
|
+
not_active_not_validated: "#ff00ff"
|
|
190
|
+
}
|
|
191
|
+
}}, pasted);
|
|
192
|
+
expect(gobj_read_attr(pasted, "changes")).toBe(true);
|
|
193
|
+
expect(gobj_read_attr(pasted, "edited")).toBe(true);
|
|
194
|
+
expect(close_asks(pasted)).toBe("all changes will be lost");
|
|
195
|
+
expect(errors()).toEqual([]);
|
|
196
|
+
});
|
|
197
|
+
});
|