@xuda.io/runtime-bundle 1.0.612 → 1.0.614

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.
@@ -31646,10 +31646,10 @@ func.UI.screen.refresh_xu_attributes = async function (SESSION_ID, fields_arr, j
31646
31646
  await iterate_field_in_progUi(progUi, field_id);
31647
31647
  }
31648
31648
  }
31649
- // run panels
31650
- for await (const [panel_wrapper_element_ui_id, panel_val] of Object.entries(panels_obj)) {
31651
- await iterate_field_in_progUi(panel_val.progUi, field_id);
31652
- }
31649
+ // // run panels
31650
+ // for await (const [panel_wrapper_element_ui_id, panel_val] of Object.entries(panels_obj)) {
31651
+ // await iterate_field_in_progUi(panel_val.progUi, field_id);
31652
+ // }
31653
31653
  }
31654
31654
 
31655
31655
  func.events.delete_job(SESSION_ID, jobNoP);
@@ -32902,7 +32902,1422 @@ func.UI.screen.set_attributes_new = async function (SESSION_ID, is_skeleton, $ro
32902
32902
  },
32903
32903
  props: {},
32904
32904
  },
32905
- ], func.UI.component = {};
32905
+ ],
32906
+ },
32907
+ ];
32908
+ delete nodeP.attributes[key];
32909
+ }
32910
+ }
32911
+
32912
+ for (let [key, val] of Object.entries(nodeP.attributes)) {
32913
+ // FIX STATIC DEFAULTS
32914
+ val = func.UI.screen.fix_val_defaults(key, val);
32915
+
32916
+ // REMOVE UNDEFINED or NULL ATTRIBUTES
32917
+ if (typeof val === 'undefined' || val === null) {
32918
+ delete nodeP.attributes[key];
32919
+ }
32920
+
32921
+ // REMOVE ATTRIBUTES WITH EMPTY VALUES
32922
+ if (glb.solid_attributes.includes(key) && !val) {
32923
+ delete nodeP.attributes[key];
32924
+ }
32925
+ }
32926
+
32927
+ // BEFORE
32928
+
32929
+ for await (const [key, attr] of Object.entries(glb.run_xu_before)) {
32930
+ if (_ret.abort) break;
32931
+ if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) {
32932
+ continue;
32933
+ }
32934
+
32935
+ if (!nodeP.attributes || !nodeP.attributes[attr] & !nodeP.attributes[`xu-exp:${attr}`]) {
32936
+ continue;
32937
+ }
32938
+
32939
+ let ret = await func.UI.screen.execute_xu_functions(
32940
+ SESSION_ID,
32941
+ is_skeleton,
32942
+ $root_container,
32943
+ nodeP,
32944
+ $container,
32945
+ paramsP,
32946
+ parent_infoP,
32947
+ jobNoP,
32948
+ keyP,
32949
+ parent_nodeP,
32950
+ attr,
32951
+ $elm,
32952
+ {
32953
+ key: attr,
32954
+ // value: _value,
32955
+ value: (await get_xuExp(attr)) || nodeP.attributes[attr],
32956
+ },
32957
+ is_init,
32958
+ );
32959
+ _ret = _.assignIn(_ret, ret);
32960
+ }
32961
+
32962
+ // ALL
32963
+
32964
+ for await (const [key, val] of Object.entries(nodeP.attributes)) {
32965
+ if (_ret.abort) break;
32966
+ if (glb.html5_events_handler.includes(key) || execute_attributes.includes(key)) {
32967
+ continue;
32968
+ }
32969
+
32970
+ const new_key = key.split(':')[0]; // break expression
32971
+ if (
32972
+ nodeP.tagName !== 'xu-panel' &&
32973
+ nodeP.tagName !== 'xu-teleport' && // nodeP.tagName.substr(0, 3) !== "xu-" &&
32974
+ (new_key.substr(0, 2) !== 'xu' || new_key.substr(2, 1) !== '-')
32975
+ ) {
32976
+ // handle common html attributes
32977
+ try {
32978
+ $elm.get(0).setAttribute(key, val);
32979
+ } catch (err) {
32980
+ console.error(err.message);
32981
+ }
32982
+
32983
+ continue;
32984
+ }
32985
+ // handle xu attributes
32986
+ try {
32987
+ $elm.data().xuAttributes[key] = val;
32988
+ } catch (error) {
32989
+ debugger;
32990
+ console.error(error);
32991
+ }
32992
+
32993
+ 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)) {
32994
+ continue;
32995
+ }
32996
+
32997
+ if (new_key === 'xu-on') {
32998
+ let ret = await func.UI.screen.execute_xu_functions(
32999
+ SESSION_ID,
33000
+ is_skeleton,
33001
+ $root_container,
33002
+ nodeP,
33003
+ $container,
33004
+ paramsP,
33005
+ parent_infoP,
33006
+ jobNoP,
33007
+ keyP,
33008
+ parent_nodeP,
33009
+ 'xu-on',
33010
+ $elm,
33011
+ {
33012
+ key: key,
33013
+ value: (await get_xuExp(new_key)) || val,
33014
+ },
33015
+ is_init,
33016
+ refreshed_ds,
33017
+ );
33018
+ _ret = _.assignIn(_ret, ret);
33019
+ continue;
33020
+ }
33021
+
33022
+ let ret = await func.UI.screen.execute_xu_functions(
33023
+ SESSION_ID,
33024
+ is_skeleton,
33025
+ $root_container,
33026
+ nodeP,
33027
+ $container,
33028
+ paramsP,
33029
+ parent_infoP,
33030
+ jobNoP,
33031
+ keyP,
33032
+ parent_nodeP,
33033
+ new_key,
33034
+ $elm,
33035
+ {
33036
+ key: key,
33037
+ value: (await get_xuExp(new_key)) || val,
33038
+ },
33039
+ is_init,
33040
+ refreshed_ds,
33041
+ );
33042
+
33043
+ _ret = _.assignIn(_ret, ret);
33044
+ }
33045
+
33046
+ // EXP for
33047
+
33048
+ for await (const [key, val] of Object.entries(nodeP.attributes)) {
33049
+ if (_ret.abort) break;
33050
+
33051
+ const attr = key.split('xu-exp:')[1];
33052
+
33053
+ if (!attr) {
33054
+ continue;
33055
+ }
33056
+
33057
+ if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) continue;
33058
+
33059
+ if (done_exp.includes(key)) {
33060
+ continue;
33061
+ }
33062
+ let ret = await func.UI.screen.execute_xu_functions(
33063
+ SESSION_ID,
33064
+ is_skeleton,
33065
+ $root_container,
33066
+ nodeP,
33067
+ $container,
33068
+ paramsP,
33069
+ parent_infoP,
33070
+ jobNoP,
33071
+ keyP,
33072
+ parent_nodeP,
33073
+ 'xu-exp',
33074
+ $elm,
33075
+ {
33076
+ key: attr,
33077
+ value: val,
33078
+ },
33079
+ true,
33080
+ refreshed_ds,
33081
+ );
33082
+ _ret = _.assignIn(_ret, ret);
33083
+ }
33084
+
33085
+ // AFTER
33086
+
33087
+ for await (const [key, attr] of Object.entries(glb.run_xu_after)) {
33088
+ if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) continue;
33089
+
33090
+ if (!nodeP.attributes || !nodeP.attributes[attr] & !nodeP.attributes[`xu-exp:${attr}`]) continue;
33091
+
33092
+ let ret = await func.UI.screen.execute_xu_functions(
33093
+ SESSION_ID,
33094
+ is_skeleton,
33095
+ $root_container,
33096
+ nodeP,
33097
+ $container,
33098
+ paramsP,
33099
+ parent_infoP,
33100
+ jobNoP,
33101
+ keyP,
33102
+ parent_nodeP,
33103
+ attr,
33104
+ $elm,
33105
+ {
33106
+ key: attr,
33107
+ value: (await get_xuExp(attr)) || nodeP.attributes[attr],
33108
+ },
33109
+ is_init,
33110
+ refreshed_ds,
33111
+ );
33112
+ _ret = _.assignIn(_ret, ret);
33113
+ }
33114
+
33115
+ // REGISTER EVENTS ATTRIBUTES
33116
+
33117
+ for await (const [key, val] of Object.entries(nodeP.attributes)) {
33118
+ if (!glb.html5_events_handler.includes(key)) break;
33119
+ $elm.attr(key, await get_xuExp(key)) || val;
33120
+ }
33121
+
33122
+ return _ret;
33123
+ };
33124
+
33125
+ func.UI.screen.panel_post_render_handler = async function (
33126
+ SESSION_ID,
33127
+ $container, // the parent program container
33128
+ $wrapper, // the wrapper element contains the rendered panel elements e.g: xu-single-view
33129
+ nodeP, // the xu-panel node
33130
+ $panel_div, // the panel div
33131
+ jobNoP,
33132
+ ) {
33133
+ const _container_ds = SESSION_OBJ[SESSION_ID].DS_GLB[$container.data().xuData.paramsP.dsSessionP];
33134
+ const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[$wrapper.data().xuData.paramsP.dsSessionP];
33135
+ const find_old_panels_elements = function () {
33136
+ return func.UI.utils.find_in_element_data('xuPanelData', $container.parent(), 'xu-ui-id', $container.data()?.xuPanelData?.xu_panel_xu_ui_id);
33137
+ };
33138
+ var $old_panel_div = find_old_panels_elements();
33139
+ const set_xuPanelData_to_the_new_rendered_items = () => {
33140
+ $container.data().xuPanelWrapper = { isWrapper: true, panelXuAttributes: _.clone($wrapper.data().xuAttributes), panelDivData: _.clone($wrapper.data()) };
33141
+ $container.attr('xu-panel-wrapper-id', $wrapper.attr('xu-ui-id'));
33142
+ $.each($wrapper.children(), function (key, val) {
33143
+ if (!$(val).data().xuPanelData) {
33144
+ $(val).data().xuPanelData = {};
33145
+ }
33146
+ $(val).data().xuPanelData.parent_element_ui_id = $old_panel_div?.length ? $container.parent().data().xuData.ui_id : $container.data().xuData.ui_id;
33147
+
33148
+ $(val).data().xuPanelData.xu_panel_xu_ui_id = (nodeP.xu_tree_id || nodeP.id) + '-' + _container_ds?.currentRecordId;
33149
+ $(val).data().xuPanelData.node = nodeP;
33150
+ $(val).data().xuPanelData.$panel_div = $panel_div.clone(true);
33151
+ });
33152
+ };
33153
+ set_xuPanelData_to_the_new_rendered_items();
33154
+
33155
+ if ($old_panel_div?.length) {
33156
+ $($old_panel_div[0]).after($wrapper.children());
33157
+ } else {
33158
+ $.each($wrapper.children(), function (key, child) {
33159
+ $.each($container.children(), function (key, elm) {
33160
+ if ($(elm)?.data()?.xuData && $(elm)?.data()?.xuData?.elem_key === $(child)?.data()?.xuData?.elem_key) {
33161
+ $(elm).remove();
33162
+ }
33163
+ });
33164
+ $container.append($(child));
33165
+ });
33166
+ }
33167
+
33168
+ if (!$wrapper.data()?.xuData?.dsSession) return;
33169
+
33170
+ if ($old_panel_div?.length) {
33171
+ $container.parent().data().xuData.paramsP.dsSessionP = _ds.parentDataSourceNo; // set the new ds when panel replaced
33172
+ } else {
33173
+ $container.data().xuData.paramsP.dsSessionP = _ds.parentDataSourceNo; // set the new ds when panel replaced
33174
+ }
33175
+
33176
+ if ($old_panel_div?.length) {
33177
+ $old_panel_div.remove();
33178
+ }
33179
+ return jobNoP;
33180
+ };
33181
+
33182
+ func.UI.screen.create_container = function (SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, classP, elem_propP, div_typeP, $appendToP, attr_str) {
33183
+ const _paramsP = _.cloneDeep(paramsP);
33184
+ var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
33185
+ var $appendTo = $container;
33186
+ if ($appendToP) $appendTo = $appendToP;
33187
+ if (!$appendTo || !$appendTo.length) return null; // screen closed or not exist abort build
33188
+ var div = 'div';
33189
+ if (div_typeP) div = div_typeP;
33190
+ var items = [];
33191
+ if (nodeP.children)
33192
+ items = nodeP.children.map(function (val) {
33193
+ return val.xu_tree_id || val.id;
33194
+ });
33195
+ var currentRecordId = _ds ? _ds.currentRecordId : '';
33196
+ var xu_id = (glb.screen_num++).toString();
33197
+ xu_id = xu_id += '_' + currentRecordId;
33198
+
33199
+ try {
33200
+ const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
33201
+ const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
33202
+ let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
33203
+
33204
+ /////////////////////////////////
33205
+
33206
+ var $div;
33207
+ if (div === 'svg') {
33208
+ const draw_svg = function (element) {
33209
+ const get_tag_str = function (element, prop, val) {
33210
+ let class_str = '';
33211
+ let attr_str = '';
33212
+ for (const [key, val] of Object.entries(prop)) {
33213
+ if (key.substr(0, 2) !== 'xu') {
33214
+ attr_str += ` ${key}="${val}" `;
33215
+ }
33216
+ }
33217
+ if (element === 'svg') {
33218
+ return `<${element} ${attr_str} > `;
33219
+ }
33220
+ let ret = '';
33221
+ if (val?.children?.length) {
33222
+ ret = iterate_svg(val);
33223
+ }
33224
+
33225
+ return `<${element} ${class_str} ${attr_str} > ${ret} </${element}>`;
33226
+ };
33227
+ let svg_str = get_tag_str(element, prop);
33228
+ let inner_str = '';
33229
+ const iterate_svg = function (node) {
33230
+ let ret = '';
33231
+ if (node.children) {
33232
+ for (let val of node.children) {
33233
+ let prop = val.attributes;
33234
+ ret += get_tag_str(val.tagName, prop, val);
33235
+ }
33236
+ }
33237
+ return ret;
33238
+ };
33239
+ inner_str = iterate_svg(nodeP);
33240
+
33241
+ $div = $(svg_str + inner_str + '</svg>').appendTo($appendTo);
33242
+ };
33243
+
33244
+ draw_svg(div_typeP);
33245
+ } else {
33246
+ $div = $(`<${div} ${attr_str ? attr_str : ''}>`);
33247
+ }
33248
+ // const svgNS = "http://www.w3.org/2000/svg";
33249
+ // // $div = $(document.createElementNS(svgNS, "svg"));
33250
+ // $div = $(`<${div} ${attr_str ? attr_str : ""} ${svg_attributes_str}>`);
33251
+ // } else {
33252
+ // $div = $(`<${div} ${attr_str ? attr_str : ""}>`);
33253
+ $div.attr('xu-ui-id', ui_id).data({
33254
+ xuData: {
33255
+ prog_id: _paramsP.prog_id,
33256
+ nodeid: nodeP.id,
33257
+ ui_type: nodeP.tagName,
33258
+ xu_id,
33259
+ recordid: currentRecordId,
33260
+ paramsP: _paramsP,
33261
+ key: keyP,
33262
+ key_path, //:($container?.data()?.xuData?.key || "0") + "-" + (keyP || "0"),
33263
+ screenId: _paramsP.screenId,
33264
+ parent_container: $container?.attr('id'),
33265
+ elem_key,
33266
+ properties: prop,
33267
+ node: nodeP,
33268
+ node_org: _.cloneDeep(nodeP),
33269
+ is_panelP: _paramsP.is_panelP,
33270
+ ui_id,
33271
+ elem_prop: elem_propP,
33272
+ debug_info: {
33273
+ id: nodeP.id,
33274
+ parent_id: $container?.data()?.xuData?.ui_id,
33275
+ items: items,
33276
+ },
33277
+ parent_node: parent_nodeP,
33278
+ currentRecordId: currentRecordId,
33279
+ $root_container: $root_container,
33280
+ parent_element_ui_id: $container?.data()?.xuData?.ui_id,
33281
+ },
33282
+ xuAttributes: {},
33283
+ });
33284
+
33285
+ if (div_typeP !== 'svg') {
33286
+ $div.appendTo($appendTo);
33287
+ }
33288
+ } catch (e) {
33289
+ console.error(e);
33290
+ }
33291
+
33292
+ if (parent_infoP?.iterate_info) {
33293
+ $div.data().xuData.iterate_info = parent_infoP.iterate_info;
33294
+ }
33295
+
33296
+ if (classP) $div.addClass(classP);
33297
+
33298
+ return $div;
33299
+ };
33300
+ func.UI.screen.execute_screen_ready_events = async function (SESSION_ID, paramsP, sourceP, $div, jobNoP, $div_objP) {
33301
+ var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
33302
+ if (!_ds) return;
33303
+ var viewEventExec_arr = [];
33304
+ const execute_view_events = async function (sourceP) {
33305
+ for await (const val of viewEventExec_arr) {
33306
+ cond = val.eventInfo.data.enabled;
33307
+ if (val.expression) {
33308
+ expCond = await func.expression.get(SESSION_ID, val.expression, paramsP.dsSessionP, 'condition', paramsP.rowIdP); // execute expression
33309
+ cond = expCond.result;
33310
+ }
33311
+ if (cond) {
33312
+ await func.events.execute(
33313
+ SESSION_ID,
33314
+ null,
33315
+ val.eventId,
33316
+ val.triggerId,
33317
+ val.eventInfo.data.action,
33318
+ val.eventInfo.data.name,
33319
+ null,
33320
+ null,
33321
+ null,
33322
+ null,
33323
+ val.eventInfo.data.action, //val.eventInfo[4]
33324
+ null,
33325
+ paramsP.dsSessionP,
33326
+ val.eventId,
33327
+ sourceP + ' event',
33328
+ true,
33329
+ null,
33330
+ null,
33331
+ paramsP.dsSessionP,
33332
+ null,
33333
+ null,
33334
+ val.eventInfo, // val.eventInfo[8],
33335
+ null,
33336
+ null,
33337
+ null,
33338
+ _ds.prog_id,
33339
+ _ds.nodeId,
33340
+ _ds.parentDataSourceNo,
33341
+ $div,
33342
+ );
33343
+
33344
+ // update changed values to screen added 18/09/13
33345
+ var fields_to_refresh = [];
33346
+ try {
33347
+ var current_record_id = _ds.currentRecordId;
33348
+ } catch (e) {
33349
+ console.error(e);
33350
+ }
33351
+
33352
+ if (_ds?.data_feed?.form_fields_changed?.[current_record_id]) {
33353
+ $.each(_ds.data_feed.form_fields_changed[current_record_id], function (key, val) {
33354
+ fields_to_refresh.push(key);
33355
+ });
33356
+
33357
+ var containerId = _ds.containerId;
33358
+ var $container = $('#' + containerId);
33359
+ if ($container?.data()?.xuData?.is_mobile_modal || $container?.data()?.xuData?.params?.is_mobile_page) {
33360
+ await func.UI.screen.refresh_container(SESSION_ID, 'init', fields_to_refresh, $container, paramsP.dsSessionP, null);
33361
+ } else {
33362
+ $container.trigger(containerId + '.refresh', ['init', fields_to_refresh]);
33363
+ }
33364
+
33365
+ if ($div_objP) {
33366
+ await func.UI.screen.refresh_container(SESSION_ID, 'init', fields_to_refresh, $div_objP, paramsP.dsSessionP, null);
33367
+ }
33368
+ }
33369
+ }
33370
+ continue;
33371
+ }
33372
+ };
33373
+ const get_view_events_count = async function (typeP) {
33374
+ const _prog = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
33375
+ viewEventExec_arr = [];
33376
+
33377
+ if (!_prog.progEvents || _.isEmpty(_prog.progEvents)) {
33378
+ return 0;
33379
+ }
33380
+ for await (const event_obj of _prog.progEvents) {
33381
+ if (event_obj.data.type !== typeP) continue;
33382
+
33383
+ if (_.isEmpty(event_obj.triggers)) continue;
33384
+
33385
+ if (event_obj.data.condition) {
33386
+ let res = await func.expression.get(SESSION_ID, event_obj.data.condition, paramsP.dsSessionP, 'condition', paramsP.rowIdP, null, null, null, null, event_obj);
33387
+ if (!res.result) {
33388
+ continue;
33389
+ }
33390
+ }
33391
+
33392
+ for await (const trigger_obj of event_obj.triggers) {
33393
+ var expression = undefined;
33394
+ var cond = undefined;
33395
+ if (!trigger_obj.data.enabled) {
33396
+ continue;
33397
+ }
33398
+ cond = true;
33399
+ if (trigger_obj.props.condition) expression = trigger_obj.props.condition;
33400
+ var expCond = {};
33401
+ if (expression) {
33402
+ expCond = await func.expression.get(SESSION_ID, expression, paramsP.dsSessionP, 'condition', paramsP.rowIdP, trigger_obj.data.type); // execute expression
33403
+ cond = expCond.result;
33404
+ expCond.conditional = true;
33405
+ }
33406
+
33407
+ if (!trigger_obj.data.action) {
33408
+ func.utils.debug_report(SESSION_ID, 'get_view_events_count', `Error initiating ${typeP} prog: ${_ds.viewSourceDesc} reason: missing action`, 'E');
33409
+ break;
33410
+ }
33411
+ if (!glb.REFERENCE_LESS_FUNCTIONS.includes(trigger_obj.data.action) && !trigger_obj.data.name?.prog) {
33412
+ func.utils.debug_report(SESSION_ID, 'get_view_events_count', `Error initiating ${typeP} prog: ${_ds.viewSourceDesc} reason: missing reference`, 'E');
33413
+ break;
33414
+ }
33415
+
33416
+ viewEventExec_arr.push({
33417
+ eventInfo: trigger_obj,
33418
+ eventId: event_obj.id,
33419
+ triggerId: trigger_obj.id,
33420
+ expression: expression,
33421
+ });
33422
+ }
33423
+ }
33424
+ return viewEventExec_arr.length;
33425
+ };
33426
+
33427
+ let count = await get_view_events_count('screen_ready');
33428
+ if (!count) return;
33429
+ return await execute_view_events(sourceP);
33430
+ };
33431
+ func.UI.screen.screen_loading_done = async function (SESSION_ID, paramsP, $div, jobNoP) {
33432
+ // await
33433
+ func.UI.screen.execute_screen_ready_events(SESSION_ID, paramsP, paramsP.screenInfo.properties?.renderType, $div, jobNoP);
33434
+ var _session = SESSION_OBJ[SESSION_ID];
33435
+ func.events.delete_job(SESSION_ID, jobNoP);
33436
+ func.UI.utils.screen_blocker(false, paramsP.prog_id + (paramsP.sourceScreenP ? '_' + paramsP.sourceScreenP : ''));
33437
+ if (_session.prog_id === paramsP.prog_id) {
33438
+ _session.system_ready = true;
33439
+ if (_session.engine_mode === 'live_preview' && STUDIO_PEER_CONN_SEND_METHOD) {
33440
+ STUDIO_PEER_CONN_SEND_METHOD({
33441
+ service: 'system_ready',
33442
+ data: {},
33443
+ id: STUDIO_PEER.id,
33444
+ source: 'runtime',
33445
+ session_id: SESSION_ID,
33446
+ app_id: _session.app_id,
33447
+ gtp_token: _session.gtp_token,
33448
+ app_token: _session.app_token,
33449
+ });
33450
+ // }
33451
+ }
33452
+ }
33453
+
33454
+ return $div;
33455
+ };
33456
+
33457
+ 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) {
33458
+ if (!is_skeleton) {
33459
+ var _session = SESSION_OBJ[SESSION_ID];
33460
+ var _ds = _session.DS_GLB[paramsP.dsSessionP];
33461
+ }
33462
+ var prop;
33463
+ try {
33464
+ prop = nodeP.attributes;
33465
+ } catch (error) {
33466
+ // debugger;
33467
+ }
33468
+
33469
+ var is_mobile = glb.MOBILE_ARR.includes(paramsP.screenInfo.properties?.menuType) ? true : false;
33470
+
33471
+ var get_element_info = function () {
33472
+ var ret = {};
33473
+ let currentRecordId = _ds?.currentRecordId || '';
33474
+
33475
+ let $div = func.UI.utils.find_in_element_data('xuData', $container.parent(), 'nodeid', nodeP.id);
33476
+
33477
+ $.each($div, function (key, val) {
33478
+ if ($(val)?.data().xuData?.recordid === currentRecordId && $(val)?.data().xuData?.key === keyP && $(val)?.prop('tagName') !== 'XURENDER') {
33479
+ ret = {
33480
+ div: $div,
33481
+ };
33482
+ }
33483
+ });
33484
+
33485
+ return ret;
33486
+ };
33487
+
33488
+ const init = async function () {
33489
+ var ret = true;
33490
+ if (!nodeP) ret = false;
33491
+ return ret;
33492
+ };
33493
+ const debug = function (is_errorP, error_descP) {
33494
+ func.utils.debug.log(SESSION_ID, paramsP.prog_id + '_' + nodeP.id_org + '_ui_prop', {
33495
+ module: 'gui',
33496
+ action: 'init',
33497
+ prop: nodeP.id,
33498
+ details: error_descP,
33499
+ result: null,
33500
+ error: is_errorP,
33501
+ source: _ds?.tree_obj?.menuName || '',
33502
+ fields: null,
33503
+ type: null,
33504
+ prog_id: paramsP.prog_id,
33505
+ dsSession: null,
33506
+ });
33507
+ };
33508
+
33509
+ const open_modal = async function ($div) {
33510
+ const modal_id = 'app_modal-' + paramsP.dsSessionP.toString();
33511
+ var xu_modal_controller = document.querySelector('xu-modal-controller');
33512
+ if (!xu_modal_controller) {
33513
+ func.UI.component.create_app_modal_component(SESSION_ID, modal_id);
33514
+ xu_modal_controller = document.querySelector('xu-modal-controller');
33515
+ }
33516
+
33517
+ var controller_params = $(xu_modal_controller).data('xuControllerParams');
33518
+
33519
+ if (!controller_params) {
33520
+ controller_params = {};
33521
+ }
33522
+
33523
+ var params = {
33524
+ menuTitle: paramsP.screenInfo.properties?.menuTitle,
33525
+ screenId: paramsP.screenId,
33526
+ $dialogDiv: $div.children(),
33527
+ $container: $container,
33528
+ dsSession: paramsP.dsSessionP,
33529
+ };
33530
+
33531
+ controller_params[modal_id] = params;
33532
+
33533
+ $(xu_modal_controller).data('xuControllerParams', controller_params);
33534
+ const modalController = await new UI_FRAMEWORK_PLUGIN.modal();
33535
+
33536
+ if (!APP_MODAL_OBJ[modal_id]) {
33537
+ const modal = await modalController.create(SESSION_ID, modal_id, paramsP.screenInfo, close_modal);
33538
+ APP_MODAL_OBJ[modal_id] = modal;
33539
+ } else {
33540
+ $(modal_id).empty();
33541
+ }
33542
+ await modalController.init(SESSION_ID, modal_id);
33543
+
33544
+ return $div;
33545
+ };
33546
+
33547
+ const close_modal = async function (modal_id) {
33548
+ delete APP_MODAL_OBJ[modal_id];
33549
+ const xu_modal_controller = document.querySelector('xu-modal-controller');
33550
+ var params = $(xu_modal_controller).data().xuControllerParams[modal_id];
33551
+ if (params && params.$container) {
33552
+ await func.UI.screen.validate_exit_events(SESSION_ID, params.$container.data().xuData.paramsP, null);
33553
+ func.datasource.clean_all(SESSION_ID, params.dsSession);
33554
+ }
33555
+ };
33556
+
33557
+ const close_all_modals = function () {
33558
+ $.each(APP_MODAL_OBJ, function (key, val) {
33559
+ if (val) {
33560
+ // close_modal(key);
33561
+ UI_FRAMEWORK_PLUGIN.modal.close(key);
33562
+ }
33563
+ });
33564
+ };
33565
+
33566
+ const open_popover = async function ($div) {
33567
+ const xu_popover_controller = func.UI.component.create_app_popover_component(SESSION_ID);
33568
+
33569
+ $(xu_popover_controller).data('xuControllerParams', {
33570
+ menuTitle: paramsP.screenInfo.properties?.menuTitle,
33571
+ screenId: paramsP.screenId,
33572
+ $dialogDiv: $div.children(),
33573
+ $container: $container,
33574
+ });
33575
+ const popover = new UI_FRAMEWORK_PLUGIN.popover(
33576
+ SESSION_ID,
33577
+ // ELEMENT_CLICK_EVENT,
33578
+ // props
33579
+ );
33580
+ await popover.open(SESSION_ID);
33581
+ CURRENT_APP_POPOVER = popover;
33582
+
33583
+ return;
33584
+ popoverController
33585
+ .create({
33586
+ component: 'xu-popover-content-' + SESSION_ID,
33587
+ event: ELEMENT_CLICK_EVENT,
33588
+ translucent: true,
33589
+ })
33590
+ .then((modal) => {
33591
+ modal.present().then(() => {
33592
+ CURRENT_APP_POPOVER = modal;
33593
+
33594
+ if (callbackP) callbackP($div);
33595
+ });
33596
+ });
33597
+ };
33598
+ const iterate_child = async function ($divP, nodeP, parent_infoP, countP, $root_container, before_record_function) {
33599
+ if (!is_mobile && nodeP.busy) return;
33600
+ nodeP.busy = true;
33601
+ const done = async function ($divP) {
33602
+ setTimeout(function () {
33603
+ nodeP.busy = false;
33604
+ }, 1000);
33605
+
33606
+ return $divP;
33607
+ };
33608
+ if (!nodeP || !nodeP.children) {
33609
+ return await done($divP);
33610
+ }
33611
+
33612
+ if (before_record_function) {
33613
+ await before_record_function();
33614
+ }
33615
+ if (nodeP?.children?.length) {
33616
+ for await (const [key, val] of Object.entries(nodeP.children)) {
33617
+ 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);
33618
+ }
33619
+ }
33620
+ return await done($divP);
33621
+ };
33622
+
33623
+ const _$ = function ($elm) {
33624
+ try {
33625
+ const id = $elm.attr('xu-ui-id');
33626
+ if (!id) return $elm;
33627
+ const $el = $(`[xu-ui-id="${id}"]`); // $("#" + id);
33628
+
33629
+ if ($el.length > 1) {
33630
+ console.warn('Multiple elements for xu-ui-id: ' + id, $el);
33631
+ }
33632
+
33633
+ return $($el[0]);
33634
+ } catch (e) {
33635
+ console.error(e);
33636
+ }
33637
+ };
33638
+
33639
+ const hover_in = function ($div) {
33640
+ if (is_skeleton) return;
33641
+ CLIENT_ACTIVITY_TS = Date.now();
33642
+ if (_$($container)?.data()?.xuData?.debug_info) _$($container).data().xuData.debug_info.hover_item = $div.attr('xu-ui-id');
33643
+ if (!_ds) return;
33644
+ ///////// SET Attributes///////////
33645
+ let attributes = {};
33646
+ $.each($div[0].attributes, function (index, attr) {
33647
+ attributes[attr.name] = attr.value;
33648
+ });
33649
+
33650
+ SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_OBJ_WIN_ELEMENT_HOVERED_ATTRIBUTES = attributes;
33651
+ //////////////////////////////////
33652
+ if (!$div.data()?.xuData) return;
33653
+ const _iterate_info = $div.data().xuData.iterate_info;
33654
+ if (_iterate_info) {
33655
+ if (_iterate_info.is_key_dynamic_field) {
33656
+ _ds.dynamic_fields[_iterate_info.iterator_key].value = _iterate_info._key;
33657
+ } else {
33658
+ try {
33659
+ const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
33660
+ _ds.data_feed.rows[row_idx][_iterate_info.iterator_key] = _iterate_info._key;
33661
+ } catch (err) {
33662
+ console.error(err);
33663
+ }
33664
+ }
33665
+
33666
+ if (_iterate_info.is_val_dynamic_field) {
33667
+ _ds.dynamic_fields[_iterate_info.iterator_val].value = _iterate_info._val;
33668
+ } else {
33669
+ try {
33670
+ const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
33671
+ _ds.data_feed.rows[row_idx][_iterate_info.iterator_val] = _iterate_info._val;
33672
+ } catch (err) {
33673
+ console.error(err);
33674
+ }
33675
+ }
33676
+ }
33677
+
33678
+ if ($div && _$($div) && _ds && paramsP.renderType === 'grid') {
33679
+ func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'update_datasource', { currentRecordId: _$($div).data().xuData.currentRecordId }, null, null, paramsP.dsSessionP);
33680
+ }
33681
+
33682
+ const set_value = function (field_id, value) {
33683
+ var currentRecordId = _$($div).data().xuData.currentRecordId;
33684
+
33685
+ func.UI.worker.add_to_queue(
33686
+ SESSION_ID,
33687
+ 'gui event',
33688
+ 'update_datasource',
33689
+ {
33690
+ currentRecordId,
33691
+ field_id,
33692
+ field_value: value,
33693
+ },
33694
+ null,
33695
+ null,
33696
+ paramsP.dsSessionP,
33697
+ );
33698
+ };
33699
+
33700
+ if ($div?.data()?.iterate_info) {
33701
+ var data = $div.data().xuData.iterate_info;
33702
+ if (data.iterator_key) {
33703
+ set_value(data.iterator_key, data._key);
33704
+ }
33705
+ if (data.iterator_val) {
33706
+ set_value(data.iterator_val, data._val);
33707
+ }
33708
+ }
33709
+ };
33710
+ const hover_out = function () {
33711
+ if (is_skeleton) return;
33712
+
33713
+ CLIENT_ACTIVITY_TS = Date.now();
33714
+ if (_$($container)?.data()?.xuData?.debug_info) {
33715
+ _$($container).data().xuData.debug_info.hover_item = null;
33716
+ }
33717
+ if (_ds?.data_system) {
33718
+ SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_OBJ_WIN_ELEMENT_HOVERED_ATTRIBUTES = {};
33719
+ }
33720
+ };
33721
+ const render_screen_type = async function ($div) {
33722
+ const set_call_screen_properties_values = async function (ui_framework) {
33723
+ params.properties = {};
33724
+ const get_values = async function (property) {
33725
+ var property_value = paramsP?.screenInfo?.properties?.[property] || paramsP?.screenInfo?.properties?.frameworkProperties?.[property];
33726
+ if (paramsP?.call_screen_propertiesP) {
33727
+ if (paramsP.call_screen_propertiesP?.[property]) {
33728
+ property_value = paramsP.call_screen_propertiesP[property];
33729
+ }
33730
+ if (paramsP.call_screen_propertiesP[`xu-exp:${property}`]) {
33731
+ property_value = (await func.expression.get(SESSION_ID, paramsP.call_screen_propertiesP[`xu-exp:${property}`], paramsP.dsSessionP, property)).result;
33732
+ }
33733
+ }
33734
+ return property_value;
33735
+ };
33736
+ params.properties['name'] = await get_values('menuTitle');
33737
+ if (await ui_framework?.properties()) {
33738
+ for await (const [key, val] of Object.entries(await ui_framework.properties())) {
33739
+ params.properties[key] = await get_values(key);
33740
+ }
33741
+ }
33742
+ };
33743
+
33744
+ var $div_content = $div.children();
33745
+
33746
+ $.each($div_content, function (key, val) {
33747
+ if (!$(val)?.data()?.xuData?.parent_container) {
33748
+ return true;
33749
+ }
33750
+ $(val).data().xuData.parent_container = $div.data().xuData.parent_container;
33751
+ });
33752
+
33753
+ let $ret = $div;
33754
+ var $nav = $(SESSION_OBJ[SESSION_ID].root_element).find('xu-nav');
33755
+ var params;
33756
+ switch (paramsP.screen_type) {
33757
+ case 'modal':
33758
+ const modal_id = 'app_modal-' + paramsP.dsSessionP.toString();
33759
+ var xu_modal_controller = document.querySelector('xu-modal-controller');
33760
+ if (!xu_modal_controller) {
33761
+ func.UI.component.create_app_modal_component(SESSION_ID, modal_id);
33762
+ xu_modal_controller = document.querySelector('xu-modal-controller');
33763
+ }
33764
+
33765
+ var controller_params = $(xu_modal_controller).data('xuControllerParams');
33766
+
33767
+ if (!controller_params) {
33768
+ controller_params = {};
33769
+ }
33770
+
33771
+ params = {
33772
+ screenId: paramsP.screenId,
33773
+ $dialogDiv: $div.children(),
33774
+ $container: $container,
33775
+ dsSession: paramsP.dsSessionP,
33776
+ modal_id,
33777
+ screenInfo: paramsP.screenInfo,
33778
+ close_callback: close_modal,
33779
+ paramsP,
33780
+ };
33781
+
33782
+ controller_params[modal_id] = params;
33783
+
33784
+ $(xu_modal_controller).data('xuControllerParams', controller_params);
33785
+ const modalController = await new UI_FRAMEWORK_PLUGIN.modal();
33786
+ await set_call_screen_properties_values(modalController);
33787
+ if (!APP_MODAL_OBJ[modal_id]) {
33788
+ const modal = await modalController.create(params);
33789
+
33790
+ APP_MODAL_OBJ[modal_id] = modal;
33791
+ } else {
33792
+ $(modal_id).empty();
33793
+ }
33794
+
33795
+ await modalController.init(params);
33796
+
33797
+ break;
33798
+
33799
+ case 'popover':
33800
+ // open_popover($div);
33801
+
33802
+ const xu_popover_controller = func.UI.component.create_app_popover_component(SESSION_ID);
33803
+ params = {
33804
+ menuTitle: paramsP.screenInfo.properties?.menuTitle,
33805
+ screenId: paramsP.screenId,
33806
+ $dialogDiv: $div.children(),
33807
+ $container: $container,
33808
+ };
33809
+
33810
+ $(xu_popover_controller).data('xuControllerParams', params);
33811
+ const popover = new UI_FRAMEWORK_PLUGIN.popover(SESSION_ID);
33812
+ await set_call_screen_properties_values(popover);
33813
+ await popover.open(params);
33814
+ CURRENT_APP_POPOVER = popover;
33815
+
33816
+ func.UI.utils.screen_blocker(false, paramsP.prog_id + '_' + paramsP.sourceScreenP);
33817
+ break;
33818
+
33819
+ case 'page':
33820
+ const nav = $nav[0];
33821
+
33822
+ params = {
33823
+ div: $div_content,
33824
+ name: paramsP.screenInfo.properties?.menuTitle,
33825
+ screenId: paramsP.screenId,
33826
+ $container: $container,
33827
+ dsSession: paramsP.dsSessionP,
33828
+ SESSION_ID,
33829
+ nav,
33830
+ paramsP,
33831
+ };
33832
+
33833
+ var component_name = 'xu-page-component-' + paramsP.dsSessionP;
33834
+ if (!$(nav).data().xuData.nav_params) {
33835
+ $(nav).data().xuData.nav_params = {};
33836
+ }
33837
+
33838
+ //restore validate
33839
+ if ($(nav)?.data()?.xuData?.params?.[paramsP.dsSessionP]) {
33840
+ params.$container.data().xuData.validate_screen_ready = $(nav).data().xuData.params[paramsP.dsSessionP].$container.data().xuData.validate_screen_ready;
33841
+ }
33842
+
33843
+ if (!$(nav)?.data()?.xuData) return;
33844
+ $(nav).data().xuData.nav_params[paramsP.dsSessionP] = params;
33845
+ if (!$(component_name).length) {
33846
+ await func.UI.component.create_app_page_component(SESSION_ID, paramsP.dsSessionP);
33847
+ const page = new UI_FRAMEWORK_PLUGIN.page();
33848
+ await set_call_screen_properties_values(page);
33849
+ await page.create(params);
33850
+ await page.init(params);
33851
+ nav.push(component_name, { params });
33852
+ } else {
33853
+ debugger;
33854
+ $(component_name).empty();
33855
+
33856
+ await UI_FRAMEWORK_PLUGIN.page(SESSION_ID, paramsP.dsSessionP);
33857
+ }
33858
+ $div.data().xuData.paramsP = $container.data().xuData.paramsP;
33859
+ break;
33860
+
33861
+ case 'panel':
33862
+ $container.append($div_content);
33863
+ $ret = $container;
33864
+ break;
33865
+
33866
+ default: // set data to nav to use in the component
33867
+ if ($nav && $nav.length) {
33868
+ // refresh made
33869
+ } else {
33870
+ $nav = $('<xu-nav>');
33871
+ $container.append($nav);
33872
+ func.UI.component.init_xu_nav($container, $nav);
33873
+ }
33874
+
33875
+ $nav.data().xuData.$div = $div_content;
33876
+
33877
+ await $nav[0].setRoot('xu-root-component-' + SESSION_ID);
33878
+ $ret = $container;
33879
+ break;
33880
+ }
33881
+ return $ret;
33882
+ };
33883
+
33884
+ if (!(await init())) return;
33885
+ debug();
33886
+ const fx = {
33887
+ widget: async function () {
33888
+ var _session = SESSION_OBJ[SESSION_ID];
33889
+
33890
+ var exist_elm_obj = get_element_info();
33891
+ var $div = exist_elm_obj.div;
33892
+ if (!exist_elm_obj.div) {
33893
+ $div = 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);
33894
+
33895
+ //////////////////////////
33896
+
33897
+ let plugin_name = prop['xu-widget'],
33898
+ method = prop['xu-method'],
33899
+ dsP = paramsP.dsSessionP,
33900
+ propsP = prop,
33901
+ sourceP = 'widgets';
33902
+
33903
+ // const set_SYS_GLOBAL_OBJ_WIDGET_INFO = async function (docP) {
33904
+ // var obj = _.clone(docP);
33905
+ // obj.date = await func.utils.get_dateTime(
33906
+ // SESSION_ID,
33907
+ // "SYS_DATE",
33908
+ // docP.date
33909
+ // );
33910
+ // obj.time = await func.utils.get_dateTime(
33911
+ // SESSION_ID,
33912
+ // "SYS_TIME",
33913
+ // docP.date
33914
+ // );
33915
+
33916
+ // var datasource_changes = {
33917
+ // [0]: {
33918
+ // ["data_system"]: {
33919
+ // ["SYS_GLOBAL_OBJ_WIDGET_INFO"]: obj,
33920
+ // },
33921
+ // },
33922
+ // };
33923
+ // await func.datasource.update(SESSION_ID, datasource_changes);
33924
+ // };
33925
+ const call_plugin_api = async function (plugin_nameP, dataP) {
33926
+ return await func.utils.call_plugin_api(SESSION_ID, plugin_nameP, dataP);
33927
+ };
33928
+ const report_error = function (descP, warn) {
33929
+ func.utils.debug.log(SESSION_ID, _session.DS_GLB[dsP].prog_id + '_' + _session.DS_GLB[dsP].callingMenuId, {
33930
+ module: 'widgets',
33931
+ action: 'Init',
33932
+ source: sourceP,
33933
+ prop: descP,
33934
+ details: descP,
33935
+ result: null,
33936
+ error: warn ? false : true,
33937
+ fields: null,
33938
+ type: 'widgets',
33939
+ prog_id: _session.DS_GLB[dsP].prog_id,
33940
+ });
33941
+ };
33942
+ const get_fields_data = async function (fields, props) {
33943
+ const report_error = function (descP, warn) {
33944
+ func.utils.debug.log(SESSION_ID, _session.DS_GLB[dsP].prog_id + '_' + _session.DS_GLB[dsP].callingMenuId, {
33945
+ module: 'widgets',
33946
+ action: 'Init',
33947
+ source: sourceP,
33948
+ prop: descP,
33949
+ details: descP,
33950
+ result: null,
33951
+ error: warn ? false : true,
33952
+ fields: null,
33953
+ type: 'widgets',
33954
+ prog_id: _session.DS_GLB[dsP].prog_id,
33955
+ });
33956
+ };
33957
+ const get_property_value = async function (fieldIdP, val) {
33958
+ if (!val) return;
33959
+ var value = props[fieldIdP] || (typeof val.defaultValue === 'function' ? val?.defaultValue?.() : val?.defaultValue);
33960
+ if (val.render === 'eventId') {
33961
+ value = props?.[fieldIdP]?.event;
33962
+ }
33963
+
33964
+ if (props[`xu-exp:${fieldIdP}`]) {
33965
+ value = (await func.expression.get(SESSION_ID, props[`xu-exp:${fieldIdP}`], dsP, 'widget property')).result;
33966
+ }
33967
+
33968
+ return func.common.get_cast_val(
33969
+ SESSION_ID,
33970
+ 'widgets',
33971
+ fieldIdP,
33972
+ val.type, //val.type !== "string" || val.type !== "number" ? "string" : val.type,
33973
+ value,
33974
+ null,
33975
+ );
33976
+ };
33977
+ var data_obj = {};
33978
+ var return_code = 1;
33979
+ // $.each(fields, function (key, val) {
33980
+ for await (const [key, val] of Object.entries(fields)) {
33981
+ data_obj[key] = await get_property_value(key, val);
33982
+ if (!data_obj[key] && val.mandatory) {
33983
+ return_code = -1;
33984
+ report_error(`${key} is a mandatory field.`);
33985
+ break;
33986
+ }
33987
+ // console.log(val);
33988
+ }
33989
+ for await (const key of ['xu-bind']) {
33990
+ data_obj[key] = await get_property_value(key, props[key]);
33991
+ }
33992
+
33993
+ return { code: return_code, data: data_obj };
33994
+ };
33995
+
33996
+ const load_css_style = function () {
33997
+ let path = get_path('style.css');
33998
+ func.utils.load_css_on_demand(path);
33999
+ };
34000
+
34001
+ const get_path = function (resource) {
34002
+ if (_session.worker_type === 'Dev') {
34003
+ return `../../plugins/${plugin_name}/${resource}`;
34004
+ }
34005
+ return `https://${_session.domain}/plugins/${plugin_name}/${resource}?gtp_token=${_session.gtp_token}&app_id=${_session.app_id}`;
34006
+ };
34007
+ const _plugin = APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];
34008
+ const index = await func.utils.get_plugin_resource(SESSION_ID, plugin_name, `${_plugin.manifest['index.mjs'].dist ? 'dist/' : ''}index.mjs`);
34009
+ const methods = index.methods;
34010
+ if (methods && !methods[method]) {
34011
+ return report_error('method not found');
34012
+ }
34013
+
34014
+ const fields_ret = await get_fields_data(methods[method].fields, propsP);
34015
+ if (fields_ret.code < 0) {
34016
+ return report_error(fields_ret.data);
34017
+ }
34018
+ const fields = fields_ret.data;
34019
+
34020
+ let exclude_attributes = [];
34021
+ for await (const [key, val] of Object.entries(propsP)) {
34022
+ if (typeof fields[key] !== 'undefined' || typeof fields[`xu-exp:${key}`] !== 'undefined') {
34023
+ exclude_attributes.push(key);
34024
+ }
34025
+ }
34026
+
34027
+ 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);
34028
+
34029
+ $div.addClass('widget_wrapper'); // class get override in set_attributes_new
34030
+
34031
+ if (!APP_OBJ[_session.app_id].app_plugins_purchased[plugin_name]) {
34032
+ return report_error(`plugin ${plugin_name} not found`);
34033
+ }
34034
+
34035
+ if (APP_OBJ[_session.app_id].app_plugins_purchased[plugin_name].manifest['style.css'].exist) {
34036
+ load_css_style();
34037
+ }
34038
+
34039
+ const plugin_setup_ret = await func.utils.get_plugin_setup(SESSION_ID, plugin_name);
34040
+ if (plugin_setup_ret.code < 0) {
34041
+ return report_error(plugin_setup_ret);
34042
+ }
34043
+
34044
+ const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
34045
+ func,
34046
+ glb,
34047
+ SESSION_OBJ,
34048
+ SESSION_ID,
34049
+ APP_OBJ,
34050
+ dsSession: paramsP.dsSessionP,
34051
+ job_id: jobNoP,
34052
+ });
34053
+
34054
+ const params = {
34055
+ SESSION_ID,
34056
+ method,
34057
+ _session,
34058
+ dsP,
34059
+ sourceP,
34060
+ propsP,
34061
+ plugin_name,
34062
+ $containerP: $div,
34063
+ plugin_setup: plugin_setup_ret.data,
34064
+
34065
+ report_error,
34066
+ call_plugin_api,
34067
+ // set_SYS_GLOBAL_OBJ_WIDGET_INFO,
34068
+ api_utils,
34069
+ };
34070
+
34071
+ const fx = await func.utils.get_plugin_resource(SESSION_ID, plugin_name, `${_plugin.manifest['runtime.mjs'].dist ? 'dist/' : ''}runtime.mjs`);
34072
+
34073
+ if (_plugin?.manifest?.['runtime.mjs'].dist && _plugin?.manifest?.['runtime.mjs']?.css) {
34074
+ const plugin_runtime_css_url = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, 'dist/runtime.css');
34075
+ func.utils.load_css_on_demand(plugin_runtime_css_url);
34076
+ }
34077
+
34078
+ if (!fx[method]) {
34079
+ throw `Method: ${method} does not exist`;
34080
+ }
34081
+ try {
34082
+ await fx[method](fields, params);
34083
+ } catch (err) {
34084
+ func.utils.debug_report(SESSION_ID, `${plugin_name} widget`, err.message, 'E');
34085
+ }
34086
+ }
34087
+ return $div;
34088
+ },
34089
+ [`xu-single-view`]: async function () {
34090
+ var exist_elm_obj = get_element_info();
34091
+ var $div = exist_elm_obj.div;
34092
+
34093
+ if (!exist_elm_obj.div) {
34094
+ var $wrapper = $('<div>');
34095
+ $div = func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, null, null, 'div', $wrapper, '');
34096
+
34097
+ if (!$div) return;
34098
+
34099
+ if (!REFRESHER_IN_PROGRESS && (paramsP.is_mobile_popover || paramsP.is_mobile_page)) {
34100
+ close_all_modals();
34101
+ }
34102
+
34103
+ $div.hover(
34104
+ function (e) {
34105
+ hover_in();
34106
+ },
34107
+ function (e) {
34108
+ hover_out();
34109
+ },
34110
+ );
34111
+ }
34112
+
34113
+ const ret = await iterate_child($div, nodeP, null, null, $div);
34114
+ if (_.isEmpty($container.data().xuAttributes)) {
34115
+ await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
34116
+ }
34117
+
34118
+ $.each($div.data().xuData, function (key, val) {
34119
+ $container.data().xuData[key] = _.cloneDeep(val);
34120
+ });
34121
+ $.each($div.data().xuAttributes, function (key, val) {
34122
+ $container.data().xuAttributes[key] = _.cloneDeep(val);
34123
+ });
34124
+
34125
+ return await render_screen_type($div);
34126
+ },
34127
+ [`xu-multi-view`]: async function () {
34128
+ var $div = $container;
34129
+
34130
+ if (!$div.data().xuData.node || !$div.data().xuData.node.children) {
34131
+ $div.data().xuData.node = nodeP;
34132
+ }
34133
+
34134
+ if (!$div.data().xuData.debug_info) {
34135
+ $div.data().xuData.debug_info = {
34136
+ id: nodeP.id,
34137
+ parent_id: $container.data().xuData.ui_id,
34138
+ };
34139
+ }
34140
+
34141
+ const done = async function (continuous_idx) {
34142
+ // const do_callback = async function ($div) {
34143
+ // // if ($root_container.data().xuData.progress_bar_circle) {
34144
+ // // setTimeout(function () {
34145
+ // // $.each(
34146
+ // // $root_container.data().xuData.progress_bar_circle,
34147
+ // // function (key, val) {
34148
+ // // val.bar.set(parseFloat(val.value)); // Number from 0.0 to 1.0
34149
+ // // }
34150
+ // // );
34151
+ // // }, 2000);
34152
+ // // }
34153
+
34154
+ // if (paramsP.screenInfo.properties?.rtl) {
34155
+ // $div_content.attr('dir', 'rtl');
34156
+ // }
34157
+
34158
+ // return $div;
34159
+ // };
34160
+ await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
34161
+
34162
+ return await render_screen_type($div);
34163
+ };
34164
+
34165
+ if (!REFRESHER_IN_PROGRESS && (paramsP.is_mobile_popover || paramsP.is_mobile_page)) {
34166
+ close_all_modals();
34167
+ }
34168
+
34169
+ const empty_result = async function () {
34170
+ var content = prop.empty_result_content || '';
34171
+
34172
+ var res = await func.expression.get(
34173
+ SESSION_ID,
34174
+ content, // prop["xu-exp:empty_result_content"],
34175
+ paramsP.dsSessionP,
34176
+ 'empty_result_content_EXP',
34177
+ _ds.currentRecordId,
34178
+ );
34179
+ content = res.result;
34180
+ // }
34181
+
34182
+ let empty_result_node = {
34183
+ type: 'element',
34184
+ id: crypto.randomUUID(),
34185
+ content,
34186
+ // : content || (typeof content === "undefined" && "Empty results"),
34187
+ tagName: 'div',
34188
+ attributes: {},
34189
+ children: [],
34190
+ };
34191
+
34192
+ 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);
34193
+ await func.events.validate(SESSION_ID, 'record_not_found', paramsP.dsSessionP);
34194
+ return await done(null);
34195
+ };
34196
+ var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
34197
+
34198
+ var continuous_idx = null;
34199
+
34200
+ if (!_ds.data_feed || _.isEmpty(_ds.data_feed.rows)) {
34201
+ return await empty_result();
34202
+ }
34203
+
34204
+ var i = 0;
34205
+ for await (const [key, val] of Object.entries(_ds.data_feed.rows)) {
34206
+ var node = JSON.parse(JSON.stringify(nodeP));
34207
+
34208
+ _ds.currentRecordId = val._ROWID;
34209
+ const ret = await iterate_child($div, node, { continuous_idx }, null, $root_container);
34210
+
34211
+ if (_.isEmpty($container.data().xuAttributes)) {
34212
+ await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
34213
+ }
34214
+ }
34215
+
34216
+ return await done(continuous_idx);
34217
+ },
34218
+ [`xu-panel`]: async function () {
34219
+ const done = async function ($new_div) {
34220
+ if (!$container.data()?.xuData?.paramsP) {
34221
+ return $container;
34222
+ }
34223
+ var $div_items = $div.data().xuData.node.children;
34224
+
34225
+ await func.UI.screen.panel_post_render_handler(SESSION_ID, $container, $new_div, nodeP, $div, jobNoP);
34226
+
34227
+ // TO FIX should be timeout
34228
+ $container.data().xuData.node.children = $div_items;
34229
+
34230
+ return $container;
34231
+ };
34232
+
34233
+ var $wrapper = $('<div>');
34234
+ $div = func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, null, null, null, $wrapper, '');
34235
+
34236
+ 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);
34237
+ if (ret.abort) {
34238
+ // // program null
34239
+ // if (ret.program_null) {
34240
+ // return render_screen_type($div);
34241
+ // }
34242
+
34243
+ // render N
34244
+ return (ret.$new_div = $('<template>').append($div));
34245
+
34246
+ // ret.$new_div = $("<template>").append($div);
34247
+ }
34248
+ let ret_done = await done(ret.$new_div);
34249
+ return ret_done;
34250
+ },
34251
+ };
34252
+
34253
+ const draw_html_element = async function (element) {
34254
+ const done = async function () {
34255
+ return $div;
34256
+ };
34257
+ if (!element || element === 'script') return await done();
34258
+ let str = '';
34259
+
34260
+ var $div = func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, prop, null, null, element, null, str);
34261
+
34262
+ $div.hover(
34263
+ function (e) {
34264
+ hover_in($div);
34265
+ },
34266
+ function (e) {
34267
+ hover_out();
34268
+ },
34269
+ );
34270
+
34271
+ 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);
34272
+ if (ret.abort) return await done();
34273
+ // check if iterator made to prevent children render
34274
+
34275
+ const ret_iterate_child = await iterate_child($div, nodeP, parent_infoP, null, $root_container);
34276
+ return await done();
34277
+ };
34278
+
34279
+ if (nodeP.content && nodeP.attributes) {
34280
+ nodeP.attributes['xu-content'] = nodeP.content;
34281
+ }
34282
+ if (nodeP.tagName === 'xu-widget') {
34283
+ if (is_skeleton) return;
34284
+ return await fx['widget']();
34285
+ }
34286
+ if (fx[nodeP.tagName]) {
34287
+ return await fx[nodeP.tagName]();
34288
+ }
34289
+
34290
+ return await draw_html_element(nodeP.tagName);
34291
+ };
34292
+
34293
+ func.UI.screen.refresh_document_changes_for_realtime_update = async function (SESSION_ID, doc_change) {
34294
+ let _session = SESSION_OBJ[SESSION_ID];
34295
+ for (const [key, _ds] of Object.entries(_session.DS_GLB)) {
34296
+ let prog_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
34297
+ if (prog_obj?.progDataSource?.dataSourceRealtime && prog_obj?.progDataSource?.dataSourceTableId === doc_change.table_id) {
34298
+ try {
34299
+ // disabled in purpose to support create row
34300
+
34301
+ // const row_idx = func.common.find_ROWID_idx(_ds, doc_change.row_id);
34302
+
34303
+ // console.log(
34304
+ // "refresh_document_changes_for_realtime_update",
34305
+ // _ds.data_feed.rows[row_idx]
34306
+ // );
34307
+
34308
+ if (!_ds.screen_params) continue;
34309
+ if (_ds.screen_params.is_panelP) {
34310
+ func.UI.screen.refresh_screen(SESSION_ID, null, key);
34311
+ } else {
34312
+ func.action.execute(SESSION_ID, 'act_refresh', _ds, null, null);
34313
+ }
34314
+ } catch (err) {
34315
+ // console.error(err);
34316
+ }
34317
+ }
34318
+ }
34319
+ };
34320
+ func.UI.component = {};
32906
34321
 
32907
34322
  func.UI.component.create_app_modal_component = function (
32908
34323
  SESSION_ID,