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