@xuda.io/runtime-bundle 1.0.1149 → 1.0.1150

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.
@@ -13001,2216 +13001,7 @@ func.UI.screen.execute_xu_functions = async function (SESSION_ID, is_skeleton, $
13001
13001
  SESSION_ID,
13002
13002
  cond,
13003
13003
  paramsP.dsSessionP,
13004
- 'UI Attr EXP',
13005
- $elm.data().xuData.currentRecordId, // SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP].currentRecordId
13006
- null,
13007
- null,
13008
- null,
13009
- null,
13010
- null,
13011
- $elm.data().xuData.iterate_info,
13012
- );
13013
-
13014
- if (res.result) {
13015
- $elm.addClass(cla);
13016
- } else {
13017
- $elm.removeClass(cla);
13018
- }
13019
-
13020
- $elm.data().xuData.debug_info.attribute_stat['xu-class'] = $elm.attr('class');
13021
- }
13022
- return {};
13023
- } catch (e) {
13024
- console.warn('parse error:' + val.value);
13025
- return { abort: true };
13026
- }
13027
- },
13028
- 'xu-exp': async function ($elm, val) {
13029
- let exp = val.value === null ? true : val.value;
13030
-
13031
- let exp_ret = await func.expression.get(SESSION_ID, exp, paramsP.dsSessionP, 'UI Attr EXP', SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP].currentRecordId, null, null, null, null, null, $elm.data().xuData.iterate_info);
13032
-
13033
- let value = func.UI.screen.fix_val_defaults(val.key, exp_ret.result);
13034
-
13035
- var new_val = {
13036
- key: val.key,
13037
- value,
13038
- };
13039
-
13040
- if (nodeP.tagName.substr(0, 3) === 'xu-') {
13041
- if (tag_fx[nodeP.tagName][new_val.key]) {
13042
- return await tag_fx[nodeP.tagName][new_val.key]($elm, new_val);
13043
- }
13044
- console.warn(`attribute ${new_val.key} not found for ${nodeP.tagName}`);
13045
- return {};
13046
- }
13047
- if (!$elm.data().xuData) return;
13048
-
13049
- $elm.data().xuData.debug_info.attribute_stat[new_val.key] = new_val.value;
13050
-
13051
- // IGNORE UNDEFINED or NULL ATTRIBUTES
13052
- if (typeof new_val.value === 'undefined' || new_val.value === null) {
13053
- return {};
13054
- }
13055
-
13056
- // IGNORE ATTRIBUTES WITH EMPTY VALUES
13057
- if (glb.solid_attributes.includes(new_val.key) && !new_val.value) {
13058
- return {};
13059
- }
13060
-
13061
- if (new_val.key.substr(0, 2) === 'xu') {
13062
- return await common_fx[new_val.key]($elm, new_val);
13063
- }
13064
-
13065
- $elm.attr(new_val.key, ($elm.attr(new_val.key) || '') + new_val.value);
13066
- return {};
13067
- },
13068
- 'xu-on': async function ($elm, val) {
13069
- CLIENT_ACTIVITY_TS = Date.now();
13070
- const trigger = val.key.split('xu-on:')[1].toLowerCase();
13071
- $elm.on(trigger, async function (evt) {
13072
- const _$elm = $(evt.currentTarget);
13073
- if (_.isEmpty(_$elm.data().xuAttributes)) return;
13074
-
13075
- for await (const [key, val] of Object.entries(_$elm.data().xuAttributes['xu-on:' + evt.type])) {
13076
- if (!_.isEmpty(val.props.condition)) {
13077
- const expCond = await func.expression.get(SESSION_ID, val.props.condition, paramsP.dsSessionP, 'condition', paramsP.recordid); // execute expression
13078
- if (!expCond.result) continue;
13079
- }
13080
-
13081
- if (val.event_modifiers && evt[val.event_modifiers]) {
13082
- evt[val.event_modifiers]();
13083
- }
13084
-
13085
- // if (val.handler === 'custom') {
13086
- if (val.workflow) {
13087
- // do BL
13088
- for await (const [key2, val2] of Object.entries(val.workflow)) {
13089
- // var cond = val2.data.enabled;
13090
- // if (val2.data.enabled && val2.props.condition) {
13091
- // expCond = await func.expression.get(SESSION_ID, val2.props.condition, paramsP.dsSessionP, 'condition', paramsP.recordid); // execute expression
13092
- // cond = expCond.result;
13093
- // }
13094
- // if (!cond) continue;
13095
-
13096
- if (!val2.data.enabled) continue; // added Jul 3, 25 - condition validate on execution
13097
-
13098
- func.events.add_to_queue(SESSION_ID, 'element event', val2.id, evt.type, val2.data.action, val2.data.name, null, _$elm.attr('xu-ui-id'), null, evt, null, null, null, paramsP.dsSessionP, null, null, null, evt.type, val2.data.name, null, null, val2, null, null, null, null, null, null);
13099
- }
13100
- }
13101
- }
13102
- });
13103
- return {};
13104
- },
13105
- 'xu-script': async function ($elm, val) {
13106
- var checkExist = setInterval(function () {
13107
- if ($elm.is(':visible')) {
13108
- try {
13109
- // var res = eval('(' + val.value + ')');
13110
- const fn = `(function(el, evt) {
13111
- ${val.value}
13112
- })(document.querySelector(\`[xu-ui-id="${$elm.attr('xu-ui-id')}"]\`),evt);`;
13113
-
13114
- var res = eval(fn);
13115
- // if (typeof res === 'function') {
13116
- // res($elm[0]);
13117
- // }
13118
- } catch (e) {
13119
- eval(val.value);
13120
- }
13121
-
13122
- clearInterval(checkExist);
13123
- }
13124
- }, 100); // check every 100ms
13125
-
13126
- return {};
13127
- },
13128
- 'xu-style-global': async function ($elm, val) {
13129
- $('head').append(`<style>${val.value}</style>`);
13130
- return {};
13131
- },
13132
- 'xu-style': async function ($elm, val) {
13133
- var cssString = val.value;
13134
-
13135
- var parser = new cssjs();
13136
-
13137
- var parsed = parser.parseCSS(cssString);
13138
- var xuUiId = `[xu-ui-id="${$elm.attr('xu-ui-id')}"]`;
13139
-
13140
- $.each(parsed, function (key, val) {
13141
- var selectors_arr = val.selector.split(',');
13142
-
13143
- $.each(selectors_arr, function (key2, val2) {
13144
- selectors_arr[key2] = `${xuUiId} ${val2}, ${xuUiId}${val2}`;
13145
- // console.log(new_selector);
13146
- });
13147
-
13148
- val.selector = selectors_arr.join(',');
13149
- // console.log(parsed);
13150
- });
13151
-
13152
- var newCSSString = parser.getCSSForEditor(parsed);
13153
-
13154
- $('head').append(`<style>${newCSSString}</style>`);
13155
- return {};
13156
- },
13157
- 'xu-cdn': async function ($elm, val) {
13158
- for await (const [key, resource] of Object.entries(val.value)) {
13159
- await load_cdn(resource);
13160
- }
13161
-
13162
- return {};
13163
- },
13164
- 'xu-ui-plugin': async function ($elm, val) {
13165
- var _session = SESSION_OBJ[SESSION_ID];
13166
-
13167
- for await (const [plugin_name, value] of Object.entries(val.value)) {
13168
- const _plugin = APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];
13169
- if (_plugin?.installed && _plugin?.manifest?.['runtime.mjs']?.exist && _plugin?.manifest?.['index.mjs']?.exist && value.enabled) {
13170
- if (_plugin?.manifest?.['runtime.mjs'].dist && _plugin?.manifest?.['runtime.mjs']?.css) {
13171
- const plugin_runtime_css_url = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, 'dist/runtime.css');
13172
- func.utils.load_css_on_demand(plugin_runtime_css_url);
13173
- }
13174
-
13175
- const plugin_index_src = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, `${_plugin.manifest['index.mjs'].dist ? 'dist/' : ''}index.mjs`);
13176
-
13177
- const plugin_index_resources = await import(plugin_index_src);
13178
-
13179
- let properties = _.cloneDeep(plugin_index_resources.properties);
13180
- for await (let [prop_name, prop_val] of Object.entries(properties)) {
13181
- prop_val.value = value?.attributes?.[prop_name];
13182
- if (value?.attributes?.[`xu-exp:${prop_name}`]) {
13183
- const res = await func.expression.get(SESSION_ID, value?.attributes?.[`xu-exp:${prop_name}`], paramsP.dsSessionP, 'UI Attr EXP');
13184
- prop_val.value = res.result;
13185
- }
13186
- }
13187
- // $elm.data().xu_ui_plugin = { properties };
13188
- const plugin_runtime_src = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, `${_plugin.manifest['runtime.mjs'].dist ? 'dist/' : ''}runtime.mjs`);
13189
-
13190
- const plugin_runtime_resources = await import(plugin_runtime_src);
13191
-
13192
- if (plugin_runtime_resources.cdn && typeof _.isArray(plugin_runtime_resources.cdn)) {
13193
- for await (const resource of plugin_runtime_resources.cdn) {
13194
- await load_cdn(resource);
13195
- }
13196
- }
13197
-
13198
- if (plugin_runtime_resources.fn) {
13199
- await plugin_runtime_resources.fn(plugin_name, $elm?.[0], properties);
13200
- // await plugin_runtime_resources.fn(plugin_name, $elm?.[0], $elm.data().xu_ui_plugin.properties);
13201
- }
13202
- }
13203
- }
13204
-
13205
- return {};
13206
- },
13207
- 'xu-store': async function ($elm, val) {
13208
- try {
13209
- const fields_obj = JSON5.parse(val.value);
13210
- for (const [field_id, value] of Object.entries(fields_obj)) {
13211
- func.datasource.add_dynamic_field_to_ds(SESSION_ID, paramsP.dsSessionP, field_id, value);
13212
- }
13213
- } catch (err) {
13214
- console.error(err);
13215
- }
13216
- return {};
13217
- },
13218
- 'xu-viewport': async function ($elm, val) {
13219
- // functionality in draw_html_element
13220
- return {};
13221
- },
13222
- };
13223
-
13224
- if (nodeP.tagName.substr(0, 3) === 'xu-') {
13225
- if (xu_func === 'xu-exp') {
13226
- return common_fx[xu_func]($elm, val);
13227
- }
13228
-
13229
- if (tag_fx?.[nodeP.tagName]?.[xu_func]) {
13230
- let ret = await tag_fx[nodeP.tagName][xu_func]($elm, val);
13231
- return ret;
13232
- }
13233
- // if (xu_func !== "tree_id")
13234
- console.warn(`attribute ${xu_func} not found for ${nodeP.tagName}`);
13235
- return {};
13236
- }
13237
- if (_.isEmpty($elm.data())) {
13238
- return {};
13239
- }
13240
- if (!$elm.data().xuData.debug_info.attribute_stat) {
13241
- $elm.data().xuData.debug_info.attribute_stat = {};
13242
- }
13243
- if (xu_func !== 'xu-exp') {
13244
- $elm.data().xuData.debug_info.attribute_stat[xu_func] = val.value;
13245
- }
13246
- try {
13247
- if (!common_fx[xu_func]) {
13248
- console.warn('invalid xu-tag', xu_func, error);
13249
- return {};
13250
- }
13251
-
13252
- return await common_fx[xu_func]($elm, val);
13253
- } catch (error) {
13254
- debugger;
13255
- }
13256
- };
13257
-
13258
- func.UI.screen.fix_val_defaults = function (key, val) {
13259
- var ret = val;
13260
- if (
13261
- key === 'xu-render' &&
13262
- (typeof val === 'undefined' || val === null || val === '') //|| val === ""
13263
- ) {
13264
- // ret = 'Y'; // was ret = "N";
13265
- ret = true;
13266
- }
13267
- if (
13268
- key === 'xu-show' &&
13269
- (typeof val === 'undefined' || val === null || val === '') //|| val === ""
13270
- ) {
13271
- // ret = 'Y';
13272
- ret = true;
13273
- }
13274
- return ret;
13275
- };
13276
-
13277
- func.UI.screen.set_attributes_new = async function (SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $elm, is_init, execute_attributes = [], refreshed_ds) {
13278
- var done_exp = [];
13279
-
13280
- const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
13281
- if (!_ds) return { abort: true };
13282
-
13283
- const get_attr_value = async function (key) {
13284
- let ret = func.UI.screen.fix_val_defaults(key, nodeP.attributes[key]);
13285
- if (nodeP?.attributes?.hasOwnProperty(`xu-exp:${key}`)) {
13286
- ret = await get_xuExp(key);
13287
- }
13288
- return ret;
13289
- };
13290
-
13291
- const get_xuExp = async function (attrib) {
13292
- if (is_skeleton) return;
13293
- if (glb.new_xu_render) {
13294
- let _xuData = $elm.data().xuData;
13295
- if (!_xuData.attr_exp_info) {
13296
- _xuData.attr_exp_info = {};
13297
- }
13298
- }
13299
- const attr = `xu-exp:${attrib}`;
13300
-
13301
- if (!nodeP?.attributes?.hasOwnProperty(attr)) return;
13302
- // const attr = `xu-exp-${attrib}`;
13303
- var exp = nodeP.attributes[attr];
13304
- // if (!value) return func.UI.screen.fix_val_defaults(attrib, exp || nodeP.attributes[attrib]);
13305
-
13306
- var res = await func.expression.get(SESSION_ID, exp, paramsP.dsSessionP, 'UI Attr EXP', _ds.currentRecordId);
13307
- if (glb.new_xu_render) {
13308
- _xuData.attr_exp_info[attrib] = res;
13309
- }
13310
- // nodeP.attributes[attr] = value; //{ value: value, res: res };
13311
- done_exp.push(attr);
13312
- return res.result; //func.UI.screen.fix_val_defaults(attrib, res.result);
13313
- };
13314
-
13315
- var _ret = {};
13316
- if (nodeP.type !== 'element' || !nodeP.attributes) return _ret;
13317
-
13318
- for (let [key, val] of Object.entries(nodeP.attributes)) {
13319
- // REMOVE STATIC ATTRIBUTES IF EXP EXISTS to avoid dup
13320
- if (key.substring(0, 6) === 'xu-exp') {
13321
- if (_.isEmpty(val)) {
13322
- delete nodeP.attributes[key];
13323
- continue;
13324
- }
13325
- const clean_key = key.split(':')[1];
13326
- if (typeof nodeP.attributes[clean_key] !== 'undefined') {
13327
- delete nodeP.attributes[clean_key];
13328
- }
13329
- }
13330
- // FIX abbreviations
13331
- if (glb.attr_abbreviations_arr.includes(key)) {
13332
- nodeP.attributes[`xu-on:${key.substring(3)}`] = [
13333
- {
13334
- handler: 'custom',
13335
- props: {},
13336
- event: [
13337
- {
13338
- id: Date.now(),
13339
- data: {
13340
- action: 'update',
13341
- name: { value: val },
13342
- enabled: true,
13343
- },
13344
- props: {},
13345
- },
13346
- ],
13347
- },
13348
- ];
13349
- delete nodeP.attributes[key];
13350
- }
13351
- }
13352
-
13353
- for (let [key, val] of Object.entries(nodeP.attributes)) {
13354
- // FIX STATIC DEFAULTS
13355
- val = func.UI.screen.fix_val_defaults(key, val);
13356
-
13357
- // REMOVE UNDEFINED or NULL ATTRIBUTES
13358
- if (typeof val === 'undefined' || val === null) {
13359
- delete nodeP.attributes[key];
13360
- }
13361
-
13362
- // REMOVE ATTRIBUTES WITH EMPTY VALUES
13363
- if (glb.solid_attributes.includes(key) && !val) {
13364
- delete nodeP.attributes[key];
13365
- }
13366
- }
13367
-
13368
- // XU-ATTRS
13369
- if (nodeP?.attributes?.['xu-attrs'] || nodeP?.attributes?.['xu-exp:xu-attrs']) {
13370
- const attr = 'xu-attrs';
13371
- let ret = await func.UI.screen.execute_xu_functions(
13372
- SESSION_ID,
13373
- is_skeleton,
13374
- $root_container,
13375
- nodeP,
13376
- $container,
13377
- paramsP,
13378
- parent_infoP,
13379
- jobNoP,
13380
- keyP,
13381
- parent_nodeP,
13382
- attr,
13383
- $elm,
13384
- {
13385
- key: attr,
13386
- value: await get_attr_value(attr),
13387
- },
13388
- is_init,
13389
- );
13390
- }
13391
-
13392
- // BEFORE
13393
- if (!_.isEmpty(nodeP.attributes)) {
13394
- for await (const [key, attr] of Object.entries(glb.run_xu_before)) {
13395
- if (_ret.abort || $container?.data()?.xuData?.pending_to_delete) break;
13396
- if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) {
13397
- continue;
13398
- }
13399
-
13400
- if (!nodeP?.attributes?.hasOwnProperty(attr) && !nodeP?.attributes?.hasOwnProperty(`xu-exp:${attr}`)) {
13401
- continue;
13402
- }
13403
-
13404
- if (!nodeP.attributes[`xu-exp:${attr}`] && nodeP?.attributes?.hasOwnProperty(attr) && typeof func.UI.screen.fix_val_defaults(attr, nodeP.attributes[attr]) === 'undefined') {
13405
- continue;
13406
- }
13407
-
13408
- let ret = await func.UI.screen.execute_xu_functions(
13409
- SESSION_ID,
13410
- is_skeleton,
13411
- $root_container,
13412
- nodeP,
13413
- $container,
13414
- paramsP,
13415
- parent_infoP,
13416
- jobNoP,
13417
- keyP,
13418
- parent_nodeP,
13419
- attr,
13420
- $elm,
13421
- {
13422
- key: attr,
13423
-
13424
- value: await get_attr_value(attr),
13425
- },
13426
- is_init,
13427
- );
13428
- _ret = _.assignIn(_ret, ret);
13429
- }
13430
- }
13431
-
13432
- // ALL
13433
-
13434
- for await (const [key, val] of Object.entries(nodeP.attributes)) {
13435
- if (_ret.abort || $container?.data()?.xuData?.pending_to_delete) break;
13436
- if (glb.html5_events_handler.includes(key) || execute_attributes.includes(key)) {
13437
- continue;
13438
- }
13439
-
13440
- const new_key = key.split(':')[0]; // break expression
13441
- if (
13442
- nodeP.tagName !== 'xu-panel' &&
13443
- nodeP.tagName !== 'xu-teleport' && // nodeP.tagName.substr(0, 3) !== "xu-" &&
13444
- (new_key.substr(0, 2) !== 'xu' || new_key.substr(2, 1) !== '-')
13445
- ) {
13446
- // handle common html attributes
13447
- try {
13448
- $elm.get(0).setAttribute(key, val);
13449
- } catch (err) {
13450
- console.error(err.message);
13451
- }
13452
-
13453
- continue;
13454
- }
13455
- // handle xu attributes
13456
- try {
13457
- if ($elm?.data()?.xuAttributes) {
13458
- // in some cases xu data delete in purpose when refreshing the screen
13459
- $elm.data().xuAttributes[key] = val;
13460
- }
13461
- } catch (error) {
13462
- debugger;
13463
- console.error(error);
13464
- }
13465
-
13466
- if (new_key === 'xu-exp' || nodeP.attributes['xu-exp:' + new_key] || glb.run_xu_before.includes(new_key) || glb.run_xu_after.includes(new_key)) {
13467
- continue;
13468
- }
13469
-
13470
- if (new_key === 'xu-on') {
13471
- let ret = await func.UI.screen.execute_xu_functions(
13472
- SESSION_ID,
13473
- is_skeleton,
13474
- $root_container,
13475
- nodeP,
13476
- $container,
13477
- paramsP,
13478
- parent_infoP,
13479
- jobNoP,
13480
- keyP,
13481
- parent_nodeP,
13482
- 'xu-on',
13483
- $elm,
13484
- {
13485
- key: key,
13486
- // value: (await get_xuExp(new_key)) || func.UI.screen.fix_val_defaults(key, val),
13487
- value: await get_attr_value(key),
13488
- },
13489
- is_init,
13490
- refreshed_ds,
13491
- );
13492
- _ret = _.assignIn(_ret, ret);
13493
- continue;
13494
- }
13495
-
13496
- let ret = await func.UI.screen.execute_xu_functions(
13497
- SESSION_ID,
13498
- is_skeleton,
13499
- $root_container,
13500
- nodeP,
13501
- $container,
13502
- paramsP,
13503
- parent_infoP,
13504
- jobNoP,
13505
- keyP,
13506
- parent_nodeP,
13507
- new_key,
13508
- $elm,
13509
- {
13510
- key: key,
13511
- // value: (await get_xuExp(new_key)) || func.UI.screen.fix_val_defaults(key, val),
13512
- value: await get_attr_value(key),
13513
- },
13514
- is_init,
13515
- refreshed_ds,
13516
- );
13517
-
13518
- _ret = _.assignIn(_ret, ret);
13519
- }
13520
-
13521
- // EXP for
13522
-
13523
- for await (const [key, val] of Object.entries(nodeP.attributes)) {
13524
- if (_ret.abort || $container?.data()?.xuData?.pending_to_delete) break;
13525
-
13526
- const attr = key.split('xu-exp:')[1];
13527
-
13528
- if (!attr) {
13529
- continue;
13530
- }
13531
-
13532
- if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) continue;
13533
-
13534
- if (done_exp.includes(key)) {
13535
- continue;
13536
- }
13537
- let ret = await func.UI.screen.execute_xu_functions(
13538
- SESSION_ID,
13539
- is_skeleton,
13540
- $root_container,
13541
- nodeP,
13542
- $container,
13543
- paramsP,
13544
- parent_infoP,
13545
- jobNoP,
13546
- keyP,
13547
- parent_nodeP,
13548
- 'xu-exp',
13549
- $elm,
13550
- {
13551
- key: attr,
13552
- value: val,
13553
- },
13554
- true,
13555
- refreshed_ds,
13556
- );
13557
- _ret = _.assignIn(_ret, ret);
13558
- }
13559
-
13560
- // AFTER
13561
-
13562
- for await (const [key, attr] of Object.entries(glb.run_xu_after)) {
13563
- if ($container?.data()?.xuData?.pending_to_delete) break;
13564
-
13565
- if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) continue;
13566
-
13567
- if (!nodeP.attributes || !nodeP.attributes[attr] & !nodeP.attributes[`xu-exp:${attr}`]) continue;
13568
-
13569
- let ret = await func.UI.screen.execute_xu_functions(
13570
- SESSION_ID,
13571
- is_skeleton,
13572
- $root_container,
13573
- nodeP,
13574
- $container,
13575
- paramsP,
13576
- parent_infoP,
13577
- jobNoP,
13578
- keyP,
13579
- parent_nodeP,
13580
- attr,
13581
- $elm,
13582
- {
13583
- key: attr,
13584
- // value: (await get_xuExp(attr)) || func.UI.screen.fix_val_defaults(attr, nodeP.attributes[attr]),
13585
- value: await get_attr_value(attr),
13586
- },
13587
- is_init,
13588
- refreshed_ds,
13589
- );
13590
- _ret = _.assignIn(_ret, ret);
13591
- }
13592
-
13593
- // REGISTER EVENTS ATTRIBUTES
13594
-
13595
- for await (const [key, val] of Object.entries(nodeP.attributes)) {
13596
- if ($container?.data()?.xuData?.pending_to_delete) break;
13597
- if (!glb.html5_events_handler.includes(key)) break;
13598
- // $elm.attr(key, await get_xuExp(key)) || val;
13599
- $elm.attr(key, await get_xuExp(key)) || val;
13600
- }
13601
-
13602
- return _ret;
13603
- };
13604
-
13605
- func.UI.screen.panel_post_render_handler = async function (
13606
- SESSION_ID,
13607
- $container, // the parent program container
13608
- $wrapper, // the wrapper element contains the rendered panel elements e.g: xu-single-view
13609
- nodeP, // the xu-panel node
13610
- $panel_div, // the panel div
13611
- jobNoP,
13612
- ) {
13613
- const _container_ds = SESSION_OBJ[SESSION_ID].DS_GLB[$container.data().xuData.paramsP.dsSessionP];
13614
- const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[$wrapper.data().xuData.paramsP.dsSessionP];
13615
- const find_old_panels_elements = function () {
13616
- return func.UI.utils.find_in_element_data('xuPanelData', $container.parent(), 'xu-ui-id', $container.data()?.xuPanelData?.xu_panel_xu_ui_id);
13617
- };
13618
- var $old_panel_div = find_old_panels_elements();
13619
- const set_xuPanelData_to_the_new_rendered_items = () => {
13620
- $container.data().xuPanelWrapper = { isWrapper: true, panelXuAttributes: _.clone($wrapper.data().xuAttributes), panelDivData: _.clone($wrapper.data()) };
13621
- $container.attr('xu-panel-wrapper-id', $wrapper.attr('xu-ui-id'));
13622
- $.each($wrapper.children(), function (key, val) {
13623
- if (!$(val).data().xuPanelData) {
13624
- $(val).data().xuPanelData = {};
13625
- }
13626
- $(val).data().xuPanelData.parent_element_ui_id = $old_panel_div?.length ? $container.parent().data().xuData.ui_id : $container.data().xuData.ui_id;
13627
-
13628
- $(val).data().xuPanelData.xu_panel_xu_ui_id = (nodeP.xu_tree_id || nodeP.id) + '-' + _container_ds?.currentRecordId;
13629
- $(val).data().xuPanelData.node = nodeP;
13630
- $(val).data().xuPanelData.$panel_div = $panel_div.clone(true);
13631
- });
13632
- };
13633
- set_xuPanelData_to_the_new_rendered_items();
13634
-
13635
- if ($old_panel_div?.length) {
13636
- $($old_panel_div[0]).after($wrapper.children());
13637
- } else {
13638
- $.each($wrapper.children(), function (key, child) {
13639
- $.each($container.children(), function (key, elm) {
13640
- if ($(elm)?.data()?.xuData && $(elm)?.data()?.xuData?.elem_key === $(child)?.data()?.xuData?.elem_key) {
13641
- $(elm).remove();
13642
- }
13643
- });
13644
- $container.append($(child));
13645
- });
13646
- }
13647
-
13648
- if (!$wrapper.data()?.xuData?.dsSession) return;
13649
-
13650
- if ($old_panel_div?.length) {
13651
- $container.parent().data().xuData.paramsP.dsSessionP = _ds.parentDataSourceNo; // set the new ds when panel replaced
13652
- } else {
13653
- $container.data().xuData.paramsP.dsSessionP = _ds.parentDataSourceNo; // set the new ds when panel replaced
13654
- }
13655
-
13656
- if ($old_panel_div?.length) {
13657
- $old_panel_div.remove();
13658
- }
13659
- return jobNoP;
13660
- };
13661
-
13662
- const generate_xu_ui_id = async function (SESSION_ID, nodeP, $container, paramsP, keyP) {
13663
- const _paramsP = _.cloneDeep(paramsP);
13664
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
13665
-
13666
- const currentRecordId = $container?.data?.()?.xuData?.recordid || (_ds ? _ds.currentRecordId : '');
13667
- const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
13668
- const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
13669
- let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
13670
-
13671
- const new_ui_id = await func.common.sha256(ui_id);
13672
- return new_ui_id;
13673
- };
13674
-
13675
- func.UI.screen.create_container = async function (SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, classP, elem_propP, div_typeP, $appendToP, attr_str, is_placeholder) {
13676
- const _paramsP = _.cloneDeep(paramsP);
13677
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
13678
- var $appendTo = $container;
13679
- if ($appendToP) $appendTo = $appendToP;
13680
- if (!$appendTo || !$appendTo.length) return null; // screen closed or not exist abort build
13681
- var div = 'div';
13682
- if (div_typeP) div = div_typeP;
13683
- var items = [];
13684
- if (nodeP.children)
13685
- items = nodeP.children.map(function (val) {
13686
- return val.xu_tree_id || val.id;
13687
- });
13688
- var currentRecordId = $container?.data?.()?.xuData?.recordid || (_ds ? _ds.currentRecordId : '');
13689
- // var xu_id = (glb.screen_num++).toString();
13690
- // xu_id = xu_id += '_' + currentRecordId;
13691
-
13692
- try {
13693
- const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
13694
- const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
13695
- // let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
13696
-
13697
- /////////////////////////////////
13698
-
13699
- var $div;
13700
-
13701
- if (div === 'svg') {
13702
- const draw_svg = function (element) {
13703
- const get_tag_str = function (element, prop, val) {
13704
- let class_str = '';
13705
- let attr_str = '';
13706
- for (const [key, val] of Object.entries(prop)) {
13707
- if (key.substr(0, 2) !== 'xu') {
13708
- attr_str += ` ${key}="${val}" `;
13709
- }
13710
- }
13711
- if (element === 'svg') {
13712
- return `<${element} ${attr_str} > `;
13713
- }
13714
- let ret = '';
13715
- if (val?.children?.length) {
13716
- ret = iterate_svg(val);
13717
- }
13718
-
13719
- return `<${element} ${class_str} ${attr_str} > ${ret} </${element}>`;
13720
- };
13721
- let svg_str = get_tag_str(element, prop);
13722
- let inner_str = '';
13723
- const iterate_svg = function (node) {
13724
- let ret = '';
13725
- if (node.children) {
13726
- for (let val of node.children) {
13727
- let prop = val.attributes;
13728
- ret += get_tag_str(val.tagName, prop, val);
13729
- }
13730
- }
13731
- return ret;
13732
- };
13733
- inner_str = iterate_svg(nodeP);
13734
-
13735
- $div = $(svg_str + inner_str + '</svg>').appendTo($appendTo);
13736
- };
13737
-
13738
- draw_svg(div_typeP);
13739
- } else {
13740
- $div = $(`<${div} ${attr_str ? attr_str : ''}>`);
13741
- }
13742
-
13743
- // // Returns a 32-bit unsigned integer hash of a string (FNV-1a)
13744
- // function hash32(str) {
13745
- // let h = 0x811c9dc5; // FNV offset basis
13746
- // for (let i = 0; i < str.length; i++) {
13747
- // h ^= str.charCodeAt(i);
13748
- // // multiply by FNV prime (2^24 + 2^8 + 0x93) with 32-bit overflow
13749
- // h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
13750
- // }
13751
- // // Convert to unsigned 32-bit
13752
- // return h >>> 0;
13753
- // }
13754
-
13755
- // function hash32hex(str) {
13756
- // return (hash32(str) >>> 0).toString(16).padStart(8, '0');
13757
- // }
13758
-
13759
- // const new_ui_id = hash32hex(ui_id);
13760
- // const new_ui_id = await func.common.sha256(ui_id);
13761
- const new_ui_id = await generate_xu_ui_id(SESSION_ID, nodeP, $container, paramsP, keyP);
13762
-
13763
- $div
13764
- .attr('xu-ui-id', new_ui_id)
13765
- // .attr('xu-node-id', nodeP.id)
13766
- .data({
13767
- xuData: {
13768
- prog_id: _paramsP.prog_id,
13769
- nodeid: nodeP.id,
13770
- ui_type: nodeP.tagName,
13771
- // xu_id,
13772
- recordid: currentRecordId,
13773
- paramsP: _paramsP,
13774
- key: keyP,
13775
- key_path, //:($container?.data()?.xuData?.key || "0") + "-" + (keyP || "0"),
13776
- screenId: _paramsP.screenId,
13777
- parent_container: $container?.attr('id'),
13778
- elem_key,
13779
- properties: prop,
13780
- node: nodeP,
13781
- node_org: _.cloneDeep(nodeP),
13782
- is_panelP: _paramsP.is_panelP,
13783
- ui_id: new_ui_id,
13784
- elem_prop: elem_propP,
13785
- debug_info: {
13786
- id: nodeP.id,
13787
- parent_id: $container?.data()?.xuData?.ui_id,
13788
- items: items,
13789
- },
13790
- parent_node: parent_nodeP,
13791
- currentRecordId: currentRecordId,
13792
- $root_container: $root_container,
13793
- parent_element_ui_id: $container?.data()?.xuData?.ui_id,
13794
- },
13795
- xuAttributes: {},
13796
- });
13797
- if (is_placeholder) {
13798
- $div.addClass('display_none');
13799
- }
13800
-
13801
- if (div_typeP !== 'svg') {
13802
- $div.appendTo($appendTo);
13803
- }
13804
- } catch (e) {
13805
- console.error(e);
13806
- }
13807
-
13808
- if (parent_infoP?.iterate_info) {
13809
- $div.data().xuData.iterate_info = parent_infoP.iterate_info;
13810
- }
13811
-
13812
- if (classP) $div.addClass(classP);
13813
-
13814
- return $div;
13815
- };
13816
- func.UI.screen.execute_screen_ready_events = async function (SESSION_ID, paramsP, sourceP, $div, jobNoP, $div_objP) {
13817
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
13818
- if (!_ds) return;
13819
- var viewEventExec_arr = [];
13820
- const execute_view_events = async function (sourceP) {
13821
- for await (const val of viewEventExec_arr) {
13822
- cond = val.eventInfo.data.enabled;
13823
- if (val.expression) {
13824
- expCond = await func.expression.get(SESSION_ID, val.expression, paramsP.dsSessionP, 'condition', paramsP.rowIdP); // execute expression
13825
- cond = expCond.result;
13826
- }
13827
- if (cond) {
13828
- await func.events.execute(
13829
- SESSION_ID,
13830
- null,
13831
- val.eventId,
13832
- val.triggerId,
13833
- val.eventInfo.data.action,
13834
- val.eventInfo.data.name,
13835
- null,
13836
- null,
13837
- null,
13838
- null,
13839
- val.eventInfo.data.action, //val.eventInfo[4]
13840
- null,
13841
- paramsP.dsSessionP,
13842
- val.eventId,
13843
- sourceP + ' event',
13844
- true,
13845
- null,
13846
- null,
13847
- paramsP.dsSessionP,
13848
- null,
13849
- null,
13850
- val.eventInfo, // val.eventInfo[8],
13851
- null,
13852
- null,
13853
- _ds.prog_id,
13854
- _ds.nodeId,
13855
- _ds.parentDataSourceNo,
13856
- $div,
13857
- );
13858
-
13859
- // update changed values to screen added 18/09/13
13860
- var fields_to_refresh = [];
13861
- try {
13862
- var current_record_id = _ds.currentRecordId;
13863
- } catch (e) {
13864
- console.error(e);
13865
- }
13866
-
13867
- if (_ds?.data_feed?.form_fields_changed?.[current_record_id]) {
13868
- $.each(_ds.data_feed.form_fields_changed[current_record_id], function (key, val) {
13869
- fields_to_refresh.push(key);
13870
- });
13871
-
13872
- var containerId = _ds.containerId;
13873
- var $container = $('#' + containerId);
13874
- if ($container?.data()?.xuData?.is_mobile_modal || $container?.data()?.xuData?.params?.is_mobile_page) {
13875
- await func.UI.screen.refresh_container(SESSION_ID, 'init', fields_to_refresh, $container, paramsP.dsSessionP, null);
13876
- } else {
13877
- $container.trigger(containerId + '.refresh', ['init', fields_to_refresh]);
13878
- }
13879
-
13880
- if ($div_objP) {
13881
- await func.UI.screen.refresh_container(SESSION_ID, 'init', fields_to_refresh, $div_objP, paramsP.dsSessionP, null);
13882
- }
13883
- }
13884
- }
13885
- continue;
13886
- }
13887
- };
13888
- const get_view_events_count = async function (typeP) {
13889
- const _prog = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
13890
- viewEventExec_arr = [];
13891
-
13892
- if (!_prog.progEvents || _.isEmpty(_prog.progEvents)) {
13893
- return 0;
13894
- }
13895
- for await (const event_obj of _prog.progEvents) {
13896
- if (event_obj.data.type !== typeP) continue;
13897
-
13898
- if (_.isEmpty(event_obj.workflow)) continue;
13899
-
13900
- if (event_obj.data.condition) {
13901
- let res = await func.expression.get(SESSION_ID, event_obj.data.condition, paramsP.dsSessionP, 'condition', paramsP.rowIdP, null, null, null, null, event_obj);
13902
- if (!res.result) {
13903
- continue;
13904
- }
13905
- }
13906
-
13907
- for await (const trigger_obj of event_obj.workflow) {
13908
- var expression = undefined;
13909
- var cond = undefined;
13910
- if (!trigger_obj.data.enabled) {
13911
- continue;
13912
- }
13913
- cond = true;
13914
- if (trigger_obj.props.condition) expression = trigger_obj.props.condition;
13915
- var expCond = {};
13916
- if (expression) {
13917
- expCond = await func.expression.get(SESSION_ID, expression, paramsP.dsSessionP, 'condition', paramsP.rowIdP, trigger_obj.data.type); // execute expression
13918
- cond = expCond.result;
13919
- expCond.conditional = true;
13920
- }
13921
-
13922
- if (!trigger_obj.data.action) {
13923
- func.utils.debug_report(SESSION_ID, 'get_view_events_count', `Error initiating ${typeP} prog: ${_ds.viewSourceDesc} reason: missing action`, 'E');
13924
- break;
13925
- }
13926
- if (!glb.REFERENCE_LESS_FUNCTIONS.includes(trigger_obj.data.action) && !trigger_obj.data.name?.prog) {
13927
- func.utils.debug_report(SESSION_ID, 'get_view_events_count', `Error initiating ${typeP} prog: ${_ds.viewSourceDesc} reason: missing reference`, 'E');
13928
- break;
13929
- }
13930
-
13931
- viewEventExec_arr.push({
13932
- eventInfo: trigger_obj,
13933
- eventId: event_obj.id,
13934
- triggerId: trigger_obj.id,
13935
- expression: expression,
13936
- });
13937
- }
13938
- }
13939
- return viewEventExec_arr.length;
13940
- };
13941
- try {
13942
- let count = await get_view_events_count('screen_ready');
13943
-
13944
- if (!count) return;
13945
- return await execute_view_events(sourceP);
13946
- } catch (error) {
13947
- debugger;
13948
- }
13949
- };
13950
- func.UI.screen.screen_loading_done = async function (SESSION_ID, paramsP, $div, jobNoP) {
13951
- // console.log($div.attr('xu-ui-id'));
13952
-
13953
- // await
13954
- let retries = 0;
13955
- let interval = setInterval(() => {
13956
- if (!$(SESSION_OBJ[SESSION_ID].root_element).find(`[xu-ui-id=${$div.attr('xu-ui-id')}]`).length && !$(SESSION_OBJ[SESSION_ID].root_element).find(`[xu-panel-wrapper-id=${$div.attr('xu-ui-id')}]`).length && !$div.attr('xu-ui-id') && $div.attr('xu-ui-id')) {
13957
- retries++;
13958
- if (retries > 100) {
13959
- console.warn('deadlock detected for screen ready');
13960
- } else {
13961
- return $div;
13962
- }
13963
- }
13964
-
13965
- clearInterval(interval);
13966
-
13967
- func.UI.screen.execute_screen_ready_events(SESSION_ID, paramsP, paramsP.screenInfo.properties?.renderType, $div, jobNoP);
13968
- var _session = SESSION_OBJ[SESSION_ID];
13969
- func.events.delete_job(SESSION_ID, jobNoP);
13970
- func.UI.utils.screen_blocker(false, paramsP.prog_id + (paramsP.sourceScreenP ? '_' + paramsP.sourceScreenP : ''));
13971
- if (_session.prog_id === paramsP.prog_id) {
13972
- _session.system_ready = true;
13973
- if (_session.engine_mode === 'live_preview' && STUDIO_PEER_CONN_SEND_METHOD) {
13974
- STUDIO_PEER_CONN_SEND_METHOD({
13975
- service: 'system_ready',
13976
- data: {},
13977
- id: STUDIO_PEER.id,
13978
- source: 'runtime',
13979
- session_id: SESSION_ID,
13980
- app_id: _session.app_id,
13981
- gtp_token: _session.gtp_token,
13982
- app_token: _session.app_token,
13983
- });
13984
- // }
13985
- }
13986
- }
13987
- }, 100);
13988
-
13989
- return $div;
13990
- };
13991
-
13992
- func.UI.screen.render_ui_tree = async function (SESSION_ID, $container, nodeP, parent_infoP, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, $root_container) {
13993
- if (!is_skeleton) {
13994
- var _session = SESSION_OBJ[SESSION_ID];
13995
- var _ds = _session.DS_GLB[paramsP.dsSessionP];
13996
- }
13997
- var prop;
13998
- try {
13999
- prop = nodeP.attributes;
14000
- } catch (error) {
14001
- // debugger;
14002
- }
14003
-
14004
- ///////////
14005
- var is_mobile = glb.MOBILE_ARR.includes(paramsP.screenInfo.properties?.menuType) ? true : false;
14006
-
14007
- const get_element_info = function () {
14008
- var ret = {};
14009
- let currentRecordId = _ds?.currentRecordId || '';
14010
-
14011
- let $div = func.UI.utils.find_in_element_data('xuData', $container.parent(), 'nodeid', nodeP.id);
14012
-
14013
- $.each($div, function (key, val) {
14014
- if ($(val)?.data().xuData?.recordid === currentRecordId && $(val)?.data().xuData?.key === keyP && $(val)?.prop('tagName') !== 'XURENDER') {
14015
- ret = {
14016
- div: $div,
14017
- };
14018
- }
14019
- });
14020
-
14021
- return ret;
14022
- };
14023
-
14024
- const init = async function () {
14025
- var ret = true;
14026
- if (!nodeP) ret = false;
14027
- return ret;
14028
- };
14029
- const debug = function (is_errorP, error_descP) {
14030
- func.utils.debug.log(SESSION_ID, paramsP.prog_id + '_' + nodeP.id_org + '_ui_prop', {
14031
- module: 'gui',
14032
- action: 'init',
14033
- prop: nodeP.id,
14034
- details: error_descP,
14035
- result: null,
14036
- error: is_errorP,
14037
- source: _ds?.tree_obj?.menuName || '',
14038
- fields: null,
14039
- type: null,
14040
- prog_id: paramsP.prog_id,
14041
- dsSession: null,
14042
- });
14043
- };
14044
-
14045
- const open_modal = async function ($div) {
14046
- const modal_id = 'app_modal-' + paramsP.dsSessionP.toString();
14047
- var xu_modal_controller = document.querySelector('xu-modal-controller');
14048
- if (!xu_modal_controller) {
14049
- func.UI.component.create_app_modal_component(SESSION_ID, modal_id);
14050
- xu_modal_controller = document.querySelector('xu-modal-controller');
14051
- }
14052
-
14053
- var controller_params = $(xu_modal_controller).data('xuControllerParams');
14054
-
14055
- if (!controller_params) {
14056
- controller_params = {};
14057
- }
14058
-
14059
- var params = {
14060
- menuTitle: paramsP.screenInfo.properties?.menuTitle,
14061
- screenId: paramsP.screenId,
14062
- $dialogDiv: $div.children(),
14063
- $container: $container,
14064
- dsSession: paramsP.dsSessionP,
14065
- };
14066
-
14067
- controller_params[modal_id] = params;
14068
-
14069
- $(xu_modal_controller).data('xuControllerParams', controller_params);
14070
- const modalController = await new UI_FRAMEWORK_PLUGIN.modal();
14071
-
14072
- if (!APP_MODAL_OBJ[modal_id]) {
14073
- const modal = await modalController.create(SESSION_ID, modal_id, paramsP.screenInfo, close_modal);
14074
- APP_MODAL_OBJ[modal_id] = modal;
14075
- } else {
14076
- $(modal_id).empty();
14077
- }
14078
- await modalController.init(SESSION_ID, modal_id);
14079
-
14080
- return $div;
14081
- };
14082
-
14083
- const close_modal = async function (modal_id) {
14084
- delete APP_MODAL_OBJ[modal_id];
14085
- const xu_modal_controller = document.querySelector('xu-modal-controller');
14086
- var params = $(xu_modal_controller).data().xuControllerParams[modal_id];
14087
- if (params && params.$container) {
14088
- await func.UI.screen.validate_exit_events(SESSION_ID, params.$container.data().xuData.paramsP, null);
14089
- func.datasource.clean_all(SESSION_ID, params.dsSession);
14090
- }
14091
- };
14092
-
14093
- const close_all_modals = function () {
14094
- $.each(APP_MODAL_OBJ, function (key, val) {
14095
- if (val) {
14096
- // close_modal(key);
14097
- UI_FRAMEWORK_PLUGIN.modal.close(key);
14098
- }
14099
- });
14100
- };
14101
-
14102
- const open_popover = async function ($div) {
14103
- const xu_popover_controller = func.UI.component.create_app_popover_component(SESSION_ID);
14104
-
14105
- $(xu_popover_controller).data('xuControllerParams', {
14106
- menuTitle: paramsP.screenInfo.properties?.menuTitle,
14107
- screenId: paramsP.screenId,
14108
- $dialogDiv: $div.children(),
14109
- $container: $container,
14110
- });
14111
- const popover = new UI_FRAMEWORK_PLUGIN.popover(
14112
- SESSION_ID,
14113
- // ELEMENT_CLICK_EVENT,
14114
- // props
14115
- );
14116
- await popover.open(SESSION_ID);
14117
- CURRENT_APP_POPOVER = popover;
14118
-
14119
- return;
14120
- popoverController
14121
- .create({
14122
- component: 'xu-popover-content-' + SESSION_ID,
14123
- event: ELEMENT_CLICK_EVENT,
14124
- translucent: true,
14125
- })
14126
- .then((modal) => {
14127
- modal.present().then(() => {
14128
- CURRENT_APP_POPOVER = modal;
14129
-
14130
- if (callbackP) callbackP($div);
14131
- });
14132
- });
14133
- };
14134
- const iterate_child = async function ($divP, nodeP, parent_infoP, $root_container, before_record_function) {
14135
- if (!is_mobile && nodeP.busy) return;
14136
- nodeP.busy = true;
14137
- const done = async function ($divP) {
14138
- setTimeout(function () {
14139
- nodeP.busy = false;
14140
- }, 1000);
14141
-
14142
- return $divP;
14143
- };
14144
- if (!nodeP || !nodeP.children) {
14145
- return await done($divP);
14146
- }
14147
-
14148
- if (before_record_function) {
14149
- await before_record_function();
14150
- }
14151
- if (nodeP?.children?.length) {
14152
- let node_promises = [];
14153
- for (const [key, val] of Object.entries(nodeP.children)) {
14154
- node_promises.push(
14155
- new Promise(async (resolve, reject) => {
14156
- const ret = await func.UI.screen.render_ui_tree(SESSION_ID, $divP, nodeP.children[key], parent_infoP, paramsP, jobNoP, is_skeleton, Number(key), null, nodeP, null, $root_container);
14157
-
14158
- resolve();
14159
- }),
14160
- );
14161
- }
14162
- await Promise.all(node_promises);
14163
- }
14164
- return await done($divP);
14165
- };
14166
-
14167
- // const iterate_child = async function ($divP, nodeP, parent_infoP, $root_container, before_record_function) {
14168
- // if (!is_mobile && nodeP.busy) return;
14169
- // nodeP.busy = true;
14170
- // const done = async function ($divP) {
14171
- // setTimeout(function () {
14172
- // nodeP.busy = false;
14173
- // }, 1000);
14174
-
14175
- // return $divP;
14176
- // };
14177
- // if (!nodeP || !nodeP.children) {
14178
- // return await done($divP);
14179
- // }
14180
-
14181
- // if (before_record_function) {
14182
- // await before_record_function();
14183
- // }
14184
- // if (nodeP?.children?.length) {
14185
- // for await (const [key, val] of Object.entries(nodeP.children)) {
14186
- // const ret = await func.UI.screen.render_ui_tree(SESSION_ID, $divP, nodeP.children[key], parent_infoP, paramsP, jobNoP, is_skeleton, Number(key), null, nodeP, null, $root_container);
14187
- // }
14188
- // }
14189
- // return await done($divP);
14190
- // };
14191
-
14192
- const _$ = function ($elm) {
14193
- try {
14194
- const id = $elm.attr('xu-ui-id');
14195
- if (!id || !glb.DEBUG_MODE) return $elm;
14196
- const $el = $(`[xu-ui-id="${id}"]`);
14197
-
14198
- if ($el.length > 1) {
14199
- console.warn('Multiple elements for xu-ui-id: ' + id, $el);
14200
- }
14201
-
14202
- return $($el[0]);
14203
- } catch (e) {
14204
- console.error(e);
14205
- }
14206
- };
14207
-
14208
- const hover_in = function ($div, e) {
14209
- if (is_skeleton || (e && (EXP_BUSY || UI_WORKER_OBJ.jobs.length))) return;
14210
- CLIENT_ACTIVITY_TS = Date.now();
14211
- if (_$($container)?.data()?.xuData?.debug_info) _$($container).data().xuData.debug_info.hover_item = $div.attr('xu-ui-id');
14212
- if (!_ds) return;
14213
- ///////// SET Attributes///////////
14214
- let attributes = {};
14215
- $.each($div[0].attributes, function (index, attr) {
14216
- attributes[attr.name] = attr.value;
14217
- });
14218
-
14219
- _session.DS_GLB[0].data_system.SYS_OBJ_WIN_ELEMENT_HOVERED_ATTRIBUTES = attributes;
14220
- //////////////////////////////////
14221
- if (!$div.data()?.xuData) return;
14222
- const _iterate_info = $div.data().xuData.iterate_info;
14223
- if (_iterate_info) {
14224
- if (_iterate_info.is_key_dynamic_field) {
14225
- _ds.dynamic_fields[_iterate_info.iterator_key].value = _iterate_info._key;
14226
- } else {
14227
- try {
14228
- const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
14229
- _ds.data_feed.rows[row_idx][_iterate_info.iterator_key] = _iterate_info._key;
14230
- } catch (err) {
14231
- console.error(err);
14232
- }
14233
- }
14234
-
14235
- if (_iterate_info.is_val_dynamic_field) {
14236
- _ds.dynamic_fields[_iterate_info.iterator_val].value = _iterate_info._val;
14237
- } else {
14238
- try {
14239
- const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
14240
- _ds.data_feed.rows[row_idx][_iterate_info.iterator_val] = _iterate_info._val;
14241
- } catch (err) {
14242
- console.error(err);
14243
- }
14244
- }
14245
- }
14246
-
14247
- if ($div && _$($div) && _ds && paramsP.renderType === 'grid') {
14248
- func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'update_datasource', { currentRecordId: _$($div).data().xuData.currentRecordId }, null, null, paramsP.dsSessionP);
14249
- }
14250
-
14251
- const set_value = function (field_id, value) {
14252
- var currentRecordId = _$($div).data().xuData.currentRecordId;
14253
-
14254
- func.UI.worker.add_to_queue(
14255
- SESSION_ID,
14256
- 'gui event',
14257
- 'update_datasource',
14258
- {
14259
- currentRecordId,
14260
- field_id,
14261
- field_value: value,
14262
- },
14263
- null,
14264
- null,
14265
- paramsP.dsSessionP,
14266
- );
14267
- };
14268
-
14269
- if ($div?.data()?.iterate_info) {
14270
- var data = $div.data().xuData.iterate_info;
14271
- if (data.iterator_key) {
14272
- set_value(data.iterator_key, data._key);
14273
- }
14274
- if (data.iterator_val) {
14275
- set_value(data.iterator_val, data._val);
14276
- }
14277
- }
14278
- };
14279
- const hover_out = function () {
14280
- if (is_skeleton) return;
14281
-
14282
- CLIENT_ACTIVITY_TS = Date.now();
14283
- if (_$($container)?.data()?.xuData?.debug_info) {
14284
- _$($container).data().xuData.debug_info.hover_item = null;
14285
- }
14286
- if (_ds?.data_system) {
14287
- SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_OBJ_WIN_ELEMENT_HOVERED_ATTRIBUTES = {};
14288
- }
14289
- };
14290
- const render_screen_type = async function ($div) {
14291
- const set_call_screen_properties_values = async function (ui_framework) {
14292
- params.properties = {};
14293
- const get_values = async function (property) {
14294
- var property_value = paramsP?.screenInfo?.properties?.[property] || paramsP?.screenInfo?.properties?.frameworkProperties?.[property];
14295
- if (paramsP?.call_screen_propertiesP) {
14296
- if (paramsP.call_screen_propertiesP?.[property]) {
14297
- property_value = paramsP.call_screen_propertiesP[property];
14298
- }
14299
- if (paramsP.call_screen_propertiesP[`xu-exp:${property}`]) {
14300
- property_value = (await func.expression.get(SESSION_ID, paramsP.call_screen_propertiesP[`xu-exp:${property}`], paramsP.dsSessionP, property)).result;
14301
- }
14302
- }
14303
- return property_value;
14304
- };
14305
- params.properties['name'] = await get_values('menuTitle');
14306
- if (await ui_framework?.properties()) {
14307
- for await (const [key, val] of Object.entries(await ui_framework.properties())) {
14308
- params.properties[key] = await get_values(key);
14309
- }
14310
- }
14311
- };
14312
-
14313
- var $div_content = $div.children();
14314
-
14315
- $.each($div_content, function (key, val) {
14316
- if (!$(val)?.data()?.xuData?.parent_container) {
14317
- return true;
14318
- }
14319
- $(val).data().xuData.parent_container = $div.data().xuData.parent_container;
14320
- });
14321
-
14322
- let $ret = $div;
14323
- var $nav = $(SESSION_OBJ[SESSION_ID].root_element).find('xu-nav');
14324
- var params;
14325
- switch (paramsP.screen_type) {
14326
- case 'modal':
14327
- const modal_id = 'app_modal-' + paramsP.dsSessionP.toString();
14328
- var xu_modal_controller = document.querySelector('xu-modal-controller');
14329
- if (!xu_modal_controller) {
14330
- func.UI.component.create_app_modal_component(SESSION_ID, modal_id);
14331
- xu_modal_controller = document.querySelector('xu-modal-controller');
14332
- }
14333
-
14334
- var controller_params = $(xu_modal_controller).data('xuControllerParams');
14335
-
14336
- if (!controller_params) {
14337
- controller_params = {};
14338
- }
14339
-
14340
- params = {
14341
- screenId: paramsP.screenId,
14342
- $dialogDiv: $div.children(),
14343
- $container: $container,
14344
- dsSession: paramsP.dsSessionP,
14345
- modal_id,
14346
- screenInfo: paramsP.screenInfo,
14347
- close_callback: close_modal,
14348
- paramsP,
14349
- };
14350
-
14351
- controller_params[modal_id] = params;
14352
-
14353
- $(xu_modal_controller).data('xuControllerParams', controller_params);
14354
- const modalController = await new UI_FRAMEWORK_PLUGIN.modal();
14355
- await set_call_screen_properties_values(modalController);
14356
- if (!APP_MODAL_OBJ[modal_id]) {
14357
- const modal = await modalController.create(params);
14358
-
14359
- APP_MODAL_OBJ[modal_id] = modal;
14360
- } else {
14361
- $(modal_id).empty();
14362
- }
14363
-
14364
- await modalController.init(params);
14365
-
14366
- break;
14367
-
14368
- case 'popover':
14369
- // open_popover($div);
14370
-
14371
- const xu_popover_controller = func.UI.component.create_app_popover_component(SESSION_ID);
14372
- params = {
14373
- menuTitle: paramsP.screenInfo.properties?.menuTitle,
14374
- screenId: paramsP.screenId,
14375
- $dialogDiv: $div.children(),
14376
- $container: $container,
14377
- };
14378
-
14379
- $(xu_popover_controller).data('xuControllerParams', params);
14380
- const popover = new UI_FRAMEWORK_PLUGIN.popover(SESSION_ID);
14381
- await set_call_screen_properties_values(popover);
14382
- await popover.open(params);
14383
- CURRENT_APP_POPOVER = popover;
14384
-
14385
- func.UI.utils.screen_blocker(false, paramsP.prog_id + '_' + paramsP.sourceScreenP);
14386
- break;
14387
-
14388
- case 'page':
14389
- const nav = $nav[0];
14390
-
14391
- params = {
14392
- div: $div_content,
14393
- name: paramsP.screenInfo.properties?.menuTitle,
14394
- screenId: paramsP.screenId,
14395
- $container: $container,
14396
- dsSession: paramsP.dsSessionP,
14397
- SESSION_ID,
14398
- nav,
14399
- paramsP,
14400
- };
14401
-
14402
- var component_name = 'xu-page-component-' + paramsP.dsSessionP;
14403
- if (!$(nav).data().xuData.nav_params) {
14404
- $(nav).data().xuData.nav_params = {};
14405
- }
14406
-
14407
- //restore validate
14408
- if ($(nav)?.data()?.xuData?.params?.[paramsP.dsSessionP]) {
14409
- params.$container.data().xuData.validate_screen_ready = $(nav).data().xuData.params[paramsP.dsSessionP].$container.data().xuData.validate_screen_ready;
14410
- }
14411
-
14412
- if (!$(nav)?.data()?.xuData) return;
14413
- $(nav).data().xuData.nav_params[paramsP.dsSessionP] = params;
14414
- if (!$(component_name).length) {
14415
- await func.UI.component.create_app_page_component(SESSION_ID, paramsP.dsSessionP);
14416
- const page = new UI_FRAMEWORK_PLUGIN.page();
14417
- await set_call_screen_properties_values(page);
14418
- await page.create(params);
14419
- await page.init(params);
14420
- nav.push(component_name, { params });
14421
- } else {
14422
- debugger;
14423
- $(component_name).empty();
14424
-
14425
- await UI_FRAMEWORK_PLUGIN.page(SESSION_ID, paramsP.dsSessionP);
14426
- }
14427
- $div.data().xuData.paramsP = $container.data().xuData.paramsP;
14428
- break;
14429
-
14430
- case 'panel':
14431
- $container.append($div_content);
14432
- $ret = $container;
14433
- break;
14434
-
14435
- default: // set data to nav to use in the component
14436
- if ($nav && $nav.length) {
14437
- // refresh made
14438
- } else {
14439
- $nav = $('<xu-nav>'); //.attr('xu-ui-id', SESSION_ID);
14440
- $container.append($nav);
14441
- func.UI.component.init_xu_nav($container, $nav);
14442
- }
14443
-
14444
- $nav.data().xuData.$div = $div_content;
14445
-
14446
- await $nav[0].setRoot('xu-root-component-' + SESSION_ID);
14447
- $ret = $container;
14448
- break;
14449
- }
14450
- return $ret;
14451
- };
14452
-
14453
- if (!(await init())) return;
14454
- debug();
14455
- const fx = {
14456
- widget: async function () {
14457
- var _session = SESSION_OBJ[SESSION_ID];
14458
-
14459
- var exist_elm_obj = get_element_info();
14460
- var $div = exist_elm_obj.div;
14461
- if (!exist_elm_obj.div) {
14462
- $div = await func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, 'widget_wrapper', null, null, null, null);
14463
-
14464
- //////////////////////////
14465
-
14466
- let plugin_name = prop['xu-widget'],
14467
- method = prop['xu-method'],
14468
- dsP = paramsP.dsSessionP,
14469
- propsP = prop,
14470
- sourceP = 'widgets';
14471
-
14472
- // const set_SYS_GLOBAL_OBJ_WIDGET_INFO = async function (docP) {
14473
- // var obj = _.clone(docP);
14474
- // obj.date = await func.utils.get_dateTime(
14475
- // SESSION_ID,
14476
- // "SYS_DATE",
14477
- // docP.date
14478
- // );
14479
- // obj.time = await func.utils.get_dateTime(
14480
- // SESSION_ID,
14481
- // "SYS_TIME",
14482
- // docP.date
14483
- // );
14484
-
14485
- // var datasource_changes = {
14486
- // [0]: {
14487
- // ["data_system"]: {
14488
- // ["SYS_GLOBAL_OBJ_WIDGET_INFO"]: obj,
14489
- // },
14490
- // },
14491
- // };
14492
- // await func.datasource.update(SESSION_ID, datasource_changes);
14493
- // };
14494
- const call_plugin_api = async function (plugin_nameP, dataP) {
14495
- return await func.utils.call_plugin_api(SESSION_ID, plugin_nameP, dataP);
14496
- };
14497
- const report_error = function (descP, warn) {
14498
- func.utils.debug.log(SESSION_ID, _session.DS_GLB[dsP].prog_id + '_' + _session.DS_GLB[dsP].callingMenuId, {
14499
- module: 'widgets',
14500
- action: 'Init',
14501
- source: sourceP,
14502
- prop: descP,
14503
- details: descP,
14504
- result: null,
14505
- error: warn ? false : true,
14506
- fields: null,
14507
- type: 'widgets',
14508
- prog_id: _session.DS_GLB[dsP].prog_id,
14509
- });
14510
- };
14511
- const get_fields_data = async function (fields, props) {
14512
- const report_error = function (descP, warn) {
14513
- func.utils.debug.log(SESSION_ID, _session.DS_GLB[dsP].prog_id + '_' + _session.DS_GLB[dsP].callingMenuId, {
14514
- module: 'widgets',
14515
- action: 'Init',
14516
- source: sourceP,
14517
- prop: descP,
14518
- details: descP,
14519
- result: null,
14520
- error: warn ? false : true,
14521
- fields: null,
14522
- type: 'widgets',
14523
- prog_id: _session.DS_GLB[dsP].prog_id,
14524
- });
14525
- };
14526
- const get_property_value = async function (fieldIdP, val) {
14527
- if (!val) return;
14528
- var value = fieldIdP in props ? props[fieldIdP] : typeof val.defaultValue === 'function' ? val?.defaultValue?.() : val?.defaultValue;
14529
- if (val.render === 'eventId') {
14530
- value = props?.[fieldIdP]?.event;
14531
- }
14532
-
14533
- if (props[`xu-exp:${fieldIdP}`]) {
14534
- value = (await func.expression.get(SESSION_ID, props[`xu-exp:${fieldIdP}`], dsP, 'widget property')).result;
14535
- }
14536
-
14537
- return func.common.get_cast_val(
14538
- SESSION_ID,
14539
- 'widgets',
14540
- fieldIdP,
14541
- val.type, //val.type !== "string" || val.type !== "number" ? "string" : val.type,
14542
- value,
14543
- null,
14544
- );
14545
- };
14546
- var data_obj = {};
14547
- var return_code = 1;
14548
- // $.each(fields, function (key, val) {
14549
- for await (const [key, val] of Object.entries(fields)) {
14550
- data_obj[key] = await get_property_value(key, val);
14551
- if (!data_obj[key] && val.mandatory) {
14552
- return_code = -1;
14553
- report_error(`${key} is a mandatory field.`);
14554
- break;
14555
- }
14556
- // console.log(val);
14557
- }
14558
- for await (const key of ['xu-bind']) {
14559
- data_obj[key] = await get_property_value(key, props[key]);
14560
- }
14561
-
14562
- return { code: return_code, data: data_obj };
14563
- };
14564
-
14565
- const load_css_style = function () {
14566
- const get_css_path = function (resource) {
14567
- if (_session.worker_type === 'Dev') {
14568
- return `../../plugins/${plugin_name}/${resource}`;
14569
- }
14570
- return `https://${_session.domain}/plugins/${plugin_name}/${APP_OBJ[_session.app_id].app_plugins_purchased[plugin_name].manifest[resource].dist ? 'dist/' : ''}${resource}?gtp_token=${_session.gtp_token}&app_id=${_session.app_id}`;
14571
- };
14572
- let path = get_css_path('style.css');
14573
- func.utils.load_css_on_demand(path);
14574
- };
14575
-
14576
- const _plugin = APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];
14577
- const index = await func.utils.get_plugin_resource(SESSION_ID, plugin_name, `${_plugin.manifest['index.mjs'].dist ? 'dist/' : ''}index.mjs`);
14578
- const methods = index.methods;
14579
- if (methods && !methods[method]) {
14580
- return report_error('method not found');
14581
- }
14582
-
14583
- const fields_ret = await get_fields_data(methods[method].fields, propsP);
14584
- if (fields_ret.code < 0) {
14585
- return report_error(fields_ret.data);
14586
- }
14587
- const fields = fields_ret.data;
14588
-
14589
- let exclude_attributes = [];
14590
- for await (const [key, val] of Object.entries(propsP)) {
14591
- if (typeof fields[key] !== 'undefined' || typeof fields[`xu-exp:${key}`] !== 'undefined') {
14592
- exclude_attributes.push(key);
14593
- }
14594
- }
14595
-
14596
- let ret = await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $div, true, exclude_attributes);
14597
-
14598
- $div.addClass('widget_wrapper'); // class get override in set_attributes_new
14599
-
14600
- if (!APP_OBJ[_session.app_id].app_plugins_purchased[plugin_name]) {
14601
- return report_error(`plugin ${plugin_name} not found`);
14602
- }
14603
-
14604
- if (APP_OBJ[_session.app_id].app_plugins_purchased[plugin_name].manifest['style.css'].exist) {
14605
- load_css_style();
14606
- }
14607
-
14608
- const plugin_setup_ret = await func.utils.get_plugin_setup(SESSION_ID, plugin_name);
14609
- if (plugin_setup_ret.code < 0) {
14610
- return report_error(plugin_setup_ret);
14611
- }
14612
-
14613
- const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
14614
- func,
14615
- glb,
14616
- SESSION_OBJ,
14617
- SESSION_ID,
14618
- APP_OBJ,
14619
- dsSession: paramsP.dsSessionP,
14620
- job_id: jobNoP,
14621
- });
14622
-
14623
- const params = {
14624
- SESSION_ID,
14625
- method,
14626
- _session,
14627
- dsP,
14628
- sourceP,
14629
- propsP,
14630
- plugin_name,
14631
- $containerP: $div,
14632
- plugin_setup: plugin_setup_ret.data,
14633
-
14634
- report_error,
14635
- call_plugin_api,
14636
- // set_SYS_GLOBAL_OBJ_WIDGET_INFO,
14637
- api_utils,
14638
- };
14639
-
14640
- const fx = await func.utils.get_plugin_resource(SESSION_ID, plugin_name, `${_plugin.manifest['runtime.mjs'].dist ? 'dist/' : ''}runtime.mjs`);
14641
-
14642
- if (_plugin?.manifest?.['runtime.mjs'].dist && _plugin?.manifest?.['runtime.mjs']?.css) {
14643
- const plugin_runtime_css_url = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, 'dist/runtime.css');
14644
- func.utils.load_css_on_demand(plugin_runtime_css_url);
14645
- }
14646
-
14647
- if (!fx[method]) {
14648
- throw `Method: ${method} does not exist`;
14649
- }
14650
- try {
14651
- await fx[method](fields, params);
14652
- } catch (err) {
14653
- func.utils.debug_report(SESSION_ID, `${plugin_name} widget`, err.message, 'E');
14654
- }
14655
- }
14656
- return $div;
14657
- },
14658
- [`xu-single-view`]: async function () {
14659
- var exist_elm_obj = get_element_info();
14660
- var $div = exist_elm_obj.div;
14661
-
14662
- if (!exist_elm_obj.div) {
14663
- var $wrapper = $('<div>');
14664
- $div = await func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, null, null, 'div', $wrapper, '');
14665
-
14666
- if (!$div) return;
14667
-
14668
- if (!REFRESHER_IN_PROGRESS && (paramsP.is_mobile_popover || paramsP.is_mobile_page)) {
14669
- close_all_modals();
14670
- }
14671
-
14672
- $div.hover(
14673
- function (e) {
14674
- hover_in();
14675
- // func.UI.screen.hover_in(SESSION_ID, null, $container, paramsP, is_skeleton);
14676
- },
14677
- function (e) {
14678
- // func.UI.screen.hover_out(SESSION_ID, $container, is_skeleton, paramsP);
14679
- hover_out();
14680
- },
14681
- );
14682
- }
14683
-
14684
- const ret = await iterate_child($div, nodeP, null, $div);
14685
- if (_.isEmpty($container.data().xuAttributes)) {
14686
- await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
14687
- }
14688
-
14689
- $.each($div.data().xuData, function (key, val) {
14690
- $container.data().xuData[key] = _.cloneDeep(val);
14691
- });
14692
- $.each($div.data().xuAttributes, function (key, val) {
14693
- $container.data().xuAttributes[key] = _.cloneDeep(val);
14694
- });
14695
-
14696
- return await render_screen_type($div);
14697
- },
14698
- [`xu-multi-view`]: async function () {
14699
- var $div = $container;
14700
-
14701
- if (!$div.data().xuData.node || !$div.data().xuData.node.children) {
14702
- $div.data().xuData.node = nodeP;
14703
- }
14704
-
14705
- if (!$div.data().xuData.debug_info) {
14706
- $div.data().xuData.debug_info = {
14707
- id: nodeP.id,
14708
- parent_id: $container.data().xuData.ui_id,
14709
- };
14710
- }
14711
-
14712
- const done = async function (continuous_idx) {
14713
- // const do_callback = async function ($div) {
14714
- // // if ($root_container.data().xuData.progress_bar_circle) {
14715
- // // setTimeout(function () {
14716
- // // $.each(
14717
- // // $root_container.data().xuData.progress_bar_circle,
14718
- // // function (key, val) {
14719
- // // val.bar.set(parseFloat(val.value)); // Number from 0.0 to 1.0
14720
- // // }
14721
- // // );
14722
- // // }, 2000);
14723
- // // }
14724
-
14725
- // if (paramsP.screenInfo.properties?.rtl) {
14726
- // $div_content.attr('dir', 'rtl');
14727
- // }
14728
-
14729
- // return $div;
14730
- // };
14731
- await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
14732
-
14733
- return await render_screen_type($div);
14734
- };
14735
-
14736
- if (!REFRESHER_IN_PROGRESS && (paramsP.is_mobile_popover || paramsP.is_mobile_page)) {
14737
- close_all_modals();
14738
- }
14739
-
14740
- const empty_result = async function () {
14741
- // var content = prop.empty_result_content || '';
14742
-
14743
- // var res = await func.expression.get(
14744
- // SESSION_ID,
14745
- // content, // prop["xu-exp:empty_result_content"],
14746
- // paramsP.dsSessionP,
14747
- // 'empty_result_content_EXP',
14748
- // _ds.currentRecordId,
14749
- // );
14750
- // content = res.result;
14751
-
14752
- // let empty_result_node = {
14753
- // type: 'element',
14754
- // id: crypto.randomUUID(),
14755
- // content,
14756
- // // : content || (typeof content === "undefined" && "Empty results"),
14757
- // tagName: 'div',
14758
- // attributes: {},
14759
- // children: [],
14760
- // };
14761
-
14762
- // const ret = await func.UI.screen.render_ui_tree(SESSION_ID, $container, empty_result_node, parent_infoP, paramsP, jobNoP, null, 0, null, nodeP, null, $root_container);
14763
- await func.events.validate(SESSION_ID, 'record_not_found', paramsP.dsSessionP);
14764
- return await done(null);
14765
- };
14766
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
14767
-
14768
- var continuous_idx = null;
14769
-
14770
- if (!_ds.data_feed || _.isEmpty(_ds.data_feed.rows)) {
14771
- return await empty_result();
14772
- }
14773
-
14774
- var i = 0;
14775
- for await (const [key, val] of Object.entries(_ds.data_feed.rows)) {
14776
- var node = JSON.parse(JSON.stringify(nodeP));
14777
-
14778
- _ds.currentRecordId = val._ROWID;
14779
- const ret = await iterate_child($div, node, { continuous_idx }, $root_container);
14780
-
14781
- if (_.isEmpty($container.data().xuAttributes)) {
14782
- await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
14783
- }
14784
- }
14785
-
14786
- return await done(continuous_idx);
14787
- },
14788
- [`xu-panel`]: async function () {
14789
- const done = async function ($new_div) {
14790
- if (!$container.data()?.xuData?.paramsP) {
14791
- return $container;
14792
- }
14793
- var $div_items = $div.data().xuData.node.children;
14794
-
14795
- await func.UI.screen.panel_post_render_handler(SESSION_ID, $container, $new_div, nodeP, $div, jobNoP);
14796
-
14797
- // TO FIX should be timeout
14798
- $container.data().xuData.node.children = $div_items;
14799
-
14800
- return $container;
14801
- };
14802
-
14803
- var $wrapper = $('<div>');
14804
- $div = await func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, null, null, null, $wrapper, '');
14805
-
14806
- let ret = await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $div.clone(true), true, undefined, refreshed_ds);
14807
- if (ret.abort) {
14808
- // render N
14809
- return (ret.$new_div = $('<template>').append($div));
14810
- }
14811
-
14812
- let $ret_panel_div = ret.$new_div;
14813
-
14814
- if (!$ret_panel_div?.children()?.length) {
14815
- ////// render default children tree
14816
- if (nodeP.children.length) {
14817
- $ret_panel_div = await func.UI.screen.render_ui_tree(SESSION_ID, $container, nodeP.children[0], parent_infoP, paramsP, jobNoP, null, 0, null, nodeP, null, $root_container);
14818
- }
14819
- }
14820
-
14821
- let ret_done = await done($ret_panel_div);
14822
-
14823
- return ret_done;
14824
- },
14825
- };
14826
-
14827
- const draw_html_element_org = async function (element) {
14828
- const done = async function (ret = {}) {
14829
- return $div;
14830
- };
14831
- if (!element || element === 'script') return await done();
14832
- let str = '';
14833
-
14834
- var $div = await func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, null, null, element, null, str);
14835
-
14836
- $div.hover(
14837
- function (e) {
14838
- hover_in($div, e);
14839
- },
14840
- function (e) {
14841
- hover_out();
14842
- },
14843
- );
14844
- if (paramsP.paramsP === 'grid' || parent_infoP?.iterate_info) {
14845
- $div.on('click contextmenu', function (e) {
14846
- hover_in($div, e);
14847
- });
14848
- }
14849
-
14850
- // let ret = await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $container, nodeP, $div, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $div, true);
14851
- let ret = await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $div, true);
14852
- if (ret.abort || nodeP.tagName === 'svg' || !_.isEmpty(nodeP?.attributes?.['xu-text']) || !_.isEmpty(nodeP?.attributes?.['xu-html']) || !_.isEmpty(nodeP?.attributes?.['xu-exp:xu-text']) || !_.isEmpty(nodeP?.attributes?.['xu-exp:xu-html'])) {
14853
- return await done(ret);
14854
- }
14855
- // check if iterator made to prevent children render
14856
-
14857
- if (nodeP?.attributes?.['xu-viewport'] == 'true') {
14858
- // const xu_viewport = async function () {
14859
- // const data = { $div: $div.clone(true), nodeP, parent_infoP, $root_container, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, $container };
14860
- // const container_id = $container.attr('xu-ui-id');
14861
- // if (!UI_WORKER_OBJ.pending_for_viewport_render[container_id]) {
14862
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id] = { base_$div: $div, data: [], $container };
14863
- // await iterate_child($div, nodeP, parent_infoP, $root_container);
14864
- // } else {
14865
- // $div.remove();
14866
- // }
14867
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id].data.push(data);
14868
-
14869
- // // if (!$div.children().length) {
14870
- // // // render the first element to determine height
14871
- // // await iterate_child($div, nodeP, parent_infoP, $root_container);
14872
- // // // hover_in($div);
14873
- // // // func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'render_viewport', data, null, null, paramsP.dsSessionP);
14874
- // // } else {
14875
- // // }
14876
- // };
14877
- const xu_viewport = function () {
14878
- const observer_inViewport = new IntersectionObserver(
14879
- function (entries) {
14880
- entries.forEach((entry) => {
14881
- if (entry.isIntersecting) {
14882
- $(entry.target).trigger('inViewport');
14883
-
14884
- // Optional: stop observing once triggered
14885
- observer_inViewport.unobserve(entry.target);
14886
- }
14887
- });
14888
- },
14889
- {
14890
- threshold: 0.1, // Trigger when 10% of element is visible
14891
- },
14892
- );
14893
-
14894
- const observer_outViewport = new IntersectionObserver(
14895
- function (entries) {
14896
- entries.forEach((entry) => {
14897
- if (!entry.isIntersecting) {
14898
- // Element is OUT of viewport - trigger custom event
14899
- $(entry.target).trigger('outViewport');
14900
-
14901
- // Optional: stop observing once triggered
14902
- // observer_outViewport.unobserve(entry.target);
14903
- }
14904
- });
14905
- },
14906
- {
14907
- threshold: 0, // Trigger when element is completely out of view
14908
- },
14909
- );
14910
-
14911
- let ui_job_id;
14912
- $div.on('inViewport', function () {
14913
- if ($div.children().length) {
14914
- $div.removeClass('skeleton');
14915
- return;
14916
- }
14917
-
14918
- // if (UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')]) {
14919
- // $div[0].style.removeProperty('height');
14920
- // $div.removeClass('skeleton');
14921
- // $div.html(UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')]);
14922
- // } else {
14923
- hover_in($div);
14924
- ui_job_id = func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'render_viewport', { $div, nodeP, parent_infoP, $root_container, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, $container }, null, null, paramsP.dsSessionP);
14925
- // }
14926
- observer_outViewport.observe($div[0]);
14927
- });
14928
-
14929
- $div.on('outViewport', function () {
14930
- func.UI.worker.delete_job(SESSION_ID, ui_job_id);
14931
-
14932
- if ($div.children().length) {
14933
- // UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')] = $div.children().clone(true);
14934
- $div.empty();
14935
- const height = $div?.data()?.xuData?.viewport_height || 10;
14936
- if (typeof height !== 'undefined') {
14937
- $div.css('height', height);
14938
- }
14939
- }
14940
- // $div.addClass('skeleton');
14941
- observer_inViewport.observe($div[0]);
14942
- });
14943
- $div.addClass('skeleton');
14944
- observer_inViewport.observe($div[0]);
14945
- };
14946
- xu_viewport();
14947
- } else {
14948
- await iterate_child($div, nodeP, parent_infoP, $root_container);
14949
- }
14950
-
14951
- // const ret_iterate_child = await iterate_child($div, nodeP, parent_infoP, null, $root_container);
14952
- return await done(ret);
14953
- };
14954
-
14955
- const draw_html_element = async function (element) {
14956
- const done = async function (ret = {}) {
14957
- const xu_ui_id = $div.attr('xu-ui-id');
14958
- $div.removeClass('display_none');
14959
- if (ret.has_xu_exp_render_attribute) {
14960
- // $div.css('display', 'unset');
14961
-
14962
- const xu_render_cache_id = await get_xu_render_cache_str(SESSION_ID, paramsP.dsSessionP, Object.keys($div.data()?.xuData?.attr_exp_info?.['xu-render']?.fields || {}));
14963
- const _$div = $div.clone(true);
14964
- UI_WORKER_OBJ.xu_render_cache[xu_ui_id + xu_render_cache_id] = { $div: _$div, paramsP, data: _$div.data() };
14965
- nodeP.xu_render_xu_ui_id = xu_ui_id;
14966
- nodeP.xu_render_cache_id = xu_render_cache_id;
14967
-
14968
- if (ret.xu_render_background_processing) {
14969
- temp_$div.remove();
14970
- // $container.find(`[xu-ui-id="${xu_ui_id}"]`).remove();
14971
- return $div;
14972
- } else {
14973
- // $div.css('display', 'unset');
14974
- temp_$div.replaceWith($div);
14975
- return $div;
14976
- }
14977
- } else {
14978
- if (ret.has_xu_render_attribute) {
14979
- temp_$div.remove();
14980
- return $div;
14981
- }
14982
- // $div.css('display', 'unset');
14983
- temp_$div.replaceWith($div);
14984
- return $div;
14985
- }
14986
- };
14987
- if (!element || element === 'script') return await done();
14988
- let str = '';
14989
-
14990
- var temp_$div = await func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, null, null, element, null, str, true);
14991
-
14992
- let temp_$container = $('<tmp>').data('xuData', $container.data().xuData);
14993
- let $div = temp_$div.clone(true);
14994
-
14995
- // $div.css('display', 'none');
14996
-
14997
- $div.hover(
14998
- function (e) {
14999
- hover_in($div, e);
15000
- },
15001
- function (e) {
15002
- hover_out();
15003
- },
15004
- );
15005
- if (paramsP.paramsP === 'grid' || parent_infoP?.iterate_info) {
15006
- $div.on('click contextmenu', function (e) {
15007
- hover_in($div, e);
15008
- });
15009
- }
15010
-
15011
- let ret = await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, temp_$container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $div, true);
15012
- if (ret.abort || nodeP.tagName === 'svg' || !_.isEmpty(nodeP?.attributes?.['xu-text']) || !_.isEmpty(nodeP?.attributes?.['xu-html']) || !_.isEmpty(nodeP?.attributes?.['xu-exp:xu-text']) || !_.isEmpty(nodeP?.attributes?.['xu-exp:xu-html'])) {
15013
- return await done(ret);
15014
- }
15015
- // check if iterator made to prevent children render
15016
-
15017
- if (nodeP?.attributes?.['xu-viewport'] == 'true') {
15018
- // const xu_viewport = async function () {
15019
- // const data = { $div: $div.clone(true), nodeP, parent_infoP, $root_container, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, $container };
15020
- // const container_id = $container.attr('xu-ui-id');
15021
- // if (!UI_WORKER_OBJ.pending_for_viewport_render[container_id]) {
15022
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id] = { base_$div: $div, data: [], $container };
15023
- // await iterate_child($div, nodeP, parent_infoP, $root_container);
15024
- // } else {
15025
- // $div.remove();
15026
- // }
15027
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id].data.push(data);
15028
-
15029
- // // if (!$div.children().length) {
15030
- // // // render the first element to determine height
15031
- // // await iterate_child($div, nodeP, parent_infoP, $root_container);
15032
- // // // hover_in($div);
15033
- // // // func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'render_viewport', data, null, null, paramsP.dsSessionP);
15034
- // // } else {
15035
- // // }
15036
- // };
15037
- const xu_viewport = function () {
15038
- const observer_inViewport = new IntersectionObserver(
15039
- function (entries) {
15040
- entries.forEach((entry) => {
15041
- if (entry.isIntersecting) {
15042
- $(entry.target).trigger('inViewport');
15043
-
15044
- // Optional: stop observing once triggered
15045
- observer_inViewport.unobserve(entry.target);
15046
- }
15047
- });
15048
- },
15049
- {
15050
- threshold: 0.1, // Trigger when 10% of element is visible
15051
- },
15052
- );
15053
-
15054
- const observer_outViewport = new IntersectionObserver(
15055
- function (entries) {
15056
- entries.forEach((entry) => {
15057
- if (!entry.isIntersecting) {
15058
- // Element is OUT of viewport - trigger custom event
15059
- $(entry.target).trigger('outViewport');
15060
-
15061
- // Optional: stop observing once triggered
15062
- // observer_outViewport.unobserve(entry.target);
15063
- }
15064
- });
15065
- },
15066
- {
15067
- threshold: 0, // Trigger when element is completely out of view
15068
- },
15069
- );
15070
-
15071
- let ui_job_id;
15072
- $div.on('inViewport', function () {
15073
- if ($div.children().length) {
15074
- $div.removeClass('skeleton');
15075
- return;
15076
- }
15077
-
15078
- // if (UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')]) {
15079
- // $div[0].style.removeProperty('height');
15080
- // $div.removeClass('skeleton');
15081
- // $div.html(UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')]);
15082
- // } else {
15083
- hover_in($div);
15084
- ui_job_id = func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'render_viewport', { $div, nodeP, parent_infoP, $root_container, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, temp_$container }, null, null, paramsP.dsSessionP);
15085
- // }
15086
- observer_outViewport.observe($div[0]);
15087
- });
15088
-
15089
- $div.on('outViewport', function () {
15090
- func.UI.worker.delete_job(SESSION_ID, ui_job_id);
15091
-
15092
- if ($div.children().length) {
15093
- // UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')] = $div.children().clone(true);
15094
- $div.empty();
15095
- const height = $div?.data()?.xuData?.viewport_height || 10;
15096
- if (typeof height !== 'undefined') {
15097
- $div.css('height', height);
15098
- }
15099
- }
15100
- // $div.addClass('skeleton');
15101
- observer_inViewport.observe($div[0]);
15102
- });
15103
- $div.addClass('skeleton');
15104
- observer_inViewport.observe($div[0]);
15105
- };
15106
- xu_viewport();
15107
- } else {
15108
- // if (ret.xu_render_background_processing) {
15109
- // // let temp_$div = $div.clone(true);
15110
- // iterate_child($div, nodeP, parent_infoP, $root_container);
15111
- // } else {
15112
- // await iterate_child($div, nodeP, parent_infoP, $root_container);
15113
- // }
15114
- if (!ret.xu_render_background_processing) {
15115
- iterate_child($div, nodeP, parent_infoP, $root_container);
15116
- }
15117
- }
15118
-
15119
- // const ret_iterate_child = await iterate_child($div, nodeP, parent_infoP, null, $root_container);
15120
- return await done(ret);
15121
- };
15122
-
15123
- if (nodeP.content && nodeP.attributes) {
15124
- nodeP.attributes['xu-content'] = nodeP.content;
15125
- }
15126
-
15127
- if (nodeP.tagName === 'xu-widget') {
15128
- if (is_skeleton) return;
15129
- return await fx['widget']();
15130
- }
15131
- if (fx[nodeP.tagName]) {
15132
- return await fx[nodeP.tagName]();
15133
- }
15134
- // const xu_viewport = async function () {
15135
- // const data = { $div, nodeP, parent_infoP, $root_container, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, $container };
15136
- // const container_id = $container.attr('xu-ui-id');
15137
- // if (!UI_WORKER_OBJ.pending_for_viewport_render[container_id]) {
15138
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id] = { base_$div: $div, data: [], $container };
15139
- // await iterate_child($div, nodeP, parent_infoP, $root_container);
15140
- // }
15141
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id].data.push(data);
15142
- // };
15143
-
15144
- // if (nodeP?.attributes?.['xu-viewport'] == 'true') {
15145
- // return await xu_viewport();
15146
- // } else {
15147
- if (!glb.new_xu_render) {
15148
- return await draw_html_element_org(nodeP.tagName);
15149
- }
15150
- return await draw_html_element(nodeP.tagName);
15151
-
15152
- // }
15153
- };
15154
-
15155
- func.UI.screen.refresh_document_changes_for_realtime_update = async function (SESSION_ID, doc_change) {
15156
- let _session = SESSION_OBJ[SESSION_ID];
15157
- for (const [key, _ds] of Object.entries(_session.DS_GLB)) {
15158
- let prog_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
15159
- if (prog_obj?.progDataSource?.dataSourceRealtime && prog_obj?.progDataSource?.dataSourceTableId === doc_change.table_id) {
15160
- try {
15161
- // disabled in purpose to support create row
15162
-
15163
- if (!_ds.screen_params) continue;
15164
- if (_ds.screen_params.is_panelP) {
15165
- func.UI.screen.refresh_screen(SESSION_ID, null, key);
15166
- } else {
15167
- func.action.execute(SESSION_ID, 'act_refresh', _ds, null, null);
15168
- }
15169
- } catch (err) {
15170
- // console.error(err);
15171
- }
15172
- }
15173
- }
15174
-
15175
- if (glb.new_xu_render) {
15176
- for (const [ui_cache_key, ui_cache_val] of Object.entries(UI_WORKER_OBJ.xu_render_cache)) {
15177
- let prog_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, ui_cache_val.paramsP.prog_id);
15178
- if (prog_obj?.progDataSource?.dataSourceTableId === doc_change.table_id) {
15179
- ui_cache_val.$div = null;
15180
- }
15181
- }
15182
- }
15183
- };
15184
-
15185
- const get_parent_ds_fields = function (SESSION_ID, dsSessionP) {
15186
- var _session = SESSION_OBJ[SESSION_ID];
15187
- var _ds = _session.DS_GLB[dsSessionP];
15188
-
15189
- const idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
15190
- const data = _ds.data_feed.rows[idx];
15191
-
15192
- let obj = {};
15193
-
15194
- if (typeof _ds.parentDataSourceNo !== 'undefined') {
15195
- obj = get_parent_ds_fields(SESSION_ID, _ds.parentDataSourceNo);
15196
- }
15197
-
15198
- return { ...data, ...obj };
15199
- };
15200
-
15201
- const get_xu_render_cache_str = async function (SESSION_ID, dsSessionP, exclude_vars = []) {
15202
- const fields_obj = get_parent_ds_fields(SESSION_ID, dsSessionP);
15203
-
15204
- let str = '';
15205
-
15206
- for (const [key, val] of Object.entries(fields_obj)) {
15207
- if (exclude_vars.includes(key)) continue;
15208
- str += typeof val !== 'undefined' ? JSON.stringify(val) : '';
15209
- }
15210
-
15211
- return 'C-' + (await func.common.sha256(str));
15212
- };
15213
- func.UI.component = {};
13004
+ func.UI.component = {};
15214
13005
 
15215
13006
  func.UI.component.create_app_modal_component = function (
15216
13007
  SESSION_ID,