tuain-ng-forms-lib 14.4.93 → 14.4.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/esm2020/lib/classes/forms/action.mjs +36 -0
  2. package/esm2020/lib/classes/forms/element.mjs +26 -0
  3. package/esm2020/lib/classes/forms/field.mjs +445 -0
  4. package/esm2020/lib/classes/forms/form.constants.mjs +26 -0
  5. package/esm2020/lib/classes/forms/form.mjs +431 -0
  6. package/esm2020/lib/classes/forms/piece-propagate.mjs +37 -0
  7. package/esm2020/lib/classes/forms/piece.mjs +95 -0
  8. package/esm2020/lib/classes/forms/section.mjs +138 -0
  9. package/esm2020/lib/classes/forms/subsection.mjs +81 -0
  10. package/esm2020/lib/classes/forms/table/action.mjs +18 -0
  11. package/esm2020/lib/classes/forms/table/column.mjs +74 -0
  12. package/esm2020/lib/classes/forms/table/row-data.mjs +116 -0
  13. package/esm2020/lib/classes/forms/table/table.mjs +416 -0
  14. package/esm2020/lib/components/elements/action.component.mjs +71 -0
  15. package/esm2020/lib/components/elements/field.component.mjs +81 -0
  16. package/esm2020/lib/components/elements/layout/element.component.mjs +20 -0
  17. package/esm2020/lib/components/elements/layout/form-error.component.mjs +20 -0
  18. package/esm2020/lib/components/elements/layout/form-header.component.mjs +31 -0
  19. package/esm2020/lib/components/elements/layout/piece.component.mjs +39 -0
  20. package/esm2020/lib/components/elements/layout/section.component.mjs +37 -0
  21. package/esm2020/lib/components/elements/layout/sub-section.component.mjs +37 -0
  22. package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +56 -0
  23. package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +30 -0
  24. package/esm2020/lib/components/elements/tables/table.component.mjs +89 -0
  25. package/esm2020/lib/components/forms/basic-form.mjs +1530 -0
  26. package/esm2020/lib/services/event-manager.service.mjs +18 -0
  27. package/esm2020/lib/services/file-manager.service.mjs +6 -0
  28. package/esm2020/lib/services/form-manager.service.mjs +80 -0
  29. package/esm2020/lib/tuain-ng-forms-lib.module.mjs +71 -0
  30. package/esm2020/public-api.mjs +19 -0
  31. package/esm2020/tuain-ng-forms-lib.mjs +5 -0
  32. package/fesm2015/tuain-ng-forms-lib.mjs +4276 -0
  33. package/fesm2015/tuain-ng-forms-lib.mjs.map +1 -0
  34. package/fesm2020/tuain-ng-forms-lib.mjs +4090 -0
  35. package/fesm2020/tuain-ng-forms-lib.mjs.map +1 -0
  36. package/lib/classes/forms/action.d.ts +22 -0
  37. package/lib/classes/forms/element.d.ts +17 -0
  38. package/lib/classes/forms/field.d.ts +205 -0
  39. package/lib/classes/forms/form.constants.d.ts +25 -0
  40. package/lib/classes/forms/form.d.ts +137 -0
  41. package/lib/classes/forms/piece-propagate.d.ts +13 -0
  42. package/lib/classes/forms/piece.d.ts +41 -0
  43. package/lib/classes/forms/section.d.ts +32 -0
  44. package/lib/classes/forms/subsection.d.ts +24 -0
  45. package/lib/classes/forms/table/action.d.ts +15 -0
  46. package/lib/classes/forms/table/column.d.ts +33 -0
  47. package/lib/classes/forms/table/row-data.d.ts +14 -0
  48. package/lib/classes/forms/table/table.d.ts +100 -0
  49. package/lib/components/elements/action.component.d.ts +17 -0
  50. package/lib/components/elements/field.component.d.ts +38 -0
  51. package/lib/components/elements/layout/element.component.d.ts +9 -0
  52. package/lib/components/elements/layout/form-error.component.d.ts +8 -0
  53. package/lib/components/elements/layout/form-header.component.d.ts +12 -0
  54. package/lib/components/elements/layout/piece.component.d.ts +12 -0
  55. package/lib/components/elements/layout/section.component.d.ts +11 -0
  56. package/lib/components/elements/layout/sub-section.component.d.ts +11 -0
  57. package/lib/components/elements/tables/table-record-action.component.d.ts +16 -0
  58. package/lib/components/elements/tables/table-record-field.component.d.ts +12 -0
  59. package/lib/components/elements/tables/table.component.d.ts +35 -0
  60. package/lib/components/forms/basic-form.d.ts +355 -0
  61. package/lib/services/event-manager.service.d.ts +9 -0
  62. package/lib/services/file-manager.service.d.ts +5 -0
  63. package/lib/services/form-manager.service.d.ts +28 -0
  64. package/lib/tuain-ng-forms-lib.module.d.ts +20 -0
  65. package/package.json +24 -6
  66. package/{src/public-api.ts → public-api.d.ts} +0 -5
  67. package/tuain-ng-forms-lib.d.ts +5 -0
  68. package/.browserslistrc +0 -16
  69. package/.yarn/cache/nanoid-npm-4.0.0-924f5c6312-7d5946df5c.zip +0 -0
  70. package/.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip +0 -0
  71. package/.yarn/cache/yn-npm-5.0.0-b001dab23c-f0ec7710d3.zip +0 -0
  72. package/.yarn/install-state.gz +0 -0
  73. package/karma.conf.js +0 -44
  74. package/ng-package.json +0 -11
  75. package/src/lib/classes/forms/action.ts +0 -56
  76. package/src/lib/classes/forms/element.ts +0 -29
  77. package/src/lib/classes/forms/field.ts +0 -500
  78. package/src/lib/classes/forms/form.constants.ts +0 -28
  79. package/src/lib/classes/forms/form.ts +0 -508
  80. package/src/lib/classes/forms/piece-propagate.ts +0 -46
  81. package/src/lib/classes/forms/piece.ts +0 -122
  82. package/src/lib/classes/forms/section.ts +0 -152
  83. package/src/lib/classes/forms/subsection.ts +0 -90
  84. package/src/lib/classes/forms/table/action.ts +0 -32
  85. package/src/lib/classes/forms/table/column.ts +0 -94
  86. package/src/lib/classes/forms/table/row-data.ts +0 -121
  87. package/src/lib/classes/forms/table/table.ts +0 -478
  88. package/src/lib/components/elements/action.component.ts +0 -59
  89. package/src/lib/components/elements/field.component.ts +0 -92
  90. package/src/lib/components/elements/layout/element.component.ts +0 -13
  91. package/src/lib/components/elements/layout/form-error.component.ts +0 -11
  92. package/src/lib/components/elements/layout/form-header.component.ts +0 -17
  93. package/src/lib/components/elements/layout/piece.component.ts +0 -34
  94. package/src/lib/components/elements/layout/section.component.ts +0 -31
  95. package/src/lib/components/elements/layout/sub-section.component.ts +0 -31
  96. package/src/lib/components/elements/tables/table-record-action.component.ts +0 -50
  97. package/src/lib/components/elements/tables/table-record-field.component.ts +0 -20
  98. package/src/lib/components/elements/tables/table.component.ts +0 -86
  99. package/src/lib/components/forms/basic-form.ts +0 -1588
  100. package/src/lib/services/event-manager.service.ts +0 -21
  101. package/src/lib/services/file-manager.service.ts +0 -6
  102. package/src/lib/services/form-manager.service.ts +0 -89
  103. package/src/lib/services/icon-dictionary.service.ts +0 -159
  104. package/src/lib/tuain-ng-forms-lib.module.ts +0 -40
  105. package/src/test.ts +0 -27
  106. package/tsconfig.lib.json +0 -15
  107. package/tsconfig.lib.prod.json +0 -10
  108. package/tsconfig.spec.json +0 -17
