@yuneta/gobj-ui 2.6.0 → 3.0.0
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 +6 -4
- package/dist/gobj-ui.cjs.js +13034 -15452
- package/dist/gobj-ui.es.js +13036 -15441
- package/index.js +0 -8
- package/package.json +1 -1
- package/src/c_yui_form.css +9 -0
- package/src/c_yui_form.js +1 -0
- package/src/c_yui_shell.css +87 -0
- package/src/c_yui_treedb_topic_with_form.css +53 -0
- package/src/c_yui_treedb_topic_with_form.js +1 -0
- package/src/c_yui_window.css +22 -0
- package/src/c_yui_window.js +2 -0
- package/src/shell_modals.js +54 -22
- package/src/tabulator.css +178 -0
- package/src/yui_toolbar.css +28 -0
- package/src/c_yui_main.css +0 -501
- package/src/c_yui_main.js +0 -1623
- package/src/c_yui_routing.css +0 -18
- package/src/c_yui_routing.js +0 -837
- package/src/c_yui_tabs.js +0 -487
- package/src/themes.js +0 -215
- package/src/ytable.css +0 -63
- package/src/ytable.js +0 -505
package/src/c_yui_routing.js
DELETED
|
@@ -1,837 +0,0 @@
|
|
|
1
|
-
/***********************************************************************
|
|
2
|
-
* ui_routing.js
|
|
3
|
-
*
|
|
4
|
-
* Manage routing (Menu/Contents), a grid of 2 columns,
|
|
5
|
-
* left with menu, right with content
|
|
6
|
-
*
|
|
7
|
-
* container-grid-2col
|
|
8
|
-
* container-grid-2col-left container-grid-2col-right
|
|
9
|
-
*
|
|
10
|
-
* The ID "main-content-container" is the REFERENCE to know the work zone.
|
|
11
|
-
*
|
|
12
|
-
* Each gobj must supply his $container.
|
|
13
|
-
* The routing is responsible to show or hide the container,
|
|
14
|
-
* according to desires of user clicking in the main left menu.
|
|
15
|
-
* Each gobj has an entry in the aside menu.
|
|
16
|
-
* The object himself is directed by #hash-left part of url:
|
|
17
|
-
*
|
|
18
|
-
* #hash-left?right-path
|
|
19
|
-
*
|
|
20
|
-
* The right-path of url is managed inside of gobj, as he wants.
|
|
21
|
-
*
|
|
22
|
-
* Main goal of routing is hide/show the containers;
|
|
23
|
-
* routing send EV_SHOW/EV_HIDE events to
|
|
24
|
-
* respect gobj, to let to do any extra own internal job.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* There is a main menu (aside left menu) that manage the content (right side of page).
|
|
28
|
-
*
|
|
29
|
-
* The routing or the selection of different parts of app is done
|
|
30
|
-
* by changing the builtin DOM location.hash,
|
|
31
|
-
* to allow the user navigate backward/forward in the app.
|
|
32
|
-
*
|
|
33
|
-
* The callback of 'hashchange' event is:
|
|
34
|
-
*
|
|
35
|
-
* window.addEventListener('hashchange', gobj.priv.hashchange_handler);
|
|
36
|
-
*
|
|
37
|
-
* The hashchange_handler() will call to
|
|
38
|
-
*
|
|
39
|
-
* select_item(gobj, location.hash);
|
|
40
|
-
*
|
|
41
|
-
* What select_item() do?
|
|
42
|
-
* - Split the href in two, split by '?'.
|
|
43
|
-
* IMPORTANT, the first href part is the ID of gobj service that will be found.
|
|
44
|
-
*
|
|
45
|
-
* - The first part of href will manage the main menu (left aside menu) :
|
|
46
|
-
* 1) - Unselect the current menu item ($current_item)
|
|
47
|
-
* (removing 'is-active')
|
|
48
|
-
* - Calling to own mt_hide():
|
|
49
|
-
* - Send EV_HIDE to associated gobj
|
|
50
|
-
*
|
|
51
|
-
* 2) - Select the new menu item defined by href first part
|
|
52
|
-
* (adding 'is-active')
|
|
53
|
-
* - Calling to own mt_show():
|
|
54
|
-
* - Send EV_SHOW to associated gobj
|
|
55
|
-
*
|
|
56
|
-
* - The second part of href (right of '?') must be processed by gobj found,
|
|
57
|
-
* that it must manage his internal selection defined by that href part.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* External menu selection can come from
|
|
61
|
-
* 1) startup sending EV_SELECT event with last_selected_menu, forcing change in hash
|
|
62
|
-
* ==> priv.hashchange_handler()
|
|
63
|
-
* ==> select_item()
|
|
64
|
-
* 2) user change url (hash) in browser
|
|
65
|
-
* ==> priv.hashchange_handler()
|
|
66
|
-
* ==> select_item()
|
|
67
|
-
*
|
|
68
|
-
* Internal menu selection comes form click in menu item:
|
|
69
|
-
* 3) The click in <a> with href provokes a new hash
|
|
70
|
-
* ==> priv.hashchange_handler()
|
|
71
|
-
* ==> select_item()
|
|
72
|
-
*
|
|
73
|
-
* Use yui_tabs to manage sub-containers or integrate in a gobj.
|
|
74
|
-
*
|
|
75
|
-
* Copyright (c) 2025, ArtGins.
|
|
76
|
-
* All Rights Reserved.
|
|
77
|
-
***********************************************************************/
|
|
78
|
-
|
|
79
|
-
import {
|
|
80
|
-
SDATA,
|
|
81
|
-
SDATA_END,
|
|
82
|
-
data_type_t,
|
|
83
|
-
gclass_flag_t,
|
|
84
|
-
sdata_flag_t,
|
|
85
|
-
gclass_create,
|
|
86
|
-
log_error,
|
|
87
|
-
gobj_subscribe_event,
|
|
88
|
-
gobj_read_pointer_attr,
|
|
89
|
-
gobj_send_event,
|
|
90
|
-
sprintf,
|
|
91
|
-
createElement2,
|
|
92
|
-
is_string,
|
|
93
|
-
is_array,
|
|
94
|
-
createOneHtml,
|
|
95
|
-
kw_set_local_storage_value,
|
|
96
|
-
gobj_find_service,
|
|
97
|
-
gobj_read_attr,
|
|
98
|
-
gobj_write_attr,
|
|
99
|
-
gobj_save_persistent_attrs,
|
|
100
|
-
gobj_is_running,
|
|
101
|
-
refresh_language,
|
|
102
|
-
} from "@yuneta/gobj-js";
|
|
103
|
-
|
|
104
|
-
import "./c_yui_routing.css"; // Must be in index.js ?
|
|
105
|
-
|
|
106
|
-
import {t} from "i18next";
|
|
107
|
-
|
|
108
|
-
/***************************************************************
|
|
109
|
-
* Constants
|
|
110
|
-
***************************************************************/
|
|
111
|
-
const GCLASS_NAME = "C_YUI_ROUTING";
|
|
112
|
-
|
|
113
|
-
/***************************************************************
|
|
114
|
-
* Data
|
|
115
|
-
***************************************************************/
|
|
116
|
-
const attrs_table = [
|
|
117
|
-
SDATA(data_type_t.DTP_POINTER, "subscriber", 0, null, "Subscriber of output events"),
|
|
118
|
-
SDATA(data_type_t.DTP_POINTER, "$parent", 0, null, "HTML content parent"),
|
|
119
|
-
SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "Layout set by this"),
|
|
120
|
-
SDATA(data_type_t.DTP_JSON, "menu", 0, "[]", "Menu tree, [{ Menu/Content}], See info at build_menu_r(). If exists at start will be decoded"),
|
|
121
|
-
SDATA(data_type_t.DTP_INTEGER, "menu_state", sdata_flag_t.SDF_PERSIST, "1", "0: hide all, 1: show all, 2: show icons only"),
|
|
122
|
-
SDATA(data_type_t.DTP_POINTER, "$current_item", 0, null, "Current selected menu item"),
|
|
123
|
-
SDATA_END()
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
let PRIVATE_DATA = {
|
|
127
|
-
hashchange_handler: null, // fixed hashchange_handler to can add/remove listener
|
|
128
|
-
isMobile: false
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
let __gclass__ = null;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
/******************************
|
|
137
|
-
* Framework Methods
|
|
138
|
-
******************************/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/***************************************************************
|
|
144
|
-
* Framework Method: Create
|
|
145
|
-
***************************************************************/
|
|
146
|
-
function mt_create(gobj)
|
|
147
|
-
{
|
|
148
|
-
let priv = gobj.priv;
|
|
149
|
-
|
|
150
|
-
build_layout(gobj);
|
|
151
|
-
|
|
152
|
-
/*
|
|
153
|
-
* SERVICE subscription model
|
|
154
|
-
*/
|
|
155
|
-
const subscriber = gobj_read_pointer_attr(gobj, "subscriber");
|
|
156
|
-
if(subscriber) {
|
|
157
|
-
gobj_subscribe_event(gobj, null, {}, subscriber);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
let __yui_main__ = gobj_find_service("__yui_main__", true);
|
|
161
|
-
if(__yui_main__) {
|
|
162
|
-
gobj_subscribe_event(__yui_main__, "EV_APP_MENU", {}, gobj);
|
|
163
|
-
gobj_subscribe_event(__yui_main__, "EV_RESIZE", {}, gobj);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/*
|
|
167
|
-
* hashchange handler
|
|
168
|
-
*/
|
|
169
|
-
priv.hashchange_handler = function(evt) {
|
|
170
|
-
/*
|
|
171
|
-
* Get the segments of hash
|
|
172
|
-
*/
|
|
173
|
-
gobj_send_event(gobj, "EV_ROUTE", {hash: location.hash}, gobj);
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/***************************************************************
|
|
178
|
-
* Framework Method: Start
|
|
179
|
-
***************************************************************/
|
|
180
|
-
function mt_start(gobj)
|
|
181
|
-
{
|
|
182
|
-
build_menu(gobj, gobj_read_attr(gobj, "menu"));
|
|
183
|
-
|
|
184
|
-
window.addEventListener('hashchange', gobj.priv.hashchange_handler);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/***************************************************************
|
|
188
|
-
* Framework Method: Stop
|
|
189
|
-
***************************************************************/
|
|
190
|
-
function mt_stop(gobj)
|
|
191
|
-
{
|
|
192
|
-
destroy_menu(gobj);
|
|
193
|
-
|
|
194
|
-
window.removeEventListener('hashchange', gobj.priv.hashchange_handler);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/***************************************************************
|
|
198
|
-
* Framework Method: Destroy
|
|
199
|
-
***************************************************************/
|
|
200
|
-
function mt_destroy(gobj)
|
|
201
|
-
{
|
|
202
|
-
destroy_layout(gobj);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/***************************************************************
|
|
206
|
-
* Framework Method: Command Parser
|
|
207
|
-
***************************************************************/
|
|
208
|
-
function mt_command_parser(gobj, command, kw, src)
|
|
209
|
-
{
|
|
210
|
-
switch(command) {
|
|
211
|
-
case "help":
|
|
212
|
-
return cmd_help(gobj, command, kw, src);
|
|
213
|
-
case "append-menu":
|
|
214
|
-
return cmd_manage_menu(gobj, command, kw, src);
|
|
215
|
-
case "insert-menu":
|
|
216
|
-
return cmd_manage_menu(gobj, command, kw, src);
|
|
217
|
-
case "remove-menu":
|
|
218
|
-
return cmd_manage_menu(gobj, command, kw, src);
|
|
219
|
-
case "append-content":
|
|
220
|
-
return cmd_manage_content(gobj, command, kw, src);
|
|
221
|
-
case "insert-content":
|
|
222
|
-
return cmd_manage_content(gobj, command, kw, src);
|
|
223
|
-
case "remove-content":
|
|
224
|
-
return cmd_manage_content(gobj, command, kw, src);
|
|
225
|
-
default:
|
|
226
|
-
log_error("Command not found: %s", command);
|
|
227
|
-
return {
|
|
228
|
-
"result": -1,
|
|
229
|
-
"comment": sprintf("Command not found: %s", command),
|
|
230
|
-
"schema": null,
|
|
231
|
-
"data": null
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
/***************************
|
|
240
|
-
* Commands
|
|
241
|
-
***************************/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
/************************************************************
|
|
247
|
-
*
|
|
248
|
-
************************************************************/
|
|
249
|
-
function cmd_help(gobj, cmd, kw, src)
|
|
250
|
-
{
|
|
251
|
-
let webix = {
|
|
252
|
-
"result": 0,
|
|
253
|
-
"comment": "",
|
|
254
|
-
"schema": null,
|
|
255
|
-
"data": null
|
|
256
|
-
};
|
|
257
|
-
return webix;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/************************************************************
|
|
261
|
-
*
|
|
262
|
-
************************************************************/
|
|
263
|
-
function cmd_manage_menu(gobj, command, kw, src)
|
|
264
|
-
{
|
|
265
|
-
return {
|
|
266
|
-
"result": -1,
|
|
267
|
-
"comment": sprintf("Command not implemented: %s", command),
|
|
268
|
-
"schema": null,
|
|
269
|
-
"data": null
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/************************************************************
|
|
274
|
-
*
|
|
275
|
-
************************************************************/
|
|
276
|
-
function cmd_manage_content(gobj, command, kw, src)
|
|
277
|
-
{
|
|
278
|
-
return {
|
|
279
|
-
"result": -1,
|
|
280
|
-
"comment": sprintf("Command not implemented: %s", command),
|
|
281
|
-
"schema": null,
|
|
282
|
-
"data": null
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
/***************************
|
|
289
|
-
* Local Methods
|
|
290
|
-
***************************/
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
/************************************************************
|
|
296
|
-
*
|
|
297
|
-
************************************************************/
|
|
298
|
-
function build_layout(gobj)
|
|
299
|
-
{
|
|
300
|
-
/*----------------------------------------------*
|
|
301
|
-
* Layout Schema
|
|
302
|
-
*----------------------------------------------*/
|
|
303
|
-
const $container = createElement2(
|
|
304
|
-
['div', {class: 'C_YUI_ROUTING', style: ''}, [
|
|
305
|
-
['div', {class: 'container-grid-2col-left'},
|
|
306
|
-
['aside', {class: 'menu'}, [
|
|
307
|
-
['ul', {class: 'menu-list'}, []]
|
|
308
|
-
]]
|
|
309
|
-
],
|
|
310
|
-
['div', {
|
|
311
|
-
id: 'main-content-container',
|
|
312
|
-
class: 'container-grid-2col-right main-content-container m-1'}, []
|
|
313
|
-
]
|
|
314
|
-
]]
|
|
315
|
-
);
|
|
316
|
-
gobj_write_attr(gobj, "$container", $container);
|
|
317
|
-
refresh_language($container, t);
|
|
318
|
-
|
|
319
|
-
let $parent = gobj_read_attr(gobj, "$parent");
|
|
320
|
-
if($parent) {
|
|
321
|
-
$parent.appendChild($container);
|
|
322
|
-
}
|
|
323
|
-
return 0;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/************************************************************
|
|
327
|
-
*
|
|
328
|
-
************************************************************/
|
|
329
|
-
function destroy_layout(gobj)
|
|
330
|
-
{
|
|
331
|
-
let $container = gobj_read_attr(gobj, "$container");
|
|
332
|
-
if($container && $container.parentNode) {
|
|
333
|
-
$container.parentNode.removeChild($container);
|
|
334
|
-
gobj_write_attr(gobj, "$container", null);
|
|
335
|
-
}
|
|
336
|
-
return 0;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/************************************************************
|
|
340
|
-
* Recurrent
|
|
341
|
-
menu: [{}]
|
|
342
|
-
You can pass a {} and a internal <li><a> will be built,
|
|
343
|
-
or you can pass an already built HTMLElement.
|
|
344
|
-
|
|
345
|
-
$menu_list_parent: Menu parent where the menu items will be added.
|
|
346
|
-
|
|
347
|
-
$content_container_parent: Container parent where the containers will be added.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
Menu item structure:
|
|
351
|
-
{
|
|
352
|
-
id: string (if null then it's a title) ==> will be the href IMPORTANT!
|
|
353
|
-
label: string (i18n)
|
|
354
|
-
icon: string (fontawesome)
|
|
355
|
-
attrs: {} html attributes for <li>
|
|
356
|
-
events: {} html event functions {event: fn()},
|
|
357
|
-
|
|
358
|
-
gobj: gobj implementing the content of container
|
|
359
|
-
It must have "$container" attribute,
|
|
360
|
-
that it has precedence over below 'container' parameter
|
|
361
|
-
It must support EV_SHOW/EV_HIDE events
|
|
362
|
-
|
|
363
|
-
menu: [] submenu children, this is a tree structure
|
|
364
|
-
|
|
365
|
-
html: it not null this 'HTMLElement' or 'html string' or [createElement2]
|
|
366
|
-
will be used instead of to build the internal <li><a>
|
|
367
|
-
|
|
368
|
-
container: it not null this 'HTMLElement' or 'html string' or [createElement2]
|
|
369
|
-
will be used instead of to build the internal <li><a>
|
|
370
|
-
|
|
371
|
-
if null and gobj have "$container" attribute it will be used
|
|
372
|
-
|
|
373
|
-
mt_show:
|
|
374
|
-
($container) ==> {$container.classList.remove('is-hidden');}
|
|
375
|
-
mt_hide:
|
|
376
|
-
($container) ==> {$container.classList.add('is-hidden');}
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
By default, the built structure is, with id:
|
|
381
|
-
|
|
382
|
-
<li "attrs"> <== attrs
|
|
383
|
-
<a "events|inside-click" "href=id" "i18n=label|id" >
|
|
384
|
-
label|id
|
|
385
|
-
</a>
|
|
386
|
-
</li>
|
|
387
|
-
|
|
388
|
-
without id (title):
|
|
389
|
-
|
|
390
|
-
<p "i18n:label">
|
|
391
|
-
label
|
|
392
|
-
</p>
|
|
393
|
-
|
|
394
|
-
************************************************************/
|
|
395
|
-
function build_menu_r(gobj, menu, $menu_list_parent, $content_container_parent)
|
|
396
|
-
{
|
|
397
|
-
function mt_show($container)
|
|
398
|
-
{
|
|
399
|
-
$container.classList.remove('is-hidden');
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
function mt_hide($container)
|
|
403
|
-
{
|
|
404
|
-
$container.classList.add('is-hidden');
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
for (let i = 0; i < menu.length; i++) {
|
|
408
|
-
let item = menu[i];
|
|
409
|
-
let $item;
|
|
410
|
-
let create_container = true;
|
|
411
|
-
let icon = item.icon || '';
|
|
412
|
-
|
|
413
|
-
/*--------------------------------------------*
|
|
414
|
-
* Aside menu
|
|
415
|
-
*--------------------------------------------*/
|
|
416
|
-
let html = item.html;
|
|
417
|
-
if(html && ((html instanceof HTMLElement) || is_string(html) || is_array(html))) {
|
|
418
|
-
/*-----------------------*
|
|
419
|
-
* External built
|
|
420
|
-
*-----------------------*/
|
|
421
|
-
if(html instanceof HTMLElement) {
|
|
422
|
-
$item = html;
|
|
423
|
-
} else if(is_string(html)) {
|
|
424
|
-
$item = createOneHtml(html);
|
|
425
|
-
} else if(is_array(html)) {
|
|
426
|
-
$item = createElement2(html);
|
|
427
|
-
}
|
|
428
|
-
} else {
|
|
429
|
-
/*-----------------------*
|
|
430
|
-
* Internal built
|
|
431
|
-
*-----------------------*/
|
|
432
|
-
if (item.id) {
|
|
433
|
-
$item = createElement2(
|
|
434
|
-
['li', item.attrs ? item.attrs : {}, [
|
|
435
|
-
[
|
|
436
|
-
'a',
|
|
437
|
-
{
|
|
438
|
-
// gobj_name, the first with '#', children with '/' '?' ???
|
|
439
|
-
id: item.id,
|
|
440
|
-
href: item.id,
|
|
441
|
-
// class: 'icon-text',
|
|
442
|
-
},
|
|
443
|
-
[
|
|
444
|
-
['span',
|
|
445
|
-
{
|
|
446
|
-
class: `icon ${icon?'':'is-hidden'}`
|
|
447
|
-
},
|
|
448
|
-
['i', {class: `${icon}`}]
|
|
449
|
-
],
|
|
450
|
-
['span',
|
|
451
|
-
{
|
|
452
|
-
class: 'menu-text pl-3',
|
|
453
|
-
i18n: item.label?item.label:item.id
|
|
454
|
-
},
|
|
455
|
-
item.label?item.label:item.id
|
|
456
|
-
],
|
|
457
|
-
['span',
|
|
458
|
-
{
|
|
459
|
-
class: 'yui-badge tag ml-2 is-rounded is-hidden',
|
|
460
|
-
},
|
|
461
|
-
''
|
|
462
|
-
]
|
|
463
|
-
],
|
|
464
|
-
item.events ? item.events : {}
|
|
465
|
-
]
|
|
466
|
-
]]
|
|
467
|
-
);
|
|
468
|
-
|
|
469
|
-
} else {
|
|
470
|
-
/*
|
|
471
|
-
* If id is empty it's title
|
|
472
|
-
*/
|
|
473
|
-
$item = createElement2(
|
|
474
|
-
['p', {class: 'menu-label', i18n: item.label}, item.label]
|
|
475
|
-
);
|
|
476
|
-
create_container = false;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
$menu_list_parent.appendChild($item);
|
|
481
|
-
|
|
482
|
-
if(!create_container) {
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/*--------------------------------------------*
|
|
487
|
-
* Content
|
|
488
|
-
*--------------------------------------------*/
|
|
489
|
-
let $container;
|
|
490
|
-
let container;
|
|
491
|
-
if(item.gobj) {
|
|
492
|
-
container = gobj_read_attr(item.gobj, "$container");
|
|
493
|
-
}
|
|
494
|
-
if(!container) {
|
|
495
|
-
container = item.container;
|
|
496
|
-
}
|
|
497
|
-
if(container && ((container instanceof HTMLElement) || is_string(container))) {
|
|
498
|
-
/*-----------------------*
|
|
499
|
-
* External built
|
|
500
|
-
*-----------------------*/
|
|
501
|
-
if(container instanceof HTMLElement) {
|
|
502
|
-
$container = container;
|
|
503
|
-
} else if(is_string(container)) {
|
|
504
|
-
$container = createOneHtml(container);
|
|
505
|
-
} else if(is_array(container)) {
|
|
506
|
-
$container = createElement2(container);
|
|
507
|
-
}
|
|
508
|
-
} else {
|
|
509
|
-
/*-----------------------*
|
|
510
|
-
* Internal built
|
|
511
|
-
*-----------------------*/
|
|
512
|
-
$container = createElement2(
|
|
513
|
-
['div', {}, `You must supply content for ${item.id}`]
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
$container.classList.add('is-hidden');
|
|
518
|
-
$content_container_parent.appendChild($container);
|
|
519
|
-
|
|
520
|
-
/*-------------------------------*
|
|
521
|
-
* Link to gobj's
|
|
522
|
-
*-------------------------------*/
|
|
523
|
-
let $item_a = $item.querySelector('a');
|
|
524
|
-
$item_a.$container = $container;
|
|
525
|
-
$item_a.gobj = item.gobj || null;
|
|
526
|
-
$container.gobj = item.gobj || null;
|
|
527
|
-
$item_a.mt_show = item.mt_show || mt_show;
|
|
528
|
-
$item_a.mt_hide = item.mt_hide || mt_hide;
|
|
529
|
-
|
|
530
|
-
/*-------------------------------*
|
|
531
|
-
* Submenus
|
|
532
|
-
*-------------------------------*/
|
|
533
|
-
if(item.submenu && item.submenu.length > 0) {
|
|
534
|
-
let $submenu = createElement2(
|
|
535
|
-
['ul', {}, []]
|
|
536
|
-
);
|
|
537
|
-
$item.appendChild($submenu);
|
|
538
|
-
build_menu_r(gobj, item.submenu, $submenu, $content_container_parent);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/************************************************************
|
|
544
|
-
*
|
|
545
|
-
************************************************************/
|
|
546
|
-
function build_menu(gobj, menu)
|
|
547
|
-
{
|
|
548
|
-
/*-------------------------------*
|
|
549
|
-
* First level
|
|
550
|
-
*-------------------------------*/
|
|
551
|
-
let $container = gobj_read_attr(gobj, "$container");
|
|
552
|
-
let $menu_list = $container.querySelector('.menu-list');
|
|
553
|
-
let $content_container = $container.querySelector('.main-content-container');
|
|
554
|
-
|
|
555
|
-
build_menu_r(gobj, menu, $menu_list, $content_container);
|
|
556
|
-
refresh_language($container, t);
|
|
557
|
-
|
|
558
|
-
set_menu_state(gobj, gobj_read_attr(gobj, "menu_state"));
|
|
559
|
-
|
|
560
|
-
return 0;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/************************************************************
|
|
564
|
-
*
|
|
565
|
-
************************************************************/
|
|
566
|
-
function destroy_menu(gobj, event, kw, src)
|
|
567
|
-
{
|
|
568
|
-
window.location.hash = '';
|
|
569
|
-
|
|
570
|
-
let $container = gobj_read_attr(gobj, "$container");
|
|
571
|
-
let $menu_list = $container.querySelector('.menu-list');
|
|
572
|
-
let $content_container = $container.querySelector('.main-content-container');
|
|
573
|
-
|
|
574
|
-
while ($menu_list.firstChild) {
|
|
575
|
-
$menu_list.removeChild($menu_list.firstChild);
|
|
576
|
-
}
|
|
577
|
-
while ($content_container.firstChild) {
|
|
578
|
-
$content_container.removeChild($content_container.firstChild);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
return 0;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
/************************************************************
|
|
585
|
-
* Select item with href that is the same as gobj's id
|
|
586
|
-
************************************************************/
|
|
587
|
-
function select_item(gobj, href)
|
|
588
|
-
{
|
|
589
|
-
/*
|
|
590
|
-
* Recover the menu item
|
|
591
|
-
*/
|
|
592
|
-
let gobj_href = href.split('?')[0];
|
|
593
|
-
let $container = gobj_read_attr(gobj, "$container");
|
|
594
|
-
let $item = $container.querySelector(`a[href="${gobj_href}"]`);
|
|
595
|
-
if(!$item) {
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/*
|
|
600
|
-
* Clean all active items (with current is enough)
|
|
601
|
-
*/
|
|
602
|
-
let $current_item = gobj_read_attr(gobj, "$current_item");
|
|
603
|
-
if($current_item) {
|
|
604
|
-
/*
|
|
605
|
-
* Unselect menu item
|
|
606
|
-
*/
|
|
607
|
-
$current_item.classList.remove('is-active');
|
|
608
|
-
/*
|
|
609
|
-
* Hide container
|
|
610
|
-
*/
|
|
611
|
-
$current_item.mt_hide($current_item.$container);
|
|
612
|
-
|
|
613
|
-
/*
|
|
614
|
-
* Call gobj_hide
|
|
615
|
-
*/
|
|
616
|
-
let gobj_hide = $current_item.gobj ||
|
|
617
|
-
gobj_find_service($current_item.getAttribute('href'));
|
|
618
|
-
|
|
619
|
-
if(gobj_hide && gobj_is_running(gobj_hide)) {
|
|
620
|
-
gobj_send_event(gobj_hide, "EV_HIDE", {}, gobj);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/*
|
|
625
|
-
* Active this item
|
|
626
|
-
*/
|
|
627
|
-
gobj_write_attr(gobj, "$current_item", $item);
|
|
628
|
-
$current_item = gobj_read_attr(gobj, "$current_item");
|
|
629
|
-
$current_item.classList.add('is-active');
|
|
630
|
-
|
|
631
|
-
/*
|
|
632
|
-
* Show container
|
|
633
|
-
*/
|
|
634
|
-
// $current_item.mt_show(gobj.config.$current_item.$container); // TODO esto había
|
|
635
|
-
$current_item.mt_show($current_item.$container); // TODO ??
|
|
636
|
-
|
|
637
|
-
/*
|
|
638
|
-
* Call gobj_show
|
|
639
|
-
*/
|
|
640
|
-
let gobj_show = $item.gobj || gobj_find_service(gobj_href);
|
|
641
|
-
if(gobj_show && gobj_is_running(gobj_show)) {
|
|
642
|
-
gobj_send_event(gobj_show, "EV_SHOW", {href:href}, gobj);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
// TODO per user?
|
|
646
|
-
kw_set_local_storage_value("last_selected_menu", href);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
/************************************************************
|
|
650
|
-
*
|
|
651
|
-
************************************************************/
|
|
652
|
-
function set_menu_state(gobj, state)
|
|
653
|
-
{
|
|
654
|
-
let $container = gobj_read_attr(gobj, "$container");
|
|
655
|
-
let $col_left = $container.querySelector('.menu');
|
|
656
|
-
switch(state) {
|
|
657
|
-
case 0: // Hide ALL
|
|
658
|
-
$col_left.classList.add('is-hidden');
|
|
659
|
-
$container.querySelectorAll('.menu-text, .menu-label').forEach(link => {
|
|
660
|
-
link.classList.add('is-hidden');
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
break;
|
|
664
|
-
|
|
665
|
-
case 1: // Show ALL
|
|
666
|
-
$col_left.classList.remove('is-hidden');
|
|
667
|
-
$container.querySelectorAll('.menu-text, .menu-label').forEach(link => {
|
|
668
|
-
link.classList.remove('is-hidden');
|
|
669
|
-
});
|
|
670
|
-
break;
|
|
671
|
-
|
|
672
|
-
case 2: // Show Icon, hide text
|
|
673
|
-
$col_left.classList.remove('is-hidden');
|
|
674
|
-
$container.querySelectorAll('.menu-text, .menu-label').forEach(link => {
|
|
675
|
-
link.classList.add('is-hidden');
|
|
676
|
-
});
|
|
677
|
-
break;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
gobj_write_attr(gobj, "menu_state", state);
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
/***************************
|
|
687
|
-
* Actions
|
|
688
|
-
***************************/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
/************************************************************
|
|
694
|
-
* User has clicked in the app menu (top left corner button)
|
|
695
|
-
* (We are subscribed to event of __main__ )
|
|
696
|
-
* Action: show or hide or show less the main left menu
|
|
697
|
-
************************************************************/
|
|
698
|
-
function ac_app_menu(gobj, event, kw, src)
|
|
699
|
-
{
|
|
700
|
-
let priv = gobj.priv;
|
|
701
|
-
|
|
702
|
-
let state = gobj_read_attr(gobj, "menu_state");
|
|
703
|
-
if(priv.isMobile) {
|
|
704
|
-
state = ++state % 2;
|
|
705
|
-
} else {
|
|
706
|
-
state = ++state % 3;
|
|
707
|
-
}
|
|
708
|
-
set_menu_state(gobj, state);
|
|
709
|
-
gobj_save_persistent_attrs(gobj, "menu_state");
|
|
710
|
-
|
|
711
|
-
return 0;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/************************************************************
|
|
715
|
-
*
|
|
716
|
-
************************************************************/
|
|
717
|
-
function ac_resize(gobj, event, kw, src)
|
|
718
|
-
{
|
|
719
|
-
let priv = gobj.priv;
|
|
720
|
-
|
|
721
|
-
priv.isMobile = window.matchMedia("(max-width: 768px)").matches;
|
|
722
|
-
if(priv.isMobile) {
|
|
723
|
-
set_menu_state(gobj, 0); // hide all
|
|
724
|
-
}
|
|
725
|
-
return 0;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
/************************************************************
|
|
729
|
-
* From startup sending EV_SELECT event with last_selected_menu
|
|
730
|
-
************************************************************/
|
|
731
|
-
function ac_select(gobj, event, kw, src)
|
|
732
|
-
{
|
|
733
|
-
/*
|
|
734
|
-
* ==> this case: simulate change in hash
|
|
735
|
-
*/
|
|
736
|
-
window.location.hash = kw.id; // This will call priv.hashchange_handler() ==> select_item()
|
|
737
|
-
|
|
738
|
-
return 0;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
/************************************************************
|
|
742
|
-
* From callback priv.hashchange_handler()
|
|
743
|
-
************************************************************/
|
|
744
|
-
function ac_route(gobj, event, kw, src)
|
|
745
|
-
{
|
|
746
|
-
let priv = gobj.priv;
|
|
747
|
-
|
|
748
|
-
select_item(gobj, kw.hash);
|
|
749
|
-
if(priv.isMobile) {
|
|
750
|
-
set_menu_state(gobj, 0); // Hide all
|
|
751
|
-
}
|
|
752
|
-
return 0;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
/***************************
|
|
759
|
-
* FSM
|
|
760
|
-
***************************/
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
/*---------------------------------------------*
|
|
766
|
-
* Global methods table
|
|
767
|
-
*---------------------------------------------*/
|
|
768
|
-
const gmt = {
|
|
769
|
-
mt_create: mt_create,
|
|
770
|
-
mt_start: mt_start,
|
|
771
|
-
mt_stop: mt_stop,
|
|
772
|
-
mt_destroy: mt_destroy,
|
|
773
|
-
mt_command_parser: mt_command_parser,
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
/***************************************************************
|
|
777
|
-
* Create the GClass
|
|
778
|
-
***************************************************************/
|
|
779
|
-
function create_gclass(gclass_name)
|
|
780
|
-
{
|
|
781
|
-
if (__gclass__) {
|
|
782
|
-
log_error(`GClass ALREADY created: ${gclass_name}`);
|
|
783
|
-
return -1;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
/*---------------------------------------------*
|
|
787
|
-
* States
|
|
788
|
-
*---------------------------------------------*/
|
|
789
|
-
const states = [
|
|
790
|
-
["ST_IDLE", [
|
|
791
|
-
["EV_ROUTE", ac_route, null],
|
|
792
|
-
["EV_APP_MENU", ac_app_menu, null],
|
|
793
|
-
["EV_RESIZE", ac_resize, null],
|
|
794
|
-
["EV_SELECT", ac_select, null]
|
|
795
|
-
]]
|
|
796
|
-
];
|
|
797
|
-
|
|
798
|
-
/*---------------------------------------------*
|
|
799
|
-
* Events
|
|
800
|
-
*---------------------------------------------*/
|
|
801
|
-
const event_types = [
|
|
802
|
-
["EV_ROUTE", 0],
|
|
803
|
-
["EV_APP_MENU", 0],
|
|
804
|
-
["EV_RESIZE", 0],
|
|
805
|
-
["EV_SELECT", 0]
|
|
806
|
-
];
|
|
807
|
-
|
|
808
|
-
__gclass__ = gclass_create(
|
|
809
|
-
gclass_name,
|
|
810
|
-
event_types,
|
|
811
|
-
states,
|
|
812
|
-
gmt,
|
|
813
|
-
0, // lmt,
|
|
814
|
-
attrs_table,
|
|
815
|
-
PRIVATE_DATA,
|
|
816
|
-
0, // authz_table,
|
|
817
|
-
0, // command_table,
|
|
818
|
-
0, // s_user_trace_level
|
|
819
|
-
gclass_flag_t.gcflag_manual_start // gclass_flag
|
|
820
|
-
);
|
|
821
|
-
if(!__gclass__) {
|
|
822
|
-
// Error already logged
|
|
823
|
-
return -1;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
return 0;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
/***************************************************************
|
|
830
|
-
* Register GClass
|
|
831
|
-
***************************************************************/
|
|
832
|
-
function register_c_yui_routing()
|
|
833
|
-
{
|
|
834
|
-
return create_gclass(GCLASS_NAME);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
export { register_c_yui_routing };
|