@sankhyalabs/ezui 3.5.0 → 4.0.0
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.
- package/dist/cjs/ez-actions-button.cjs.entry.js +1 -1
- package/dist/cjs/ez-alert.cjs.entry.js +1 -1
- package/dist/cjs/ez-application.cjs.entry.js +1 -1
- package/dist/cjs/ez-breadcrumb.cjs.entry.js +12 -2
- package/dist/cjs/ez-button.cjs.entry.js +1 -1
- package/dist/cjs/ez-calendar.cjs.entry.js +1 -1
- package/dist/cjs/ez-card-item.cjs.entry.js +1 -1
- package/dist/cjs/ez-check.cjs.entry.js +1 -1
- package/dist/cjs/ez-chip.cjs.entry.js +1 -1
- package/dist/cjs/ez-collapsible-box.cjs.entry.js +1 -1
- package/dist/cjs/ez-combo-box.cjs.entry.js +16 -10
- package/dist/cjs/ez-date-input.cjs.entry.js +2 -2
- package/dist/cjs/ez-date-time-input.cjs.entry.js +4 -12
- package/dist/cjs/ez-dialog.cjs.entry.js +1 -1
- package/dist/cjs/ez-dropdown.cjs.entry.js +1 -1
- package/dist/cjs/ez-file-item.cjs.entry.js +1 -1
- package/dist/cjs/ez-filter-input_4.cjs.entry.js +67 -6
- package/dist/cjs/ez-form-view.cjs.entry.js +30 -23
- package/dist/cjs/ez-form.cjs.entry.js +562 -545
- package/dist/cjs/ez-grid.cjs.entry.js +8 -5
- package/dist/cjs/ez-guide-navigator.cjs.entry.js +51 -3
- package/dist/cjs/ez-icon.cjs.entry.js +1 -1
- package/dist/cjs/ez-list.cjs.entry.js +11 -8
- package/dist/cjs/ez-loading-bar.cjs.entry.js +1 -1
- package/dist/cjs/ez-modal-container.cjs.entry.js +1 -1
- package/dist/cjs/ez-modal.cjs.entry.js +1 -1
- package/dist/cjs/ez-number-input.cjs.entry.js +1 -1
- package/dist/cjs/ez-popover.cjs.entry.js +1 -1
- package/dist/cjs/ez-popup.cjs.entry.js +1 -1
- package/dist/cjs/ez-radio-button.cjs.entry.js +1 -1
- package/dist/cjs/ez-search.cjs.entry.js +1 -1
- package/dist/cjs/ez-tabselector.cjs.entry.js +1 -1
- package/dist/cjs/ez-text-area.cjs.entry.js +1 -1
- package/dist/cjs/ez-text-edit.cjs.entry.js +1 -1
- package/dist/cjs/ez-text-input.cjs.entry.js +1 -1
- package/dist/cjs/ez-time-input.cjs.entry.js +1 -1
- package/dist/cjs/ez-toast.cjs.entry.js +1 -1
- package/dist/cjs/ez-upload.cjs.entry.js +1 -1
- package/dist/cjs/ez-view-stack.cjs.entry.js +1 -1
- package/dist/cjs/ezui.cjs.js +2 -2
- package/dist/cjs/{index-b54f47a1.js → index-892780f1.js} +0 -5
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/ez-breadcrumb/ez-breadcrumb.js +12 -2
- package/dist/collection/components/ez-combo-box/ez-combo-box.js +16 -10
- package/dist/collection/components/ez-date-input/ez-date-input.js +1 -1
- package/dist/collection/components/ez-date-time-input/ez-date-time-input.js +3 -11
- package/dist/collection/components/ez-form/ez-form.css +0 -6
- package/dist/collection/components/ez-form/ez-form.js +18 -239
- package/dist/collection/components/ez-form-view/ez-form-view.js +51 -0
- package/dist/collection/components/ez-form-view/fieldbuilder/templates/CheckBox.tpl.js +4 -4
- package/dist/collection/components/ez-form-view/fieldbuilder/templates/ComboBox.tpl.js +2 -2
- package/dist/collection/components/ez-form-view/fieldbuilder/templates/DateInput.tpl.js +2 -2
- package/dist/collection/components/ez-form-view/fieldbuilder/templates/FileInput.tpl.js +2 -2
- package/dist/collection/components/ez-form-view/fieldbuilder/templates/NumberInput.tpl.js +6 -6
- package/dist/collection/components/ez-form-view/fieldbuilder/templates/SearchInput.tpl.js +2 -2
- package/dist/collection/components/ez-form-view/fieldbuilder/templates/TextArea.tpl.js +2 -2
- package/dist/collection/components/ez-form-view/fieldbuilder/templates/TextInput.tpl.js +2 -2
- package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +5 -2
- package/dist/collection/components/ez-grid/ez-grid.css +4 -2
- package/dist/collection/components/ez-grid/ez-grid.js +1 -1
- package/dist/collection/components/ez-guide-navigator/ez-guide-navigator.css +1 -1
- package/dist/collection/components/ez-guide-navigator/ez-guide-navigator.js +218 -1
- package/dist/collection/components/ez-list/ez-list.css +5 -2
- package/dist/collection/components/ez-list/ez-list.js +27 -6
- package/dist/collection/components/ez-sidebar-button/ez-sidebar-button.css +2 -0
- package/dist/collection/components/ez-tree/ez-tree.js +151 -3
- package/dist/collection/components/ez-tree/types/Node.js +7 -1
- package/dist/collection/components/ez-tree/types/Tree.js +6 -0
- package/dist/collection/{components/ez-form → utils/form}/DataBinder.js +118 -4
- package/dist/collection/{components/ez-form → utils/form}/FormMetadata.js +83 -36
- package/dist/collection/utils/form/index.js +2 -0
- package/dist/collection/utils/index.js +2 -0
- package/dist/custom-elements/index.js +712 -565
- package/dist/esm/ez-actions-button.entry.js +1 -1
- package/dist/esm/ez-alert.entry.js +1 -1
- package/dist/esm/ez-application.entry.js +1 -1
- package/dist/esm/ez-breadcrumb.entry.js +13 -3
- package/dist/esm/ez-button.entry.js +1 -1
- package/dist/esm/ez-calendar.entry.js +1 -1
- package/dist/esm/ez-card-item.entry.js +1 -1
- package/dist/esm/ez-check.entry.js +1 -1
- package/dist/esm/ez-chip.entry.js +1 -1
- package/dist/esm/ez-collapsible-box.entry.js +1 -1
- package/dist/esm/ez-combo-box.entry.js +17 -11
- package/dist/esm/ez-date-input.entry.js +2 -2
- package/dist/esm/ez-date-time-input.entry.js +4 -12
- package/dist/esm/ez-dialog.entry.js +1 -1
- package/dist/esm/ez-dropdown.entry.js +1 -1
- package/dist/esm/ez-file-item.entry.js +1 -1
- package/dist/esm/ez-filter-input_4.entry.js +67 -6
- package/dist/esm/ez-form-view.entry.js +30 -23
- package/dist/esm/ez-form.entry.js +563 -546
- package/dist/esm/ez-grid.entry.js +8 -5
- package/dist/esm/ez-guide-navigator.entry.js +51 -3
- package/dist/esm/ez-icon.entry.js +1 -1
- package/dist/esm/ez-list.entry.js +11 -8
- package/dist/esm/ez-loading-bar.entry.js +1 -1
- package/dist/esm/ez-modal-container.entry.js +1 -1
- package/dist/esm/ez-modal.entry.js +1 -1
- package/dist/esm/ez-number-input.entry.js +1 -1
- package/dist/esm/ez-popover.entry.js +1 -1
- package/dist/esm/ez-popup.entry.js +1 -1
- package/dist/esm/ez-radio-button.entry.js +1 -1
- package/dist/esm/ez-search.entry.js +1 -1
- package/dist/esm/ez-tabselector.entry.js +1 -1
- package/dist/esm/ez-text-area.entry.js +1 -1
- package/dist/esm/ez-text-edit.entry.js +1 -1
- package/dist/esm/ez-text-input.entry.js +1 -1
- package/dist/esm/ez-time-input.entry.js +1 -1
- package/dist/esm/ez-toast.entry.js +1 -1
- package/dist/esm/ez-upload.entry.js +1 -1
- package/dist/esm/ez-view-stack.entry.js +1 -1
- package/dist/esm/ezui.js +3 -3
- package/dist/esm/{index-c27164d3.js → index-de655f48.js} +0 -5
- package/dist/esm/loader.js +3 -3
- package/dist/ezui/ezui.esm.js +1 -1
- package/dist/ezui/{p-85c1e00f.entry.js → p-06b3e801.entry.js} +1 -1
- package/dist/ezui/{p-216e1153.entry.js → p-07b99b94.entry.js} +1 -1
- package/dist/ezui/p-09271677.entry.js +1 -0
- package/dist/ezui/{p-044a3427.entry.js → p-0c7e81fe.entry.js} +1 -1
- package/dist/ezui/p-0e53898b.entry.js +1 -0
- package/dist/ezui/{p-124859c3.entry.js → p-36f7ec68.entry.js} +1 -1
- package/dist/ezui/p-4555df8f.entry.js +1 -0
- package/dist/ezui/{p-1806b3c6.entry.js → p-493e2af4.entry.js} +1 -1
- package/dist/ezui/p-50883460.entry.js +1 -0
- package/dist/ezui/p-581df847.entry.js +1 -0
- package/dist/ezui/{p-78b28632.entry.js → p-600f1732.entry.js} +1 -1
- package/dist/ezui/{p-74379544.entry.js → p-622c2d53.entry.js} +1 -1
- package/dist/ezui/{p-bb011a51.entry.js → p-62481744.entry.js} +1 -1
- package/dist/ezui/{p-064e558f.entry.js → p-6818dd0a.entry.js} +1 -1
- package/dist/ezui/{p-e8271a0e.entry.js → p-695facd0.entry.js} +1 -1
- package/dist/ezui/p-6cf406ff.entry.js +1 -0
- package/dist/ezui/{p-07d71b7a.entry.js → p-7147d43a.entry.js} +1 -1
- package/dist/ezui/{p-108acc0f.entry.js → p-7c8fb43e.entry.js} +1 -1
- package/dist/ezui/{p-00ea9b50.js → p-7ffd12e7.js} +2 -2
- package/dist/ezui/{p-aaba630e.entry.js → p-86d29565.entry.js} +1 -1
- package/dist/ezui/p-8d5ec02b.entry.js +1 -0
- package/dist/ezui/{p-149442dd.entry.js → p-9613fae6.entry.js} +1 -1
- package/dist/ezui/{p-38520b9c.entry.js → p-99d822cc.entry.js} +1 -1
- package/dist/ezui/p-9a1549c2.entry.js +1 -0
- package/dist/ezui/{p-330aef41.entry.js → p-a323b415.entry.js} +1 -1
- package/dist/ezui/{p-7ff5d0cc.entry.js → p-a4b281ca.entry.js} +1 -1
- package/dist/ezui/{p-e6cf82e8.entry.js → p-a67e056f.entry.js} +1 -1
- package/dist/ezui/p-ada6e6b0.entry.js +1 -0
- package/dist/ezui/{p-93c8bdc6.entry.js → p-b3c7b243.entry.js} +1 -1
- package/dist/ezui/{p-936ae3ac.entry.js → p-b941aeee.entry.js} +1 -1
- package/dist/ezui/{p-d015295f.entry.js → p-bbccda3f.entry.js} +1 -1
- package/dist/ezui/{p-66dba09c.entry.js → p-c0184982.entry.js} +1 -1
- package/dist/ezui/{p-ce1408dd.entry.js → p-cc40fcb3.entry.js} +1 -1
- package/dist/ezui/{p-80f79b1c.entry.js → p-cc5cfcb7.entry.js} +1 -1
- package/dist/ezui/{p-77c1ae43.entry.js → p-dc15b6d1.entry.js} +2 -2
- package/dist/ezui/{p-eae59101.entry.js → p-e6f3d036.entry.js} +1 -1
- package/dist/ezui/p-e748b5d3.entry.js +1 -0
- package/dist/ezui/{p-be4cc43f.entry.js → p-e85f1a6a.entry.js} +1 -1
- package/dist/ezui/{p-1cfae451.entry.js → p-eceb9382.entry.js} +1 -1
- package/dist/ezui/{p-bb0607a6.entry.js → p-fd87638e.entry.js} +1 -1
- package/dist/types/components/ez-breadcrumb/ez-breadcrumb.d.ts +2 -1
- package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +0 -1
- package/dist/types/components/ez-form/ez-form.d.ts +3 -23
- package/dist/types/components/ez-form/store/form.slice.d.ts +2 -2
- package/dist/types/components/ez-form-view/ez-form-view.d.ts +7 -0
- package/dist/types/components/ez-form-view/fieldbuilder/templates/ComboBox.tpl.d.ts +1 -1
- package/dist/types/components/ez-form-view/fieldbuilder/templates/DateInput.tpl.d.ts +1 -1
- package/dist/types/components/ez-form-view/fieldbuilder/templates/FileInput.tpl.d.ts +1 -1
- package/dist/types/components/ez-form-view/fieldbuilder/templates/NumberInput.tpl.d.ts +2 -2
- package/dist/types/components/ez-form-view/fieldbuilder/templates/SearchInput.tpl.d.ts +1 -1
- package/dist/types/components/ez-form-view/fieldbuilder/templates/TextArea.tpl.d.ts +1 -1
- package/dist/types/components/ez-form-view/fieldbuilder/templates/TextInput.tpl.d.ts +1 -1
- package/dist/types/components/ez-form-view/interfaces/IFormViewField.d.ts +1 -0
- package/dist/types/components/ez-guide-navigator/ez-guide-navigator.d.ts +32 -0
- package/dist/types/components/ez-guide-navigator/interfaces/IGuideItem.d.ts +1 -0
- package/dist/types/components/ez-list/ez-list.d.ts +4 -0
- package/dist/types/components/ez-tree/ez-tree.d.ts +18 -0
- package/dist/types/components.d.ts +79 -31
- package/dist/types/utils/form/DataBinder.d.ts +31 -0
- package/dist/types/utils/form/FormMetadata.d.ts +23 -0
- package/dist/types/utils/form/index.d.ts +2 -0
- package/dist/types/utils/form/interfaces/IFormCardConfig.d.ts +5 -0
- package/dist/types/utils/form/interfaces/IFormConfig.d.ts +12 -0
- package/dist/types/utils/form/interfaces/IFormSheetMetadata.d.ts +6 -0
- package/dist/types/{components/ez-form → utils/form}/interfaces/IRecordValidator.d.ts +1 -2
- package/dist/types/utils/form/interfaces/ISummaryField.d.ts +4 -0
- package/dist/types/{interfaces/ez-form → utils/form/interfaces}/ITabConfig.d.ts +1 -0
- package/dist/types/{components/ez-form → utils/form}/interfaces/index.d.ts +6 -4
- package/dist/types/utils/index.d.ts +2 -0
- package/package.json +3 -3
- package/dist/collection/interfaces/ez-form/IDefaultConfig.js +0 -1
- package/dist/collection/interfaces/ez-form/IFieldConfig.js +0 -1
- package/dist/collection/interfaces/ez-form/IFieldMetadata.js +0 -1
- package/dist/collection/interfaces/ez-form/IFieldSetMetadata.js +0 -1
- package/dist/collection/interfaces/ez-form/IFormSheetMetadata.js +0 -1
- package/dist/collection/interfaces/ez-form/IInvalidField.js +0 -1
- package/dist/collection/interfaces/ez-form/IRecordValidator.js +0 -1
- package/dist/collection/interfaces/ez-form/IValidationResult.js +0 -1
- package/dist/collection/interfaces/ez-form/index.js +0 -1
- package/dist/ezui/p-1a1c2eda.entry.js +0 -1
- package/dist/ezui/p-51ecf138.entry.js +0 -1
- package/dist/ezui/p-5473e08d.entry.js +0 -1
- package/dist/ezui/p-74b3615b.entry.js +0 -1
- package/dist/ezui/p-77d70bae.entry.js +0 -1
- package/dist/ezui/p-90c3d4fd.entry.js +0 -1
- package/dist/ezui/p-97cfbd29.entry.js +0 -1
- package/dist/ezui/p-a0e47238.entry.js +0 -1
- package/dist/ezui/p-bfca509e.entry.js +0 -1
- package/dist/ezui/p-cd1e0679.entry.js +0 -1
- package/dist/types/components/ez-form/DataBinder.d.ts +0 -22
- package/dist/types/components/ez-form/FormMetadata.d.ts +0 -16
- package/dist/types/components/ez-form/interfaces/IFormConfig.d.ts +0 -7
- package/dist/types/components/ez-form/interfaces/IFormSheetMetadata.d.ts +0 -9
- package/dist/types/components/ez-form/interfaces/ITabConfig.d.ts +0 -5
- package/dist/types/interfaces/ez-form/IDefaultConfig.d.ts +0 -5
- package/dist/types/interfaces/ez-form/IFieldConfig.d.ts +0 -13
- package/dist/types/interfaces/ez-form/IFieldMetadata.d.ts +0 -6
- package/dist/types/interfaces/ez-form/IFieldSetMetadata.d.ts +0 -5
- package/dist/types/interfaces/ez-form/IFormConfig.d.ts +0 -7
- package/dist/types/interfaces/ez-form/IFormSheetMetadata.d.ts +0 -10
- package/dist/types/interfaces/ez-form/IInvalidField.d.ts +0 -4
- package/dist/types/interfaces/ez-form/IRecordValidator.d.ts +0 -6
- package/dist/types/interfaces/ez-form/IValidationResult.d.ts +0 -8
- package/dist/types/interfaces/ez-form/index.d.ts +0 -10
- /package/dist/collection/{components/ez-form → utils/form}/interfaces/IDefaultConfig.js +0 -0
- /package/dist/collection/{components/ez-form → utils/form}/interfaces/IFieldConfig.js +0 -0
- /package/dist/collection/{components/ez-form/interfaces/IFormConfig.js → utils/form/interfaces/IFormCardConfig.js} +0 -0
- /package/dist/collection/{interfaces/ez-form → utils/form/interfaces}/IFormConfig.js +0 -0
- /package/dist/collection/{components/ez-form → utils/form}/interfaces/IFormSheetMetadata.js +0 -0
- /package/dist/collection/{components/ez-form → utils/form}/interfaces/IInvalidField.js +0 -0
- /package/dist/collection/{components/ez-form → utils/form}/interfaces/IRecordValidator.js +0 -0
- /package/dist/collection/{components/ez-form/interfaces/ITabConfig.js → utils/form/interfaces/ISummaryField.js} +0 -0
- /package/dist/collection/{interfaces/ez-form → utils/form/interfaces}/ITabConfig.js +0 -0
- /package/dist/collection/{components/ez-form → utils/form}/interfaces/IValidationResult.js +0 -0
- /package/dist/collection/{components/ez-form → utils/form}/interfaces/index.js +0 -0
- /package/dist/types/{components/ez-form → utils/form}/interfaces/IDefaultConfig.d.ts +0 -0
- /package/dist/types/{components/ez-form → utils/form}/interfaces/IFieldConfig.d.ts +0 -0
- /package/dist/types/{components/ez-form → utils/form}/interfaces/IInvalidField.d.ts +0 -0
- /package/dist/types/{components/ez-form → utils/form}/interfaces/IValidationResult.d.ts +0 -0
|
@@ -2,11 +2,514 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const index = require('./index-
|
|
5
|
+
const index = require('./index-892780f1.js');
|
|
6
6
|
const core = require('@sankhyalabs/core');
|
|
7
7
|
const ApplicationUtils = require('./ApplicationUtils-1eef635f.js');
|
|
8
8
|
require('./DialogType-2114c337.js');
|
|
9
9
|
|
|
10
|
+
const DETAIL_PATTERN = /child\[([^\]]+)\]/;
|
|
11
|
+
const REGEX_DEFAULT_VAR_KEY = /\$\{.+\}/;
|
|
12
|
+
class FormMetadata {
|
|
13
|
+
constructor() {
|
|
14
|
+
this._sheets = new Map();
|
|
15
|
+
this._requiredFields = [];
|
|
16
|
+
this._cleanOnCopyFields = [];
|
|
17
|
+
this._defaultValues = {};
|
|
18
|
+
}
|
|
19
|
+
static getDetailName(name) {
|
|
20
|
+
const result = DETAIL_PATTERN.exec(name);
|
|
21
|
+
return result ? result[1] : undefined;
|
|
22
|
+
}
|
|
23
|
+
getSheet(name) {
|
|
24
|
+
return this._sheets.get(name);
|
|
25
|
+
}
|
|
26
|
+
getAllSheets() {
|
|
27
|
+
return this._sheets;
|
|
28
|
+
}
|
|
29
|
+
addSheet(sheet) {
|
|
30
|
+
this._sheets.set(sheet.name, sheet);
|
|
31
|
+
}
|
|
32
|
+
addRequiredFields(fields) {
|
|
33
|
+
this._requiredFields = this._requiredFields.concat(fields);
|
|
34
|
+
}
|
|
35
|
+
getRequiredFields() {
|
|
36
|
+
return this._requiredFields;
|
|
37
|
+
}
|
|
38
|
+
addCleanOnCopyFields(fields) {
|
|
39
|
+
this._cleanOnCopyFields = this._cleanOnCopyFields.concat(fields);
|
|
40
|
+
}
|
|
41
|
+
getCleanOnCopyFields() {
|
|
42
|
+
return this._cleanOnCopyFields;
|
|
43
|
+
}
|
|
44
|
+
addDefaultValues(defaultValues) {
|
|
45
|
+
return this._defaultValues = Object.assign(Object.assign({}, this._defaultValues), defaultValues);
|
|
46
|
+
}
|
|
47
|
+
getDefaultValues() {
|
|
48
|
+
const result = {};
|
|
49
|
+
Object.entries(this._defaultValues).forEach(([key, value]) => {
|
|
50
|
+
if (typeof value === "string") {
|
|
51
|
+
const result = REGEX_DEFAULT_VAR_KEY.exec(value);
|
|
52
|
+
if (result) {
|
|
53
|
+
value = this.getDefaultVar(result[0]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
result[key] = value;
|
|
57
|
+
});
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
getDefaultVar(name) {
|
|
61
|
+
if (name === "${data}") {
|
|
62
|
+
return core.DateUtils.getToday();
|
|
63
|
+
}
|
|
64
|
+
if (name === "${datahora}") {
|
|
65
|
+
return core.DateUtils.getToday(true);
|
|
66
|
+
}
|
|
67
|
+
return this._defaultVars ? this._defaultVars.get(name) : undefined;
|
|
68
|
+
}
|
|
69
|
+
setDefaultVars(vars) {
|
|
70
|
+
this._defaultVars = vars;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const buildFormConfigFromDataUnit = (dataUnit) => {
|
|
74
|
+
const unitMD = dataUnit.metadata;
|
|
75
|
+
let fields;
|
|
76
|
+
if (unitMD) {
|
|
77
|
+
fields = unitMD.fields
|
|
78
|
+
.filter(descriptor => descriptor.visible !== false)
|
|
79
|
+
.map(descriptor => { return { name: descriptor.name, defaultValue: descriptor.defaultValue }; });
|
|
80
|
+
}
|
|
81
|
+
const config = { fields };
|
|
82
|
+
return config;
|
|
83
|
+
};
|
|
84
|
+
const buildFormMetadata = (config, dataUnit, includeDetails = false) => {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
if (config == undefined) {
|
|
87
|
+
config = buildFormConfigFromDataUnit(dataUnit);
|
|
88
|
+
}
|
|
89
|
+
const sheets = new Map();
|
|
90
|
+
const hiddenTabs = new Map();
|
|
91
|
+
const requiredFields = [];
|
|
92
|
+
const cleanOnCopyFields = [];
|
|
93
|
+
const defaultValues = {};
|
|
94
|
+
(_a = config === null || config === void 0 ? void 0 : config.tabs) === null || _a === void 0 ? void 0 : _a.forEach((tab) => {
|
|
95
|
+
if (!hiddenTabs.has(tab.label) && tab.visible === false) {
|
|
96
|
+
hiddenTabs.set(tab.label, tab);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
(_b = config === null || config === void 0 ? void 0 : config.fields) === null || _b === void 0 ? void 0 : _b.forEach((field) => {
|
|
100
|
+
var _a, _b, _c;
|
|
101
|
+
if (field.visible !== false) {
|
|
102
|
+
const tabConfig = getTabConfig(field.tab || "__main", sheets);
|
|
103
|
+
if (hiddenTabs.has(tabConfig.label)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const descriptor = dataUnit.getField(field.name);
|
|
107
|
+
if (descriptor && tabConfig.visible) {
|
|
108
|
+
if (!sheets.has(tabConfig)) {
|
|
109
|
+
sheets.set(tabConfig, []);
|
|
110
|
+
}
|
|
111
|
+
const formField = buildFormField(descriptor, field);
|
|
112
|
+
sheets.get(tabConfig).push(formField);
|
|
113
|
+
if (formField.required) {
|
|
114
|
+
requiredFields.push(field.name);
|
|
115
|
+
}
|
|
116
|
+
const cleanOnCopy = field.cleanOnCopy == undefined ? (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy : field.cleanOnCopy;
|
|
117
|
+
if (cleanOnCopy || ((_b = descriptor.properties) === null || _b === void 0 ? void 0 : _b.cleanOnCopy)) {
|
|
118
|
+
cleanOnCopyFields.push(field.name);
|
|
119
|
+
}
|
|
120
|
+
let defaultValue = field.defaultValue == undefined ? (_c = descriptor.properties) === null || _c === void 0 ? void 0 : _c.defaultValue : field.defaultValue;
|
|
121
|
+
if (defaultValue) {
|
|
122
|
+
if ((typeof defaultValue === "object") && defaultValue["type"] === "V") {
|
|
123
|
+
// Atualmente a configuração do formulário eventualmente deposita um objeto
|
|
124
|
+
// prototipado como {type: "V", value: "${nome.de.variavel}"} para campos com
|
|
125
|
+
// valor padrão do tipo variável. Dessa forma precisamos "desenvelopar" o valor
|
|
126
|
+
// para que a variável chegue corretamente a seu destino.
|
|
127
|
+
defaultValue = defaultValue["value"];
|
|
128
|
+
}
|
|
129
|
+
defaultValues[field.name] = defaultValue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
const metadata = new FormMetadata();
|
|
135
|
+
metadata.setDefaultVars(config.defaultVars);
|
|
136
|
+
if (includeDetails) {
|
|
137
|
+
const unitMD = dataUnit.metadata;
|
|
138
|
+
if (unitMD != undefined && unitMD.children != undefined) {
|
|
139
|
+
unitMD.children.forEach(child => {
|
|
140
|
+
const { label, name, fields } = buildDetailSheet(child);
|
|
141
|
+
sheets.set({ name, label }, fields);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
Array.from(sheets.entries())
|
|
146
|
+
.sort(sortTabs)
|
|
147
|
+
.forEach(([key, fields]) => {
|
|
148
|
+
metadata.addSheet({
|
|
149
|
+
label: (key.label === "__main") ? "Principal" : key.label,
|
|
150
|
+
name: key.name || key.label,
|
|
151
|
+
fields
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
metadata.addRequiredFields(requiredFields);
|
|
155
|
+
metadata.addCleanOnCopyFields(cleanOnCopyFields);
|
|
156
|
+
metadata.addDefaultValues(defaultValues);
|
|
157
|
+
return metadata;
|
|
158
|
+
};
|
|
159
|
+
const buildFormField = (descriptor, config) => {
|
|
160
|
+
let { name, label, group } = Object.assign({}, config);
|
|
161
|
+
let { readOnly, required } = Object.assign({}, config);
|
|
162
|
+
let props;
|
|
163
|
+
let userInterface;
|
|
164
|
+
if (descriptor) {
|
|
165
|
+
label = label || descriptor.label;
|
|
166
|
+
name = name || descriptor.name;
|
|
167
|
+
required = descriptor.required || (config === null || config === void 0 ? void 0 : config.required);
|
|
168
|
+
readOnly = descriptor.readOnly || (config === null || config === void 0 ? void 0 : config.readOnly);
|
|
169
|
+
props = descriptor.properties;
|
|
170
|
+
userInterface = descriptor.userInterface;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
name, label, group,
|
|
174
|
+
readOnly, required,
|
|
175
|
+
props,
|
|
176
|
+
userInterface: userInterface || core.UserInterface.SHORTTEXT
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
const getTabConfig = (tab, sheets) => {
|
|
180
|
+
const tabConfig = (typeof tab === "string" ? Array.from(sheets.keys()).find(t => t.label === tab) : tab);
|
|
181
|
+
return tabConfig || { label: tab, visible: true };
|
|
182
|
+
};
|
|
183
|
+
const sortTabs = (a, b) => {
|
|
184
|
+
return a[0].label == '__main' ? -1 : (a[0].order || 10000) - (b[0].order || 10000);
|
|
185
|
+
};
|
|
186
|
+
const buildDetailSheet = (child) => {
|
|
187
|
+
return {
|
|
188
|
+
name: `child[${child.name}]`,
|
|
189
|
+
label: child.label,
|
|
190
|
+
fields: []
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
class DataBinder {
|
|
195
|
+
constructor(dataUnit) {
|
|
196
|
+
this._invalidFields = new Map();
|
|
197
|
+
this.onDataUnitEvent = (action) => {
|
|
198
|
+
var _a;
|
|
199
|
+
switch (action.type) {
|
|
200
|
+
case core.Action.DATA_LOADED:
|
|
201
|
+
case core.Action.DATA_SAVED:
|
|
202
|
+
case core.Action.RECORDS_REMOVED:
|
|
203
|
+
case core.Action.RECORDS_ADDED:
|
|
204
|
+
case core.Action.RECORDS_COPIED:
|
|
205
|
+
case core.Action.EDITION_CANCELED:
|
|
206
|
+
case core.Action.SELECTION_CHANGED:
|
|
207
|
+
case core.Action.NEXT_SELECTED:
|
|
208
|
+
case core.Action.PREVIOUS_SELECTED:
|
|
209
|
+
this.clearInvalid();
|
|
210
|
+
case core.Action.DATA_CHANGED:
|
|
211
|
+
case core.Action.CHANGE_UNDONE:
|
|
212
|
+
case core.Action.CHANGE_REDONE:
|
|
213
|
+
case core.Action.RECORD_LOADED:
|
|
214
|
+
(_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
|
|
215
|
+
this.updateValue(field.fieldName, field.field);
|
|
216
|
+
});
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
this._fields = new Map();
|
|
221
|
+
this._dataUnit = dataUnit;
|
|
222
|
+
this._dataUnit.subscribe(this.onDataUnitEvent);
|
|
223
|
+
this._dataUnit.addInterceptor(this);
|
|
224
|
+
}
|
|
225
|
+
bind(fields, currentContextName, formMetadata, recordsValidator) {
|
|
226
|
+
fields.forEach(fieldElement => {
|
|
227
|
+
const { fieldName, contextName } = fieldElement.dataset;
|
|
228
|
+
if (contextName == undefined || contextName === currentContextName) {
|
|
229
|
+
this.updateBind(fieldName, fieldElement);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
this._formMetadata = formMetadata;
|
|
233
|
+
this._recordsValidator = recordsValidator;
|
|
234
|
+
}
|
|
235
|
+
onDisconnectedCallback() {
|
|
236
|
+
this._dataUnit.unsubscribe(this.onDataUnitEvent);
|
|
237
|
+
this._dataUnit.removeInterceptor(this);
|
|
238
|
+
}
|
|
239
|
+
markInvalid(field) {
|
|
240
|
+
this._invalidFields.set(field.name, field);
|
|
241
|
+
if (this._fields.has(field.name)) {
|
|
242
|
+
const fieldElement = this._fields.get(field.name).field;
|
|
243
|
+
if (!fieldElement["errorMessage"]) {
|
|
244
|
+
this.updateErrorMessage(field.name, fieldElement);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
clearInvalid() {
|
|
249
|
+
this._invalidFields.clear();
|
|
250
|
+
this._fields.forEach(fieldBinder => {
|
|
251
|
+
const fieldElement = fieldBinder.field;
|
|
252
|
+
fieldElement["errorMessage"] = "";
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
updateValue(fieldName, field) {
|
|
256
|
+
const bind = this._fields.get(fieldName);
|
|
257
|
+
try {
|
|
258
|
+
if (bind) {
|
|
259
|
+
bind.listen = false;
|
|
260
|
+
}
|
|
261
|
+
field["value"] = this._dataUnit.getFieldValue(fieldName);
|
|
262
|
+
this.updateErrorMessage(fieldName, field);
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
if (bind) {
|
|
266
|
+
bind.listen = true;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
validate() {
|
|
271
|
+
return new Promise((accept, reject) => {
|
|
272
|
+
var _a;
|
|
273
|
+
const records = this._dataUnit.getModifiedRecords();
|
|
274
|
+
for (let i = 0; i < records.length; i++) {
|
|
275
|
+
const record = records[i];
|
|
276
|
+
const invalidResults = [];
|
|
277
|
+
let validationResult = this.validateRequired(record);
|
|
278
|
+
if (validationResult && !validationResult.isValid) {
|
|
279
|
+
invalidResults.push(validationResult);
|
|
280
|
+
}
|
|
281
|
+
validationResult = (_a = this._recordsValidator) === null || _a === void 0 ? void 0 : _a.validateRecord(record);
|
|
282
|
+
if (validationResult && !validationResult.isValid) {
|
|
283
|
+
invalidResults.push(validationResult);
|
|
284
|
+
}
|
|
285
|
+
if (invalidResults.length > 0) {
|
|
286
|
+
this.processValidationResult(invalidResults);
|
|
287
|
+
reject();
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return accept();
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
validateRequired(record) {
|
|
295
|
+
const requiredFields = this._formMetadata.getRequiredFields();
|
|
296
|
+
const invalidFields = [];
|
|
297
|
+
new Set(requiredFields).forEach(field => {
|
|
298
|
+
const value = record[field];
|
|
299
|
+
if (value == undefined || value === "") {
|
|
300
|
+
const errorMessage = this.getErrorMessage(field);
|
|
301
|
+
if (errorMessage) {
|
|
302
|
+
invalidFields.push({ name: field, message: errorMessage });
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
invalidFields.push({ name: field, message: "Essa informação é obrigatória" });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
if (invalidFields.length > 0) {
|
|
310
|
+
return { isValid: false, invalidFields, infoMessage: "Há pelo menos um campo obrigatório não preenchido." };
|
|
311
|
+
}
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
processValidationResult(validationResult) {
|
|
315
|
+
validationResult.forEach(invalidResult => {
|
|
316
|
+
const invalidFields = invalidResult.invalidFields;
|
|
317
|
+
if (invalidFields) {
|
|
318
|
+
invalidFields.forEach(field => {
|
|
319
|
+
this.markInvalid(field);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (invalidResult.infoMessage) {
|
|
323
|
+
ApplicationUtils.ApplicationUtils.info(invalidResult.infoMessage);
|
|
324
|
+
}
|
|
325
|
+
if (invalidResult.errorMessage) {
|
|
326
|
+
const { errorTitle, errorMessage } = invalidResult;
|
|
327
|
+
ApplicationUtils.ApplicationUtils.error(errorTitle, errorMessage);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
updateErrorMessage(fieldName, field) {
|
|
332
|
+
const invalidField = this._invalidFields.get(fieldName);
|
|
333
|
+
if (invalidField) {
|
|
334
|
+
field["errorMessage"] = invalidField.message;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
getErrorMessage(fieldName) {
|
|
338
|
+
if (this._fields.has(fieldName)) {
|
|
339
|
+
const fieldElement = this._fields.get(fieldName).field;
|
|
340
|
+
return fieldElement["errorMessage"] || null;
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
updateBind(fieldName, field) {
|
|
345
|
+
const oldBind = this._fields.get(fieldName);
|
|
346
|
+
if (oldBind) {
|
|
347
|
+
oldBind.destroy();
|
|
348
|
+
}
|
|
349
|
+
field["value"] = this._dataUnit.getFieldValue(fieldName);
|
|
350
|
+
this.updateErrorMessage(fieldName, field);
|
|
351
|
+
this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, waitingChange) => this.changeStarted(fieldName, waitingChange), (fieldName) => this.cancelWaitingChange(fieldName), (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
|
|
352
|
+
this.bindSearchOptionsLoader(fieldName, field);
|
|
353
|
+
this.applyEzUploadContext(fieldName, field);
|
|
354
|
+
}
|
|
355
|
+
changeStarted(fieldName, waitingChange) {
|
|
356
|
+
/**
|
|
357
|
+
* se o waitingChange não é blocante, add um event listener pra
|
|
358
|
+
* fazer o accept da promise
|
|
359
|
+
*
|
|
360
|
+
* se não tiver promise no waitingChange, eu crio uma e resolvo no bind
|
|
361
|
+
*
|
|
362
|
+
*
|
|
363
|
+
*/
|
|
364
|
+
if (this._dataUnit.records.length === 0) {
|
|
365
|
+
this._dataUnit.addRecord();
|
|
366
|
+
}
|
|
367
|
+
if (!waitingChange.blocking && waitingChange.promise == undefined) {
|
|
368
|
+
const bind = this._fields.get(fieldName);
|
|
369
|
+
if (bind) {
|
|
370
|
+
waitingChange.promise = new Promise((resolve, reject) => {
|
|
371
|
+
bind.waitingChangePromiseResolve = resolve;
|
|
372
|
+
bind.waitingChangePromiseReject = reject;
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
this._dataUnit.startChange(fieldName, waitingChange);
|
|
377
|
+
}
|
|
378
|
+
cancelWaitingChange(fieldName) {
|
|
379
|
+
if (this._dataUnit.waitingForChange(fieldName)) {
|
|
380
|
+
this._dataUnit.cancelWaitingChange(fieldName);
|
|
381
|
+
const bind = this._fields.get(fieldName);
|
|
382
|
+
if (bind) {
|
|
383
|
+
bind.rejectWaitingChange(new core.WaitingChangeException("Change canceled", fieldName));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
setFieldValue(fieldName, newValue) {
|
|
388
|
+
if (this._dataUnit.records.length === 0) {
|
|
389
|
+
this._dataUnit.addRecord();
|
|
390
|
+
}
|
|
391
|
+
this._invalidFields.delete(fieldName);
|
|
392
|
+
this._dataUnit.setFieldValue(fieldName, newValue);
|
|
393
|
+
if (this._dataUnit.waitingForChange(fieldName)) {
|
|
394
|
+
const bind = this._fields.get(fieldName);
|
|
395
|
+
if (bind) {
|
|
396
|
+
bind.acceptWaitingChange();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
bindSearchOptionsLoader(fieldName, field) {
|
|
401
|
+
if (field.nodeName === "EZ-SEARCH" && field["optionLoader"] == undefined) {
|
|
402
|
+
const loader = core.ApplicationContext.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");
|
|
403
|
+
if (loader) {
|
|
404
|
+
field["optionLoader"] = (arg) => {
|
|
405
|
+
return loader(arg, fieldName, this._dataUnit);
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
applyEzUploadContext(fieldName, field) {
|
|
411
|
+
var _a, _b;
|
|
412
|
+
if (field.nodeName === "EZ-UPLOAD") {
|
|
413
|
+
field["urlUpload"] = core.ApplicationContext.getContextValue("__EZUI__UPLOAD__ADD__URL__");
|
|
414
|
+
field["urlDelete"] = core.ApplicationContext.getContextValue("__EZUI__UPLOAD__DEL__URL__");
|
|
415
|
+
const descriptor = this._dataUnit.getField(fieldName);
|
|
416
|
+
const destination = (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.DESTINATION;
|
|
417
|
+
if (destination) {
|
|
418
|
+
field["requestHeaders"] = { XTRAINF: `{"destination": "${destination}"}` };
|
|
419
|
+
}
|
|
420
|
+
field["maxFiles"] = ((_b = descriptor.properties) === null || _b === void 0 ? void 0 : _b.MAX_FILES) || 0;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
interceptAction(action) {
|
|
424
|
+
var _a;
|
|
425
|
+
if (action.type === core.Action.RECORDS_COPIED) {
|
|
426
|
+
const cleanFields = this._formMetadata.getCleanOnCopyFields();
|
|
427
|
+
if (cleanFields) {
|
|
428
|
+
const records = action.payload;
|
|
429
|
+
return new core.DataUnitAction(core.Action.RECORDS_COPIED, records.map(record => {
|
|
430
|
+
const newRecord = Object.assign({}, record);
|
|
431
|
+
cleanFields.forEach(fieldName => delete newRecord[fieldName]);
|
|
432
|
+
return newRecord;
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (action.type === core.Action.SAVING_DATA) {
|
|
437
|
+
return new Promise((resolve) => {
|
|
438
|
+
this.validate()
|
|
439
|
+
.then(() => resolve(action))
|
|
440
|
+
.catch(() => { });
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
if (action.type === core.Action.RECORDS_ADDED) {
|
|
444
|
+
const defaultValues = (_a = this._formMetadata) === null || _a === void 0 ? void 0 : _a.getDefaultValues();
|
|
445
|
+
if (defaultValues) {
|
|
446
|
+
const records = action.payload;
|
|
447
|
+
return new core.DataUnitAction(core.Action.RECORDS_ADDED, records.map(record => {
|
|
448
|
+
const newRecord = Object.assign({}, record);
|
|
449
|
+
for (const field in defaultValues) {
|
|
450
|
+
const defaultValue = this.getFormattedValue(defaultValues[field]);
|
|
451
|
+
const recordValue = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
452
|
+
newRecord[field] = this._dataUnit.valueFromString(field, recordValue);
|
|
453
|
+
}
|
|
454
|
+
return newRecord;
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return action;
|
|
459
|
+
}
|
|
460
|
+
getFormattedValue(defaultValue) {
|
|
461
|
+
if (defaultValue == undefined || typeof defaultValue !== "object") {
|
|
462
|
+
return defaultValue;
|
|
463
|
+
}
|
|
464
|
+
if ("formattedValue" in defaultValue) {
|
|
465
|
+
return defaultValue.formattedValue;
|
|
466
|
+
}
|
|
467
|
+
return defaultValue.value;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
class Bind {
|
|
471
|
+
constructor() {
|
|
472
|
+
this.listen = true;
|
|
473
|
+
this.startChangeEventName = "ezStartChange";
|
|
474
|
+
this.cancelWaitingChangeEventName = "ezCancelWaitingChange";
|
|
475
|
+
this.changeEventName = "ezChange";
|
|
476
|
+
}
|
|
477
|
+
destroy() {
|
|
478
|
+
this.field.removeEventListener(this.startChangeEventName, this.startChangeListener);
|
|
479
|
+
this.field.removeEventListener(this.cancelWaitingChangeEventName, this.cancelWaitingChangeListener);
|
|
480
|
+
this.field.removeEventListener(this.changeEventName, this.changeListener);
|
|
481
|
+
}
|
|
482
|
+
acceptWaitingChange() {
|
|
483
|
+
if (this.waitingChangePromiseResolve) {
|
|
484
|
+
this.waitingChangePromiseResolve();
|
|
485
|
+
this.waitingChangePromiseReject = undefined;
|
|
486
|
+
this.waitingChangePromiseResolve = undefined;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
rejectWaitingChange(reason) {
|
|
490
|
+
if (this.waitingChangePromiseReject) {
|
|
491
|
+
this.waitingChangePromiseReject(reason);
|
|
492
|
+
this.waitingChangePromiseReject = undefined;
|
|
493
|
+
this.waitingChangePromiseResolve = undefined;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
static create(fieldName, field, startChangeCallback, cancelWaitingChangeCallback, changeCallback) {
|
|
497
|
+
const b = new Bind();
|
|
498
|
+
b.field = field;
|
|
499
|
+
b.fieldName = fieldName;
|
|
500
|
+
b.startChangeListener = (evt) => { if (b.listen)
|
|
501
|
+
startChangeCallback(fieldName, evt.detail); };
|
|
502
|
+
b.field.addEventListener(b.startChangeEventName, b.startChangeListener);
|
|
503
|
+
b.cancelWaitingChangeListener = () => { if (b.listen)
|
|
504
|
+
cancelWaitingChangeCallback(fieldName); };
|
|
505
|
+
b.field.addEventListener(b.cancelWaitingChangeEventName, b.cancelWaitingChangeListener);
|
|
506
|
+
b.changeListener = (evt) => { if (b.listen)
|
|
507
|
+
changeCallback(fieldName, evt.detail); };
|
|
508
|
+
b.field.addEventListener(b.changeEventName, b.changeListener);
|
|
509
|
+
return b;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
10
513
|
/**
|
|
11
514
|
* Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
|
|
12
515
|
*
|
|
@@ -283,257 +786,51 @@ function createStore(reducer, preloadedState, enhancer) {
|
|
|
283
786
|
|
|
284
787
|
function observable() {
|
|
285
788
|
var _ref;
|
|
286
|
-
|
|
287
|
-
var outerSubscribe = subscribe;
|
|
288
|
-
return _ref = {
|
|
289
|
-
/**
|
|
290
|
-
* The minimal observable subscription method.
|
|
291
|
-
* @param {Object} observer Any object that can be used as an observer.
|
|
292
|
-
* The observer object should have a `next` method.
|
|
293
|
-
* @returns {subscription} An object with an `unsubscribe` method that can
|
|
294
|
-
* be used to unsubscribe the observable from the store, and prevent further
|
|
295
|
-
* emission of values from the observable.
|
|
296
|
-
*/
|
|
297
|
-
subscribe: function subscribe(observer) {
|
|
298
|
-
if (typeof observer !== 'object' || observer === null) {
|
|
299
|
-
throw new Error(formatProdErrorMessage(11) );
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function observeState() {
|
|
303
|
-
if (observer.next) {
|
|
304
|
-
observer.next(getState());
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
observeState();
|
|
309
|
-
var unsubscribe = outerSubscribe(observeState);
|
|
310
|
-
return {
|
|
311
|
-
unsubscribe: unsubscribe
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
}, _ref[$$observable] = function () {
|
|
315
|
-
return this;
|
|
316
|
-
}, _ref;
|
|
317
|
-
} // When a store is created, an "INIT" action is dispatched so that every
|
|
318
|
-
// reducer returns their initial state. This effectively populates
|
|
319
|
-
// the initial state tree.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
dispatch({
|
|
323
|
-
type: ActionTypes.INIT
|
|
324
|
-
});
|
|
325
|
-
return _ref2 = {
|
|
326
|
-
dispatch: dispatch,
|
|
327
|
-
subscribe: subscribe,
|
|
328
|
-
getState: getState,
|
|
329
|
-
replaceReducer: replaceReducer
|
|
330
|
-
}, _ref2[$$observable] = observable, _ref2;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
class DataBinder {
|
|
334
|
-
constructor(dataUnit) {
|
|
335
|
-
this._invalidFields = new Map();
|
|
336
|
-
this.onDataUnitEvent = (action) => {
|
|
337
|
-
var _a;
|
|
338
|
-
switch (action.type) {
|
|
339
|
-
case core.Action.DATA_LOADED:
|
|
340
|
-
case core.Action.DATA_SAVED:
|
|
341
|
-
case core.Action.RECORDS_REMOVED:
|
|
342
|
-
case core.Action.RECORDS_ADDED:
|
|
343
|
-
case core.Action.RECORDS_COPIED:
|
|
344
|
-
case core.Action.EDITION_CANCELED:
|
|
345
|
-
case core.Action.SELECTION_CHANGED:
|
|
346
|
-
case core.Action.NEXT_SELECTED:
|
|
347
|
-
case core.Action.PREVIOUS_SELECTED:
|
|
348
|
-
this.clearInvalid();
|
|
349
|
-
case core.Action.DATA_CHANGED:
|
|
350
|
-
case core.Action.CHANGE_UNDONE:
|
|
351
|
-
case core.Action.CHANGE_REDONE:
|
|
352
|
-
case core.Action.RECORD_LOADED:
|
|
353
|
-
(_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
|
|
354
|
-
this.updateValue(field.fieldName, field.field);
|
|
355
|
-
});
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
this._fields = new Map();
|
|
360
|
-
this._dataUnit = dataUnit;
|
|
361
|
-
this._dataUnit.subscribe(this.onDataUnitEvent);
|
|
362
|
-
}
|
|
363
|
-
bind(fields) {
|
|
364
|
-
fields.forEach(fieldElement => {
|
|
365
|
-
const fieldName = fieldElement.dataset.fieldName;
|
|
366
|
-
this.updateBind(fieldName, fieldElement);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
onDisconnectedCallback() {
|
|
370
|
-
this._dataUnit.unsubscribe(this.onDataUnitEvent);
|
|
371
|
-
}
|
|
372
|
-
markInvalid(field) {
|
|
373
|
-
this._invalidFields.set(field.name, field);
|
|
374
|
-
if (this._fields.has(field.name)) {
|
|
375
|
-
const fieldElement = this._fields.get(field.name).field;
|
|
376
|
-
if (!fieldElement["errorMessage"]) {
|
|
377
|
-
this.updateErrorMessage(field.name, fieldElement);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
clearInvalid() {
|
|
382
|
-
this._invalidFields.clear();
|
|
383
|
-
this._fields.forEach(fieldBinder => {
|
|
384
|
-
const fieldElement = fieldBinder.field;
|
|
385
|
-
fieldElement["errorMessage"] = "";
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
updateValue(fieldName, field) {
|
|
389
|
-
const bind = this._fields.get(fieldName);
|
|
390
|
-
try {
|
|
391
|
-
if (bind) {
|
|
392
|
-
bind.listen = false;
|
|
393
|
-
}
|
|
394
|
-
field["value"] = this._dataUnit.getFieldValue(fieldName);
|
|
395
|
-
this.updateErrorMessage(fieldName, field);
|
|
396
|
-
}
|
|
397
|
-
finally {
|
|
398
|
-
if (bind) {
|
|
399
|
-
bind.listen = true;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
updateErrorMessage(fieldName, field) {
|
|
404
|
-
const invalidField = this._invalidFields.get(fieldName);
|
|
405
|
-
if (invalidField) {
|
|
406
|
-
field["errorMessage"] = invalidField.message;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
getErrorMessage(fieldName) {
|
|
410
|
-
if (this._fields.has(fieldName)) {
|
|
411
|
-
const fieldElement = this._fields.get(fieldName).field;
|
|
412
|
-
return fieldElement["errorMessage"] || null;
|
|
413
|
-
}
|
|
414
|
-
return undefined;
|
|
415
|
-
}
|
|
416
|
-
updateBind(fieldName, field) {
|
|
417
|
-
const oldBind = this._fields.get(fieldName);
|
|
418
|
-
if (oldBind) {
|
|
419
|
-
oldBind.destroy();
|
|
420
|
-
}
|
|
421
|
-
field["value"] = this._dataUnit.getFieldValue(fieldName);
|
|
422
|
-
this.updateErrorMessage(fieldName, field);
|
|
423
|
-
this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, waitingChange) => this.changeStarted(fieldName, waitingChange), (fieldName) => this.cancelWaitingChange(fieldName), (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
|
|
424
|
-
this.bindSearchOptionsLoader(fieldName, field);
|
|
425
|
-
this.applyEzUploadContext(fieldName, field);
|
|
426
|
-
}
|
|
427
|
-
changeStarted(fieldName, waitingChange) {
|
|
428
|
-
/**
|
|
429
|
-
* se o waitingChange não é blocante, add um event listener pra
|
|
430
|
-
* fazer o accept da promise
|
|
431
|
-
*
|
|
432
|
-
* se não tiver promise no waitingChange, eu crio uma e resolvo no bind
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*/
|
|
436
|
-
if (this._dataUnit.records.length === 0) {
|
|
437
|
-
this._dataUnit.addRecord();
|
|
438
|
-
}
|
|
439
|
-
if (!waitingChange.blocking && waitingChange.promise == undefined) {
|
|
440
|
-
const bind = this._fields.get(fieldName);
|
|
441
|
-
if (bind) {
|
|
442
|
-
waitingChange.promise = new Promise((resolve, reject) => {
|
|
443
|
-
bind.waitingChangePromiseResolve = resolve;
|
|
444
|
-
bind.waitingChangePromiseReject = reject;
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
this._dataUnit.startChange(fieldName, waitingChange);
|
|
449
|
-
}
|
|
450
|
-
cancelWaitingChange(fieldName) {
|
|
451
|
-
if (this._dataUnit.waitingForChange(fieldName)) {
|
|
452
|
-
this._dataUnit.cancelWaitingChange(fieldName);
|
|
453
|
-
const bind = this._fields.get(fieldName);
|
|
454
|
-
if (bind) {
|
|
455
|
-
bind.rejectWaitingChange(new core.WaitingChangeException("Change canceled", fieldName));
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
setFieldValue(fieldName, newValue) {
|
|
460
|
-
if (this._dataUnit.records.length === 0) {
|
|
461
|
-
this._dataUnit.addRecord();
|
|
462
|
-
}
|
|
463
|
-
this._invalidFields.delete(fieldName);
|
|
464
|
-
this._dataUnit.setFieldValue(fieldName, newValue);
|
|
465
|
-
if (this._dataUnit.waitingForChange(fieldName)) {
|
|
466
|
-
const bind = this._fields.get(fieldName);
|
|
467
|
-
if (bind) {
|
|
468
|
-
bind.acceptWaitingChange();
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
bindSearchOptionsLoader(fieldName, field) {
|
|
473
|
-
if (field.nodeName === "EZ-SEARCH" && field["optionLoader"] == undefined) {
|
|
474
|
-
const loader = core.ApplicationContext.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");
|
|
475
|
-
if (loader) {
|
|
476
|
-
field["optionLoader"] = (arg) => {
|
|
477
|
-
return loader(arg, fieldName, this._dataUnit);
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
applyEzUploadContext(fieldName, field) {
|
|
483
|
-
var _a, _b;
|
|
484
|
-
if (field.nodeName === "EZ-UPLOAD") {
|
|
485
|
-
field["urlUpload"] = core.ApplicationContext.getContextValue("__EZUI__UPLOAD__ADD__URL__");
|
|
486
|
-
field["urlDelete"] = core.ApplicationContext.getContextValue("__EZUI__UPLOAD__DEL__URL__");
|
|
487
|
-
const descriptor = this._dataUnit.getField(fieldName);
|
|
488
|
-
const destination = (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.DESTINATION;
|
|
489
|
-
if (destination) {
|
|
490
|
-
field["requestHeaders"] = { XTRAINF: `{"destination": "${destination}"}` };
|
|
491
|
-
}
|
|
492
|
-
field["maxFiles"] = ((_b = descriptor.properties) === null || _b === void 0 ? void 0 : _b.MAX_FILES) || 0;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
class Bind {
|
|
497
|
-
constructor() {
|
|
498
|
-
this.listen = true;
|
|
499
|
-
this.startChangeEventName = "ezStartChange";
|
|
500
|
-
this.cancelWaitingChangeEventName = "ezCancelWaitingChange";
|
|
501
|
-
this.changeEventName = "ezChange";
|
|
502
|
-
}
|
|
503
|
-
destroy() {
|
|
504
|
-
this.field.removeEventListener(this.startChangeEventName, this.startChangeListener);
|
|
505
|
-
this.field.removeEventListener(this.cancelWaitingChangeEventName, this.cancelWaitingChangeListener);
|
|
506
|
-
this.field.removeEventListener(this.changeEventName, this.changeListener);
|
|
507
|
-
}
|
|
508
|
-
acceptWaitingChange() {
|
|
509
|
-
if (this.waitingChangePromiseResolve) {
|
|
510
|
-
this.waitingChangePromiseResolve();
|
|
511
|
-
this.waitingChangePromiseReject = undefined;
|
|
512
|
-
this.waitingChangePromiseResolve = undefined;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
rejectWaitingChange(reason) {
|
|
516
|
-
if (this.waitingChangePromiseReject) {
|
|
517
|
-
this.waitingChangePromiseReject(reason);
|
|
518
|
-
this.waitingChangePromiseReject = undefined;
|
|
519
|
-
this.waitingChangePromiseResolve = undefined;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
static create(fieldName, field, startChangeCallback, cancelWaitingChangeCallback, changeCallback) {
|
|
523
|
-
const b = new Bind();
|
|
524
|
-
b.field = field;
|
|
525
|
-
b.fieldName = fieldName;
|
|
526
|
-
b.startChangeListener = (evt) => { if (b.listen)
|
|
527
|
-
startChangeCallback(fieldName, evt.detail); };
|
|
528
|
-
b.field.addEventListener(b.startChangeEventName, b.startChangeListener);
|
|
529
|
-
b.cancelWaitingChangeListener = () => { if (b.listen)
|
|
530
|
-
cancelWaitingChangeCallback(fieldName); };
|
|
531
|
-
b.field.addEventListener(b.cancelWaitingChangeEventName, b.cancelWaitingChangeListener);
|
|
532
|
-
b.changeListener = (evt) => { if (b.listen)
|
|
533
|
-
changeCallback(fieldName, evt.detail); };
|
|
534
|
-
b.field.addEventListener(b.changeEventName, b.changeListener);
|
|
535
|
-
return b;
|
|
536
|
-
}
|
|
789
|
+
|
|
790
|
+
var outerSubscribe = subscribe;
|
|
791
|
+
return _ref = {
|
|
792
|
+
/**
|
|
793
|
+
* The minimal observable subscription method.
|
|
794
|
+
* @param {Object} observer Any object that can be used as an observer.
|
|
795
|
+
* The observer object should have a `next` method.
|
|
796
|
+
* @returns {subscription} An object with an `unsubscribe` method that can
|
|
797
|
+
* be used to unsubscribe the observable from the store, and prevent further
|
|
798
|
+
* emission of values from the observable.
|
|
799
|
+
*/
|
|
800
|
+
subscribe: function subscribe(observer) {
|
|
801
|
+
if (typeof observer !== 'object' || observer === null) {
|
|
802
|
+
throw new Error(formatProdErrorMessage(11) );
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
function observeState() {
|
|
806
|
+
if (observer.next) {
|
|
807
|
+
observer.next(getState());
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
observeState();
|
|
812
|
+
var unsubscribe = outerSubscribe(observeState);
|
|
813
|
+
return {
|
|
814
|
+
unsubscribe: unsubscribe
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
}, _ref[$$observable] = function () {
|
|
818
|
+
return this;
|
|
819
|
+
}, _ref;
|
|
820
|
+
} // When a store is created, an "INIT" action is dispatched so that every
|
|
821
|
+
// reducer returns their initial state. This effectively populates
|
|
822
|
+
// the initial state tree.
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
dispatch({
|
|
826
|
+
type: ActionTypes.INIT
|
|
827
|
+
});
|
|
828
|
+
return _ref2 = {
|
|
829
|
+
dispatch: dispatch,
|
|
830
|
+
subscribe: subscribe,
|
|
831
|
+
getState: getState,
|
|
832
|
+
replaceReducer: replaceReducer
|
|
833
|
+
}, _ref2[$$observable] = observable, _ref2;
|
|
537
834
|
}
|
|
538
835
|
|
|
539
836
|
const inicialState = {};
|
|
@@ -579,144 +876,7 @@ var FormActions;
|
|
|
579
876
|
FormActions["CHANGE_TAB"] = "FORM/CHANGE_TAB";
|
|
580
877
|
})(FormActions || (FormActions = {}));
|
|
581
878
|
|
|
582
|
-
|
|
583
|
-
constructor() {
|
|
584
|
-
this._sheets = new Map();
|
|
585
|
-
this._requiredFields = [];
|
|
586
|
-
this._cleanOnCopyFields = [];
|
|
587
|
-
this._defaultValues = {};
|
|
588
|
-
}
|
|
589
|
-
getSheet(name) {
|
|
590
|
-
return this._sheets.get(name);
|
|
591
|
-
}
|
|
592
|
-
getAllSheets() {
|
|
593
|
-
return this._sheets;
|
|
594
|
-
}
|
|
595
|
-
addSheet(sheet) {
|
|
596
|
-
this._sheets.set(sheet.name, sheet);
|
|
597
|
-
this._requiredFields = this._requiredFields.concat(sheet.requiredFields);
|
|
598
|
-
this._cleanOnCopyFields = this._cleanOnCopyFields.concat(sheet.cleanOnCopyFields);
|
|
599
|
-
this._defaultValues = sheet.defaultValues;
|
|
600
|
-
}
|
|
601
|
-
getRequiredFields() {
|
|
602
|
-
return this._requiredFields;
|
|
603
|
-
}
|
|
604
|
-
getCleanOnCopyFields() {
|
|
605
|
-
return this._cleanOnCopyFields;
|
|
606
|
-
}
|
|
607
|
-
getDefaultValues() {
|
|
608
|
-
return this._defaultValues;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
const buildFromDataUnit = (dataUnit) => {
|
|
612
|
-
const unitMD = dataUnit.metadata;
|
|
613
|
-
const metadata = new FormMetadata();
|
|
614
|
-
if (unitMD) {
|
|
615
|
-
const visibleFields = (unitMD.fields || []).filter(descriptor => descriptor.visible !== false);
|
|
616
|
-
const fields = visibleFields.map(descriptor => buildFormField(descriptor));
|
|
617
|
-
let defaultValues = {};
|
|
618
|
-
visibleFields
|
|
619
|
-
.filter(descriptor => descriptor.defaultValue)
|
|
620
|
-
.forEach((descriptor) => defaultValues[descriptor.name] = descriptor.defaultValue);
|
|
621
|
-
metadata.addSheet({
|
|
622
|
-
name: unitMD.name,
|
|
623
|
-
label: unitMD.label,
|
|
624
|
-
fields,
|
|
625
|
-
requiredFields: visibleFields
|
|
626
|
-
.filter(descriptor => descriptor.required)
|
|
627
|
-
.map(descriptor => descriptor.name),
|
|
628
|
-
cleanOnCopyFields: visibleFields
|
|
629
|
-
.filter(descriptor => { var _a, _b; return ((_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy) || ((_b = descriptor.properties) === null || _b === void 0 ? void 0 : _b.autoNum); })
|
|
630
|
-
.map(descriptor => descriptor.name),
|
|
631
|
-
defaultValues
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
return metadata;
|
|
635
|
-
};
|
|
636
|
-
const buildFromConfig = (config, dataUnit) => {
|
|
637
|
-
var _a, _b;
|
|
638
|
-
const sheets = new Map();
|
|
639
|
-
const hiddenTabs = new Map();
|
|
640
|
-
const requiredFields = [];
|
|
641
|
-
const cleanOnCopyFields = [];
|
|
642
|
-
const defaultValues = {};
|
|
643
|
-
(_a = config === null || config === void 0 ? void 0 : config.tabs) === null || _a === void 0 ? void 0 : _a.forEach((tab) => {
|
|
644
|
-
if (!hiddenTabs.has(tab.label) && tab.visible === false) {
|
|
645
|
-
hiddenTabs.set(tab.label, tab);
|
|
646
|
-
}
|
|
647
|
-
});
|
|
648
|
-
(_b = config === null || config === void 0 ? void 0 : config.fields) === null || _b === void 0 ? void 0 : _b.forEach((field) => {
|
|
649
|
-
var _a, _b, _c, _d;
|
|
650
|
-
if (field.visible !== false) {
|
|
651
|
-
const tabConfig = getTabConfig(field.tab || "__main", sheets);
|
|
652
|
-
if (hiddenTabs.has(tabConfig.label)) {
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
const descriptor = dataUnit.getField(field.name);
|
|
656
|
-
if (descriptor && tabConfig.visible) {
|
|
657
|
-
if (!sheets.has(tabConfig)) {
|
|
658
|
-
sheets.set(tabConfig, []);
|
|
659
|
-
}
|
|
660
|
-
const formField = buildFormField(descriptor, field);
|
|
661
|
-
sheets.get(tabConfig).push(formField);
|
|
662
|
-
if (formField.required) {
|
|
663
|
-
requiredFields.push(field.name);
|
|
664
|
-
}
|
|
665
|
-
const cleanOnCopy = field.cleanOnCopy == undefined ? (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy : field.cleanOnCopy;
|
|
666
|
-
if (cleanOnCopy || ((_b = descriptor.properties) === null || _b === void 0 ? void 0 : _b.autoNum) || ((_c = descriptor.properties) === null || _c === void 0 ? void 0 : _c.cleanOnCopy)) {
|
|
667
|
-
cleanOnCopyFields.push(field.name);
|
|
668
|
-
}
|
|
669
|
-
const defaultValue = field.defaultValue == undefined ? (_d = descriptor.properties) === null || _d === void 0 ? void 0 : _d.defaultValue : field.defaultValue;
|
|
670
|
-
if (defaultValue) {
|
|
671
|
-
defaultValues[field.name] = field.defaultValue;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
});
|
|
676
|
-
const metadata = new FormMetadata();
|
|
677
|
-
Array.from(sheets.entries())
|
|
678
|
-
.sort(sortTabs)
|
|
679
|
-
.forEach(([key, fields]) => {
|
|
680
|
-
metadata.addSheet({
|
|
681
|
-
label: (key.label === "__main") ? "Principal" : key.label,
|
|
682
|
-
name: key.label,
|
|
683
|
-
fields,
|
|
684
|
-
requiredFields,
|
|
685
|
-
cleanOnCopyFields,
|
|
686
|
-
defaultValues
|
|
687
|
-
});
|
|
688
|
-
});
|
|
689
|
-
return metadata;
|
|
690
|
-
};
|
|
691
|
-
const buildFormField = (descriptor, config) => {
|
|
692
|
-
let { name, label, group } = Object.assign({}, config);
|
|
693
|
-
let { readOnly, required } = Object.assign({}, config);
|
|
694
|
-
let props;
|
|
695
|
-
let userInterface;
|
|
696
|
-
if (descriptor) {
|
|
697
|
-
label = label || descriptor.label;
|
|
698
|
-
name = name || descriptor.name;
|
|
699
|
-
required = descriptor.required || (config === null || config === void 0 ? void 0 : config.required);
|
|
700
|
-
readOnly = descriptor.readOnly || (config === null || config === void 0 ? void 0 : config.readOnly);
|
|
701
|
-
props = descriptor.properties;
|
|
702
|
-
userInterface = descriptor.userInterface;
|
|
703
|
-
}
|
|
704
|
-
return {
|
|
705
|
-
name, label, group,
|
|
706
|
-
readOnly, required,
|
|
707
|
-
props,
|
|
708
|
-
userInterface: userInterface || core.UserInterface.SHORTTEXT
|
|
709
|
-
};
|
|
710
|
-
};
|
|
711
|
-
const getTabConfig = (tab, sheets) => {
|
|
712
|
-
const tabConfig = (typeof tab === "string" ? Array.from(sheets.keys()).find(t => t.label === tab) : tab);
|
|
713
|
-
return tabConfig || { label: tab, visible: true };
|
|
714
|
-
};
|
|
715
|
-
const sortTabs = (a, b) => {
|
|
716
|
-
return a[0].label == '__main' ? -1 : (a[0].order || 10000) - (b[0].order || 10000);
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
const ezFormCss = ".sc-ez-form-h{display:flex;flex-direction:column;width:100%}.dynamic-content.sc-ez-form ez-collapsible-box.sc-ez-form{--ez-collapsible-box__header--padding-right:var(--space-small, 6px);--ez-collapsible-box__header--padding-left:var(--space-small, 6px)}.multi-level__container.sc-ez-form{display:grid;grid-template-columns:minmax(20%, 300px) auto;width:100%}";
|
|
879
|
+
const ezFormCss = ".sc-ez-form-h{display:flex;flex-direction:column;width:100%}.dynamic-content.sc-ez-form ez-collapsible-box.sc-ez-form{--ez-collapsible-box__header--padding-right:var(--space-small, 6px);--ez-collapsible-box__header--padding-left:var(--space-small, 6px)}";
|
|
720
880
|
|
|
721
881
|
const EzForm = class {
|
|
722
882
|
constructor(hostRef) {
|
|
@@ -730,114 +890,24 @@ const EzForm = class {
|
|
|
730
890
|
this.dataUnit = undefined;
|
|
731
891
|
this.config = undefined;
|
|
732
892
|
this.recordsValidator = undefined;
|
|
733
|
-
this.multiLevel = undefined;
|
|
734
|
-
this.levelResolver = undefined;
|
|
735
|
-
this.contentBuilder = undefined;
|
|
736
893
|
}
|
|
737
894
|
/**
|
|
738
895
|
* Realiza validação no conteúdo de todos os campos.
|
|
739
896
|
*/
|
|
740
897
|
validate() {
|
|
741
|
-
return
|
|
742
|
-
var _a;
|
|
743
|
-
const records = this.dataUnit.getModifiedRecords();
|
|
744
|
-
for (let i = 0; i < records.length; i++) {
|
|
745
|
-
const record = records[i];
|
|
746
|
-
const invalidResults = [];
|
|
747
|
-
let validationResult = this.validateRequired(record);
|
|
748
|
-
if (validationResult && !validationResult.isValid) {
|
|
749
|
-
invalidResults.push(validationResult);
|
|
750
|
-
}
|
|
751
|
-
validationResult = (_a = this.recordsValidator) === null || _a === void 0 ? void 0 : _a.validateRecord(this, record);
|
|
752
|
-
if (validationResult && !validationResult.isValid) {
|
|
753
|
-
invalidResults.push(validationResult);
|
|
754
|
-
}
|
|
755
|
-
if (invalidResults.length > 0) {
|
|
756
|
-
this.processValidationResult(invalidResults);
|
|
757
|
-
reject();
|
|
758
|
-
break;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
accept();
|
|
762
|
-
});
|
|
898
|
+
return this._dataBinder.validate();
|
|
763
899
|
}
|
|
764
900
|
observeConfig() {
|
|
765
901
|
this.processMetadata();
|
|
766
902
|
}
|
|
767
|
-
validateRequired(record) {
|
|
768
|
-
const metadata = selectFormMetadata(this._store.getState());
|
|
769
|
-
const requiredFields = this._staticFields
|
|
770
|
-
.filter(f => f.dataset.required)
|
|
771
|
-
.map(f => f.dataset.fieldName)
|
|
772
|
-
.concat(metadata.getRequiredFields());
|
|
773
|
-
const invalidFields = [];
|
|
774
|
-
new Set(requiredFields).forEach(field => {
|
|
775
|
-
const value = record[field];
|
|
776
|
-
if (value == undefined || value === "") {
|
|
777
|
-
const errorMessage = this._dataBinder.getErrorMessage(field);
|
|
778
|
-
if (errorMessage) {
|
|
779
|
-
invalidFields.push({ name: field, message: errorMessage });
|
|
780
|
-
}
|
|
781
|
-
else {
|
|
782
|
-
invalidFields.push({ name: field, message: "Essa informação é obrigatória" });
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
if (invalidFields.length > 0) {
|
|
787
|
-
return { isValid: false, invalidFields, infoMessage: "Há pelo menos um campo obrigatório não preenchido." };
|
|
788
|
-
}
|
|
789
|
-
return undefined;
|
|
790
|
-
}
|
|
791
|
-
processValidationResult(validationResult) {
|
|
792
|
-
validationResult.forEach(invalidResult => {
|
|
793
|
-
const invalidFields = invalidResult.invalidFields;
|
|
794
|
-
if (invalidFields) {
|
|
795
|
-
invalidFields.forEach(field => {
|
|
796
|
-
this._dataBinder.markInvalid(field);
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
if (invalidResult.infoMessage) {
|
|
800
|
-
ApplicationUtils.ApplicationUtils.info(invalidResult.infoMessage);
|
|
801
|
-
}
|
|
802
|
-
if (invalidResult.errorMessage) {
|
|
803
|
-
const { errorTitle, errorMessage } = invalidResult;
|
|
804
|
-
ApplicationUtils.ApplicationUtils.error(errorTitle, errorMessage);
|
|
805
|
-
}
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
resolveLevel(items) {
|
|
809
|
-
if (!this.levelResolver) {
|
|
810
|
-
return items;
|
|
811
|
-
}
|
|
812
|
-
return this.levelResolver(items);
|
|
813
|
-
}
|
|
814
|
-
getMultiLevelContent(sheets, currentSheet, currentSheetId) {
|
|
815
|
-
const treeItems = this.resolveLevel(sheets.map(sheet => {
|
|
816
|
-
const item = {
|
|
817
|
-
id: sheet.name,
|
|
818
|
-
label: sheet.label
|
|
819
|
-
};
|
|
820
|
-
return item;
|
|
821
|
-
}));
|
|
822
|
-
return (index.h("div", { class: "multi-level__container" }, index.h("div", null, index.h("ez-tree", { selectedId: currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.name, items: treeItems, onEzChange: (evt) => {
|
|
823
|
-
var _a;
|
|
824
|
-
const selectedItem = (_a = evt.detail) === null || _a === void 0 ? void 0 : _a.id;
|
|
825
|
-
if (selectedItem && selectedItem !== (currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.name)) {
|
|
826
|
-
this._store.dispatch(changeTab(selectedItem));
|
|
827
|
-
}
|
|
828
|
-
} })), index.h("div", null, this.buildFormContent(currentSheetId, currentSheet))));
|
|
829
|
-
}
|
|
830
903
|
getDynamicContent() {
|
|
831
|
-
var _a
|
|
904
|
+
var _a;
|
|
832
905
|
const formMD = selectFormMetadata(this._store.getState());
|
|
833
|
-
if (!formMD)
|
|
906
|
+
if (!formMD) {
|
|
834
907
|
return null;
|
|
835
|
-
const allSheets = Array.from(formMD.getAllSheets().values());
|
|
836
|
-
const currentSheetId = selectCurrentSheetId((_a = this._store) === null || _a === void 0 ? void 0 : _a.getState());
|
|
837
|
-
const currentSheet = selectCurrentSheet((_b = this._store) === null || _b === void 0 ? void 0 : _b.getState());
|
|
838
|
-
if (this.multiLevel) {
|
|
839
|
-
return this.getMultiLevelContent(allSheets, currentSheet, currentSheetId);
|
|
840
908
|
}
|
|
909
|
+
const allSheets = Array.from(formMD.getAllSheets().values());
|
|
910
|
+
const currentSheet = selectCurrentSheet((_a = this._store) === null || _a === void 0 ? void 0 : _a.getState());
|
|
841
911
|
let result = [];
|
|
842
912
|
if (allSheets.length > 1) {
|
|
843
913
|
const tabs = allSheets.map((sheet, index) => {
|
|
@@ -846,26 +916,20 @@ const EzForm = class {
|
|
|
846
916
|
const idTabSelector = `selector`;
|
|
847
917
|
result.push(index.h("ez-tabselector", { tabs: this.buildIdTabSelector(tabs), onEzChange: (evt) => this._store.dispatch(changeTab(evt.detail)), selectedTab: currentSheet.name, "data-element-id": idTabSelector }));
|
|
848
918
|
}
|
|
849
|
-
result = result.concat(this.buildFormContent(
|
|
919
|
+
result = result.concat(this.buildFormContent(currentSheet));
|
|
850
920
|
return result;
|
|
851
921
|
}
|
|
852
|
-
buildFormContent(
|
|
922
|
+
buildFormContent(currentSheet) {
|
|
853
923
|
const fields = currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.fields;
|
|
854
|
-
if (this.contentBuilder != undefined) {
|
|
855
|
-
const customContent = this.contentBuilder(sheetId, fields);
|
|
856
|
-
if (customContent != undefined) {
|
|
857
|
-
return index.h("div", { "innerHTML": customContent });
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
924
|
if (currentSheet == undefined) {
|
|
861
925
|
return;
|
|
862
926
|
}
|
|
863
927
|
const idFormSheet = `${core.StringUtils.replaceAccentuatedChars(core.StringUtils.toCamelCase(currentSheet === null || currentSheet === void 0 ? void 0 : currentSheet.label), false)}_selectorContainer`;
|
|
864
|
-
return (index.h("div", { class: "dynamic-content
|
|
928
|
+
return (index.h("div", { class: "dynamic-content", "data-element-id": idFormSheet }, index.h("ez-form-view", { class: "ez-row ez-padding-vertical--small", fields: fields })));
|
|
865
929
|
}
|
|
866
930
|
processMetadata() {
|
|
867
931
|
if (!this.isStatic() && this.dataUnit && this._store) {
|
|
868
|
-
const metadata =
|
|
932
|
+
const metadata = buildFormMetadata(this.config, this.dataUnit);
|
|
869
933
|
this._store.dispatch(loadMetadata(metadata));
|
|
870
934
|
}
|
|
871
935
|
}
|
|
@@ -873,58 +937,10 @@ const EzForm = class {
|
|
|
873
937
|
var _a;
|
|
874
938
|
return ((_a = this._staticFields) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
875
939
|
}
|
|
876
|
-
getFormattedValue(defaultValue) {
|
|
877
|
-
if (defaultValue == undefined || typeof defaultValue !== "object") {
|
|
878
|
-
return defaultValue;
|
|
879
|
-
}
|
|
880
|
-
if ("formattedValue" in defaultValue) {
|
|
881
|
-
return defaultValue.formattedValue;
|
|
882
|
-
}
|
|
883
|
-
return defaultValue.value;
|
|
884
|
-
}
|
|
885
|
-
interceptAction(action) {
|
|
886
|
-
if (action.type === core.Action.RECORDS_COPIED) {
|
|
887
|
-
const metadata = selectFormMetadata(this._store.getState());
|
|
888
|
-
const cleanFields = metadata.getCleanOnCopyFields();
|
|
889
|
-
if (cleanFields) {
|
|
890
|
-
const records = action.payload;
|
|
891
|
-
return new core.DataUnitAction(core.Action.RECORDS_COPIED, records.map(record => {
|
|
892
|
-
const newRecord = Object.assign({}, record);
|
|
893
|
-
cleanFields.forEach(fieldName => delete newRecord[fieldName]);
|
|
894
|
-
return newRecord;
|
|
895
|
-
}));
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
if (action.type === core.Action.SAVING_DATA) {
|
|
899
|
-
return new Promise((resolve) => {
|
|
900
|
-
this.validate()
|
|
901
|
-
.then(() => resolve(action))
|
|
902
|
-
.catch(() => { });
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
if (action.type === core.Action.RECORDS_ADDED) {
|
|
906
|
-
const metadata = selectFormMetadata(this._store.getState());
|
|
907
|
-
const defaultValues = metadata === null || metadata === void 0 ? void 0 : metadata.getDefaultValues();
|
|
908
|
-
if (defaultValues) {
|
|
909
|
-
const records = action.payload;
|
|
910
|
-
return new core.DataUnitAction(core.Action.RECORDS_ADDED, records.map(record => {
|
|
911
|
-
const newRecord = Object.assign({}, record);
|
|
912
|
-
for (const field in defaultValues) {
|
|
913
|
-
const defaultValue = this.getFormattedValue(defaultValues[field]);
|
|
914
|
-
const recordValue = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
915
|
-
newRecord[field] = this.dataUnit.valueFromString(field, recordValue);
|
|
916
|
-
}
|
|
917
|
-
return newRecord;
|
|
918
|
-
}));
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
return action;
|
|
922
|
-
}
|
|
923
940
|
componentWillLoad() {
|
|
924
941
|
if (this.dataUnit === undefined) {
|
|
925
942
|
this.dataUnit = new core.DataUnit("ez-form");
|
|
926
943
|
}
|
|
927
|
-
this.dataUnit.addInterceptor(this);
|
|
928
944
|
this.dataUnit.subscribe(this.onDataUnitAction);
|
|
929
945
|
this._dataBinder = new DataBinder(this.dataUnit);
|
|
930
946
|
this._store = createStore(formReducer);
|
|
@@ -935,12 +951,13 @@ const EzForm = class {
|
|
|
935
951
|
core.ElementIDUtils.addIDInfo(this._element, null, dataInfo);
|
|
936
952
|
}
|
|
937
953
|
componentDidRender() {
|
|
938
|
-
|
|
954
|
+
const metadata = selectFormMetadata(this._store.getState());
|
|
955
|
+
metadata.addRequiredFields(this._staticFields.filter(f => f.dataset.required).map(f => f.dataset.fieldName));
|
|
956
|
+
this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")), this.dataUnit.dataUnitId, metadata, this.recordsValidator);
|
|
939
957
|
this.ezReady.emit();
|
|
940
958
|
}
|
|
941
959
|
disconnectedCallback() {
|
|
942
960
|
this.dataUnit.unsubscribe(this.onDataUnitAction);
|
|
943
|
-
this.dataUnit.removeInterceptor(this);
|
|
944
961
|
this._dataBinder.onDisconnectedCallback();
|
|
945
962
|
}
|
|
946
963
|
buildIdTabSelector(tabs) {
|