@xuda.io/xuda-worker-bundle 1.3.1178 → 1.3.1180

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.
Files changed (2) hide show
  1. package/index.js +1 -1772
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7533,1778 +7533,7 @@ func.utils.set_SYS_GLOBAL_OBJ_WIDGET_INFO = async function (SESSION_ID, docP) {
7533
7533
  await func.datasource.update(SESSION_ID, datasource_changes);
7534
7534
  };
7535
7535
 
7536
- func.events = {};
7537
- func.events.validate = async function (
7538
- SESSION_ID,
7539
- triggerP,
7540
- dsSessionP,
7541
- eventIdP,
7542
- sourceP,
7543
- argumentsP,
7544
- return_validation_onlyP
7545
- ) {
7546
- var _session = SESSION_OBJ[SESSION_ID];
7547
- var _ds = _session.DS_GLB[dsSessionP];
7548
- var args = {
7549
- triggerP,
7550
- dsSessionP,
7551
- eventIdP,
7552
-
7553
- sourceP,
7554
- argumentsP,
7555
- return_validation_onlyP,
7556
- };
7557
- const search_event_in_parent_ds = async function () {
7558
- if (_ds && typeof _ds.parentDataSourceNo !== "undefined") {
7559
- await func.events.validate(
7560
- SESSION_ID,
7561
- triggerP,
7562
- _ds.parentDataSourceNo,
7563
- eventIdP,
7564
- sourceP,
7565
- argumentsP,
7566
- return_validation_onlyP
7567
- );
7568
- }
7569
- };
7570
- var ret = false;
7571
- var jobs = [];
7572
-
7573
- // var success;
7574
- if (_ds?.prog_id) {
7575
- const _view_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
7576
- // check view exist
7577
- if (!glb.IS_WORKER) _ds.event_stat_obj = {};
7578
-
7579
- if (_view_obj.progEvents) {
7580
- if (_session.api_callback && eventIdP) {
7581
- _session.api_callback(eventIdP, SESSION_ID, SESSION_OBJ);
7582
- }
7583
- // check events has rows
7584
- for await (let val of _view_obj.progEvents) {
7585
- //run events rows
7586
- var eventProp = undefined;
7587
- if (val.data.type === triggerP) {
7588
- // compare event trigger
7589
- if (
7590
- (triggerP !== "user_defined") |
7591
- (triggerP === "user_defined" && eventIdP === val.data.event_name)
7592
- ) {
7593
- // compare user defined name
7594
-
7595
- var expCond;
7596
- if (val.data.condition)
7597
- expCond = await func.expression.get(
7598
- SESSION_ID,
7599
- val.data.condition,
7600
- dsSessionP,
7601
- "condition"
7602
- );
7603
- if (!val.data.condition || expCond.result) {
7604
- func.utils.debug.watch(
7605
- SESSION_ID,
7606
- _ds.prog_id + "%" + val.id,
7607
- "view_event",
7608
- val,
7609
- triggerP + " " + eventIdP,
7610
- expCond
7611
- );
7612
- ret = true;
7613
- if (return_validation_onlyP) break;
7614
- const set_arguments = async function () {
7615
- var args = argumentsP || {};
7616
-
7617
- for await (let [key, fieldId] of Object.entries(
7618
- val.data.parameters
7619
- )) {
7620
- const field_info = func.common.find_item_by_key(
7621
- _view_obj.progFields,
7622
- "field_id",
7623
- fieldId
7624
- );
7625
-
7626
- var value = await func.common.get_cast_val(
7627
- SESSION_ID,
7628
- "events",
7629
- fieldId,
7630
- field_info.props.fieldType,
7631
- args[fieldId]
7632
- );
7633
-
7634
- const ret = await func.datasource.get_value(
7635
- SESSION_ID,
7636
- fieldId,
7637
- dsSessionP,
7638
- _ds.currentRecordId
7639
- );
7640
-
7641
- const datasource_changes = {
7642
- [ret.dsSessionP]: {
7643
- [ret.currentRecordId]: { [fieldId]: value },
7644
- },
7645
- };
7646
- await func.datasource.update(SESSION_ID, datasource_changes);
7647
- }
7648
-
7649
- add_event();
7650
- };
7651
- var add_event = function () {
7652
- const _event = func.common.find_item_by_key_root(
7653
- _view_obj.progEvents,
7654
- "id",
7655
- val.id
7656
- );
7657
- if (_event.triggers) {
7658
- // check if event property exist
7659
-
7660
- if (!_event.triggers || _.isEmpty(_event.triggers)) return;
7661
- // check events has rows
7662
- for (const trigger_obj of _event.triggers) {
7663
- //run events rows
7664
- if (!trigger_obj.data.action) continue;
7665
- if (!trigger_obj.data.enabled) continue;
7666
- // condition ok
7667
- var callingEventId = val.data.event_name;
7668
- if (!callingEventId) callingEventId = val.id; // default event id when event name is missing
7669
- // eventProp = trigger_obj;
7670
-
7671
- // success = true;
7672
- const ref_id = trigger_obj.data.name;
7673
-
7674
- var container = undefined;
7675
- var screen_prop = undefined;
7676
- if (!glb.IS_WORKER) {
7677
- if (_ds.panel_div_id) {
7678
- try {
7679
- container = "#" + _ds.panel_div_id;
7680
- if ($(container).data().xuData.panel_info) {
7681
- screen_prop =
7682
- $(container).data().xuData.panel_info.paramsP;
7683
- } else {
7684
- ///////////////
7685
- container =
7686
- "#" + _session.DS_GLB[dsSessionP].screenId;
7687
-
7688
- if ($(container) && $(container).data()) {
7689
- screen_prop = $(container).data().xuData.paramsP;
7690
- }
7691
-
7692
- if (!$(container) || !$(container).length) {
7693
- container =
7694
- "#" + _session.DS_GLB[dsSessionP].containerId;
7695
- }
7696
- //////////////
7697
- }
7698
- } catch (e) {
7699
- console.error(e);
7700
- }
7701
- } else {
7702
- container = "#" + _ds.screenId;
7703
-
7704
- if ($(container) && $(container).data()) {
7705
- screen_prop = $(container).data().xuData.paramsP;
7706
- }
7707
-
7708
- if (!$(container) || !$(container).length) {
7709
- container = "#" + _ds.containerId;
7710
- }
7711
- }
7712
- } else {
7713
- screen_prop = {
7714
- callingContainerP: _ds.containerId,
7715
- };
7716
- }
7717
-
7718
- jobs.push(
7719
- func.events.add_to_queue(
7720
- SESSION_ID,
7721
- sourceP + " event",
7722
- trigger_obj.id,
7723
- null, // was click
7724
- trigger_obj.data.action,
7725
- ref_id,
7726
- container,
7727
- null,
7728
- _ds.currentRecordId,
7729
- null,
7730
- trigger_obj.data.name,
7731
- null,
7732
- null,
7733
- dsSessionP,
7734
- null,
7735
- null,
7736
- trigger_obj,
7737
- triggerP,
7738
- screen_prop,
7739
- null, // was target frame id
7740
- null,
7741
- trigger_obj,
7742
- trigger_obj.data.parameter_source_data,
7743
- val.id,
7744
- null,
7745
- args,
7746
- null,
7747
- null
7748
- )
7749
- );
7750
- }
7751
- }
7752
- };
7753
- if (val.data.parameters) {
7754
- await set_arguments();
7755
- } else {
7756
- add_event();
7757
- }
7758
- } else {
7759
- if (val.data.condition && !expCond.result) {
7760
- func.utils.debug.watch(
7761
- SESSION_ID,
7762
- _ds.prog_id + "%" + val.id,
7763
- "view_event",
7764
- val,
7765
- triggerP + " " + eventIdP,
7766
- expCond,
7767
- true
7768
- );
7769
- }
7770
- }
7771
- }
7772
- }
7773
- }
7774
- }
7775
- }
7776
- if (return_validation_onlyP) return ret;
7777
- if (!ret) await search_event_in_parent_ds();
7778
-
7779
- return jobs;
7780
- };
7781
- func.events.add_to_queue = async function (
7782
- SESSION_ID,
7783
- typeP,
7784
- eventIdP,
7785
- triggerP,
7786
- functionP,
7787
- refIdP,
7788
- containerP,
7789
- elementP,
7790
- rowP,
7791
- NA_colP,
7792
- descP,
7793
- NA_rootScreenIdP,
7794
- NA_callingEventIdP,
7795
- dsSessionP,
7796
- NA_isInitP,
7797
- NA_calling_program,
7798
- event_propertiesP,
7799
- calling_triggerP,
7800
- paramsP,
7801
- NA_target_frame_idP,
7802
- _NA2,
7803
- calling_trigger_prop,
7804
- argumentsP,
7805
- source_event_idP,
7806
- calling_job,
7807
- args,
7808
- $div,
7809
- $container
7810
- ) {
7811
- var _session = SESSION_OBJ[SESSION_ID];
7812
- var obj = {
7813
- SESSION_ID,
7814
- typeP,
7815
- eventIdP,
7816
- triggerP,
7817
- functionP,
7818
- refIdP,
7819
- containerP,
7820
- elementP,
7821
- rowP,
7822
- descP,
7823
- dsSessionP,
7824
- event_propertiesP,
7825
- calling_triggerP,
7826
- paramsP,
7827
- calling_trigger_prop,
7828
- argumentsP,
7829
- source_event_idP,
7830
- calling_job,
7831
- args,
7832
- $div,
7833
- $container,
7834
-
7835
- job_num: _session.WORKER_OBJ.num,
7836
- };
7837
- var _ds = _session.DS_GLB[dsSessionP];
7838
- if (typeof dsSessionP !== "undefined" && dsSessionP !== null) {
7839
- obj.prog_id = _ds.prog_id;
7840
- obj.parentDataSourceNo = _ds.parentDataSourceNo;
7841
- obj.nodeId = _ds.nodeId;
7842
- }
7843
- ///////
7844
- if (glb.IS_WORKER && func.utils.is_onscreen_event(functionP)) {
7845
- obj.client = true;
7846
- if (functionP === "call_library") {
7847
- obj.client = false;
7848
- }
7849
- if (typeof dsSessionP !== "undefined" && dsSessionP !== null) {
7850
- obj.ds_obj = func.utils.clean_returned_datasource(SESSION_ID, dsSessionP);
7851
- }
7852
- if (obj.client) {
7853
- _session.WORKER_OBJ.num++;
7854
- // if (!_session.IS_API)
7855
- func.utils.post_back_to_client(
7856
- SESSION_ID,
7857
- "job",
7858
- _session.worker_id,
7859
- obj
7860
- );
7861
- return;
7862
- }
7863
- }
7864
- ////////
7865
-
7866
- if (calling_job) {
7867
- var job_index = func.events.find_job_index(SESSION_ID, calling_job);
7868
-
7869
- try {
7870
- if (!_session.WORKER_OBJ.jobs[job_index].splice_count) {
7871
- _session.WORKER_OBJ.jobs[job_index].splice_count = 0;
7872
- }
7873
- _session.WORKER_OBJ.jobs[job_index].splice_count++;
7874
- _session.WORKER_OBJ.jobs.splice(
7875
- job_index + _session.WORKER_OBJ.jobs[job_index].splice_count,
7876
- 0,
7877
- obj
7878
- );
7879
- // }
7880
- } catch (e) {
7881
- console.error("bug");
7882
- // _session.WORKER_OBJ.jobs.splice(0, 0, obj);
7883
- }
7884
- } else {
7885
- _session.WORKER_OBJ.jobs.push(obj);
7886
- }
7887
-
7888
- _session.WORKER_OBJ.num++;
7889
- return _session.WORKER_OBJ.num - 1;
7890
- };
7891
- func.events.find_job_index = function (SESSION_ID, jobNoP) {
7892
- var _session = SESSION_OBJ[SESSION_ID];
7893
- var ret = null;
7894
- if (!_session.WORKER_OBJ) return ret;
7895
- _.forEach(_session.WORKER_OBJ.jobs, function (val, key) {
7896
- if (val && val.job_num == jobNoP) {
7897
- ret = key;
7898
- return false;
7899
- }
7900
- });
7901
- return ret;
7902
- };
7903
- func.events.execute = async function (
7904
- SESSION_ID,
7905
- jobNoP,
7906
- eventIdP,
7907
- triggerP,
7908
- functionP,
7909
- refIdP,
7910
- containerP,
7911
- elementP,
7912
- rowP,
7913
- NA_colP,
7914
- descP,
7915
- rootScreenIdP,
7916
- dsSessionP,
7917
- NA_callingEventIdP,
7918
- callingSourceP,
7919
- NA_isInitP,
7920
- event_propertiesP,
7921
- calling_triggerP,
7922
- calling_jobP,
7923
- paramsP,
7924
- NA_target_frame_idP,
7925
- calling_trigger_prop,
7926
- NA_calling_program,
7927
- argumentsP,
7928
- NA_viewIdP,
7929
- NA_nodeIdP,
7930
- NA_parentDataSourceNoP,
7931
- $div
7932
- ) {
7933
- var _session = SESSION_OBJ[SESSION_ID];
7934
- var _ds = _session.DS_GLB[dsSessionP];
7935
- if (functionP === "update") refIdP = null; // in case of left over when program changing from call function to update
7936
-
7937
- var job_index = func.events.find_job_index(SESSION_ID, jobNoP);
7938
- if (_session.WORKER_OBJ.jobs?.[job_index]?.stat === "busy") {
7939
- if (jobNoP) _session.WORKER_OBJ.stat = job_index;
7940
- return;
7941
- }
7942
- if (jobNoP && !_session.WORKER_OBJ.jobs[job_index]) {
7943
- _session.WORKER_OBJ.stat = null;
7944
- return;
7945
- }
7946
-
7947
- if (jobNoP) _session.WORKER_OBJ.stat = job_index;
7948
-
7949
- if (jobNoP && calling_trigger_prop?.props?.async) {
7950
- func.events.delete_job(SESSION_ID, jobNoP);
7951
- _session.WORKER_OBJ.stat = null;
7952
- }
7953
-
7954
- if (_session.WORKER_OBJ.jobs[job_index]) {
7955
- _session.WORKER_OBJ.jobs[job_index].stat = "busy";
7956
- }
7957
-
7958
- var dsSession = dsSessionP; // new 2020420
7959
- var field_elm = elementP;
7960
-
7961
- var calling_field_id = field_elm;
7962
- if (field_elm && typeof field_elm === "object")
7963
- calling_field_id = field_elm.attr("xu-ui-id");
7964
-
7965
- var log_nodeId;
7966
- var log_prog_id;
7967
- var log_source;
7968
-
7969
- if (_session.DS_GLB[dsSession]?.prog_id)
7970
- log_prog_id = _session.DS_GLB[dsSession].prog_id;
7971
- log_nodeId = log_prog_id + "_" + eventIdP;
7972
- var log_prop = callingSourceP;
7973
- if (callingSourceP === "system event") {
7974
- log_prop = "global event";
7975
- }
7976
- if (calling_field_id) {
7977
- const _view_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
7978
- let _field_obj = func.common.find_item_by_key(
7979
- _view_obj.progFields,
7980
- "field_id",
7981
- calling_field_id
7982
- );
7983
- log_nodeId = log_prog_id + "_" + eventIdP + "_" + _field_obj?.id;
7984
-
7985
- log_source = calling_field_id;
7986
- }
7987
- if (elementP) {
7988
- log_prop = triggerP;
7989
- log_nodeId = log_nodeId + "_ui_prop"; //+"_"+eventIdP;
7990
- }
7991
- //check condition
7992
- var expCond;
7993
- if (event_propertiesP) {
7994
- // conditional event
7995
- if (event_propertiesP?.props?.condition) {
7996
- expCond = await func.expression.get(
7997
- SESSION_ID,
7998
- event_propertiesP.props.condition,
7999
- dsSession,
8000
- "condition",
8001
- null,
8002
- null,
8003
- null,
8004
- calling_field_id ? calling_field_id : calling_triggerP,
8005
- null,
8006
- descP
8007
- ); // execute expression
8008
- func.utils.debug.log(SESSION_ID, log_nodeId, {
8009
- module: "event",
8010
- action: log_prop,
8011
- source: log_source,
8012
- prop: descP,
8013
- details: event_propertiesP.props.condition,
8014
- result: expCond.result,
8015
- error: expCond.error,
8016
- fields: expCond.fields,
8017
- type: "event",
8018
- prog_id: log_prog_id,
8019
- conditional: true,
8020
- });
8021
- var cond = expCond.result;
8022
- if (!cond || expCond.error) {
8023
- // condition failed // === true 03/04/16
8024
- func.events.delete_job(SESSION_ID, jobNoP);
8025
-
8026
- func.utils.debug.watch(
8027
- SESSION_ID,
8028
- calling_trigger_prop?.id,
8029
- functionP,
8030
- "",
8031
- "",
8032
- expCond,
8033
- true
8034
- );
8035
- return;
8036
- }
8037
- } // Non conditional event
8038
- else {
8039
- func.utils.debug.log(SESSION_ID, log_nodeId, {
8040
- module: "event",
8041
- action: log_prop,
8042
- source: log_source,
8043
- prop: descP,
8044
- details: null,
8045
- result: null,
8046
- error: null,
8047
- fields: null,
8048
- type: "event",
8049
- prog_id: log_prog_id,
8050
- });
8051
- }
8052
- }
8053
-
8054
- // var log_error = function (descP, detailsP, warning) {
8055
- // func.utils.debug.log(SESSION_ID, log_nodeId, {
8056
- // module: "event",
8057
- // action: functionP,
8058
- // source: log_source,
8059
- // prop: descP,
8060
- // details: detailsP,
8061
- // result: null,
8062
- // error: !warning,
8063
- // warning: warning,
8064
- // fields: null,
8065
- // type: "event",
8066
- // prog_id: log_prog_id,
8067
- // });
8068
- // };
8069
-
8070
- const get_params_obj = async function () {
8071
- const _prog = await func.utils.VIEWS_OBJ.get(
8072
- SESSION_ID,
8073
- await get_prog_id()
8074
- );
8075
- if (!_prog) {
8076
- func.events.delete_job(SESSION_ID, jobNoP);
8077
- return func.utils.debug_report(
8078
- SESSION_ID,
8079
- "func.events.execute",
8080
- "Program not found: " + refIdP.prog,
8081
- "E"
8082
- );
8083
- }
8084
-
8085
- // get in parameters
8086
- var params_obj = {};
8087
- if (_prog?.properties?.progParams) {
8088
- for await (const [key, val] of Object.entries(
8089
- _prog.properties.progParams
8090
- )) {
8091
- if (!val.data.dir === "in") continue;
8092
- if (
8093
- typeof args.parameters_obj_inP?.[val.data.parameter] !== "undefined"
8094
- ) {
8095
- if (args.parameters_obj_inP?.[val.data.parameter].fx) {
8096
- let ret = await func.expression.get(
8097
- SESSION_ID,
8098
- args.parameters_obj_inP?.[val.data.parameter].fx,
8099
- dsSession,
8100
- "parameters"
8101
- );
8102
- params_obj[val.data.parameter] = ret.result;
8103
- } else {
8104
- params_obj[val.data.parameter] =
8105
- args.parameters_obj_inP?.[val.data.parameter].value;
8106
- }
8107
- continue;
8108
- }
8109
- console.warn(
8110
- `Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`
8111
- );
8112
- }
8113
- }
8114
- return params_obj;
8115
- };
8116
-
8117
- const get_prog_id = async function () {
8118
- let _prop = args?.calling_trigger_prop?.data?.name?.properties;
8119
- let _prog_id = args.prog_id;
8120
- if (_prop?.["xu-exp:prog"]) {
8121
- _prog_id = (
8122
- await func.expression.get(
8123
- SESSION_ID,
8124
- _prop["xu-exp:prog"],
8125
- dsSession,
8126
- "prog_id expression"
8127
- )
8128
- ).result;
8129
- }
8130
-
8131
- return _prog_id;
8132
- };
8133
- // const get_args_property_value = async function (prop_name) {
8134
- // let _prop = args?.calling_trigger_prop?.data?.name;
8135
- // let _value = _prop[prop_name];
8136
- // if (_prop?.[`xu-exp:${prop_name}`]) {
8137
- // _value = (
8138
- // await func.expression.get(
8139
- // SESSION_ID,
8140
- // _prop[`xu-exp:${prop_name}`],
8141
- // dsSession,
8142
- // `${prop_name} expression`
8143
- // )
8144
- // ).result;
8145
- // }
8146
-
8147
- // return _value;
8148
- // };
8149
-
8150
-
8151
- var args = {
8152
- prog_id: refIdP?.prog,
8153
- screenIdP: refIdP?.prog,
8154
- callingFieldIdP: field_elm,
8155
- dataSourceNoP: null,
8156
- parentDataSourceNoP: dsSession,
8157
- triggerIdP: eventIdP,
8158
- containerIdP: null,
8159
- rowIdP: rowP, //sub_row_idP ? sub_row_idP : rowP,
8160
- jobNoP: jobNoP,
8161
-
8162
- callingSourceP: callingSourceP,
8163
- calling_jobP: calling_jobP,
8164
- screen_dsP: null,
8165
- is_panelP: null,
8166
- argument_listP: null,
8167
- calling_trigger_prop: calling_trigger_prop,
8168
- parameters_obj_inP: refIdP?.parameters,
8169
- call_screen_propertiesP: refIdP?.properties,
8170
- };
8171
-
8172
- const fx = {
8173
- Call_window: async function () {
8174
- var is_panel;
8175
- var $calling_container;
8176
- if (_session.WORKER_OBJ.jobs[job_index]) {
8177
- if (_session.WORKER_OBJ.jobs[job_index].paramsP) {
8178
- $calling_container = $(
8179
- "#" + _session.WORKER_OBJ.jobs[job_index].paramsP.callingContainerP
8180
- );
8181
- } else {
8182
- $calling_container = ""; // calling from datasource 0
8183
- _session.WORKER_OBJ.jobs[job_index].paramsP = {};
8184
- }
8185
- }
8186
-
8187
- if (!refIdP.prog) {
8188
- func.events.delete_job(SESSION_ID, jobNoP);
8189
- return func.utils.debug_report(
8190
- SESSION_ID,
8191
- "func.events.execute",
8192
- "Program is empty",
8193
- "E"
8194
- );
8195
- }
8196
-
8197
- const params_obj = await get_params_obj();
8198
- return await func.UI.screen.init(
8199
- SESSION_ID,
8200
- await get_prog_id(),
8201
- $(containerP)?.data()?.xuData.screenId,
8202
- _session.DS_GLB[dsSession],
8203
- $calling_container,
8204
- eventIdP,
8205
- rowP,
8206
- jobNoP,
8207
- is_panel,
8208
- params_obj,
8209
- functionP,
8210
- args.call_screen_propertiesP
8211
- );
8212
- },
8213
- call_modal: async function () {
8214
- return await fx.Call_window();
8215
- },
8216
- call_popover: async function () {
8217
- return await fx.Call_window();
8218
- },
8219
- call_page: async function () {
8220
- return await fx.Call_window();
8221
- },
8222
- call_library: async function () {
8223
- let plugin_name = refIdP.plugin_name,
8224
- method = refIdP.library_method,
8225
- $containerP = $div,
8226
- dsP = dsSession,
8227
- propsP = refIdP.library_props,
8228
- sourceP = descP;
8229
-
8230
- var _session = SESSION_OBJ[SESSION_ID];
8231
-
8232
- const set_SYS_GLOBAL_OBJ_WIDGET_INFO = async function (docP) {
8233
- var obj = _.clone(docP);
8234
- obj.date = await func.utils.get_dateTime(
8235
- SESSION_ID,
8236
- "SYS_DATE",
8237
- docP.date
8238
- );
8239
- obj.time = await func.utils.get_dateTime(
8240
- SESSION_ID,
8241
- "SYS_TIME",
8242
- docP.date
8243
- );
8244
-
8245
- var datasource_changes = {
8246
- [0]: {
8247
- ["data_system"]: {
8248
- ["SYS_GLOBAL_OBJ_WIDGET_INFO"]: obj,
8249
- },
8250
- },
8251
- };
8252
- await func.datasource.update(SESSION_ID, datasource_changes);
8253
- };
8254
- const call_plugin_api = async function (plugin_nameP, dataP) {
8255
- return await func.utils.call_plugin_api(
8256
- SESSION_ID,
8257
- plugin_nameP,
8258
- dataP
8259
- );
8260
- };
8261
- const report_error = function (descP, warn) {
8262
- func.utils.debug.log(
8263
- SESSION_ID,
8264
- _session.DS_GLB[dsP].prog_id +
8265
- "_" +
8266
- _session.DS_GLB[dsP].callingMenuId,
8267
- {
8268
- module: "widgets",
8269
- action: "Init",
8270
- source: sourceP,
8271
- prop: descP,
8272
- details: descP,
8273
- result: null,
8274
- error: warn ? false : true,
8275
- fields: null,
8276
- type: "widgets",
8277
- prog_id: _session.DS_GLB[dsP].prog_id,
8278
- }
8279
- );
8280
- };
8281
- const get_fields_data = async function (fields, props) {
8282
- const report_error = function (descP, warn) {
8283
- func.utils.debug.log(
8284
- SESSION_ID,
8285
- _session.DS_GLB[dsP].prog_id +
8286
- "_" +
8287
- _session.DS_GLB[dsP].callingMenuId,
8288
- {
8289
- module: "widgets",
8290
- action: "Init",
8291
- source: sourceP,
8292
- prop: descP,
8293
- details: descP,
8294
- result: null,
8295
- error: warn ? false : true,
8296
- fields: null,
8297
- type: "widgets",
8298
- prog_id: _session.DS_GLB[dsP].prog_id,
8299
- }
8300
- );
8301
- };
8302
- const get_property_value = async function (fieldIdP, val) {
8303
- // var value = props[fieldIdP];
8304
-
8305
- var value =
8306
- props[fieldIdP] ||
8307
- (typeof val.defaultValue === "function"
8308
- ? val?.defaultValue?.()
8309
- : val?.defaultValue);
8310
-
8311
- if (props[`xu-exp:${fieldIdP}`]) {
8312
- value = (
8313
- await func.expression.get(
8314
- SESSION_ID,
8315
- props[`xu-exp:${fieldIdP}`],
8316
- dsP,
8317
- "widget property"
8318
- )
8319
- ).result;
8320
- }
8321
-
8322
- return func.common.get_cast_val(
8323
- SESSION_ID,
8324
- "widgets",
8325
- fieldIdP,
8326
- val.type, //val.type !== "string" || val.type !== "number" ? "string" : val.type,
8327
- value,
8328
- null
8329
- );
8330
- };
8331
- var data_obj = {};
8332
- var return_code = 1;
8333
- // $.each(fields, function (key, val) {
8334
- for await (const [key, val] of Object.entries(fields)) {
8335
- try {
8336
- data_obj[key] = await get_property_value(key, val);
8337
- if (!data_obj[key] && val.mandatory) {
8338
- return_code = -1;
8339
- report_error(`${key} is a mandatory field.`);
8340
- break;
8341
- }
8342
- // console.log(val);
8343
- } catch (error) {
8344
- debugger;
8345
- }
8346
- }
8347
- return { code: return_code, data: data_obj };
8348
- };
8349
-
8350
- try {
8351
- const _plugin =
8352
- APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];
8353
-
8354
- const index = await func.utils.get_plugin_resource(
8355
- SESSION_ID,
8356
- plugin_name,
8357
- `${_plugin.manifest["index.mjs"].dist ? "dist/" : ""}index.mjs`
8358
- );
8359
-
8360
- const methods = index.methods;
8361
- if (methods && !methods[method]) {
8362
- return report_error("method not found");
8363
- }
8364
-
8365
- const fields_ret = await get_fields_data(
8366
- methods[method].fields,
8367
- propsP
8368
- );
8369
-
8370
- if (fields_ret.code < 0) {
8371
- return report_error(fields_ret.data);
8372
- }
8373
- const fields = fields_ret.data;
8374
-
8375
- const plugin_setup_ret = await func.utils.get_plugin_setup(
8376
- SESSION_ID,
8377
- plugin_name
8378
- );
8379
- if (plugin_setup_ret.code < 0) {
8380
- return report_error(plugin_setup_ret);
8381
- }
8382
-
8383
- const api_utils = await func.common.get_module(
8384
- SESSION_ID,
8385
- "xuda-api-library.mjs",
8386
- {
8387
- func,
8388
- glb,
8389
- SESSION_OBJ,
8390
- SESSION_ID,
8391
- APP_OBJ,
8392
- dsSession: dsP,
8393
- job_id: jobNoP,
8394
- }
8395
- );
8396
-
8397
- const params = {
8398
- SESSION_ID,
8399
- method,
8400
- _session,
8401
- dsP,
8402
- sourceP,
8403
- propsP,
8404
- plugin_name,
8405
- $containerP,
8406
- plugin_setup: plugin_setup_ret.data,
8407
-
8408
- report_error,
8409
- call_plugin_api,
8410
- set_SYS_GLOBAL_OBJ_WIDGET_INFO,
8411
- api_utils,
8412
- };
8413
-
8414
- const fx = await func.utils.get_plugin_resource(
8415
- SESSION_ID,
8416
- plugin_name,
8417
- `${_plugin.manifest["runtime.mjs"].dist ? "dist/" : ""}runtime.mjs`
8418
- );
8419
-
8420
- if (!fx[method]) {
8421
- throw `Method: ${method} does not exist`;
8422
- }
8423
- await fx[method](fields, params);
8424
- } catch (err) {
8425
- report_error(err);
8426
- }
8427
-
8428
- func.events.delete_job(SESSION_ID, jobNoP);
8429
- },
8430
-
8431
- call_native_javascript: async function () {
8432
- const module = await func.common.get_module(
8433
- SESSION_ID,
8434
- "xuda-event-javascript-module.mjs"
8435
- );
8436
- return await module.call_javascript(
8437
- SESSION_ID,
8438
- jobNoP,
8439
- refIdP,
8440
- dsSession
8441
- );
8442
- },
8443
- call_evaluate_javascript: async function () {
8444
- const module = await func.common.get_module(
8445
- SESSION_ID,
8446
- "xuda-event-javascript-module.mjs"
8447
- );
8448
- return await module.call_javascript(
8449
- SESSION_ID,
8450
- jobNoP,
8451
- refIdP,
8452
- dsSession,
8453
- true
8454
- );
8455
- },
8456
- execute_native_javascript: async function () {
8457
- const module = await func.common.get_module(
8458
- SESSION_ID,
8459
- "xuda-event-javascript-module.mjs"
8460
- );
8461
-
8462
- const result = await module.run_javascript(
8463
- SESSION_ID,
8464
- jobNoP,
8465
- dsSession,
8466
- `(async function(el) {
8467
- ${refIdP.value}
8468
- })(document.querySelector(\`[xu-ui-id=${elementP}]\`))`
8469
- );
8470
- return result
8471
- },
8472
- execute_evaluate_javascript: async function () {
8473
- const module = await func.common.get_module(
8474
- SESSION_ID,
8475
- "xuda-event-javascript-module.mjs"
8476
- );
8477
-
8478
- return await module.run_javascript(
8479
- SESSION_ID,
8480
- jobNoP,
8481
- dsSession,
8482
- `(async function(el) {
8483
- ${refIdP.value}
8484
- })(document.querySelector(\`[xu-ui-id=${elementP}]\`))`,
8485
- true
8486
- );
8487
- },
8488
- loader_on: async function () {
8489
- glb.CURRENT_APP_LOADING = null;
8490
- LOADER_ACTIVE = true;
8491
- LOADER_TEXT = descP;
8492
- // }
8493
- func.events.delete_job(SESSION_ID, jobNoP);
8494
- // if (callbackP) callbackP();
8495
- },
8496
- loader_off: async function () {
8497
- LOADER_ACTIVE = false;
8498
-
8499
- func.events.delete_job(SESSION_ID, jobNoP);
8500
- // if (callbackP) callbackP();
8501
- },
8502
- emit_event: async function () {
8503
- if (refIdP.value) {
8504
- // if (descP.value) {
8505
- $(document).trigger(refIdP.value, [_session.DS_GLB[dsSession]]);
8506
- } else {
8507
- func.utils.debug_report(
8508
- SESSION_ID,
8509
- "func.events.execute",
8510
- "Event name missing",
8511
- "E"
8512
- );
8513
- }
8514
- func.events.delete_job(SESSION_ID, jobNoP);
8515
- // if (callbackP) callbackP();
8516
- },
8517
-
8518
- invoke_action: async function () {
8519
- func.utils.debug.watch(
8520
- SESSION_ID,
8521
- calling_trigger_prop?.id,
8522
- functionP,
8523
- null,
8524
- null,
8525
- expCond
8526
- );
8527
-
8528
- await func.action.execute(
8529
- SESSION_ID,
8530
- refIdP.value,
8531
- _ds,
8532
- null,
8533
- null,
8534
- jobNoP,
8535
- containerP
8536
- );
8537
- },
8538
- raise_event: async function () {
8539
- var _ds = _session.DS_GLB[dsSession];
8540
- const _view_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, _ds.prog_id);
8541
- if (callingSourceP === "grid" || callingSourceP === "form") {
8542
- let _field_obj = func.common.find_item_by_key(
8543
- _view_obj.progFields,
8544
- "field_id",
8545
- field_elm
8546
- );
8547
- var event_name = _field_obj?.triggers?.[eventIdP].name.event;
8548
-
8549
- if (_field_obj?.triggers?.[eventIdP].name?.properties["xu-exp:event"]) {
8550
- event_name = (
8551
- await func.expression.get(
8552
- SESSION_ID,
8553
- props[`xu-exp:event`],
8554
- dsSession,
8555
- "event_name expression"
8556
- )
8557
- ).result;
8558
- }
8559
-
8560
- if (field_elm && event_name) {
8561
- // get container for fields events
8562
- const dsP = await func.datasource.find_event_dataSource(
8563
- SESSION_ID,
8564
- event_name,
8565
- dsSession
8566
- );
8567
-
8568
- return await func.datasource.run_events_functions(
8569
- SESSION_ID,
8570
- dsP,
8571
- event_name,
8572
- jobNoP,
8573
- null
8574
- );
8575
- }
8576
- // done_execution(event_name);
8577
- }
8578
- if (callingSourceP.includes("event")) {
8579
- let event_name = refIdP.event;
8580
-
8581
- if (refIdP?.properties?.["xu-exp:event"]) {
8582
- event_name = (
8583
- await func.expression.get(
8584
- SESSION_ID,
8585
- refIdP.properties["xu-exp:event"],
8586
- dsSession,
8587
- "event_name expression"
8588
- )
8589
- ).result;
8590
- }
8591
-
8592
- const dsP = await func.datasource.find_event_dataSource(
8593
- SESSION_ID,
8594
- event_name,
8595
- dsSession
8596
- );
8597
-
8598
- await func.datasource.run_events_functions(
8599
- SESSION_ID,
8600
- dsP,
8601
- event_name,
8602
- jobNoP,
8603
- null
8604
- );
8605
- // done_execution(event_name);
8606
- }
8607
-
8608
- func.events.delete_job(SESSION_ID, jobNoP);
8609
- // if (callbackP) callbackP();
8610
-
8611
- func.utils.debug.watch(
8612
- SESSION_ID,
8613
- calling_trigger_prop?.id,
8614
- functionP,
8615
- "",
8616
- "",
8617
- expCond
8618
- );
8619
- },
8620
- get_data: async function () {
8621
- const params_obj = await get_params_obj();
8622
-
8623
- if (!(await get_prog_id())) {
8624
- func.utils.debug_report(
8625
- SESSION_ID,
8626
- "func.events.execute",
8627
- `${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,
8628
- "E"
8629
- );
8630
- func.events.delete_job(SESSION_ID, jobNoP);
8631
- return;
8632
- }
8633
-
8634
- var _ds = _session.DS_GLB[dsSession];
8635
- if (!_ds) {
8636
- func.events.delete_job(SESSION_ID, jobNoP);
8637
- return;
8638
- }
8639
-
8640
- // args.prog_id = _viewId;
8641
- if (_ds) {
8642
- func.utils.debug.watch(
8643
- SESSION_ID,
8644
- calling_trigger_prop?.id,
8645
- functionP,
8646
- null,
8647
- calling_trigger_prop,
8648
- expCond
8649
- );
8650
- // }
8651
- const ret = await func.datasource.create(
8652
- SESSION_ID,
8653
- await get_prog_id(),
8654
- args.dataSourceNoP,
8655
- args.parentDataSourceNoP,
8656
- args.containerIdP,
8657
- args.rowIdP,
8658
- args.jobNoP,
8659
- args.calling_trigger_prop,
8660
- null,
8661
- null,
8662
- args.callingSourceP,
8663
- args.calling_jobP,
8664
- args.screen_dsP,
8665
- args.is_panelP,
8666
- params_obj
8667
- );
8668
-
8669
- let _ds_new = _session.DS_GLB[ret.dsSessionP];
8670
- let parameters = args?.calling_trigger_prop?.data?.name?.parameters;
8671
- if (parameters && !_.isEmpty(parameters)) {
8672
- await func.datasource.update_changes_for_out_parameter(
8673
- SESSION_ID,
8674
- _ds_new.dsSession,
8675
- _ds.dsSession
8676
- );
8677
- }
8678
- // if (parameters && !_.isEmpty(parameters) && _ds_new.PARAM_OUT_INFO) {
8679
- // let data = {};
8680
- // for await (const [key, val] of Object.entries(
8681
- // _ds_new.PARAM_OUT_INFO
8682
- // )) {
8683
- // if (val.prop === "out") {
8684
- // try {
8685
- // const row_idx = func.common.find_ROWID_idx(
8686
- // _ds_new,
8687
- // _ds_new.currentRecordId
8688
- // );
8689
- // data[val.details] =
8690
- // _ds_new.data_feed.rows[row_idx][val.fieldId];
8691
- // } catch (err) {
8692
- // console.error(err);
8693
- // }
8694
- // }
8695
- // }
8696
- // if (!_.isEmpty(data)) {
8697
- // let datasource_changes = {
8698
- // [_ds.dsSession]: { [_ds.currentRecordId]: data },
8699
- // };
8700
- // await func.datasource.update(SESSION_ID, datasource_changes);
8701
- // }
8702
- // }
8703
-
8704
- func.events.delete_job(SESSION_ID, jobNoP);
8705
- return _ds_new
8706
- }
8707
- },
8708
- set_data: async function () {
8709
- return this.get_data();
8710
- },
8711
- batch: async function () {
8712
- const result = await this.get_data();
8713
- debugger
8714
- // await set_outputField(SESSION_ID, elementP, triggerP, functionP, dsSessionP, result);
8715
- return result
8716
-
8717
- },
8718
- update: async function () {
8719
- const obj_values_to_update =
8720
- func.datasource.get_viewFields_for_update_function(
8721
- SESSION_ID,
8722
- calling_trigger_prop,
8723
- null,
8724
- dsSessionP
8725
- );
8726
- if (!obj_values_to_update || _.isEmpty(obj_values_to_update)) {
8727
- func.utils.debug_report(
8728
- SESSION_ID,
8729
- "Update values object is empty",
8730
- "",
8731
- "W"
8732
- );
8733
- if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP);
8734
- return;
8735
- }
8736
- var updates = [];
8737
-
8738
- for await (const [key, val] of Object.entries(obj_values_to_update)) {
8739
- var $element;
8740
-
8741
- if (elementP) {
8742
- $element = $(`[xu-ui-id="${elementP}"]`).clone(true);
8743
- }
8744
-
8745
- let ret_field_id = await func.expression.get(
8746
- SESSION_ID,
8747
- val.id.trim(),
8748
- dsSessionP,
8749
- "update",
8750
- null,
8751
- null,
8752
- null,
8753
- null,
8754
- null,
8755
- null,
8756
- $element?.length ? $element?.data()?.xuData?.iterate_info : null
8757
- );
8758
- let ret_value = await func.expression.get(
8759
- SESSION_ID,
8760
- val.val.trim(),
8761
- dsSessionP,
8762
- "update",
8763
- null,
8764
- null,
8765
- null,
8766
- null,
8767
- null,
8768
- null,
8769
- $element?.length ? $element?.data()?.xuData?.iterate_info : null
8770
- );
8771
- let _field_id = ret_field_id.result;
8772
- let _value = ret_value.result;
8773
-
8774
- updates.push({ _field_id, _value });
8775
- }
8776
-
8777
- let datasource_changes = {};
8778
- for await (const change of updates) {
8779
- let ret_get_value = await func.datasource.get_value(
8780
- SESSION_ID,
8781
- change._field_id,
8782
- dsSessionP
8783
- );
8784
- if (ret_get_value.found) {
8785
- let _ds = _session.DS_GLB[ret_get_value.dsSessionP];
8786
- if (!datasource_changes[_ds.dsSession]) {
8787
- datasource_changes[_ds.dsSession] = {};
8788
- }
8789
- if (
8790
- !datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]
8791
- ) {
8792
- datasource_changes[_ds.dsSession][ret_get_value.currentRecordId] =
8793
- {};
8794
- }
8795
- datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][
8796
- change._field_id
8797
- ] = change._value;
8798
- }
8799
- }
8800
-
8801
- await func.datasource.update(SESSION_ID, datasource_changes);
8802
- if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP);
8803
- // return changes;
8804
- },
8805
- call_alert: async function () {
8806
- await func.utils.alerts.invoke(
8807
- SESSION_ID,
8808
- "call_alert",
8809
- refIdP,
8810
- log_source,
8811
- dsSession
8812
- );
8813
- func.events.delete_job(SESSION_ID, jobNoP);
8814
- },
8815
- alert: async function () {
8816
- await func.utils.alerts.invoke(
8817
- SESSION_ID,
8818
- "alert",
8819
- refIdP,
8820
- log_source,
8821
- dsSession
8822
- );
8823
- func.events.delete_job(SESSION_ID, jobNoP);
8824
- },
8825
- delay: async function () {
8826
- return new Promise((resolve) => {
8827
- setTimeout(function () {
8828
- if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP);
8829
- resolve();
8830
- }, refIdP.value);
8831
- });
8832
- },
8833
- comment: async function () {
8834
- if (jobNoP) func.events.delete_job(SESSION_ID, jobNoP);
8835
- },
8836
- call_project_api: async function () {
8837
- const params_obj = await get_params_obj();
8838
- const _prog_id = await get_prog_id();
8839
-
8840
- if (!_prog_id) {
8841
- func.utils.debug_report(
8842
- SESSION_ID,
8843
- "func.events.execute",
8844
- `${elementP} > ${triggerP} > ${functionP} > program not defined`,
8845
- "E"
8846
- );
8847
- func.events.delete_job(SESSION_ID, jobNoP);
8848
- return;
8849
- }
8850
-
8851
- // const output_field = await get_args_property_value("outputField");
8852
-
8853
- // if (!output_field) {
8854
- // func.utils.debug_report(
8855
- // SESSION_ID,
8856
- // "func.events.execute",
8857
- // `${elementP} >${triggerP} >${functionP} > Output field not defined`,
8858
- // "W"
8859
- // );
8860
- // // func.events.delete_job(SESSION_ID, jobNoP);
8861
- // // return;
8862
- // }
8863
-
8864
- const api_ret = await func.api.call_project_api(_prog_id, params_obj);
8865
-
8866
- await func.datasource.set_outputField(SESSION_ID, dsSessionP, api_ret);
8867
-
8868
- // if (output_field) {
8869
- // let datasource_changes = {};
8870
-
8871
- // let ret_get_value = await func.datasource.get_value(
8872
- // SESSION_ID,
8873
- // output_field,
8874
- // dsSessionP
8875
- // );
8876
- // if (ret_get_value.found) {
8877
- // let _ds = _session.DS_GLB[ret_get_value.dsSessionP];
8878
- // if (!datasource_changes[_ds.dsSession]) {
8879
- // datasource_changes[_ds.dsSession] = {};
8880
- // }
8881
- // if (
8882
- // !datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]
8883
- // ) {
8884
- // datasource_changes[_ds.dsSession][ret_get_value.currentRecordId] =
8885
- // {};
8886
- // }
8887
- // datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][
8888
- // output_field
8889
- // ] = api_ret;
8890
- // await func.datasource.update(SESSION_ID, datasource_changes);
8891
- // }
8892
- // }
8893
- func.events.delete_job(SESSION_ID, jobNoP);
8894
- },
8895
- call_system_api: async function () {
8896
- const api_method = await func.datasource.get_args_property_value(SESSION_ID, dsSession, args, "api_method");
8897
-
8898
- if (!api_method) {
8899
- func.utils.debug_report(
8900
- SESSION_ID,
8901
- "func.events.execute",
8902
- `${elementP} >${triggerP} >${functionP} > api_method not defined`,
8903
- "E"
8904
- );
8905
- func.events.delete_job(SESSION_ID, jobNoP);
8906
- return;
8907
- }
8908
- let payload = {};
8909
- const _payload = await func.datasource.get_args_property_value(SESSION_ID, dsSession, args, "payload");
8910
- if (_payload) {
8911
- const get_payload_property_value = async function (prop_name) {
8912
- let _prop = _payload;
8913
- let _value = _prop[prop_name];
8914
- if (_prop?.[`xu-exp:${prop_name}`]) {
8915
- _value = (
8916
- await func.expression.get(
8917
- SESSION_ID,
8918
- _prop[`xu-exp:${prop_name}`],
8919
- dsSession,
8920
- `${prop_name} expression`
8921
- )
8922
- ).result;
8923
- }
8924
-
8925
- return _value;
8926
- };
8927
-
8928
- for await (let [key, val] of Object.entries(_payload)) {
8929
- // if (key.substring(0, 7) !== "xu-exp:") {
8930
- const new_key = key.replaceAll("xu-exp:", ""); //key.substring(0, 7) === "xu-exp:" ? key.substring(7): key
8931
- payload[new_key] = await get_payload_property_value(new_key);
8932
- // }
8933
- }
8934
- }
8935
-
8936
- // if (!payload) {
8937
- // func.utils.debug_report(
8938
- // SESSION_ID,
8939
- // "func.events.execute",
8940
- // `${elementP} >${triggerP} >${functionP} > payload not defined`,
8941
- // "E"
8942
- // );
8943
- // func.events.delete_job(SESSION_ID, jobNoP);
8944
- // return;
8945
- // }
8946
-
8947
- const output_field = await func.datasource.get_args_property_value(SESSION_ID, dsSession, args, "outputField");
8948
-
8949
- // if (!output_field) {
8950
- // func.utils.debug_report(
8951
- // SESSION_ID,
8952
- // "func.events.execute",
8953
- // `${elementP} >${triggerP} >${functionP} > Output field not defined`,
8954
- // "E"
8955
- // );
8956
- // func.events.delete_job(SESSION_ID, jobNoP);
8957
- // return;
8958
- // }
8959
-
8960
- const api_ret = await func.api.call_system_api(api_method, payload);
8961
- if (output_field) {
8962
- let datasource_changes = {};
8963
-
8964
- let ret_get_value = await func.datasource.get_value(
8965
- SESSION_ID,
8966
- output_field,
8967
- dsSessionP
8968
- );
8969
- if (ret_get_value.found) {
8970
- let _ds = _session.DS_GLB[ret_get_value.dsSessionP];
8971
- if (!datasource_changes[_ds.dsSession]) {
8972
- datasource_changes[_ds.dsSession] = {};
8973
- }
8974
- if (
8975
- !datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]
8976
- ) {
8977
- datasource_changes[_ds.dsSession][ret_get_value.currentRecordId] =
8978
- {};
8979
- }
8980
- datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][
8981
- output_field
8982
- ] = api_ret;
8983
- await func.datasource.update(SESSION_ID, datasource_changes);
8984
- }
8985
- }
8986
- func.events.delete_job(SESSION_ID, jobNoP);
8987
- },
8988
- call_external_api: async function () {
8989
- const method = await func.datasource.get_args_property_value(SESSION_ID, dsSession, args, "method");
8990
-
8991
- if (!method) {
8992
- func.utils.debug_report(
8993
- SESSION_ID,
8994
- "func.events.execute",
8995
- `${elementP} >${triggerP} >${functionP} > method not defined`,
8996
- "E"
8997
- );
8998
- func.events.delete_job(SESSION_ID, jobNoP);
8999
- return;
9000
- }
9001
-
9002
- const url = await func.datasource.get_args_property_value(SESSION_ID, dsSession, args, "url");
9003
-
9004
- if (!url) {
9005
- func.utils.debug_report(
9006
- SESSION_ID,
9007
- "func.events.execute",
9008
- `${elementP} >${triggerP} >${functionP} > url not defined`,
9009
- "E"
9010
- );
9011
- func.events.delete_job(SESSION_ID, jobNoP);
9012
- return;
9013
- }
9014
-
9015
- const payload_arr = await func.datasource.get_args_property_value(SESSION_ID, dsSession, args, "payload");
9016
-
9017
- const report_conversion_error = function (res, typeP, valP) {
9018
- var msg = `${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;
9019
- if (error) {
9020
- return func.utils.debug_report(SESSION_ID, msg, "", "W");
9021
- }
9022
- func.utils.debug_report(
9023
- SESSION_ID,
9024
- msg + " " + _.capitalize(source) + prog_info,
9025
- "",
9026
- "E"
9027
- );
9028
- };
9029
- const report_conversion_warn = function (res) {
9030
- var msg = `${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;
9031
- func.utils.debug_report(
9032
- SESSION_ID,
9033
- msg + " " + _.capitalize(source) + prog_info,
9034
- "",
9035
- "W"
9036
- );
9037
- };
9038
- // var ret = valP;
9039
- if (error) {
9040
- return report_conversion_error();
9041
- }
9042
-
9043
- const module = await func.common.get_module(
9044
- SESSION_ID,
9045
- "xuda-get-cast-util-module.mjs"
9046
- );
9047
- // return module.cast(
9048
- // typeP,
9049
- // valP,
9050
- // report_conversion_error,
9051
- // report_conversion_warn
9052
- // );
9053
-
9054
- var payload = _.reduce(
9055
- payload_arr,
9056
- (ret, val, key) => {
9057
- ret[val.key] = module.cast(
9058
- val.type,
9059
- val.val,
9060
- report_conversion_error,
9061
- report_conversion_warn
9062
- );
9063
-
9064
- return ret;
9065
- },
9066
- {}
9067
- );
9068
- // if (!payload) {
9069
- // func.utils.debug_report(
9070
- // SESSION_ID,
9071
- // "func.events.execute",
9072
- // `${elementP} >${triggerP} >${functionP} > payload not defined`,
9073
- // "E"
9074
- // );
9075
- // func.events.delete_job(SESSION_ID, jobNoP);
9076
- // return;
9077
- // }
9078
-
9079
- const output_field = await func.datasource.get_args_property_value(SESSION_ID, dsSession, args, "outputField");
9080
-
9081
- // if (!output_field) {
9082
- // func.utils.debug_report(
9083
- // SESSION_ID,
9084
- // "func.events.execute",
9085
- // `${elementP} >${triggerP} >${functionP} > Output field not defined`,
9086
- // "E"
9087
- // );
9088
- // func.events.delete_job(SESSION_ID, jobNoP);
9089
- // return;
9090
- // }
9091
-
9092
- const api_ret = await func.api.call_external_api(method, url, payload);
9093
- if (output_field) {
9094
- let datasource_changes = {};
9095
-
9096
- let ret_get_value = await func.datasource.get_value(
9097
- SESSION_ID,
9098
- output_field,
9099
- dsSessionP
9100
- );
9101
- if (ret_get_value.found) {
9102
- let _ds = _session.DS_GLB[ret_get_value.dsSessionP];
9103
- if (!datasource_changes[_ds.dsSession]) {
9104
- datasource_changes[_ds.dsSession] = {};
9105
- }
9106
- if (
9107
- !datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]
9108
- ) {
9109
- datasource_changes[_ds.dsSession][ret_get_value.currentRecordId] =
9110
- {};
9111
- }
9112
- datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][
9113
- output_field
9114
- ] = api_ret;
9115
- await func.datasource.update(SESSION_ID, datasource_changes);
9116
- }
9117
- }
9118
- func.events.delete_job(SESSION_ID, jobNoP);
9119
- },
9120
- };
9121
- // if (functionP.includes("alert")) {
9122
- // return await fx.alert();
9123
- // } else {
9124
- // try {
9125
- // console.log("functionP", functionP);
9126
- return await fx[functionP]();
9127
- // } catch (err) {
9128
- // console.error(err);
9129
- // debugger;
9130
- // }
9131
- // }
9132
- };
9133
-
9134
- func.events.delete_job = function (SESSION_ID, jobNoP) {
9135
- var _session = SESSION_OBJ[SESSION_ID];
9136
- var job_index = func.events.find_job_index(SESSION_ID, jobNoP);
9137
-
9138
- // console.log(jobNoP, job_index);
9139
- if (!_session.WORKER_OBJ.jobs[job_index]) {
9140
- _session.WORKER_OBJ.stat = null;
9141
- return;
9142
- }
9143
-
9144
- var dsSession = _session.WORKER_OBJ.jobs[job_index].dsSessionP;
9145
- let ds_obj = _session?.DS_GLB[dsSession];
9146
- if (ds_obj) {
9147
- delete SCREEN_BLOCKER_OBJ[
9148
- ds_obj.screenId +
9149
- (ds_obj.callingScreenId ? "_" + ds_obj.callingScreenId : "")
9150
- ];
9151
- }
9152
- if (
9153
- dsSession &&
9154
- ds_obj?.loops_limit &&
9155
- ds_obj?.loops_count < ds_obj?.loops_limit - 1
9156
- ) {
9157
- return;
9158
- }
9159
- _session.WORKER_OBJ.stat = null;
9160
-
9161
- _session.WORKER_OBJ.jobs.splice(job_index, 1);
9162
- };
9163
- func.events.delete_job_0 = function (SESSION_ID) {
9164
- var job_index = 0;
9165
- var _session = SESSION_OBJ[SESSION_ID];
9166
- if (!_session.WORKER_OBJ.jobs[job_index]) {
9167
- _session.WORKER_OBJ.stat = null;
9168
- return;
9169
- }
9170
-
9171
- var dsSession = _session.WORKER_OBJ.jobs[job_index].dsSession;
9172
- let ds_obj = _session?.DS_GLB[dsSession];
9173
- if (ds_obj) {
9174
- delete SCREEN_BLOCKER_OBJ[
9175
- ds_obj.screenId +
9176
- (ds_obj.callingScreenId ? "_" + ds_obj.callingScreenId : "")
9177
- ];
9178
- }
9179
- if (
9180
- dsSession &&
9181
- ds_obj &&
9182
- ds_obj.loops_limit &&
9183
- ds_obj.loops_count < ds_obj.loops_limit - 1
9184
- ) {
9185
- return;
9186
- }
9187
- _session.WORKER_OBJ.stat = null;
9188
-
9189
- _session.WORKER_OBJ.jobs.splice(job_index, 1);
9190
- };
9191
- func.events.check_jobs_idle = async function (SESSION_ID, jobsP) {
9192
- return new Promise((resolve, reject) => {
9193
- var _session = SESSION_OBJ[SESSION_ID];
9194
- if (!jobsP || (jobsP && jobsP.length === 0)) {
9195
- resolve();
9196
- return;
9197
- }
9198
- var listener = setInterval(function () {
9199
- var found;
9200
- for (const [key, val] of Object.entries(jobsP)) {
9201
- _.forEach(_session.WORKER_OBJ.jobs, function (val2, key2) {
9202
- if (key2 === val) {
9203
- found = true;
9204
- return false;
9205
- }
9206
- });
9207
- }
9208
- if (!found) {
9209
- do_callback();
9210
- return;
9211
- }
9212
- }, 100);
9213
- var do_callback = function () {
9214
- window.clearInterval(listener);
9215
- resolve();
9216
- };
9217
- });
9218
- };
9219
-
9220
- var loop_detected_obj = {};
9221
- setInterval(function () {
9222
- loop_detected_obj = {};
9223
- }, 1000);
9224
-
9225
- func.events.set_browser_changes = function (dsP, fieldsChangedP) {
9226
- if (fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))
9227
- document.title = dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"];
9228
- };
9229
-
9230
- func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
9231
- for (let [key, url] of Object.entries(PENDING_OPEN_URL_EVENTS)) {
9232
- if (url) {
9233
- glb.WINDOW_LOCATION_SEARCH = url;
9234
- glb.ROOT_ELEMENT_ATTRIBUTES = func.UI.utils.get_root_element_attributes();
9235
-
9236
- const params_obj = func.common.getObjectFromUrl(
9237
- url,
9238
- glb.ROOT_ELEMENT_ATTRIBUTES
9239
- );
9240
- if (!params_obj.prog) {
9241
- return console.warn("prog empty");
9242
- }
9243
-
9244
- await func.utils.TREE_OBJ.get(SESSION_ID, params_obj.prog);
9245
- let screen_ret = await func.utils.get_screen_obj(
9246
- SESSION_ID,
9247
- params_obj.prog
9248
- );
9249
-
9250
- if (screen_ret) {
9251
- await func.UI.screen.init(
9252
- SESSION_ID,
9253
- params_obj.prog,
9254
- null,
9255
- null,
9256
- $("#embed_" + SESSION_ID),
9257
- null,
9258
- null,
9259
- null,
9260
- null,
9261
- null,
9262
- "pendingUrlEvent_embed"
9263
- );
9264
- } else {
9265
- console.error("Program not exist", params_obj.prog_id);
9266
- func.UI.utils.progressScreen.show(
9267
- SESSION_ID,
9268
- "Program not exist",
9269
- null,
9270
- true
9271
- );
9272
- }
9273
- } else {
9274
- console.warn("url empty");
9275
- }
9276
- }
9277
- };
9278
- func.events.invoke = async function (event_id) {
9279
- var _session = SESSION_OBJ[SESSION_ID];
9280
- if (!event_id) {
9281
- console.warn("event_id Cannot be empty");
9282
- return false;
9283
- }
9284
- var ds;
9285
- for await (const [ds_key, val] of Object.entries(_session.DS_GLB)) {
9286
- const _view_obj = await func.utils.VIEWS_OBJ.get(SESSION_ID, val.prog_id);
9287
- if (_.isEmpty(_view_obj.progEvents)) continue;
9288
- if (ds) break;
9289
- for await (const [key, val] of Object.entries(_view_obj.progEvents)) {
9290
- if (
9291
- val?.data?.type === "user_defined" &&
9292
- val.data.event_name === event_id
9293
- ) {
9294
- ds = ds_key;
9295
- break;
9296
- }
9297
- }
9298
- }
9299
-
9300
- if (!ds) {
9301
- console.warn("event_id not found");
9302
- return false;
9303
- }
9304
-
9305
- func.events.validate(SESSION_ID, "user_defined", ds, event_id);
9306
- };
9307
- func.expression = {};
7536
+ func.expression = {};
9308
7537
 
9309
7538
  func.expression.get = async function (
9310
7539
  SESSION_ID,