@xuda.io/runtime-bundle 1.0.1152 → 1.0.1153

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