@@ -0,0 +1,4276 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Component, Input, EventEmitter, Output, ChangeDetectionStrategy, NgModule } from '@angular/core';
3
+ import { __awaiter } from 'tslib';
4
+ import { BehaviorSubject, Subject, ReplaySubject } from 'rxjs';
5
+ import yn from 'yn';
6
+ import { nanoid } from 'nanoid';
7
+ import { CommonModule } from '@angular/common';
8
+ import { RouterModule } from '@angular/router';
9
+ import { FormsModule } from '@angular/forms';
10
+
11
+ const CUSTOM_ATTRIBUTES = 'customAttributes';
12
+ class PieceComponent {
13
+ constructor() {
14
+ this.visible = true;
15
+ this.disabled = false;
16
+ this.customAttributes = {};
17
+ }
18
+ defaultProcessAttributeChange(attribute, value) {
19
+ if (!attribute || attribute.trim() === '') {
20
+ return false;
21
+ }
22
+ const attributeParts = attribute.split('.');
23
+ if ((attributeParts === null || attributeParts === void 0 ? void 0 : attributeParts.length) > 1) {
24
+ const [attributeType, subAttribute] = attributeParts;
25
+ if (attributeType === CUSTOM_ATTRIBUTES) {
26
+ this.customAttributes[subAttribute] = value;
27
+ this.customAttributeChange(subAttribute, value);
28
+ }
29
+ }
30
+ else {
31
+ this[attribute] = value;
32
+ }
33
+ return true;
34
+ }
35
+ customProcessAttributeChange(attribute, value) { }
36
+ customAttributeChange(subAttribute, value) { }
37
+ }
38
+ PieceComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: PieceComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
39
+ PieceComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: PieceComponent, selector: "lib-piece", ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
40
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: PieceComponent, decorators: [{
41
+ type: Component,
42
+ args: [{
43
+ selector: 'lib-piece',
44
+ template: `<ng-content></ng-content>`
45
+ }]
46
+ }] });
47
+
48
+ class ElementComponent extends PieceComponent {
49
+ start() { }
50
+ }
51
+ ElementComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: ElementComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
52
+ ElementComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: ElementComponent, selector: "lib-element", inputs: { element: "element", form: "form" }, usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
53
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: ElementComponent, decorators: [{
54
+ type: Component,
55
+ args: [{
56
+ selector: 'lib-element',
57
+ template: `<ng-content></ng-content>`
58
+ }]
59
+ }], propDecorators: { element: [{
60
+ type: Input
61
+ }], form: [{
62
+ type: Input
63
+ }] } });
64
+
65
+ class ActionComponent extends ElementComponent {
66
+ constructor() {
67
+ super(...arguments);
68
+ this.inProgress = false;
69
+ this.action = null;
70
+ this.style = 'primary';
71
+ this.showLabel = true;
72
+ }
73
+ ngOnInit() {
74
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
75
+ if (!this.action) {
76
+ return;
77
+ }
78
+ this.formConfig = (_a = this.action) === null || _a === void 0 ? void 0 : _a._formConfig;
79
+ const mapping = Object.entries((_b = this.formConfig) === null || _b === void 0 ? void 0 : _b.actionPropagateAttributes);
80
+ for (let index = 0; index < mapping.length; index++) {
81
+ const actionAttr = (_c = mapping[index]) === null || _c === void 0 ? void 0 : _c[0];
82
+ const componentAttr = (_f = (_e = (_d = mapping[index]) === null || _d === void 0 ? void 0 : _d[1]) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : '';
83
+ if (componentAttr) {
84
+ const value = (_g = this.action) === null || _g === void 0 ? void 0 : _g[actionAttr];
85
+ this.defaultProcessAttributeChange(componentAttr, value);
86
+ this.customProcessAttributeChange(componentAttr, value);
87
+ }
88
+ }
89
+ (_j = (_h = this.action) === null || _h === void 0 ? void 0 : _h.attributeChange) === null || _j === void 0 ? void 0 : _j.subscribe(event => {
90
+ const { name: componentAttr, value } = event;
91
+ this.defaultProcessAttributeChange(componentAttr, value);
92
+ this.customProcessAttributeChange(componentAttr, value);
93
+ });
94
+ this.start();
95
+ }
96
+ activate() {
97
+ var _a;
98
+ if ((_a = this.action) === null || _a === void 0 ? void 0 : _a.notifyActivation) {
99
+ this.action.notifyActivation();
100
+ }
101
+ }
102
+ visibleOnRestriction() {
103
+ var _a, _b, _c, _d, _e;
104
+ if (!((_a = this.action) === null || _a === void 0 ? void 0 : _a.restrictedOnField)) {
105
+ return true;
106
+ }
107
+ if ((((_b = this.action) === null || _b === void 0 ? void 0 : _b.restrictedOnOperator) === '=='
108
+ && this.relatedField === ((_c = this.action) === null || _c === void 0 ? void 0 : _c.restrictedOnValue))
109
+ || (((_d = this.action) === null || _d === void 0 ? void 0 : _d.restrictedOnOperator) === '!='
110
+ && this.relatedField !== ((_e = this.action) === null || _e === void 0 ? void 0 : _e.restrictedOnValue))) {
111
+ return true;
112
+ }
113
+ return false;
114
+ }
115
+ }
116
+ ActionComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: ActionComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
117
+ ActionComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: ActionComponent, selector: "lib-action", inputs: { action: "action", busy: "busy", relatedField: "relatedField", style: "style", showLabel: "showLabel" }, usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
118
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: ActionComponent, decorators: [{
119
+ type: Component,
120
+ args: [{
121
+ selector: 'lib-action',
122
+ template: `<ng-content></ng-content>`
123
+ }]
124
+ }], propDecorators: { action: [{
125
+ type: Input
126
+ }], busy: [{
127
+ type: Input
128
+ }], relatedField: [{
129
+ type: Input
130
+ }], style: [{
131
+ type: Input
132
+ }], showLabel: [{
133
+ type: Input
134
+ }] } });
135
+
136
+ const VALUE = 'value';
137
+ const FOCUS = 'focus';
138
+ class FieldComponent extends ElementComponent {
139
+ constructor() {
140
+ super(...arguments);
141
+ // Atributos obtenidos estáticamente
142
+ this.code = '';
143
+ this.info = '';
144
+ this.alignment = '';
145
+ this.tooltip = '';
146
+ this.field = null;
147
+ }
148
+ ngOnInit() {
149
+ var _a, _b, _c, _d, _e, _f, _g, _h;
150
+ if (!this.field) {
151
+ return;
152
+ }
153
+ this.formConfig = (_a = this.field) === null || _a === void 0 ? void 0 : _a._formConfig;
154
+ const mapping = Object.entries((_b = this.formConfig) === null || _b === void 0 ? void 0 : _b.fieldPropagateAttributes);
155
+ for (let index = 0; index < mapping.length; index++) {
156
+ const fieldAttr = (_c = mapping[index]) === null || _c === void 0 ? void 0 : _c[0];
157
+ const componentAttr = (_f = (_e = (_d = mapping[index]) === null || _d === void 0 ? void 0 : _d[1]) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : '';
158
+ if (componentAttr) {
159
+ const value = (_g = this.field) === null || _g === void 0 ? void 0 : _g[fieldAttr];
160
+ this.defaultProcessAttributeChange(componentAttr, value);
161
+ this.customProcessAttributeChange(componentAttr, value);
162
+ }
163
+ }
164
+ // Subscripción a cambios en atributos
165
+ (_h = this.field) === null || _h === void 0 ? void 0 : _h.attributeChange.subscribe(event => {
166
+ const { name: componentAttr, value } = event;
167
+ this.defaultProcessAttributeChange(componentAttr, value);
168
+ this.customProcessAttributeChange(componentAttr, value);
169
+ });
170
+ this.start();
171
+ }
172
+ defaultProcessAttributeChange(attribute, value) {
173
+ if (attribute === VALUE) {
174
+ this.updateValue();
175
+ }
176
+ else if (attribute === FOCUS) {
177
+ this.focus();
178
+ }
179
+ else {
180
+ return super.defaultProcessAttributeChange(attribute, value);
181
+ }
182
+ return true;
183
+ }
184
+ updateValue() { var _a; this.value = (_a = this.field) === null || _a === void 0 ? void 0 : _a.value; }
185
+ onInputChange() { setTimeout(() => { var _a; return (_a = this.field) === null || _a === void 0 ? void 0 : _a.notifyEditionPartial(); }, 50); }
186
+ onChangeContent() { setTimeout(() => { var _a; return (_a = this.field) === null || _a === void 0 ? void 0 : _a.notifyEditionFinish(); }, 50); }
187
+ onShowInfo(detail = null) { setTimeout(() => { var _a; return (_a = this.field) === null || _a === void 0 ? void 0 : _a.notifyEditionDetailRequest(detail); }, 50); }
188
+ focus() { }
189
+ updateObject(widgetUpdate = true) { var _a; (_a = this.field) === null || _a === void 0 ? void 0 : _a.setValue(this.value, widgetUpdate); }
190
+ inputChanged() {
191
+ var _a;
192
+ (_a = this.field) === null || _a === void 0 ? void 0 : _a.setValue(this.value);
193
+ this.onChangeContent();
194
+ }
195
+ inputTyped() {
196
+ this.updateObject(false);
197
+ this.onInputChange();
198
+ }
199
+ numberInputValidation(event) {
200
+ const k = event.charCode;
201
+ return (k > 47 && k < 58);
202
+ }
203
+ }
204
+ FieldComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: FieldComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
205
+ FieldComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: FieldComponent, selector: "lib-field", inputs: { field: "field" }, usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
206
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: FieldComponent, decorators: [{
207
+ type: Component,
208
+ args: [{
209
+ selector: 'lib-field',
210
+ template: `<ng-content></ng-content>`
211
+ }]
212
+ }], propDecorators: { field: [{
213
+ type: Input
214
+ }] } });
215
+
216
+ class FormErrorComponent {
217
+ }
218
+ FormErrorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: FormErrorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
219
+ FormErrorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: FormErrorComponent, selector: "lib-form-error", inputs: { errorTitle: "errorTitle", errorMessage: "errorMessage", errorType: "errorType" }, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
220
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: FormErrorComponent, decorators: [{
221
+ type: Component,
222
+ args: [{
223
+ selector: 'lib-form-error',
224
+ template: `<ng-content></ng-content>`
225
+ }]
226
+ }], propDecorators: { errorTitle: [{
227
+ type: Input
228
+ }], errorMessage: [{
229
+ type: Input
230
+ }], errorType: [{
231
+ type: Input
232
+ }] } });
233
+
234
+ class FormHeaderComponent {
235
+ constructor() {
236
+ this.canGoBack = false;
237
+ this.goBackEvent = new EventEmitter();
238
+ }
239
+ goBackForm() {
240
+ this.goBackEvent.emit();
241
+ }
242
+ }
243
+ FormHeaderComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: FormHeaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
244
+ FormHeaderComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: FormHeaderComponent, selector: "lib-form-header", inputs: { form: "form", canGoBack: "canGoBack", showTitle: "showTitle", headerActions: "headerActions" }, outputs: { goBackEvent: "goBackEvent" }, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
245
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: FormHeaderComponent, decorators: [{
246
+ type: Component,
247
+ args: [{
248
+ selector: 'lib-form-header',
249
+ template: `<ng-content></ng-content>`
250
+ }]
251
+ }], propDecorators: { form: [{
252
+ type: Input
253
+ }], canGoBack: [{
254
+ type: Input
255
+ }], showTitle: [{
256
+ type: Input
257
+ }], headerActions: [{
258
+ type: Input
259
+ }], goBackEvent: [{
260
+ type: Output
261
+ }] } });
262
+
263
+ class SectionComponent extends PieceComponent {
264
+ ngOnInit() {
265
+ var _a, _b, _c, _d;
266
+ this.formConfig = (_a = this.section) === null || _a === void 0 ? void 0 : _a._formConfig;
267
+ const mapping = (_b = this.formConfig) === null || _b === void 0 ? void 0 : _b.sectionPropagateAttributes;
268
+ for (let index = 0; index < mapping.length; index++) {
269
+ const attrName = mapping[index].toString();
270
+ const attributeValue = (_c = this.section) === null || _c === void 0 ? void 0 : _c[attrName];
271
+ this.defaultProcessAttributeChange(attrName, attributeValue);
272
+ this.customProcessAttributeChange(attrName, attributeValue);
273
+ }
274
+ // Subscripción a cambios en atributos
275
+ (_d = this.section) === null || _d === void 0 ? void 0 : _d.attributeChange.subscribe(event => {
276
+ const { name: attrName, value } = event;
277
+ this.defaultProcessAttributeChange(attrName, value);
278
+ this.customProcessAttributeChange(attrName, value);
279
+ });
280
+ this.start();
281
+ }
282
+ start() { }
283
+ }
284
+ SectionComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: SectionComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
285
+ SectionComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: SectionComponent, selector: "lib-section", inputs: { section: "section", form: "form" }, usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
286
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: SectionComponent, decorators: [{
287
+ type: Component,
288
+ args: [{
289
+ selector: 'lib-section',
290
+ template: `<ng-content></ng-content>`
291
+ }]
292
+ }], propDecorators: { section: [{
293
+ type: Input
294
+ }], form: [{
295
+ type: Input
296
+ }] } });
297
+
298
+ class SubSectionComponent extends PieceComponent {
299
+ ngOnInit() {
300
+ var _a, _b, _c, _d;
301
+ this.formConfig = (_a = this.subSection) === null || _a === void 0 ? void 0 : _a._formConfig;
302
+ const mapping = (_b = this.formConfig) === null || _b === void 0 ? void 0 : _b.subSectionPropagateAttributes;
303
+ for (let index = 0; index < mapping.length; index++) {
304
+ const attrName = mapping[index].toString();
305
+ const attributeValue = (_c = this.subSection) === null || _c === void 0 ? void 0 : _c[attrName];
306
+ this.defaultProcessAttributeChange(attrName, attributeValue);
307
+ this.customProcessAttributeChange(attrName, attributeValue);
308
+ }
309
+ // Subscripción a cambios en atributos
310
+ (_d = this.subSection) === null || _d === void 0 ? void 0 : _d.attributeChange.subscribe(event => {
311
+ const { name: attrName, value } = event;
312
+ this.defaultProcessAttributeChange(attrName, value);
313
+ this.customProcessAttributeChange(attrName, value);
314
+ });
315
+ this.start();
316
+ }
317
+ start() { }
318
+ }
319
+ SubSectionComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: SubSectionComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
320
+ SubSectionComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: SubSectionComponent, selector: "lib-subsection", inputs: { subSection: "subSection", form: "form" }, usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
321
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: SubSectionComponent, decorators: [{
322
+ type: Component,
323
+ args: [{
324
+ selector: 'lib-subsection',
325
+ template: `<ng-content></ng-content>`
326
+ }]
327
+ }], propDecorators: { subSection: [{
328
+ type: Input
329
+ }], form: [{
330
+ type: Input
331
+ }] } });
332
+
333
+ const INLINE_ACTION$1 = 'INLINE';
334
+ class LibTableRecordActionComponent extends PieceComponent {
335
+ constructor() {
336
+ super(...arguments);
337
+ this.actionSelected = new EventEmitter();
338
+ }
339
+ ngOnInit() {
340
+ var _a, _b, _c, _d;
341
+ this.formConfig = (_a = this.action) === null || _a === void 0 ? void 0 : _a._formConfig;
342
+ const mapping = (_b = this.formConfig) === null || _b === void 0 ? void 0 : _b.actionPropagateAttributes;
343
+ for (let index = 0; index < mapping.length; index++) {
344
+ const attrName = mapping[index].toString();
345
+ const attributeValue = (_c = this.action) === null || _c === void 0 ? void 0 : _c[attrName];
346
+ this.defaultProcessAttributeChange(attrName, attributeValue);
347
+ this.customProcessAttributeChange(attrName, attributeValue);
348
+ }
349
+ // Subscripción a cambios en atributos
350
+ (_d = this.action) === null || _d === void 0 ? void 0 : _d.attributeChange.subscribe(event => {
351
+ const { name: attrName, value } = event;
352
+ this.defaultProcessAttributeChange(attrName, value);
353
+ this.customProcessAttributeChange(attrName, value);
354
+ });
355
+ this.start();
356
+ }
357
+ start() { }
358
+ onActivate() {
359
+ const tableEvent = {
360
+ actionCode: this.action.actionCode,
361
+ recordId: this.recordId,
362
+ recordData: this.recordData,
363
+ };
364
+ this.actionSelected.emit(tableEvent);
365
+ }
366
+ class() { }
367
+ }
368
+ LibTableRecordActionComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: LibTableRecordActionComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
369
+ LibTableRecordActionComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: LibTableRecordActionComponent, selector: "lib-table-record-action", inputs: { recordId: "recordId", recordData: "recordData", action: "action" }, outputs: { actionSelected: "actionSelected" }, usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
370
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: LibTableRecordActionComponent, decorators: [{
371
+ type: Component,
372
+ args: [{
373
+ selector: 'lib-table-record-action',
374
+ template: `<ng-content></ng-content>`,
375
+ changeDetection: ChangeDetectionStrategy.OnPush
376
+ }]
377
+ }], propDecorators: { recordId: [{
378
+ type: Input
379
+ }], recordData: [{
380
+ type: Input
381
+ }], action: [{
382
+ type: Input
383
+ }], actionSelected: [{
384
+ type: Output
385
+ }] } });
386
+
387
+ class LibTableRecordFieldComponent {
388
+ constructor() {
389
+ this.column = null;
390
+ }
391
+ ngOnInit() {
392
+ this.start();
393
+ }
394
+ start() { }
395
+ }
396
+ LibTableRecordFieldComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: LibTableRecordFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
397
+ LibTableRecordFieldComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: LibTableRecordFieldComponent, selector: "lib-table-record-field", inputs: { fieldCode: "fieldCode", fieldType: "fieldType", fieldValue: "fieldValue", column: "column" }, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
398
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: LibTableRecordFieldComponent, decorators: [{
399
+ type: Component,
400
+ args: [{
401
+ selector: 'lib-table-record-field',
402
+ template: `<ng-content></ng-content>`,
403
+ changeDetection: ChangeDetectionStrategy.OnPush
404
+ }]
405
+ }], propDecorators: { fieldCode: [{
406
+ type: Input
407
+ }], fieldType: [{
408
+ type: Input
409
+ }], fieldValue: [{
410
+ type: Input
411
+ }], column: [{
412
+ type: Input
413
+ }] } });
414
+
415
+ class LibTableComponent extends ElementComponent {
416
+ constructor() {
417
+ super(...arguments);
418
+ this.globalFilterString = '';
419
+ this.loaded = false;
420
+ this.selectable = false;
421
+ this.hasActions = false;
422
+ this.table = null;
423
+ this.visibleRecords = [];
424
+ this.waiting = false;
425
+ }
426
+ ngOnInit() {
427
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
428
+ if (!this.table) {
429
+ return;
430
+ }
431
+ this.formConfig = (_a = this.table) === null || _a === void 0 ? void 0 : _a._formConfig;
432
+ this.tableFieldStyles = (_b = this.formConfig) === null || _b === void 0 ? void 0 : _b.tableFieldStyles;
433
+ this.selectable = (_c = this.table) === null || _c === void 0 ? void 0 : _c.selectable;
434
+ this.hasActions = (_d = this.table) === null || _d === void 0 ? void 0 : _d.hasActions();
435
+ this.inlineActions = (_e = this.table) === null || _e === void 0 ? void 0 : _e.getActions((_f = this.formConfig) === null || _f === void 0 ? void 0 : _f.tableActions.inline);
436
+ this.globalActions = (_g = this.table) === null || _g === void 0 ? void 0 : _g.getActions((_h = this.formConfig) === null || _h === void 0 ? void 0 : _h.tableActions.global);
437
+ this.selectionActions = (_j = this.table) === null || _j === void 0 ? void 0 : _j.getActions((_k = this.formConfig) === null || _k === void 0 ? void 0 : _k.tableActions.selection);
438
+ // Inicialización de campos mapeados del objeto
439
+ const mapping = Object.entries((_l = this.formConfig) === null || _l === void 0 ? void 0 : _l.tablePropagationAttributes);
440
+ for (let index = 0; index < mapping.length; index++) {
441
+ const tableAttr = (_m = mapping[index]) === null || _m === void 0 ? void 0 : _m[0];
442
+ const componentAttr = (_q = (_p = (_o = mapping[index]) === null || _o === void 0 ? void 0 : _o[1]) === null || _p === void 0 ? void 0 : _p.toString()) !== null && _q !== void 0 ? _q : '';
443
+ const attributeValue = (_r = this.table) === null || _r === void 0 ? void 0 : _r[tableAttr];
444
+ this.defaultProcessAttributeChange(componentAttr, attributeValue);
445
+ this.customProcessAttributeChange(componentAttr, attributeValue);
446
+ }
447
+ // Subscripción a cambios en atributos
448
+ (_s = this.table) === null || _s === void 0 ? void 0 : _s.attributeChange.subscribe(event => {
449
+ const { name: attrName, value } = event;
450
+ this.defaultProcessAttributeChange(attrName, value);
451
+ this.customProcessAttributeChange(attrName, value);
452
+ });
453
+ this.start();
454
+ }
455
+ updateTableData() { }
456
+ tableGlobalAction(actionCode) { var _a; (_a = this.table) === null || _a === void 0 ? void 0 : _a.notifyGlobalAction(actionCode); }
457
+ tableSelectionAction(actionCode) { var _a; (_a = this.table) === null || _a === void 0 ? void 0 : _a.notifySelectionAction(actionCode); }
458
+ tableActionSelected(actionEvent) { var _a; (_a = this.table) === null || _a === void 0 ? void 0 : _a.notifyInlineAction(actionEvent); }
459
+ tableSelectionToggle(recordId) { var _a; (_a = this.table) === null || _a === void 0 ? void 0 : _a.notifyRecordSelection(recordId); }
460
+ toggleSelectAll() { var _a, _b, _c; return ((_a = this.table) === null || _a === void 0 ? void 0 : _a.allSelected) ? (_b = this.table) === null || _b === void 0 ? void 0 : _b.unSelectAll() : (_c = this.table) === null || _c === void 0 ? void 0 : _c.selectAll(); }
461
+ globalFilterCompleted() { this.changePage(1); }
462
+ changePage(requestedPage) { var _a; (_a = this.table) === null || _a === void 0 ? void 0 : _a.changePage(requestedPage); }
463
+ tableColumnSort(columnName, direction = null) { var _a; (_a = this.table) === null || _a === void 0 ? void 0 : _a.sort(columnName, direction !== null && direction !== void 0 ? direction : 'ascend'); }
464
+ globalFilterChanged() { var _a, _b, _c; (_a = this.table) === null || _a === void 0 ? void 0 : _a.setGlobalFilterString((_c = (_b = this.globalFilterString) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '', false); }
465
+ defaultProcessAttributeChange(attribute, value) {
466
+ try {
467
+ if (attribute === 'visibleRecords') {
468
+ this.updateTableData();
469
+ }
470
+ return super.defaultProcessAttributeChange(attribute, value);
471
+ }
472
+ catch (_a) {
473
+ return false;
474
+ }
475
+ }
476
+ filterHasChanged(column, values) {
477
+ var _a, _b;
478
+ if (!values || values.length === 0) {
479
+ (_a = this.table) === null || _a === void 0 ? void 0 : _a.removeColumnFilter(column.fieldCode);
480
+ }
481
+ else {
482
+ (_b = this.table) === null || _b === void 0 ? void 0 : _b.addColumnFilter(column.fieldCode, values);
483
+ }
484
+ }
485
+ }
486
+ LibTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: LibTableComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
487
+ LibTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: LibTableComponent, selector: "lib-table", inputs: { table: "table", visibleRecords: "visibleRecords", waiting: "waiting" }, usesInheritance: true, ngImport: i0, template: `<ng-content></ng-content>`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
488
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: LibTableComponent, decorators: [{
489
+ type: Component,
490
+ args: [{
491
+ selector: 'lib-table',
492
+ template: `<ng-content></ng-content>`,
493
+ changeDetection: ChangeDetectionStrategy.OnPush
494
+ }]
495
+ }], propDecorators: { table: [{
496
+ type: Input
497
+ }], visibleRecords: [{
498
+ type: Input
499
+ }], waiting: [{
500
+ type: Input
501
+ }] } });
502
+
503
+ const NO_ERROR = '00';
504
+ const HEADER$1 = 'HEADER';
505
+ const elementTypes = {
506
+ action: 'ACTION',
507
+ field: 'FIELD',
508
+ table: 'TABLE',
509
+ };
510
+ const formActions = {
511
+ tableAction: 'TABLEACTION',
512
+ getData: 'GETDATA',
513
+ getTableData: 'GETTABLEDATA',
514
+ validate: 'VALIDATE',
515
+ };
516
+ const operators = {
517
+ G: 'G',
518
+ L: 'L',
519
+ GE: 'GE',
520
+ LE: 'LE',
521
+ EQ: 'EQ',
522
+ NEQ: 'NEQ',
523
+ HAS: 'HAS',
524
+ NOTHAS: 'NOTHAS',
525
+ BETWEEN: 'BETWEEN',
526
+ IN: 'IN',
527
+ };
528
+
529
+ class FormPiece {
530
+ constructor(pieceDefinition, formConfig) {
531
+ var _a, _b, _c, _d;
532
+ this._formState = '';
533
+ this._absoluteVisible = true;
534
+ this._absoluteDisabled = false;
535
+ this.visibleStates = null;
536
+ this.enabledStates = null;
537
+ this._visible = true;
538
+ this._disabled = false;
539
+ this.customAttributes = {};
540
+ this._formConfig = formConfig;
541
+ this._isForced = false;
542
+ this._visibleForced = false;
543
+ this.setVisibleStates(pieceDefinition.visibleStates);
544
+ this.setEnabledStates(pieceDefinition.enabledStates);
545
+ this.enabled = (_a = !(pieceDefinition === null || pieceDefinition === void 0 ? void 0 : pieceDefinition.disabled)) !== null && _a !== void 0 ? _a : false;
546
+ this.setVisibility((_b = pieceDefinition === null || pieceDefinition === void 0 ? void 0 : pieceDefinition.visible) !== null && _b !== void 0 ? _b : true);
547
+ this.customAttributes = (_c = pieceDefinition === null || pieceDefinition === void 0 ? void 0 : pieceDefinition.customAttributes) !== null && _c !== void 0 ? _c : {};
548
+ if (pieceDefinition === null || pieceDefinition === void 0 ? void 0 : pieceDefinition.customAttributes) {
549
+ (_d = Object.keys(pieceDefinition === null || pieceDefinition === void 0 ? void 0 : pieceDefinition.customAttributes)) === null || _d === void 0 ? void 0 : _d.forEach(attr => this.customAttributes[attr] = pieceDefinition === null || pieceDefinition === void 0 ? void 0 : pieceDefinition.customAttributes[attr]);
550
+ }
551
+ }
552
+ getCustomAttribute(name) { var _a, _b; return (_b = (_a = this.customAttributes) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : null; }
553
+ setCustomAttribute(name, value) {
554
+ if (name) {
555
+ this.customAttributes[name] = value;
556
+ }
557
+ }
558
+ setCustomAttributes(attributes) {
559
+ Object.entries(attributes).forEach(([name, value]) => {
560
+ this.setCustomAttribute(name, value);
561
+ });
562
+ }
563
+ matchAttribute(name, value) { var _a; return ((_a = this.customAttributes) === null || _a === void 0 ? void 0 : _a[name]) === value; }
564
+ setVisibleStates(newStates) {
565
+ const visibleStates = (!Array.isArray(newStates) && typeof newStates === 'string')
566
+ ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
567
+ : newStates;
568
+ this.visibleStates = (Array.isArray(visibleStates)) ? visibleStates : [];
569
+ }
570
+ setEnabledStates(newStates) {
571
+ const enabledStates = (!Array.isArray(newStates) && typeof newStates === 'string')
572
+ ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
573
+ : newStates;
574
+ this.enabledStates = (Array.isArray(enabledStates)) ? enabledStates : [];
575
+ }
576
+ viewOnState(state) { return (this.visibleStates && state) ? this.visibleStates.includes(state) : false; }
577
+ enabledOnState(state) { return (this.enabledStates && state) ? this.enabledStates.includes(state) : false; }
578
+ get absoluteVisible() { return this._absoluteVisible; }
579
+ get absoluteDisabled() { return this._absoluteDisabled; }
580
+ get visible() { return this._visible; }
581
+ set visible(visible) { this.setVisibility(visible); }
582
+ visibleOn(state) {
583
+ return this._absoluteVisible && this.viewOnState(state);
584
+ }
585
+ enabledOn(state) {
586
+ return !this._absoluteDisabled && this.enabledOnState(state);
587
+ }
588
+ setVisibility(visible, forced = null) {
589
+ this._absoluteVisible = !!visible;
590
+ if (forced !== null) {
591
+ this._isForced = forced;
592
+ this._visibleForced = visible;
593
+ }
594
+ this._visible = this._absoluteVisible && this.viewOnState(this._formState);
595
+ }
596
+ show(forced = null) {
597
+ this.setVisibility(true, forced);
598
+ }
599
+ hide(forced = null) {
600
+ this.setVisibility(false, forced);
601
+ }
602
+ get enabled() { return !this._disabled; }
603
+ set enabled(enabled) {
604
+ this._absoluteDisabled = !enabled;
605
+ this._disabled = this._absoluteDisabled || !this.enabledOnState(this._formState);
606
+ }
607
+ get editable() { return !this._disabled; }
608
+ get disabled() { return this._disabled; }
609
+ set disabled(disabled) { this.enabled = !disabled; }
610
+ enable() { this.enabled = true; }
611
+ disable() { this.enabled = false; }
612
+ formStateChangeCustomSubscribe(formChangeSubject) { }
613
+ formStateChange(state) {
614
+ if (state) {
615
+ this._formState = state;
616
+ this._visible = this._absoluteVisible && this.viewOnState(state);
617
+ this._disabled = this._absoluteDisabled || !this.enabledOnState(state);
618
+ }
619
+ }
620
+ subscribeFormStateChange(formChangeSubject) {
621
+ this.formStateChangeCustomSubscribe(formChangeSubject);
622
+ formChangeSubject.subscribe(event => this.formStateChange(event === null || event === void 0 ? void 0 : event.state));
623
+ }
624
+ }
625
+
626
+ const VISIBLE = 'visible';
627
+ const DISABLED = 'disabled';
628
+ class FormPiecePropagate extends FormPiece {
629
+ constructor(pieceDefinition, formConfig) {
630
+ super(pieceDefinition, formConfig);
631
+ this.propagationCustomAttributes = [];
632
+ this._attributeChange = new BehaviorSubject(null);
633
+ }
634
+ get attributeChange() { return this._attributeChange; }
635
+ propagateAttribute(name, value) {
636
+ var _a;
637
+ (_a = this._attributeChange) === null || _a === void 0 ? void 0 : _a.next({ name, value });
638
+ }
639
+ setCustomAttribute(name, value) {
640
+ var _a;
641
+ super.setCustomAttribute(name, value);
642
+ if ((_a = this.propagationCustomAttributes) === null || _a === void 0 ? void 0 : _a.includes(name)) {
643
+ this.propagateAttribute(name, value);
644
+ }
645
+ }
646
+ setVisibility(visible, forced = null) {
647
+ super.setVisibility(visible, forced);
648
+ this.propagateAttribute(VISIBLE, this._visible);
649
+ }
650
+ set enabled(enabled) {
651
+ super.enabled = enabled;
652
+ this.propagateAttribute(DISABLED, this._disabled);
653
+ }
654
+ formStateChange(state) {
655
+ super.formStateChange(state);
656
+ if (state) {
657
+ this.propagateAttribute(VISIBLE, this._visible);
658
+ this.propagateAttribute(DISABLED, this._disabled);
659
+ }
660
+ }
661
+ }
662
+
663
+ class FormElement extends FormPiecePropagate {
664
+ constructor(elementDefinition, formConfig) {
665
+ super(elementDefinition, formConfig);
666
+ this.elementType = null;
667
+ }
668
+ ;
669
+ setAttr(attr, value) {
670
+ const { name: attrName, propagate: name } = attr;
671
+ this[attrName] = value;
672
+ name && this.propagateAttribute(name, value);
673
+ }
674
+ isField() { return this.elementType === elementTypes.field; }
675
+ isAction() { return this.elementType === elementTypes.action; }
676
+ isTable() { return this.elementType === elementTypes.table; }
677
+ /**
678
+ * @deprecated Utilizar viewOnState
679
+ */
680
+ supportState(state) { return this.viewOnState(state); }
681
+ /**
682
+ * @deprecated Utilizar viewOnState
683
+ */
684
+ supportMode(state) { return this.viewOnState(state); }
685
+ }
686
+
687
+ const HEADER = 'HEADER';
688
+ class FormAction extends FormElement {
689
+ constructor(actionDefinition, formConfig) {
690
+ var _a, _b, _c, _d, _e;
691
+ super(actionDefinition, formConfig);
692
+ this._actionActivated = new Subject();
693
+ this.inProgress = false;
694
+ this.propagationCustomAttributes = (_c = (_b = (_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.propagationCustomAttributes) === null || _b === void 0 ? void 0 : _b.actions) !== null && _c !== void 0 ? _c : [];
695
+ this.elementType = elementTypes.action;
696
+ this.actionCode = actionDefinition.actionCode ? actionDefinition.actionCode.toString() : '';
697
+ this.actionName = actionDefinition.actionTitle;
698
+ this.iconName = actionDefinition.iconName || this.actionCode;
699
+ this.setCustomAttribute('location', actionDefinition.position || HEADER);
700
+ this.backend = (_d = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.serverAction) !== null && _d !== void 0 ? _d : false;
701
+ this.newState = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.newState;
702
+ this.restrictedOnField = actionDefinition.fieldRestrictedCode ? actionDefinition.fieldRestrictedCode.toString() : '';
703
+ this.restrictedOnOperator = actionDefinition.operatorRestricted || '';
704
+ this.restrictedOnValue = (_e = actionDefinition.valueRestricted) !== null && _e !== void 0 ? _e : '';
705
+ this.customValidation = () => true;
706
+ }
707
+ get actionActivated() { return this._actionActivated; }
708
+ start() { this.inProgress = true; }
709
+ stop() { this.inProgress = false; }
710
+ notifyActivation() { this._actionActivated.next(this.actionCode); }
711
+ updateFromServer(receivedAction) {
712
+ for (const propertyName in receivedAction) {
713
+ if (propertyName !== 'actionCode' && propertyName !== 'actionId') {
714
+ this[propertyName] = receivedAction[propertyName];
715
+ }
716
+ }
717
+ }
718
+ setCustomValidation(callback) { this.customValidation = () => callback(); }
719
+ }
720
+
721
+ const UNDEFINED = 'undefined';
722
+ const DEFAULT_ERROR_TYPE = 'error';
723
+ const DEFAULT_CAPTURE_TYPE = 'INPUT';
724
+ const DEFAULT_ALIGNMENT = 'left';
725
+ const STD_MAX_LENGTH = 50;
726
+ const BIG_MAX_LENGTH = 500;
727
+ const directChanges = [
728
+ 'defaultEditable', 'defaultValue', 'alignment', 'required', 'errorCode', 'errorMessage', 'errorType',
729
+ 'tooltip', 'info', 'format', 'intrinsicErrorMessage', 'outputOnly', 'captureType', 'title', 'type',
730
+ 'maxLength', 'maxValue', 'minLength', 'minValue', 'validateOnServer', 'serverAction', 'visibleLabel',
731
+ 'options',
732
+ ];
733
+ const attrs$1 = {
734
+ _captureType: { name: '_captureType', propagate: 'captureType' },
735
+ _errorCode: { name: '_errorCode', propagate: 'errorCode' },
736
+ _errorMessage: { name: '_errorMessage', propagate: 'errorMessage' },
737
+ _errorType: { name: '_errorType', propagate: 'errorType' },
738
+ _defaultValue: { name: '_defaultValue', propagate: 'defaultValue' },
739
+ _defaultEditable: { name: '_defaultEditable', propagate: 'defaultEditable' },
740
+ _fieldAlignment: { name: '_fieldAlignment', propagate: 'alignment' },
741
+ _fieldCode: { name: '_fieldCode', propagate: 'code' },
742
+ _fieldInfo: { name: '_fieldInfo', propagate: 'info' },
743
+ _fieldRequired: { name: '_fieldRequired', propagate: 'required' },
744
+ _fieldTitle: { name: '_fieldTitle', propagate: 'title' },
745
+ _fieldType: { name: '_fieldType', propagate: 'type' },
746
+ _fieldFormat: { name: '_fieldFormat', propagate: 'format' },
747
+ _fieldOptions: { name: '_fieldOptions', propagate: 'options' },
748
+ _focus: { name: '_focus', propagate: 'focus' },
749
+ _hasChanged: { name: '_hasChanged', propagate: 'hasChanged' },
750
+ _intrinsicErrorMessage: { name: '_intrinsicErrorMessage', propagate: null },
751
+ _maxLength: { name: '_maxLength', propagate: 'maxLength' },
752
+ _maxValue: { name: '_maxValue', propagate: 'maxValue' },
753
+ _minLength: { name: '_minLength', propagate: 'minLength' },
754
+ _minValue: { name: '_minValue', propagate: 'minValue' },
755
+ _onValidation: { name: '_onValidation', propagate: 'onValidation' },
756
+ _outputOnly: { name: '_outputOnly', propagate: 'outputOnly' },
757
+ _tooltipText: { name: '_tooltipText', propagate: 'tooltip' },
758
+ _validateOnServer: { name: '_validateOnServer', propagate: 'validateOnServer' },
759
+ _value: { name: '_value', propagate: 'value' },
760
+ _visibleLabel: { name: '_visibleLabel', propagate: 'visibleLabel' },
761
+ };
762
+ class FieldDescriptor extends FormElement {
763
+ constructor(inputFieldReceived, formConfig) {
764
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
765
+ super(inputFieldReceived, formConfig);
766
+ this._editionFinish = new Subject();
767
+ this._editionPartial = new Subject();
768
+ this._detailRequest = new Subject();
769
+ this._errorType = '';
770
+ this._errorCode = '';
771
+ this._errorMessage = '';
772
+ this._fieldCode = '';
773
+ this._intrinsicErrorMessage = '';
774
+ this._maxLength = 0;
775
+ this._minLength = 0;
776
+ this._focus = false;
777
+ this._onValidation = false;
778
+ this._validateOnServer = false;
779
+ this._visibleLabel = false;
780
+ this._captureType = '';
781
+ this._defaultValue = '';
782
+ this._defaultEditable = false;
783
+ this._fieldAlignment = '';
784
+ this._fieldInfo = '';
785
+ this._fieldRequired = false;
786
+ this._fieldTitle = '';
787
+ this._fieldType = '';
788
+ this._fieldFormat = null;
789
+ this._fieldOptions = null;
790
+ this._hasChanged = false;
791
+ this._outputOnly = false;
792
+ this._tooltipText = '';
793
+ this.propagationCustomAttributes = (_c = (_b = (_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.propagationCustomAttributes) === null || _b === void 0 ? void 0 : _b.fields) !== null && _c !== void 0 ? _c : [];
794
+ this.elementType = elementTypes.field;
795
+ const fld = (inputFieldReceived) ? inputFieldReceived : {};
796
+ this.setAttr(attrs$1._fieldCode, fld.fieldCode);
797
+ this.title = (_d = fld.fieldTitle) !== null && _d !== void 0 ? _d : this._fieldCode;
798
+ this.type = fld.fieldTypeCode;
799
+ this.captureType = (_e = fld.captureType) !== null && _e !== void 0 ? _e : DEFAULT_CAPTURE_TYPE;
800
+ const defaultValue = (_f = fld.defaultValue) !== null && _f !== void 0 ? _f : null;
801
+ if (this._fieldType === this._formConfig.fieldTypes.boolean) {
802
+ this.defaultValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : false;
803
+ }
804
+ else {
805
+ this.defaultValue = defaultValue;
806
+ }
807
+ const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this._fieldType] != null)
808
+ ? this._formConfig.tableFieldStyles[this._fieldType]['text-align'] : DEFAULT_ALIGNMENT;
809
+ const fieldAlignment = (fld.alignment != null) ? fld.alignment.toLowerCase() : defaultTypeAlignment;
810
+ this.alignment = fieldAlignment;
811
+ this.info = fld.info || '';
812
+ let fieldFormat;
813
+ try {
814
+ fieldFormat = (fld.format) ? new RegExp(fld.format) : null;
815
+ }
816
+ catch (e) {
817
+ fieldFormat = null;
818
+ }
819
+ this.format = fieldFormat;
820
+ this.validateOnServer = (_g = fld.serverAction) !== null && _g !== void 0 ? _g : false;
821
+ this.tooltip = fld.tooltip || '';
822
+ this.defaultEditable = this.enabled;
823
+ this.required = (_h = fld.required) !== null && _h !== void 0 ? _h : false;
824
+ this.outputOnly = (_j = fld.outputOnly) !== null && _j !== void 0 ? _j : false;
825
+ this.maxLength = fld.maxLength || (this._captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
826
+ this.intrinsicErrorMessage = (_s = (_o = (_m = (_l = (_k = this._formConfig) === null || _k === void 0 ? void 0 : _k.fieldValidations) === null || _l === void 0 ? void 0 : _l[this._fieldType]) === null || _m === void 0 ? void 0 : _m.message) !== null && _o !== void 0 ? _o : (_r = (_q = (_p = this._formConfig) === null || _p === void 0 ? void 0 : _p.fieldValidations) === null || _q === void 0 ? void 0 : _q.DEFAULT) === null || _r === void 0 ? void 0 : _r.message) !== null && _s !== void 0 ? _s : '';
827
+ this.setError(fld.errorCode, fld.errorMessage, (_t = fld.errorType) !== null && _t !== void 0 ? _t : DEFAULT_ERROR_TYPE);
828
+ this.setEditable((_u = fld.editable) !== null && _u !== void 0 ? _u : true);
829
+ this.visibleLabel = (_v = fld.visibleLabel) !== null && _v !== void 0 ? _v : true;
830
+ this.setVisibility(fld.visible);
831
+ this.options = fld.fieldOptions;
832
+ this._setValue((_x = (_w = fld.fieldValue) !== null && _w !== void 0 ? _w : this._defaultValue) !== null && _x !== void 0 ? _x : '');
833
+ }
834
+ get alignment() { return this._fieldAlignment; }
835
+ set alignment(alignment) { this.setAttr(attrs$1._fieldAlignment, alignment); }
836
+ get backend() { return this._validateOnServer; }
837
+ get captureType() { return this._captureType; }
838
+ set captureType(captureType) { this.setAttr(attrs$1._captureType, captureType); }
839
+ get code() { return this._fieldCode; }
840
+ get fieldCode() { return this._fieldCode; }
841
+ get defaultValue() { return this._defaultValue; }
842
+ set defaultValue(defaultValue) { this.setAttr(attrs$1._defaultValue, defaultValue); }
843
+ get defaultEditable() { return this._defaultEditable; }
844
+ set defaultEditable(editable) { this.setAttr(attrs$1._defaultEditable, editable); }
845
+ get detailRequest() { return this._detailRequest; }
846
+ get editionFinish() { return this._editionFinish; }
847
+ get editionPartial() { return this._editionPartial; }
848
+ get empty() {
849
+ const fieldCurrentValue = this.value;
850
+ if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
851
+ return true;
852
+ }
853
+ if (this._fieldType === this._formConfig.fieldTypes.array
854
+ && Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
855
+ return true;
856
+ }
857
+ ;
858
+ if (this._fieldType === this._formConfig.fieldTypes.phone) {
859
+ if (!Array.isArray(fieldCurrentValue)) {
860
+ return true;
861
+ }
862
+ if (fieldCurrentValue.length !== 2 || !fieldCurrentValue[0] || !fieldCurrentValue[1]) {
863
+ return true;
864
+ }
865
+ return false;
866
+ }
867
+ ;
868
+ return fieldCurrentValue === '';
869
+ }
870
+ get error() { return { type: this._errorType, code: this._errorCode, message: this._errorMessage }; }
871
+ set error(errorObj) { var _a; this.setError(errorObj.code, errorObj.message, (_a = errorObj.type) !== null && _a !== void 0 ? _a : DEFAULT_ERROR_TYPE); }
872
+ get errorCode() { return this._errorCode; }
873
+ set errorCode(code) { this.setError(code, this._errorMessage); }
874
+ get errorMessage() { return this._errorMessage; }
875
+ set errorMessage(msg) { this.setError(this._errorCode, msg); }
876
+ get errorType() { return this._errorType; }
877
+ get externalValue() { return this._externalValue; }
878
+ get format() { return this._fieldFormat; }
879
+ set format(format) { this.setAttr(attrs$1._fieldFormat, format); }
880
+ get hasChanged() { return this._hasChanged; }
881
+ set hasChanged(hasChanged) { this.setAttr(attrs$1._hasChanged, hasChanged); }
882
+ get info() { return this._fieldInfo; }
883
+ set info(newInfo) { this.setAttr(attrs$1._fieldInfo, newInfo); }
884
+ set intrinsicErrorMessage(message) { this.setAttr(attrs$1._intrinsicErrorMessage, message); }
885
+ get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
886
+ set maxLength(requiredMaxLength) { this.setAttr(attrs$1._maxLength, requiredMaxLength ? +requiredMaxLength : null); }
887
+ get maxValue() { return this._maxValue; }
888
+ set maxValue(inputMaxValue) {
889
+ let maxValue = inputMaxValue;
890
+ if (this._fieldType === this._formConfig.fieldTypes.date) {
891
+ maxValue = new Date(maxValue);
892
+ }
893
+ this.setAttr(attrs$1._maxValue, maxValue);
894
+ }
895
+ get minLength() { return this._minLength; }
896
+ set minLength(requiredMinLength) { this.setAttr(attrs$1._minLength, requiredMinLength ? +requiredMinLength : null); }
897
+ get minValue() { return this._minValue; }
898
+ set minValue(inputMinValue) {
899
+ let minValue = inputMinValue;
900
+ if (this._fieldType === this._formConfig.fieldTypes.date) {
901
+ minValue = new Date(minValue);
902
+ }
903
+ this.setAttr(attrs$1._minValue, minValue);
904
+ }
905
+ get name() { return this._fieldCode; }
906
+ get options() {
907
+ var _a, _b;
908
+ return (_b = (_a = this._fieldOptions) === null || _a === void 0 ? void 0 : _a.map(option => {
909
+ const optionCopy = Object.assign({}, option);
910
+ return optionCopy;
911
+ })) !== null && _b !== void 0 ? _b : null;
912
+ }
913
+ set options(newOptions) {
914
+ var _a, _b, _c, _d, _e;
915
+ if ((!this._formConfig.captureTypesWithOptions.includes(this._captureType))
916
+ || typeof newOptions === UNDEFINED || !newOptions
917
+ || !Array.isArray(newOptions)) {
918
+ return;
919
+ }
920
+ let fieldOptions = newOptions.map((option) => {
921
+ if (option.text !== undefined && option.text !== null
922
+ && option.value !== undefined && option.value !== null) {
923
+ return { fieldOptionValue: option.text, fieldOptionId: option.value };
924
+ }
925
+ return option;
926
+ });
927
+ fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
928
+ && fieldOptions.length > 0) ? fieldOptions : [];
929
+ this.setAttr(attrs$1._fieldOptions, fieldOptions);
930
+ if (this._value) {
931
+ if (this._fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
932
+ const fieldValue = (_a = this._value) === null || _a === void 0 ? void 0 : _a.filter(item => { var _a; return (_a = this._fieldOptions) === null || _a === void 0 ? void 0 : _a.find(opt => opt.fieldOptionId === item); });
933
+ this.setAttr(attrs$1._value, fieldValue);
934
+ }
935
+ else {
936
+ const valInOptions = (_b = this._fieldOptions) === null || _b === void 0 ? void 0 : _b.find(item => item.fieldOptionId === this._value);
937
+ if (!valInOptions) {
938
+ this._setValue('');
939
+ }
940
+ }
941
+ }
942
+ if (this._fieldRequired && ((_c = this._fieldOptions) === null || _c === void 0 ? void 0 : _c.length) === 1 && this._value !== ((_d = this._fieldOptions) === null || _d === void 0 ? void 0 : _d[0].fieldOptionId)) {
943
+ this._setValue((_e = this._fieldOptions) === null || _e === void 0 ? void 0 : _e[0].fieldOptionId);
944
+ this.notifyEditionFinish();
945
+ }
946
+ }
947
+ get optionText() { var _a, _b, _c; return (_c = (_b = (_a = this._fieldOptions) === null || _a === void 0 ? void 0 : _a.find(item => item.fieldOptionId === this._value)) === null || _b === void 0 ? void 0 : _b.fieldOptionValue) !== null && _c !== void 0 ? _c : null; }
948
+ get outputOnly() { return this._outputOnly; }
949
+ set outputOnly(outputOnly) { this.setAttr(attrs$1._outputOnly, outputOnly); }
950
+ get required() { return this._fieldRequired; }
951
+ set required(required) { this.setAttr(attrs$1._fieldRequired, required !== null && required !== void 0 ? required : false); }
952
+ get title() { return this._fieldTitle; }
953
+ set title(title) { var _a; this.setAttr(attrs$1._fieldTitle, (_a = title === null || title === void 0 ? void 0 : title.toString()) !== null && _a !== void 0 ? _a : ''); }
954
+ get tooltip() { return this._tooltipText; }
955
+ set tooltip(tooltip) { this.setAttr(attrs$1._tooltipText, tooltip); }
956
+ get type() { return this._fieldType; }
957
+ set type(fieldType) { this.setAttr(attrs$1._fieldType, fieldType); }
958
+ get validating() { return this._onValidation; }
959
+ set validating(isValidating) { this.setAttr(attrs$1._onValidation, isValidating); }
960
+ get value() {
961
+ return (this._fieldType === this._formConfig.fieldTypes.boolean
962
+ || this._fieldType === this._formConfig.fieldTypes.check) ? yn(this._value) : this._value;
963
+ }
964
+ get validateOnServer() { return this._validateOnServer; }
965
+ set validateOnServer(validateOnServer) { this.setAttr(attrs$1._validateOnServer, validateOnServer); }
966
+ get serverAction() { return this._validateOnServer; }
967
+ set serverAction(validateOnServer) { this.validateOnServer = validateOnServer; }
968
+ set value(newValue) { this._setValue(newValue); }
969
+ get visibleLabel() { return this._visibleLabel; }
970
+ set visibleLabel(visibleLabel) { this.setAttr(attrs$1._visibleLabel, visibleLabel); }
971
+ /**
972
+ * @deprecated Use options
973
+ */
974
+ get fieldOptions() { return this._fieldOptions; }
975
+ /**
976
+ * @deprecated Use options
977
+ */
978
+ set fieldOptions(options) { this.options = options; }
979
+ /**
980
+ * @deprecated Use value
981
+ */
982
+ get fieldValue() { return this.value; }
983
+ /**
984
+ * @deprecated Use hasChanged
985
+ */
986
+ changed(hasChanged = true) { this.hasChanged = hasChanged; }
987
+ clean() { this._setValue(this._defaultValue || ''); this.resetError(); }
988
+ focus() { this.setAttr(attrs$1._focus, true); }
989
+ getErrorCode() { return this.error.code; }
990
+ setErrorCode(code) { this.setError(code, this._errorMessage); }
991
+ getErrorMessage() { return this.error.message; }
992
+ setErrorMessage(msg) { this.setError(this._errorCode, msg); }
993
+ getRequired() { return this.required; }
994
+ hasError() { return this._errorCode !== NO_ERROR; }
995
+ hideLabel() { this.visibleLabel = false; }
996
+ resetError() { (this._errorCode !== NO_ERROR) && this.setError(NO_ERROR, null); }
997
+ setEditable(editable = true) { (editable) ? this.enable() : this.disable(); }
998
+ setValue(newValue, widgetUpdate = true) { this._setValue(newValue, widgetUpdate); }
999
+ showLabel() { this.visibleLabel = true; }
1000
+ /**
1001
+ * @deprecated Use title
1002
+ */
1003
+ setLabel(label) { this.title = label; }
1004
+ /**
1005
+ * @deprecated Use required
1006
+ */
1007
+ setRequired(required) { this.required = required; }
1008
+ /**
1009
+ * @deprecated Use changed
1010
+ */
1011
+ setChanged(hasChanged) { this.changed(hasChanged); }
1012
+ /**
1013
+ * @deprecated Use value
1014
+ */
1015
+ getValue() { return this.value; }
1016
+ /**
1017
+ * @deprecated Use empty
1018
+ */
1019
+ isEmpty() { return this.empty; }
1020
+ /**
1021
+ * @deprecated Use error
1022
+ */
1023
+ getError() { return this.error; }
1024
+ /**
1025
+ * @deprecated Use optionText
1026
+ */
1027
+ getOptionText() { return this.optionText; }
1028
+ /**
1029
+ * @deprecated Use options
1030
+ */
1031
+ getFieldOptions() { return this.options; }
1032
+ /**
1033
+ * @deprecated Use options
1034
+ */
1035
+ setFieldOptions(newOptions) { return this.options = newOptions; }
1036
+ /**
1037
+ * @deprecated Use intrinsicErrorMessage
1038
+ */
1039
+ setIntrinsicErrorMessage(message) { this.intrinsicErrorMessage = message; }
1040
+ /**
1041
+ * @deprecated Use maxValue
1042
+ */
1043
+ setMaxValue(inputMaxValue) { this.maxValue = inputMaxValue; }
1044
+ /**
1045
+ * @deprecated Use minValue
1046
+ */
1047
+ setMinValue(inputMinValue) { this.minValue = inputMinValue; }
1048
+ /**
1049
+ * @deprecated Use showLabel
1050
+ */
1051
+ setVisibleLabel(visibleLabel) { this.visibleLabel = visibleLabel; }
1052
+ notifyEditionPartial() {
1053
+ this.resetError();
1054
+ this._editionPartial.next({ code: this._fieldCode, intrinsicValidation: true });
1055
+ }
1056
+ notifyEditionFinish() {
1057
+ var _a, _b, _c, _d, _e;
1058
+ const fieldValue = this.value;
1059
+ this.resetError();
1060
+ const validationConfig = (_b = (_a = this._formConfig.fieldValidations) === null || _a === void 0 ? void 0 : _a[this._fieldType]) !== null && _b !== void 0 ? _b : {};
1061
+ const { type, validation } = validationConfig;
1062
+ let message = validationConfig === null || validationConfig === void 0 ? void 0 : validationConfig.message;
1063
+ let intrinsicValidation = true;
1064
+ if (fieldValue && (validation || this._fieldFormat)) {
1065
+ if (type === 'regexp') {
1066
+ intrinsicValidation = ((_c = validation === null || validation === void 0 ? void 0 : validation.test(fieldValue)) !== null && _c !== void 0 ? _c : true)
1067
+ && ((_e = (_d = this._fieldFormat) === null || _d === void 0 ? void 0 : _d.test(fieldValue)) !== null && _e !== void 0 ? _e : true);
1068
+ }
1069
+ else if (type === 'function' && typeof validation === 'function') {
1070
+ const { valid, message: customMessage } = validation(fieldValue, this);
1071
+ intrinsicValidation = valid;
1072
+ message = customMessage;
1073
+ }
1074
+ if (!intrinsicValidation) {
1075
+ this.setError('99', message !== null && message !== void 0 ? message : this._intrinsicErrorMessage);
1076
+ }
1077
+ }
1078
+ if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
1079
+ intrinsicValidation = false;
1080
+ this.setError('99', 'Campo con valor inferior al mínimo');
1081
+ }
1082
+ if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
1083
+ intrinsicValidation = false;
1084
+ this.setError('99', 'Campo con valor superior al máximo');
1085
+ }
1086
+ if (intrinsicValidation && fieldValue && typeof fieldValue === 'string'
1087
+ && this._minLength && (fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.length) < this._minLength) {
1088
+ intrinsicValidation = false;
1089
+ this.setError('99', `Longitud de ${this._fieldTitle} debe ser de al menos ${this._minLength}`);
1090
+ }
1091
+ this._editionFinish.next({ code: this._fieldCode, intrinsicValidation });
1092
+ }
1093
+ notifyEditionDetailRequest(detail) {
1094
+ const detailEvent = { code: this._fieldCode, detail };
1095
+ this._detailRequest.next(detailEvent);
1096
+ }
1097
+ setError(code, message, type = DEFAULT_ERROR_TYPE) {
1098
+ this.setAttr(attrs$1._errorCode, code !== null && code !== void 0 ? code : NO_ERROR);
1099
+ this.setAttr(attrs$1._errorType, (this._errorCode === NO_ERROR) ? '' : type);
1100
+ this.setAttr(attrs$1._errorMessage, message !== null && message !== void 0 ? message : '');
1101
+ }
1102
+ updateFromServer(fld) {
1103
+ const fieldKeys = Object.keys(fld);
1104
+ for (let index = 0; index < fieldKeys.length; index++) {
1105
+ const attrName = fieldKeys[index];
1106
+ const attrValue = fld[attrName];
1107
+ if (directChanges.includes(attrName)) {
1108
+ this[attrName] = attrValue;
1109
+ }
1110
+ else {
1111
+ (attrName === 'label') && (this.title = attrValue);
1112
+ (attrName === 'labelVisible') && (this.visibleLabel = attrValue);
1113
+ (attrName === 'editable') && this.setEditable(attrValue);
1114
+ (attrName === 'visible') && this.setVisibility(attrValue);
1115
+ (attrName === 'value') && (this._setValue(attrValue) && (this.hasChanged = false));
1116
+ (attrName === 'fieldValue') && (this._setValue(attrValue) && (this.hasChanged = false));
1117
+ (attrName === 'fieldOptions') && (this.options = attrValue);
1118
+ (attrName === 'fieldTitle') && (this.title = attrValue);
1119
+ (attrName === 'fieldTypeCode') && (this.type = attrValue);
1120
+ (attrName === 'fieldType') && (this.type = attrValue);
1121
+ (attrName === 'tooltipText') && (this.tooltip = attrValue);
1122
+ }
1123
+ }
1124
+ }
1125
+ _setValue(newValue, widgetUpdate = true) {
1126
+ var _a;
1127
+ if (typeof newValue === UNDEFINED) {
1128
+ return true;
1129
+ }
1130
+ if (newValue === null && this.required) {
1131
+ return true;
1132
+ }
1133
+ let newFinalValue;
1134
+ if (this._fieldType === this._formConfig.fieldTypes.boolean
1135
+ || this._fieldType === this._formConfig.fieldTypes.check) {
1136
+ newFinalValue = (_a = yn(newValue)) !== null && _a !== void 0 ? _a : false;
1137
+ }
1138
+ else if (this._fieldType === this._formConfig.fieldTypes.array
1139
+ || this._fieldType === this._formConfig.fieldTypes.map) {
1140
+ if (newValue === null || newValue === '') {
1141
+ newFinalValue = [];
1142
+ }
1143
+ else if (Array.isArray(newValue)) {
1144
+ newFinalValue = newValue;
1145
+ }
1146
+ else {
1147
+ newFinalValue = newValue.toString().split(',');
1148
+ }
1149
+ }
1150
+ else {
1151
+ newFinalValue = newValue;
1152
+ }
1153
+ if (this._value !== newFinalValue) {
1154
+ this.hasChanged = true;
1155
+ if (widgetUpdate) {
1156
+ this.setAttr(attrs$1._value, newFinalValue);
1157
+ }
1158
+ else {
1159
+ this._value = newFinalValue;
1160
+ }
1161
+ }
1162
+ return true;
1163
+ }
1164
+ }
1165
+
1166
+ class RecordTableColumn extends FormPiece {
1167
+ constructor(recTableColReceived, formConfig) {
1168
+ var _a, _b, _c, _d;
1169
+ super(recTableColReceived, formConfig);
1170
+ this.fieldCode = '';
1171
+ this.fieldTitle = '';
1172
+ this.fieldType = '';
1173
+ this.fieldAlignment = '';
1174
+ this.fieldFormat = '';
1175
+ this.sortable = true;
1176
+ this.searchable = true;
1177
+ this.sortDirections = [];
1178
+ // Filtros
1179
+ this.filterVisible = false;
1180
+ this.filterDef = null;
1181
+ this.filterSetup = null;
1182
+ this.filterDef = null;
1183
+ if (recTableColReceived) {
1184
+ this.fieldCode = recTableColReceived.fieldCode;
1185
+ this.fieldTitle = recTableColReceived.fieldTitle;
1186
+ this.fieldType = recTableColReceived.fieldTypeCode || this._formConfig.fieldTypes.text;
1187
+ const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this.fieldType] != null) ? this._formConfig.tableFieldStyles[this.fieldType]['text-align'] : 'left';
1188
+ this.fieldAlignment = (recTableColReceived.alignment != null) ? recTableColReceived.alignment.toLowerCase() : defaultTypeAlignment;
1189
+ this._absoluteVisible = (_a = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.visible) !== null && _a !== void 0 ? _a : true;
1190
+ this.sortable = (_b = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.sortable) !== null && _b !== void 0 ? _b : false;
1191
+ this.searchable = (_c = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.searchable) !== null && _c !== void 0 ? _c : true;
1192
+ this.sortDirections = (this.sortable) ? ['ascend', 'descend'] : [];
1193
+ this.fieldFormat = recTableColReceived.format || '';
1194
+ this.customAttributes = (_d = recTableColReceived === null || recTableColReceived === void 0 ? void 0 : recTableColReceived.customAttributes) !== null && _d !== void 0 ? _d : {};
1195
+ }
1196
+ }
1197
+ setSearchable(searchable = true) { this.searchable = searchable; }
1198
+ hideFilter() {
1199
+ this.filterVisible = false;
1200
+ }
1201
+ addFilterDefinition(filterDefinition) {
1202
+ var _a;
1203
+ this.filterDef = {
1204
+ operators: filterDefinition.operators,
1205
+ options: (_a = filterDefinition.options) !== null && _a !== void 0 ? _a : null,
1206
+ };
1207
+ }
1208
+ get filterDefinition() {
1209
+ return this.filterDef;
1210
+ }
1211
+ addFilter(columnValues, operator) {
1212
+ var _a;
1213
+ this.filterSetup = {
1214
+ fieldCode: this.fieldCode,
1215
+ operator: operator !== null && operator !== void 0 ? operator : (_a = this.filterDef) === null || _a === void 0 ? void 0 : _a.operators[0],
1216
+ values: columnValues,
1217
+ };
1218
+ }
1219
+ get filter() {
1220
+ return this.filterSetup;
1221
+ }
1222
+ removeFilter() {
1223
+ this.filterSetup = null;
1224
+ }
1225
+ get options() {
1226
+ var _a, _b, _c, _d;
1227
+ if (((_b = (_a = this.filterDef) === null || _a === void 0 ? void 0 : _a.operators) === null || _b === void 0 ? void 0 : _b.length) === 1 && ((_c = this.filterDef) === null || _c === void 0 ? void 0 : _c.operators[0]) === 'IN') {
1228
+ return (_d = this.filterDef) === null || _d === void 0 ? void 0 : _d.options;
1229
+ }
1230
+ return null;
1231
+ }
1232
+ serSortDirections(ascend, descend) {
1233
+ this.sortDirections = [];
1234
+ if (ascend) {
1235
+ this.sortDirections.unshift('ascend');
1236
+ }
1237
+ if (descend) {
1238
+ this.sortDirections.unshift('descend');
1239
+ }
1240
+ }
1241
+ }
1242
+
1243
+ class TableAction extends FormPiece {
1244
+ constructor(actionDefinition, formConfig) {
1245
+ var _a, _b;
1246
+ super(actionDefinition, formConfig);
1247
+ this.actionCode = actionDefinition.actionCode;
1248
+ this.actionTitle = actionDefinition.actionTitle;
1249
+ this.iconName = actionDefinition.iconName || this.actionCode;
1250
+ this.actionType = actionDefinition.actionType || 'STANDARD';
1251
+ this.actionClass = actionDefinition.actionClass || 'INLINE';
1252
+ this.newState = actionDefinition.newState;
1253
+ this.stateField = actionDefinition.stateField || '';
1254
+ this.backend = (_a = actionDefinition === null || actionDefinition === void 0 ? void 0 : actionDefinition.serverAction) !== null && _a !== void 0 ? _a : false;
1255
+ this.restrictedOnField = actionDefinition.fieldRestrictedCode || '';
1256
+ this.restrictedOnValue = (_b = actionDefinition.valueRestricted) !== null && _b !== void 0 ? _b : '';
1257
+ this.restrictedOnOperator = actionDefinition.operatorRestricted || '';
1258
+ }
1259
+ }
1260
+
1261
+ class TableRecordData {
1262
+ constructor(recordReceived, recordDefinition, selectionFieldName = null) {
1263
+ this.recordId = null;
1264
+ this.selected = false;
1265
+ this.recordData = {};
1266
+ const { tableRecordId, recordData } = recordReceived;
1267
+ this.recordId = tableRecordId;
1268
+ if (!recordDefinition || recordDefinition.length === 0 || !recordData || recordData.length === 0) {
1269
+ return;
1270
+ }
1271
+ const fieldNames = recordDefinition.map(column => column.fieldCode);
1272
+ if (Array.isArray(recordData)) {
1273
+ const rawRecordData = recordData.filter(fieldData => fieldData.fieldCode && fieldNames.includes(fieldData.fieldCode));
1274
+ rawRecordData.forEach(fieldData => {
1275
+ const { fieldCode, fieldValue } = fieldData;
1276
+ const fieldDef = recordDefinition.find(column => column.fieldCode === fieldCode);
1277
+ this.recordData[fieldCode] = fieldValue !== null && fieldValue !== void 0 ? fieldValue : '';
1278
+ if (fieldCode === selectionFieldName) {
1279
+ this.selected = fieldValue;
1280
+ }
1281
+ });
1282
+ }
1283
+ else {
1284
+ const fields = Object.keys(recordData);
1285
+ fields.forEach(fieldCode => {
1286
+ const fieldValue = recordData[fieldCode];
1287
+ const fieldDef = recordDefinition.find(column => column.fieldCode === fieldCode);
1288
+ this.recordData[fieldCode] = fieldValue !== null && fieldValue !== void 0 ? fieldValue : '';
1289
+ });
1290
+ }
1291
+ }
1292
+ toggleSelect() { this.selected = !this.selected; }
1293
+ select() { this.selected = true; }
1294
+ unselect() { this.selected = false; }
1295
+ get recordIdKey() {
1296
+ return (typeof this.recordId === 'object')
1297
+ ? JSON.stringify(this.recordId) : this.recordId;
1298
+ }
1299
+ getFieldValue(fieldCode) {
1300
+ return (fieldCode && this.recordData) ? this.recordData[fieldCode] : null;
1301
+ }
1302
+ hasPattern(words, columnObj) {
1303
+ if (!words || words.length === 0) {
1304
+ return true;
1305
+ }
1306
+ for (const word of words) {
1307
+ let wordIsPresent = false;
1308
+ for (const fieldCode in this.recordData) {
1309
+ const columnDef = columnObj === null || columnObj === void 0 ? void 0 : columnObj[fieldCode];
1310
+ if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.searchable) && this.recordData.hasOwnProperty(fieldCode)) {
1311
+ const term = word.toUpperCase();
1312
+ let fieldValue;
1313
+ if (columnDef.fieldType.toUpperCase().includes('DATE')) {
1314
+ fieldValue = this.recordData[fieldCode].substring(0, 16);
1315
+ }
1316
+ else {
1317
+ fieldValue = this.recordData[fieldCode];
1318
+ }
1319
+ if (fieldValue.toString().toUpperCase().includes(term)) {
1320
+ wordIsPresent = true;
1321
+ break;
1322
+ }
1323
+ }
1324
+ }
1325
+ if (!wordIsPresent) {
1326
+ return false;
1327
+ }
1328
+ }
1329
+ return true;
1330
+ }
1331
+ hasCondition(columnFilters) {
1332
+ if (!columnFilters || columnFilters.length === 0) {
1333
+ return true;
1334
+ }
1335
+ for (const condition of columnFilters) {
1336
+ const { fieldCode, operator, values } = condition;
1337
+ if (this.recordData.hasOwnProperty(fieldCode)) {
1338
+ const fieldValue = this.recordData[fieldCode];
1339
+ const stringValue = fieldValue.toString().toUpperCase();
1340
+ if (operator === operators.G && fieldValue <= values[0]) {
1341
+ return false;
1342
+ }
1343
+ if (operator === operators.L && fieldValue >= values[0]) {
1344
+ return false;
1345
+ }
1346
+ if (operator === operators.GE && fieldValue < values[0]) {
1347
+ return false;
1348
+ }
1349
+ if (operator === operators.LE && fieldValue > values[0]) {
1350
+ return false;
1351
+ }
1352
+ if (operator === operators.IN && !values.includes(fieldValue)) {
1353
+ return false;
1354
+ }
1355
+ if (operator === operators.EQ) {
1356
+ return fieldValue === values[0];
1357
+ }
1358
+ if (operator === operators.NEQ && fieldValue === values[0]) {
1359
+ return false;
1360
+ }
1361
+ if (operator === operators.HAS && !stringValue.includes(values[0].toString().toUpperCase())) {
1362
+ return false;
1363
+ }
1364
+ if (operator === operators.NOTHAS && stringValue.includes(values[0].toString().toUpperCase())) {
1365
+ return false;
1366
+ }
1367
+ if (operator === operators.BETWEEN && (fieldValue < values[0] || fieldValue > values[1])) {
1368
+ return false;
1369
+ }
1370
+ }
1371
+ }
1372
+ return true;
1373
+ }
1374
+ }
1375
+
1376
+ const TABLE_SORT_ASCENDING = 'asc';
1377
+ const TABLE_SORT_DESCENDING = 'desc';
1378
+ const attrs = {
1379
+ allSelected: { name: 'allSelected', propagate: 'allSelected' },
1380
+ tableCode: { name: 'tableCode', propagate: 'code' },
1381
+ clientPaging: { name: 'clientPaging', propagate: null },
1382
+ globalSearch: { name: 'globalSearch', propagate: 'globalSearch' },
1383
+ globalFilterString: { name: 'globalFilterString', propagate: 'globalFilterString' },
1384
+ sorting: { name: 'sorting', propagate: null },
1385
+ recordsPerPage: { name: 'recordsPerPage', propagate: 'recordsPerPage' },
1386
+ layout: { name: 'layout', propagate: 'layout' },
1387
+ columns: { name: 'columns', propagate: 'columns' },
1388
+ selectedRecords: { name: 'selectedRecords', propagate: 'selectedRecords' },
1389
+ currentPage: { name: 'currentPage', propagate: 'currentPage' },
1390
+ totalRecordsNumber: { name: 'totalRecordsNumber', propagate: 'totalRecordsNumber' },
1391
+ visibleRecords: { name: 'visibleRecords', propagate: 'visibleRecords' },
1392
+ };
1393
+ class RecordTable extends FormElement {
1394
+ constructor(tableReceived, formConfig) {
1395
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1396
+ super(tableReceived, formConfig);
1397
+ this._inlineActionTrigger = new Subject();
1398
+ this._globalActionTrigger = new Subject();
1399
+ this._recordSelectionTrigger = new Subject();
1400
+ this._selectionActionTrigger = new Subject();
1401
+ this._getDataTrigger = new Subject();
1402
+ this._tableColumnObj = {};
1403
+ this._actionsObj = {};
1404
+ // Mecanismos de filtrado nueva versión
1405
+ this.globalFilterString = '';
1406
+ this.globalFilterStrings = [];
1407
+ this.layout = null;
1408
+ this.tableRecordObj = {};
1409
+ this.visibleRecords = null;
1410
+ this.allSelected = false;
1411
+ this.tableCode = '';
1412
+ this.recordsPerPage = 10;
1413
+ this.totalRecordsNumber = 0;
1414
+ this.recordsNumber = 0;
1415
+ this.clientPaging = true;
1416
+ this.propagationCustomAttributes = (_c = (_b = (_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.propagationCustomAttributes) === null || _b === void 0 ? void 0 : _b.tables) !== null && _c !== void 0 ? _c : [];
1417
+ this.elementType = elementTypes.table;
1418
+ this.waiting = false;
1419
+ this.currentPage = 1;
1420
+ this.totalPages = 1;
1421
+ this.requestedPage = 1;
1422
+ this.columns = [];
1423
+ this._tableColumnObj = {};
1424
+ this._actions = [];
1425
+ this._actionsObj = {};
1426
+ this.tableRecords = [];
1427
+ this.globalSearch = false;
1428
+ this.restrictedId = null;
1429
+ this.tableTitle = tableReceived.tableTitle;
1430
+ this._appendPages = (_d = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.append) !== null && _d !== void 0 ? _d : false;
1431
+ this.selectable = (_e = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectable) !== null && _e !== void 0 ? _e : false;
1432
+ this.selectionBackend = (_f = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionBackend) !== null && _f !== void 0 ? _f : false;
1433
+ this.sortable = (_g = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.sortable) !== null && _g !== void 0 ? _g : false;
1434
+ this.setAttr(attrs.allSelected, false);
1435
+ this.setAttr(attrs.tableCode, tableReceived.tableCode);
1436
+ this.setAttr(attrs.clientPaging, (_h = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.clientPaging) !== null && _h !== void 0 ? _h : true);
1437
+ this.setAttr(attrs.globalSearch, (_j = tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.simpleFilter) !== null && _j !== void 0 ? _j : false);
1438
+ this.setAttr(attrs.globalFilterString, '');
1439
+ this.setAttr(attrs.sorting, { columnName: '', direction: '' });
1440
+ this.setAttr(attrs.recordsPerPage, formConfig.defaultRecordsPerPage);
1441
+ this.setAttr(attrs.layout, '');
1442
+ if (tableReceived.fields) {
1443
+ const columns = [];
1444
+ for (const columnReceived of tableReceived.fields) {
1445
+ const columnEnriched = Object.assign(Object.assign({}, columnReceived), { visibleStates: this.visibleStates, enabledStates: this.enabledStates });
1446
+ const columnDefinition = new RecordTableColumn(columnEnriched, this._formConfig);
1447
+ columns.push(columnDefinition);
1448
+ this._tableColumnObj[columnDefinition.fieldCode] = columnDefinition;
1449
+ }
1450
+ this.setAttr(attrs.columns, columns);
1451
+ }
1452
+ if (tableReceived.actions) {
1453
+ const tableActions = tableReceived.actions.map(objDef => {
1454
+ let visibleStates = objDef.visibleStates;
1455
+ let enabledStates = objDef.enabledStates;
1456
+ if (!visibleStates) {
1457
+ visibleStates = (objDef.actionModes || '').split(',')
1458
+ .map(state => state.trim())
1459
+ .filter(state => state.length > 0);
1460
+ enabledStates = (objDef.actionModes || '').split(',')
1461
+ .map(state => state.trim())
1462
+ .filter(state => state.length > 0);
1463
+ }
1464
+ return Object.assign(Object.assign({}, objDef), { visibleStates, enabledStates });
1465
+ });
1466
+ for (const actionReceived of tableActions) {
1467
+ const inlineAction = new TableAction(actionReceived, this._formConfig);
1468
+ this._actions.push(inlineAction);
1469
+ this._actionsObj[inlineAction.actionCode] = inlineAction;
1470
+ }
1471
+ }
1472
+ this.selectionField = (this.selectable) ? tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.selectionField : null;
1473
+ // Filtros predefinidos en el formulario
1474
+ if (tableReceived.filters) {
1475
+ for (let index = 0; index < tableReceived.filters.length; index++) {
1476
+ this.addFilterDefinition(tableReceived.filters[index].fieldCode, tableReceived.filters[index]);
1477
+ }
1478
+ }
1479
+ }
1480
+ get columnNames() { return Object.keys(this._tableColumnObj); }
1481
+ get inlineActionTrigger() { return this._inlineActionTrigger; }
1482
+ get globalActionTrigger() { return this._globalActionTrigger; }
1483
+ get selectionActionTrigger() { return this._selectionActionTrigger; }
1484
+ get recordSelectionTrigger() { return this._recordSelectionTrigger; }
1485
+ get getDataTrigger() { return this._getDataTrigger; }
1486
+ getLayout() { return this.layout; }
1487
+ setLayout(layout) { this.setAttr(attrs.layout, layout); }
1488
+ hasActions() { return (this._actions.length > 0); }
1489
+ getSelectedRecords() { return this.tableRecords.filter(rec => rec.selected).map(rec => rec.recordId); }
1490
+ activateGlobalSearch() { this.globalSearch = true; }
1491
+ inactivateGlobalSearch() { this.globalSearch = false; }
1492
+ columnDefinition(fieldCode) { return this._tableColumnObj[fieldCode]; }
1493
+ putOnWait() { this.waiting = true; }
1494
+ freeWaiting() { this.waiting = false; }
1495
+ notifyGlobalAction(actionCode) {
1496
+ const tableEvent = {
1497
+ tableCode: this.tableCode,
1498
+ actionCode,
1499
+ actionDetail: null
1500
+ };
1501
+ this._globalActionTrigger.next(tableEvent);
1502
+ }
1503
+ notifyInlineAction(tableActionEvent) {
1504
+ const tableEvent = {
1505
+ tableCode: this.tableCode,
1506
+ actionCode: tableActionEvent.actionCode,
1507
+ actionDetail: {
1508
+ recordId: tableActionEvent.recordId,
1509
+ recordData: tableActionEvent.recordData
1510
+ }
1511
+ };
1512
+ this._inlineActionTrigger.next(tableEvent);
1513
+ }
1514
+ notifyRecordSelection(recordId) {
1515
+ var _a;
1516
+ const record = this.getTableRecord(recordId);
1517
+ if (!record) {
1518
+ return;
1519
+ }
1520
+ record.toggleSelect();
1521
+ this.requestedPage = (_a = this.currentPage) !== null && _a !== void 0 ? _a : 1;
1522
+ const tableEvent = {
1523
+ tableCode: this.tableCode,
1524
+ actionCode: null,
1525
+ actionDetail: {
1526
+ recordId: record.recordId,
1527
+ recordData: record.recordData
1528
+ }
1529
+ };
1530
+ this.recordSelectionTrigger.next(tableEvent);
1531
+ }
1532
+ notifySelectionAction(actionCode) {
1533
+ const tableEvent = {
1534
+ tableCode: this.tableCode,
1535
+ actionCode,
1536
+ actionDetail: {
1537
+ selectedRecords: this.selectedRecords
1538
+ }
1539
+ };
1540
+ this._selectionActionTrigger.next(tableEvent);
1541
+ }
1542
+ notifyGetDataAction(requestedPage = null) {
1543
+ this.updateVisibleRecords();
1544
+ this.requestedPage = requestedPage || this.currentPage || 1;
1545
+ const tableEvent = {
1546
+ tableCode: this.tableCode,
1547
+ actionCode: null,
1548
+ actionDetail: null,
1549
+ };
1550
+ this._getDataTrigger.next(tableEvent);
1551
+ return null;
1552
+ }
1553
+ clean() {
1554
+ this.tableRecords = [];
1555
+ this.unSelectAll();
1556
+ this.tableRecordObj = {};
1557
+ this.updateVisibleRecords();
1558
+ }
1559
+ selectAll() {
1560
+ this.setAttr(attrs.allSelected, true);
1561
+ this.tableRecords.forEach(record => record.select());
1562
+ this.setAttr(attrs.selectedRecords, this.getSelectedRecords());
1563
+ return true;
1564
+ }
1565
+ unSelectAll() {
1566
+ this.setAttr(attrs.allSelected, false);
1567
+ this.tableRecords.forEach(record => record.unselect());
1568
+ this.setAttr(attrs.selectedRecords, this.getSelectedRecords());
1569
+ return true;
1570
+ }
1571
+ setTableRecords(tableRecords, append) {
1572
+ if (!append) {
1573
+ this.tableRecords = [];
1574
+ this.setAttr(attrs.allSelected, false);
1575
+ this.tableRecords.forEach(record => record.unselect());
1576
+ this.setAttr(attrs.selectedRecords, []);
1577
+ this.tableRecordObj = {};
1578
+ }
1579
+ const newRecordsObj = Object.assign({}, this.tableRecordObj);
1580
+ const newRecords = [...this.tableRecords];
1581
+ for (const tableRecord of tableRecords) {
1582
+ const recordReceived = new TableRecordData(tableRecord, this.columns, this.selectionField);
1583
+ const recordIdKey = recordReceived.recordIdKey;
1584
+ newRecords.push(recordReceived);
1585
+ newRecordsObj[recordIdKey] = recordReceived;
1586
+ }
1587
+ this.tableRecords = newRecords;
1588
+ this.setAttr(attrs.selectedRecords, this.getSelectedRecords());
1589
+ this.tableRecordObj = newRecordsObj;
1590
+ this.updateVisibleRecords();
1591
+ }
1592
+ appendRecords(records) { this.setTableRecords(records, true); }
1593
+ replaceRecords(records) { this.setTableRecords(records, false); }
1594
+ setTableAppend(append) { this._appendPages = append; }
1595
+ changePage(requestedPage) {
1596
+ if (this.clientPaging) {
1597
+ this.setAttr(attrs.currentPage, requestedPage);
1598
+ this.updateVisibleRecords();
1599
+ }
1600
+ else {
1601
+ this.notifyGetDataAction(requestedPage);
1602
+ }
1603
+ }
1604
+ updateVisibleRecords() {
1605
+ let visibleRecords;
1606
+ if (this.clientPaging) {
1607
+ let filteredRecords = this.getFilteredRecords();
1608
+ this.setAttr(attrs.totalRecordsNumber, filteredRecords.length);
1609
+ const sliceNumber1 = (this.currentPage - 1) * this.recordsPerPage;
1610
+ const sliceNumber2 = (this.currentPage - 1) * this.recordsPerPage + this.recordsPerPage;
1611
+ visibleRecords = filteredRecords.slice(sliceNumber1, sliceNumber2);
1612
+ const recordsLastPage = this.totalRecordsNumber % this.recordsPerPage;
1613
+ const totalPages = Math.trunc(this.totalRecordsNumber / this.recordsPerPage + (recordsLastPage ? 1 : 0));
1614
+ if (this.currentPage > totalPages) {
1615
+ this.currentPage = totalPages || 1;
1616
+ }
1617
+ }
1618
+ else {
1619
+ visibleRecords = this.tableRecords;
1620
+ }
1621
+ this.setAttr(attrs.visibleRecords, visibleRecords);
1622
+ }
1623
+ updateFromServer(tableReceived) {
1624
+ this.requestedPage = 1;
1625
+ this.visible = (tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.visible) || true;
1626
+ this.totalPages = tableReceived.totalPages || 1;
1627
+ this.recordsNumber = tableReceived.recordsNumber;
1628
+ this.setAttr(attrs.currentPage, +(tableReceived === null || tableReceived === void 0 ? void 0 : tableReceived.currentPage) || 1);
1629
+ this.setAttr(attrs.recordsPerPage, +tableReceived.recordsPerPage);
1630
+ this.setAttr(attrs.totalRecordsNumber, (this.clientPaging) ? tableReceived.tableRecords.length : +tableReceived.totalRecordsNumber);
1631
+ this.setAttr(attrs.sorting, {
1632
+ columnName: tableReceived.sortingColumn || '',
1633
+ direction: tableReceived.sortingDirection || ''
1634
+ });
1635
+ this.waiting = false;
1636
+ if (!this._appendPages) {
1637
+ this.replaceRecords(tableReceived.tableRecords);
1638
+ }
1639
+ else {
1640
+ this.appendRecords(tableReceived.tableRecords);
1641
+ }
1642
+ this.updateVisibleRecords();
1643
+ }
1644
+ getTableRecord(recordId) {
1645
+ const recordIdKey = (typeof recordId === 'object') ? JSON.stringify(recordId) : recordId;
1646
+ return (this.tableRecordObj && recordId && this.tableRecordObj[recordId])
1647
+ ? this.tableRecordObj[recordId] : null;
1648
+ }
1649
+ getAction(actionCode) {
1650
+ return (this._actionsObj && actionCode && this._actionsObj[actionCode])
1651
+ ? this._actionsObj[actionCode] : null;
1652
+ }
1653
+ getActions(actionClass = this._formConfig.tableActions.inline, actionTypes = null) {
1654
+ return this._actions.filter(actionDef => {
1655
+ const typeIncluded = (actionTypes) ? actionTypes.includes(actionDef.actionType) : true;
1656
+ return actionDef.actionClass === actionClass && typeIncluded;
1657
+ });
1658
+ }
1659
+ // Filtros
1660
+ setFilterById(id) {
1661
+ if (this.restrictedId === id) {
1662
+ return;
1663
+ }
1664
+ this.restrictedId = id;
1665
+ this.updateVisibleRecords();
1666
+ }
1667
+ cleanIdFilter() {
1668
+ if (this.restrictedId === null) {
1669
+ return;
1670
+ }
1671
+ this.restrictedId = null;
1672
+ this.updateVisibleRecords();
1673
+ }
1674
+ setGlobalFilterString(text, notifyComponent = true) {
1675
+ var _a;
1676
+ this.globalFilterStrings = (_a = text.split(' ').filter(t => t && t.trim().length > 0).map(t => t.trim())) !== null && _a !== void 0 ? _a : [];
1677
+ if (this.clientPaging) {
1678
+ this.changePage(1);
1679
+ }
1680
+ if (notifyComponent) {
1681
+ this.setAttr(attrs.globalFilterString, text.trim());
1682
+ }
1683
+ }
1684
+ addFilterDefinition(columnName, filterDefinition) {
1685
+ const tableColumn = this.columnDefinition(columnName);
1686
+ tableColumn && tableColumn.addFilterDefinition(filterDefinition);
1687
+ }
1688
+ getFilteredRecords() {
1689
+ let filteredRecords = this.tableRecords;
1690
+ if (this.restrictedId) {
1691
+ filteredRecords = filteredRecords.filter(record => record.recordId === this.restrictedId);
1692
+ }
1693
+ if (this.globalFilterStrings.length > 0) {
1694
+ filteredRecords = filteredRecords.filter(record => record.hasPattern(this.globalFilterStrings, this._tableColumnObj));
1695
+ }
1696
+ const columnFilters = this.columns.filter(column => column.filter).map(column => column.filter);
1697
+ if (columnFilters.length > 0) {
1698
+ filteredRecords = filteredRecords.filter(record => record.hasCondition(columnFilters));
1699
+ }
1700
+ return filteredRecords;
1701
+ }
1702
+ getColumnFilter(columnName) {
1703
+ var _a;
1704
+ const tableColumn = this.columnDefinition(columnName);
1705
+ return (_a = tableColumn === null || tableColumn === void 0 ? void 0 : tableColumn.filter) !== null && _a !== void 0 ? _a : null;
1706
+ }
1707
+ addColumnFilter(columnName, columnValues, operator = null) {
1708
+ var _a;
1709
+ const tableColumn = this.columnDefinition(columnName);
1710
+ const columnFilterDefinition = (_a = tableColumn === null || tableColumn === void 0 ? void 0 : tableColumn.filterDefinition) !== null && _a !== void 0 ? _a : null;
1711
+ if (!columnFilterDefinition) {
1712
+ return;
1713
+ }
1714
+ tableColumn && tableColumn.addFilter(columnValues, operator);
1715
+ this.updateVisibleRecords();
1716
+ }
1717
+ removeColumnFilter(columnName) {
1718
+ const tableColumn = this.columnDefinition(columnName);
1719
+ tableColumn && tableColumn.removeFilter();
1720
+ this.updateVisibleRecords();
1721
+ }
1722
+ get currentFilter() {
1723
+ const compactFilter = {
1724
+ simpleFilterWords: this.globalFilterStrings,
1725
+ advancedFilter: [],
1726
+ };
1727
+ const columnFilters = this.columns.filter(column => column.filter).map(column => column.filter);
1728
+ for (let index = 0; index < columnFilters.length; index++) {
1729
+ const columnFilter = columnFilters[index];
1730
+ compactFilter.advancedFilter.push({
1731
+ fieldCode: columnFilter === null || columnFilter === void 0 ? void 0 : columnFilter.fieldCode,
1732
+ operator: columnFilter === null || columnFilter === void 0 ? void 0 : columnFilter.operator,
1733
+ fieldValue1: columnFilter === null || columnFilter === void 0 ? void 0 : columnFilter.values[0],
1734
+ fieldValue2: columnFilter === null || columnFilter === void 0 ? void 0 : columnFilter.values[1],
1735
+ });
1736
+ }
1737
+ return compactFilter;
1738
+ }
1739
+ // Ordenamiento de registros local
1740
+ sort(columnName, direction) {
1741
+ this.setRequiredOrder(columnName, direction);
1742
+ if (this.clientPaging) {
1743
+ this.localSortData();
1744
+ }
1745
+ else {
1746
+ this.notifyGetDataAction();
1747
+ }
1748
+ }
1749
+ setRequiredOrder(columnField, direction = null) {
1750
+ this.setAttr(attrs.sorting, {
1751
+ columnName: columnField,
1752
+ direction: (direction === 'ascend') ? TABLE_SORT_ASCENDING : TABLE_SORT_DESCENDING,
1753
+ });
1754
+ }
1755
+ localSortData() {
1756
+ if (!this.sorting.columnName || !this.sorting.direction) {
1757
+ return;
1758
+ }
1759
+ this.tableRecords.sort((a, b) => this.recordCompare(a, b, this.sorting.columnName, this.sorting.direction));
1760
+ //this.unSelectAll();
1761
+ this.updateVisibleRecords();
1762
+ }
1763
+ recordCompare(recordA, recordB, columnCompare, direction) {
1764
+ const recordAValue = recordA.getFieldValue(columnCompare);
1765
+ const recordBValue = recordB.getFieldValue(columnCompare);
1766
+ const recordAColumn = isNaN(recordAValue) ? recordAValue.toLocaleLowerCase() : +recordAValue;
1767
+ const recordBColumn = isNaN(recordBValue) ? recordBValue.toLocaleLowerCase() : +recordBValue;
1768
+ let result = 0;
1769
+ if (recordAColumn < recordBColumn) {
1770
+ result = -1;
1771
+ }
1772
+ else if (recordAColumn > recordBColumn) {
1773
+ result = 1;
1774
+ }
1775
+ return direction === TABLE_SORT_ASCENDING ? result : -result;
1776
+ }
1777
+ formStateChangeCustomSubscribe(formChangeSubject) {
1778
+ var _a, _b;
1779
+ (_a = this.columns) === null || _a === void 0 ? void 0 : _a.forEach(column => {
1780
+ column === null || column === void 0 ? void 0 : column.subscribeFormStateChange(formChangeSubject);
1781
+ });
1782
+ (_b = this._actions) === null || _b === void 0 ? void 0 : _b.forEach(action => {
1783
+ action === null || action === void 0 ? void 0 : action.subscribeFormStateChange(formChangeSubject);
1784
+ });
1785
+ }
1786
+ }
1787
+
1788
+ class RecordFormSubSection extends FormPiecePropagate {
1789
+ constructor(subsectionReceived, formObject, formConfig) {
1790
+ var _a, _b, _c;
1791
+ super(subsectionReceived, formConfig);
1792
+ this._customRender = null;
1793
+ this.subsectionId = null;
1794
+ this.subsectionCode = null;
1795
+ this.subsectionTitle = null;
1796
+ this.subSectionElements = [];
1797
+ this.subSectionFields = [];
1798
+ this.subSectionTables = [];
1799
+ this.subSectionActions = [];
1800
+ this.elementsArray = {};
1801
+ this.active = false;
1802
+ this.propagationCustomAttributes = (_c = (_b = (_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.propagationCustomAttributes) === null || _b === void 0 ? void 0 : _b.subsections) !== null && _c !== void 0 ? _c : [];
1803
+ if (!subsectionReceived) {
1804
+ return;
1805
+ }
1806
+ this.subsectionId = (subsectionReceived.subsectionId) ? subsectionReceived.subsectionId.toString() : '';
1807
+ this.subsectionCode = (subsectionReceived.subsectionCode) ? subsectionReceived.subsectionCode : '';
1808
+ this.subsectionTitle = (subsectionReceived.subsectionTitle) ? subsectionReceived.subsectionTitle : '';
1809
+ if (subsectionReceived.elements) {
1810
+ for (const receivedElement of subsectionReceived.elements) {
1811
+ let elementObject = null;
1812
+ let arrayToAdd = [];
1813
+ const { type, code } = receivedElement;
1814
+ switch (type) {
1815
+ case elementTypes.field:
1816
+ elementObject = formObject.getField(code);
1817
+ arrayToAdd = this.subSectionFields;
1818
+ break;
1819
+ case elementTypes.table:
1820
+ elementObject = formObject.getTable(code);
1821
+ arrayToAdd = this.subSectionTables;
1822
+ break;
1823
+ case elementTypes.action:
1824
+ elementObject = formObject.getAction(code);
1825
+ arrayToAdd = this.subSectionActions;
1826
+ break;
1827
+ }
1828
+ if (elementObject) {
1829
+ elementObject.elementType = type;
1830
+ arrayToAdd.push(elementObject);
1831
+ this.subSectionElements.push(elementObject);
1832
+ this.elementsArray[code] = elementObject;
1833
+ }
1834
+ }
1835
+ }
1836
+ }
1837
+ get customRender() { return this._customRender; }
1838
+ set customRender(customRenderName) { this._customRender = customRenderName; }
1839
+ getField(name) {
1840
+ return this.subSectionFields.find(fld => fld.name === name);
1841
+ }
1842
+ getFields() {
1843
+ return this.subSectionFields;
1844
+ }
1845
+ getFieldNames() {
1846
+ return this.subSectionFields.map(field => field.code);
1847
+ }
1848
+ getActions() {
1849
+ return this.subSectionActions;
1850
+ }
1851
+ getActionNames() {
1852
+ return this.subSectionActions.map(action => action.actionCode);
1853
+ }
1854
+ activate() {
1855
+ if (!this.active) {
1856
+ this.active = true;
1857
+ // this.subsectionCode && this._activation.next(this.subsectionCode);
1858
+ }
1859
+ }
1860
+ inactivate() {
1861
+ if (this.active) {
1862
+ this.active = false;
1863
+ // this.subsectionCode && this._inactivation.next(this.subsectionCode);
1864
+ }
1865
+ }
1866
+ }
1867
+
1868
+ const ACTIVE$1 = 'active';
1869
+ class RecordFormSection extends FormPiecePropagate {
1870
+ constructor(sectionReceived, formObject, formConfig) {
1871
+ var _a, _b, _c;
1872
+ super(sectionReceived, formConfig);
1873
+ this._activation = new Subject();
1874
+ this._inactivation = new Subject();
1875
+ this.active = false;
1876
+ this.sectionId = null;
1877
+ this.sectionCode = null;
1878
+ this.sectionTitle = null;
1879
+ this.subSections = [];
1880
+ this._exclusiveSubSectionsByAttr = {};
1881
+ this.propagationCustomAttributes = (_c = (_b = (_a = this._formConfig) === null || _a === void 0 ? void 0 : _a.propagationCustomAttributes) === null || _b === void 0 ? void 0 : _b.sections) !== null && _c !== void 0 ? _c : [];
1882
+ if (!sectionReceived) {
1883
+ return;
1884
+ }
1885
+ this.sectionId = (sectionReceived.sectionId) ? sectionReceived.sectionId.toString() : '';
1886
+ this.sectionCode = (sectionReceived.sectionCode) ? sectionReceived.sectionCode : '';
1887
+ this.sectionTitle = (sectionReceived.sectionTitle) ? sectionReceived.sectionTitle : '';
1888
+ this.subSections = [];
1889
+ this.subSectionsObj = {};
1890
+ if (sectionReceived.subsections) {
1891
+ const subsections = sectionReceived.subsections.map(subSecDef => {
1892
+ var _a;
1893
+ const visibleStates = (_a = subSecDef.visibleStates) !== null && _a !== void 0 ? _a : [];
1894
+ if (subSecDef.elements && Array.isArray(subSecDef.elements)) {
1895
+ subSecDef.elements = subSecDef.elements.map(elm => ({ code: elm.elementCode, type: elm.elementTypeName }));
1896
+ }
1897
+ return Object.assign(Object.assign({}, subSecDef), { visibleStates });
1898
+ });
1899
+ for (const subsectionReceived of subsections) {
1900
+ const subSectionToAdd = new RecordFormSubSection(subsectionReceived, formObject, formConfig);
1901
+ const subsectionCode = subSectionToAdd.subsectionCode;
1902
+ if (subsectionCode) {
1903
+ this.subSections.push(subSectionToAdd);
1904
+ this.subSectionsObj[subsectionCode] = subSectionToAdd;
1905
+ }
1906
+ }
1907
+ }
1908
+ }
1909
+ get code() { return this.sectionCode; }
1910
+ get activation() { return this._activation; }
1911
+ get inactivation() { return this._inactivation; }
1912
+ activate() {
1913
+ if (!this.active) {
1914
+ this.active = true;
1915
+ this.sectionCode && this._activation.next(this.sectionCode);
1916
+ }
1917
+ }
1918
+ inactivate() {
1919
+ if (this.active) {
1920
+ this.active = false;
1921
+ this.sectionCode && this._inactivation.next(this.sectionCode);
1922
+ }
1923
+ }
1924
+ get title() { return this.sectionTitle; }
1925
+ set title(title) { this.sectionTitle = title; }
1926
+ getVisibleSubsections(state) {
1927
+ return this.subSections.filter(subSection => subSection.visible);
1928
+ }
1929
+ getSubsection(subSectionCode) {
1930
+ return (this.subSectionsObj && this.subSectionsObj[subSectionCode])
1931
+ ? this.subSectionsObj[subSectionCode] : null;
1932
+ }
1933
+ activateSubSection(subSectionCode) {
1934
+ if (subSectionCode === this._exclusiveSubSectionsByAttr[ACTIVE$1]) {
1935
+ return;
1936
+ }
1937
+ const subSection = (this.subSectionsObj && this.subSectionsObj[subSectionCode])
1938
+ ? this.subSectionsObj[subSectionCode] : null;
1939
+ if (subSection) {
1940
+ subSection === null || subSection === void 0 ? void 0 : subSection.activate();
1941
+ this._exclusiveSubSectionsByAttr[ACTIVE$1] = subSectionCode;
1942
+ }
1943
+ }
1944
+ getFields() {
1945
+ var _a;
1946
+ let fieldsArray = [];
1947
+ if (this.subSections && this.subSections.length > 0) {
1948
+ for (const subSection of this.subSections) {
1949
+ const subsectionFields = (_a = subSection.getFields()) !== null && _a !== void 0 ? _a : [];
1950
+ if ((subsectionFields === null || subsectionFields === void 0 ? void 0 : subsectionFields.length) > 0) {
1951
+ fieldsArray = fieldsArray.concat(subsectionFields);
1952
+ }
1953
+ }
1954
+ }
1955
+ return fieldsArray;
1956
+ }
1957
+ getActions() {
1958
+ var _a;
1959
+ let actionArray = [];
1960
+ if (this.subSections && this.subSections.length > 0) {
1961
+ for (const subSection of this.subSections) {
1962
+ const subSectionActions = (_a = subSection.getActions()) !== null && _a !== void 0 ? _a : [];
1963
+ if ((subSectionActions === null || subSectionActions === void 0 ? void 0 : subSectionActions.length) > 0) {
1964
+ actionArray = actionArray.concat(subSectionActions);
1965
+ }
1966
+ }
1967
+ }
1968
+ return actionArray;
1969
+ }
1970
+ getActionNames() {
1971
+ let actionArray = [];
1972
+ if (this.subSections && this.subSections.length > 0) {
1973
+ for (const subSection of this.subSections) {
1974
+ actionArray = actionArray.concat(subSection.getActionNames());
1975
+ }
1976
+ }
1977
+ return actionArray;
1978
+ }
1979
+ getFieldNames() {
1980
+ let fieldsArray = [];
1981
+ if (this.subSections && this.subSections.length > 0) {
1982
+ for (const subSection of this.subSections) {
1983
+ fieldsArray = fieldsArray.concat(subSection.getFieldNames());
1984
+ }
1985
+ }
1986
+ return fieldsArray;
1987
+ }
1988
+ getField(name) {
1989
+ let field = null;
1990
+ if (this.subSections && this.subSections.length > 0) {
1991
+ for (const subSection of this.subSections) {
1992
+ field = subSection.getField(name);
1993
+ if (field) {
1994
+ return field;
1995
+ }
1996
+ }
1997
+ }
1998
+ return null;
1999
+ }
2000
+ formStateChangeCustomSubscribe(formChangeSubject) {
2001
+ var _a;
2002
+ (_a = this.subSections) === null || _a === void 0 ? void 0 : _a.forEach(subsection => {
2003
+ subsection === null || subsection === void 0 ? void 0 : subsection.subscribeFormStateChange(formChangeSubject);
2004
+ });
2005
+ }
2006
+ }
2007
+
2008
+ const ACTIVE = 'active';
2009
+ const SHOW = 'show';
2010
+ const HIDE = 'hide';
2011
+ const ENABLE = 'enable';
2012
+ const DISABLE = 'disable';
2013
+ const CLEAN = 'clean';
2014
+ class FormStructureAndData {
2015
+ constructor(definitionReceived, formConfig) {
2016
+ this._stateChange = new Subject();
2017
+ this._name = '';
2018
+ this._title = '';
2019
+ this._fields = {};
2020
+ this._actions = {};
2021
+ this._tables = {};
2022
+ this._sections = {};
2023
+ this._immutableData = {};
2024
+ this._extraInfo = {};
2025
+ this._exclusiveSectionsByAttr = {};
2026
+ this._formConfig = formConfig;
2027
+ this.state = '';
2028
+ this._actionArray = [];
2029
+ this._fieldArray = [];
2030
+ this._tableArray = [];
2031
+ this._sectionArray = [];
2032
+ this._stateFlow = {
2033
+ defaultState: '',
2034
+ states: [],
2035
+ transitions: [],
2036
+ };
2037
+ if (!definitionReceived) {
2038
+ return;
2039
+ }
2040
+ this._name = (definitionReceived.form && definitionReceived.form.formCode)
2041
+ ? definitionReceived.form.formCode : this._name;
2042
+ this._title = (definitionReceived.form && definitionReceived.form.formTitle)
2043
+ ? definitionReceived.form.formTitle : '';
2044
+ this.setStateFlow(definitionReceived === null || definitionReceived === void 0 ? void 0 : definitionReceived.states, definitionReceived === null || definitionReceived === void 0 ? void 0 : definitionReceived.transitions, definitionReceived === null || definitionReceived === void 0 ? void 0 : definitionReceived.defaultState);
2045
+ this.immutableData = definitionReceived.immutableData;
2046
+ this.extraInfo = definitionReceived.extraInfo;
2047
+ if (definitionReceived.actions) {
2048
+ const formActions = definitionReceived.actions.map(objDef => {
2049
+ var _a;
2050
+ let visibleStates = objDef.visibleStates;
2051
+ let enabledStates = (_a = objDef.enabledStates) !== null && _a !== void 0 ? _a : objDef.editableStates;
2052
+ if (!visibleStates) {
2053
+ visibleStates = (objDef.actionModes || '').split(',')
2054
+ .map(state => state.trim())
2055
+ .filter(state => state.length > 0) || [];
2056
+ enabledStates = [...visibleStates];
2057
+ }
2058
+ return Object.assign(Object.assign({}, objDef), { visibleStates, enabledStates });
2059
+ });
2060
+ for (const actionReceived of formActions) {
2061
+ const globalAction = new FormAction(actionReceived, this._formConfig);
2062
+ const globalActionCode = globalAction.actionCode;
2063
+ if (globalActionCode) {
2064
+ this._actionArray.push(globalAction);
2065
+ this._actions[globalActionCode] = globalAction;
2066
+ }
2067
+ }
2068
+ }
2069
+ if (definitionReceived.fields) {
2070
+ const formFields = definitionReceived.fields.map(objDef => {
2071
+ var _a;
2072
+ let visibleStates = objDef.visibleStates;
2073
+ let enabledStates = (_a = objDef.enabledStates) !== null && _a !== void 0 ? _a : objDef.editableStates;
2074
+ if (!visibleStates) {
2075
+ visibleStates = (objDef.fieldModes || '').split(',')
2076
+ .map(state => state.trim())
2077
+ .filter(state => state.length > 0) || [];
2078
+ enabledStates = [...visibleStates];
2079
+ }
2080
+ return Object.assign(Object.assign({}, objDef), { visibleStates, enabledStates });
2081
+ });
2082
+ for (const fieldReceived of formFields) {
2083
+ const fieldToAdd = new FieldDescriptor(fieldReceived, this._formConfig);
2084
+ const fieldCode = fieldToAdd.code;
2085
+ if (fieldCode) {
2086
+ this._fieldArray.push(fieldToAdd);
2087
+ this._fields[fieldCode] = fieldToAdd;
2088
+ }
2089
+ }
2090
+ }
2091
+ if (definitionReceived.tables) {
2092
+ const tables = definitionReceived.tables.map(objDef => {
2093
+ let visibleStates = objDef.visibleStates;
2094
+ let enabledStates = objDef.enabledStates || objDef.editableStates;
2095
+ if (!visibleStates) {
2096
+ visibleStates = (objDef.tableModes || '').split(',')
2097
+ .map(state => state.trim())
2098
+ .filter(state => state.length > 0) || [];
2099
+ enabledStates = [...visibleStates];
2100
+ }
2101
+ return Object.assign(Object.assign({}, objDef), { visibleStates, enabledStates });
2102
+ });
2103
+ for (const tableReceived of tables) {
2104
+ const tableToAdd = new RecordTable(tableReceived, this._formConfig);
2105
+ const tableCode = tableToAdd.tableCode;
2106
+ if (tableCode) {
2107
+ this._tableArray.push(tableToAdd);
2108
+ this._tables[tableCode] = tableToAdd;
2109
+ }
2110
+ }
2111
+ }
2112
+ if (definitionReceived.sections) {
2113
+ const formSections = definitionReceived.sections.map(objDef => {
2114
+ let visibleStates = objDef.visibleStates;
2115
+ if (!visibleStates) {
2116
+ visibleStates = (objDef.sectionModes || '').split(',')
2117
+ .map(state => state.trim())
2118
+ .filter(state => state.length > 0) || [];
2119
+ }
2120
+ return Object.assign(Object.assign({}, objDef), { visibleStates });
2121
+ });
2122
+ for (const sectionReceived of formSections) {
2123
+ const sectionToAdd = new RecordFormSection(sectionReceived, this, this._formConfig);
2124
+ const sectionCode = sectionToAdd.sectionCode;
2125
+ if (sectionCode) {
2126
+ this._sectionArray.push(sectionToAdd);
2127
+ this._sections[sectionCode] = sectionToAdd;
2128
+ }
2129
+ }
2130
+ }
2131
+ }
2132
+ getTitle() { return this._title; }
2133
+ setTitle(title) { this._title = title; }
2134
+ get name() { return this._name; }
2135
+ set name(name) { this._name = name; }
2136
+ // Estados
2137
+ get defaultState() { return this._stateFlow.defaultState; }
2138
+ supportState(state) { var _a; return (_a = this._stateFlow.states) === null || _a === void 0 ? void 0 : _a.includes(state); }
2139
+ supportMode(state) { return this.supportState(state); }
2140
+ get states() { return this._stateFlow.states; }
2141
+ getCurrentState() { return this.state; }
2142
+ changeState(newState) {
2143
+ if (!newState || !this.supportState(newState)) {
2144
+ return false;
2145
+ }
2146
+ if (!this.state) {
2147
+ this.state = newState;
2148
+ }
2149
+ else {
2150
+ const transitionToChange = this._stateFlow.transitions.find(trns => trns.source === this.state && trns.destination === newState);
2151
+ if (transitionToChange) {
2152
+ this.state = newState;
2153
+ }
2154
+ }
2155
+ this._stateChange.next({ state: this.state });
2156
+ return (this.state === newState);
2157
+ }
2158
+ get stateChange() { return this._stateChange; }
2159
+ setStateFlow(states, transitions, defaultState) {
2160
+ this._stateFlow.states = states;
2161
+ this._stateFlow.defaultState = defaultState || this._stateFlow.states[0];
2162
+ this._stateFlow.transitions = transitions.map(transition => {
2163
+ const name = transition.name;
2164
+ const source = (this._stateFlow.states.includes(transition.source)) ? transition.source : '';
2165
+ const destination = (this._stateFlow.states.includes(transition.destination)) ? transition.destination : '';
2166
+ return { name, source, destination };
2167
+ }).filter(item => item.name && item.source && item.destination);
2168
+ }
2169
+ // immutable Data
2170
+ getImmutableElement(name) { var _a, _b, _c; return (_c = (_b = (_a = this._immutableData) === null || _a === void 0 ? void 0 : _a[name]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : null; }
2171
+ set immutableData(immutableData) { Object.assign(this._immutableData, immutableData); }
2172
+ get immutableData() { return JSON.parse(JSON.stringify(this._immutableData)); }
2173
+ // extra Info
2174
+ getExtraInfo(name) { var _a, _b, _c; return (_c = (_b = (_a = this._extraInfo) === null || _a === void 0 ? void 0 : _a[name]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : null; }
2175
+ set extraInfo(extraInfo) { Object.assign(this._extraInfo, extraInfo); }
2176
+ get extraInfo() { return JSON.parse(JSON.stringify(this._extraInfo)); }
2177
+ // Fields
2178
+ get fields() { return this._fields; }
2179
+ get fieldNames() { return this.getFieldNames(); }
2180
+ getFields() { return this._fieldArray; }
2181
+ getFieldNames() { return this._fieldArray.map(field => field.code); }
2182
+ getField(code) { var _a; return (code && ((_a = this._fields) === null || _a === void 0 ? void 0 : _a[code])) ? this._fields[code] : null; }
2183
+ enableField(code) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.enable(); }
2184
+ disableField(code) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.disable(); }
2185
+ getFieldValue(code) { var _a; return (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.value; }
2186
+ getFieldOptionText(code) { var _a; return (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.optionText; }
2187
+ getFieldOptions(code) { var _a, _b; return (_b = (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.options) !== null && _b !== void 0 ? _b : null; }
2188
+ setFieldValue(code, value) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.setValue(value); }
2189
+ setFieldError(code, errorCode, message, type = 'error') { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.setError(errorCode, message, type); }
2190
+ setFieldIntrinsicErrorMessage(code, message) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.setIntrinsicErrorMessage(message); }
2191
+ setFieldRequired(inputCodes, required) {
2192
+ var _a;
2193
+ const codes = this.getFieldSet(null, inputCodes !== null && inputCodes !== void 0 ? inputCodes : null);
2194
+ for (const code of codes) {
2195
+ try {
2196
+ const field = (_a = this.getField(code)) !== null && _a !== void 0 ? _a : null;
2197
+ field && (field.required = required);
2198
+ }
2199
+ catch (e) {
2200
+ console.log(`Error modificando campo ${code}: ${e}`);
2201
+ }
2202
+ }
2203
+ }
2204
+ setFieldErrorMessage(code, message) { var _a; (_a = this.getField(code)) === null || _a === void 0 ? void 0 : _a.setErrorMessage(message); }
2205
+ setFieldOptions(code, optionsArray, idAttribute, nameAttribute) {
2206
+ const field = this.getField(code);
2207
+ if (field && (optionsArray === null || optionsArray === void 0 ? void 0 : optionsArray.length) > 0) {
2208
+ const fieldOptions = optionsArray.map(item => ({
2209
+ fieldOptionId: item[idAttribute],
2210
+ fieldOptionValue: item[nameAttribute]
2211
+ }));
2212
+ field.setFieldOptions(fieldOptions);
2213
+ }
2214
+ }
2215
+ getFieldSet(filter, inputCodes, secCode, subCode) {
2216
+ var _a, _b, _c, _d, _e;
2217
+ let codes = [];
2218
+ if (inputCodes) {
2219
+ if (typeof inputCodes === 'string') {
2220
+ codes = [inputCodes];
2221
+ }
2222
+ else if (Array.isArray(inputCodes) && inputCodes.length > 0) {
2223
+ codes = inputCodes !== null && inputCodes !== void 0 ? inputCodes : [];
2224
+ }
2225
+ }
2226
+ else if (secCode && !subCode) {
2227
+ codes = (_b = (_a = this.getSection(secCode)) === null || _a === void 0 ? void 0 : _a.getFieldNames()) !== null && _b !== void 0 ? _b : [];
2228
+ }
2229
+ else if (secCode && subCode) {
2230
+ codes = (_d = (_c = this.getSubSection(secCode, subCode)) === null || _c === void 0 ? void 0 : _c.getFieldNames()) !== null && _d !== void 0 ? _d : [];
2231
+ }
2232
+ else {
2233
+ codes = (_e = this.getFieldNames()) !== null && _e !== void 0 ? _e : [];
2234
+ }
2235
+ return (filter) ? codes.filter(fld => filter(this.getField(fld))) : codes;
2236
+ }
2237
+ applyOnFields(processFunc, inputCodes, secCode, subCode) {
2238
+ if (!processFunc) {
2239
+ return 0;
2240
+ }
2241
+ const codes = this.getFieldSet(null, inputCodes !== null && inputCodes !== void 0 ? inputCodes : null, secCode, subCode);
2242
+ let processedFields = 0;
2243
+ for (const code of codes) {
2244
+ const field = this.getField(code);
2245
+ if (field) {
2246
+ try {
2247
+ processFunc(field);
2248
+ processedFields += 1;
2249
+ }
2250
+ catch (e) {
2251
+ console.log(`Error procesando funcion en campo ${field}: ${e}`);
2252
+ }
2253
+ }
2254
+ }
2255
+ return processedFields;
2256
+ }
2257
+ enableFields(codes, secCode, subCode) {
2258
+ return this.applyOnFields(fld => fld === null || fld === void 0 ? void 0 : fld.enable(), codes, secCode, subCode);
2259
+ }
2260
+ showFields(codes, secCode, subCode) {
2261
+ return this.applyOnFields(fld => fld === null || fld === void 0 ? void 0 : fld.show(), codes, secCode, subCode);
2262
+ }
2263
+ hideFields(codes, secCode, subCode) {
2264
+ return this.applyOnFields(fld => fld === null || fld === void 0 ? void 0 : fld.hide(), codes, secCode, subCode);
2265
+ }
2266
+ showLabelFields(codes, secCode, subCode) {
2267
+ return this.applyOnFields(fld => fld === null || fld === void 0 ? void 0 : fld.showLablel(), codes, secCode, subCode);
2268
+ }
2269
+ hideLabelFields(codes, secCode, subCode) {
2270
+ return this.applyOnFields(fld => fld === null || fld === void 0 ? void 0 : fld.hideLabel(), codes, secCode, subCode);
2271
+ }
2272
+ disableFields(codes, secCode, subCode) {
2273
+ return this.applyOnFields(fld => fld === null || fld === void 0 ? void 0 : fld.disable(), codes, secCode, subCode);
2274
+ }
2275
+ cleanFields(codes, secCode, subCode) {
2276
+ return this.applyOnFields(fld => fld === null || fld === void 0 ? void 0 : fld.clean(), codes, secCode, subCode);
2277
+ }
2278
+ tagFieldsWithError(message, codes, secCode, subCode) {
2279
+ return this.applyOnFields(fld => fld === null || fld === void 0 ? void 0 : fld.setErrorMessage(message), codes, secCode, subCode);
2280
+ }
2281
+ cleanErrorFields(codes, secCode, subCode) {
2282
+ return this.tagFieldsWithError('', codes, secCode, subCode);
2283
+ }
2284
+ tagEmptyRequiredFields(message, codes = null, secCode, subCode) {
2285
+ return this.tagFieldsWithError(message, this.getRequiredEmptyFields(codes, secCode, subCode)) > 0;
2286
+ }
2287
+ getRequiredFields(codes, secCode, subCode) {
2288
+ return this.getFieldSet(fld => fld === null || fld === void 0 ? void 0 : fld.required, codes !== null && codes !== void 0 ? codes : null, secCode, subCode);
2289
+ }
2290
+ getRequiredEmptyFields(codes, secCode, subCode) {
2291
+ return this.getFieldSet(fld => (fld === null || fld === void 0 ? void 0 : fld.required) && (fld === null || fld === void 0 ? void 0 : fld.empty), codes !== null && codes !== void 0 ? codes : null, secCode, subCode);
2292
+ }
2293
+ getChangedFields(codes, secCode, subCode) {
2294
+ return this.getFieldSet(fld => !(fld === null || fld === void 0 ? void 0 : fld.outputOnly) && (fld === null || fld === void 0 ? void 0 : fld.hasChanged()), codes !== null && codes !== void 0 ? codes : null, secCode, subCode);
2295
+ }
2296
+ getFieldsWithValidationIssues(codes, secCode, subCode) {
2297
+ return this.getFieldSet(fld => fld === null || fld === void 0 ? void 0 : fld.hasError(), codes !== null && codes !== void 0 ? codes : null, secCode, subCode);
2298
+ }
2299
+ getFieldsValues(inputCodes, secCode, subCode) {
2300
+ var _a, _b, _c;
2301
+ const codes = this.getFieldSet(null, inputCodes !== null && inputCodes !== void 0 ? inputCodes : null, secCode, subCode);
2302
+ const resultObject = {};
2303
+ for (let index = 0; index < codes.length; index++) {
2304
+ const code = codes[index];
2305
+ if (code) {
2306
+ resultObject[code] = (_c = (_b = (_a = this._fields) === null || _a === void 0 ? void 0 : _a[code]) === null || _b === void 0 ? void 0 : _b.getValue()) !== null && _c !== void 0 ? _c : null;
2307
+ }
2308
+ }
2309
+ return resultObject;
2310
+ }
2311
+ // Acciones
2312
+ get actions() { return this._actions; }
2313
+ getActionsByAttribute(name, value) { return this._actionArray.filter(actionItem => actionItem.matchAttribute(name, value)); }
2314
+ getActions() { return this._actionArray; }
2315
+ getAction(code) { var _a; return (code && ((_a = this._actions) === null || _a === void 0 ? void 0 : _a[code])) ? this._actions[code] : null; }
2316
+ showActions(codes) { return this.execOnActions(codes, SHOW); }
2317
+ hideActions(codes) { return this.execOnActions(codes, HIDE); }
2318
+ enableActions(codes) { return this.execOnActions(codes, ENABLE); }
2319
+ disableActions(codes) { return this.execOnActions(codes, DISABLE); }
2320
+ execOnActions(codes, functionName) {
2321
+ const actionCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
2322
+ if (!functionName || actionCodes.length === 0) {
2323
+ return;
2324
+ }
2325
+ actionCodes.forEach(code => {
2326
+ var _a;
2327
+ const action = this.getAction(code);
2328
+ (_a = action === null || action === void 0 ? void 0 : action[functionName]) === null || _a === void 0 ? void 0 : _a.call(action);
2329
+ });
2330
+ }
2331
+ // Tablas
2332
+ get tables() { return this.tables; }
2333
+ getTables() { return this._tableArray; }
2334
+ getTable(code) { var _a; return (code && ((_a = this._tables) === null || _a === void 0 ? void 0 : _a[code])) ? this._tables[code] : null; }
2335
+ getTableRecord(code, id) { var _a; return (_a = this.getTable(code)) === null || _a === void 0 ? void 0 : _a.getTableRecord(id); }
2336
+ enableTables(codes) { return this.execOnTables(codes, ENABLE); }
2337
+ disableTables(codes) { return this.execOnTables(codes, DISABLE); }
2338
+ showTables(codes) { return this.execOnTables(codes, SHOW); }
2339
+ hideTables(codes) { return this.execOnTables(codes, HIDE); }
2340
+ cleanTables(codes) { return this.execOnTables(codes, CLEAN); }
2341
+ execOnTables(codes, functionName) {
2342
+ const tableCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
2343
+ if (!functionName || tableCodes.length === 0) {
2344
+ return;
2345
+ }
2346
+ tableCodes.forEach(code => {
2347
+ var _a;
2348
+ const table = this.getTable(code);
2349
+ (_a = table === null || table === void 0 ? void 0 : table[functionName]) === null || _a === void 0 ? void 0 : _a.call(table);
2350
+ });
2351
+ }
2352
+ // Secciones
2353
+ get sections() { return this._sections; }
2354
+ getSections() { return this._sectionArray; }
2355
+ getSectionsByAttribute(name, value) { return this._sectionArray.filter(item => item.matchAttribute(name, value)); }
2356
+ get sectionTitles() { return this._sectionArray.map(formSection => formSection.sectionTitle); }
2357
+ get visibleSections() { return this._sectionArray.filter(sec => sec.absoluteVisible); }
2358
+ getSection(code) { var _a; return (code && ((_a = this._sections) === null || _a === void 0 ? void 0 : _a[code])) ? this._sections[code] : null; }
2359
+ showSections(codes) { this.execOnSections(codes, SHOW); }
2360
+ hideSections(codes) { this.execOnSections(codes, HIDE); }
2361
+ activeSection() { return this._exclusiveSectionsByAttr[ACTIVE]; }
2362
+ getSubSection(code, subCode) { var _a, _b; return (_b = (_a = this.getSection(code)) === null || _a === void 0 ? void 0 : _a.getSubsection(subCode)) !== null && _b !== void 0 ? _b : null; }
2363
+ showSubSections(code, subCodes) { return this.execOnSubSections(code, subCodes, SHOW); }
2364
+ hideSubSections(code, subCodes) { return this.execOnSubSections(code, subCodes, HIDE); }
2365
+ getSectionActions(code) { var _a, _b; return (_b = (_a = this.getSection(code)) === null || _a === void 0 ? void 0 : _a.getActions()) !== null && _b !== void 0 ? _b : null; }
2366
+ getSectionActionNames(code) { var _a, _b; return (_b = (_a = this.getSection(code)) === null || _a === void 0 ? void 0 : _a.getActionNames()) !== null && _b !== void 0 ? _b : null; }
2367
+ activateSection(code) {
2368
+ var _a, _b;
2369
+ if (code === this._exclusiveSectionsByAttr[ACTIVE]) {
2370
+ return;
2371
+ }
2372
+ (_a = this.getSection(this.activeSection())) === null || _a === void 0 ? void 0 : _a.inactivate();
2373
+ (_b = this.getSection(code)) === null || _b === void 0 ? void 0 : _b.activate();
2374
+ this._exclusiveSectionsByAttr[ACTIVE] = code;
2375
+ }
2376
+ execOnSections(codes, functionName) {
2377
+ const sectionCodes = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
2378
+ if (!functionName || sectionCodes.length === 0) {
2379
+ return;
2380
+ }
2381
+ sectionCodes.forEach(code => {
2382
+ var _a;
2383
+ const section = this.getSection(code);
2384
+ (_a = section === null || section === void 0 ? void 0 : section[functionName]) === null || _a === void 0 ? void 0 : _a.call(section);
2385
+ });
2386
+ }
2387
+ execOnSubSections(code, subNames, functionName) {
2388
+ var _a;
2389
+ const subCodes = (Array.isArray(subNames)) ? subNames : (subNames ? [subNames] : []);
2390
+ const section = this.getSection(code);
2391
+ if (!functionName || !section || subCodes.length === 0) {
2392
+ return;
2393
+ }
2394
+ for (const subCode of subCodes) {
2395
+ const subSection = this.getSubSection(code, subCode);
2396
+ (_a = subSection === null || subSection === void 0 ? void 0 : subSection[functionName]) === null || _a === void 0 ? void 0 : _a.call(subSection);
2397
+ }
2398
+ }
2399
+ /**
2400
+ * Métodos propios de gestión del formulario
2401
+ */
2402
+ cleanData() {
2403
+ for (const field of this._fieldArray) {
2404
+ field.setValue(field.defaultValue);
2405
+ }
2406
+ for (const table of this._tableArray) {
2407
+ table.clean();
2408
+ }
2409
+ }
2410
+ getPayload() {
2411
+ const formData = {
2412
+ fields: [],
2413
+ tables: [],
2414
+ };
2415
+ formData.fields = this.getFields().filter(fld => !(fld === null || fld === void 0 ? void 0 : fld.outputOnly))
2416
+ .map(fld => {
2417
+ const fieldPayload = {
2418
+ fieldCode: fld === null || fld === void 0 ? void 0 : fld.code,
2419
+ fieldValue: fld === null || fld === void 0 ? void 0 : fld.value,
2420
+ editable: !(fld === null || fld === void 0 ? void 0 : fld.absoluteDisabled),
2421
+ visible: fld === null || fld === void 0 ? void 0 : fld.absoluteVisible,
2422
+ required: fld === null || fld === void 0 ? void 0 : fld.required,
2423
+ fieldOptions: '',
2424
+ };
2425
+ return fieldPayload;
2426
+ });
2427
+ formData.tables = this.getTables().map(tbl => {
2428
+ const tablePayload = {
2429
+ tableCode: tbl.tableCode,
2430
+ visible: tbl.absoluteVisible,
2431
+ currentPage: tbl.currentPage,
2432
+ requestedPage: tbl.requestedPage,
2433
+ recordsPerPage: tbl.recordsPerPage,
2434
+ currentFilter: tbl.currentFilter,
2435
+ sortingColumn: tbl.sorting.columnName,
2436
+ sortingDirection: tbl.sorting.direction,
2437
+ };
2438
+ return tablePayload;
2439
+ });
2440
+ return formData;
2441
+ }
2442
+ }
2443
+
2444
+ class LibFormManagerService {
2445
+ constructor() {
2446
+ this.cleanStack();
2447
+ }
2448
+ // Métodos virtuales para las aplicaciones
2449
+ getFormDefinition(formCode) { }
2450
+ execServerAction(actionDetail) { }
2451
+ goToForm(formCode, token, subject) { }
2452
+ loadStack() {
2453
+ return __awaiter(this, void 0, void 0, function* () { });
2454
+ }
2455
+ saveStack() { }
2456
+ cleanStack() { this.pageStack = []; }
2457
+ resetPageStack() { this.cleanStack(); }
2458
+ findFormInStack(token) {
2459
+ const index = this.pageStack.findIndex(item => (item === null || item === void 0 ? void 0 : item.token) === token);
2460
+ const data = (index >= 0) ? this.pageStack[index] : null;
2461
+ return { index, data };
2462
+ }
2463
+ replaceItem(token, formInfo) {
2464
+ var _a, _b, _c, _d;
2465
+ if (!token || !formInfo) {
2466
+ return;
2467
+ }
2468
+ const { index, data: storedForm } = this.findFormInStack(token);
2469
+ let updatedForm = null;
2470
+ if (index >= 0) {
2471
+ updatedForm = Object.assign({}, storedForm);
2472
+ updatedForm.subject = (_a = formInfo === null || formInfo === void 0 ? void 0 : formInfo.subject) !== null && _a !== void 0 ? _a : storedForm.subject;
2473
+ updatedForm.state = (_b = formInfo === null || formInfo === void 0 ? void 0 : formInfo.state) !== null && _b !== void 0 ? _b : storedForm.state;
2474
+ updatedForm.fields = (_c = storedForm === null || storedForm === void 0 ? void 0 : storedForm.fields) !== null && _c !== void 0 ? _c : {};
2475
+ updatedForm.extra = (_d = storedForm === null || storedForm === void 0 ? void 0 : storedForm.extra) !== null && _d !== void 0 ? _d : {};
2476
+ if (formInfo.fields) {
2477
+ Object.assign(updatedForm.fields, formInfo.fields);
2478
+ }
2479
+ if (formInfo.extra) {
2480
+ Object.assign(updatedForm.extra, formInfo.extra);
2481
+ }
2482
+ this.pageStack[index] = updatedForm;
2483
+ this.saveStack();
2484
+ }
2485
+ }
2486
+ stack(origin, target) {
2487
+ const token = nanoid(6);
2488
+ this.replaceItem(target.originToken, origin);
2489
+ this.pageStack.push(Object.assign({ token }, target));
2490
+ this.saveStack();
2491
+ return token;
2492
+ }
2493
+ unstack(token = null) {
2494
+ let index = (token) ? this.findFormInStack(token).index : this.pageStack.length - 2;
2495
+ let formInfo = null;
2496
+ if (index >= 0) {
2497
+ formInfo = this.pageStack[index];
2498
+ this.pageStack.splice(index + 1);
2499
+ this.saveStack();
2500
+ }
2501
+ return formInfo;
2502
+ }
2503
+ getFormInfo(token) {
2504
+ var _a, _b;
2505
+ const { data } = this.findFormInStack(token);
2506
+ return {
2507
+ token: data === null || data === void 0 ? void 0 : data.token,
2508
+ subject: data === null || data === void 0 ? void 0 : data.subject,
2509
+ state: data === null || data === void 0 ? void 0 : data.state,
2510
+ originToken: data === null || data === void 0 ? void 0 : data.originToken,
2511
+ fields: (_a = data === null || data === void 0 ? void 0 : data.fields) !== null && _a !== void 0 ? _a : {},
2512
+ extra: (_b = data === null || data === void 0 ? void 0 : data.extra) !== null && _b !== void 0 ? _b : {}
2513
+ };
2514
+ }
2515
+ openForm(origin, target) {
2516
+ var _a;
2517
+ (!origin) && this.cleanStack();
2518
+ target.originToken = (_a = origin === null || origin === void 0 ? void 0 : origin.token) !== null && _a !== void 0 ? _a : null;
2519
+ const token = this.stack(origin, target);
2520
+ this.goToForm(target.name, token, target.subject);
2521
+ }
2522
+ backTo(targetToken = null) {
2523
+ const formInfo = this.unstack(targetToken);
2524
+ formInfo && formInfo.name && this.goToForm(formInfo.name, formInfo.token, formInfo.subject);
2525
+ }
2526
+ }
2527
+
2528
+ class LibEventManagerService {
2529
+ constructor(eventNames) {
2530
+ this.eventSubjects = {};
2531
+ eventNames.forEach((name) => { this.addEventName(name); });
2532
+ }
2533
+ addEventName(name) {
2534
+ if (!this.eventSubjects[name]) {
2535
+ const newEventSubject = new ReplaySubject(1);
2536
+ this.eventSubjects[name] = newEventSubject;
2537
+ }
2538
+ }
2539
+ getEventNames() { return Object.keys(this.eventSubjects); }
2540
+ getSubject(eventClassName) { return eventClassName ? this.eventSubjects[eventClassName] : null; }
2541
+ subscribe(eventClassName, callback) { this.getSubject(eventClassName).subscribe(callback); }
2542
+ next(eventClassName, data) { this.getSubject(eventClassName).next(data); }
2543
+ }
2544
+
2545
+ class LibFileManagementService {
2546
+ openFile(fileBase64Data, fileName, fileType) { }
2547
+ saveFileFromURL(fileUrl, fullFileName = null) { }
2548
+ saveFile(fileBase64Data, fileName, fileType) { }
2549
+ }
2550
+
2551
+ const PAYLOAD_VERSION = 'TUAINEXCHANGE_1.0';
2552
+ const INLINE_ACTION = 'INLINE';
2553
+ const GLOBAL_ACTION = 'GLOBAL';
2554
+ const GET_DATA_ACTION = 'GETDATA';
2555
+ const SUBJECT = 'subject';
2556
+ const TOKEN = 'token';
2557
+ class BasicFormComponent {
2558
+ constructor(formManagerService, _eventManager, fileMgmtServices) {
2559
+ this.formManagerService = formManagerService;
2560
+ this._eventManager = _eventManager;
2561
+ this.fileMgmtServices = fileMgmtServices;
2562
+ this._formStructure = null;
2563
+ this._controlToken = null;
2564
+ this._originToken = null;
2565
+ this._formRoute = null;
2566
+ this._definitionObtained = false;
2567
+ // Eventos de acciones y campos
2568
+ this._formChangeState = [];
2569
+ this._formSectionsCanDeactivate = {};
2570
+ this._formSectionsActivate = {};
2571
+ this._formSectionsInactivate = {};
2572
+ this._formActionsStart = {};
2573
+ this._formActionsFinish = {};
2574
+ this._fieldInputValidation = {};
2575
+ this._fieldValidationsStart = {};
2576
+ this._fieldValidationsFinish = {};
2577
+ // Callback de acciones de tablas
2578
+ this._tableSelectionsStart = {};
2579
+ this._tableSelectionsFinish = {};
2580
+ this._tableActionsStart = {};
2581
+ this._tableActionsFinish = {};
2582
+ this._tableGetDataStart = {};
2583
+ this._tableGetDataFinish = {};
2584
+ this._actionServerError = [];
2585
+ this._fieldServerError = [];
2586
+ this._tableServerError = [];
2587
+ this.inputDataFields = {};
2588
+ this.extraData = {};
2589
+ this.enabledSections = [];
2590
+ this.name = null;
2591
+ this.formSubject = null;
2592
+ this._errorType = '';
2593
+ this.errorCode = '';
2594
+ this.errorFullCode = '';
2595
+ this.errorName = '';
2596
+ this.errorMessage = '';
2597
+ this.errorDetail = '';
2598
+ this.visible = false;
2599
+ this.busy = false;
2600
+ this._eventEmiter = this._eventManager;
2601
+ this.cleanStart();
2602
+ this.customPreProcessing();
2603
+ }
2604
+ get title() { var _a; return (_a = this.getTitle()) !== null && _a !== void 0 ? _a : ''; }
2605
+ set title(title) { this.setTitle(title); }
2606
+ getTitle() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getTitle(); }
2607
+ setTitle(title) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setTitle(title); }
2608
+ cleanData() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.cleanData(); }
2609
+ getCurrentState() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getCurrentState(); }
2610
+ supportState(state) { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.supportState(state !== null && state !== void 0 ? state : '')) !== null && _b !== void 0 ? _b : false; }
2611
+ getStates() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.states; }
2612
+ getImmutableElement(name) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getImmutableElement(name); }
2613
+ getExtraInfo(name) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getExtraInfo(name); }
2614
+ getFields() { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFields()) !== null && _b !== void 0 ? _b : null; }
2615
+ getFieldNames() { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldNames()) !== null && _b !== void 0 ? _b : null; }
2616
+ getField(code) { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getField(code)) !== null && _b !== void 0 ? _b : null; }
2617
+ enableField(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.enableField(code); }
2618
+ disableField(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.disableField(code); }
2619
+ getFieldValue(code) { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldValue(code)) !== null && _b !== void 0 ? _b : null; }
2620
+ getFieldOptionText(code) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldOptionText(code); }
2621
+ getFieldsValues(codes) { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldsValues(codes)) !== null && _b !== void 0 ? _b : null; }
2622
+ getFieldOptions(code) { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldOptions(code)) !== null && _b !== void 0 ? _b : null; }
2623
+ setFieldValue(code, value) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldValue(code, value); }
2624
+ setFieldRequired(inputCodes, required) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldRequired(inputCodes, required); }
2625
+ setFieldErrorMessage(code, errorMessage) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldErrorMessage(code, errorMessage); }
2626
+ setFieldError(code, errorCode, message, type) { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldError(code, errorCode, message, type); }
2627
+ setFieldIntrinsicErrorMessage(code, message) {
2628
+ var _a;
2629
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldIntrinsicErrorMessage(code, message);
2630
+ }
2631
+ setFieldOptions(code, optionsArray, idAttribute, nameAttribute) {
2632
+ var _a;
2633
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.setFieldOptions(code, optionsArray, idAttribute, nameAttribute);
2634
+ }
2635
+ getFieldSet(filterFunc, codes, secCode, subCode) {
2636
+ var _a;
2637
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldSet(filterFunc, codes !== null && codes !== void 0 ? codes : null, secCode !== null && secCode !== void 0 ? secCode : null, subCode !== null && subCode !== void 0 ? subCode : null);
2638
+ }
2639
+ applyOnFields(processFunc, codes, secCode, subCode) {
2640
+ var _a;
2641
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.applyOnFields(processFunc, codes, secCode, subCode);
2642
+ }
2643
+ applyProcessToAllFields(processFunc) {
2644
+ var _a;
2645
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.applyOnFields(processFunc);
2646
+ }
2647
+ cleanFields(codes, secCode, subCode) {
2648
+ var _a;
2649
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.cleanFields(codes, secCode, subCode);
2650
+ }
2651
+ getRequiredFields(codes, secCode, subCode) {
2652
+ var _a;
2653
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getRequiredFields(codes, secCode, subCode);
2654
+ }
2655
+ getRequiredEmptyFields(codes, secCode, subCode) {
2656
+ var _a, _b;
2657
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getRequiredEmptyFields(codes, secCode, subCode)) !== null && _b !== void 0 ? _b : null;
2658
+ }
2659
+ getChangedFields(codes, secCode, subCode) {
2660
+ var _a;
2661
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getChangedFields(codes, secCode, subCode);
2662
+ }
2663
+ getFieldsWithValidationIssues(codes, secCode, subCode) {
2664
+ var _a;
2665
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFieldsWithValidationIssues(codes, secCode, subCode);
2666
+ }
2667
+ tagFieldsWithError(errorMessage, codes, secCode, subCode) {
2668
+ var _a;
2669
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.tagFieldsWithError(errorMessage, codes, secCode, subCode);
2670
+ }
2671
+ cleanErrorFields(codes, secCode, subCode) {
2672
+ var _a;
2673
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.cleanErrorFields(codes, secCode, subCode);
2674
+ }
2675
+ showLabelFields(codes, secCode, subCode) {
2676
+ var _a;
2677
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showLabelFields(codes, secCode, subCode);
2678
+ }
2679
+ hideLabelFields(codes, secCode, subCode) {
2680
+ var _a;
2681
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideLabelFields(codes, secCode, subCode);
2682
+ }
2683
+ enableFields(codes, secCode, subCode) {
2684
+ var _a;
2685
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.enableFields(codes, secCode, subCode);
2686
+ }
2687
+ disableFields(codes, secCode, subCode) {
2688
+ var _a;
2689
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.disableFields(codes, secCode, subCode);
2690
+ }
2691
+ /**
2692
+ * @deprecated Use enableFields
2693
+ */
2694
+ enableEditFields(codes, secCode, subCode) {
2695
+ return this.enableFields(codes, secCode, subCode);
2696
+ }
2697
+ /**
2698
+ * @deprecated Use disableFields
2699
+ */
2700
+ disableEditFields(codes, secCode, subCode) {
2701
+ return this.disableFields(codes, secCode, subCode);
2702
+ }
2703
+ showFields(codes, secCode, subCode) {
2704
+ var _a;
2705
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showFields(codes, secCode, subCode);
2706
+ }
2707
+ hideFields(codes, secCode, subCode) {
2708
+ var _a;
2709
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideFields(codes, secCode, subCode);
2710
+ }
2711
+ getActionsByAttribute(name, value) {
2712
+ var _a;
2713
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getActionsByAttribute(name, value);
2714
+ }
2715
+ getHeaderActions() {
2716
+ var _a;
2717
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getActionsByAttribute('location', HEADER$1);
2718
+ }
2719
+ getAction(actionCode) {
2720
+ var _a, _b;
2721
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getAction(actionCode)) !== null && _b !== void 0 ? _b : null;
2722
+ }
2723
+ showActions(actionArray) {
2724
+ var _a;
2725
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showActions(actionArray);
2726
+ }
2727
+ hideActions(actionArray) {
2728
+ var _a;
2729
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideActions(actionArray);
2730
+ }
2731
+ enableActions(actionArray) {
2732
+ var _a;
2733
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.enableActions(actionArray);
2734
+ }
2735
+ disableActions(actionArray) {
2736
+ var _a;
2737
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.disableActions(actionArray);
2738
+ }
2739
+ showAction(code) {
2740
+ var _a;
2741
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showActions(code);
2742
+ }
2743
+ hideAction(code) {
2744
+ var _a;
2745
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideActions(code);
2746
+ }
2747
+ enableAction(code) {
2748
+ var _a;
2749
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.enableActions(code);
2750
+ }
2751
+ disableAction(code) {
2752
+ var _a;
2753
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.disableActions(code);
2754
+ }
2755
+ getSections() {
2756
+ var _a, _b;
2757
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSections()) !== null && _b !== void 0 ? _b : null;
2758
+ }
2759
+ activateSection(code) {
2760
+ var _a;
2761
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.activateSection(code);
2762
+ }
2763
+ getSectionsTitles() {
2764
+ var _a, _b;
2765
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSections().map(sec => sec.title)) !== null && _b !== void 0 ? _b : null;
2766
+ }
2767
+ getSection(code) {
2768
+ var _a, _b;
2769
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSection(code)) !== null && _b !== void 0 ? _b : null;
2770
+ }
2771
+ showSection(code) {
2772
+ var _a;
2773
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showSections(code);
2774
+ }
2775
+ hideSection(code) {
2776
+ var _a;
2777
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideSections(code);
2778
+ }
2779
+ showSections(codes) {
2780
+ var _a;
2781
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showSections(codes);
2782
+ }
2783
+ hideSections(codes) {
2784
+ var _a;
2785
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideSections(codes);
2786
+ }
2787
+ getSubSection(code, subCode) {
2788
+ var _a, _b;
2789
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSubSection(code, subCode)) !== null && _b !== void 0 ? _b : null;
2790
+ }
2791
+ showSubSection(code, subCode) {
2792
+ var _a;
2793
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showSubSections(code, subCode);
2794
+ }
2795
+ hideSubSection(code, subCode) {
2796
+ var _a;
2797
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideSubSections(code, subCode);
2798
+ }
2799
+ showSubSections(code, subCodes) {
2800
+ var _a;
2801
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showSubSections(code, subCodes);
2802
+ }
2803
+ hideSubSections(code, subCodes) {
2804
+ var _a;
2805
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideSubSections(code, subCodes);
2806
+ }
2807
+ getSectionActions(code) {
2808
+ var _a, _b;
2809
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSectionActions(code)) !== null && _b !== void 0 ? _b : null;
2810
+ }
2811
+ getSectionActionNames(code) {
2812
+ var _a, _b;
2813
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSectionActionNames(code)) !== null && _b !== void 0 ? _b : null;
2814
+ }
2815
+ getTables() {
2816
+ var _a;
2817
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getTables();
2818
+ }
2819
+ showTables(codes) {
2820
+ var _a;
2821
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showTables(codes);
2822
+ }
2823
+ hideTables(codes) {
2824
+ var _a;
2825
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideTables(codes);
2826
+ }
2827
+ cleanTables(codes) {
2828
+ var _a;
2829
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.cleanTables(codes);
2830
+ }
2831
+ getTable(code) {
2832
+ var _a, _b;
2833
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getTable(code)) !== null && _b !== void 0 ? _b : null;
2834
+ }
2835
+ showTable(code) {
2836
+ var _a;
2837
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.showTables(code);
2838
+ }
2839
+ hideTable(code) {
2840
+ var _a;
2841
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.hideTables(code);
2842
+ }
2843
+ cleanTable(code) {
2844
+ var _a, _b;
2845
+ return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getTable(code)) === null || _b === void 0 ? void 0 : _b.clean();
2846
+ }
2847
+ getTableRecord(code, recordId) {
2848
+ var _a;
2849
+ return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getTableRecord(code, recordId);
2850
+ }
2851
+ setConfig(formConfig) {
2852
+ this.formConfig = formConfig;
2853
+ }
2854
+ cleanStart() {
2855
+ this._errorType = '';
2856
+ this.errorCode = '';
2857
+ this.errorFullCode = '';
2858
+ this.errorName = '';
2859
+ this.errorMessage = '';
2860
+ this.errorDetail = '';
2861
+ this._formStructure = null;
2862
+ this.fields = null;
2863
+ this.actions = null;
2864
+ this.sections = null;
2865
+ this._controlToken = null;
2866
+ this.inputDataFields = {};
2867
+ this._definitionObtained = false;
2868
+ // Se limpian los manejadores de eventos
2869
+ this.visible = false;
2870
+ this.busy = false;
2871
+ this._formChangeState = [];
2872
+ this._formSectionsCanDeactivate = {};
2873
+ this._formSectionsActivate = {};
2874
+ this._formSectionsInactivate = {};
2875
+ this._formActionsStart = {};
2876
+ this._formActionsFinish = {};
2877
+ this._fieldInputValidation = {};
2878
+ this._fieldValidationsStart = {};
2879
+ this._fieldValidationsFinish = {};
2880
+ this._tableSelectionsStart = {};
2881
+ this._tableSelectionsFinish = {};
2882
+ this._tableActionsStart = {};
2883
+ this._tableActionsFinish = {};
2884
+ this._tableGetDataStart = {};
2885
+ this._tableGetDataFinish = {};
2886
+ this._actionServerError = [];
2887
+ this._fieldServerError = [];
2888
+ this._tableServerError = [];
2889
+ this.onActionServerError(() => this.displayActionServerError());
2890
+ this.onValidationServerError(() => this.displayValidationServerError());
2891
+ this.onTableServerError(() => this.displayTableServerError());
2892
+ }
2893
+ get formVisible() { return this.visible; }
2894
+ get formManager() { return this; }
2895
+ get formCode() { var _a; return (_a = this.name) !== null && _a !== void 0 ? _a : ''; }
2896
+ set formCode(name) { this.name = name; }
2897
+ get inServerProcess() { return this.busy; }
2898
+ get form() { return this._formStructure; }
2899
+ get state() { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.state) !== null && _b !== void 0 ? _b : null; }
2900
+ get currentState() { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.state) !== null && _b !== void 0 ? _b : ''; }
2901
+ set currentState(state) { this === null || this === void 0 ? void 0 : this.changeState(state); }
2902
+ get immutableData() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.immutableData; }
2903
+ get extraInfo() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.extraInfo; }
2904
+ get visibleSections() { var _a, _b; return (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.visibleSections) !== null && _b !== void 0 ? _b : null; }
2905
+ get formRoute() { var _a; return (_a = this._formRoute) !== null && _a !== void 0 ? _a : ''; }
2906
+ set formRoute(route) { this._formRoute = route; }
2907
+ get subject() { var _a; return (_a = this.formSubject) !== null && _a !== void 0 ? _a : ''; }
2908
+ // Métodos virtuales
2909
+ customPreProcessing() { }
2910
+ start() { }
2911
+ customFormStart() { }
2912
+ displayActionServerError() { }
2913
+ displayValidationServerError() { }
2914
+ displayTableServerError() { }
2915
+ showFieldInfo(code, detail) { }
2916
+ showModalDialog(title, body, options, callback, params) { }
2917
+ openUploadDialog(title, body, options, callback, params) { }
2918
+ /**
2919
+ * @deprecated Use supportState
2920
+ */
2921
+ supportMode(state) { return this.supportState(state); }
2922
+ /**
2923
+ * @deprecated Use getField
2924
+ */
2925
+ getFieldObject(code) { return this.getField(code); }
2926
+ /**
2927
+ * @deprecated Use getAction
2928
+ */
2929
+ getActionObject(code) { return this.getAction(code); }
2930
+ /**
2931
+ * @deprecated Use getTable
2932
+ */
2933
+ getTableObject(code) { return this.getTable(code); }
2934
+ /**
2935
+ * @deprecated Use getSection
2936
+ */
2937
+ getSectionObject(code) { return this.getSection(code); }
2938
+ /**
2939
+ * @deprecated Use changeState
2940
+ */
2941
+ changeFormMode(state) { return this.changeState(state); }
2942
+ /**
2943
+ * @deprecated Use subject
2944
+ */
2945
+ getFormSubject() { return this.subject; }
2946
+ /**
2947
+ * @deprecated Use subject
2948
+ */
2949
+ getSubject() { var _a; return (_a = this.formSubject) !== null && _a !== void 0 ? _a : ''; }
2950
+ /**
2951
+ * @deprecated Use subject
2952
+ */
2953
+ getformSubject() { var _a; return (_a = this.formSubject) !== null && _a !== void 0 ? _a : ''; }
2954
+ numSections() { var _a; return (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.sections.length; }
2955
+ subscribeAppEvent(eventName, callback) {
2956
+ this._eventEmiter.subscribe(eventName, callback);
2957
+ }
2958
+ openForm(name, data = null, backData = null, cleanStack = false) {
2959
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2960
+ let origin = null;
2961
+ if (!cleanStack) {
2962
+ origin = Object.assign(Object.assign({}, backData), { name: this.name, url: this._formRoute, token: this._controlToken });
2963
+ origin.subject = (_a = origin === null || origin === void 0 ? void 0 : origin.subject) !== null && _a !== void 0 ? _a : this.formSubject;
2964
+ origin.state = (_b = origin === null || origin === void 0 ? void 0 : origin.state) !== null && _b !== void 0 ? _b : this.state;
2965
+ origin.fields = (_c = origin === null || origin === void 0 ? void 0 : origin.fields) !== null && _c !== void 0 ? _c : {};
2966
+ origin.extra = (_d = origin === null || origin === void 0 ? void 0 : origin.extra) !== null && _d !== void 0 ? _d : {};
2967
+ }
2968
+ const target = Object.assign(Object.assign({}, data), { name });
2969
+ target.subject = (_e = target === null || target === void 0 ? void 0 : target.subject) !== null && _e !== void 0 ? _e : null;
2970
+ target.state = (_f = target === null || target === void 0 ? void 0 : target.state) !== null && _f !== void 0 ? _f : null;
2971
+ target.fields = (_g = target === null || target === void 0 ? void 0 : target.fields) !== null && _g !== void 0 ? _g : {};
2972
+ target.extra = (_h = target === null || target === void 0 ? void 0 : target.extra) !== null && _h !== void 0 ? _h : {};
2973
+ this.formManagerService.openForm(origin, target);
2974
+ }
2975
+ canGoBack() { return this._originToken !== null; }
2976
+ goBack() { return this.formManagerService.backTo(); }
2977
+ goBackForm() { return this.goBack(); }
2978
+ getOriginDetail() { var _a, _b; return (_a = this.formManagerService) === null || _a === void 0 ? void 0 : _a.getFormInfo((_b = this._originToken) !== null && _b !== void 0 ? _b : ''); }
2979
+ setError(errorType, errorMessage, errorDetail) {
2980
+ this._errorType = errorType || '';
2981
+ this.errorMessage = errorMessage || '';
2982
+ this.errorDetail = errorDetail || '';
2983
+ }
2984
+ resetError() {
2985
+ this.errorCode = NO_ERROR;
2986
+ this.errorFullCode = '';
2987
+ this.errorName = '';
2988
+ this.errorMessage = '';
2989
+ this.errorDetail = '';
2990
+ }
2991
+ getErrorType() { return this._errorType; }
2992
+ getErrorMessage() { return this.errorMessage; }
2993
+ getErrorDetail() { return this.errorDetail; }
2994
+ getErrorName() { return this.errorName; }
2995
+ getErrorFullCode() { return this.errorFullCode; }
2996
+ getErrorCode() { return this.errorCode; }
2997
+ getFormParameter(name) {
2998
+ var _a, _b;
2999
+ return (name) ? ((_b = (_a = this.extraData) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : null) : null;
3000
+ }
3001
+ preocessInputParams(params) {
3002
+ var _a, _b, _c, _d;
3003
+ this._controlToken = (_a = params === null || params === void 0 ? void 0 : params[TOKEN]) !== null && _a !== void 0 ? _a : null;
3004
+ this.formSubject = (_b = params === null || params === void 0 ? void 0 : params[SUBJECT]) !== null && _b !== void 0 ? _b : null;
3005
+ const tokenInfo = (this._controlToken) ? this.formManagerService.getFormInfo(this._controlToken) : {};
3006
+ const { token, subject, state, fields, extra, originToken } = tokenInfo;
3007
+ if (token && this._controlToken === token) {
3008
+ this.formSubject = (_d = (_c = this.formSubject) !== null && _c !== void 0 ? _c : subject) !== null && _d !== void 0 ? _d : null;
3009
+ this.inputDataFields = fields;
3010
+ this.extraData = extra;
3011
+ this._originToken = originToken;
3012
+ return state;
3013
+ }
3014
+ return null;
3015
+ }
3016
+ subscribeSectionActivation() {
3017
+ var _a, _b;
3018
+ const formSections = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.sections;
3019
+ const sectionNames = Object.keys(formSections);
3020
+ for (let index = 0; index < sectionNames.length; index++) {
3021
+ const sectionName = sectionNames[index];
3022
+ const section = formSections[sectionName];
3023
+ section.activation.subscribe((code) => this.launchSectionActivation(code));
3024
+ section.inactivation.subscribe((code) => this.launchSectionInactivation(code));
3025
+ // Adicionalmente se le pide a la sección se subscriba al cambio de estado del formulario
3026
+ section.subscribeFormStateChange((_b = this._formStructure) === null || _b === void 0 ? void 0 : _b.stateChange);
3027
+ }
3028
+ }
3029
+ subscribeFieldsSubjects() {
3030
+ var _a;
3031
+ const formFields = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getFields();
3032
+ if (Array.isArray(formFields)) {
3033
+ formFields.forEach(field => {
3034
+ var _a;
3035
+ field.editionFinish.subscribe(event => {
3036
+ const { code, intrinsicValidation } = event;
3037
+ this.startFieldValidation(code, intrinsicValidation);
3038
+ });
3039
+ field.editionPartial.subscribe(event => {
3040
+ const { code, intrinsicValidation } = event;
3041
+ this.startFieldInputValidation(code, intrinsicValidation);
3042
+ });
3043
+ field.detailRequest.subscribe(event => this.showFieldInfo(event.code, event.detail));
3044
+ // Adicionalmente se le pide al campo se subscriba al cambio de estado del formulario
3045
+ field.subscribeFormStateChange((_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.stateChange);
3046
+ });
3047
+ }
3048
+ }
3049
+ subscribeActionSubjects() {
3050
+ var _a;
3051
+ const formActions = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getActions();
3052
+ if (Array.isArray(formActions)) {
3053
+ formActions.forEach(action => {
3054
+ var _a;
3055
+ action.actionActivated.subscribe(code => this.startAction(code));
3056
+ // Adicionalmente se le pide a la acción se subscriba al cambio de estado del formulario
3057
+ action.subscribeFormStateChange((_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.stateChange);
3058
+ });
3059
+ }
3060
+ }
3061
+ subscribeTableSubjects() {
3062
+ var _a;
3063
+ const formTables = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getTables();
3064
+ if (Array.isArray(formTables)) {
3065
+ formTables.forEach(table => {
3066
+ var _a;
3067
+ table.inlineActionTrigger.subscribe(event => this.startTableAction(event));
3068
+ table.globalActionTrigger.subscribe(event => this.startTableGlobalAction(event));
3069
+ table.recordSelectionTrigger.subscribe(event => this.startTableRecordSelection(event));
3070
+ table.selectionActionTrigger.subscribe(event => this.startTableSelectionAction(event));
3071
+ table.getDataTrigger.subscribe(event => this.startTableGetData(event));
3072
+ // Adicionalmente se le pide a la tabla se subscriba al cambio de estado del formulario
3073
+ table.subscribeFormStateChange((_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.stateChange);
3074
+ });
3075
+ }
3076
+ }
3077
+ formInit(params, forceReload = false) {
3078
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3079
+ return __awaiter(this, void 0, void 0, function* () {
3080
+ let initialState = this.preocessInputParams(params);
3081
+ if (!this.name) {
3082
+ return;
3083
+ }
3084
+ if (forceReload || !this._definitionObtained) {
3085
+ this.busy = true;
3086
+ const formDefinition = yield this.formManagerService.getFormDefinition(this.name);
3087
+ this.busy = false;
3088
+ this._formStructure = new FormStructureAndData(formDefinition, this.formConfig);
3089
+ this.fields = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.fields;
3090
+ this.actions = (_b = this._formStructure) === null || _b === void 0 ? void 0 : _b.actions;
3091
+ this.sections = (_c = this._formStructure) === null || _c === void 0 ? void 0 : _c.sections;
3092
+ this._definitionObtained = true;
3093
+ }
3094
+ else {
3095
+ this.cleanData();
3096
+ }
3097
+ if (!this.supportState(initialState)) {
3098
+ initialState = (_e = (_d = this._formStructure) === null || _d === void 0 ? void 0 : _d.defaultState) !== null && _e !== void 0 ? _e : null;
3099
+ }
3100
+ const inputFieldNames = Object.keys(this.inputDataFields);
3101
+ for (let index = 0; index < inputFieldNames.length; index++) {
3102
+ const code = inputFieldNames[index];
3103
+ const fieldValue = this.inputDataFields[code];
3104
+ this.setFieldValue(code, fieldValue);
3105
+ }
3106
+ this.subscribeSectionActivation();
3107
+ this.subscribeFieldsSubjects();
3108
+ this.subscribeActionSubjects();
3109
+ this.subscribeTableSubjects();
3110
+ // Se define el estado inicial y se solicita la acción inicial
3111
+ this.changeState(initialState || ((_f = this._formStructure) === null || _f === void 0 ? void 0 : _f.defaultState));
3112
+ const recordResponse = yield this.requestFormAction(formActions.getData);
3113
+ this.checkErrorRecordReceived(recordResponse);
3114
+ this.visible = true;
3115
+ this.enabledSections = (_h = (_g = this._formStructure) === null || _g === void 0 ? void 0 : _g.visibleSections) !== null && _h !== void 0 ? _h : [];
3116
+ this.start();
3117
+ this.customFormStart();
3118
+ });
3119
+ }
3120
+ changeState(state) {
3121
+ var _a, _b;
3122
+ const stateChanged = (_b = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.changeState(state !== null && state !== void 0 ? state : '')) !== null && _b !== void 0 ? _b : false;
3123
+ if (stateChanged) {
3124
+ const clientActionMethods = this._formChangeState;
3125
+ if (clientActionMethods && clientActionMethods.length > 0) {
3126
+ for (const callback of clientActionMethods) {
3127
+ callback(state);
3128
+ }
3129
+ }
3130
+ }
3131
+ return stateChanged;
3132
+ }
3133
+ checkErrorRecordReceived(recordResponse) {
3134
+ const { error } = recordResponse;
3135
+ if (!error) {
3136
+ return false;
3137
+ }
3138
+ this.errorCode = recordResponse.errorCode;
3139
+ this.errorFullCode = recordResponse.errorFullCode;
3140
+ this.errorName = recordResponse.errorName;
3141
+ this.errorMessage = recordResponse.errorMessage;
3142
+ this.errorDetail = recordResponse.errorDetail;
3143
+ return true;
3144
+ }
3145
+ errorOccured() {
3146
+ return (this.errorCode !== NO_ERROR);
3147
+ }
3148
+ /**
3149
+ * Soporte manejo de eventos de formulario
3150
+ */
3151
+ requestFormAction(actionCode, actionSubject = {}) {
3152
+ var _a, _b, _c;
3153
+ return __awaiter(this, void 0, void 0, function* () {
3154
+ const actionDetail = {
3155
+ formCode: this.name,
3156
+ formSubject: this.formSubject,
3157
+ currentMode: (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.state,
3158
+ actionCode,
3159
+ actionSubject,
3160
+ version: PAYLOAD_VERSION,
3161
+ formData: (_b = this._formStructure) === null || _b === void 0 ? void 0 : _b.getPayload(),
3162
+ immutableData: (_c = this._formStructure) === null || _c === void 0 ? void 0 : _c.immutableData,
3163
+ };
3164
+ this.errorCode = NO_ERROR;
3165
+ this.errorFullCode = '';
3166
+ this.errorName = '';
3167
+ this.errorMessage = '';
3168
+ this.errorDetail = '';
3169
+ this.busy = true;
3170
+ const formActionResponse = yield this.formManagerService.execServerAction(actionDetail);
3171
+ this.busy = false;
3172
+ if (formActionResponse.hasError()) {
3173
+ const error = formActionResponse.error;
3174
+ this.errorCode = error.errorCode;
3175
+ this.errorFullCode = error.errorFullCode;
3176
+ this.errorName = error.errorName;
3177
+ this.errorMessage = error.errorMessage;
3178
+ this.errorDetail = error.errorDetail;
3179
+ }
3180
+ const formResponseData = formActionResponse.getData();
3181
+ this.updateFormWithServerData(formResponseData);
3182
+ return formResponseData;
3183
+ });
3184
+ }
3185
+ updateFormWithServerData(formContent) {
3186
+ const { currentMode, formSubject, actions, fields, recordTables, returnedFile, immutableData, extraInfo, } = formContent;
3187
+ currentMode && this.changeState(currentMode);
3188
+ if (formSubject) {
3189
+ this.formSubject = formSubject;
3190
+ }
3191
+ if (actions && actions.length > 0) {
3192
+ for (const changedAction of actions) {
3193
+ const actionObject = this.getAction(changedAction.actionCode);
3194
+ if (actionObject) {
3195
+ actionObject.updateFromServer(changedAction);
3196
+ }
3197
+ }
3198
+ }
3199
+ if (fields && fields.length > 0) {
3200
+ for (const changedField of fields) {
3201
+ const fieldObject = this.getField(changedField.fieldCode);
3202
+ if (fieldObject) {
3203
+ fieldObject.updateFromServer(changedField);
3204
+ }
3205
+ }
3206
+ }
3207
+ if (recordTables && recordTables.length > 0) {
3208
+ for (const changedTable of recordTables) {
3209
+ const tableObject = this.getTable(changedTable.tableCode);
3210
+ if (tableObject) {
3211
+ tableObject.updateFromServer(changedTable);
3212
+ }
3213
+ }
3214
+ }
3215
+ if (returnedFile && returnedFile.file) {
3216
+ this.fileMgmtServices.saveFile(returnedFile.file, returnedFile.name, returnedFile.type);
3217
+ }
3218
+ if (this._formStructure) {
3219
+ this._formStructure.immutableData = immutableData;
3220
+ this._formStructure.extraInfo = extraInfo;
3221
+ }
3222
+ }
3223
+ /**
3224
+ * Manejo de event handlers para errores Server del formulario
3225
+ */
3226
+ cleanActionServerError() {
3227
+ this._actionServerError = [];
3228
+ }
3229
+ cleanFieldServerError() {
3230
+ this._fieldServerError = [];
3231
+ }
3232
+ cleanTableServerError() {
3233
+ this._tableServerError = [];
3234
+ }
3235
+ onActionServerError(callback, properties = null) {
3236
+ this._actionServerError.push({ callback, properties });
3237
+ }
3238
+ onValidationServerError(callback, properties = null) {
3239
+ this._fieldServerError.push({ callback, properties });
3240
+ }
3241
+ onTableServerError(callback, properties = null) {
3242
+ this._tableServerError.push({ callback, properties });
3243
+ }
3244
+ /**
3245
+ * Manejo de event handlers para acciones sobre el formulario
3246
+ */
3247
+ onFormChange(callback) {
3248
+ this._formChangeState.push(callback);
3249
+ }
3250
+ onSectionCanDeactivate(codes, callback, properties = null) {
3251
+ const sectionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
3252
+ sectionSet.forEach((sectionName) => {
3253
+ if (!this._formSectionsCanDeactivate[sectionName]) {
3254
+ this._formSectionsCanDeactivate[sectionName] = [];
3255
+ }
3256
+ this._formSectionsCanDeactivate[sectionName].push({ callback, properties });
3257
+ });
3258
+ }
3259
+ onSectionActivation(codes, callback, properties = null) {
3260
+ const sectionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
3261
+ sectionSet.forEach((sectionName) => {
3262
+ if (!this._formSectionsActivate[sectionName]) {
3263
+ this._formSectionsActivate[sectionName] = [];
3264
+ }
3265
+ this._formSectionsActivate[sectionName].push({ callback, properties });
3266
+ });
3267
+ }
3268
+ onSectionInactivation(codes, callback, properties = null) {
3269
+ const sectionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
3270
+ sectionSet.forEach((sectionName) => {
3271
+ if (!this._formSectionsInactivate[sectionName]) {
3272
+ this._formSectionsInactivate[sectionName] = [];
3273
+ }
3274
+ this._formSectionsInactivate[sectionName].push({ callback, properties });
3275
+ });
3276
+ }
3277
+ onActionStart(codes, callback, properties = null) {
3278
+ const actionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
3279
+ actionSet.forEach((actionName) => {
3280
+ if (!this._formActionsStart[actionName]) {
3281
+ this._formActionsStart[actionName] = [];
3282
+ }
3283
+ this._formActionsStart[actionName].push({ callback, properties });
3284
+ });
3285
+ }
3286
+ onActionFinish(codes, callback, properties = null) {
3287
+ const actionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
3288
+ actionSet.forEach((actionName) => {
3289
+ if (!this._formActionsFinish[actionName]) {
3290
+ this._formActionsFinish[actionName] = [];
3291
+ }
3292
+ this._formActionsFinish[actionName].push({ callback, properties });
3293
+ });
3294
+ }
3295
+ verifySectionActivation(code) {
3296
+ var _a;
3297
+ return __awaiter(this, void 0, void 0, function* () {
3298
+ const sectionObject = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSection(code);
3299
+ if (!sectionObject) {
3300
+ return false;
3301
+ }
3302
+ const clientSectionMethods = this._formSectionsCanDeactivate[code];
3303
+ if (clientSectionMethods) {
3304
+ for (const clientSectionMethod of clientSectionMethods) {
3305
+ const { callback, properties } = clientSectionMethod;
3306
+ const canActivate = callback(sectionObject);
3307
+ if (canActivate === false) {
3308
+ return false;
3309
+ }
3310
+ }
3311
+ }
3312
+ return true;
3313
+ });
3314
+ }
3315
+ launchSectionActivation(code) {
3316
+ var _a;
3317
+ return __awaiter(this, void 0, void 0, function* () {
3318
+ this.notifyFormActivity();
3319
+ const sectionObject = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSection(code);
3320
+ if (!sectionObject) {
3321
+ return;
3322
+ }
3323
+ const clientSectionMethods = this._formSectionsActivate[code];
3324
+ if (clientSectionMethods) {
3325
+ for (const clientSectionMethod of clientSectionMethods) {
3326
+ const { callback, properties } = clientSectionMethod;
3327
+ callback(sectionObject);
3328
+ }
3329
+ }
3330
+ });
3331
+ }
3332
+ launchSectionInactivation(code) {
3333
+ var _a;
3334
+ return __awaiter(this, void 0, void 0, function* () {
3335
+ this.notifyFormActivity();
3336
+ const sectionObject = (_a = this._formStructure) === null || _a === void 0 ? void 0 : _a.getSection(code);
3337
+ if (!sectionObject) {
3338
+ return;
3339
+ }
3340
+ const clientSectionMethods = this._formSectionsInactivate[code];
3341
+ if (clientSectionMethods) {
3342
+ for (const clientSectionMethod of clientSectionMethods) {
3343
+ const { callback, properties } = clientSectionMethod;
3344
+ callback(sectionObject);
3345
+ }
3346
+ }
3347
+ });
3348
+ }
3349
+ startAction(code) {
3350
+ return __awaiter(this, void 0, void 0, function* () {
3351
+ this.notifyFormActivity();
3352
+ const actionObject = this.getAction(code);
3353
+ if (!actionObject) {
3354
+ return;
3355
+ }
3356
+ this.resetError();
3357
+ actionObject.start();
3358
+ const clientActionMethods = this._formActionsStart[code];
3359
+ if (clientActionMethods) {
3360
+ const clientActionPromises = [];
3361
+ for (const clientActionMethod of clientActionMethods) {
3362
+ const { callback, properties } = clientActionMethod;
3363
+ const continueActionPromise = callback(actionObject);
3364
+ clientActionPromises.push(continueActionPromise);
3365
+ }
3366
+ const clientActionResults = yield Promise.all(clientActionPromises);
3367
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
3368
+ if (!continueAction) {
3369
+ actionObject.stop();
3370
+ return;
3371
+ }
3372
+ }
3373
+ this.startServerAction(actionObject);
3374
+ });
3375
+ }
3376
+ startServerAction(actionInput) {
3377
+ return __awaiter(this, void 0, void 0, function* () {
3378
+ const action = (typeof actionInput === 'string')
3379
+ ? this.getAction(actionInput) : actionInput;
3380
+ let serverError = false;
3381
+ let actionResult = null;
3382
+ if (action.backend) {
3383
+ actionResult = yield this.requestFormAction(action.actionCode);
3384
+ serverError = !!this.errorOccured();
3385
+ }
3386
+ yield this.finishAction(action, actionResult, serverError);
3387
+ if (!serverError) {
3388
+ action.newState && this.changeState(action.newState);
3389
+ }
3390
+ else {
3391
+ for (let index = 0; index < this._actionServerError.length; index++) {
3392
+ const { callback, properties } = this._actionServerError[index];
3393
+ callback(action);
3394
+ }
3395
+ }
3396
+ action.stop();
3397
+ });
3398
+ }
3399
+ finishAction(action, actionResult, serverError = false) {
3400
+ var _a;
3401
+ return __awaiter(this, void 0, void 0, function* () {
3402
+ const finishActionMethods = this._formActionsFinish[action.actionCode];
3403
+ if (finishActionMethods) {
3404
+ const clientActionPromises = [];
3405
+ for (const clientActionMethod of finishActionMethods) {
3406
+ const { callback, properties } = clientActionMethod;
3407
+ const continueOnError = (_a = properties === null || properties === void 0 ? void 0 : properties.continueOnError) !== null && _a !== void 0 ? _a : false;
3408
+ if (callback && (!serverError || continueOnError)) {
3409
+ clientActionPromises.push(callback(action, actionResult));
3410
+ }
3411
+ }
3412
+ yield Promise.all(clientActionPromises);
3413
+ }
3414
+ });
3415
+ }
3416
+ completeGlobalAction(action) {
3417
+ return this.startServerAction(action);
3418
+ }
3419
+ /**
3420
+ * Manejadores de eventos para validaciones sobre campos
3421
+ */
3422
+ onFieldInput(codes, callback, properties = null) {
3423
+ const fieldSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
3424
+ fieldSet.forEach((code) => {
3425
+ if (!this._fieldInputValidation[code]) {
3426
+ this._fieldInputValidation[code] = [];
3427
+ }
3428
+ this._fieldInputValidation[code].push({ callback, properties });
3429
+ });
3430
+ }
3431
+ onFieldValidationStart(codes, callback, properties = null) {
3432
+ const fieldSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
3433
+ fieldSet.forEach((code) => {
3434
+ if (!this._fieldValidationsStart[code]) {
3435
+ this._fieldValidationsStart[code] = [];
3436
+ }
3437
+ this._fieldValidationsStart[code].push({ callback, properties });
3438
+ });
3439
+ }
3440
+ onFieldValidationFinish(codes, callback, properties = null) {
3441
+ const fieldSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
3442
+ fieldSet.forEach((code) => {
3443
+ if (!this._fieldValidationsFinish[code]) {
3444
+ this._fieldValidationsFinish[code] = [];
3445
+ }
3446
+ this._fieldValidationsFinish[code].push({ callback, properties });
3447
+ });
3448
+ }
3449
+ startFieldInputValidation(code, intrinsicValidation = true) {
3450
+ return __awaiter(this, void 0, void 0, function* () {
3451
+ this.notifyFormActivity();
3452
+ const fieldToValidate = this.getField(code);
3453
+ if (!fieldToValidate) {
3454
+ return false;
3455
+ }
3456
+ const validationCallbacks = this._fieldInputValidation[code];
3457
+ if (validationCallbacks) {
3458
+ const clientValidationPromises = [];
3459
+ for (const validationMethod of validationCallbacks) {
3460
+ const { callback, properties } = validationMethod;
3461
+ const continueValidationPromise = callback(fieldToValidate);
3462
+ clientValidationPromises.push(continueValidationPromise);
3463
+ }
3464
+ yield Promise.all(clientValidationPromises);
3465
+ }
3466
+ return true;
3467
+ });
3468
+ }
3469
+ startFieldValidation(code, intrinsicValidation = true) {
3470
+ return __awaiter(this, void 0, void 0, function* () {
3471
+ this.notifyFormActivity();
3472
+ const fieldToValidate = this.getField(code);
3473
+ if (!fieldToValidate) {
3474
+ return;
3475
+ }
3476
+ const validationCallbacks = this._fieldValidationsStart[code];
3477
+ if (validationCallbacks) {
3478
+ const clientValidationPromises = [];
3479
+ for (const validationMethod of validationCallbacks) {
3480
+ const { callback, properties } = validationMethod;
3481
+ const clientValidationPromise = callback(fieldToValidate);
3482
+ clientValidationPromises.push(clientValidationPromise);
3483
+ }
3484
+ const clientValidationResults = yield Promise.all(clientValidationPromises);
3485
+ const continueValidation = clientValidationResults.reduce((total, curr) => (total && (curr !== false)), true);
3486
+ if (!continueValidation) {
3487
+ return;
3488
+ }
3489
+ }
3490
+ if (intrinsicValidation) {
3491
+ this.startServerFieldValidation(fieldToValidate);
3492
+ }
3493
+ });
3494
+ }
3495
+ startServerFieldValidation(inputField) {
3496
+ return __awaiter(this, void 0, void 0, function* () {
3497
+ const fieldObj = (typeof inputField === 'string')
3498
+ ? this.getField(inputField) : inputField;
3499
+ let serverError = false;
3500
+ let validationResult = true;
3501
+ if (!fieldObj) {
3502
+ return;
3503
+ }
3504
+ if (fieldObj.backend) {
3505
+ fieldObj.validating = true;
3506
+ validationResult = yield this
3507
+ .requestFormAction(formActions.validate, fieldObj.code);
3508
+ serverError = !!this.errorOccured();
3509
+ }
3510
+ if (serverError) {
3511
+ fieldObj === null || fieldObj === void 0 ? void 0 : fieldObj.setErrorCode(this.errorCode);
3512
+ fieldObj === null || fieldObj === void 0 ? void 0 : fieldObj.setErrorMessage(this.errorMessage);
3513
+ for (let index = 0; index < this._fieldServerError.length; index++) {
3514
+ const { callback, properties } = this._fieldServerError[index];
3515
+ callback(fieldObj);
3516
+ }
3517
+ }
3518
+ yield this.finishFieldValidation(fieldObj, validationResult, serverError);
3519
+ fieldObj.validating = false;
3520
+ });
3521
+ }
3522
+ finishFieldValidation(fieldObject, validationResult, serverError = false) {
3523
+ var _a;
3524
+ return __awaiter(this, void 0, void 0, function* () {
3525
+ const validationCallbacks = this._fieldValidationsFinish[fieldObject.code];
3526
+ if (validationCallbacks) {
3527
+ const clientActionPromises = [];
3528
+ for (const validationMethod of validationCallbacks) {
3529
+ const { callback, properties } = validationMethod;
3530
+ const continueOnError = (_a = properties === null || properties === void 0 ? void 0 : properties.continueOnError) !== null && _a !== void 0 ? _a : false;
3531
+ if (!serverError || continueOnError) {
3532
+ clientActionPromises.push(callback(fieldObject, validationResult));
3533
+ }
3534
+ }
3535
+ yield Promise.all(clientActionPromises);
3536
+ }
3537
+ });
3538
+ }
3539
+ continueFieldValidation(code) {
3540
+ return __awaiter(this, void 0, void 0, function* () {
3541
+ return this.startServerFieldValidation(code);
3542
+ });
3543
+ }
3544
+ /**
3545
+ * Manejadores de eventos para acciones sobre Tablas
3546
+ */
3547
+ onTableActionStart(code, actionCode, callback, properties = null) {
3548
+ const tableObject = this.getTable(code);
3549
+ if (!tableObject) {
3550
+ return;
3551
+ }
3552
+ const inlineActionObject = tableObject.getAction(actionCode);
3553
+ if (!inlineActionObject) {
3554
+ return;
3555
+ }
3556
+ let tableEventHandlers;
3557
+ if (this._tableActionsStart[code]) {
3558
+ tableEventHandlers = this._tableActionsStart[code];
3559
+ }
3560
+ else {
3561
+ tableEventHandlers = {};
3562
+ this._tableActionsStart[code] = tableEventHandlers;
3563
+ }
3564
+ if (!tableEventHandlers[actionCode]) {
3565
+ tableEventHandlers[actionCode] = [];
3566
+ }
3567
+ tableEventHandlers[actionCode].push({ callback, properties });
3568
+ }
3569
+ onTableActionFinish(code, actionCode, callback, properties = null) {
3570
+ const tableObject = this.getTable(code);
3571
+ if (!tableObject) {
3572
+ return;
3573
+ }
3574
+ const inlineActionObject = tableObject.getAction(actionCode);
3575
+ if (!inlineActionObject) {
3576
+ return;
3577
+ }
3578
+ let tableEventHandlers;
3579
+ if (this._tableActionsFinish[code]) {
3580
+ tableEventHandlers = this._tableActionsFinish[code];
3581
+ }
3582
+ else {
3583
+ tableEventHandlers = {};
3584
+ this._tableActionsFinish[code] = tableEventHandlers;
3585
+ }
3586
+ if (!tableEventHandlers[actionCode]) {
3587
+ tableEventHandlers[actionCode] = [];
3588
+ }
3589
+ tableEventHandlers[actionCode].push({ callback, properties });
3590
+ }
3591
+ onTableSelectionStart(code, callback, properties = null) {
3592
+ const tableObject = this.getTable(code);
3593
+ if (!tableObject) {
3594
+ return;
3595
+ }
3596
+ let tableEventHandlers;
3597
+ if (this._tableSelectionsStart[code]) {
3598
+ tableEventHandlers = this._tableSelectionsStart[code];
3599
+ }
3600
+ else {
3601
+ tableEventHandlers = [];
3602
+ this._tableSelectionsStart[code] = tableEventHandlers;
3603
+ }
3604
+ tableEventHandlers.push({ callback, properties });
3605
+ }
3606
+ onTableSelectionFinish(code, callback, properties = null) {
3607
+ const tableObject = this.getTable(code);
3608
+ if (!tableObject) {
3609
+ return;
3610
+ }
3611
+ let tableEventHandlers;
3612
+ if (this._tableSelectionsFinish[code]) {
3613
+ tableEventHandlers = this._tableSelectionsFinish[code];
3614
+ }
3615
+ else {
3616
+ tableEventHandlers = [];
3617
+ this._tableSelectionsFinish[code] = tableEventHandlers;
3618
+ }
3619
+ tableEventHandlers.push({ callback, properties });
3620
+ }
3621
+ onTableGetDataStart(code, callback, properties = null) {
3622
+ const tableObject = this.getTable(code);
3623
+ if (!tableObject) {
3624
+ return;
3625
+ }
3626
+ let tableEventHandlers;
3627
+ if (this._tableGetDataStart[code]) {
3628
+ tableEventHandlers = this._tableGetDataStart[code];
3629
+ }
3630
+ else {
3631
+ tableEventHandlers = [];
3632
+ this._tableGetDataStart[code] = tableEventHandlers;
3633
+ }
3634
+ tableEventHandlers.push({ callback, properties });
3635
+ }
3636
+ onTableGetDataFinish(code, callback, properties = null) {
3637
+ const tableObject = this.getTable(code);
3638
+ if (!tableObject) {
3639
+ return;
3640
+ }
3641
+ let tableEventHandlers;
3642
+ if (this._tableGetDataFinish[code]) {
3643
+ tableEventHandlers = this._tableGetDataFinish[code];
3644
+ }
3645
+ else {
3646
+ tableEventHandlers = {};
3647
+ this._tableGetDataFinish[code] = tableEventHandlers;
3648
+ }
3649
+ tableEventHandlers[GET_DATA_ACTION] = { callback, properties };
3650
+ }
3651
+ startTableGlobalAction(tableActionEvent) {
3652
+ return __awaiter(this, void 0, void 0, function* () {
3653
+ this.notifyFormActivity();
3654
+ const { tableCode, actionCode } = tableActionEvent;
3655
+ const tableObject = this.getTable(tableCode);
3656
+ if (!tableObject || !actionCode) {
3657
+ return;
3658
+ }
3659
+ this.resetError();
3660
+ const action = tableObject.getAction(actionCode);
3661
+ if (!action) {
3662
+ return;
3663
+ }
3664
+ const tableActionDetail = {
3665
+ tableObject,
3666
+ action,
3667
+ tableCode,
3668
+ actionCode,
3669
+ };
3670
+ const tableEventHandlers = this._tableActionsStart[tableCode];
3671
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
3672
+ if (tableActionMethods) {
3673
+ const clientActionPromises = [];
3674
+ for (const tableActionMethod of tableActionMethods) {
3675
+ const { callback, properties } = tableActionMethod;
3676
+ const clientActionPromise = callback(tableActionDetail);
3677
+ clientActionPromises.push(clientActionPromise);
3678
+ }
3679
+ const clientActionResults = yield Promise.all(clientActionPromises);
3680
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
3681
+ if (!continueAction) {
3682
+ return;
3683
+ }
3684
+ }
3685
+ this.startTableServerGlobalAction(tableActionDetail);
3686
+ });
3687
+ }
3688
+ startTableServerGlobalAction(tableActionDetail) {
3689
+ return __awaiter(this, void 0, void 0, function* () {
3690
+ const { tableObject, action, tableCode, actionCode } = tableActionDetail;
3691
+ if (!tableObject || !action) {
3692
+ return;
3693
+ }
3694
+ tableObject.putOnWait();
3695
+ let serverError = false;
3696
+ let actionResult = null;
3697
+ if (action.backend) {
3698
+ const actionSubject = {
3699
+ tableCode,
3700
+ actionType: GLOBAL_ACTION,
3701
+ actionCode
3702
+ };
3703
+ actionResult = yield this
3704
+ .requestFormAction(formActions.tableAction, actionSubject);
3705
+ serverError = !!this.errorOccured();
3706
+ }
3707
+ yield this.finishTableGlobalAction(tableActionDetail, actionResult, serverError);
3708
+ if (!serverError) {
3709
+ action.newState && this.changeState(action.newState);
3710
+ }
3711
+ else {
3712
+ for (let index = 0; index < this._tableServerError.length; index++) {
3713
+ const { callback, properties } = this._tableServerError[index];
3714
+ callback(tableObject);
3715
+ }
3716
+ }
3717
+ tableObject.freeWaiting();
3718
+ });
3719
+ }
3720
+ finishTableGlobalAction(tableActionDetail, actionResult, serverError = false) {
3721
+ var _a;
3722
+ return __awaiter(this, void 0, void 0, function* () {
3723
+ const { tableCode, actionCode } = tableActionDetail;
3724
+ const tableEventHandlers = this._tableActionsFinish[tableCode];
3725
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
3726
+ if (tableActionMethods) {
3727
+ const clientActionPromises = [];
3728
+ for (const tableActionMethod of tableActionMethods) {
3729
+ const { callback, properties } = tableActionMethod;
3730
+ const continueOnError = (_a = properties === null || properties === void 0 ? void 0 : properties.continueOnError) !== null && _a !== void 0 ? _a : false;
3731
+ if (!serverError || continueOnError) {
3732
+ clientActionPromises.push(callback(tableActionDetail, actionResult));
3733
+ }
3734
+ }
3735
+ yield Promise.all(clientActionPromises);
3736
+ }
3737
+ });
3738
+ }
3739
+ startTableAction(tableActionEvent) {
3740
+ return __awaiter(this, void 0, void 0, function* () {
3741
+ this.notifyFormActivity();
3742
+ const { tableCode, actionCode, actionDetail } = tableActionEvent;
3743
+ const tableObject = this.getTable(tableCode);
3744
+ if (!tableObject || !actionCode) {
3745
+ return;
3746
+ }
3747
+ this.resetError();
3748
+ const { recordId, recordData } = actionDetail;
3749
+ const action = tableObject.getAction(actionCode);
3750
+ if (!action) {
3751
+ return;
3752
+ }
3753
+ const tableActionDetail = {
3754
+ tableObject,
3755
+ action,
3756
+ tableCode,
3757
+ actionCode,
3758
+ recordId,
3759
+ recordData
3760
+ };
3761
+ const tableEventHandlers = this._tableActionsStart[tableCode];
3762
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
3763
+ if (tableActionMethods) {
3764
+ const clientActionPromises = [];
3765
+ for (const tableActionMethod of tableActionMethods) {
3766
+ const { callback, properties } = tableActionMethod;
3767
+ const clientActionPromise = callback(tableActionDetail);
3768
+ clientActionPromises.push(clientActionPromise);
3769
+ }
3770
+ const clientActionResults = yield Promise.all(clientActionPromises);
3771
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
3772
+ if (!continueAction) {
3773
+ return;
3774
+ }
3775
+ }
3776
+ this.startTableServerAction(tableActionDetail);
3777
+ });
3778
+ }
3779
+ startTableServerAction(tableActionDetail) {
3780
+ var _a;
3781
+ return __awaiter(this, void 0, void 0, function* () {
3782
+ const { tableObject, action, tableCode, actionCode, recordId, recordData } = tableActionDetail;
3783
+ if (!tableObject || !action) {
3784
+ return;
3785
+ }
3786
+ tableObject.putOnWait();
3787
+ let serverError = false;
3788
+ let actionResult = null;
3789
+ if (action.backend) {
3790
+ const actionSubject = {
3791
+ tableCode,
3792
+ actionType: (_a = this.formConfig) === null || _a === void 0 ? void 0 : _a.tableActions.inline,
3793
+ actionCode,
3794
+ tableRecordId: recordId,
3795
+ tableRecordData: recordData
3796
+ };
3797
+ actionResult = yield this
3798
+ .requestFormAction(formActions.tableAction, actionSubject);
3799
+ serverError = !!this.errorOccured();
3800
+ }
3801
+ yield this.finishTableAction(tableActionDetail, actionResult, serverError);
3802
+ if (!serverError) {
3803
+ action.newState && this.changeState(action.newState);
3804
+ }
3805
+ else {
3806
+ this.displayTableServerError();
3807
+ }
3808
+ tableObject.freeWaiting();
3809
+ });
3810
+ }
3811
+ completeInlineAction(tableAction) {
3812
+ return this.startTableServerAction(tableAction);
3813
+ }
3814
+ finishTableAction(tableActionDetail, actionResult, serverError = false) {
3815
+ var _a;
3816
+ return __awaiter(this, void 0, void 0, function* () {
3817
+ const { tableCode, actionCode } = tableActionDetail;
3818
+ const tableEventHandlers = this._tableActionsFinish[tableCode];
3819
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
3820
+ if (tableActionMethods) {
3821
+ const clientActionPromises = [];
3822
+ for (const tableActionMethod of tableActionMethods) {
3823
+ const { callback, properties } = tableActionMethod;
3824
+ const continueOnError = (_a = properties === null || properties === void 0 ? void 0 : properties.continueOnError) !== null && _a !== void 0 ? _a : false;
3825
+ if (!serverError || continueOnError) {
3826
+ clientActionPromises.push(callback(tableActionDetail, actionResult));
3827
+ }
3828
+ }
3829
+ yield Promise.all(clientActionPromises);
3830
+ }
3831
+ });
3832
+ }
3833
+ startTableRecordSelection(tableActionEvent) {
3834
+ return __awaiter(this, void 0, void 0, function* () {
3835
+ this.notifyFormActivity();
3836
+ const { tableCode, actionDetail } = tableActionEvent;
3837
+ const tableObject = this.getTable(tableCode);
3838
+ if (!tableObject) {
3839
+ return;
3840
+ }
3841
+ this.resetError();
3842
+ const { recordId, recordData } = actionDetail;
3843
+ const tableSelectionDetail = {
3844
+ tableObject,
3845
+ tableCode,
3846
+ recordId,
3847
+ recordData
3848
+ };
3849
+ const tableEventHandlers = this._tableSelectionsStart[tableCode];
3850
+ if (tableEventHandlers) {
3851
+ const clientActionPromises = [];
3852
+ for (const tableSelectionMethod of tableEventHandlers) {
3853
+ const { callback, properties } = tableSelectionMethod;
3854
+ const clientActionPromise = callback(tableSelectionDetail);
3855
+ clientActionPromises.push(clientActionPromise);
3856
+ }
3857
+ const clientActionResults = yield Promise.all(clientActionPromises);
3858
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
3859
+ if (!continueAction) {
3860
+ return;
3861
+ }
3862
+ }
3863
+ this.startTableServerRecordSelection(tableSelectionDetail);
3864
+ });
3865
+ }
3866
+ startTableServerRecordSelection(tableSelectionDetail) {
3867
+ var _a;
3868
+ return __awaiter(this, void 0, void 0, function* () {
3869
+ const { tableObject, tableCode, recordId, recordData } = tableSelectionDetail;
3870
+ if (!tableObject) {
3871
+ return;
3872
+ }
3873
+ tableObject.putOnWait();
3874
+ let serverError = false;
3875
+ let actionResult = null;
3876
+ if (tableObject.selectionBackend) {
3877
+ const actionSubject = {
3878
+ tableCode,
3879
+ actionType: (_a = this.formConfig) === null || _a === void 0 ? void 0 : _a.tableActions.rowSelection,
3880
+ actionCode: null,
3881
+ tableRecordId: recordId,
3882
+ tableRecordData: recordData
3883
+ };
3884
+ actionResult = yield this
3885
+ .requestFormAction(formActions.tableAction, actionSubject);
3886
+ serverError = !!this.errorOccured();
3887
+ }
3888
+ yield this.finishTableRecordSelection(tableSelectionDetail, actionResult, serverError);
3889
+ if (serverError) {
3890
+ this.displayTableServerError();
3891
+ }
3892
+ tableObject.freeWaiting();
3893
+ });
3894
+ }
3895
+ finishTableRecordSelection(tableSelectionDetail, actionResult, serverError = false) {
3896
+ var _a;
3897
+ return __awaiter(this, void 0, void 0, function* () {
3898
+ const { tableCode } = tableSelectionDetail;
3899
+ const tableEventHandlers = this._tableSelectionsFinish[tableCode];
3900
+ if (tableEventHandlers) {
3901
+ const clientActionPromises = [];
3902
+ for (const tableSelectionMethod of tableEventHandlers) {
3903
+ const { callback, properties } = tableSelectionMethod;
3904
+ const continueOnError = (_a = properties === null || properties === void 0 ? void 0 : properties.continueOnError) !== null && _a !== void 0 ? _a : false;
3905
+ if (!serverError || continueOnError) {
3906
+ clientActionPromises.push(callback(tableSelectionDetail, actionResult));
3907
+ }
3908
+ }
3909
+ yield Promise.all(clientActionPromises);
3910
+ }
3911
+ });
3912
+ }
3913
+ startTableSelectionAction(tableActionEvent) {
3914
+ return __awaiter(this, void 0, void 0, function* () {
3915
+ this.notifyFormActivity();
3916
+ const { tableCode, actionCode, actionDetail } = tableActionEvent;
3917
+ const tableObject = this.getTable(tableCode);
3918
+ if (!tableObject || !actionCode) {
3919
+ return;
3920
+ }
3921
+ this.resetError();
3922
+ const { selectedRecords } = actionDetail;
3923
+ const action = tableObject.getAction(actionCode);
3924
+ if (!action) {
3925
+ return;
3926
+ }
3927
+ const tableActionDetail = {
3928
+ tableObject,
3929
+ action,
3930
+ tableCode,
3931
+ actionCode,
3932
+ selectedRecords
3933
+ };
3934
+ const tableEventHandlers = this._tableActionsStart[tableCode];
3935
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
3936
+ if (tableActionMethods) {
3937
+ const clientActionPromises = [];
3938
+ for (const tableActionMethod of tableActionMethods) {
3939
+ const { callback, properties } = tableActionMethod;
3940
+ const clientActionPromise = callback(tableActionDetail);
3941
+ clientActionPromises.push(clientActionPromise);
3942
+ }
3943
+ const clientActionResults = yield Promise.all(clientActionPromises);
3944
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
3945
+ if (!continueAction) {
3946
+ return;
3947
+ }
3948
+ }
3949
+ this.startTableServerSelectionAction(tableActionDetail);
3950
+ });
3951
+ }
3952
+ startTableServerSelectionAction(tableActionDetail) {
3953
+ var _a;
3954
+ return __awaiter(this, void 0, void 0, function* () {
3955
+ const { tableObject, action, tableCode, actionCode, selectedRecords } = tableActionDetail;
3956
+ if (!tableObject || !action) {
3957
+ return;
3958
+ }
3959
+ tableObject.putOnWait();
3960
+ let serverError = false;
3961
+ let actionResult = null;
3962
+ if (action.backend) {
3963
+ const actionSubject = {
3964
+ tableCode,
3965
+ actionType: (_a = this.formConfig) === null || _a === void 0 ? void 0 : _a.tableActions.selection,
3966
+ actionCode,
3967
+ selectedRecords
3968
+ };
3969
+ actionResult = yield this
3970
+ .requestFormAction(formActions.tableAction, actionSubject);
3971
+ serverError = !!this.errorOccured();
3972
+ }
3973
+ yield this.finishTableSelectionAction(tableActionDetail, actionResult, serverError);
3974
+ if (!serverError) {
3975
+ action.newState && this.changeState(action.newState);
3976
+ }
3977
+ else {
3978
+ this.displayTableServerError();
3979
+ }
3980
+ tableObject.freeWaiting();
3981
+ });
3982
+ }
3983
+ finishTableSelectionAction(tableActionDetail, actionResult, serverError = false) {
3984
+ var _a;
3985
+ return __awaiter(this, void 0, void 0, function* () {
3986
+ const { tableCode, actionCode } = tableActionDetail;
3987
+ const tableEventHandlers = this._tableActionsFinish[tableCode];
3988
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
3989
+ if (tableActionMethods) {
3990
+ const clientActionPromises = [];
3991
+ for (const tableActionMethod of tableActionMethods) {
3992
+ const { callback, properties } = tableActionMethod;
3993
+ const continueOnError = (_a = properties === null || properties === void 0 ? void 0 : properties.continueOnError) !== null && _a !== void 0 ? _a : false;
3994
+ if (!serverError || continueOnError) {
3995
+ clientActionPromises.push(callback(tableActionDetail, actionResult));
3996
+ }
3997
+ }
3998
+ yield Promise.all(clientActionPromises);
3999
+ }
4000
+ });
4001
+ }
4002
+ startTableGetData(tableActionEvent) {
4003
+ return __awaiter(this, void 0, void 0, function* () {
4004
+ this.notifyFormActivity();
4005
+ const { tableCode } = tableActionEvent;
4006
+ const tableObject = this.getTable(tableCode);
4007
+ const tableActionDetail = {
4008
+ tableObject,
4009
+ tableCode
4010
+ };
4011
+ this.resetError();
4012
+ const tableEventHandlers = this._tableGetDataStart[tableCode];
4013
+ if (tableEventHandlers) {
4014
+ const clientActionPromises = [];
4015
+ for (const tableActionMethod of tableEventHandlers) {
4016
+ const { callback, properties } = tableActionMethod;
4017
+ const clientActionPromise = callback(tableActionDetail);
4018
+ clientActionPromises.push(clientActionPromise);
4019
+ }
4020
+ const clientActionResults = yield Promise.all(clientActionPromises);
4021
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
4022
+ if (!continueAction) {
4023
+ return;
4024
+ }
4025
+ }
4026
+ this.startTableServerGetData(tableActionDetail);
4027
+ });
4028
+ }
4029
+ startTableServerGetData(tableActionDetail) {
4030
+ return __awaiter(this, void 0, void 0, function* () {
4031
+ const { tableObject, tableCode } = tableActionDetail;
4032
+ tableObject.putOnWait();
4033
+ let serverError = false;
4034
+ const actionSubject = { tableCode };
4035
+ const actionResult = yield this
4036
+ .requestFormAction(formActions.getTableData, actionSubject);
4037
+ serverError = !!this.errorOccured();
4038
+ yield this.finishTableGetData(tableActionDetail, actionResult, serverError);
4039
+ if (serverError) {
4040
+ this.displayTableServerError();
4041
+ }
4042
+ tableObject.freeWaiting();
4043
+ });
4044
+ }
4045
+ finishTableGetData(tableActionDetail, actionResult, serverError = false) {
4046
+ var _a;
4047
+ return __awaiter(this, void 0, void 0, function* () {
4048
+ const { tableCode, tableActionCode } = tableActionDetail;
4049
+ const tableEventHandlers = this._tableActionsFinish[tableCode];
4050
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[tableActionCode] : null;
4051
+ if (tableActionMethods) {
4052
+ const clientActionPromises = [];
4053
+ for (const tableActionMethod of tableActionMethods) {
4054
+ const { callback, properties } = tableActionMethod;
4055
+ const continueOnError = (_a = properties === null || properties === void 0 ? void 0 : properties.continueOnError) !== null && _a !== void 0 ? _a : false;
4056
+ if (!serverError || continueOnError) {
4057
+ clientActionPromises.push(callback(tableActionDetail, actionResult));
4058
+ }
4059
+ }
4060
+ yield Promise.all(clientActionPromises);
4061
+ }
4062
+ });
4063
+ }
4064
+ checkSectionRequiredFields(sectionCode, reqFieldMessage) {
4065
+ var _a;
4066
+ this.cleanErrorFields(null, sectionCode);
4067
+ const requiredFieldMessage = reqFieldMessage !== null && reqFieldMessage !== void 0 ? reqFieldMessage : (_a = this.formConfig) === null || _a === void 0 ? void 0 : _a.formStandardErrors.requiredField;
4068
+ const numErrors = this.tagFieldsWithError(requiredFieldMessage, this.getRequiredEmptyFields(null, sectionCode));
4069
+ return (numErrors === 0);
4070
+ }
4071
+ validateSectionConsistency(sectionCode, reqFieldMessage) {
4072
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
4073
+ this.resetError();
4074
+ const completeFields = this.checkSectionRequiredFields(sectionCode, reqFieldMessage);
4075
+ if (!completeFields) {
4076
+ this.setError((_a = this.formConfig) === null || _a === void 0 ? void 0 : _a.formStandardErrors.typeWarning, (_b = this.formConfig) === null || _b === void 0 ? void 0 : _b.formStandardErrors.validationTitle, (_c = this.formConfig) === null || _c === void 0 ? void 0 : _c.formStandardErrors.requiredFields);
4077
+ return false;
4078
+ }
4079
+ let validationError = false;
4080
+ const requiredEmptyFields = (_d = this.getRequiredEmptyFields(null, sectionCode)) !== null && _d !== void 0 ? _d : [];
4081
+ if ((requiredEmptyFields === null || requiredEmptyFields === void 0 ? void 0 : requiredEmptyFields.length) > 0) {
4082
+ validationError = true;
4083
+ this.setError((_e = this.formConfig) === null || _e === void 0 ? void 0 : _e.formStandardErrors.typeWarning, (_f = this.formConfig) === null || _f === void 0 ? void 0 : _f.formStandardErrors.validationTitle, (_g = this.formConfig) === null || _g === void 0 ? void 0 : _g.formStandardErrors.requiredFields);
4084
+ this.tagFieldsWithError((_h = this.formConfig) === null || _h === void 0 ? void 0 : _h.formStandardErrors.requiredField, requiredEmptyFields);
4085
+ for (const code of requiredEmptyFields) {
4086
+ const requiredEmptyField = this.getField(code);
4087
+ requiredEmptyField === null || requiredEmptyField === void 0 ? void 0 : requiredEmptyField.focus();
4088
+ break;
4089
+ }
4090
+ }
4091
+ const validationIssueFields = (_j = this.getFieldsWithValidationIssues(null, sectionCode)) !== null && _j !== void 0 ? _j : [];
4092
+ if (!validationError && validationIssueFields.length > 0) {
4093
+ validationError = true;
4094
+ this.setError((_k = this.formConfig) === null || _k === void 0 ? void 0 : _k.formStandardErrors.typeWarning, (_l = this.formConfig) === null || _l === void 0 ? void 0 : _l.formStandardErrors.validationTitle, (_m = this.formConfig) === null || _m === void 0 ? void 0 : _m.formStandardErrors.validationFields);
4095
+ for (const code of validationIssueFields) {
4096
+ const validationIssueField = this.getField(code);
4097
+ if (validationIssueField) {
4098
+ validationIssueField.focus();
4099
+ }
4100
+ break;
4101
+ }
4102
+ }
4103
+ return validationError;
4104
+ }
4105
+ copyTableRecordToFields(tableObj, mappingTable = null) {
4106
+ var _a, _b;
4107
+ const tableObject = this.getTable(tableObj.tableCode);
4108
+ const tableRecord = tableObject === null || tableObject === void 0 ? void 0 : tableObject.getTableRecord(tableObj.recordId);
4109
+ const columnNames = tableObject === null || tableObject === void 0 ? void 0 : tableObject.columnNames;
4110
+ if (tableRecord && columnNames) {
4111
+ for (const columnName of columnNames) {
4112
+ const columnValue = (_a = tableRecord.getFieldValue(columnName)) !== null && _a !== void 0 ? _a : '';
4113
+ const code = (_b = mappingTable === null || mappingTable === void 0 ? void 0 : mappingTable[columnName]) !== null && _b !== void 0 ? _b : columnName;
4114
+ this.setFieldValue(code, columnValue);
4115
+ }
4116
+ return true;
4117
+ }
4118
+ return false;
4119
+ }
4120
+ notifyFormActivity() { this._eventEmiter.next('formActivity', { code: this.formCode }); }
4121
+ /**
4122
+ * Métodos Legacy de compatibilidad hacia atrás
4123
+ */
4124
+ /**
4125
+ * @deprecated Use onSectionActivation
4126
+ */
4127
+ addSectionActivation(codes, callback, properties = null) {
4128
+ return this.onSectionActivation(codes, callback, properties);
4129
+ }
4130
+ /**
4131
+ * @deprecated Use onSectionInactivation
4132
+ */
4133
+ addSectionInactivation(codes, callback, properties = null) {
4134
+ return this.onSectionInactivation(codes, callback, properties);
4135
+ }
4136
+ /**
4137
+ * @deprecated Use onActionStart
4138
+ */
4139
+ addActionMethodStart(codes, callback, properties = null) {
4140
+ return this.onActionStart(codes, callback, properties);
4141
+ }
4142
+ /**
4143
+ * @deprecated Use onActionFinish
4144
+ */
4145
+ addActionMethodFinish(codes, callback, properties = null) {
4146
+ return this.onActionFinish(codes, callback, properties);
4147
+ }
4148
+ /**
4149
+ * @deprecated Use onFieldInput
4150
+ */
4151
+ addFieldInputValidation(codes, callback, properties = null) {
4152
+ return this.onFieldInput(codes, callback, properties);
4153
+ }
4154
+ /**
4155
+ * @deprecated Use onFieldValidationStart
4156
+ */
4157
+ addFieldValidationStart(codes, callback, properties = null) {
4158
+ return this.onFieldValidationStart(codes, callback, properties);
4159
+ }
4160
+ /**
4161
+ * @deprecated Use onFieldValidationFinish
4162
+ */
4163
+ addFieldValidationFinish(codes, callback, properties = null) {
4164
+ return this.onFieldValidationFinish(codes, callback, properties);
4165
+ }
4166
+ /**
4167
+ * @deprecated Use onTableActionStart
4168
+ */
4169
+ addTableActionStart(code, actionCode, callback, properties = null) {
4170
+ return this.onTableActionStart(code, actionCode, callback, properties);
4171
+ }
4172
+ /**
4173
+ * @deprecated Use onTableActionFinish
4174
+ */
4175
+ addTableActionFinish(code, actionCode, callback, properties = null) {
4176
+ return this.onTableActionFinish(code, actionCode, callback, properties);
4177
+ }
4178
+ /**
4179
+ * @deprecated Use onTableSelectionStart
4180
+ */
4181
+ addTableSelectionStart(code, callback, properties = null) {
4182
+ return this.onTableSelectionStart(code, callback, properties);
4183
+ }
4184
+ /**
4185
+ * @deprecated Use onTableSelectionFinish
4186
+ */
4187
+ addTableSelectionFinish(code, callback, properties = null) {
4188
+ return this.onTableSelectionFinish(code, callback, properties);
4189
+ }
4190
+ /**
4191
+ * @deprecated Use onTableGetDataStart
4192
+ */
4193
+ addTableGetDataStart(code, callback, properties = null) {
4194
+ return this.onTableGetDataStart(code, callback, properties);
4195
+ }
4196
+ /**
4197
+ * @deprecated Use onTableGetDataFinish
4198
+ */
4199
+ addTableGetDataFinish(code, callback, properties = null) {
4200
+ return this.onTableGetDataFinish(code, callback, properties);
4201
+ }
4202
+ }
4203
+ BasicFormComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BasicFormComponent, deps: [{ token: LibFormManagerService }, { token: LibEventManagerService }, { token: LibFileManagementService }], target: i0.ɵɵFactoryTarget.Component });
4204
+ BasicFormComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: BasicFormComponent, selector: "ng-component", ngImport: i0, template: `<ng-content></ng-content>`, isInline: true });
4205
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: BasicFormComponent, decorators: [{
4206
+ type: Component,
4207
+ args: [{
4208
+ template: `<ng-content></ng-content>`
4209
+ }]
4210
+ }], ctorParameters: function () { return [{ type: LibFormManagerService }, { type: LibEventManagerService }, { type: LibFileManagementService }]; } });
4211
+
4212
+ const COMPONENTS = [
4213
+ BasicFormComponent,
4214
+ ActionComponent,
4215
+ FieldComponent,
4216
+ ElementComponent,
4217
+ FormErrorComponent,
4218
+ FormHeaderComponent,
4219
+ SectionComponent,
4220
+ SubSectionComponent,
4221
+ LibTableRecordActionComponent,
4222
+ LibTableRecordFieldComponent,
4223
+ LibTableComponent
4224
+ ];
4225
+ class TuainNgFormsLibModule {
4226
+ }
4227
+ TuainNgFormsLibModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: TuainNgFormsLibModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
4228
+ TuainNgFormsLibModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.6", ngImport: i0, type: TuainNgFormsLibModule, declarations: [BasicFormComponent,
4229
+ ActionComponent,
4230
+ FieldComponent,
4231
+ ElementComponent,
4232
+ FormErrorComponent,
4233
+ FormHeaderComponent,
4234
+ SectionComponent,
4235
+ SubSectionComponent,
4236
+ LibTableRecordActionComponent,
4237
+ LibTableRecordFieldComponent,
4238
+ LibTableComponent], imports: [CommonModule,
4239
+ RouterModule,
4240
+ FormsModule], exports: [BasicFormComponent,
4241
+ ActionComponent,
4242
+ FieldComponent,
4243
+ ElementComponent,
4244
+ FormErrorComponent,
4245
+ FormHeaderComponent,
4246
+ SectionComponent,
4247
+ SubSectionComponent,
4248
+ LibTableRecordActionComponent,
4249
+ LibTableRecordFieldComponent,
4250
+ LibTableComponent] });
4251
+ TuainNgFormsLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: TuainNgFormsLibModule, imports: [CommonModule,
4252
+ RouterModule,
4253
+ FormsModule] });
4254
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: TuainNgFormsLibModule, decorators: [{
4255
+ type: NgModule,
4256
+ args: [{
4257
+ declarations: COMPONENTS,
4258
+ imports: [
4259
+ CommonModule,
4260
+ RouterModule,
4261
+ FormsModule,
4262
+ ],
4263
+ exports: COMPONENTS
4264
+ }]
4265
+ }] });
4266
+
4267
+ /*
4268
+ * Public API Surface of tuain-ng-forms-lib
4269
+ */
4270
+
4271
+ /**
4272
+ * Generated bundle index. Do not edit.
4273
+ */
4274
+
4275
+ export { ActionComponent, BasicFormComponent, ElementComponent, FieldComponent, FormErrorComponent, FormHeaderComponent, LibEventManagerService, LibFileManagementService, LibFormManagerService, LibTableComponent, LibTableRecordActionComponent, LibTableRecordFieldComponent, SectionComponent, SubSectionComponent, TuainNgFormsLibModule };
4276
+ //# sourceMappingURL=tuain-ng-forms-lib.mjs.map