@yuneta/gobj-ui 7.32.10 → 7.32.11
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 +75 -0
- package/dist/gobj-ui.cjs.js +943 -358
- package/dist/gobj-ui.es.js +932 -359
- package/index.js +18 -0
- package/package.json +1 -1
- package/src/c_yui_node.js +47 -9
- package/src/c_yui_preferences.js +282 -0
- package/src/c_yui_shell.js +57 -1
- package/src/i18n_key_functions.js +6 -0
- package/src/preferences.wiring.test.js +159 -0
- package/src/yui_preferences.js +331 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* preferences.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* The Preferences page every app shows (C_YUI_PREFERENCES and the
|
|
5
|
+
* parts of yui_preferences.js):
|
|
6
|
+
*
|
|
7
|
+
* - three rows: theme, language, navigation, each marking the
|
|
8
|
+
* current choice;
|
|
9
|
+
* - a press applies through what the app registered
|
|
10
|
+
* (yui_preferences_setup), and the page marks the new choice;
|
|
11
|
+
* - the navigation is the shell's (yui_shell_nav_mode): a
|
|
12
|
+
* C_YUI_NODE tree with no mode of its own follows it, one with
|
|
13
|
+
* its own keeps it;
|
|
14
|
+
* - a language is shown and named in its own words, with `lang`;
|
|
15
|
+
* - the boxes the app adds come after the three rows.
|
|
16
|
+
*
|
|
17
|
+
* Driven through the real gclasses on a document double.
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2026, ArtGins.
|
|
20
|
+
* All Rights Reserved.
|
|
21
|
+
***********************************************************************/
|
|
22
|
+
import {test, expect, beforeAll, beforeEach} from "vitest";
|
|
23
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
24
|
+
|
|
25
|
+
install_dom_double();
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
SDATA_END, gclass_create,
|
|
29
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_pure_child,
|
|
30
|
+
gobj_start, gobj_send_event, gobj_read_attr,
|
|
31
|
+
set_log_callback,
|
|
32
|
+
} = await import("@yuneta/gobj-js");
|
|
33
|
+
const {register_c_yui_shell, yui_shell_nav_mode} = await import("./c_yui_shell.js");
|
|
34
|
+
const {register_c_yui_nav} = await import("./c_yui_nav.js");
|
|
35
|
+
const {register_c_yui_node, yui_node_nav_mode} = await import("./c_yui_node.js");
|
|
36
|
+
const {register_c_yui_preferences} = await import("./c_yui_preferences.js");
|
|
37
|
+
const {yui_preferences_setup} = await import("./yui_preferences.js");
|
|
38
|
+
|
|
39
|
+
const logged = [];
|
|
40
|
+
const applied = [];
|
|
41
|
+
const state = {theme: "light", language: "en"};
|
|
42
|
+
let yuno = null;
|
|
43
|
+
let seq = 0;
|
|
44
|
+
|
|
45
|
+
beforeAll(async () => {
|
|
46
|
+
const i18next = (await import("i18next")).default;
|
|
47
|
+
await i18next.init({lng: "en", resources: {}});
|
|
48
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
49
|
+
set_log_callback((level, msg) => {
|
|
50
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
51
|
+
});
|
|
52
|
+
gclass_create("C_TEST_PREF_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
53
|
+
register_c_yui_shell();
|
|
54
|
+
register_c_yui_nav();
|
|
55
|
+
register_c_yui_node();
|
|
56
|
+
register_c_yui_preferences();
|
|
57
|
+
yuno = gobj_create_yuno("pref_yuno", "C_TEST_PREF_HOST", {});
|
|
58
|
+
gobj_start(yuno);
|
|
59
|
+
|
|
60
|
+
yui_preferences_setup({
|
|
61
|
+
current_theme: () => state.theme,
|
|
62
|
+
set_theme: (v) => { state.theme = v; applied.push(["theme", v]); },
|
|
63
|
+
languages: [{value: "en", text: "English"}, {value: "es", text: "Español"}],
|
|
64
|
+
current_language: () => state.language,
|
|
65
|
+
set_language: (v) => { state.language = v; applied.push(["language", v]); },
|
|
66
|
+
sections: () => [["div", {class: "APP_BOX box"}, "the app's own"]],
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
logged.length = 0;
|
|
72
|
+
applied.length = 0;
|
|
73
|
+
window.localStorage.removeItem("yui_nav_mode");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/* The errors of the page, without the routing of a shell that has no
|
|
77
|
+
* routes: it starts on "/home" and has no target for it. */
|
|
78
|
+
function errors()
|
|
79
|
+
{
|
|
80
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg)
|
|
81
|
+
.filter((m) => !m.includes("no target for route"));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function new_page()
|
|
85
|
+
{
|
|
86
|
+
const n = ++seq;
|
|
87
|
+
const shell = gobj_create(`pref_shell_${n}`, "C_YUI_SHELL",
|
|
88
|
+
{config: {shell: {}}, default_route: "/home"}, yuno);
|
|
89
|
+
gobj_start(shell);
|
|
90
|
+
const page = gobj_create(`pref_page_${n}`, "C_YUI_PREFERENCES", {}, shell);
|
|
91
|
+
gobj_start(page);
|
|
92
|
+
return {shell, page, $c: gobj_read_attr(page, "$container")};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* The value of the marked option of a row */
|
|
96
|
+
function marked($c, row)
|
|
97
|
+
{
|
|
98
|
+
const $on = $c.querySelector(`.${row} .PREF_SEGMENT_ITEM.is-selected`);
|
|
99
|
+
return $on ? $on.querySelector(".PREF_SEGMENT_TEXT").textContent : null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
test("three rows, each marking the current choice, then the app's boxes", () => {
|
|
103
|
+
const {$c} = new_page();
|
|
104
|
+
expect($c.querySelector(".PREF_TITLE")).not.toBe(null);
|
|
105
|
+
expect($c.querySelectorAll(".PREF_APPEARANCE .PREF_FIELD").length).toBe(3);
|
|
106
|
+
expect(marked($c, "PREF_THEME")).toBe("light theme");
|
|
107
|
+
expect(marked($c, "PREF_LANGUAGE")).toBe("English");
|
|
108
|
+
expect(marked($c, "PREF_NAVIGATION")).toBe("stacked strips");
|
|
109
|
+
expect($c.querySelector(".APP_BOX")).not.toBe(null);
|
|
110
|
+
expect(errors()).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("a language is shown and named in its own words, with its lang", () => {
|
|
114
|
+
const {$c} = new_page();
|
|
115
|
+
const $es = $c.querySelectorAll(".PREF_LANGUAGE .PREF_SEGMENT_ITEM")[1];
|
|
116
|
+
expect($es.getAttribute("aria-label")).toBe("Español");
|
|
117
|
+
expect($es.getAttribute("lang")).toBe("es");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("a press applies through the app and the page marks it", () => {
|
|
121
|
+
const {page, $c} = new_page();
|
|
122
|
+
gobj_send_event(page, "EV_SET_THEME", {value: "dark"}, page);
|
|
123
|
+
gobj_send_event(page, "EV_SET_LANGUAGE", {value: "es"}, page);
|
|
124
|
+
expect(applied).toEqual([["theme", "dark"], ["language", "es"]]);
|
|
125
|
+
expect(marked($c, "PREF_THEME")).toBe("dark theme");
|
|
126
|
+
expect(marked($c, "PREF_LANGUAGE")).toBe("Español");
|
|
127
|
+
state.theme = "light";
|
|
128
|
+
state.language = "en";
|
|
129
|
+
expect(errors()).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("the navigation is the shell's, and a tree with no mode of its own follows it", () => {
|
|
133
|
+
const {shell, page, $c} = new_page();
|
|
134
|
+
const follows = gobj_create_pure_child(`pref_tree_a_${seq}`, "C_YUI_NODE", {
|
|
135
|
+
node_id: "a", base_route: "/a", children: [{id: "x", label: "X"}]
|
|
136
|
+
}, shell);
|
|
137
|
+
gobj_start(follows);
|
|
138
|
+
const pinned = gobj_create_pure_child(`pref_tree_b_${seq}`, "C_YUI_NODE", {
|
|
139
|
+
node_id: "b", base_route: "/b", nav_mode: "back", children: [{id: "y", label: "Y"}]
|
|
140
|
+
}, shell);
|
|
141
|
+
gobj_start(pinned);
|
|
142
|
+
|
|
143
|
+
gobj_send_event(page, "EV_SET_NAV_MODE", {value: "path"}, page);
|
|
144
|
+
expect(yui_shell_nav_mode(shell)).toBe("path");
|
|
145
|
+
expect(marked($c, "PREF_NAVIGATION")).toBe("breadcrumb");
|
|
146
|
+
expect(yui_node_nav_mode(follows)).toBe("path");
|
|
147
|
+
expect(yui_node_nav_mode(pinned)).toBe("back");
|
|
148
|
+
|
|
149
|
+
gobj_send_event(page, "EV_SET_NAV_MODE", {value: "stack"}, page);
|
|
150
|
+
expect(yui_node_nav_mode(follows)).toBe("stack");
|
|
151
|
+
expect(errors()).toEqual([]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("an unknown navigation mode is refused, and said", () => {
|
|
155
|
+
const {shell, page} = new_page();
|
|
156
|
+
gobj_send_event(page, "EV_SET_NAV_MODE", {value: "sideways"}, page);
|
|
157
|
+
expect(yui_shell_nav_mode(shell)).toBe("stack");
|
|
158
|
+
expect(errors().some((e) => e.includes("unknown nav_mode 'sideways'"))).toBe(true);
|
|
159
|
+
});
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_preferences.js
|
|
3
|
+
*
|
|
4
|
+
* The Preferences page of an app: what the READER chose for this
|
|
5
|
+
* browser. Every app shows at least the same three rows, in one
|
|
6
|
+
* box headed "Appearance":
|
|
7
|
+
*
|
|
8
|
+
* Theme light theme | dark theme
|
|
9
|
+
* Language the app's languages, each in its own words
|
|
10
|
+
* Navigation stacked strips | back to parent | breadcrumb
|
|
11
|
+
*
|
|
12
|
+
* Two ways to use it:
|
|
13
|
+
*
|
|
14
|
+
* - C_YUI_PREFERENCES, a whole page: a view the shell mounts at
|
|
15
|
+
* /preferences. It draws the three rows, then the boxes the app
|
|
16
|
+
* adds (the `sections` of the setup).
|
|
17
|
+
* - The parts, for an app whose page has fields of its own with
|
|
18
|
+
* actions of its own: yui_pref_header(), yui_pref_field(),
|
|
19
|
+
* yui_pref_segment() and yui_pref_appearance_fields(). The host
|
|
20
|
+
* declares EV_SET_THEME, EV_SET_LANGUAGE and EV_SET_NAV_MODE
|
|
21
|
+
* ({value}) and hands them to yui_pref_apply().
|
|
22
|
+
*
|
|
23
|
+
* The theme and the language are the APP's: it says once, at start
|
|
24
|
+
* up, how to read them and how to change them, with
|
|
25
|
+
* yui_preferences_setup(). The navigation is the shell's
|
|
26
|
+
* (yui_shell_nav_mode / yui_shell_set_nav_mode): every C_YUI_NODE
|
|
27
|
+
* tree with no mode of its own follows it, and an app with no tree
|
|
28
|
+
* keeps the choice for the day it has one.
|
|
29
|
+
*
|
|
30
|
+
* A language is SHOWN and NAMED in its own words ("Español", with
|
|
31
|
+
* its `lang`): a reader looking for their language finds it in the
|
|
32
|
+
* language they read, and an app of ten languages needs no key per
|
|
33
|
+
* language name.
|
|
34
|
+
*
|
|
35
|
+
* Copyright (c) 2026, ArtGins.
|
|
36
|
+
* All Rights Reserved.
|
|
37
|
+
***********************************************************************/
|
|
38
|
+
import {
|
|
39
|
+
log_error,
|
|
40
|
+
gobj_send_event,
|
|
41
|
+
refresh_language,
|
|
42
|
+
} from "@yuneta/gobj-js";
|
|
43
|
+
|
|
44
|
+
import {t} from "i18next";
|
|
45
|
+
|
|
46
|
+
import {yui_toolbar_icon} from "./yui_toolbar_icon.js";
|
|
47
|
+
import {text_node} from "./yui_text.js";
|
|
48
|
+
import {
|
|
49
|
+
yui_shell_of,
|
|
50
|
+
yui_shell_language_changed,
|
|
51
|
+
yui_shell_nav_mode,
|
|
52
|
+
yui_shell_set_nav_mode,
|
|
53
|
+
} from "./c_yui_shell.js";
|
|
54
|
+
|
|
55
|
+
/***************************************************************
|
|
56
|
+
* Constants
|
|
57
|
+
***************************************************************/
|
|
58
|
+
/* The keys this module hands to t() as variables (the options of a
|
|
59
|
+
* segment): published for validate-locales. */
|
|
60
|
+
export const YUI_PREFERENCES_I18N_KEYS = [
|
|
61
|
+
"light theme", "dark theme",
|
|
62
|
+
"stacked strips", "back to parent", "breadcrumb"
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const THEMES = [
|
|
66
|
+
{value: "light", key: "light theme", icon: "yi-sun"},
|
|
67
|
+
{value: "dark", key: "dark theme", icon: "yi-moon"}
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const NAV_MODE_OPTIONS = [
|
|
71
|
+
{value: "stack", key: "stacked strips", icon: "yi-layer-group"},
|
|
72
|
+
{value: "back", key: "back to parent", icon: "yi-arrow-left"},
|
|
73
|
+
{value: "path", key: "breadcrumb", icon: "yi-route"}
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
/* What the app said at start up (yui_preferences_setup). */
|
|
77
|
+
let __setup__ = null;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
/***************************
|
|
83
|
+
* Setup
|
|
84
|
+
***************************/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/***************************************************************
|
|
90
|
+
* How this app reads and changes its theme and its language, and
|
|
91
|
+
* the boxes it adds to the page. Called once, at start up, before
|
|
92
|
+
* the page is shown:
|
|
93
|
+
*
|
|
94
|
+
* yui_preferences_setup({
|
|
95
|
+
* current_theme: () => "dark",
|
|
96
|
+
* set_theme: (value) => {...},
|
|
97
|
+
* languages: [{value: "en", text: "English"},
|
|
98
|
+
* {value: "es", text: "Español"}],
|
|
99
|
+
* current_language: () => "es",
|
|
100
|
+
* set_language: (value) => {...}, // the app's i18next
|
|
101
|
+
* sections: (gobj) => [...], // optional: boxes
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* set_language() switches the app's i18next; the shell is told after
|
|
105
|
+
* it (yui_shell_language_changed), so the app does not do it twice.
|
|
106
|
+
***************************************************************/
|
|
107
|
+
function yui_preferences_setup(opts)
|
|
108
|
+
{
|
|
109
|
+
let o = opts || {};
|
|
110
|
+
let needed = ["current_theme", "set_theme", "current_language", "set_language"];
|
|
111
|
+
for(let name of needed) {
|
|
112
|
+
if(typeof o[name] !== "function") {
|
|
113
|
+
log_error(`yui_preferences_setup(): '${name}' must be a function`);
|
|
114
|
+
return -1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if(!Array.isArray(o.languages) || o.languages.length === 0) {
|
|
118
|
+
log_error(`yui_preferences_setup(): 'languages' must list the app's languages`);
|
|
119
|
+
return -1;
|
|
120
|
+
}
|
|
121
|
+
if(o.sections !== undefined && typeof o.sections !== "function") {
|
|
122
|
+
log_error(`yui_preferences_setup(): 'sections' must be a function`);
|
|
123
|
+
return -1;
|
|
124
|
+
}
|
|
125
|
+
__setup__ = o;
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* What the app said, or null (and an error) when it said nothing. */
|
|
130
|
+
function setup_of(who)
|
|
131
|
+
{
|
|
132
|
+
if(!__setup__) {
|
|
133
|
+
log_error(`${who}: no yui_preferences_setup() — the app must call it at start up`);
|
|
134
|
+
}
|
|
135
|
+
return __setup__;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
/***************************
|
|
142
|
+
* Parts of the page
|
|
143
|
+
***************************/
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
/***************************************************************
|
|
149
|
+
* The title of the page and the name of its first box.
|
|
150
|
+
***************************************************************/
|
|
151
|
+
function yui_pref_header()
|
|
152
|
+
{
|
|
153
|
+
return ["div", {class: "PREF_HEADER", style: "margin-bottom:0.5rem;"}, [
|
|
154
|
+
["h1", {class: "PREF_TITLE title is-3 has-text-link", style: "margin-bottom:0.25rem;",
|
|
155
|
+
i18n: "preferences"}, "preferences"],
|
|
156
|
+
["p", {class: "PREF_SUBTITLE subtitle is-6 has-text-grey", style: "margin-bottom:1rem;",
|
|
157
|
+
i18n: "appearance"}, "appearance"]
|
|
158
|
+
]];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/***************************************************************
|
|
162
|
+
* A box of fields, as wide as the page reads well.
|
|
163
|
+
***************************************************************/
|
|
164
|
+
function yui_pref_box(fields, extra_class)
|
|
165
|
+
{
|
|
166
|
+
return ["div", {class: `PREF_BOX box ${extra_class || ""}`, style: "max-width:540px;"},
|
|
167
|
+
fields];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/***************************************************************
|
|
171
|
+
* One field: its label over its control.
|
|
172
|
+
***************************************************************/
|
|
173
|
+
function yui_pref_field(label_key, control, extra_class)
|
|
174
|
+
{
|
|
175
|
+
return ["div", {class: `PREF_FIELD field ${extra_class || ""}`,
|
|
176
|
+
style: "margin-bottom:1.25rem;"}, [
|
|
177
|
+
["label", {class: "PREF_LABEL label", i18n: label_key}, label_key],
|
|
178
|
+
["div", {class: "PREF_CONTROL control"}, [control]]
|
|
179
|
+
]];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/***************************************************************
|
|
183
|
+
* A segmented choice: one button per option, the current one
|
|
184
|
+
* marked (`is-primary is-selected`). An option is
|
|
185
|
+
*
|
|
186
|
+
* {value, key, icon} the label and the name are the key
|
|
187
|
+
* {value, text, lang} the label and the name are the text,
|
|
188
|
+
* which is data (a language's own name)
|
|
189
|
+
*
|
|
190
|
+
* A click sends `event_name` {value} to `gobj`: the click is an OS
|
|
191
|
+
* notification, the change is an action of the host.
|
|
192
|
+
***************************************************************/
|
|
193
|
+
function yui_pref_segment(gobj, event_name, options, current, extra_class)
|
|
194
|
+
{
|
|
195
|
+
let buttons = options.map(function(opt) {
|
|
196
|
+
let active = (opt.value === current);
|
|
197
|
+
let cls = "PREF_SEGMENT_ITEM button" + (active ? " is-primary is-selected" : "");
|
|
198
|
+
let kids = [];
|
|
199
|
+
if(opt.icon) {
|
|
200
|
+
kids.push(["span", {class: "icon"}, [yui_toolbar_icon(opt.icon)]]);
|
|
201
|
+
}
|
|
202
|
+
let attrs = {type: "button", class: cls, "aria-pressed": active ? "true" : "false"};
|
|
203
|
+
if(opt.key) {
|
|
204
|
+
kids.push(["span", {class: "PREF_SEGMENT_TEXT",
|
|
205
|
+
i18n: /* i18n: YUI_PREFERENCES_I18N_KEYS */ opt.key}, opt.key]);
|
|
206
|
+
attrs.title = t(/* i18n: YUI_PREFERENCES_I18N_KEYS */ opt.key);
|
|
207
|
+
attrs["data-i18n-title"] = opt.key;
|
|
208
|
+
attrs["aria-label"] = t(/* i18n: YUI_PREFERENCES_I18N_KEYS */ opt.key);
|
|
209
|
+
attrs["data-i18n-aria-label"] = opt.key;
|
|
210
|
+
} else {
|
|
211
|
+
kids.push(["span", {class: "PREF_SEGMENT_TEXT", lang: opt.lang || opt.value},
|
|
212
|
+
text_node(opt.text)]);
|
|
213
|
+
attrs.title = opt.text;
|
|
214
|
+
attrs["aria-label"] = opt.text;
|
|
215
|
+
attrs.lang = opt.lang || opt.value;
|
|
216
|
+
}
|
|
217
|
+
return ["button", attrs, kids, {
|
|
218
|
+
click: function() {
|
|
219
|
+
gobj_send_event(gobj, event_name, {value: opt.value}, gobj);
|
|
220
|
+
}
|
|
221
|
+
}];
|
|
222
|
+
});
|
|
223
|
+
return ["div", {class: `PREF_SEGMENT buttons has-addons ${extra_class || ""}`}, buttons];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/***************************************************************
|
|
227
|
+
* The three rows every app shows: theme, language, navigation.
|
|
228
|
+
* Their clicks send EV_SET_THEME / EV_SET_LANGUAGE /
|
|
229
|
+
* EV_SET_NAV_MODE {value} to `gobj`.
|
|
230
|
+
***************************************************************/
|
|
231
|
+
function yui_pref_appearance_fields(gobj)
|
|
232
|
+
{
|
|
233
|
+
let setup = setup_of("yui_pref_appearance_fields()");
|
|
234
|
+
if(!setup) {
|
|
235
|
+
return []; // Error already logged
|
|
236
|
+
}
|
|
237
|
+
let shell = yui_shell_of(gobj);
|
|
238
|
+
let languages = setup.languages.map((l) => ({value: l.value, text: l.text, lang: l.value}));
|
|
239
|
+
|
|
240
|
+
return [
|
|
241
|
+
yui_pref_field("theme",
|
|
242
|
+
yui_pref_segment(gobj, "EV_SET_THEME", THEMES, setup.current_theme(), "PREF_THEME"),
|
|
243
|
+
"PREF_THEME_FIELD"),
|
|
244
|
+
yui_pref_field("language",
|
|
245
|
+
/* The languages are the app's, each named in its own words: data */
|
|
246
|
+
yui_pref_segment(gobj, "EV_SET_LANGUAGE", /* i18n: data */ languages,
|
|
247
|
+
setup.current_language(),
|
|
248
|
+
"PREF_LANGUAGE"),
|
|
249
|
+
"PREF_LANGUAGE_FIELD"),
|
|
250
|
+
yui_pref_field("navigation",
|
|
251
|
+
yui_pref_segment(gobj, "EV_SET_NAV_MODE", NAV_MODE_OPTIONS,
|
|
252
|
+
shell ? yui_shell_nav_mode(shell) : "stack", "PREF_NAVIGATION"),
|
|
253
|
+
"PREF_NAVIGATION_FIELD")
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/***************************************************************
|
|
258
|
+
* The extra boxes of the app (its `sections`), or none.
|
|
259
|
+
***************************************************************/
|
|
260
|
+
function yui_pref_sections(gobj)
|
|
261
|
+
{
|
|
262
|
+
let setup = setup_of("yui_pref_sections()");
|
|
263
|
+
if(!setup || !setup.sections) {
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
let boxes = setup.sections(gobj);
|
|
267
|
+
return Array.isArray(boxes) ? boxes : [];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
/***************************
|
|
274
|
+
* Applying a choice
|
|
275
|
+
***************************/
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
/***************************************************************
|
|
281
|
+
* Apply one of the three choices: EV_SET_THEME, EV_SET_LANGUAGE
|
|
282
|
+
* or EV_SET_NAV_MODE, with its {value}. The host calls it from
|
|
283
|
+
* its action and draws its page again: which option is marked is
|
|
284
|
+
* markup, which no refresh_language() moves.
|
|
285
|
+
***************************************************************/
|
|
286
|
+
function yui_pref_apply(gobj, event, kw)
|
|
287
|
+
{
|
|
288
|
+
let setup = setup_of("yui_pref_apply()");
|
|
289
|
+
if(!setup) {
|
|
290
|
+
return -1; // Error already logged
|
|
291
|
+
}
|
|
292
|
+
let value = (kw && kw.value) || "";
|
|
293
|
+
let shell = yui_shell_of(gobj);
|
|
294
|
+
|
|
295
|
+
switch(event) {
|
|
296
|
+
case "EV_SET_THEME":
|
|
297
|
+
setup.set_theme(value);
|
|
298
|
+
return 0;
|
|
299
|
+
|
|
300
|
+
case "EV_SET_LANGUAGE":
|
|
301
|
+
setup.set_language(value);
|
|
302
|
+
if(shell) {
|
|
303
|
+
yui_shell_language_changed(shell);
|
|
304
|
+
} else {
|
|
305
|
+
refresh_language(document.body, t);
|
|
306
|
+
}
|
|
307
|
+
return 0;
|
|
308
|
+
|
|
309
|
+
case "EV_SET_NAV_MODE":
|
|
310
|
+
if(!shell) {
|
|
311
|
+
log_error(`yui_pref_apply(): no shell, the navigation cannot change`);
|
|
312
|
+
return -1;
|
|
313
|
+
}
|
|
314
|
+
return yui_shell_set_nav_mode(shell, value);
|
|
315
|
+
|
|
316
|
+
default:
|
|
317
|
+
log_error(`yui_pref_apply(): '${event}' is not a preference`);
|
|
318
|
+
return -1;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export {
|
|
323
|
+
yui_preferences_setup,
|
|
324
|
+
yui_pref_header,
|
|
325
|
+
yui_pref_box,
|
|
326
|
+
yui_pref_field,
|
|
327
|
+
yui_pref_segment,
|
|
328
|
+
yui_pref_appearance_fields,
|
|
329
|
+
yui_pref_sections,
|
|
330
|
+
yui_pref_apply,
|
|
331
|
+
};
|