tuain-ng-forms-lib 14.4.91 → 14.4.93

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