tuain-ng-forms-lib 12.0.89 → 13.0.1

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