@xuda.io/runtime-bundle 1.0.1148 → 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.
|
@@ -30952,7 +30952,1740 @@ func.datasource.get_args_property_value = async function (SESSION_ID, dsSession,
|
|
|
30952
30952
|
|
|
30953
30953
|
return _value;
|
|
30954
30954
|
};
|
|
30955
|
-
|
|
30955
|
+
func.UI.screen = {};
|
|
30956
|
+
func.UI.screen.init = async function (SESSION_ID, prog_id, sourceScreenP, callingDataSource_objP, $callingContainerP, triggerIdP, rowIdP, jobNoP, is_panelP, parameters_obj_inP, source_functionP, call_screen_propertiesP, refreshed_ds, parameters_raw_obj) {
|
|
30957
|
+
if (!prog_id) return console.error('program is empty');
|
|
30958
|
+
let screen_ret = await func.utils.get_screen_obj(SESSION_ID, prog_id);
|
|
30959
|
+
if (!screen_ret) return console.error('program is not a screen object');
|
|
30960
|
+
await func.UI.utils.init_ui_framework(SESSION_ID, prog_id);
|
|
30961
|
+
|
|
30962
|
+
let _session = SESSION_OBJ[SESSION_ID];
|
|
30963
|
+
|
|
30964
|
+
const screenInfo = _.cloneDeep(screen_ret);
|
|
30965
|
+
// const $callingContainerP_data = $callingContainerP.clone(true)?.data();
|
|
30966
|
+
|
|
30967
|
+
var screen_type = source_functionP?.split('_')?.[1]; //|| (is_panelP && "panel");
|
|
30968
|
+
|
|
30969
|
+
var screenId = (glb.screen_num++).toString();
|
|
30970
|
+
|
|
30971
|
+
if (SCREEN_BLOCKER_OBJ[prog_id + (sourceScreenP ? '_' + sourceScreenP : '')]) {
|
|
30972
|
+
const wait_for_SCREEN_BLOCKER_release = () => {
|
|
30973
|
+
return new Promise((resolve) => {
|
|
30974
|
+
var interval = setInterval(function () {
|
|
30975
|
+
if (!SCREEN_BLOCKER_OBJ[prog_id + (sourceScreenP ? '_' + sourceScreenP : '')]) {
|
|
30976
|
+
window.clearInterval(interval);
|
|
30977
|
+
resolve();
|
|
30978
|
+
// run_screen();
|
|
30979
|
+
}
|
|
30980
|
+
}, 5);
|
|
30981
|
+
});
|
|
30982
|
+
};
|
|
30983
|
+
await wait_for_SCREEN_BLOCKER_release();
|
|
30984
|
+
}
|
|
30985
|
+
|
|
30986
|
+
func.UI.utils.screen_blocker(true, prog_id + (sourceScreenP ? '_' + sourceScreenP : ''));
|
|
30987
|
+
|
|
30988
|
+
if ($callingContainerP && !_.isEmpty($callingContainerP)) $callingContainerP.data().xuData.screenInfo = screenInfo;
|
|
30989
|
+
|
|
30990
|
+
var $dialogDiv;
|
|
30991
|
+
var $rootFrame;
|
|
30992
|
+
var containerId;
|
|
30993
|
+
|
|
30994
|
+
var params = {
|
|
30995
|
+
prog_id,
|
|
30996
|
+
sourceScreenP,
|
|
30997
|
+
$callingContainerP,
|
|
30998
|
+
triggerIdP,
|
|
30999
|
+
callingDataSource_objP,
|
|
31000
|
+
rowIdP,
|
|
31001
|
+
renderType: screenInfo.properties?.renderType,
|
|
31002
|
+
parameters_obj_inP,
|
|
31003
|
+
source_functionP,
|
|
31004
|
+
is_panelP,
|
|
31005
|
+
screen_type,
|
|
31006
|
+
screenInfo,
|
|
31007
|
+
call_screen_propertiesP,
|
|
31008
|
+
parentDataSourceNoP: _session.DS_GLB?.[callingDataSource_objP?.dsSession]?.dsSession || callingDataSource_objP?.parentDataSourceNo || 0,
|
|
31009
|
+
parameters_raw_obj,
|
|
31010
|
+
};
|
|
31011
|
+
|
|
31012
|
+
switch (screen_type) {
|
|
31013
|
+
case 'embed':
|
|
31014
|
+
$dialogDiv = $('<div>')
|
|
31015
|
+
.attr({
|
|
31016
|
+
id: screenId,
|
|
31017
|
+
ui_engine: UI_FRAMEWORK_INSTALLED,
|
|
31018
|
+
})
|
|
31019
|
+
.addClass('xu_embed_container')
|
|
31020
|
+
.css({ display: 'contents' })
|
|
31021
|
+
.data({
|
|
31022
|
+
xuData: {
|
|
31023
|
+
paramsP: params,
|
|
31024
|
+
screenInfo: params.screenInfo,
|
|
31025
|
+
},
|
|
31026
|
+
});
|
|
31027
|
+
|
|
31028
|
+
let rootTagName = 'div';
|
|
31029
|
+
if (typeof glb.SLIM_BUNDLE === 'undefined' && !glb.SLIM_BUNDLE) {
|
|
31030
|
+
const ui_plugin_core = new UI_FRAMEWORK_PLUGIN.core();
|
|
31031
|
+
rootTagName = ui_plugin_core?.rootTagName();
|
|
31032
|
+
}
|
|
31033
|
+
|
|
31034
|
+
$rootFrame = $(`<${rootTagName}>`).data('xuData', {}).data('xuAttributes', {}).appendTo($dialogDiv);
|
|
31035
|
+
|
|
31036
|
+
$dialogDiv.appendTo($callingContainerP);
|
|
31037
|
+
break;
|
|
31038
|
+
|
|
31039
|
+
case 'panel':
|
|
31040
|
+
$dialogDiv = $callingContainerP;
|
|
31041
|
+
$dialogDiv.data({
|
|
31042
|
+
xuData: {
|
|
31043
|
+
paramsP: params,
|
|
31044
|
+
screenInfo: params.screenInfo,
|
|
31045
|
+
},
|
|
31046
|
+
});
|
|
31047
|
+
$rootFrame = $dialogDiv;
|
|
31048
|
+
break;
|
|
31049
|
+
|
|
31050
|
+
case 'page':
|
|
31051
|
+
case 'modal':
|
|
31052
|
+
case 'popover':
|
|
31053
|
+
$dialogDiv = $('<div>');
|
|
31054
|
+
$rootFrame = $('<div>').appendTo($dialogDiv);
|
|
31055
|
+
$dialogDiv.appendTo('body');
|
|
31056
|
+
break;
|
|
31057
|
+
|
|
31058
|
+
default:
|
|
31059
|
+
}
|
|
31060
|
+
|
|
31061
|
+
params.containerIdP = $rootFrame.attr('id');
|
|
31062
|
+
params.$container = $rootFrame;
|
|
31063
|
+
|
|
31064
|
+
containerId = 'container_' + params.screenInfo.properties?.id + '_' + screenId;
|
|
31065
|
+
|
|
31066
|
+
var data = {
|
|
31067
|
+
note: ' ROOT container',
|
|
31068
|
+
root: true,
|
|
31069
|
+
screenId,
|
|
31070
|
+
is_panelP,
|
|
31071
|
+
prog_id,
|
|
31072
|
+
screen_type,
|
|
31073
|
+
container: '#' + containerId, // initiate container that hold the element
|
|
31074
|
+
};
|
|
31075
|
+
if (is_panelP) {
|
|
31076
|
+
$rootFrame.data().xuData.rootFrame = data;
|
|
31077
|
+
} else {
|
|
31078
|
+
if (!$rootFrame.data().xuData) {
|
|
31079
|
+
$rootFrame.data().xuData = {};
|
|
31080
|
+
}
|
|
31081
|
+
$rootFrame.attr('id', containerId).data().xuData.rootFrame = data;
|
|
31082
|
+
$rootFrame.css('display', 'contents');
|
|
31083
|
+
}
|
|
31084
|
+
|
|
31085
|
+
var node = JSON.parse(JSON.stringify(screen_ret.progUi));
|
|
31086
|
+
|
|
31087
|
+
func.UI.utils.indicator.screen.busy();
|
|
31088
|
+
|
|
31089
|
+
const ret = await func.datasource.create(SESSION_ID, prog_id, refreshed_ds, params.parentDataSourceNoP, $rootFrame.attr('id'), rowIdP, jobNoP, null, parameters_raw_obj, null, null, null, null, null, parameters_obj_inP);
|
|
31090
|
+
|
|
31091
|
+
var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[ret.dsSessionP];
|
|
31092
|
+
_ds.screen_params = params;
|
|
31093
|
+
|
|
31094
|
+
params.dsSessionP = ret.dsSessionP;
|
|
31095
|
+
|
|
31096
|
+
func.UI.screen.update_SYS_OBJ_WIN_INFO(SESSION_ID, params.dsSessionP);
|
|
31097
|
+
|
|
31098
|
+
if (ret.dsSessionP >= 0) {
|
|
31099
|
+
// Call from contact info screen
|
|
31100
|
+
var viewDoc;
|
|
31101
|
+
let view_ret = await func.utils.VIEWS_OBJ.get(SESSION_ID, SESSION_OBJ[SESSION_ID].DS_GLB[ret.dsSessionP].prog_id);
|
|
31102
|
+
if (view_ret) {
|
|
31103
|
+
viewDoc = view_ret;
|
|
31104
|
+
}
|
|
31105
|
+
if (!viewDoc?.progUi) {
|
|
31106
|
+
return func.utils.alerts.invoke(SESSION_ID, 'system_msg', 'SYS_MSG_0780', params.renderType, ret.dsSessionP);
|
|
31107
|
+
}
|
|
31108
|
+
var node;
|
|
31109
|
+
node = _.cloneDeep(viewDoc.progUi);
|
|
31110
|
+
if (!node.length) return console.warn('ui node empty');
|
|
31111
|
+
const ret_render_$container = await func.UI.screen.render_ui_tree(SESSION_ID, $rootFrame, node[0], null, params, jobNoP, null, null, null, null, null, $rootFrame);
|
|
31112
|
+
|
|
31113
|
+
// $(".skeleton_wrapper").remove();
|
|
31114
|
+
|
|
31115
|
+
// fix for svg // deprecated Aug 12 25
|
|
31116
|
+
|
|
31117
|
+
// const fix_svg = function () {
|
|
31118
|
+
// let $svg = $('svg');
|
|
31119
|
+
// $.each($svg, function (key, elm) {
|
|
31120
|
+
// elm.outerHTML = elm.outerHTML;
|
|
31121
|
+
// });
|
|
31122
|
+
// };
|
|
31123
|
+
// setTimeout(function () {
|
|
31124
|
+
// fix_svg();
|
|
31125
|
+
// }, 200);
|
|
31126
|
+
|
|
31127
|
+
func.UI.utils.indicator.screen.normal();
|
|
31128
|
+
|
|
31129
|
+
let ret_screen_loading = await func.UI.screen.screen_loading_done(SESSION_ID, params, ret_render_$container, jobNoP);
|
|
31130
|
+
|
|
31131
|
+
// for (const [container_xu_ui_id, val] of Object.entries(UI_WORKER_OBJ.pending_for_viewport_render)) {
|
|
31132
|
+
// const height = val.base_$div.height();
|
|
31133
|
+
// if (height) {
|
|
31134
|
+
// const total_height = height * val.data.length || 1;
|
|
31135
|
+
// if (total_height > val.$container.height()) {
|
|
31136
|
+
// val.$container.css('height', height * val.data.length);
|
|
31137
|
+
// }
|
|
31138
|
+
// }
|
|
31139
|
+
// debugger;
|
|
31140
|
+
// }
|
|
31141
|
+
|
|
31142
|
+
return ret_screen_loading;
|
|
31143
|
+
}
|
|
31144
|
+
};
|
|
31145
|
+
|
|
31146
|
+
func.UI.screen.update_SYS_OBJ_WIN_INFO = function (SESSION_ID, dsNoP) {
|
|
31147
|
+
var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP];
|
|
31148
|
+
if (!_ds) return;
|
|
31149
|
+
if (!_ds.data_system) {
|
|
31150
|
+
_ds.data_system = {};
|
|
31151
|
+
}
|
|
31152
|
+
|
|
31153
|
+
_ds.data_system['SYS_STR_WIN_ID'] = _ds.tree_obj?.id;
|
|
31154
|
+
_ds.data_system['SYS_STR_WIN_NAME'] = _ds.tree_obj?.menuName;
|
|
31155
|
+
if (SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP].mode) {
|
|
31156
|
+
_ds.data_system['SYS_STR_WIN_MODE'] = SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP].mode;
|
|
31157
|
+
}
|
|
31158
|
+
// _ds.data_system["SYS_OBJ_WIN_INFO"] = func.UI.screen.get_info(
|
|
31159
|
+
// SESSION_ID,
|
|
31160
|
+
// dsNoP
|
|
31161
|
+
// );
|
|
31162
|
+
// get all top fields into json
|
|
31163
|
+
};
|
|
31164
|
+
|
|
31165
|
+
func.UI.screen.validate_exit_events = async function (SESSION_ID, div_data_paramsP, forceP) {
|
|
31166
|
+
return new Promise(async (resolve) => {
|
|
31167
|
+
await func.events.validate(SESSION_ID, 'on_exit', div_data_paramsP.dsSessionP, null, 'screen');
|
|
31168
|
+
|
|
31169
|
+
var interval = setInterval(function () {
|
|
31170
|
+
if (!SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs.length || forceP) {
|
|
31171
|
+
clearInterval(interval);
|
|
31172
|
+
resolve();
|
|
31173
|
+
}
|
|
31174
|
+
}, 5);
|
|
31175
|
+
});
|
|
31176
|
+
};
|
|
31177
|
+
|
|
31178
|
+
func.UI.screen.call_embed = function (SESSION_ID, prog) {
|
|
31179
|
+
$('#embed_' + SESSION_ID)
|
|
31180
|
+
.empty()
|
|
31181
|
+
.data().xuData.screenInfo = null;
|
|
31182
|
+
|
|
31183
|
+
_.forEach(SESSION_OBJ[SESSION_ID].DS_GLB, function (val, key) {
|
|
31184
|
+
if (key) func.datasource.del(SESSION_ID, key);
|
|
31185
|
+
});
|
|
31186
|
+
func.UI.main.embed_prog_execute(SESSION_ID, prog);
|
|
31187
|
+
};
|
|
31188
|
+
func.UI.screen.refresh_xu_attributes = async function (SESSION_ID, fields_arr, jobNoP, $elm_to_search, dsSession_changed, avoid_xu_for_refresh, trigger) {
|
|
31189
|
+
if (trigger !== 'click') {
|
|
31190
|
+
if (!_.isEmpty(SCREEN_BLOCKER_OBJ)) {
|
|
31191
|
+
// let dom to finish
|
|
31192
|
+
setTimeout(() => {
|
|
31193
|
+
func.UI.screen.refresh_xu_attributes(SESSION_ID, fields_arr, jobNoP, $elm_to_search, dsSession_changed);
|
|
31194
|
+
}, 100);
|
|
31195
|
+
return;
|
|
31196
|
+
}
|
|
31197
|
+
}
|
|
31198
|
+
|
|
31199
|
+
UI_WORKER_OBJ.cache = {};
|
|
31200
|
+
const _session = SESSION_OBJ[SESSION_ID];
|
|
31201
|
+
if (glb.DEBUG_MODE) {
|
|
31202
|
+
console.info('========= xu-attributes refresh info ==============');
|
|
31203
|
+
console.info('fields_arr:', fields_arr);
|
|
31204
|
+
}
|
|
31205
|
+
|
|
31206
|
+
var selectors = {};
|
|
31207
|
+
var search_from = 'body';
|
|
31208
|
+
var new_job = jobNoP;
|
|
31209
|
+
|
|
31210
|
+
if ($elm_to_search) {
|
|
31211
|
+
search_from = '#' + $elm_to_search.attr('id');
|
|
31212
|
+
}
|
|
31213
|
+
const get_selectors = function () {
|
|
31214
|
+
$.each(fields_arr, function (key_field, val_field) {
|
|
31215
|
+
$(search_from)
|
|
31216
|
+
.find('*')
|
|
31217
|
+
.filter(function () {
|
|
31218
|
+
// check if the changed field include in the calling in parameters
|
|
31219
|
+
const elm_data = $(this).data();
|
|
31220
|
+
if (!elm_data.xuData) return true;
|
|
31221
|
+
|
|
31222
|
+
if (typeof dsSession_changed !== 'undefined' && elm_data.xuData.paramsP && elm_data.xuData.paramsP.dsSessionP < dsSession_changed) return true;
|
|
31223
|
+
|
|
31224
|
+
let attr = [];
|
|
31225
|
+
|
|
31226
|
+
const validate_param_in = function (exp, without_var) {
|
|
31227
|
+
let exp_val_for_parameter_in_validation;
|
|
31228
|
+
if (typeof exp === 'string') exp_val_for_parameter_in_validation = exp;
|
|
31229
|
+
if (typeof exp === 'object') exp_val_for_parameter_in_validation = JSON.stringify(exp);
|
|
31230
|
+
if (!exp_val_for_parameter_in_validation) return;
|
|
31231
|
+
if (!exp.includes('@')) return;
|
|
31232
|
+
if (_.isEmpty(elm_data?.xuData?.paramsP?.parameters_raw_obj)) return;
|
|
31233
|
+
|
|
31234
|
+
for (const [param_key, param_val] of Object.entries(elm_data?.xuData?.paramsP?.parameters_raw_obj)) {
|
|
31235
|
+
if (!param_val.includes('@')) continue;
|
|
31236
|
+
exp_val_for_parameter_in_validation = exp_val_for_parameter_in_validation.replaceAll((without_var ? '' : '@') + param_key, param_val);
|
|
31237
|
+
}
|
|
31238
|
+
return exp_val_for_parameter_in_validation?.includes?.((without_var ? '' : '@') + val_field);
|
|
31239
|
+
};
|
|
31240
|
+
|
|
31241
|
+
$.each(elm_data?.xuAttributes, function (key, val) {
|
|
31242
|
+
if (typeof val !== 'string' && typeof val !== 'object') return true;
|
|
31243
|
+
if (typeof val === 'string' && !val?.includes('@') && key !== 'xu-bind' && key !== 'xu-for') return true;
|
|
31244
|
+
if (key.substr(0, 3) !== 'xu-') return true;
|
|
31245
|
+
|
|
31246
|
+
if (key === 'xu-bind' || key === 'xu-for') {
|
|
31247
|
+
if (val?.includes?.(val_field) || validate_param_in(val, true)) {
|
|
31248
|
+
attr.push(key);
|
|
31249
|
+
}
|
|
31250
|
+
return true;
|
|
31251
|
+
}
|
|
31252
|
+
|
|
31253
|
+
// if (key === 'xu-for') {
|
|
31254
|
+
// // match static value for xu-for
|
|
31255
|
+
// if (val?.includes?.(val_field) || validate_param_in(val)) {
|
|
31256
|
+
// attr.push(key);
|
|
31257
|
+
// }
|
|
31258
|
+
// return true;
|
|
31259
|
+
// }
|
|
31260
|
+
|
|
31261
|
+
// console.log(key, val);
|
|
31262
|
+
|
|
31263
|
+
if (key.substr(0, 6) === 'xu-exp' && key.substr(6, 1) === ':') {
|
|
31264
|
+
if (val?.includes?.('@' + val_field) || validate_param_in(val)) {
|
|
31265
|
+
attr.push(key);
|
|
31266
|
+
}
|
|
31267
|
+
return true;
|
|
31268
|
+
}
|
|
31269
|
+
|
|
31270
|
+
if (key.substr(0, 8) === 'xu-class') {
|
|
31271
|
+
try {
|
|
31272
|
+
const classes_string = val;
|
|
31273
|
+
const classes_obj = _.isString(classes_string) ? JSON.parse(classes_string) : _.defaults(classes_string, {});
|
|
31274
|
+
|
|
31275
|
+
$.each(classes_obj, function (cla, cond) {
|
|
31276
|
+
if (cond.includes('@' + val_field) || validate_param_in(cond)) {
|
|
31277
|
+
attr.push('xu-class');
|
|
31278
|
+
return false;
|
|
31279
|
+
}
|
|
31280
|
+
});
|
|
31281
|
+
if (attr.length) {
|
|
31282
|
+
return false;
|
|
31283
|
+
}
|
|
31284
|
+
} catch (e) {
|
|
31285
|
+
console.warn('parse error:' + val);
|
|
31286
|
+
}
|
|
31287
|
+
}
|
|
31288
|
+
|
|
31289
|
+
if (key === 'xu-ui-plugin') {
|
|
31290
|
+
const plugin_str = JSON.stringify(val);
|
|
31291
|
+
if (plugin_str.includes('@' + val_field) || validate_param_in(plugin_str)) {
|
|
31292
|
+
attr.push(key);
|
|
31293
|
+
return false;
|
|
31294
|
+
}
|
|
31295
|
+
}
|
|
31296
|
+
});
|
|
31297
|
+
|
|
31298
|
+
// const selector_id = glb.new_xu_render ? $(this).data()?.xuData?.ui_id : $(this).data()?.xuData?.xu_id;
|
|
31299
|
+
|
|
31300
|
+
const selector_id = $(this).attr('xu-ui-id');
|
|
31301
|
+
|
|
31302
|
+
if (attr.length) {
|
|
31303
|
+
selectors[selector_id] = selectors[selector_id];
|
|
31304
|
+
|
|
31305
|
+
if (!selectors[selector_id]) {
|
|
31306
|
+
selectors[selector_id] = { attributes: [], $elm: $(this) };
|
|
31307
|
+
}
|
|
31308
|
+
attr.forEach(function (value) {
|
|
31309
|
+
if (!selectors[selector_id].attributes.includes(value)) selectors[selector_id].attributes.push(value);
|
|
31310
|
+
});
|
|
31311
|
+
}
|
|
31312
|
+
});
|
|
31313
|
+
});
|
|
31314
|
+
};
|
|
31315
|
+
|
|
31316
|
+
get_selectors();
|
|
31317
|
+
// console.log('selectors>>>>', selectors);
|
|
31318
|
+
|
|
31319
|
+
for await (let [elem_key, elem_val] of Object.entries(selectors)) {
|
|
31320
|
+
if (elem_key === 'length') break;
|
|
31321
|
+
|
|
31322
|
+
if (!elem_val.$elm.data().xuData) continue;
|
|
31323
|
+
if (elem_val.$elm.data().xuData.pending_to_delete) continue;
|
|
31324
|
+
|
|
31325
|
+
const add_execute_queue = async function (type) {
|
|
31326
|
+
if (!elem_val.$elm?.data?.()?.xuData) return;
|
|
31327
|
+
try {
|
|
31328
|
+
const obj = {
|
|
31329
|
+
ui_type: elem_val.$elm.data().xuData.ui_type,
|
|
31330
|
+
SESSION_ID,
|
|
31331
|
+
fields_arr,
|
|
31332
|
+
elem_key,
|
|
31333
|
+
elem_val,
|
|
31334
|
+
};
|
|
31335
|
+
|
|
31336
|
+
new_job = await func.UI.worker.add_to_queue(SESSION_ID, 'gui event', type, obj, new_job, elem_val.$elm);
|
|
31337
|
+
|
|
31338
|
+
if (glb.DEBUG_MODE) {
|
|
31339
|
+
console.log(type + '>>>', new_job, obj);
|
|
31340
|
+
}
|
|
31341
|
+
} catch (error) {
|
|
31342
|
+
debugger;
|
|
31343
|
+
}
|
|
31344
|
+
};
|
|
31345
|
+
//////////// process render first ///////////////
|
|
31346
|
+
|
|
31347
|
+
var performed_render = undefined;
|
|
31348
|
+
|
|
31349
|
+
if (!elem_val?.$elm?.data()?.xuAttributes) continue;
|
|
31350
|
+
|
|
31351
|
+
if (elem_val.attributes.includes('xu-exp:xu-render')) {
|
|
31352
|
+
var res = await func.expression.get(SESSION_ID, elem_val.$elm.data().xuAttributes['xu-exp:xu-render'], elem_val.$elm.data().xuData.paramsP.dsSessionP, 'UI Property EXP', elem_val.$elm.data().xuData.recordid);
|
|
31353
|
+
|
|
31354
|
+
var attr_value = await func.common.get_cast_val(SESSION_ID, 'refresh xu-attributes', 'xu-render', 'bool', res.result);
|
|
31355
|
+
|
|
31356
|
+
if (!attr_value && elem_val.$elm[0].tagName === 'XURENDER') continue; // bypass job
|
|
31357
|
+
|
|
31358
|
+
if (attr_value && elem_val.$elm[0].tagName !== 'XURENDER') {
|
|
31359
|
+
await add_execute_queue('execute_xu_all_attributes');
|
|
31360
|
+
|
|
31361
|
+
continue; // bypass render job
|
|
31362
|
+
}
|
|
31363
|
+
|
|
31364
|
+
if (!elem_val?.$elm?.data()?.xuData?.ui_type) continue;
|
|
31365
|
+
|
|
31366
|
+
// RENDER = false handler
|
|
31367
|
+
const obj = {
|
|
31368
|
+
ui_type: elem_val.$elm.data().xuData.ui_type,
|
|
31369
|
+
SESSION_ID,
|
|
31370
|
+
elem_key,
|
|
31371
|
+
elem_val,
|
|
31372
|
+
fields_arr,
|
|
31373
|
+
attr_value,
|
|
31374
|
+
};
|
|
31375
|
+
new_job = jobNoP;
|
|
31376
|
+
new_job = await func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'execute_xu_render_attributes', obj, new_job, elem_val.$elm, elem_val.$elm.data().xuData.paramsP.dsSessionP);
|
|
31377
|
+
performed_render = true;
|
|
31378
|
+
|
|
31379
|
+
// mark children items ignore list
|
|
31380
|
+
$.each(elem_val.$elm.find('*'), function (key, val) {
|
|
31381
|
+
if ($(val).data().xuData) {
|
|
31382
|
+
$(val).data().xuData.pending_to_delete = true;
|
|
31383
|
+
}
|
|
31384
|
+
});
|
|
31385
|
+
|
|
31386
|
+
if (glb.DEBUG_MODE) {
|
|
31387
|
+
console.info('execute_xu_render_attributes', obj);
|
|
31388
|
+
}
|
|
31389
|
+
}
|
|
31390
|
+
|
|
31391
|
+
if (performed_render || elem_val.$elm[0].tagName === 'XURENDER') continue; // bypass job
|
|
31392
|
+
|
|
31393
|
+
if (elem_val.attributes.includes('xu-exp:xu-for') || elem_val.attributes.includes('xu-for')) continue;
|
|
31394
|
+
|
|
31395
|
+
add_execute_queue('execute_xu_all_attributes');
|
|
31396
|
+
}
|
|
31397
|
+
|
|
31398
|
+
// xu-for
|
|
31399
|
+
selectors = {};
|
|
31400
|
+
get_selectors();
|
|
31401
|
+
// console.log('selectors', selectors);
|
|
31402
|
+
let refreshed_ids = [];
|
|
31403
|
+
// handle xu-for
|
|
31404
|
+
let parent_element_ui_id;
|
|
31405
|
+
for await (let [elem_key, elem_val] of Object.entries(selectors)) {
|
|
31406
|
+
if (elem_key === 'length') break;
|
|
31407
|
+
|
|
31408
|
+
if (!elem_val.$elm.data().xuData) continue;
|
|
31409
|
+
if (elem_val.$elm.data().xuData.pending_to_delete) continue;
|
|
31410
|
+
|
|
31411
|
+
if (!elem_val.attributes.includes('xu-exp:xu-for') && !elem_val.attributes.includes('xu-for')) continue;
|
|
31412
|
+
|
|
31413
|
+
let _parent_element_ui_id;
|
|
31414
|
+
if (elem_val?.$elm?.data()?.xuPanelData) {
|
|
31415
|
+
// handle li panel
|
|
31416
|
+
_parent_element_ui_id = elem_val?.$elm?.data()?.xuPanelData?.parent_element_ui_id;
|
|
31417
|
+
} else {
|
|
31418
|
+
// handle regular li
|
|
31419
|
+
_parent_element_ui_id = elem_val?.$elm?.data()?.xuData?.parent_element_ui_id;
|
|
31420
|
+
}
|
|
31421
|
+
|
|
31422
|
+
if (!parent_element_ui_id || _parent_element_ui_id != parent_element_ui_id) {
|
|
31423
|
+
parent_element_ui_id = _parent_element_ui_id;
|
|
31424
|
+
|
|
31425
|
+
const _$elem = $(`[xu-ui-id=${parent_element_ui_id}]`);
|
|
31426
|
+
const _elem_key = parent_element_ui_id;
|
|
31427
|
+
const _elem_val = { attributes: [], $elm: _$elem };
|
|
31428
|
+
|
|
31429
|
+
$.each(_$elem.data()?.xuAttributes, function (key, val) {
|
|
31430
|
+
_elem_val.attributes.push(key);
|
|
31431
|
+
});
|
|
31432
|
+
const obj = {
|
|
31433
|
+
ui_type: _elem_val.$elm.data().xuData.ui_type,
|
|
31434
|
+
SESSION_ID,
|
|
31435
|
+
elem_key: _elem_key,
|
|
31436
|
+
elem_val: _elem_val,
|
|
31437
|
+
fields_arr,
|
|
31438
|
+
xu_for_item_id: elem_val?.$elm?.data()?.xuPanelData ? elem_val?.$elm?.data()?.xuPanelData.node.id : elem_val?.$elm?.data().xuData.nodeid,
|
|
31439
|
+
};
|
|
31440
|
+
if (avoid_xu_for_refresh) return;
|
|
31441
|
+
await func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'execute_xu_for', obj, new_job, _elem_val.$elm, _elem_val.$elm.data().xuData.paramsP.dsSessionP);
|
|
31442
|
+
|
|
31443
|
+
refreshed_ids.push(parent_element_ui_id);
|
|
31444
|
+
|
|
31445
|
+
if (glb.DEBUG_MODE) {
|
|
31446
|
+
console.info('execute_xu_for', obj);
|
|
31447
|
+
}
|
|
31448
|
+
}
|
|
31449
|
+
}
|
|
31450
|
+
|
|
31451
|
+
/////////// xu-for for non displayed elements ////////////
|
|
31452
|
+
const iterate_field_in_progUi = async function (progUi, field_id, panel_val) {
|
|
31453
|
+
let found;
|
|
31454
|
+
const iterate_progUi = async function (node, node_id) {
|
|
31455
|
+
for (let item of node) {
|
|
31456
|
+
if (!_.isEmpty(item.attributes)) {
|
|
31457
|
+
const parent_element_ui_id = node_id;
|
|
31458
|
+
// const _$elem = $(`[xu-node-id="${parent_element_ui_id}"]`);
|
|
31459
|
+
for await (const [attr, val] of Object.entries(item.attributes)) {
|
|
31460
|
+
if (attr === 'xu-exp:xu-for' || attr === 'xu-for') {
|
|
31461
|
+
if (val?.includes(field_id)) {
|
|
31462
|
+
// const parent_element_ui_id = node_id;
|
|
31463
|
+
// debugger;
|
|
31464
|
+
// let _$elem = $(`[xu-ui-id^=${parent_element_ui_id}]`);
|
|
31465
|
+
// let _$elem = $(`[xu-node-id=${parent_element_ui_id}]`);
|
|
31466
|
+
const _$elem = func.UI.utils.find_in_element_data('xuData', $(SESSION_OBJ[SESSION_ID].root_element), 'nodeid', parent_element_ui_id);
|
|
31467
|
+
// const _elem_key = parent_element_ui_id;
|
|
31468
|
+
const _elem_key = _$elem.attr('xu-ui-id');
|
|
31469
|
+
const _elem_val = { attributes: [], $elm: _$elem };
|
|
31470
|
+
if (!_$elem?.length) continue;
|
|
31471
|
+
|
|
31472
|
+
if (refreshed_ids.includes(_$elem.attr('xu-ui-id'))) break;
|
|
31473
|
+
|
|
31474
|
+
$.each(_$elem.data()?.xuAttributes, function (key, val) {
|
|
31475
|
+
_elem_val.attributes.push(key);
|
|
31476
|
+
});
|
|
31477
|
+
const obj = {
|
|
31478
|
+
ui_type: _elem_val.$elm.data().xuData.ui_type,
|
|
31479
|
+
SESSION_ID,
|
|
31480
|
+
elem_key: _elem_key,
|
|
31481
|
+
elem_val: _elem_val,
|
|
31482
|
+
fields_arr,
|
|
31483
|
+
xu_for_item_id: item.id,
|
|
31484
|
+
};
|
|
31485
|
+
if (avoid_xu_for_refresh) return;
|
|
31486
|
+
await func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'execute_xu_for', obj, new_job, _elem_val.$elm, _elem_val.$elm.data().xuData.paramsP.dsSessionP);
|
|
31487
|
+
|
|
31488
|
+
if (glb.DEBUG_MODE) {
|
|
31489
|
+
console.info('node execute_xu_for', obj, panel_val);
|
|
31490
|
+
}
|
|
31491
|
+
|
|
31492
|
+
break;
|
|
31493
|
+
}
|
|
31494
|
+
}
|
|
31495
|
+
|
|
31496
|
+
// if (glb.new_xu_render) {
|
|
31497
|
+
// if (attr === 'xu-exp:xu-render') {
|
|
31498
|
+
// //|| attr === 'xu-render'
|
|
31499
|
+
// for await (const [key, val] of Object.entries(_$elem)) {
|
|
31500
|
+
// if (key === 'length') break;
|
|
31501
|
+
// if ($(val).data().xuData.node) {
|
|
31502
|
+
// for await (const node of $(val).data().xuData.node.children) {
|
|
31503
|
+
// if (item.id !== node.id) continue;
|
|
31504
|
+
|
|
31505
|
+
// if (typeof node.xu_render_made !== 'undefined' && !node.xu_render_made) {
|
|
31506
|
+
// const node_data = UI_WORKER_OBJ.xu_render_cache[node.xu_render_xu_ui_id + node.xu_render_cache_id];
|
|
31507
|
+
// parent_element_ui_id;
|
|
31508
|
+
// const elem_key = node.xu_render_xu_ui_id;
|
|
31509
|
+
// const elem_val = { attributes: [attr], $elm: node_data.$div, data: node_data.data };
|
|
31510
|
+
// if (!elem_val.data?.xuData) continue;
|
|
31511
|
+
// elem_val.data.xuData.parent_element_ui_id = $(val).attr('xu-ui-id');
|
|
31512
|
+
// var res = await func.expression.get(SESSION_ID, elem_val.data.xuAttributes['xu-exp:xu-render'], elem_val.data.xuData.paramsP.dsSessionP, 'UI Property EXP', elem_val.data.xuData.recordid);
|
|
31513
|
+
|
|
31514
|
+
// var attr_value = await func.common.get_cast_val(SESSION_ID, 'refresh xu-attributes', 'xu-render', 'bool', res.result);
|
|
31515
|
+
// try {
|
|
31516
|
+
// const obj = {
|
|
31517
|
+
// ui_type: elem_val.data.xuData.ui_type,
|
|
31518
|
+
// SESSION_ID,
|
|
31519
|
+
// elem_key,
|
|
31520
|
+
// elem_val,
|
|
31521
|
+
// fields_arr,
|
|
31522
|
+
// attr_value,
|
|
31523
|
+
// };
|
|
31524
|
+
// func.UI.worker.add_to_queue(SESSION_ID, 'gui event', 'execute_xu_render_attributes', obj, new_job, elem_val.$elm, elem_val.data.xuData.paramsP.dsSessionP);
|
|
31525
|
+
// } catch (error) {
|
|
31526
|
+
// debugger;
|
|
31527
|
+
// }
|
|
31528
|
+
// }
|
|
31529
|
+
// }
|
|
31530
|
+
// }
|
|
31531
|
+
// }
|
|
31532
|
+
// }
|
|
31533
|
+
// }
|
|
31534
|
+
}
|
|
31535
|
+
}
|
|
31536
|
+
if (found) break;
|
|
31537
|
+
|
|
31538
|
+
if (item.children) {
|
|
31539
|
+
await iterate_progUi(item.children, item.id);
|
|
31540
|
+
}
|
|
31541
|
+
}
|
|
31542
|
+
};
|
|
31543
|
+
await iterate_progUi(progUi);
|
|
31544
|
+
return found;
|
|
31545
|
+
};
|
|
31546
|
+
|
|
31547
|
+
const $xu_embed_container = $('.xu_embed_container');
|
|
31548
|
+
const panels_obj = await func.UI.utils.get_panels_wrapper_from_dom(SESSION_ID, $xu_embed_container, true);
|
|
31549
|
+
|
|
31550
|
+
for await (const field_id of fields_arr) {
|
|
31551
|
+
// run root
|
|
31552
|
+
if ($xu_embed_container.length) {
|
|
31553
|
+
const progUi = $xu_embed_container?.data()?.xuData?.screenInfo?.progUi;
|
|
31554
|
+
if (progUi) {
|
|
31555
|
+
await iterate_field_in_progUi(progUi, field_id);
|
|
31556
|
+
}
|
|
31557
|
+
}
|
|
31558
|
+
// run panels
|
|
31559
|
+
for await (const [panel_wrapper_element_ui_id, panel_val] of Object.entries(panels_obj)) {
|
|
31560
|
+
await iterate_field_in_progUi(panel_val.progUi, field_id, panel_val);
|
|
31561
|
+
}
|
|
31562
|
+
}
|
|
31563
|
+
|
|
31564
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
31565
|
+
|
|
31566
|
+
if (glb.DEBUG_MODE) {
|
|
31567
|
+
console.info('===================================================');
|
|
31568
|
+
}
|
|
31569
|
+
};
|
|
31570
|
+
|
|
31571
|
+
func.UI.screen.refresh_screen = async function (SESSION_ID, fields_changed_arr, datasource_changed, fields_changed_datasource) {
|
|
31572
|
+
var found, refresh_reason, refresh_details;
|
|
31573
|
+
const validate_change = function (prog_doc, panelXuAttributes, skip_ui_check) {
|
|
31574
|
+
found = null;
|
|
31575
|
+
refresh_reason = null;
|
|
31576
|
+
refresh_details = null;
|
|
31577
|
+
const progDataSource_str = JSON.stringify(prog_doc.progDataSource);
|
|
31578
|
+
for (const field_id of fields_changed_arr) {
|
|
31579
|
+
// get panel attributes
|
|
31580
|
+
const _attributes = panelXuAttributes || {};
|
|
31581
|
+
|
|
31582
|
+
// detect if program changed
|
|
31583
|
+
found = _attributes['xu-exp:program']?.includes('@' + field_id);
|
|
31584
|
+
|
|
31585
|
+
if (found) {
|
|
31586
|
+
refresh_reason = `program ${_attributes['xu-exp:program']} ${field_id} changed `;
|
|
31587
|
+
refresh_details = _attributes;
|
|
31588
|
+
break;
|
|
31589
|
+
}
|
|
31590
|
+
|
|
31591
|
+
// _attributes holds also info of parameters in code_in: @code
|
|
31592
|
+
// search field changed in panel call send parameters exp
|
|
31593
|
+
for (const [attr, value] of Object.entries(_attributes)) {
|
|
31594
|
+
const pattern = /xu-exp:(\w+)/;
|
|
31595
|
+
const match = attr.match(pattern);
|
|
31596
|
+
|
|
31597
|
+
if (!match) {
|
|
31598
|
+
// continue if attribute is not expression
|
|
31599
|
+
continue;
|
|
31600
|
+
}
|
|
31601
|
+
// code_in
|
|
31602
|
+
const parameter_in_field_id = match?.[1];
|
|
31603
|
+
// @code
|
|
31604
|
+
if (value.includes(field_id)) {
|
|
31605
|
+
// search parameter in field in the target program's progDataSource
|
|
31606
|
+
found = progDataSource_str?.includes('@' + parameter_in_field_id);
|
|
31607
|
+
|
|
31608
|
+
if (found) {
|
|
31609
|
+
refresh_reason = `field ${field_id} in progDataSource parameter_in changed`;
|
|
31610
|
+
refresh_details = prog_doc?.progDataSource;
|
|
31611
|
+
|
|
31612
|
+
break;
|
|
31613
|
+
}
|
|
31614
|
+
if (!skip_ui_check) {
|
|
31615
|
+
found = func.UI.find_field_in_progUi_attributes(prog_doc.progUi, parameter_in_field_id, 'xu-for').length;
|
|
31616
|
+
|
|
31617
|
+
if (found) {
|
|
31618
|
+
refresh_reason = `field ${field_id} in progUi xu-for parameter_in changed`;
|
|
31619
|
+
refresh_details = found;
|
|
31620
|
+
|
|
31621
|
+
break;
|
|
31622
|
+
}
|
|
31623
|
+
}
|
|
31624
|
+
}
|
|
31625
|
+
}
|
|
31626
|
+
|
|
31627
|
+
if (found) break;
|
|
31628
|
+
|
|
31629
|
+
// search field changed in the target program's progDataSource // @code
|
|
31630
|
+
found = progDataSource_str?.includes('@' + field_id);
|
|
31631
|
+
if (found) {
|
|
31632
|
+
refresh_reason = `field ${field_id} in progDataSource changed`;
|
|
31633
|
+
refresh_details = prog_doc?.progDataSource;
|
|
31634
|
+
|
|
31635
|
+
break;
|
|
31636
|
+
}
|
|
31637
|
+
if (!skip_ui_check) {
|
|
31638
|
+
found = func.UI.find_field_in_progUi_attributes(prog_doc.progUi, field_id, 'xu-for').length;
|
|
31639
|
+
if (found) {
|
|
31640
|
+
refresh_reason = `field ${field_id} in progUi xu-for changed`;
|
|
31641
|
+
refresh_details = found;
|
|
31642
|
+
|
|
31643
|
+
break;
|
|
31644
|
+
}
|
|
31645
|
+
}
|
|
31646
|
+
|
|
31647
|
+
if (found) {
|
|
31648
|
+
break;
|
|
31649
|
+
}
|
|
31650
|
+
}
|
|
31651
|
+
};
|
|
31652
|
+
|
|
31653
|
+
// check the main program
|
|
31654
|
+
if (fields_changed_datasource) {
|
|
31655
|
+
const _session = SESSION_OBJ[SESSION_ID];
|
|
31656
|
+
const _ds = _session.DS_GLB[fields_changed_datasource];
|
|
31657
|
+
const prog_doc = await func.utils.DOCS_OBJ.get(SESSION_ID, _ds.prog_id);
|
|
31658
|
+
if (prog_doc.progUi) {
|
|
31659
|
+
validate_change(prog_doc, null, true);
|
|
31660
|
+
if (found) {
|
|
31661
|
+
const $elm = $(`#container_${_ds.prog_id}_0`);
|
|
31662
|
+
if ($elm?.length) {
|
|
31663
|
+
const elm_data = $elm.data();
|
|
31664
|
+
const $wrapper = $elm.parent();
|
|
31665
|
+
|
|
31666
|
+
const refreshed_ds = _ds.dsSession;
|
|
31667
|
+
|
|
31668
|
+
$elm.empty();
|
|
31669
|
+
if ($elm.data()) {
|
|
31670
|
+
const new_$div = await func.UI.screen.render_ui_tree(
|
|
31671
|
+
SESSION_ID,
|
|
31672
|
+
$elm, // the wrapper
|
|
31673
|
+
_.cloneDeep($elm.data().xuData.node), // the xu-panel node
|
|
31674
|
+
{},
|
|
31675
|
+
elm_data.xuData.paramsP, // the wrapper params
|
|
31676
|
+
null,
|
|
31677
|
+
null,
|
|
31678
|
+
elm_data.xuData.key, // the wrapper key
|
|
31679
|
+
refreshed_ds, // the refreshed_ds
|
|
31680
|
+
elm_data.xuData.parent_node, // the wrapper parent node
|
|
31681
|
+
null,
|
|
31682
|
+
elm_data.xuData.$root_container, // the wrapper root container
|
|
31683
|
+
);
|
|
31684
|
+
|
|
31685
|
+
if (glb.DEBUG_MODE) {
|
|
31686
|
+
console.info('========= refresh main info ==============');
|
|
31687
|
+
console.info('reason:', refresh_reason);
|
|
31688
|
+
console.info('element:', $elm);
|
|
31689
|
+
console.info('==========================================');
|
|
31690
|
+
}
|
|
31691
|
+
|
|
31692
|
+
return;
|
|
31693
|
+
}
|
|
31694
|
+
}
|
|
31695
|
+
}
|
|
31696
|
+
}
|
|
31697
|
+
}
|
|
31698
|
+
|
|
31699
|
+
const panels_obj = await func.UI.utils.get_panels_wrapper_from_dom(SESSION_ID, $(SESSION_OBJ[SESSION_ID].root_element), false);
|
|
31700
|
+
|
|
31701
|
+
for await (const [parent_element_ui_id, panel_val] of Object.entries(panels_obj)) {
|
|
31702
|
+
// const progDataSource_str = JSON.stringify(panel_val.prog_doc.progDataSource);
|
|
31703
|
+
if (!panel_val.$panel_div?.data()?.xuData) continue;
|
|
31704
|
+
|
|
31705
|
+
if (panel_val.$panel_div.data().xuData.pending_to_delete) continue;
|
|
31706
|
+
|
|
31707
|
+
if (fields_changed_arr) {
|
|
31708
|
+
if (fields_changed_datasource && panel_val._ds.dsSession <= Number(fields_changed_datasource)) {
|
|
31709
|
+
continue;
|
|
31710
|
+
}
|
|
31711
|
+
validate_change(panel_val.prog_doc, panel_val?.panelXuAttributes);
|
|
31712
|
+
}
|
|
31713
|
+
|
|
31714
|
+
if (datasource_changed) {
|
|
31715
|
+
if (panel_val._ds.dsSession == datasource_changed) {
|
|
31716
|
+
refresh_reason = `panel datasource ${datasource_changed} changed`;
|
|
31717
|
+
refresh_details = '';
|
|
31718
|
+
|
|
31719
|
+
found = true;
|
|
31720
|
+
}
|
|
31721
|
+
}
|
|
31722
|
+
if (found) {
|
|
31723
|
+
UI_WORKER_OBJ.cache = {};
|
|
31724
|
+
const _session = SESSION_OBJ[SESSION_ID];
|
|
31725
|
+
if (glb.DEBUG_MODE) {
|
|
31726
|
+
console.info('========= refresh info ==============');
|
|
31727
|
+
console.info('reason:', refresh_reason);
|
|
31728
|
+
console.info('details:', refresh_details);
|
|
31729
|
+
console.info('panel:', panel_val);
|
|
31730
|
+
console.info('=====================================');
|
|
31731
|
+
}
|
|
31732
|
+
const $div_elm = panel_val.$panel_div;
|
|
31733
|
+
const wrapper_data = $div_elm.data();
|
|
31734
|
+
|
|
31735
|
+
if (_.isEmpty(wrapper_data)) continue;
|
|
31736
|
+
|
|
31737
|
+
try {
|
|
31738
|
+
const ts = Date.now();
|
|
31739
|
+
// remove old panel content
|
|
31740
|
+
$.each(panel_val.ids, async function (key, val) {
|
|
31741
|
+
$("[xu-ui-id='" + val + "']")
|
|
31742
|
+
.attr('xu-ui-id', val + ts)
|
|
31743
|
+
.removeData();
|
|
31744
|
+
});
|
|
31745
|
+
|
|
31746
|
+
let refreshed_ds;
|
|
31747
|
+
// check if ds exist and deleted by garbage collector
|
|
31748
|
+
|
|
31749
|
+
if (_session.DS_GLB[panel_val._ds.dsSession]) {
|
|
31750
|
+
refreshed_ds = panel_val._ds.dsSession;
|
|
31751
|
+
}
|
|
31752
|
+
for await (const item of wrapper_data.xuData.node_org.children) {
|
|
31753
|
+
if (item.tagName !== 'xu-panel') continue;
|
|
31754
|
+
|
|
31755
|
+
const new_$div = await func.UI.screen.render_ui_tree(
|
|
31756
|
+
SESSION_ID,
|
|
31757
|
+
$div_elm, // the wrapper
|
|
31758
|
+
_.cloneDeep(item), // _.cloneDeep(wrapper_data.xuData.node_org.children[0]), // the xu-panel node
|
|
31759
|
+
{},
|
|
31760
|
+
wrapper_data.xuData.paramsP, // the wrapper params
|
|
31761
|
+
null,
|
|
31762
|
+
null,
|
|
31763
|
+
wrapper_data.xuData.key, // the wrapper key
|
|
31764
|
+
refreshed_ds, // the refreshed_ds
|
|
31765
|
+
wrapper_data.xuData.parent_node, // the wrapper parent node
|
|
31766
|
+
null,
|
|
31767
|
+
wrapper_data.xuData.$root_container, // the wrapper root container
|
|
31768
|
+
);
|
|
31769
|
+
}
|
|
31770
|
+
|
|
31771
|
+
// remove old panel content
|
|
31772
|
+
$.each(panel_val.ids, async function (key, val) {
|
|
31773
|
+
$("[xu-ui-id='" + val + ts + "']").remove();
|
|
31774
|
+
});
|
|
31775
|
+
} catch (error) {
|
|
31776
|
+
debugger;
|
|
31777
|
+
}
|
|
31778
|
+
// continue;
|
|
31779
|
+
}
|
|
31780
|
+
}
|
|
31781
|
+
};
|
|
31782
|
+
|
|
31783
|
+
const get_params_obj_new = async function (SESSION_ID, prog_id, nodeP, dsSession) {
|
|
31784
|
+
const _prog = await func.utils.VIEWS_OBJ.get(SESSION_ID, prog_id);
|
|
31785
|
+
if (!_prog) return;
|
|
31786
|
+
|
|
31787
|
+
// get in parameters
|
|
31788
|
+
let params_res = {},
|
|
31789
|
+
params_raw = {};
|
|
31790
|
+
if (_prog?.properties?.progParams) {
|
|
31791
|
+
for await (const [key, val] of Object.entries(_prog.properties.progParams)) {
|
|
31792
|
+
if (!['in', 'out'].includes(val.data.dir)) continue;
|
|
31793
|
+
|
|
31794
|
+
if (nodeP.attributes) {
|
|
31795
|
+
if (nodeP.attributes[val.data.parameter]) {
|
|
31796
|
+
params_res[val.data.parameter] = nodeP.attributes[val.data.parameter];
|
|
31797
|
+
} else if (nodeP.attributes[`xu-exp:${val.data.parameter}`]) {
|
|
31798
|
+
if (val.data.dir == 'out') {
|
|
31799
|
+
// only reference
|
|
31800
|
+
params_res[val.data.parameter] = nodeP.attributes[`xu-exp:${val.data.parameter}`].replaceAll('@', '');
|
|
31801
|
+
} else {
|
|
31802
|
+
// in parameter
|
|
31803
|
+
let ret = await func.expression.get(SESSION_ID, nodeP.attributes[`xu-exp:${val.data.parameter}`], dsSession, 'parameters');
|
|
31804
|
+
params_res[val.data.parameter] = ret.result;
|
|
31805
|
+
params_raw[val.data.parameter] = nodeP.attributes[`xu-exp:${val.data.parameter}`];
|
|
31806
|
+
}
|
|
31807
|
+
}
|
|
31808
|
+
continue;
|
|
31809
|
+
}
|
|
31810
|
+
console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`);
|
|
31811
|
+
}
|
|
31812
|
+
}
|
|
31813
|
+
return { params_res, params_raw };
|
|
31814
|
+
};
|
|
31815
|
+
|
|
31816
|
+
func.UI.screen.execute_xu_functions = async function (SESSION_ID, is_skeleton, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, xu_func, $elm, val, is_init, refreshed_ds) {
|
|
31817
|
+
if (is_skeleton) return;
|
|
31818
|
+
|
|
31819
|
+
// console.log(nodeP.id, xu_func, val);
|
|
31820
|
+
var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
|
|
31821
|
+
const tag_fx = {
|
|
31822
|
+
[`xu-panel`]: {
|
|
31823
|
+
program: async function ($elm, val) {
|
|
31824
|
+
var ret = {};
|
|
31825
|
+
var _session = SESSION_OBJ[SESSION_ID];
|
|
31826
|
+
var _ds = _session.DS_GLB[paramsP.dsSessionP];
|
|
31827
|
+
const init_program = async function () {
|
|
31828
|
+
async function render_panel() {
|
|
31829
|
+
const prog_id = val.value?.prog || val.value;
|
|
31830
|
+
const params_obj = await get_params_obj_new(SESSION_ID, prog_id, nodeP, paramsP.dsSessionP);
|
|
31831
|
+
let ret_panel = await func.UI.screen.init(SESSION_ID, prog_id, paramsP.screenId, _ds, $elm, null, _ds.currentRecordId, null, true, params_obj.params_res, 'initXu_panel', undefined, prog_id !== _ds.prog_id ? null : refreshed_ds, params_obj.params_raw);
|
|
31832
|
+
ret = { $new_div: ret_panel };
|
|
31833
|
+
if ($container.data().xuData) {
|
|
31834
|
+
$container.data().xuData.xuPanelProps = $elm.data().xuAttributes;
|
|
31835
|
+
$container.data().xuData.xuPanelData = ret_panel.data();
|
|
31836
|
+
}
|
|
31837
|
+
return ret;
|
|
31838
|
+
}
|
|
31839
|
+
|
|
31840
|
+
if (!val.value) {
|
|
31841
|
+
val.value = '_empty_panel_program';
|
|
31842
|
+
}
|
|
31843
|
+
|
|
31844
|
+
ret = await render_panel();
|
|
31845
|
+
|
|
31846
|
+
return ret;
|
|
31847
|
+
};
|
|
31848
|
+
const alter_program = async function () {
|
|
31849
|
+
var _session = SESSION_OBJ[SESSION_ID];
|
|
31850
|
+
var _ds = _session.DS_GLB[paramsP.dsSessionP];
|
|
31851
|
+
|
|
31852
|
+
/////////////////
|
|
31853
|
+
async function render_panel() {
|
|
31854
|
+
// // if (!cache_str) {
|
|
31855
|
+
// // await update_container(screen_ready_function);
|
|
31856
|
+
// // }
|
|
31857
|
+
// // if (cache_str && !CACHE_PROG_UI[cache_str]) {
|
|
31858
|
+
// // await update_container(screen_ready_function);
|
|
31859
|
+
// // save_cache();
|
|
31860
|
+
// // }
|
|
31861
|
+
// // if (callback) callback($div);
|
|
31862
|
+
// // $container.data().xuData.node.children =
|
|
31863
|
+
// // $div.data().xuData.node.children;
|
|
31864
|
+
// // //swiper-wrapper
|
|
31865
|
+
// // var restore_slides_elements = async function () {
|
|
31866
|
+
// // if ($tmp_div.children().length) {
|
|
31867
|
+
// // $tmp_div
|
|
31868
|
+
// // .find(".swiper-wrapper")
|
|
31869
|
+
// // .empty()
|
|
31870
|
+
// // .append($new_div.children());
|
|
31871
|
+
// // $new_div.append($tmp_div.children());
|
|
31872
|
+
// // }
|
|
31873
|
+
// // };
|
|
31874
|
+
// // // console.log($tmp_div);
|
|
31875
|
+
// // await restore_slides_elements();
|
|
31876
|
+
// // // CHANGE_PANEL_BUSY = false;
|
|
31877
|
+
// // func.events.delete_job(SESSION_ID, jobNo);
|
|
31878
|
+
// };
|
|
31879
|
+
const program = val.value?.prog || val.value;
|
|
31880
|
+
var $wrapper = $('<div>');
|
|
31881
|
+
var $div = await func.UI.screen.create_container(SESSION_ID, $root_container, nodeP, $container, paramsP, parent_infoP, jobNoP, keyP, parent_nodeP, nodeP.attributes, null, null, null, $wrapper, '');
|
|
31882
|
+
const params_obj = await get_params_obj_new(SESSION_ID, program, nodeP, paramsP.dsSessionP);
|
|
31883
|
+
let ret_init = await func.UI.screen.init(SESSION_ID, program, paramsP.screenId, _ds, $div, null, _ds.currentRecordId, jobNoP, true, params_obj.params_res, 'alterXu_panel', undefined, undefined, params_obj.params_raw);
|
|
31884
|
+
ret = {
|
|
31885
|
+
$new_div: ret_init,
|
|
31886
|
+
abort: true,
|
|
31887
|
+
};
|
|
31888
|
+
await func.UI.screen.panel_post_render_handler(SESSION_ID, $elm, $new_div, nodeP, $div.clone(true), jobNoP);
|
|
31889
|
+
|
|
31890
|
+
return ret;
|
|
31891
|
+
}
|
|
31892
|
+
if (!val.value) {
|
|
31893
|
+
return { abort: true };
|
|
31894
|
+
}
|
|
31895
|
+
await render_panel();
|
|
31896
|
+
return ret;
|
|
31897
|
+
};
|
|
31898
|
+
|
|
31899
|
+
if (is_init) {
|
|
31900
|
+
let ret = await init_program();
|
|
31901
|
+
return ret;
|
|
31902
|
+
}
|
|
31903
|
+
return alter_program();
|
|
31904
|
+
},
|
|
31905
|
+
|
|
31906
|
+
'xu-render': async function ($elm, val) {
|
|
31907
|
+
let ret = await common_fx['xu-render']($elm, val, true);
|
|
31908
|
+
return ret;
|
|
31909
|
+
},
|
|
31910
|
+
'xu-ref': async function ($elm, val) {
|
|
31911
|
+
let ret = await common_fx['xu-ref']($container, val, $container.data().xuData.xuPanelData.xuData.paramsP.dsSessionP);
|
|
31912
|
+
return ret;
|
|
31913
|
+
},
|
|
31914
|
+
},
|
|
31915
|
+
[`xu-teleport`]: {
|
|
31916
|
+
to: async function ($elm, val) {
|
|
31917
|
+
if (!glb.new_xu_render) {
|
|
31918
|
+
if (val.value) {
|
|
31919
|
+
// parent_infoP.is_xu_teleport;
|
|
31920
|
+
if ($elm?.parent()?.data()?.xuData?.length) {
|
|
31921
|
+
$elm.parent().data('xuTeleportData', []);
|
|
31922
|
+
for (const [key, node] of Object.entries(nodeP.children)) {
|
|
31923
|
+
const $teleport_elm = await func.UI.screen.render_ui_tree(SESSION_ID, $(val.value), node, parent_infoP, paramsP, jobNoP, is_skeleton, Number(key), null, node, null, $root_container);
|
|
31924
|
+
|
|
31925
|
+
$elm.parent().data().xuTeleportData.push($teleport_elm.attr('xu-ui-id'));
|
|
31926
|
+
$teleport_elm.attr('xu-teleport-parent-id', $elm.parent().attr('xu-ui-id'));
|
|
31927
|
+
}
|
|
31928
|
+
$elm.remove();
|
|
31929
|
+
} else {
|
|
31930
|
+
$elm.data('xuTeleportData', []).attr('hidden', true);
|
|
31931
|
+
for (const [key, node] of Object.entries(nodeP.children)) {
|
|
31932
|
+
const $to_container = $(val.value);
|
|
31933
|
+
if (!$to_container?.length) {
|
|
31934
|
+
return console.error(`container ${val.value} for xuTeleportData not found`);
|
|
31935
|
+
}
|
|
31936
|
+
const $teleport_elm = await func.UI.screen.render_ui_tree(SESSION_ID, $to_container, node, parent_infoP, paramsP, jobNoP, is_skeleton, Number(key), null, node, null, $root_container);
|
|
31937
|
+
|
|
31938
|
+
$elm.data().xuTeleportData.push($teleport_elm.attr('xu-ui-id'));
|
|
31939
|
+
$teleport_elm.attr('xu-teleport-parent-id', $elm.attr('xu-ui-id'));
|
|
31940
|
+
}
|
|
31941
|
+
}
|
|
31942
|
+
}
|
|
31943
|
+
return { abort: true };
|
|
31944
|
+
}
|
|
31945
|
+
|
|
31946
|
+
if (val.value) {
|
|
31947
|
+
// // parent_infoP.is_xu_teleport;
|
|
31948
|
+
// if ($elm?.parent()?.data()?.xuData?.length) {
|
|
31949
|
+
// $elm.parent().data('xuTeleportData', []);
|
|
31950
|
+
// for (const [key, node] of Object.entries(nodeP.children)) {
|
|
31951
|
+
// const $teleport_elm = await func.UI.screen.render_ui_tree(SESSION_ID, $(val.value), node, parent_infoP, paramsP, jobNoP, is_skeleton, Number(key), null, node, null, $root_container);
|
|
31952
|
+
// $elm.parent().data().xuTeleportData.push($teleport_elm.attr('xu-ui-id'));
|
|
31953
|
+
// $teleport_elm.attr('xu-teleport-parent-id', $elm.parent().attr('xu-ui-id'));
|
|
31954
|
+
// }
|
|
31955
|
+
// $elm.remove();
|
|
31956
|
+
// } else {
|
|
31957
|
+
// $elm.data('xuTeleportData', []).attr('hidden', true);
|
|
31958
|
+
// for (const [key, node] of Object.entries(nodeP.children)) {
|
|
31959
|
+
// const $to_container = $(val.value);
|
|
31960
|
+
// if (!$to_container?.length) {
|
|
31961
|
+
// return console.error(`container ${val.value} for xuTeleportData not found`);
|
|
31962
|
+
// }
|
|
31963
|
+
// const $teleport_elm = await func.UI.screen.render_ui_tree(SESSION_ID, $to_container, node, parent_infoP, paramsP, jobNoP, is_skeleton, Number(key), null, node, null, $root_container);
|
|
31964
|
+
// $elm.data().xuTeleportData.push($teleport_elm.attr('xu-ui-id'));
|
|
31965
|
+
// $teleport_elm.attr('xu-teleport-parent-id', $elm.attr('xu-ui-id'));
|
|
31966
|
+
// }
|
|
31967
|
+
// }
|
|
31968
|
+
}
|
|
31969
|
+
return {};
|
|
31970
|
+
},
|
|
31971
|
+
'xu-render': async function ($elm, val) {
|
|
31972
|
+
let ret = await common_fx['xu-render']($elm, val, true);
|
|
31973
|
+
return ret;
|
|
31974
|
+
},
|
|
31975
|
+
'xu-show': async function ($elm, val) {
|
|
31976
|
+
let ret = await common_fx['xu-show']($elm, val, true);
|
|
31977
|
+
return ret;
|
|
31978
|
+
},
|
|
31979
|
+
},
|
|
31980
|
+
};
|
|
31981
|
+
|
|
31982
|
+
const load_cdn = async function (resource) {
|
|
31983
|
+
// console.log("loading cdn", resource);
|
|
31984
|
+
if (!_.isObject(resource) && _.isString(resource)) {
|
|
31985
|
+
resource = { src: resource, type: 'js' };
|
|
31986
|
+
}
|
|
31987
|
+
if (!_.isObject(resource)) {
|
|
31988
|
+
throw new Error('cdn resource in wrong format');
|
|
31989
|
+
}
|
|
31990
|
+
return new Promise(async (resolve) => {
|
|
31991
|
+
try {
|
|
31992
|
+
switch (resource.type) {
|
|
31993
|
+
case 'js':
|
|
31994
|
+
await func.utils.load_js_on_demand(resource.src);
|
|
31995
|
+
break;
|
|
31996
|
+
case 'css':
|
|
31997
|
+
await func.utils.load_js_on_demand(resource.src);
|
|
31998
|
+
break;
|
|
31999
|
+
case 'module':
|
|
32000
|
+
func.utils.load_js_on_demand(resource.src, 'module');
|
|
32001
|
+
break;
|
|
32002
|
+
|
|
32003
|
+
default:
|
|
32004
|
+
await func.utils.load_js_on_demand(resource.src);
|
|
32005
|
+
break;
|
|
32006
|
+
}
|
|
32007
|
+
resolve();
|
|
32008
|
+
} catch (error) {
|
|
32009
|
+
func.utils.debug_report(SESSION_ID, 'xu-cdn', 'Fail to load: ' + resource, 'W');
|
|
32010
|
+
resolve();
|
|
32011
|
+
}
|
|
32012
|
+
|
|
32013
|
+
// if (resource.type === "js" || !resource.type) {
|
|
32014
|
+
// await func.utils.load_js_on_demand(resource.src);
|
|
32015
|
+
// return resolve();
|
|
32016
|
+
// }
|
|
32017
|
+
// if (resource.type === "css") {
|
|
32018
|
+
// func.utils.load_css_on_demand(resource.src);
|
|
32019
|
+
// return resolve();
|
|
32020
|
+
// }
|
|
32021
|
+
// if (resource.type === "module") {
|
|
32022
|
+
// func.utils.load_js_on_demand(resource.src, "module");
|
|
32023
|
+
// return resolve();
|
|
32024
|
+
// }
|
|
32025
|
+
// func.utils.debug_report(
|
|
32026
|
+
// SESSION_ID,
|
|
32027
|
+
// "xu-cdn",
|
|
32028
|
+
// "Fail to load: " + resource,
|
|
32029
|
+
// "W"
|
|
32030
|
+
// );
|
|
32031
|
+
// return resolve();
|
|
32032
|
+
});
|
|
32033
|
+
};
|
|
32034
|
+
|
|
32035
|
+
const common_fx = {
|
|
32036
|
+
'xu-attrs': async function ($elm, val) {
|
|
32037
|
+
if (!val.value) return {};
|
|
32038
|
+
if (!_.isObject(val.value)) throw 'xu-attrs value us not an object';
|
|
32039
|
+
for (const [attr_key, attr_val] of Object.entries(val.value)) {
|
|
32040
|
+
nodeP.attributes[attr_key] = attr_val;
|
|
32041
|
+
}
|
|
32042
|
+
|
|
32043
|
+
return {};
|
|
32044
|
+
},
|
|
32045
|
+
'xu-ref': async function ($elm, val, dsSession) {
|
|
32046
|
+
if (!val.value) return {};
|
|
32047
|
+
|
|
32048
|
+
func.UI.update_xu_ref(SESSION_ID, dsSession || paramsP.dsSessionP, val.value, $elm);
|
|
32049
|
+
|
|
32050
|
+
// Select the node that will be observed for mutations
|
|
32051
|
+
const targetNode = $elm[0];
|
|
32052
|
+
|
|
32053
|
+
if (!targetNode) return;
|
|
32054
|
+
|
|
32055
|
+
// Options for the observer (which mutations to observe)
|
|
32056
|
+
const config = { attributes: true, childList: true, subtree: true };
|
|
32057
|
+
|
|
32058
|
+
// Callback function to execute when mutations are observed
|
|
32059
|
+
const callback = (mutationList, observer) => {
|
|
32060
|
+
func.UI.screen.refresh_xu_attributes(SESSION_ID, [val.value]);
|
|
32061
|
+
};
|
|
32062
|
+
|
|
32063
|
+
// Create an observer instance linked to the callback function
|
|
32064
|
+
const observer = new MutationObserver(callback);
|
|
32065
|
+
|
|
32066
|
+
// Start observing the target node for configured mutations
|
|
32067
|
+
observer.observe(targetNode, config);
|
|
32068
|
+
|
|
32069
|
+
// Later, you can stop observing
|
|
32070
|
+
// observer.disconnect();
|
|
32071
|
+
|
|
32072
|
+
return {};
|
|
32073
|
+
},
|
|
32074
|
+
'xu-bind': async function ($elm, val) {
|
|
32075
|
+
if (is_skeleton) return;
|
|
32076
|
+
|
|
32077
|
+
let val_is_reference_field = false;
|
|
32078
|
+
|
|
32079
|
+
let _prog_id = $elm.data().xuData.paramsP.prog_id;
|
|
32080
|
+
let _dsP = $elm.data().xuData.paramsP.dsSessionP;
|
|
32081
|
+
const view_ret = await func.utils.VIEWS_OBJ.get(SESSION_ID, _prog_id);
|
|
32082
|
+
if (!view_ret) return {};
|
|
32083
|
+
|
|
32084
|
+
let is_dynamic_field = false;
|
|
32085
|
+
let field_prop;
|
|
32086
|
+
let bind_field_id;
|
|
32087
|
+
|
|
32088
|
+
const input_field_type = $elm.attr('type');
|
|
32089
|
+
|
|
32090
|
+
const get_bind_field = async function (field_id) {
|
|
32091
|
+
if (['_FOR_VAL', '_FOR_KEY'].includes(field_id)) {
|
|
32092
|
+
is_dynamic_field = true;
|
|
32093
|
+
field_prop = _ds.dynamic_fields[field_id];
|
|
32094
|
+
} else {
|
|
32095
|
+
field_prop = func.common.find_item_by_key(view_ret.progFields, 'field_id', field_id);
|
|
32096
|
+
if (!field_prop) {
|
|
32097
|
+
/// find the field everywhere in the chain Aug 30 2024
|
|
32098
|
+
const ret_get_value = await func.datasource.get_value(SESSION_ID, field_id, _dsP);
|
|
32099
|
+
|
|
32100
|
+
if (ret_get_value.found) {
|
|
32101
|
+
_dsP = ret_get_value.dsSessionP;
|
|
32102
|
+
let _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_dsP];
|
|
32103
|
+
_prog_id = _ds.prog_id;
|
|
32104
|
+
const view_ret = await func.utils.VIEWS_OBJ.get(SESSION_ID, _prog_id);
|
|
32105
|
+
if (!view_ret) return {};
|
|
32106
|
+
field_prop = func.common.find_item_by_key(view_ret.progFields, 'field_id', field_id);
|
|
32107
|
+
}
|
|
32108
|
+
if (!field_prop) {
|
|
32109
|
+
throw `field ${field_id} not found in the program scope`;
|
|
32110
|
+
}
|
|
32111
|
+
}
|
|
32112
|
+
}
|
|
32113
|
+
return field_id;
|
|
32114
|
+
};
|
|
32115
|
+
|
|
32116
|
+
try {
|
|
32117
|
+
bind_field_id = await get_bind_field(val.value.split('.')[0]);
|
|
32118
|
+
val_is_reference_field = true;
|
|
32119
|
+
} catch (err) {
|
|
32120
|
+
console.error(err?.message || err);
|
|
32121
|
+
return {};
|
|
32122
|
+
}
|
|
32123
|
+
|
|
32124
|
+
const field_changed = async function (e) {
|
|
32125
|
+
var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_dsP];
|
|
32126
|
+
|
|
32127
|
+
// update array for checkbox that not in xu-for
|
|
32128
|
+
if (field_prop.props.fieldType === 'array' && input_field_type === 'checkbox' && val_is_reference_field) {
|
|
32129
|
+
let arr_value_before_cast = _.clone((await func.datasource.get_value(SESSION_ID, bind_field_id, _dsP, _ds.currentRecordId)).ret.value);
|
|
32130
|
+
let value_from_getter = bind.getter($elm[0]);
|
|
32131
|
+
let value;
|
|
32132
|
+
if (arr_value_before_cast.includes(value_from_getter)) {
|
|
32133
|
+
value = arr_value_before_cast.filter((item) => !_.isEqual(item, value_from_getter));
|
|
32134
|
+
} else {
|
|
32135
|
+
arr_value_before_cast.push(value_from_getter);
|
|
32136
|
+
value = arr_value_before_cast;
|
|
32137
|
+
}
|
|
32138
|
+
|
|
32139
|
+
let datasource_changes = {
|
|
32140
|
+
[_dsP]: {
|
|
32141
|
+
[_ds.currentRecordId]: {
|
|
32142
|
+
[bind_field_id]: value,
|
|
32143
|
+
},
|
|
32144
|
+
},
|
|
32145
|
+
};
|
|
32146
|
+
|
|
32147
|
+
return await func.datasource.update(SESSION_ID, datasource_changes);
|
|
32148
|
+
}
|
|
32149
|
+
|
|
32150
|
+
// update array for radio that not in xu-for
|
|
32151
|
+
if (field_prop.props.fieldType === 'array' && input_field_type === 'radio' && val_is_reference_field) {
|
|
32152
|
+
let value_from_getter = bind.getter($elm[0]);
|
|
32153
|
+
|
|
32154
|
+
let datasource_changes = {
|
|
32155
|
+
[_dsP]: {
|
|
32156
|
+
[_ds.currentRecordId]: {
|
|
32157
|
+
[bind_field_id]: [value_from_getter],
|
|
32158
|
+
},
|
|
32159
|
+
},
|
|
32160
|
+
};
|
|
32161
|
+
|
|
32162
|
+
return await func.datasource.update(SESSION_ID, datasource_changes);
|
|
32163
|
+
}
|
|
32164
|
+
|
|
32165
|
+
var value = await func.common.get_cast_val(SESSION_ID, 'xu-bind', 'value', field_prop.props.fieldType, bind.getter($elm[0]));
|
|
32166
|
+
|
|
32167
|
+
if (field_prop.props.fieldType === 'object') {
|
|
32168
|
+
value = await func.common.get_cast_val(SESSION_ID, 'xu-bind', 'value', input_field_type, bind.getter($elm[0]));
|
|
32169
|
+
}
|
|
32170
|
+
|
|
32171
|
+
if (!_ds.currentRecordId) return;
|
|
32172
|
+
|
|
32173
|
+
let datasource_changes = {
|
|
32174
|
+
[_dsP]: {
|
|
32175
|
+
[_ds.currentRecordId]: {
|
|
32176
|
+
[bind_field_id]: value,
|
|
32177
|
+
},
|
|
32178
|
+
},
|
|
32179
|
+
};
|
|
32180
|
+
|
|
32181
|
+
await func.datasource.update(SESSION_ID, datasource_changes);
|
|
32182
|
+
const iterate_info = $elm?.data()?.xuData?.iterate_info;
|
|
32183
|
+
const reference_source_obj = iterate_info?.reference_source_obj;
|
|
32184
|
+
if (reference_source_obj) {
|
|
32185
|
+
if (reference_source_obj.ret.type === 'array') {
|
|
32186
|
+
if (iterate_info.iterator_val === bind_field_id) {
|
|
32187
|
+
const arr_idx = Number($elm?.data()?.xuData?.iterate_info._key);
|
|
32188
|
+
|
|
32189
|
+
const dataset_arr = await func.datasource.get_value(SESSION_ID, reference_source_obj.fieldIdP, _dsP, reference_source_obj.currentRecordId);
|
|
32190
|
+
let new_arr = _.cloneDeep(dataset_arr.ret.value);
|
|
32191
|
+
|
|
32192
|
+
if (field_prop.props.fieldType === 'object' && val_is_reference_field) {
|
|
32193
|
+
let obj_item = new_arr[arr_idx];
|
|
32194
|
+
|
|
32195
|
+
let e_exp = val.value.replace(bind_field_id, 'obj_item');
|
|
32196
|
+
|
|
32197
|
+
let new_val = eval(e_exp + (input_field_type === 'string' ? `="${value}"` : `=${value}`));
|
|
32198
|
+
|
|
32199
|
+
new_arr[arr_idx] = obj_item;
|
|
32200
|
+
} else {
|
|
32201
|
+
new_arr[arr_idx] = value;
|
|
32202
|
+
}
|
|
32203
|
+
// datasource_changes[_dsP][_ds.currentRecordId][reference_source_obj.fieldIdP] = new_arr;
|
|
32204
|
+
|
|
32205
|
+
let datasource_changes = {
|
|
32206
|
+
[_dsP]: {
|
|
32207
|
+
[_ds.currentRecordId]: {
|
|
32208
|
+
[reference_source_obj.fieldIdP]: new_arr,
|
|
32209
|
+
},
|
|
32210
|
+
},
|
|
32211
|
+
};
|
|
32212
|
+
|
|
32213
|
+
await func.datasource.update(SESSION_ID, datasource_changes, null, true);
|
|
32214
|
+
}
|
|
32215
|
+
}
|
|
32216
|
+
}
|
|
32217
|
+
|
|
32218
|
+
await func.datasource.update_changes_for_out_parameter(SESSION_ID, _dsP, _ds.parentDataSourceNo);
|
|
32219
|
+
};
|
|
32220
|
+
|
|
32221
|
+
const bind = new UI_FRAMEWORK_PLUGIN.bind();
|
|
32222
|
+
|
|
32223
|
+
bind.listener($elm[0], field_changed);
|
|
32224
|
+
|
|
32225
|
+
const set_value = function () {
|
|
32226
|
+
let _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
|
|
32227
|
+
if (!_ds.currentRecordId) return;
|
|
32228
|
+
let value;
|
|
32229
|
+
try {
|
|
32230
|
+
if (val_is_reference_field) {
|
|
32231
|
+
if (is_dynamic_field) {
|
|
32232
|
+
value = _ds.dynamic_fields[bind_field_id].value;
|
|
32233
|
+
} else {
|
|
32234
|
+
const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
|
|
32235
|
+
value = _ds.data_feed.rows?.[row_idx]?.[bind_field_id];
|
|
32236
|
+
}
|
|
32237
|
+
if (field_prop.props.fieldType === 'array' && $elm.attr('type') === 'checkbox' && $elm.attr('value')) {
|
|
32238
|
+
if (value.includes($elm.attr('value'))) {
|
|
32239
|
+
value = true;
|
|
32240
|
+
} else {
|
|
32241
|
+
value = false;
|
|
32242
|
+
}
|
|
32243
|
+
} else if (field_prop.props.fieldType === 'array' && $elm.attr('type') === 'radio' && $elm.attr('value')) {
|
|
32244
|
+
if (value.includes($elm.attr('value'))) {
|
|
32245
|
+
value = $elm.attr('value');
|
|
32246
|
+
} else {
|
|
32247
|
+
value = false;
|
|
32248
|
+
}
|
|
32249
|
+
} else if (field_prop.props.fieldType === 'object' && val.value.split('.').length > 1) {
|
|
32250
|
+
let str = val.value.replace(bind_field_id, '(' + JSON.stringify(value) + ')');
|
|
32251
|
+
value = eval(str);
|
|
32252
|
+
}
|
|
32253
|
+
} else {
|
|
32254
|
+
value = val.value;
|
|
32255
|
+
}
|
|
32256
|
+
if (typeof value === 'undefined') return;
|
|
32257
|
+
bind.setter($elm[0], value);
|
|
32258
|
+
} catch (err) {
|
|
32259
|
+
console.error(err);
|
|
32260
|
+
}
|
|
32261
|
+
};
|
|
32262
|
+
/// init value from ds
|
|
32263
|
+
$('body').on('xu-bind-refresh.' + _ds.dsSession.toString(), () => {
|
|
32264
|
+
set_value();
|
|
32265
|
+
});
|
|
32266
|
+
|
|
32267
|
+
set_value();
|
|
32268
|
+
return {};
|
|
32269
|
+
},
|
|
32270
|
+
'xu-render': async function ($elm, val, from_panel) {
|
|
32271
|
+
const old_render = async function () {
|
|
32272
|
+
var value = await func.common.get_cast_val(SESSION_ID, 'common fx', 'xu-render', 'bool', val.value);
|
|
32273
|
+
const init_render = function () {
|
|
32274
|
+
if (!value) {
|
|
32275
|
+
var cloned_$div = $elm.clone(true);
|
|
32276
|
+
|
|
32277
|
+
let $xurender = $('<xurender>').attr('xu-ui-id', $elm.attr('xu-ui-id')).attr('hidden', true).appendTo($container); //.hide();
|
|
32278
|
+
let original_data_obj = {
|
|
32279
|
+
$container: cloned_$div,
|
|
32280
|
+
nodeP: _.cloneDeep(nodeP),
|
|
32281
|
+
parent_infoP,
|
|
32282
|
+
paramsP,
|
|
32283
|
+
keyP,
|
|
32284
|
+
parent_nodeP,
|
|
32285
|
+
$root_container,
|
|
32286
|
+
};
|
|
32287
|
+
$xurender.data('xuData', cloned_$div.data().xuData);
|
|
32288
|
+
$xurender.data().xuData.original_data_obj = original_data_obj;
|
|
32289
|
+
$xurender.data().xuData.xurender_node = cloned_$div;
|
|
32290
|
+
$xurender.data().xuAttributes = nodeP.attributes || {};
|
|
32291
|
+
// $xurender.hide();
|
|
32292
|
+
|
|
32293
|
+
$elm.remove();
|
|
32294
|
+
return { abort: true };
|
|
32295
|
+
}
|
|
32296
|
+
return {};
|
|
32297
|
+
};
|
|
32298
|
+
|
|
32299
|
+
const post_render = async function () {
|
|
32300
|
+
if (value) {
|
|
32301
|
+
try {
|
|
32302
|
+
// abort if already rended
|
|
32303
|
+
if ($elm[0].tagName !== 'XURENDER' && $elm?.length) {
|
|
32304
|
+
return func.events.delete_job(SESSION_ID, jobNoP);
|
|
32305
|
+
}
|
|
32306
|
+
|
|
32307
|
+
let original_data_obj = $elm.data().xuData.original_data_obj;
|
|
32308
|
+
|
|
32309
|
+
if (!original_data_obj) {
|
|
32310
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
32311
|
+
return { delete_job: jobNoP };
|
|
32312
|
+
}
|
|
32313
|
+
|
|
32314
|
+
const new_$div = await func.UI.screen.render_ui_tree(
|
|
32315
|
+
SESSION_ID,
|
|
32316
|
+
$elm, //original_data_obj.$container,
|
|
32317
|
+
_.cloneDeep(original_data_obj.nodeP),
|
|
32318
|
+
original_data_obj.parent_infoP,
|
|
32319
|
+
original_data_obj.paramsP,
|
|
32320
|
+
jobNoP,
|
|
32321
|
+
null,
|
|
32322
|
+
original_data_obj.keyP,
|
|
32323
|
+
null,
|
|
32324
|
+
original_data_obj.parent_nodeP,
|
|
32325
|
+
null,
|
|
32326
|
+
original_data_obj.$root_container,
|
|
32327
|
+
);
|
|
32328
|
+
|
|
32329
|
+
new_$div.data().xuData.original_data_obj = original_data_obj;
|
|
32330
|
+
new_$div.data().xuData.xurender_node = $elm.clone(true);
|
|
32331
|
+
new_$div.data().xuAttributes = $elm.data().xuAttributes || {};
|
|
32332
|
+
|
|
32333
|
+
const replace = async function () {
|
|
32334
|
+
$elm.replaceWith(new_$div);
|
|
32335
|
+
if (from_panel) {
|
|
32336
|
+
const xuPanelWrapper = _.clone(new_$div.data().xuPanelWrapper);
|
|
32337
|
+
$elm.parent().data().xuPanelWrapper = xuPanelWrapper;
|
|
32338
|
+
$elm.replaceWith(new_$div.children());
|
|
32339
|
+
}
|
|
32340
|
+
|
|
32341
|
+
if (val.fields_arr) {
|
|
32342
|
+
return await func.UI.screen.refresh_xu_attributes(SESSION_ID, val.fields_arr, val.jobNoP, new_$div);
|
|
32343
|
+
}
|
|
32344
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
32345
|
+
};
|
|
32346
|
+
// if ($elm && func.UI.utils.find_in_element_data('xuData', $(SESSION_OBJ[SESSION_ID].root_element), 'xu_id', $elm.data().xuData.xu_id).length) {
|
|
32347
|
+
if ($elm && $(`[xu-ui-id="${$elm.attr('xu-ui-id')}"]`).length) {
|
|
32348
|
+
if (new_$div.data().xuData.paramsP) {
|
|
32349
|
+
return await replace();
|
|
32350
|
+
}
|
|
32351
|
+
|
|
32352
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
32353
|
+
}
|
|
32354
|
+
} catch (error) {
|
|
32355
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
32356
|
+
}
|
|
32357
|
+
return;
|
|
32358
|
+
}
|
|
32359
|
+
// if (!value) {
|
|
32360
|
+
if ($elm.prop('tagName') === 'XURENDER') {
|
|
32361
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
32362
|
+
return;
|
|
32363
|
+
}
|
|
32364
|
+
|
|
32365
|
+
let tmp_$div = $('<div>');
|
|
32366
|
+
|
|
32367
|
+
let $xurender = $('<xurender>').attr('xu-ui-id', $elm.attr('xu-ui-id')).appendTo(tmp_$div); //.hide();
|
|
32368
|
+
// was true before
|
|
32369
|
+
if ($elm.data().xuData.xurender_node) {
|
|
32370
|
+
$xurender.data({
|
|
32371
|
+
xuAttributes: $elm.data().xuData.xurender_node.data().xuAttributes || {},
|
|
32372
|
+
xuData: $elm.data().xuData.xurender_node.data().xuData || {},
|
|
32373
|
+
});
|
|
32374
|
+
} else {
|
|
32375
|
+
// default new state
|
|
32376
|
+
|
|
32377
|
+
$xurender.data({
|
|
32378
|
+
xuAttributes: $elm.data().xuAttributes || {},
|
|
32379
|
+
xuData: $elm.data().xuData || {},
|
|
32380
|
+
});
|
|
32381
|
+
const original_data_obj = {
|
|
32382
|
+
nodeP: _.cloneDeep($elm.data().xuData.node_org),
|
|
32383
|
+
paramsP: $elm.data().xuData.paramsP,
|
|
32384
|
+
$container: $elm.clone(true),
|
|
32385
|
+
parent_infoP: parent_infoP,
|
|
32386
|
+
};
|
|
32387
|
+
|
|
32388
|
+
$xurender.data().xuData.original_data_obj = original_data_obj;
|
|
32389
|
+
}
|
|
32390
|
+
|
|
32391
|
+
//remove xu-teleport trace
|
|
32392
|
+
$.each($elm.find('xu-teleport'), (key, val) => {
|
|
32393
|
+
const xuTeleportData = $(val).data().xuTeleportData || [];
|
|
32394
|
+
for (const teleported_elm_id of xuTeleportData) {
|
|
32395
|
+
$(`[xu-ui-id="${teleported_elm_id}"]`).remove();
|
|
32396
|
+
}
|
|
32397
|
+
});
|
|
32398
|
+
|
|
32399
|
+
$elm.replaceWith(tmp_$div.children());
|
|
32400
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
32401
|
+
// }
|
|
32402
|
+
};
|
|
32403
|
+
if (is_init) {
|
|
32404
|
+
return init_render();
|
|
32405
|
+
}
|
|
32406
|
+
return await post_render();
|
|
32407
|
+
};
|
|
32408
|
+
|
|
32409
|
+
const new_render = async function () {
|
|
32410
|
+
var value = await func.common.get_cast_val(SESSION_ID, 'common fx', 'xu-render', 'bool', val.value);
|
|
32411
|
+
const has_xu_render_attribute = true;
|
|
32412
|
+
const has_xu_exp_render_attribute = $elm.data()?.xuData?.attr_exp_info?.['xu-render'] ? true : false;
|
|
32413
|
+
const init_render = async function () {
|
|
32414
|
+
nodeP.xu_render_made = value;
|
|
32415
|
+
if (!value) {
|
|
32416
|
+
if (has_xu_exp_render_attribute) {
|
|
32417
|
+
return { has_xu_exp_render_attribute, has_xu_render_attribute, xu_render_background_processing: true };
|
|
32418
|
+
}
|
|
32419
|
+
return { has_xu_render_attribute, abort: true };
|
|
32420
|
+
}
|
|
32421
|
+
return { has_xu_exp_render_attribute, has_xu_render_attribute };
|
|
32422
|
+
};
|
|
32423
|
+
|
|
32424
|
+
const post_render = async function () {
|
|
32425
|
+
// always come from refresh
|
|
32426
|
+
let nodeP = $container.data().xuData.node.children[keyP];
|
|
32427
|
+
nodeP.xu_render_made = value;
|
|
32428
|
+
if (value) {
|
|
32429
|
+
try {
|
|
32430
|
+
const xu_render_cache_id = await get_xu_render_cache_str(SESSION_ID, paramsP.dsSessionP, Object.keys($elm.data()?.xuData?.attr_exp_info?.['xu-render']?.fields || {}));
|
|
32431
|
+
const xu_ui_id = $elm.attr('xu-ui-id');
|
|
32432
|
+
let new_$div = UI_WORKER_OBJ?.xu_render_cache?.[xu_ui_id + xu_render_cache_id]?.$div.clone(true);
|
|
32433
|
+
let found_parent_vars = false;
|
|
32434
|
+
if (new_$div) {
|
|
32435
|
+
// validate if $div contains fields from parent ds
|
|
32436
|
+
const parent_data = get_parent_ds_fields(SESSION_ID, paramsP.dsSessionP);
|
|
32437
|
+
const parent_fields = Object.keys(parent_data);
|
|
32438
|
+
|
|
32439
|
+
$.each(new_$div.find('*'), (key, val) => {
|
|
32440
|
+
const _xuAttributes = $(val)?.data()?.xuAttributes;
|
|
32441
|
+
if (found_parent_vars || !_xuAttributes) return;
|
|
32442
|
+
for (const [attr_key, attr_val] of Object.entries(_xuAttributes)) {
|
|
32443
|
+
if (found_parent_vars) break;
|
|
32444
|
+
for (const [key, val] of Object.entries(parent_fields)) {
|
|
32445
|
+
if (attr_val.includes('@' + key)) {
|
|
32446
|
+
found_parent_vars = true;
|
|
32447
|
+
break;
|
|
32448
|
+
}
|
|
32449
|
+
}
|
|
32450
|
+
}
|
|
32451
|
+
});
|
|
32452
|
+
}
|
|
32453
|
+
|
|
32454
|
+
if (!new_$div || found_parent_vars) {
|
|
32455
|
+
UI_WORKER_OBJ.xu_render_cache[xu_ui_id + xu_render_cache_id] = { paramsP };
|
|
32456
|
+
nodeP.xu_render_xu_ui_id = xu_ui_id;
|
|
32457
|
+
nodeP.xu_render_cache_id = xu_render_cache_id;
|
|
32458
|
+
new_$div = await func.UI.screen.render_ui_tree(SESSION_ID, $container, nodeP, parent_infoP, paramsP, jobNoP, null, keyP, null, parent_nodeP, null, $root_container);
|
|
32459
|
+
const _$div = new_$div.clone(true);
|
|
32460
|
+
UI_WORKER_OBJ.xu_render_cache[xu_ui_id + xu_render_cache_id].$div = _$div;
|
|
32461
|
+
UI_WORKER_OBJ.xu_render_cache[xu_ui_id + xu_render_cache_id].data = _$div.data();
|
|
32462
|
+
}
|
|
32463
|
+
// append order handling
|
|
32464
|
+
|
|
32465
|
+
if (!$container.children().length) {
|
|
32466
|
+
new_$div.appendTo($container);
|
|
32467
|
+
} else {
|
|
32468
|
+
// iterate the container node
|
|
32469
|
+
let $last_elm_found = [];
|
|
32470
|
+
$.each($container.data().xuData.node.children, (item_key, item_val) => {
|
|
32471
|
+
// const $elm = $(`[xu-node-id="${item_val.id}"]`);
|
|
32472
|
+
const $elm = func.UI.utils.find_in_element_data('xuData', $(SESSION_OBJ[SESSION_ID].root_element), 'nodeid', item_val.id);
|
|
32473
|
+
if ($elm.length) {
|
|
32474
|
+
$last_elm_found = $elm;
|
|
32475
|
+
}
|
|
32476
|
+
if (keyP == item_key) {
|
|
32477
|
+
if ($last_elm_found.length) {
|
|
32478
|
+
new_$div.after($last_elm_found);
|
|
32479
|
+
} else {
|
|
32480
|
+
$container.prepend(new_$div);
|
|
32481
|
+
}
|
|
32482
|
+
}
|
|
32483
|
+
});
|
|
32484
|
+
}
|
|
32485
|
+
} catch (error) {
|
|
32486
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
32487
|
+
}
|
|
32488
|
+
return;
|
|
32489
|
+
}
|
|
32490
|
+
|
|
32491
|
+
/////////// !value ///////////
|
|
32492
|
+
|
|
32493
|
+
const xu_ui_id = $elm.attr('xu-ui-id');
|
|
32494
|
+
|
|
32495
|
+
const cache_str = await get_xu_render_cache_str(SESSION_ID, paramsP.dsSessionP, Object.keys($elm.data()?.xuData?.attr_exp_info?.['xu-render']?.fields || {}));
|
|
32496
|
+
const _$div = $elm.clone(true);
|
|
32497
|
+
UI_WORKER_OBJ.xu_render_cache[xu_ui_id + cache_str] = { $div: _$div, data: _$div.data(), paramsP };
|
|
32498
|
+
$elm.remove();
|
|
32499
|
+
func.events.delete_job(SESSION_ID, jobNoP);
|
|
32500
|
+
};
|
|
32501
|
+
if (is_init) {
|
|
32502
|
+
return await init_render();
|
|
32503
|
+
}
|
|
32504
|
+
return await post_render();
|
|
32505
|
+
};
|
|
32506
|
+
|
|
32507
|
+
if (glb.new_xu_render) {
|
|
32508
|
+
return new_render();
|
|
32509
|
+
}
|
|
32510
|
+
return old_render();
|
|
32511
|
+
},
|
|
32512
|
+
'xu-show': async function ($elm, val) {
|
|
32513
|
+
var value = await func.common.get_cast_val(SESSION_ID, 'common fx', 'xu-show', 'bool', val.value);
|
|
32514
|
+
if (value) {
|
|
32515
|
+
$elm.show();
|
|
32516
|
+
}
|
|
32517
|
+
if (!value) {
|
|
32518
|
+
$elm.hide();
|
|
32519
|
+
}
|
|
32520
|
+
return {};
|
|
32521
|
+
},
|
|
32522
|
+
'xu-content': async function ($elm, val) {
|
|
32523
|
+
try {
|
|
32524
|
+
$elm.html(val.value);
|
|
32525
|
+
} catch (error) {
|
|
32526
|
+
console.warn(e);
|
|
32527
|
+
}
|
|
32528
|
+
return;
|
|
32529
|
+
},
|
|
32530
|
+
'xu-text': async function ($elm, val) {
|
|
32531
|
+
try {
|
|
32532
|
+
$elm.text(val.value);
|
|
32533
|
+
} catch (error) {
|
|
32534
|
+
console.warn(e);
|
|
32535
|
+
}
|
|
32536
|
+
return;
|
|
32537
|
+
},
|
|
32538
|
+
'xu-html': async function ($elm, val) {
|
|
32539
|
+
try {
|
|
32540
|
+
$elm.html(val.value);
|
|
32541
|
+
} catch (error) {
|
|
32542
|
+
console.warn(e);
|
|
32543
|
+
}
|
|
32544
|
+
return;
|
|
32545
|
+
},
|
|
32546
|
+
'xu-for': async function ($elm, data) {
|
|
32547
|
+
// exit if call from rendered xu-for item to prevent infante loop (parent_infoP?.iterate_info indicate call from rendered item)
|
|
32548
|
+
if (parent_infoP?.iterate_info) return {};
|
|
32549
|
+
if (!data.value) return {};
|
|
32550
|
+
try {
|
|
32551
|
+
// data.value (xu-for) can store actual values such as an array, a CSV, or a field_id that references a specific field within the dataset, initialized with values for the iteration.
|
|
32552
|
+
let arr = data.value;
|
|
32553
|
+
|
|
32554
|
+
// find reference source field
|
|
32555
|
+
let reference_source_obj;
|
|
32556
|
+
|
|
32557
|
+
const _progFields = await func.datasource.get_progFields(SESSION_ID, paramsP.dsSessionP);
|
|
32558
|
+
|
|
32559
|
+
let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', data.value);
|
|
32560
|
+
// detect if data.value (xu-for) is reference field_id by checking if exist in the dataset
|
|
32561
|
+
if (view_field_obj) {
|
|
32562
|
+
// xu-for is reference field_id
|
|
32563
|
+
reference_source_obj = await func.datasource.get_value(SESSION_ID, data.value, paramsP.dsSessionP);
|
|
32564
|
+
arr = reference_source_obj?.ret?.value;
|
|
32565
|
+
} else {
|
|
32566
|
+
// xu-for is actual data
|
|
32567
|
+
if (typeof data.value === 'string') {
|
|
32568
|
+
arr = eval(data.value.replaceAll('\\', ''));
|
|
32569
|
+
}
|
|
32570
|
+
if (typeof arr === 'number') {
|
|
32571
|
+
arr = Array.from(Array(arr).keys());
|
|
32572
|
+
}
|
|
32573
|
+
}
|
|
32574
|
+
|
|
32575
|
+
const custom_iterator_key = $elm.data().xuData.iterator_key;
|
|
32576
|
+
const custom_iterator_val = $elm.data().xuData.iterator_val;
|
|
32577
|
+
|
|
32578
|
+
let iterator_key = custom_iterator_key;
|
|
32579
|
+
let iterator_val = custom_iterator_val;
|
|
32580
|
+
let is_key_dynamic_field, is_val_dynamic_field;
|
|
32581
|
+
|
|
32582
|
+
// custom FOR_VAL name or namespaced default name
|
|
32583
|
+
if (!custom_iterator_key) {
|
|
32584
|
+
is_key_dynamic_field = true;
|
|
32585
|
+
|
|
32586
|
+
iterator_key = '_FOR_KEY';
|
|
32587
|
+
}
|
|
32588
|
+
|
|
32589
|
+
if (!custom_iterator_val) {
|
|
32590
|
+
is_val_dynamic_field = true;
|
|
32591
|
+
|
|
32592
|
+
iterator_val = '_FOR_VAL';
|
|
32593
|
+
}
|
|
32594
|
+
|
|
32595
|
+
var i = 0;
|
|
32596
|
+
for await (let [_key, _val] of Object.entries(arr)) {
|
|
32597
|
+
if (_.isArray(arr)) {
|
|
32598
|
+
_key = Number(_key);
|
|
32599
|
+
}
|
|
32600
|
+
|
|
32601
|
+
const set_value = async function (is_dynamic_field, currentRecordId, field_id, value) {
|
|
32602
|
+
if (is_dynamic_field) {
|
|
32603
|
+
func.datasource.add_dynamic_field_to_ds(SESSION_ID, paramsP.dsSessionP, field_id, value);
|
|
32604
|
+
} else {
|
|
32605
|
+
const _progFields = await func.datasource.get_progFields(SESSION_ID, paramsP.dsSessionP);
|
|
32606
|
+
|
|
32607
|
+
let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', field_id);
|
|
32608
|
+
if (view_field_obj) {
|
|
32609
|
+
let _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
|
|
32610
|
+
try {
|
|
32611
|
+
const row_idx = func.common.find_ROWID_idx(_ds, currentRecordId);
|
|
32612
|
+
_ds.data_feed.rows[row_idx][field_id] = value;
|
|
32613
|
+
} catch (err) {
|
|
32614
|
+
console.error(err);
|
|
32615
|
+
}
|
|
32616
|
+
} else {
|
|
32617
|
+
console.error('field not exist in dataset for xu-for method');
|
|
32618
|
+
}
|
|
32619
|
+
}
|
|
32620
|
+
};
|
|
32621
|
+
|
|
32622
|
+
var currentRecordId = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP].currentRecordId.toString();
|
|
32623
|
+
|
|
32624
|
+
await set_value(is_key_dynamic_field, currentRecordId, iterator_key, _key);
|
|
32625
|
+
await set_value(is_val_dynamic_field, currentRecordId, iterator_val, _val);
|
|
32626
|
+
|
|
32627
|
+
var iterate_info = {
|
|
32628
|
+
_val,
|
|
32629
|
+
_key,
|
|
32630
|
+
iterator_key,
|
|
32631
|
+
iterator_val,
|
|
32632
|
+
is_key_dynamic_field,
|
|
32633
|
+
is_val_dynamic_field,
|
|
32634
|
+
reference_source_obj,
|
|
32635
|
+
};
|
|
32636
|
+
let _parent_info = _.cloneDeep(parent_infoP) || {};
|
|
32637
|
+
_parent_info.iterate_info = iterate_info;
|
|
32638
|
+
|
|
32639
|
+
const $divP = await func.UI.screen.render_ui_tree(
|
|
32640
|
+
SESSION_ID,
|
|
32641
|
+
$container,
|
|
32642
|
+
nodeP,
|
|
32643
|
+
_parent_info, //parent_infoP ? _.cloneDeep(_parent_info) : null,
|
|
32644
|
+
paramsP,
|
|
32645
|
+
jobNoP,
|
|
32646
|
+
null,
|
|
32647
|
+
i,
|
|
32648
|
+
null,
|
|
32649
|
+
nodeP,
|
|
32650
|
+
null,
|
|
32651
|
+
$root_container,
|
|
32652
|
+
);
|
|
32653
|
+
|
|
32654
|
+
$.each($divP.children(), function (key, val) {
|
|
32655
|
+
if ($(val)?.data()?.xuData) {
|
|
32656
|
+
$(val).data().xuData.iterate_info = iterate_info;
|
|
32657
|
+
}
|
|
32658
|
+
});
|
|
32659
|
+
|
|
32660
|
+
i++;
|
|
32661
|
+
}
|
|
32662
|
+
$elm.remove();
|
|
32663
|
+
return { abort: true };
|
|
32664
|
+
} catch (e) {
|
|
32665
|
+
console.error(' Iterator Arr parse error');
|
|
32666
|
+
return { abort: true };
|
|
32667
|
+
}
|
|
32668
|
+
},
|
|
32669
|
+
'xu-for-key': async function ($elm, val) {
|
|
32670
|
+
$elm.data().xuData.iterator_key = val.value;
|
|
32671
|
+
return {};
|
|
32672
|
+
},
|
|
32673
|
+
'xu-for-val': async function ($elm, val) {
|
|
32674
|
+
$elm.data().xuData.iterator_val = val.value;
|
|
32675
|
+
return {};
|
|
32676
|
+
},
|
|
32677
|
+
'xu-class': async function ($elm, val) {
|
|
32678
|
+
try {
|
|
32679
|
+
const classes_string = val.value;
|
|
32680
|
+
// let obj = _.isString(classes_string) ? JSON.parse(classes_string) : _.defaults(classes_string, {});
|
|
32681
|
+
|
|
32682
|
+
const classes_obj = _.isString(classes_string) ? JSON.parse(classes_string) : _.defaults(classes_string, {});
|
|
32683
|
+
for await (const [cla, cond] of Object.entries(classes_obj)) {
|
|
32684
|
+
let res = await func.expression.get(
|
|
32685
|
+
SESSION_ID,
|
|
32686
|
+
cond,
|
|
32687
|
+
paramsP.dsSessionP,
|
|
32688
|
+
func.UI.component = {};
|
|
30956
32689
|
|
|
30957
32690
|
func.UI.component.create_app_modal_component = function (
|
|
30958
32691
|
SESSION_ID,
|