@xuda.io/runtime-bundle 1.0.1149 → 1.0.1150

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32685,2216 +32685,7 @@ func.UI.screen.execute_xu_functions = async function (SESSION_ID, is_skeleton, $
32685
32685
  SESSION_ID,
32686
32686
  cond,
32687
32687
  paramsP.dsSessionP,
32688
- 'UI Attr EXP',
32689
- $elm.data().xuData.currentRecordId, // SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP].currentRecordId
32690
- null,
32691
- null,
32692
- null,
32693
- null,
32694
- null,
32695
- $elm.data().xuData.iterate_info,
32696
- );
32697
-
32698
- if (res.result) {
32699
- $elm.addClass(cla);
32700
- } else {
32701
- $elm.removeClass(cla);
32702
- }
32703
-
32704
- $elm.data().xuData.debug_info.attribute_stat['xu-class'] = $elm.attr('class');
32705
- }
32706
- return {};
32707
- } catch (e) {
32708
- console.warn('parse error:' + val.value);
32709
- return { abort: true };
32710
- }
32711
- },
32712
- 'xu-exp': async function ($elm, val) {
32713
- let exp = val.value === null ? true : val.value;
32714
-
32715
- 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);
32716
-
32717
- let value = func.UI.screen.fix_val_defaults(val.key, exp_ret.result);
32718
-
32719
- var new_val = {
32720
- key: val.key,
32721
- value,
32722
- };
32723
-
32724
- if (nodeP.tagName.substr(0, 3) === 'xu-') {
32725
- if (tag_fx[nodeP.tagName][new_val.key]) {
32726
- return await tag_fx[nodeP.tagName][new_val.key]($elm, new_val);
32727
- }
32728
- console.warn(`attribute ${new_val.key} not found for ${nodeP.tagName}`);
32729
- return {};
32730
- }
32731
- if (!$elm.data().xuData) return;
32732
-
32733
- $elm.data().xuData.debug_info.attribute_stat[new_val.key] = new_val.value;
32734
-
32735
- // IGNORE UNDEFINED or NULL ATTRIBUTES
32736
- if (typeof new_val.value === 'undefined' || new_val.value === null) {
32737
- return {};
32738
- }
32739
-
32740
- // IGNORE ATTRIBUTES WITH EMPTY VALUES
32741
- if (glb.solid_attributes.includes(new_val.key) && !new_val.value) {
32742
- return {};
32743
- }
32744
-
32745
- if (new_val.key.substr(0, 2) === 'xu') {
32746
- return await common_fx[new_val.key]($elm, new_val);
32747
- }
32748
-
32749
- $elm.attr(new_val.key, ($elm.attr(new_val.key) || '') + new_val.value);
32750
- return {};
32751
- },
32752
- 'xu-on': async function ($elm, val) {
32753
- CLIENT_ACTIVITY_TS = Date.now();
32754
- const trigger = val.key.split('xu-on:')[1].toLowerCase();
32755
- $elm.on(trigger, async function (evt) {
32756
- const _$elm = $(evt.currentTarget);
32757
- if (_.isEmpty(_$elm.data().xuAttributes)) return;
32758
-
32759
- for await (const [key, val] of Object.entries(_$elm.data().xuAttributes['xu-on:' + evt.type])) {
32760
- if (!_.isEmpty(val.props.condition)) {
32761
- const expCond = await func.expression.get(SESSION_ID, val.props.condition, paramsP.dsSessionP, 'condition', paramsP.recordid); // execute expression
32762
- if (!expCond.result) continue;
32763
- }
32764
-
32765
- if (val.event_modifiers && evt[val.event_modifiers]) {
32766
- evt[val.event_modifiers]();
32767
- }
32768
-
32769
- // if (val.handler === 'custom') {
32770
- if (val.workflow) {
32771
- // do BL
32772
- for await (const [key2, val2] of Object.entries(val.workflow)) {
32773
- // var cond = val2.data.enabled;
32774
- // if (val2.data.enabled && val2.props.condition) {
32775
- // expCond = await func.expression.get(SESSION_ID, val2.props.condition, paramsP.dsSessionP, 'condition', paramsP.recordid); // execute expression
32776
- // cond = expCond.result;
32777
- // }
32778
- // if (!cond) continue;
32779
-
32780
- if (!val2.data.enabled) continue; // added Jul 3, 25 - condition validate on execution
32781
-
32782
- 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);
32783
- }
32784
- }
32785
- }
32786
- });
32787
- return {};
32788
- },
32789
- 'xu-script': async function ($elm, val) {
32790
- var checkExist = setInterval(function () {
32791
- if ($elm.is(':visible')) {
32792
- try {
32793
- // var res = eval('(' + val.value + ')');
32794
- const fn = `(function(el, evt) {
32795
- ${val.value}
32796
- })(document.querySelector(\`[xu-ui-id="${$elm.attr('xu-ui-id')}"]\`),evt);`;
32797
-
32798
- var res = eval(fn);
32799
- // if (typeof res === 'function') {
32800
- // res($elm[0]);
32801
- // }
32802
- } catch (e) {
32803
- eval(val.value);
32804
- }
32805
-
32806
- clearInterval(checkExist);
32807
- }
32808
- }, 100); // check every 100ms
32809
-
32810
- return {};
32811
- },
32812
- 'xu-style-global': async function ($elm, val) {
32813
- $('head').append(`<style>${val.value}</style>`);
32814
- return {};
32815
- },
32816
- 'xu-style': async function ($elm, val) {
32817
- var cssString = val.value;
32818
-
32819
- var parser = new cssjs();
32820
-
32821
- var parsed = parser.parseCSS(cssString);
32822
- var xuUiId = `[xu-ui-id="${$elm.attr('xu-ui-id')}"]`;
32823
-
32824
- $.each(parsed, function (key, val) {
32825
- var selectors_arr = val.selector.split(',');
32826
-
32827
- $.each(selectors_arr, function (key2, val2) {
32828
- selectors_arr[key2] = `${xuUiId} ${val2}, ${xuUiId}${val2}`;
32829
- // console.log(new_selector);
32830
- });
32831
-
32832
- val.selector = selectors_arr.join(',');
32833
- // console.log(parsed);
32834
- });
32835
-
32836
- var newCSSString = parser.getCSSForEditor(parsed);
32837
-
32838
- $('head').append(`<style>${newCSSString}</style>`);
32839
- return {};
32840
- },
32841
- 'xu-cdn': async function ($elm, val) {
32842
- for await (const [key, resource] of Object.entries(val.value)) {
32843
- await load_cdn(resource);
32844
- }
32845
-
32846
- return {};
32847
- },
32848
- 'xu-ui-plugin': async function ($elm, val) {
32849
- var _session = SESSION_OBJ[SESSION_ID];
32850
-
32851
- for await (const [plugin_name, value] of Object.entries(val.value)) {
32852
- const _plugin = APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];
32853
- if (_plugin?.installed && _plugin?.manifest?.['runtime.mjs']?.exist && _plugin?.manifest?.['index.mjs']?.exist && value.enabled) {
32854
- if (_plugin?.manifest?.['runtime.mjs'].dist && _plugin?.manifest?.['runtime.mjs']?.css) {
32855
- const plugin_runtime_css_url = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, 'dist/runtime.css');
32856
- func.utils.load_css_on_demand(plugin_runtime_css_url);
32857
- }
32858
-
32859
- const plugin_index_src = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, `${_plugin.manifest['index.mjs'].dist ? 'dist/' : ''}index.mjs`);
32860
-
32861
- const plugin_index_resources = await import(plugin_index_src);
32862
-
32863
- let properties = _.cloneDeep(plugin_index_resources.properties);
32864
- for await (let [prop_name, prop_val] of Object.entries(properties)) {
32865
- prop_val.value = value?.attributes?.[prop_name];
32866
- if (value?.attributes?.[`xu-exp:${prop_name}`]) {
32867
- const res = await func.expression.get(SESSION_ID, value?.attributes?.[`xu-exp:${prop_name}`], paramsP.dsSessionP, 'UI Attr EXP');
32868
- prop_val.value = res.result;
32869
- }
32870
- }
32871
- // $elm.data().xu_ui_plugin = { properties };
32872
- const plugin_runtime_src = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, `${_plugin.manifest['runtime.mjs'].dist ? 'dist/' : ''}runtime.mjs`);
32873
-
32874
- const plugin_runtime_resources = await import(plugin_runtime_src);
32875
-
32876
- if (plugin_runtime_resources.cdn && typeof _.isArray(plugin_runtime_resources.cdn)) {
32877
- for await (const resource of plugin_runtime_resources.cdn) {
32878
- await load_cdn(resource);
32879
- }
32880
- }
32881
-
32882
- if (plugin_runtime_resources.fn) {
32883
- await plugin_runtime_resources.fn(plugin_name, $elm?.[0], properties);
32884
- // await plugin_runtime_resources.fn(plugin_name, $elm?.[0], $elm.data().xu_ui_plugin.properties);
32885
- }
32886
- }
32887
- }
32888
-
32889
- return {};
32890
- },
32891
- 'xu-store': async function ($elm, val) {
32892
- try {
32893
- const fields_obj = JSON5.parse(val.value);
32894
- for (const [field_id, value] of Object.entries(fields_obj)) {
32895
- func.datasource.add_dynamic_field_to_ds(SESSION_ID, paramsP.dsSessionP, field_id, value);
32896
- }
32897
- } catch (err) {
32898
- console.error(err);
32899
- }
32900
- return {};
32901
- },
32902
- 'xu-viewport': async function ($elm, val) {
32903
- // functionality in draw_html_element
32904
- return {};
32905
- },
32906
- };
32907
-
32908
- if (nodeP.tagName.substr(0, 3) === 'xu-') {
32909
- if (xu_func === 'xu-exp') {
32910
- return common_fx[xu_func]($elm, val);
32911
- }
32912
-
32913
- if (tag_fx?.[nodeP.tagName]?.[xu_func]) {
32914
- let ret = await tag_fx[nodeP.tagName][xu_func]($elm, val);
32915
- return ret;
32916
- }
32917
- // if (xu_func !== "tree_id")
32918
- console.warn(`attribute ${xu_func} not found for ${nodeP.tagName}`);
32919
- return {};
32920
- }
32921
- if (_.isEmpty($elm.data())) {
32922
- return {};
32923
- }
32924
- if (!$elm.data().xuData.debug_info.attribute_stat) {
32925
- $elm.data().xuData.debug_info.attribute_stat = {};
32926
- }
32927
- if (xu_func !== 'xu-exp') {
32928
- $elm.data().xuData.debug_info.attribute_stat[xu_func] = val.value;
32929
- }
32930
- try {
32931
- if (!common_fx[xu_func]) {
32932
- console.warn('invalid xu-tag', xu_func, error);
32933
- return {};
32934
- }
32935
-
32936
- return await common_fx[xu_func]($elm, val);
32937
- } catch (error) {
32938
- debugger;
32939
- }
32940
- };
32941
-
32942
- func.UI.screen.fix_val_defaults = function (key, val) {
32943
- var ret = val;
32944
- if (
32945
- key === 'xu-render' &&
32946
- (typeof val === 'undefined' || val === null || val === '') //|| val === ""
32947
- ) {
32948
- // ret = 'Y'; // was ret = "N";
32949
- ret = true;
32950
- }
32951
- if (
32952
- key === 'xu-show' &&
32953
- (typeof val === 'undefined' || val === null || val === '') //|| val === ""
32954
- ) {
32955
- // ret = 'Y';
32956
- ret = true;
32957
- }
32958
- return ret;
32959
- };
32960
-
32961
- 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) {
32962
- var done_exp = [];
32963
-
32964
- const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
32965
- if (!_ds) return { abort: true };
32966
-
32967
- const get_attr_value = async function (key) {
32968
- let ret = func.UI.screen.fix_val_defaults(key, nodeP.attributes[key]);
32969
- if (nodeP?.attributes?.hasOwnProperty(`xu-exp:${key}`)) {
32970
- ret = await get_xuExp(key);
32971
- }
32972
- return ret;
32973
- };
32974
-
32975
- const get_xuExp = async function (attrib) {
32976
- if (is_skeleton) return;
32977
- if (glb.new_xu_render) {
32978
- let _xuData = $elm.data().xuData;
32979
- if (!_xuData.attr_exp_info) {
32980
- _xuData.attr_exp_info = {};
32981
- }
32982
- }
32983
- const attr = `xu-exp:${attrib}`;
32984
-
32985
- if (!nodeP?.attributes?.hasOwnProperty(attr)) return;
32986
- // const attr = `xu-exp-${attrib}`;
32987
- var exp = nodeP.attributes[attr];
32988
- // if (!value) return func.UI.screen.fix_val_defaults(attrib, exp || nodeP.attributes[attrib]);
32989
-
32990
- var res = await func.expression.get(SESSION_ID, exp, paramsP.dsSessionP, 'UI Attr EXP', _ds.currentRecordId);
32991
- if (glb.new_xu_render) {
32992
- _xuData.attr_exp_info[attrib] = res;
32993
- }
32994
- // nodeP.attributes[attr] = value; //{ value: value, res: res };
32995
- done_exp.push(attr);
32996
- return res.result; //func.UI.screen.fix_val_defaults(attrib, res.result);
32997
- };
32998
-
32999
- var _ret = {};
33000
- if (nodeP.type !== 'element' || !nodeP.attributes) return _ret;
33001
-
33002
- for (let [key, val] of Object.entries(nodeP.attributes)) {
33003
- // REMOVE STATIC ATTRIBUTES IF EXP EXISTS to avoid dup
33004
- if (key.substring(0, 6) === 'xu-exp') {
33005
- if (_.isEmpty(val)) {
33006
- delete nodeP.attributes[key];
33007
- continue;
33008
- }
33009
- const clean_key = key.split(':')[1];
33010
- if (typeof nodeP.attributes[clean_key] !== 'undefined') {
33011
- delete nodeP.attributes[clean_key];
33012
- }
33013
- }
33014
- // FIX abbreviations
33015
- if (glb.attr_abbreviations_arr.includes(key)) {
33016
- nodeP.attributes[`xu-on:${key.substring(3)}`] = [
33017
- {
33018
- handler: 'custom',
33019
- props: {},
33020
- event: [
33021
- {
33022
- id: Date.now(),
33023
- data: {
33024
- action: 'update',
33025
- name: { value: val },
33026
- enabled: true,
33027
- },
33028
- props: {},
33029
- },
33030
- ],
33031
- },
33032
- ];
33033
- delete nodeP.attributes[key];
33034
- }
33035
- }
33036
-
33037
- for (let [key, val] of Object.entries(nodeP.attributes)) {
33038
- // FIX STATIC DEFAULTS
33039
- val = func.UI.screen.fix_val_defaults(key, val);
33040
-
33041
- // REMOVE UNDEFINED or NULL ATTRIBUTES
33042
- if (typeof val === 'undefined' || val === null) {
33043
- delete nodeP.attributes[key];
33044
- }
33045
-
33046
- // REMOVE ATTRIBUTES WITH EMPTY VALUES
33047
- if (glb.solid_attributes.includes(key) && !val) {
33048
- delete nodeP.attributes[key];
33049
- }
33050
- }
33051
-
33052
- // XU-ATTRS
33053
- if (nodeP?.attributes?.['xu-attrs'] || nodeP?.attributes?.['xu-exp:xu-attrs']) {
33054
- const attr = 'xu-attrs';
33055
- let ret = await func.UI.screen.execute_xu_functions(
33056
- SESSION_ID,
33057
- is_skeleton,
33058
- $root_container,
33059
- nodeP,
33060
- $container,
33061
- paramsP,
33062
- parent_infoP,
33063
- jobNoP,
33064
- keyP,
33065
- parent_nodeP,
33066
- attr,
33067
- $elm,
33068
- {
33069
- key: attr,
33070
- value: await get_attr_value(attr),
33071
- },
33072
- is_init,
33073
- );
33074
- }
33075
-
33076
- // BEFORE
33077
- if (!_.isEmpty(nodeP.attributes)) {
33078
- for await (const [key, attr] of Object.entries(glb.run_xu_before)) {
33079
- if (_ret.abort || $container?.data()?.xuData?.pending_to_delete) break;
33080
- if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) {
33081
- continue;
33082
- }
33083
-
33084
- if (!nodeP?.attributes?.hasOwnProperty(attr) && !nodeP?.attributes?.hasOwnProperty(`xu-exp:${attr}`)) {
33085
- continue;
33086
- }
33087
-
33088
- if (!nodeP.attributes[`xu-exp:${attr}`] && nodeP?.attributes?.hasOwnProperty(attr) && typeof func.UI.screen.fix_val_defaults(attr, nodeP.attributes[attr]) === 'undefined') {
33089
- continue;
33090
- }
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
-
33108
- value: await get_attr_value(attr),
33109
- },
33110
- is_init,
33111
- );
33112
- _ret = _.assignIn(_ret, ret);
33113
- }
33114
- }
33115
-
33116
- // ALL
33117
-
33118
- for await (const [key, val] of Object.entries(nodeP.attributes)) {
33119
- if (_ret.abort || $container?.data()?.xuData?.pending_to_delete) break;
33120
- if (glb.html5_events_handler.includes(key) || execute_attributes.includes(key)) {
33121
- continue;
33122
- }
33123
-
33124
- const new_key = key.split(':')[0]; // break expression
33125
- if (
33126
- nodeP.tagName !== 'xu-panel' &&
33127
- nodeP.tagName !== 'xu-teleport' && // nodeP.tagName.substr(0, 3) !== "xu-" &&
33128
- (new_key.substr(0, 2) !== 'xu' || new_key.substr(2, 1) !== '-')
33129
- ) {
33130
- // handle common html attributes
33131
- try {
33132
- $elm.get(0).setAttribute(key, val);
33133
- } catch (err) {
33134
- console.error(err.message);
33135
- }
33136
-
33137
- continue;
33138
- }
33139
- // handle xu attributes
33140
- try {
33141
- if ($elm?.data()?.xuAttributes) {
33142
- // in some cases xu data delete in purpose when refreshing the screen
33143
- $elm.data().xuAttributes[key] = val;
33144
- }
33145
- } catch (error) {
33146
- debugger;
33147
- console.error(error);
33148
- }
33149
-
33150
- 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)) {
33151
- continue;
33152
- }
33153
-
33154
- if (new_key === 'xu-on') {
33155
- let ret = await func.UI.screen.execute_xu_functions(
33156
- SESSION_ID,
33157
- is_skeleton,
33158
- $root_container,
33159
- nodeP,
33160
- $container,
33161
- paramsP,
33162
- parent_infoP,
33163
- jobNoP,
33164
- keyP,
33165
- parent_nodeP,
33166
- 'xu-on',
33167
- $elm,
33168
- {
33169
- key: key,
33170
- // value: (await get_xuExp(new_key)) || func.UI.screen.fix_val_defaults(key, val),
33171
- value: await get_attr_value(key),
33172
- },
33173
- is_init,
33174
- refreshed_ds,
33175
- );
33176
- _ret = _.assignIn(_ret, ret);
33177
- continue;
33178
- }
33179
-
33180
- let ret = await func.UI.screen.execute_xu_functions(
33181
- SESSION_ID,
33182
- is_skeleton,
33183
- $root_container,
33184
- nodeP,
33185
- $container,
33186
- paramsP,
33187
- parent_infoP,
33188
- jobNoP,
33189
- keyP,
33190
- parent_nodeP,
33191
- new_key,
33192
- $elm,
33193
- {
33194
- key: key,
33195
- // value: (await get_xuExp(new_key)) || func.UI.screen.fix_val_defaults(key, val),
33196
- value: await get_attr_value(key),
33197
- },
33198
- is_init,
33199
- refreshed_ds,
33200
- );
33201
-
33202
- _ret = _.assignIn(_ret, ret);
33203
- }
33204
-
33205
- // EXP for
33206
-
33207
- for await (const [key, val] of Object.entries(nodeP.attributes)) {
33208
- if (_ret.abort || $container?.data()?.xuData?.pending_to_delete) break;
33209
-
33210
- const attr = key.split('xu-exp:')[1];
33211
-
33212
- if (!attr) {
33213
- continue;
33214
- }
33215
-
33216
- if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) continue;
33217
-
33218
- if (done_exp.includes(key)) {
33219
- continue;
33220
- }
33221
- let ret = await func.UI.screen.execute_xu_functions(
33222
- SESSION_ID,
33223
- is_skeleton,
33224
- $root_container,
33225
- nodeP,
33226
- $container,
33227
- paramsP,
33228
- parent_infoP,
33229
- jobNoP,
33230
- keyP,
33231
- parent_nodeP,
33232
- 'xu-exp',
33233
- $elm,
33234
- {
33235
- key: attr,
33236
- value: val,
33237
- },
33238
- true,
33239
- refreshed_ds,
33240
- );
33241
- _ret = _.assignIn(_ret, ret);
33242
- }
33243
-
33244
- // AFTER
33245
-
33246
- for await (const [key, attr] of Object.entries(glb.run_xu_after)) {
33247
- if ($container?.data()?.xuData?.pending_to_delete) break;
33248
-
33249
- if (glb.html5_events_handler.includes(attr) || execute_attributes.includes(attr)) continue;
33250
-
33251
- if (!nodeP.attributes || !nodeP.attributes[attr] & !nodeP.attributes[`xu-exp:${attr}`]) continue;
33252
-
33253
- let ret = await func.UI.screen.execute_xu_functions(
33254
- SESSION_ID,
33255
- is_skeleton,
33256
- $root_container,
33257
- nodeP,
33258
- $container,
33259
- paramsP,
33260
- parent_infoP,
33261
- jobNoP,
33262
- keyP,
33263
- parent_nodeP,
33264
- attr,
33265
- $elm,
33266
- {
33267
- key: attr,
33268
- // value: (await get_xuExp(attr)) || func.UI.screen.fix_val_defaults(attr, nodeP.attributes[attr]),
33269
- value: await get_attr_value(attr),
33270
- },
33271
- is_init,
33272
- refreshed_ds,
33273
- );
33274
- _ret = _.assignIn(_ret, ret);
33275
- }
33276
-
33277
- // REGISTER EVENTS ATTRIBUTES
33278
-
33279
- for await (const [key, val] of Object.entries(nodeP.attributes)) {
33280
- if ($container?.data()?.xuData?.pending_to_delete) break;
33281
- if (!glb.html5_events_handler.includes(key)) break;
33282
- // $elm.attr(key, await get_xuExp(key)) || val;
33283
- $elm.attr(key, await get_xuExp(key)) || val;
33284
- }
33285
-
33286
- return _ret;
33287
- };
33288
-
33289
- func.UI.screen.panel_post_render_handler = async function (
33290
- SESSION_ID,
33291
- $container, // the parent program container
33292
- $wrapper, // the wrapper element contains the rendered panel elements e.g: xu-single-view
33293
- nodeP, // the xu-panel node
33294
- $panel_div, // the panel div
33295
- jobNoP,
33296
- ) {
33297
- const _container_ds = SESSION_OBJ[SESSION_ID].DS_GLB[$container.data().xuData.paramsP.dsSessionP];
33298
- const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[$wrapper.data().xuData.paramsP.dsSessionP];
33299
- const find_old_panels_elements = function () {
33300
- return func.UI.utils.find_in_element_data('xuPanelData', $container.parent(), 'xu-ui-id', $container.data()?.xuPanelData?.xu_panel_xu_ui_id);
33301
- };
33302
- var $old_panel_div = find_old_panels_elements();
33303
- const set_xuPanelData_to_the_new_rendered_items = () => {
33304
- $container.data().xuPanelWrapper = { isWrapper: true, panelXuAttributes: _.clone($wrapper.data().xuAttributes), panelDivData: _.clone($wrapper.data()) };
33305
- $container.attr('xu-panel-wrapper-id', $wrapper.attr('xu-ui-id'));
33306
- $.each($wrapper.children(), function (key, val) {
33307
- if (!$(val).data().xuPanelData) {
33308
- $(val).data().xuPanelData = {};
33309
- }
33310
- $(val).data().xuPanelData.parent_element_ui_id = $old_panel_div?.length ? $container.parent().data().xuData.ui_id : $container.data().xuData.ui_id;
33311
-
33312
- $(val).data().xuPanelData.xu_panel_xu_ui_id = (nodeP.xu_tree_id || nodeP.id) + '-' + _container_ds?.currentRecordId;
33313
- $(val).data().xuPanelData.node = nodeP;
33314
- $(val).data().xuPanelData.$panel_div = $panel_div.clone(true);
33315
- });
33316
- };
33317
- set_xuPanelData_to_the_new_rendered_items();
33318
-
33319
- if ($old_panel_div?.length) {
33320
- $($old_panel_div[0]).after($wrapper.children());
33321
- } else {
33322
- $.each($wrapper.children(), function (key, child) {
33323
- $.each($container.children(), function (key, elm) {
33324
- if ($(elm)?.data()?.xuData && $(elm)?.data()?.xuData?.elem_key === $(child)?.data()?.xuData?.elem_key) {
33325
- $(elm).remove();
33326
- }
33327
- });
33328
- $container.append($(child));
33329
- });
33330
- }
33331
-
33332
- if (!$wrapper.data()?.xuData?.dsSession) return;
33333
-
33334
- if ($old_panel_div?.length) {
33335
- $container.parent().data().xuData.paramsP.dsSessionP = _ds.parentDataSourceNo; // set the new ds when panel replaced
33336
- } else {
33337
- $container.data().xuData.paramsP.dsSessionP = _ds.parentDataSourceNo; // set the new ds when panel replaced
33338
- }
33339
-
33340
- if ($old_panel_div?.length) {
33341
- $old_panel_div.remove();
33342
- }
33343
- return jobNoP;
33344
- };
33345
-
33346
- const generate_xu_ui_id = async function (SESSION_ID, nodeP, $container, paramsP, keyP) {
33347
- const _paramsP = _.cloneDeep(paramsP);
33348
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
33349
-
33350
- const currentRecordId = $container?.data?.()?.xuData?.recordid || (_ds ? _ds.currentRecordId : '');
33351
- const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
33352
- const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
33353
- let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
33354
-
33355
- const new_ui_id = await func.common.sha256(ui_id);
33356
- return new_ui_id;
33357
- };
33358
-
33359
- 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) {
33360
- const _paramsP = _.cloneDeep(paramsP);
33361
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
33362
- var $appendTo = $container;
33363
- if ($appendToP) $appendTo = $appendToP;
33364
- if (!$appendTo || !$appendTo.length) return null; // screen closed or not exist abort build
33365
- var div = 'div';
33366
- if (div_typeP) div = div_typeP;
33367
- var items = [];
33368
- if (nodeP.children)
33369
- items = nodeP.children.map(function (val) {
33370
- return val.xu_tree_id || val.id;
33371
- });
33372
- var currentRecordId = $container?.data?.()?.xuData?.recordid || (_ds ? _ds.currentRecordId : '');
33373
- // var xu_id = (glb.screen_num++).toString();
33374
- // xu_id = xu_id += '_' + currentRecordId;
33375
-
33376
- try {
33377
- const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
33378
- const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
33379
- // let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
33380
-
33381
- /////////////////////////////////
33382
-
33383
- var $div;
33384
-
33385
- if (div === 'svg') {
33386
- const draw_svg = function (element) {
33387
- const get_tag_str = function (element, prop, val) {
33388
- let class_str = '';
33389
- let attr_str = '';
33390
- for (const [key, val] of Object.entries(prop)) {
33391
- if (key.substr(0, 2) !== 'xu') {
33392
- attr_str += ` ${key}="${val}" `;
33393
- }
33394
- }
33395
- if (element === 'svg') {
33396
- return `<${element} ${attr_str} > `;
33397
- }
33398
- let ret = '';
33399
- if (val?.children?.length) {
33400
- ret = iterate_svg(val);
33401
- }
33402
-
33403
- return `<${element} ${class_str} ${attr_str} > ${ret} </${element}>`;
33404
- };
33405
- let svg_str = get_tag_str(element, prop);
33406
- let inner_str = '';
33407
- const iterate_svg = function (node) {
33408
- let ret = '';
33409
- if (node.children) {
33410
- for (let val of node.children) {
33411
- let prop = val.attributes;
33412
- ret += get_tag_str(val.tagName, prop, val);
33413
- }
33414
- }
33415
- return ret;
33416
- };
33417
- inner_str = iterate_svg(nodeP);
33418
-
33419
- $div = $(svg_str + inner_str + '</svg>').appendTo($appendTo);
33420
- };
33421
-
33422
- draw_svg(div_typeP);
33423
- } else {
33424
- $div = $(`<${div} ${attr_str ? attr_str : ''}>`);
33425
- }
33426
-
33427
- // // Returns a 32-bit unsigned integer hash of a string (FNV-1a)
33428
- // function hash32(str) {
33429
- // let h = 0x811c9dc5; // FNV offset basis
33430
- // for (let i = 0; i < str.length; i++) {
33431
- // h ^= str.charCodeAt(i);
33432
- // // multiply by FNV prime (2^24 + 2^8 + 0x93) with 32-bit overflow
33433
- // h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
33434
- // }
33435
- // // Convert to unsigned 32-bit
33436
- // return h >>> 0;
33437
- // }
33438
-
33439
- // function hash32hex(str) {
33440
- // return (hash32(str) >>> 0).toString(16).padStart(8, '0');
33441
- // }
33442
-
33443
- // const new_ui_id = hash32hex(ui_id);
33444
- // const new_ui_id = await func.common.sha256(ui_id);
33445
- const new_ui_id = await generate_xu_ui_id(SESSION_ID, nodeP, $container, paramsP, keyP);
33446
-
33447
- $div
33448
- .attr('xu-ui-id', new_ui_id)
33449
- // .attr('xu-node-id', nodeP.id)
33450
- .data({
33451
- xuData: {
33452
- prog_id: _paramsP.prog_id,
33453
- nodeid: nodeP.id,
33454
- ui_type: nodeP.tagName,
33455
- // xu_id,
33456
- recordid: currentRecordId,
33457
- paramsP: _paramsP,
33458
- key: keyP,
33459
- key_path, //:($container?.data()?.xuData?.key || "0") + "-" + (keyP || "0"),
33460
- screenId: _paramsP.screenId,
33461
- parent_container: $container?.attr('id'),
33462
- elem_key,
33463
- properties: prop,
33464
- node: nodeP,
33465
- node_org: _.cloneDeep(nodeP),
33466
- is_panelP: _paramsP.is_panelP,
33467
- ui_id: new_ui_id,
33468
- elem_prop: elem_propP,
33469
- debug_info: {
33470
- id: nodeP.id,
33471
- parent_id: $container?.data()?.xuData?.ui_id,
33472
- items: items,
33473
- },
33474
- parent_node: parent_nodeP,
33475
- currentRecordId: currentRecordId,
33476
- $root_container: $root_container,
33477
- parent_element_ui_id: $container?.data()?.xuData?.ui_id,
33478
- },
33479
- xuAttributes: {},
33480
- });
33481
- if (is_placeholder) {
33482
- $div.addClass('display_none');
33483
- }
33484
-
33485
- if (div_typeP !== 'svg') {
33486
- $div.appendTo($appendTo);
33487
- }
33488
- } catch (e) {
33489
- console.error(e);
33490
- }
33491
-
33492
- if (parent_infoP?.iterate_info) {
33493
- $div.data().xuData.iterate_info = parent_infoP.iterate_info;
33494
- }
33495
-
33496
- if (classP) $div.addClass(classP);
33497
-
33498
- return $div;
33499
- };
33500
- func.UI.screen.execute_screen_ready_events = async function (SESSION_ID, paramsP, sourceP, $div, jobNoP, $div_objP) {
33501
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
33502
- if (!_ds) return;
33503
- var viewEventExec_arr = [];
33504
- const execute_view_events = async function (sourceP) {
33505
- for await (const val of viewEventExec_arr) {
33506
- cond = val.eventInfo.data.enabled;
33507
- if (val.expression) {
33508
- expCond = await func.expression.get(SESSION_ID, val.expression, paramsP.dsSessionP, 'condition', paramsP.rowIdP); // execute expression
33509
- cond = expCond.result;
33510
- }
33511
- if (cond) {
33512
- await func.events.execute(
33513
- SESSION_ID,
33514
- null,
33515
- val.eventId,
33516
- val.triggerId,
33517
- val.eventInfo.data.action,
33518
- val.eventInfo.data.name,
33519
- null,
33520
- null,
33521
- null,
33522
- null,
33523
- val.eventInfo.data.action, //val.eventInfo[4]
33524
- null,
33525
- paramsP.dsSessionP,
33526
- val.eventId,
33527
- sourceP + ' event',
33528
- true,
33529
- null,
33530
- null,
33531
- paramsP.dsSessionP,
33532
- null,
33533
- null,
33534
- val.eventInfo, // val.eventInfo[8],
33535
- null,
33536
- null,
33537
- _ds.prog_id,
33538
- _ds.nodeId,
33539
- _ds.parentDataSourceNo,
33540
- $div,
33541
- );
33542
-
33543
- // update changed values to screen added 18/09/13
33544
- var fields_to_refresh = [];
33545
- try {
33546
- var current_record_id = _ds.currentRecordId;
33547
- } catch (e) {
33548
- console.error(e);
33549
- }
33550
-
33551
- if (_ds?.data_feed?.form_fields_changed?.[current_record_id]) {
33552
- $.each(_ds.data_feed.form_fields_changed[current_record_id], function (key, val) {
33553
- fields_to_refresh.push(key);
33554
- });
33555
-
33556
- var containerId = _ds.containerId;
33557
- var $container = $('#' + containerId);
33558
- if ($container?.data()?.xuData?.is_mobile_modal || $container?.data()?.xuData?.params?.is_mobile_page) {
33559
- await func.UI.screen.refresh_container(SESSION_ID, 'init', fields_to_refresh, $container, paramsP.dsSessionP, null);
33560
- } else {
33561
- $container.trigger(containerId + '.refresh', ['init', fields_to_refresh]);
33562
- }
33563
-
33564
- if ($div_objP) {
33565
- await func.UI.screen.refresh_container(SESSION_ID, 'init', fields_to_refresh, $div_objP, paramsP.dsSessionP, null);
33566
- }
33567
- }
33568
- }
33569
- continue;
33570
- }
33571
- };
33572
- const get_view_events_count = async function (typeP) {
33573
- const _prog = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
33574
- viewEventExec_arr = [];
33575
-
33576
- if (!_prog.progEvents || _.isEmpty(_prog.progEvents)) {
33577
- return 0;
33578
- }
33579
- for await (const event_obj of _prog.progEvents) {
33580
- if (event_obj.data.type !== typeP) continue;
33581
-
33582
- if (_.isEmpty(event_obj.workflow)) continue;
33583
-
33584
- if (event_obj.data.condition) {
33585
- let res = await func.expression.get(SESSION_ID, event_obj.data.condition, paramsP.dsSessionP, 'condition', paramsP.rowIdP, null, null, null, null, event_obj);
33586
- if (!res.result) {
33587
- continue;
33588
- }
33589
- }
33590
-
33591
- for await (const trigger_obj of event_obj.workflow) {
33592
- var expression = undefined;
33593
- var cond = undefined;
33594
- if (!trigger_obj.data.enabled) {
33595
- continue;
33596
- }
33597
- cond = true;
33598
- if (trigger_obj.props.condition) expression = trigger_obj.props.condition;
33599
- var expCond = {};
33600
- if (expression) {
33601
- expCond = await func.expression.get(SESSION_ID, expression, paramsP.dsSessionP, 'condition', paramsP.rowIdP, trigger_obj.data.type); // execute expression
33602
- cond = expCond.result;
33603
- expCond.conditional = true;
33604
- }
33605
-
33606
- if (!trigger_obj.data.action) {
33607
- func.utils.debug_report(SESSION_ID, 'get_view_events_count', `Error initiating ${typeP} prog: ${_ds.viewSourceDesc} reason: missing action`, 'E');
33608
- break;
33609
- }
33610
- if (!glb.REFERENCE_LESS_FUNCTIONS.includes(trigger_obj.data.action) && !trigger_obj.data.name?.prog) {
33611
- func.utils.debug_report(SESSION_ID, 'get_view_events_count', `Error initiating ${typeP} prog: ${_ds.viewSourceDesc} reason: missing reference`, 'E');
33612
- break;
33613
- }
33614
-
33615
- viewEventExec_arr.push({
33616
- eventInfo: trigger_obj,
33617
- eventId: event_obj.id,
33618
- triggerId: trigger_obj.id,
33619
- expression: expression,
33620
- });
33621
- }
33622
- }
33623
- return viewEventExec_arr.length;
33624
- };
33625
- try {
33626
- let count = await get_view_events_count('screen_ready');
33627
-
33628
- if (!count) return;
33629
- return await execute_view_events(sourceP);
33630
- } catch (error) {
33631
- debugger;
33632
- }
33633
- };
33634
- func.UI.screen.screen_loading_done = async function (SESSION_ID, paramsP, $div, jobNoP) {
33635
- // console.log($div.attr('xu-ui-id'));
33636
-
33637
- // await
33638
- let retries = 0;
33639
- let interval = setInterval(() => {
33640
- 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')) {
33641
- retries++;
33642
- if (retries > 100) {
33643
- console.warn('deadlock detected for screen ready');
33644
- } else {
33645
- return $div;
33646
- }
33647
- }
33648
-
33649
- clearInterval(interval);
33650
-
33651
- func.UI.screen.execute_screen_ready_events(SESSION_ID, paramsP, paramsP.screenInfo.properties?.renderType, $div, jobNoP);
33652
- var _session = SESSION_OBJ[SESSION_ID];
33653
- func.events.delete_job(SESSION_ID, jobNoP);
33654
- func.UI.utils.screen_blocker(false, paramsP.prog_id + (paramsP.sourceScreenP ? '_' + paramsP.sourceScreenP : ''));
33655
- if (_session.prog_id === paramsP.prog_id) {
33656
- _session.system_ready = true;
33657
- if (_session.engine_mode === 'live_preview' && STUDIO_PEER_CONN_SEND_METHOD) {
33658
- STUDIO_PEER_CONN_SEND_METHOD({
33659
- service: 'system_ready',
33660
- data: {},
33661
- id: STUDIO_PEER.id,
33662
- source: 'runtime',
33663
- session_id: SESSION_ID,
33664
- app_id: _session.app_id,
33665
- gtp_token: _session.gtp_token,
33666
- app_token: _session.app_token,
33667
- });
33668
- // }
33669
- }
33670
- }
33671
- }, 100);
33672
-
33673
- return $div;
33674
- };
33675
-
33676
- 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) {
33677
- if (!is_skeleton) {
33678
- var _session = SESSION_OBJ[SESSION_ID];
33679
- var _ds = _session.DS_GLB[paramsP.dsSessionP];
33680
- }
33681
- var prop;
33682
- try {
33683
- prop = nodeP.attributes;
33684
- } catch (error) {
33685
- // debugger;
33686
- }
33687
-
33688
- ///////////
33689
- var is_mobile = glb.MOBILE_ARR.includes(paramsP.screenInfo.properties?.menuType) ? true : false;
33690
-
33691
- const get_element_info = function () {
33692
- var ret = {};
33693
- let currentRecordId = _ds?.currentRecordId || '';
33694
-
33695
- let $div = func.UI.utils.find_in_element_data('xuData', $container.parent(), 'nodeid', nodeP.id);
33696
-
33697
- $.each($div, function (key, val) {
33698
- if ($(val)?.data().xuData?.recordid === currentRecordId && $(val)?.data().xuData?.key === keyP && $(val)?.prop('tagName') !== 'XURENDER') {
33699
- ret = {
33700
- div: $div,
33701
- };
33702
- }
33703
- });
33704
-
33705
- return ret;
33706
- };
33707
-
33708
- const init = async function () {
33709
- var ret = true;
33710
- if (!nodeP) ret = false;
33711
- return ret;
33712
- };
33713
- const debug = function (is_errorP, error_descP) {
33714
- func.utils.debug.log(SESSION_ID, paramsP.prog_id + '_' + nodeP.id_org + '_ui_prop', {
33715
- module: 'gui',
33716
- action: 'init',
33717
- prop: nodeP.id,
33718
- details: error_descP,
33719
- result: null,
33720
- error: is_errorP,
33721
- source: _ds?.tree_obj?.menuName || '',
33722
- fields: null,
33723
- type: null,
33724
- prog_id: paramsP.prog_id,
33725
- dsSession: null,
33726
- });
33727
- };
33728
-
33729
- const open_modal = async function ($div) {
33730
- const modal_id = 'app_modal-' + paramsP.dsSessionP.toString();
33731
- var xu_modal_controller = document.querySelector('xu-modal-controller');
33732
- if (!xu_modal_controller) {
33733
- func.UI.component.create_app_modal_component(SESSION_ID, modal_id);
33734
- xu_modal_controller = document.querySelector('xu-modal-controller');
33735
- }
33736
-
33737
- var controller_params = $(xu_modal_controller).data('xuControllerParams');
33738
-
33739
- if (!controller_params) {
33740
- controller_params = {};
33741
- }
33742
-
33743
- var params = {
33744
- menuTitle: paramsP.screenInfo.properties?.menuTitle,
33745
- screenId: paramsP.screenId,
33746
- $dialogDiv: $div.children(),
33747
- $container: $container,
33748
- dsSession: paramsP.dsSessionP,
33749
- };
33750
-
33751
- controller_params[modal_id] = params;
33752
-
33753
- $(xu_modal_controller).data('xuControllerParams', controller_params);
33754
- const modalController = await new UI_FRAMEWORK_PLUGIN.modal();
33755
-
33756
- if (!APP_MODAL_OBJ[modal_id]) {
33757
- const modal = await modalController.create(SESSION_ID, modal_id, paramsP.screenInfo, close_modal);
33758
- APP_MODAL_OBJ[modal_id] = modal;
33759
- } else {
33760
- $(modal_id).empty();
33761
- }
33762
- await modalController.init(SESSION_ID, modal_id);
33763
-
33764
- return $div;
33765
- };
33766
-
33767
- const close_modal = async function (modal_id) {
33768
- delete APP_MODAL_OBJ[modal_id];
33769
- const xu_modal_controller = document.querySelector('xu-modal-controller');
33770
- var params = $(xu_modal_controller).data().xuControllerParams[modal_id];
33771
- if (params && params.$container) {
33772
- await func.UI.screen.validate_exit_events(SESSION_ID, params.$container.data().xuData.paramsP, null);
33773
- func.datasource.clean_all(SESSION_ID, params.dsSession);
33774
- }
33775
- };
33776
-
33777
- const close_all_modals = function () {
33778
- $.each(APP_MODAL_OBJ, function (key, val) {
33779
- if (val) {
33780
- // close_modal(key);
33781
- UI_FRAMEWORK_PLUGIN.modal.close(key);
33782
- }
33783
- });
33784
- };
33785
-
33786
- const open_popover = async function ($div) {
33787
- const xu_popover_controller = func.UI.component.create_app_popover_component(SESSION_ID);
33788
-
33789
- $(xu_popover_controller).data('xuControllerParams', {
33790
- menuTitle: paramsP.screenInfo.properties?.menuTitle,
33791
- screenId: paramsP.screenId,
33792
- $dialogDiv: $div.children(),
33793
- $container: $container,
33794
- });
33795
- const popover = new UI_FRAMEWORK_PLUGIN.popover(
33796
- SESSION_ID,
33797
- // ELEMENT_CLICK_EVENT,
33798
- // props
33799
- );
33800
- await popover.open(SESSION_ID);
33801
- CURRENT_APP_POPOVER = popover;
33802
-
33803
- return;
33804
- popoverController
33805
- .create({
33806
- component: 'xu-popover-content-' + SESSION_ID,
33807
- event: ELEMENT_CLICK_EVENT,
33808
- translucent: true,
33809
- })
33810
- .then((modal) => {
33811
- modal.present().then(() => {
33812
- CURRENT_APP_POPOVER = modal;
33813
-
33814
- if (callbackP) callbackP($div);
33815
- });
33816
- });
33817
- };
33818
- const iterate_child = async function ($divP, nodeP, parent_infoP, $root_container, before_record_function) {
33819
- if (!is_mobile && nodeP.busy) return;
33820
- nodeP.busy = true;
33821
- const done = async function ($divP) {
33822
- setTimeout(function () {
33823
- nodeP.busy = false;
33824
- }, 1000);
33825
-
33826
- return $divP;
33827
- };
33828
- if (!nodeP || !nodeP.children) {
33829
- return await done($divP);
33830
- }
33831
-
33832
- if (before_record_function) {
33833
- await before_record_function();
33834
- }
33835
- if (nodeP?.children?.length) {
33836
- let node_promises = [];
33837
- for (const [key, val] of Object.entries(nodeP.children)) {
33838
- node_promises.push(
33839
- new Promise(async (resolve, reject) => {
33840
- 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);
33841
-
33842
- resolve();
33843
- }),
33844
- );
33845
- }
33846
- await Promise.all(node_promises);
33847
- }
33848
- return await done($divP);
33849
- };
33850
-
33851
- // const iterate_child = async function ($divP, nodeP, parent_infoP, $root_container, before_record_function) {
33852
- // if (!is_mobile && nodeP.busy) return;
33853
- // nodeP.busy = true;
33854
- // const done = async function ($divP) {
33855
- // setTimeout(function () {
33856
- // nodeP.busy = false;
33857
- // }, 1000);
33858
-
33859
- // return $divP;
33860
- // };
33861
- // if (!nodeP || !nodeP.children) {
33862
- // return await done($divP);
33863
- // }
33864
-
33865
- // if (before_record_function) {
33866
- // await before_record_function();
33867
- // }
33868
- // if (nodeP?.children?.length) {
33869
- // for await (const [key, val] of Object.entries(nodeP.children)) {
33870
- // 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);
33871
- // }
33872
- // }
33873
- // return await done($divP);
33874
- // };
33875
-
33876
- const _$ = function ($elm) {
33877
- try {
33878
- const id = $elm.attr('xu-ui-id');
33879
- if (!id || !glb.DEBUG_MODE) return $elm;
33880
- const $el = $(`[xu-ui-id="${id}"]`);
33881
-
33882
- if ($el.length > 1) {
33883
- console.warn('Multiple elements for xu-ui-id: ' + id, $el);
33884
- }
33885
-
33886
- return $($el[0]);
33887
- } catch (e) {
33888
- console.error(e);
33889
- }
33890
- };
33891
-
33892
- const hover_in = function ($div, e) {
33893
- if (is_skeleton || (e && (EXP_BUSY || UI_WORKER_OBJ.jobs.length))) return;
33894
- CLIENT_ACTIVITY_TS = Date.now();
33895
- if (_$($container)?.data()?.xuData?.debug_info) _$($container).data().xuData.debug_info.hover_item = $div.attr('xu-ui-id');
33896
- if (!_ds) return;
33897
- ///////// SET Attributes///////////
33898
- let attributes = {};
33899
- $.each($div[0].attributes, function (index, attr) {
33900
- attributes[attr.name] = attr.value;
33901
- });
33902
-
33903
- _session.DS_GLB[0].data_system.SYS_OBJ_WIN_ELEMENT_HOVERED_ATTRIBUTES = attributes;
33904
- //////////////////////////////////
33905
- if (!$div.data()?.xuData) return;
33906
- const _iterate_info = $div.data().xuData.iterate_info;
33907
- if (_iterate_info) {
33908
- if (_iterate_info.is_key_dynamic_field) {
33909
- _ds.dynamic_fields[_iterate_info.iterator_key].value = _iterate_info._key;
33910
- } else {
33911
- try {
33912
- const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
33913
- _ds.data_feed.rows[row_idx][_iterate_info.iterator_key] = _iterate_info._key;
33914
- } catch (err) {
33915
- console.error(err);
33916
- }
33917
- }
33918
-
33919
- if (_iterate_info.is_val_dynamic_field) {
33920
- _ds.dynamic_fields[_iterate_info.iterator_val].value = _iterate_info._val;
33921
- } else {
33922
- try {
33923
- const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
33924
- _ds.data_feed.rows[row_idx][_iterate_info.iterator_val] = _iterate_info._val;
33925
- } catch (err) {
33926
- console.error(err);
33927
- }
33928
- }
33929
- }
33930
-
33931
- if ($div && _$($div) && _ds && paramsP.renderType === 'grid') {
33932
- func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'update_datasource', { currentRecordId: _$($div).data().xuData.currentRecordId }, null, null, paramsP.dsSessionP);
33933
- }
33934
-
33935
- const set_value = function (field_id, value) {
33936
- var currentRecordId = _$($div).data().xuData.currentRecordId;
33937
-
33938
- func.UI.worker.add_to_queue(
33939
- SESSION_ID,
33940
- 'gui event',
33941
- 'update_datasource',
33942
- {
33943
- currentRecordId,
33944
- field_id,
33945
- field_value: value,
33946
- },
33947
- null,
33948
- null,
33949
- paramsP.dsSessionP,
33950
- );
33951
- };
33952
-
33953
- if ($div?.data()?.iterate_info) {
33954
- var data = $div.data().xuData.iterate_info;
33955
- if (data.iterator_key) {
33956
- set_value(data.iterator_key, data._key);
33957
- }
33958
- if (data.iterator_val) {
33959
- set_value(data.iterator_val, data._val);
33960
- }
33961
- }
33962
- };
33963
- const hover_out = function () {
33964
- if (is_skeleton) return;
33965
-
33966
- CLIENT_ACTIVITY_TS = Date.now();
33967
- if (_$($container)?.data()?.xuData?.debug_info) {
33968
- _$($container).data().xuData.debug_info.hover_item = null;
33969
- }
33970
- if (_ds?.data_system) {
33971
- SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_OBJ_WIN_ELEMENT_HOVERED_ATTRIBUTES = {};
33972
- }
33973
- };
33974
- const render_screen_type = async function ($div) {
33975
- const set_call_screen_properties_values = async function (ui_framework) {
33976
- params.properties = {};
33977
- const get_values = async function (property) {
33978
- var property_value = paramsP?.screenInfo?.properties?.[property] || paramsP?.screenInfo?.properties?.frameworkProperties?.[property];
33979
- if (paramsP?.call_screen_propertiesP) {
33980
- if (paramsP.call_screen_propertiesP?.[property]) {
33981
- property_value = paramsP.call_screen_propertiesP[property];
33982
- }
33983
- if (paramsP.call_screen_propertiesP[`xu-exp:${property}`]) {
33984
- property_value = (await func.expression.get(SESSION_ID, paramsP.call_screen_propertiesP[`xu-exp:${property}`], paramsP.dsSessionP, property)).result;
33985
- }
33986
- }
33987
- return property_value;
33988
- };
33989
- params.properties['name'] = await get_values('menuTitle');
33990
- if (await ui_framework?.properties()) {
33991
- for await (const [key, val] of Object.entries(await ui_framework.properties())) {
33992
- params.properties[key] = await get_values(key);
33993
- }
33994
- }
33995
- };
33996
-
33997
- var $div_content = $div.children();
33998
-
33999
- $.each($div_content, function (key, val) {
34000
- if (!$(val)?.data()?.xuData?.parent_container) {
34001
- return true;
34002
- }
34003
- $(val).data().xuData.parent_container = $div.data().xuData.parent_container;
34004
- });
34005
-
34006
- let $ret = $div;
34007
- var $nav = $(SESSION_OBJ[SESSION_ID].root_element).find('xu-nav');
34008
- var params;
34009
- switch (paramsP.screen_type) {
34010
- case 'modal':
34011
- const modal_id = 'app_modal-' + paramsP.dsSessionP.toString();
34012
- var xu_modal_controller = document.querySelector('xu-modal-controller');
34013
- if (!xu_modal_controller) {
34014
- func.UI.component.create_app_modal_component(SESSION_ID, modal_id);
34015
- xu_modal_controller = document.querySelector('xu-modal-controller');
34016
- }
34017
-
34018
- var controller_params = $(xu_modal_controller).data('xuControllerParams');
34019
-
34020
- if (!controller_params) {
34021
- controller_params = {};
34022
- }
34023
-
34024
- params = {
34025
- screenId: paramsP.screenId,
34026
- $dialogDiv: $div.children(),
34027
- $container: $container,
34028
- dsSession: paramsP.dsSessionP,
34029
- modal_id,
34030
- screenInfo: paramsP.screenInfo,
34031
- close_callback: close_modal,
34032
- paramsP,
34033
- };
34034
-
34035
- controller_params[modal_id] = params;
34036
-
34037
- $(xu_modal_controller).data('xuControllerParams', controller_params);
34038
- const modalController = await new UI_FRAMEWORK_PLUGIN.modal();
34039
- await set_call_screen_properties_values(modalController);
34040
- if (!APP_MODAL_OBJ[modal_id]) {
34041
- const modal = await modalController.create(params);
34042
-
34043
- APP_MODAL_OBJ[modal_id] = modal;
34044
- } else {
34045
- $(modal_id).empty();
34046
- }
34047
-
34048
- await modalController.init(params);
34049
-
34050
- break;
34051
-
34052
- case 'popover':
34053
- // open_popover($div);
34054
-
34055
- const xu_popover_controller = func.UI.component.create_app_popover_component(SESSION_ID);
34056
- params = {
34057
- menuTitle: paramsP.screenInfo.properties?.menuTitle,
34058
- screenId: paramsP.screenId,
34059
- $dialogDiv: $div.children(),
34060
- $container: $container,
34061
- };
34062
-
34063
- $(xu_popover_controller).data('xuControllerParams', params);
34064
- const popover = new UI_FRAMEWORK_PLUGIN.popover(SESSION_ID);
34065
- await set_call_screen_properties_values(popover);
34066
- await popover.open(params);
34067
- CURRENT_APP_POPOVER = popover;
34068
-
34069
- func.UI.utils.screen_blocker(false, paramsP.prog_id + '_' + paramsP.sourceScreenP);
34070
- break;
34071
-
34072
- case 'page':
34073
- const nav = $nav[0];
34074
-
34075
- params = {
34076
- div: $div_content,
34077
- name: paramsP.screenInfo.properties?.menuTitle,
34078
- screenId: paramsP.screenId,
34079
- $container: $container,
34080
- dsSession: paramsP.dsSessionP,
34081
- SESSION_ID,
34082
- nav,
34083
- paramsP,
34084
- };
34085
-
34086
- var component_name = 'xu-page-component-' + paramsP.dsSessionP;
34087
- if (!$(nav).data().xuData.nav_params) {
34088
- $(nav).data().xuData.nav_params = {};
34089
- }
34090
-
34091
- //restore validate
34092
- if ($(nav)?.data()?.xuData?.params?.[paramsP.dsSessionP]) {
34093
- params.$container.data().xuData.validate_screen_ready = $(nav).data().xuData.params[paramsP.dsSessionP].$container.data().xuData.validate_screen_ready;
34094
- }
34095
-
34096
- if (!$(nav)?.data()?.xuData) return;
34097
- $(nav).data().xuData.nav_params[paramsP.dsSessionP] = params;
34098
- if (!$(component_name).length) {
34099
- await func.UI.component.create_app_page_component(SESSION_ID, paramsP.dsSessionP);
34100
- const page = new UI_FRAMEWORK_PLUGIN.page();
34101
- await set_call_screen_properties_values(page);
34102
- await page.create(params);
34103
- await page.init(params);
34104
- nav.push(component_name, { params });
34105
- } else {
34106
- debugger;
34107
- $(component_name).empty();
34108
-
34109
- await UI_FRAMEWORK_PLUGIN.page(SESSION_ID, paramsP.dsSessionP);
34110
- }
34111
- $div.data().xuData.paramsP = $container.data().xuData.paramsP;
34112
- break;
34113
-
34114
- case 'panel':
34115
- $container.append($div_content);
34116
- $ret = $container;
34117
- break;
34118
-
34119
- default: // set data to nav to use in the component
34120
- if ($nav && $nav.length) {
34121
- // refresh made
34122
- } else {
34123
- $nav = $('<xu-nav>'); //.attr('xu-ui-id', SESSION_ID);
34124
- $container.append($nav);
34125
- func.UI.component.init_xu_nav($container, $nav);
34126
- }
34127
-
34128
- $nav.data().xuData.$div = $div_content;
34129
-
34130
- await $nav[0].setRoot('xu-root-component-' + SESSION_ID);
34131
- $ret = $container;
34132
- break;
34133
- }
34134
- return $ret;
34135
- };
34136
-
34137
- if (!(await init())) return;
34138
- debug();
34139
- const fx = {
34140
- widget: async function () {
34141
- var _session = SESSION_OBJ[SESSION_ID];
34142
-
34143
- var exist_elm_obj = get_element_info();
34144
- var $div = exist_elm_obj.div;
34145
- if (!exist_elm_obj.div) {
34146
- $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);
34147
-
34148
- //////////////////////////
34149
-
34150
- let plugin_name = prop['xu-widget'],
34151
- method = prop['xu-method'],
34152
- dsP = paramsP.dsSessionP,
34153
- propsP = prop,
34154
- sourceP = 'widgets';
34155
-
34156
- // const set_SYS_GLOBAL_OBJ_WIDGET_INFO = async function (docP) {
34157
- // var obj = _.clone(docP);
34158
- // obj.date = await func.utils.get_dateTime(
34159
- // SESSION_ID,
34160
- // "SYS_DATE",
34161
- // docP.date
34162
- // );
34163
- // obj.time = await func.utils.get_dateTime(
34164
- // SESSION_ID,
34165
- // "SYS_TIME",
34166
- // docP.date
34167
- // );
34168
-
34169
- // var datasource_changes = {
34170
- // [0]: {
34171
- // ["data_system"]: {
34172
- // ["SYS_GLOBAL_OBJ_WIDGET_INFO"]: obj,
34173
- // },
34174
- // },
34175
- // };
34176
- // await func.datasource.update(SESSION_ID, datasource_changes);
34177
- // };
34178
- const call_plugin_api = async function (plugin_nameP, dataP) {
34179
- return await func.utils.call_plugin_api(SESSION_ID, plugin_nameP, dataP);
34180
- };
34181
- const report_error = function (descP, warn) {
34182
- func.utils.debug.log(SESSION_ID, _session.DS_GLB[dsP].prog_id + '_' + _session.DS_GLB[dsP].callingMenuId, {
34183
- module: 'widgets',
34184
- action: 'Init',
34185
- source: sourceP,
34186
- prop: descP,
34187
- details: descP,
34188
- result: null,
34189
- error: warn ? false : true,
34190
- fields: null,
34191
- type: 'widgets',
34192
- prog_id: _session.DS_GLB[dsP].prog_id,
34193
- });
34194
- };
34195
- const get_fields_data = async function (fields, props) {
34196
- const report_error = function (descP, warn) {
34197
- func.utils.debug.log(SESSION_ID, _session.DS_GLB[dsP].prog_id + '_' + _session.DS_GLB[dsP].callingMenuId, {
34198
- module: 'widgets',
34199
- action: 'Init',
34200
- source: sourceP,
34201
- prop: descP,
34202
- details: descP,
34203
- result: null,
34204
- error: warn ? false : true,
34205
- fields: null,
34206
- type: 'widgets',
34207
- prog_id: _session.DS_GLB[dsP].prog_id,
34208
- });
34209
- };
34210
- const get_property_value = async function (fieldIdP, val) {
34211
- if (!val) return;
34212
- var value = fieldIdP in props ? props[fieldIdP] : typeof val.defaultValue === 'function' ? val?.defaultValue?.() : val?.defaultValue;
34213
- if (val.render === 'eventId') {
34214
- value = props?.[fieldIdP]?.event;
34215
- }
34216
-
34217
- if (props[`xu-exp:${fieldIdP}`]) {
34218
- value = (await func.expression.get(SESSION_ID, props[`xu-exp:${fieldIdP}`], dsP, 'widget property')).result;
34219
- }
34220
-
34221
- return func.common.get_cast_val(
34222
- SESSION_ID,
34223
- 'widgets',
34224
- fieldIdP,
34225
- val.type, //val.type !== "string" || val.type !== "number" ? "string" : val.type,
34226
- value,
34227
- null,
34228
- );
34229
- };
34230
- var data_obj = {};
34231
- var return_code = 1;
34232
- // $.each(fields, function (key, val) {
34233
- for await (const [key, val] of Object.entries(fields)) {
34234
- data_obj[key] = await get_property_value(key, val);
34235
- if (!data_obj[key] && val.mandatory) {
34236
- return_code = -1;
34237
- report_error(`${key} is a mandatory field.`);
34238
- break;
34239
- }
34240
- // console.log(val);
34241
- }
34242
- for await (const key of ['xu-bind']) {
34243
- data_obj[key] = await get_property_value(key, props[key]);
34244
- }
34245
-
34246
- return { code: return_code, data: data_obj };
34247
- };
34248
-
34249
- const load_css_style = function () {
34250
- const get_css_path = function (resource) {
34251
- if (_session.worker_type === 'Dev') {
34252
- return `../../plugins/${plugin_name}/${resource}`;
34253
- }
34254
- 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}`;
34255
- };
34256
- let path = get_css_path('style.css');
34257
- func.utils.load_css_on_demand(path);
34258
- };
34259
-
34260
- const _plugin = APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];
34261
- const index = await func.utils.get_plugin_resource(SESSION_ID, plugin_name, `${_plugin.manifest['index.mjs'].dist ? 'dist/' : ''}index.mjs`);
34262
- const methods = index.methods;
34263
- if (methods && !methods[method]) {
34264
- return report_error('method not found');
34265
- }
34266
-
34267
- const fields_ret = await get_fields_data(methods[method].fields, propsP);
34268
- if (fields_ret.code < 0) {
34269
- return report_error(fields_ret.data);
34270
- }
34271
- const fields = fields_ret.data;
34272
-
34273
- let exclude_attributes = [];
34274
- for await (const [key, val] of Object.entries(propsP)) {
34275
- if (typeof fields[key] !== 'undefined' || typeof fields[`xu-exp:${key}`] !== 'undefined') {
34276
- exclude_attributes.push(key);
34277
- }
34278
- }
34279
-
34280
- 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);
34281
-
34282
- $div.addClass('widget_wrapper'); // class get override in set_attributes_new
34283
-
34284
- if (!APP_OBJ[_session.app_id].app_plugins_purchased[plugin_name]) {
34285
- return report_error(`plugin ${plugin_name} not found`);
34286
- }
34287
-
34288
- if (APP_OBJ[_session.app_id].app_plugins_purchased[plugin_name].manifest['style.css'].exist) {
34289
- load_css_style();
34290
- }
34291
-
34292
- const plugin_setup_ret = await func.utils.get_plugin_setup(SESSION_ID, plugin_name);
34293
- if (plugin_setup_ret.code < 0) {
34294
- return report_error(plugin_setup_ret);
34295
- }
34296
-
34297
- const api_utils = await func.common.get_module(SESSION_ID, 'xuda-api-library.mjs', {
34298
- func,
34299
- glb,
34300
- SESSION_OBJ,
34301
- SESSION_ID,
34302
- APP_OBJ,
34303
- dsSession: paramsP.dsSessionP,
34304
- job_id: jobNoP,
34305
- });
34306
-
34307
- const params = {
34308
- SESSION_ID,
34309
- method,
34310
- _session,
34311
- dsP,
34312
- sourceP,
34313
- propsP,
34314
- plugin_name,
34315
- $containerP: $div,
34316
- plugin_setup: plugin_setup_ret.data,
34317
-
34318
- report_error,
34319
- call_plugin_api,
34320
- // set_SYS_GLOBAL_OBJ_WIDGET_INFO,
34321
- api_utils,
34322
- };
34323
-
34324
- const fx = await func.utils.get_plugin_resource(SESSION_ID, plugin_name, `${_plugin.manifest['runtime.mjs'].dist ? 'dist/' : ''}runtime.mjs`);
34325
-
34326
- if (_plugin?.manifest?.['runtime.mjs'].dist && _plugin?.manifest?.['runtime.mjs']?.css) {
34327
- const plugin_runtime_css_url = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, 'dist/runtime.css');
34328
- func.utils.load_css_on_demand(plugin_runtime_css_url);
34329
- }
34330
-
34331
- if (!fx[method]) {
34332
- throw `Method: ${method} does not exist`;
34333
- }
34334
- try {
34335
- await fx[method](fields, params);
34336
- } catch (err) {
34337
- func.utils.debug_report(SESSION_ID, `${plugin_name} widget`, err.message, 'E');
34338
- }
34339
- }
34340
- return $div;
34341
- },
34342
- [`xu-single-view`]: async function () {
34343
- var exist_elm_obj = get_element_info();
34344
- var $div = exist_elm_obj.div;
34345
-
34346
- if (!exist_elm_obj.div) {
34347
- var $wrapper = $('<div>');
34348
- $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, '');
34349
-
34350
- if (!$div) return;
34351
-
34352
- if (!REFRESHER_IN_PROGRESS && (paramsP.is_mobile_popover || paramsP.is_mobile_page)) {
34353
- close_all_modals();
34354
- }
34355
-
34356
- $div.hover(
34357
- function (e) {
34358
- hover_in();
34359
- // func.UI.screen.hover_in(SESSION_ID, null, $container, paramsP, is_skeleton);
34360
- },
34361
- function (e) {
34362
- // func.UI.screen.hover_out(SESSION_ID, $container, is_skeleton, paramsP);
34363
- hover_out();
34364
- },
34365
- );
34366
- }
34367
-
34368
- const ret = await iterate_child($div, nodeP, null, $div);
34369
- if (_.isEmpty($container.data().xuAttributes)) {
34370
- await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
34371
- }
34372
-
34373
- $.each($div.data().xuData, function (key, val) {
34374
- $container.data().xuData[key] = _.cloneDeep(val);
34375
- });
34376
- $.each($div.data().xuAttributes, function (key, val) {
34377
- $container.data().xuAttributes[key] = _.cloneDeep(val);
34378
- });
34379
-
34380
- return await render_screen_type($div);
34381
- },
34382
- [`xu-multi-view`]: async function () {
34383
- var $div = $container;
34384
-
34385
- if (!$div.data().xuData.node || !$div.data().xuData.node.children) {
34386
- $div.data().xuData.node = nodeP;
34387
- }
34388
-
34389
- if (!$div.data().xuData.debug_info) {
34390
- $div.data().xuData.debug_info = {
34391
- id: nodeP.id,
34392
- parent_id: $container.data().xuData.ui_id,
34393
- };
34394
- }
34395
-
34396
- const done = async function (continuous_idx) {
34397
- // const do_callback = async function ($div) {
34398
- // // if ($root_container.data().xuData.progress_bar_circle) {
34399
- // // setTimeout(function () {
34400
- // // $.each(
34401
- // // $root_container.data().xuData.progress_bar_circle,
34402
- // // function (key, val) {
34403
- // // val.bar.set(parseFloat(val.value)); // Number from 0.0 to 1.0
34404
- // // }
34405
- // // );
34406
- // // }, 2000);
34407
- // // }
34408
-
34409
- // if (paramsP.screenInfo.properties?.rtl) {
34410
- // $div_content.attr('dir', 'rtl');
34411
- // }
34412
-
34413
- // return $div;
34414
- // };
34415
- await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
34416
-
34417
- return await render_screen_type($div);
34418
- };
34419
-
34420
- if (!REFRESHER_IN_PROGRESS && (paramsP.is_mobile_popover || paramsP.is_mobile_page)) {
34421
- close_all_modals();
34422
- }
34423
-
34424
- const empty_result = async function () {
34425
- // var content = prop.empty_result_content || '';
34426
-
34427
- // var res = await func.expression.get(
34428
- // SESSION_ID,
34429
- // content, // prop["xu-exp:empty_result_content"],
34430
- // paramsP.dsSessionP,
34431
- // 'empty_result_content_EXP',
34432
- // _ds.currentRecordId,
34433
- // );
34434
- // content = res.result;
34435
-
34436
- // let empty_result_node = {
34437
- // type: 'element',
34438
- // id: crypto.randomUUID(),
34439
- // content,
34440
- // // : content || (typeof content === "undefined" && "Empty results"),
34441
- // tagName: 'div',
34442
- // attributes: {},
34443
- // children: [],
34444
- // };
34445
-
34446
- // 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);
34447
- await func.events.validate(SESSION_ID, 'record_not_found', paramsP.dsSessionP);
34448
- return await done(null);
34449
- };
34450
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
34451
-
34452
- var continuous_idx = null;
34453
-
34454
- if (!_ds.data_feed || _.isEmpty(_ds.data_feed.rows)) {
34455
- return await empty_result();
34456
- }
34457
-
34458
- var i = 0;
34459
- for await (const [key, val] of Object.entries(_ds.data_feed.rows)) {
34460
- var node = JSON.parse(JSON.stringify(nodeP));
34461
-
34462
- _ds.currentRecordId = val._ROWID;
34463
- const ret = await iterate_child($div, node, { continuous_idx }, $root_container);
34464
-
34465
- if (_.isEmpty($container.data().xuAttributes)) {
34466
- await func.UI.screen.set_attributes_new(SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, $container, true);
34467
- }
34468
- }
34469
-
34470
- return await done(continuous_idx);
34471
- },
34472
- [`xu-panel`]: async function () {
34473
- const done = async function ($new_div) {
34474
- if (!$container.data()?.xuData?.paramsP) {
34475
- return $container;
34476
- }
34477
- var $div_items = $div.data().xuData.node.children;
34478
-
34479
- await func.UI.screen.panel_post_render_handler(SESSION_ID, $container, $new_div, nodeP, $div, jobNoP);
34480
-
34481
- // TO FIX should be timeout
34482
- $container.data().xuData.node.children = $div_items;
34483
-
34484
- return $container;
34485
- };
34486
-
34487
- var $wrapper = $('<div>');
34488
- $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, '');
34489
-
34490
- 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);
34491
- if (ret.abort) {
34492
- // render N
34493
- return (ret.$new_div = $('<template>').append($div));
34494
- }
34495
-
34496
- let $ret_panel_div = ret.$new_div;
34497
-
34498
- if (!$ret_panel_div?.children()?.length) {
34499
- ////// render default children tree
34500
- if (nodeP.children.length) {
34501
- $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);
34502
- }
34503
- }
34504
-
34505
- let ret_done = await done($ret_panel_div);
34506
-
34507
- return ret_done;
34508
- },
34509
- };
34510
-
34511
- const draw_html_element_org = async function (element) {
34512
- const done = async function (ret = {}) {
34513
- return $div;
34514
- };
34515
- if (!element || element === 'script') return await done();
34516
- let str = '';
34517
-
34518
- 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);
34519
-
34520
- $div.hover(
34521
- function (e) {
34522
- hover_in($div, e);
34523
- },
34524
- function (e) {
34525
- hover_out();
34526
- },
34527
- );
34528
- if (paramsP.paramsP === 'grid' || parent_infoP?.iterate_info) {
34529
- $div.on('click contextmenu', function (e) {
34530
- hover_in($div, e);
34531
- });
34532
- }
34533
-
34534
- // 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);
34535
- 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);
34536
- 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'])) {
34537
- return await done(ret);
34538
- }
34539
- // check if iterator made to prevent children render
34540
-
34541
- if (nodeP?.attributes?.['xu-viewport'] == 'true') {
34542
- // const xu_viewport = async function () {
34543
- // const data = { $div: $div.clone(true), nodeP, parent_infoP, $root_container, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, $container };
34544
- // const container_id = $container.attr('xu-ui-id');
34545
- // if (!UI_WORKER_OBJ.pending_for_viewport_render[container_id]) {
34546
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id] = { base_$div: $div, data: [], $container };
34547
- // await iterate_child($div, nodeP, parent_infoP, $root_container);
34548
- // } else {
34549
- // $div.remove();
34550
- // }
34551
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id].data.push(data);
34552
-
34553
- // // if (!$div.children().length) {
34554
- // // // render the first element to determine height
34555
- // // await iterate_child($div, nodeP, parent_infoP, $root_container);
34556
- // // // hover_in($div);
34557
- // // // func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'render_viewport', data, null, null, paramsP.dsSessionP);
34558
- // // } else {
34559
- // // }
34560
- // };
34561
- const xu_viewport = function () {
34562
- const observer_inViewport = new IntersectionObserver(
34563
- function (entries) {
34564
- entries.forEach((entry) => {
34565
- if (entry.isIntersecting) {
34566
- $(entry.target).trigger('inViewport');
34567
-
34568
- // Optional: stop observing once triggered
34569
- observer_inViewport.unobserve(entry.target);
34570
- }
34571
- });
34572
- },
34573
- {
34574
- threshold: 0.1, // Trigger when 10% of element is visible
34575
- },
34576
- );
34577
-
34578
- const observer_outViewport = new IntersectionObserver(
34579
- function (entries) {
34580
- entries.forEach((entry) => {
34581
- if (!entry.isIntersecting) {
34582
- // Element is OUT of viewport - trigger custom event
34583
- $(entry.target).trigger('outViewport');
34584
-
34585
- // Optional: stop observing once triggered
34586
- // observer_outViewport.unobserve(entry.target);
34587
- }
34588
- });
34589
- },
34590
- {
34591
- threshold: 0, // Trigger when element is completely out of view
34592
- },
34593
- );
34594
-
34595
- let ui_job_id;
34596
- $div.on('inViewport', function () {
34597
- if ($div.children().length) {
34598
- $div.removeClass('skeleton');
34599
- return;
34600
- }
34601
-
34602
- // if (UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')]) {
34603
- // $div[0].style.removeProperty('height');
34604
- // $div.removeClass('skeleton');
34605
- // $div.html(UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')]);
34606
- // } else {
34607
- hover_in($div);
34608
- 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);
34609
- // }
34610
- observer_outViewport.observe($div[0]);
34611
- });
34612
-
34613
- $div.on('outViewport', function () {
34614
- func.UI.worker.delete_job(SESSION_ID, ui_job_id);
34615
-
34616
- if ($div.children().length) {
34617
- // UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')] = $div.children().clone(true);
34618
- $div.empty();
34619
- const height = $div?.data()?.xuData?.viewport_height || 10;
34620
- if (typeof height !== 'undefined') {
34621
- $div.css('height', height);
34622
- }
34623
- }
34624
- // $div.addClass('skeleton');
34625
- observer_inViewport.observe($div[0]);
34626
- });
34627
- $div.addClass('skeleton');
34628
- observer_inViewport.observe($div[0]);
34629
- };
34630
- xu_viewport();
34631
- } else {
34632
- await iterate_child($div, nodeP, parent_infoP, $root_container);
34633
- }
34634
-
34635
- // const ret_iterate_child = await iterate_child($div, nodeP, parent_infoP, null, $root_container);
34636
- return await done(ret);
34637
- };
34638
-
34639
- const draw_html_element = async function (element) {
34640
- const done = async function (ret = {}) {
34641
- const xu_ui_id = $div.attr('xu-ui-id');
34642
- $div.removeClass('display_none');
34643
- if (ret.has_xu_exp_render_attribute) {
34644
- // $div.css('display', 'unset');
34645
-
34646
- 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 || {}));
34647
- const _$div = $div.clone(true);
34648
- UI_WORKER_OBJ.xu_render_cache[xu_ui_id + xu_render_cache_id] = { $div: _$div, paramsP, data: _$div.data() };
34649
- nodeP.xu_render_xu_ui_id = xu_ui_id;
34650
- nodeP.xu_render_cache_id = xu_render_cache_id;
34651
-
34652
- if (ret.xu_render_background_processing) {
34653
- temp_$div.remove();
34654
- // $container.find(`[xu-ui-id="${xu_ui_id}"]`).remove();
34655
- return $div;
34656
- } else {
34657
- // $div.css('display', 'unset');
34658
- temp_$div.replaceWith($div);
34659
- return $div;
34660
- }
34661
- } else {
34662
- if (ret.has_xu_render_attribute) {
34663
- temp_$div.remove();
34664
- return $div;
34665
- }
34666
- // $div.css('display', 'unset');
34667
- temp_$div.replaceWith($div);
34668
- return $div;
34669
- }
34670
- };
34671
- if (!element || element === 'script') return await done();
34672
- let str = '';
34673
-
34674
- 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);
34675
-
34676
- let temp_$container = $('<tmp>').data('xuData', $container.data().xuData);
34677
- let $div = temp_$div.clone(true);
34678
-
34679
- // $div.css('display', 'none');
34680
-
34681
- $div.hover(
34682
- function (e) {
34683
- hover_in($div, e);
34684
- },
34685
- function (e) {
34686
- hover_out();
34687
- },
34688
- );
34689
- if (paramsP.paramsP === 'grid' || parent_infoP?.iterate_info) {
34690
- $div.on('click contextmenu', function (e) {
34691
- hover_in($div, e);
34692
- });
34693
- }
34694
-
34695
- 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);
34696
- 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'])) {
34697
- return await done(ret);
34698
- }
34699
- // check if iterator made to prevent children render
34700
-
34701
- if (nodeP?.attributes?.['xu-viewport'] == 'true') {
34702
- // const xu_viewport = async function () {
34703
- // const data = { $div: $div.clone(true), nodeP, parent_infoP, $root_container, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, $container };
34704
- // const container_id = $container.attr('xu-ui-id');
34705
- // if (!UI_WORKER_OBJ.pending_for_viewport_render[container_id]) {
34706
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id] = { base_$div: $div, data: [], $container };
34707
- // await iterate_child($div, nodeP, parent_infoP, $root_container);
34708
- // } else {
34709
- // $div.remove();
34710
- // }
34711
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id].data.push(data);
34712
-
34713
- // // if (!$div.children().length) {
34714
- // // // render the first element to determine height
34715
- // // await iterate_child($div, nodeP, parent_infoP, $root_container);
34716
- // // // hover_in($div);
34717
- // // // func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'render_viewport', data, null, null, paramsP.dsSessionP);
34718
- // // } else {
34719
- // // }
34720
- // };
34721
- const xu_viewport = function () {
34722
- const observer_inViewport = new IntersectionObserver(
34723
- function (entries) {
34724
- entries.forEach((entry) => {
34725
- if (entry.isIntersecting) {
34726
- $(entry.target).trigger('inViewport');
34727
-
34728
- // Optional: stop observing once triggered
34729
- observer_inViewport.unobserve(entry.target);
34730
- }
34731
- });
34732
- },
34733
- {
34734
- threshold: 0.1, // Trigger when 10% of element is visible
34735
- },
34736
- );
34737
-
34738
- const observer_outViewport = new IntersectionObserver(
34739
- function (entries) {
34740
- entries.forEach((entry) => {
34741
- if (!entry.isIntersecting) {
34742
- // Element is OUT of viewport - trigger custom event
34743
- $(entry.target).trigger('outViewport');
34744
-
34745
- // Optional: stop observing once triggered
34746
- // observer_outViewport.unobserve(entry.target);
34747
- }
34748
- });
34749
- },
34750
- {
34751
- threshold: 0, // Trigger when element is completely out of view
34752
- },
34753
- );
34754
-
34755
- let ui_job_id;
34756
- $div.on('inViewport', function () {
34757
- if ($div.children().length) {
34758
- $div.removeClass('skeleton');
34759
- return;
34760
- }
34761
-
34762
- // if (UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')]) {
34763
- // $div[0].style.removeProperty('height');
34764
- // $div.removeClass('skeleton');
34765
- // $div.html(UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')]);
34766
- // } else {
34767
- hover_in($div);
34768
- 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);
34769
- // }
34770
- observer_outViewport.observe($div[0]);
34771
- });
34772
-
34773
- $div.on('outViewport', function () {
34774
- func.UI.worker.delete_job(SESSION_ID, ui_job_id);
34775
-
34776
- if ($div.children().length) {
34777
- // UI_WORKER_OBJ.cache[$div.attr('xu-ui-id')] = $div.children().clone(true);
34778
- $div.empty();
34779
- const height = $div?.data()?.xuData?.viewport_height || 10;
34780
- if (typeof height !== 'undefined') {
34781
- $div.css('height', height);
34782
- }
34783
- }
34784
- // $div.addClass('skeleton');
34785
- observer_inViewport.observe($div[0]);
34786
- });
34787
- $div.addClass('skeleton');
34788
- observer_inViewport.observe($div[0]);
34789
- };
34790
- xu_viewport();
34791
- } else {
34792
- // if (ret.xu_render_background_processing) {
34793
- // // let temp_$div = $div.clone(true);
34794
- // iterate_child($div, nodeP, parent_infoP, $root_container);
34795
- // } else {
34796
- // await iterate_child($div, nodeP, parent_infoP, $root_container);
34797
- // }
34798
- if (!ret.xu_render_background_processing) {
34799
- iterate_child($div, nodeP, parent_infoP, $root_container);
34800
- }
34801
- }
34802
-
34803
- // const ret_iterate_child = await iterate_child($div, nodeP, parent_infoP, null, $root_container);
34804
- return await done(ret);
34805
- };
34806
-
34807
- if (nodeP.content && nodeP.attributes) {
34808
- nodeP.attributes['xu-content'] = nodeP.content;
34809
- }
34810
-
34811
- if (nodeP.tagName === 'xu-widget') {
34812
- if (is_skeleton) return;
34813
- return await fx['widget']();
34814
- }
34815
- if (fx[nodeP.tagName]) {
34816
- return await fx[nodeP.tagName]();
34817
- }
34818
- // const xu_viewport = async function () {
34819
- // const data = { $div, nodeP, parent_infoP, $root_container, paramsP, jobNoP, is_skeleton, keyP, refreshed_ds, parent_nodeP, check_existP, $container };
34820
- // const container_id = $container.attr('xu-ui-id');
34821
- // if (!UI_WORKER_OBJ.pending_for_viewport_render[container_id]) {
34822
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id] = { base_$div: $div, data: [], $container };
34823
- // await iterate_child($div, nodeP, parent_infoP, $root_container);
34824
- // }
34825
- // UI_WORKER_OBJ.pending_for_viewport_render[container_id].data.push(data);
34826
- // };
34827
-
34828
- // if (nodeP?.attributes?.['xu-viewport'] == 'true') {
34829
- // return await xu_viewport();
34830
- // } else {
34831
- if (!glb.new_xu_render) {
34832
- return await draw_html_element_org(nodeP.tagName);
34833
- }
34834
- return await draw_html_element(nodeP.tagName);
34835
-
34836
- // }
34837
- };
34838
-
34839
- func.UI.screen.refresh_document_changes_for_realtime_update = async function (SESSION_ID, doc_change) {
34840
- let _session = SESSION_OBJ[SESSION_ID];
34841
- for (const [key, _ds] of Object.entries(_session.DS_GLB)) {
34842
- let prog_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
34843
- if (prog_obj?.progDataSource?.dataSourceRealtime && prog_obj?.progDataSource?.dataSourceTableId === doc_change.table_id) {
34844
- try {
34845
- // disabled in purpose to support create row
34846
-
34847
- if (!_ds.screen_params) continue;
34848
- if (_ds.screen_params.is_panelP) {
34849
- func.UI.screen.refresh_screen(SESSION_ID, null, key);
34850
- } else {
34851
- func.action.execute(SESSION_ID, 'act_refresh', _ds, null, null);
34852
- }
34853
- } catch (err) {
34854
- // console.error(err);
34855
- }
34856
- }
34857
- }
34858
-
34859
- if (glb.new_xu_render) {
34860
- for (const [ui_cache_key, ui_cache_val] of Object.entries(UI_WORKER_OBJ.xu_render_cache)) {
34861
- let prog_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, ui_cache_val.paramsP.prog_id);
34862
- if (prog_obj?.progDataSource?.dataSourceTableId === doc_change.table_id) {
34863
- ui_cache_val.$div = null;
34864
- }
34865
- }
34866
- }
34867
- };
34868
-
34869
- const get_parent_ds_fields = function (SESSION_ID, dsSessionP) {
34870
- var _session = SESSION_OBJ[SESSION_ID];
34871
- var _ds = _session.DS_GLB[dsSessionP];
34872
-
34873
- const idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
34874
- const data = _ds.data_feed.rows[idx];
34875
-
34876
- let obj = {};
34877
-
34878
- if (typeof _ds.parentDataSourceNo !== 'undefined') {
34879
- obj = get_parent_ds_fields(SESSION_ID, _ds.parentDataSourceNo);
34880
- }
34881
-
34882
- return { ...data, ...obj };
34883
- };
34884
-
34885
- const get_xu_render_cache_str = async function (SESSION_ID, dsSessionP, exclude_vars = []) {
34886
- const fields_obj = get_parent_ds_fields(SESSION_ID, dsSessionP);
34887
-
34888
- let str = '';
34889
-
34890
- for (const [key, val] of Object.entries(fields_obj)) {
34891
- if (exclude_vars.includes(key)) continue;
34892
- str += typeof val !== 'undefined' ? JSON.stringify(val) : '';
34893
- }
34894
-
34895
- return 'C-' + (await func.common.sha256(str));
34896
- };
34897
- func.UI.component = {};
32688
+ func.UI.component = {};
34898
32689
 
34899
32690
  func.UI.component.create_app_modal_component = function (
34900
32691
  SESSION_ID,