tuain-ng-forms-lib 13.0.15 → 14.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) 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.0-9cb6dc5030-8c4aa6a3c5.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 -26
  9. package/src/lib/classes/forms/action.ts +55 -0
  10. package/src/lib/classes/forms/element.ts +98 -0
  11. package/src/lib/classes/forms/field.ts +408 -0
  12. package/src/lib/classes/forms/form.constants.ts +28 -0
  13. package/src/lib/classes/forms/form.ts +495 -0
  14. package/src/lib/classes/forms/section.ts +154 -0
  15. package/src/lib/classes/forms/subsection.ts +91 -0
  16. package/src/lib/classes/forms/table/action.ts +41 -0
  17. package/src/lib/classes/forms/table/column.ts +91 -0
  18. package/src/lib/classes/forms/table/row-data.ts +118 -0
  19. package/src/lib/classes/forms/table/table.ts +438 -0
  20. package/src/lib/components/elements/action.component.ts +53 -0
  21. package/src/lib/components/elements/field.component.ts +118 -0
  22. package/src/lib/components/elements/layout/element.component.ts +28 -0
  23. package/src/lib/components/elements/layout/form-error.component.ts +11 -0
  24. package/src/lib/components/elements/layout/form-header.component.ts +17 -0
  25. package/src/lib/components/elements/layout/section.component.ts +16 -0
  26. package/src/lib/components/elements/layout/sub-section.component.ts +17 -0
  27. package/src/lib/components/elements/tables/table-record-action.component.ts +37 -0
  28. package/src/lib/components/elements/tables/table-record-field.component.ts +19 -0
  29. package/src/lib/components/elements/tables/table.component.ts +102 -0
  30. package/src/lib/components/forms/basic-form.ts +1496 -0
  31. package/src/lib/services/event-manager.service.ts +21 -0
  32. package/src/lib/services/file-manager.service.ts +6 -0
  33. package/src/lib/services/form-manager.service.ts +89 -0
  34. package/src/lib/services/icon-dictionary.service.ts +159 -0
  35. package/src/lib/tuain-ng-forms-lib.module.ts +40 -0
  36. package/{public-api.d.ts → src/public-api.ts} +5 -0
  37. package/src/test.ts +27 -0
  38. package/tsconfig.lib.json +15 -0
  39. package/tsconfig.lib.prod.json +10 -0
  40. package/tsconfig.spec.json +17 -0
  41. package/esm2020/lib/classes/forms/action.mjs +0 -35
  42. package/esm2020/lib/classes/forms/element.mjs +0 -76
  43. package/esm2020/lib/classes/forms/field.mjs +0 -321
  44. package/esm2020/lib/classes/forms/form.constants.mjs +0 -26
  45. package/esm2020/lib/classes/forms/form.mjs +0 -422
  46. package/esm2020/lib/classes/forms/section.mjs +0 -132
  47. package/esm2020/lib/classes/forms/subsection.mjs +0 -70
  48. package/esm2020/lib/classes/forms/table/action.mjs +0 -22
  49. package/esm2020/lib/classes/forms/table/column.mjs +0 -61
  50. package/esm2020/lib/classes/forms/table/row-data.mjs +0 -111
  51. package/esm2020/lib/classes/forms/table/table.mjs +0 -372
  52. package/esm2020/lib/components/elements/action.component.mjs +0 -58
  53. package/esm2020/lib/components/elements/field.component.mjs +0 -90
  54. package/esm2020/lib/components/elements/layout/element.component.mjs +0 -31
  55. package/esm2020/lib/components/elements/layout/form-error.component.mjs +0 -20
  56. package/esm2020/lib/components/elements/layout/form-header.component.mjs +0 -30
  57. package/esm2020/lib/components/elements/layout/section.component.mjs +0 -22
  58. package/esm2020/lib/components/elements/layout/sub-section.component.mjs +0 -24
  59. package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +0 -40
  60. package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +0 -25
  61. package/esm2020/lib/components/elements/tables/table.component.mjs +0 -95
  62. package/esm2020/lib/components/forms/basic-form.mjs +0 -1425
  63. package/esm2020/lib/services/event-manager.service.mjs +0 -18
  64. package/esm2020/lib/services/file-manager.service.mjs +0 -6
  65. package/esm2020/lib/services/form-manager.service.mjs +0 -80
  66. package/esm2020/lib/tuain-ng-forms-lib.module.mjs +0 -73
  67. package/esm2020/public-api.mjs +0 -19
  68. package/esm2020/tuain-ng-forms-lib.mjs +0 -5
  69. package/fesm2015/tuain-ng-forms-lib.mjs +0 -3805
  70. package/fesm2015/tuain-ng-forms-lib.mjs.map +0 -1
  71. package/fesm2020/tuain-ng-forms-lib.mjs +0 -3636
  72. package/fesm2020/tuain-ng-forms-lib.mjs.map +0 -1
  73. package/lib/classes/forms/action.d.ts +0 -22
  74. package/lib/classes/forms/element.d.ts +0 -41
  75. package/lib/classes/forms/field.d.ts +0 -109
  76. package/lib/classes/forms/form.constants.d.ts +0 -25
  77. package/lib/classes/forms/form.d.ts +0 -134
  78. package/lib/classes/forms/section.d.ts +0 -39
  79. package/lib/classes/forms/subsection.d.ts +0 -26
  80. package/lib/classes/forms/table/action.d.ts +0 -20
  81. package/lib/classes/forms/table/column.d.ts +0 -33
  82. package/lib/classes/forms/table/row-data.d.ts +0 -14
  83. package/lib/classes/forms/table/table.d.ts +0 -100
  84. package/lib/components/elements/action.component.d.ts +0 -21
  85. package/lib/components/elements/field.component.d.ts +0 -43
  86. package/lib/components/elements/layout/element.component.d.ts +0 -14
  87. package/lib/components/elements/layout/form-error.component.d.ts +0 -8
  88. package/lib/components/elements/layout/form-header.component.d.ts +0 -12
  89. package/lib/components/elements/layout/section.component.d.ts +0 -10
  90. package/lib/components/elements/layout/sub-section.component.d.ts +0 -11
  91. package/lib/components/elements/tables/table-record-action.component.d.ts +0 -15
  92. package/lib/components/elements/tables/table-record-field.component.d.ts +0 -11
  93. package/lib/components/elements/tables/table.component.d.ts +0 -47
  94. package/lib/components/forms/basic-form.d.ts +0 -307
  95. package/lib/services/event-manager.service.d.ts +0 -9
  96. package/lib/services/file-manager.service.d.ts +0 -5
  97. package/lib/services/form-manager.service.d.ts +0 -28
  98. package/lib/tuain-ng-forms-lib.module.d.ts +0 -20
  99. package/tuain-ng-forms-lib.d.ts +0 -5
@@ -0,0 +1,1496 @@
1
+ import { Component } from '@angular/core';
2
+ import { FormStructureAndData } from '../../classes/forms/form';
3
+ import { LibFormManagerService } from '../../services/form-manager.service';
4
+ import { LibEventManagerService } from '../../services/event-manager.service';
5
+ import { LibFileManagementService } from '../../services/file-manager.service';
6
+ import { formActions, NO_ERROR, HEADER } from '../../classes/forms/form.constants';
7
+ import { FormAction } from '../../classes/forms/action';
8
+ import { FieldDescriptor, FieldOption } from '../../classes/forms/field';
9
+ import { RecordTable } from '../../classes/forms/table/table';
10
+ import { RecordFormSection } from '../../classes/forms/section';
11
+ import { RecordFormSubSection } from '../../classes/forms/subsection';
12
+
13
+ const PAYLOAD_VERSION = 'TUAINEXCHANGE_1.0';
14
+ const INLINE_ACTION = 'INLINE';
15
+ const GLOBAL_ACTION = 'GLOBAL';
16
+ const GET_DATA_ACTION = 'GETDATA';
17
+
18
+ const SUBJECT = 'subject';
19
+ const TOKEN = 'token';
20
+
21
+ @Component({
22
+ template: `<ng-content></ng-content>`
23
+ })
24
+ export class BasicFormComponent {
25
+ private _formStructure: FormStructureAndData | null = null;
26
+ private _controlToken: string | null = null;
27
+ private _originToken: string | null = null;
28
+ private _formRoute: string | null = null;
29
+ private _definitionObtained: boolean = false;
30
+ // Eventos de acciones y campos
31
+ private _formSectionsActivate: any = {};
32
+ private _formSectionsInactivate: any = {};
33
+ private _formActionsStart: any = {};
34
+ private _formActionsFinish: any = {};
35
+ private _fieldInputValidation: any = {};
36
+ private _fieldValidationsStart: any = {};
37
+ private _fieldValidationsFinish: any = {};
38
+ // Callback de acciones de tablas
39
+ private _tableSelectionsStart: any = {};
40
+ private _tableSelectionsFinish: any = {};
41
+ private _tableActionsStart: any = {};
42
+ private _tableActionsFinish: any = {};
43
+ private _tableGetDataStart: any = {};
44
+ private _tableGetDataFinish: any = {};
45
+
46
+ private _actionServerError: any[] = [];
47
+ private _fieldServerError: any[] = [];
48
+ private _tableServerError: any[] = [];
49
+
50
+ protected inputDataFields: any = {};
51
+ protected extraData: any = {};
52
+ protected _eventEmiter: LibEventManagerService;
53
+ protected enabledSections: RecordFormSection[] = [];
54
+
55
+ formConfig: any;
56
+ name: string | null = null;
57
+ formSubject: string | null = null;
58
+ _errorType: string = '';
59
+ errorCode: string = '';
60
+ errorFullCode: string = '';
61
+ errorName: string = '';
62
+ errorMessage: string = '';
63
+ errorDetail: string = '';
64
+ visible: boolean = false;
65
+
66
+ fields: any;
67
+ actions: any;
68
+ sections: any;
69
+ busy: boolean = false;
70
+
71
+ getTitle() { return this._formStructure?.getTitle(); }
72
+ setTitle(title: string) { return this._formStructure?.setTitle(title); }
73
+ cleanData() { return this._formStructure?.cleanData(); }
74
+ getCurrentState() { return this._formStructure?.getCurrentState(); }
75
+ supportState(state: string | null) { return this._formStructure?.supportState(state ?? '') ?? false; }
76
+ changeState(state): boolean { return this._formStructure?.changeState(state) ?? false; }
77
+ getStates() { return this._formStructure?.states; }
78
+ getImmutableElement(name: string) { return this._formStructure?.getImmutableElement(name); }
79
+ getExtraInfo(name: string) { return this._formStructure?.getExtraInfo(name); }
80
+ getFields() { return this._formStructure?.getFields() ?? null; }
81
+ getFieldNames() { return this._formStructure?.getFieldNames() ?? null; }
82
+ getField(code: string) { return this._formStructure?.getField(code) ?? null; }
83
+ enableField(code: string) { return this._formStructure?.enableField(code); }
84
+ disableField(code: string) { return this._formStructure?.disableField(code); }
85
+ getFieldValue(code: string): any { return this._formStructure?.getFieldValue(code) ?? null; }
86
+ getFieldOptionText(code: string): any { return this._formStructure?.getFieldOptionText(code); }
87
+ getFieldsValues(codes: string[]) { return this._formStructure?.getFieldsValues(codes) ?? null; }
88
+ getFieldOptions(code: string): FieldOption[] | null { return this._formStructure?.getFieldOptions(code) ?? null; }
89
+ setFieldValue(code: string, value: any) { return this._formStructure?.setFieldValue(code, value); }
90
+ setFieldRequired(code: string, required: boolean) { return this._formStructure?.setFieldRequired(code, required); }
91
+ setFieldErrorMessage(code: string, errorMessage: string) { return this._formStructure?.setFieldErrorMessage(code, errorMessage); }
92
+ setFieldError(code: string, errorCode: string, message: string, type?: string) { return this._formStructure?.setFieldError(code, errorCode, message, type); }
93
+ setFieldIntrinsicErrorMessage(code: string, message: string) {
94
+ return this._formStructure?.setFieldIntrinsicErrorMessage(code, message);
95
+ }
96
+ setFieldOptions(code, optionsArray, idAttribute, nameAttribute) {
97
+ return this._formStructure?.setFieldOptions(code, optionsArray, idAttribute, nameAttribute);
98
+ }
99
+ getFieldSet(filterFunc?, codes?: string[] | string | null, secCode?: string | null, subCode?: string | null) {
100
+ return this._formStructure?.getFieldSet(filterFunc, codes ?? null, secCode ?? null, subCode ?? null);
101
+ }
102
+ applyOnFields(processFunc, codes?: string[] | string | null, secCode?: string, subCode?: string) {
103
+ return this._formStructure?.applyOnFields(processFunc, codes, secCode, subCode);
104
+ }
105
+ applyProcessToAllFields(processFunc) {
106
+ return this._formStructure?.applyOnFields(processFunc);
107
+ }
108
+ cleanFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
109
+ return this._formStructure?.cleanFields(codes, secCode, subCode);
110
+ }
111
+ getRequiredFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
112
+ return this._formStructure?.getRequiredFields(codes, secCode, subCode);
113
+ }
114
+ getRequiredEmptyFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
115
+ return this._formStructure?.getRequiredEmptyFields(codes, secCode, subCode) ?? null;
116
+ }
117
+ getChangedFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
118
+ return this._formStructure?.getChangedFields(codes, secCode, subCode);
119
+ }
120
+ getFieldsWithValidationIssues(codes?: string[] | string | null, secCode?: string, subCode?: string) {
121
+ return this._formStructure?.getFieldsWithValidationIssues(codes, secCode, subCode);
122
+ }
123
+ tagFieldsWithError(errorMessage: string, codes?: string[] | string | null, secCode?: string, subCode?: string) {
124
+ return this._formStructure?.tagFieldsWithError(errorMessage, codes, secCode, subCode);
125
+ }
126
+ cleanErrorFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
127
+ return this._formStructure?.cleanErrorFields(codes, secCode, subCode);
128
+ }
129
+ showLabelFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
130
+ return this._formStructure?.showLabelFields(codes, secCode, subCode);
131
+ }
132
+ hideLabelFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
133
+ return this._formStructure?.hideLabelFields(codes, secCode, subCode);
134
+ }
135
+ enableFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
136
+ return this._formStructure?.enableFields(codes, secCode, subCode);
137
+ }
138
+ disableFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
139
+ return this._formStructure?.disableFields(codes, secCode, subCode);
140
+ }
141
+ /**
142
+ * @deprecated Use enableFields
143
+ */
144
+ enableEditFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
145
+ return this.enableFields(codes, secCode, subCode);
146
+ }
147
+ /**
148
+ * @deprecated Use disableFields
149
+ */
150
+ disableEditFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
151
+ return this.disableFields(codes, secCode, subCode);
152
+ }
153
+ showFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
154
+ return this._formStructure?.showFields(codes, secCode, subCode);
155
+ }
156
+ hideFields(codes?: string[] | string | null, secCode?: string, subCode?: string) {
157
+ return this._formStructure?.hideFields(codes, secCode, subCode);
158
+ }
159
+ getActionsByAttribute(name: string, value) {
160
+ return this._formStructure?.getActionsByAttribute(name, value);
161
+ }
162
+ getHeaderActions() {
163
+ return this._formStructure?.getActionsByAttribute('location', HEADER);
164
+ }
165
+ getAction(actionCode: string): FormAction | null {
166
+ return this._formStructure?.getAction(actionCode) ?? null;
167
+ }
168
+ showActions(actionArray): void {
169
+ return this._formStructure?.showActions(actionArray);
170
+ }
171
+ hideActions(actionArray): void {
172
+ return this._formStructure?.hideActions(actionArray);
173
+ }
174
+ enableActions(actionArray): void {
175
+ return this._formStructure?.enableActions(actionArray);
176
+ }
177
+ disableActions(actionArray): void {
178
+ return this._formStructure?.disableActions(actionArray);
179
+ }
180
+ showAction(code: string): void {
181
+ return this._formStructure?.showActions(code);
182
+ }
183
+ hideAction(code: string): void {
184
+ return this._formStructure?.hideActions(code);
185
+ }
186
+ enableAction(code: string): void {
187
+ return this._formStructure?.enableActions(code);
188
+ }
189
+ disableAction(code: string): void {
190
+ return this._formStructure?.disableActions(code);
191
+ }
192
+ getSections(): RecordFormSection[] | null {
193
+ return this._formStructure?.getSections() ?? null;
194
+ }
195
+ activateSection(code): void {
196
+ return this._formStructure?.activateSection(code);
197
+ }
198
+ getSectionsTitles(): string[] | null {
199
+ return this._formStructure?.getSections().map(sec => sec.title) ?? null;
200
+ }
201
+ getSection(code: string): RecordFormSection | null {
202
+ return this._formStructure?.getSection(code) ?? null;
203
+ }
204
+ showSection(code: string): void {
205
+ return this._formStructure?.showSections(code);
206
+ }
207
+ hideSection(code: string): void {
208
+ return this._formStructure?.hideSections(code);
209
+ }
210
+ showSections(codes: string[] | string): void {
211
+ return this._formStructure?.showSections(codes);
212
+ }
213
+ hideSections(codes: string[] | string): void {
214
+ return this._formStructure?.hideSections(codes);
215
+ }
216
+ getSubSection(code: string, subCode: string): RecordFormSubSection | null {
217
+ return this._formStructure?.getSubSection(code, subCode) ?? null;
218
+ }
219
+ showSubSection(code: string, subCode: string): void {
220
+ return this._formStructure?.showSubSections(code, subCode);
221
+ }
222
+ hideSubSection(code: string, subCode: string): void {
223
+ return this._formStructure?.hideSubSections(code, subCode);
224
+ }
225
+ showSubSections(code: string, subCodes: string[] | string): void {
226
+ return this._formStructure?.showSubSections(code, subCodes);
227
+ }
228
+ hideSubSections(code: string, subCodes: string[] | string): void {
229
+ return this._formStructure?.hideSubSections(code, subCodes);
230
+ }
231
+ getSectionActions(code: string): FormAction[] | null {
232
+ return this._formStructure?.getSectionActions(code) ?? null;
233
+ }
234
+ getSectionActionNames(code: string): string[] | null {
235
+ return this._formStructure?.getSectionActionNames(code) ?? null;
236
+ }
237
+
238
+ getTables() {
239
+ return this._formStructure?.getTables();
240
+ }
241
+ showTables(codes: string[] | string) {
242
+ return this._formStructure?.showTables(codes);
243
+ }
244
+ hideTables(codes: string[] | string) {
245
+ return this._formStructure?.hideTables(codes);
246
+ }
247
+ cleanTables(codes: string[] | string) {
248
+ return this._formStructure?.cleanTables(codes);
249
+ }
250
+ getTable(code: string) {
251
+ return this._formStructure?.getTable(code) ?? null;
252
+ }
253
+ showTable(code: string) {
254
+ return this._formStructure?.showTables(code);
255
+ }
256
+ hideTable(code: string) {
257
+ return this._formStructure?.hideTables(code);
258
+ }
259
+ cleanTable(code: string) {
260
+ return this._formStructure?.getTable(code)?.clean();
261
+ }
262
+ getTableRecord(code: string, recordId: any) {
263
+ return this._formStructure?.getTableRecord(code, recordId);
264
+ }
265
+
266
+ constructor(
267
+ protected formManagerService: LibFormManagerService,
268
+ protected _eventManager: LibEventManagerService,
269
+ protected fileMgmtServices: LibFileManagementService) {
270
+ this._eventEmiter = this._eventManager;
271
+ this.cleanStart();
272
+ this.customPreProcessing();
273
+ }
274
+
275
+ setConfig(formConfig) {
276
+ this.formConfig = formConfig;
277
+ }
278
+
279
+ cleanStart() {
280
+ this._errorType = '';
281
+ this.errorCode = '';
282
+ this.errorFullCode = '';
283
+ this.errorName = '';
284
+ this.errorMessage = '';
285
+ this.errorDetail = '';
286
+ this._formStructure = null;
287
+ this.fields = null;
288
+ this.actions = null;
289
+ this.sections = null;
290
+ this._controlToken = null;
291
+ this.inputDataFields = {};
292
+ this._definitionObtained = false;
293
+ // Se limpian los manejadores de eventos
294
+ this.visible = false;
295
+ this.busy = false;
296
+ this._formSectionsActivate = {};
297
+ this._formSectionsInactivate = {};
298
+ this._formActionsStart = {};
299
+ this._formActionsFinish = {};
300
+ this._fieldInputValidation = {};
301
+ this._fieldValidationsStart = {};
302
+ this._fieldValidationsFinish = {};
303
+ this._tableSelectionsStart = {};
304
+ this._tableSelectionsFinish = {};
305
+ this._tableActionsStart = {};
306
+ this._tableActionsFinish = {};
307
+ this._tableGetDataStart = {};
308
+ this._tableGetDataFinish = {};
309
+
310
+ this._actionServerError = [];
311
+ this._fieldServerError = [];
312
+ this._tableServerError = [];
313
+
314
+ this.onActionServerError(() => this.displayActionServerError());
315
+ this.onValidationServerError(() => this.displayValidationServerError());
316
+ this.onTableServerError(() => this.displayTableServerError());
317
+ }
318
+
319
+ get formVisible(): boolean { return this.visible; }
320
+ get formManager() { return this; }
321
+ get formCode(): string { return this.name ?? ''; }
322
+ set formCode(name: string) { this.name = name; }
323
+ get inServerProcess() { return this.busy; }
324
+ get form(): FormStructureAndData | null { return this._formStructure; }
325
+
326
+ get state(): string | null { return this._formStructure?.state ?? null; }
327
+ get currentState(): string { return this._formStructure?.state ?? ''; }
328
+ set currentState(state: string) { this?._formStructure?.changeState(state); }
329
+ get immutableData(): any { return this._formStructure?.immutableData }
330
+ get extraInfo(): any { return this._formStructure?.extraInfo }
331
+ get visibleSections(): RecordFormSection[] | null { return this._formStructure?.visibleSections ?? null; }
332
+
333
+ get formRoute(): string { return this._formRoute ?? ''; }
334
+ set formRoute(route: string) { this._formRoute = route; }
335
+
336
+ get subject(): string { return this.formSubject ?? ''; }
337
+
338
+ // Métodos virtuales
339
+ customPreProcessing() { }
340
+ customFormStart() { }
341
+ displayActionServerError() { }
342
+ displayValidationServerError() { }
343
+ displayTableServerError() { }
344
+ showFieldInfo(fieldCode?: string, detail?: any) { }
345
+ showModalDialog(title, body, options, callback?, params?) { }
346
+ openUploadDialog(title, body, options, callback?, params?) { }
347
+
348
+ /**
349
+ * @deprecated Use supportState
350
+ */
351
+ supportMode(state: string): boolean { return this.supportState(state); }
352
+
353
+ /**
354
+ * @deprecated Use getField
355
+ */
356
+ getFieldObject(code: string): FieldDescriptor | null { return this.getField(code); }
357
+
358
+ /**
359
+ * @deprecated Use getAction
360
+ */
361
+ getActionObject(code: string): FormAction | null { return this.getAction(code); }
362
+
363
+ /**
364
+ * @deprecated Use getTable
365
+ */
366
+ getTableObject(code: string): RecordTable | null { return this.getTable(code); }
367
+
368
+ /**
369
+ * @deprecated Use getSection
370
+ */
371
+ getSectionObject(code: string): RecordFormSection | null { return this.getSection(code); }
372
+
373
+ /**
374
+ * @deprecated Use changeState
375
+ */
376
+ changeFormMode(state: string): boolean { return this.changeState(state); }
377
+
378
+ /**
379
+ * @deprecated Use subject
380
+ */
381
+ getFormSubject(): string { return this.subject; }
382
+ /**
383
+ * @deprecated Use subject
384
+ */
385
+ getSubject(): string { return this.formSubject ?? ''; }
386
+ /**
387
+ * @deprecated Use subject
388
+ */
389
+ getformSubject(): string { return this.formSubject ?? ''; }
390
+
391
+
392
+ numSections(): number { return this._formStructure?.sections.length; }
393
+
394
+ subscribeAppEvent(eventName: string, callback): void {
395
+ this._eventEmiter.subscribe(eventName, callback);
396
+ }
397
+
398
+ openForm(name: string, data: any = null, backData: any = null, cleanStack = false): void {
399
+ let origin: any = null;
400
+ if (!cleanStack) {
401
+ origin = { ...backData, name: this.name, url: this._formRoute, token: this._controlToken };
402
+ origin.subject = origin?.subject ?? this.formSubject;
403
+ origin.state = origin?.state ?? this.state;
404
+ origin.fields = origin?.fields ?? {};
405
+ origin.extra = origin?.extra ?? {};
406
+ }
407
+ const target = { ...data, name };
408
+ target.subject = target?.subject ?? null;
409
+ target.state = target?.state ?? null;
410
+ target.fields = target?.fields ?? {};
411
+ target.extra = target?.extra ?? {};
412
+ this.formManagerService.openForm(origin, target);
413
+ }
414
+
415
+ canGoBack(): boolean { return this._originToken !== null }
416
+ goBack(): void { return this.formManagerService.backTo(); }
417
+ goBackForm(): void { return this.goBack(); }
418
+ getOriginDetail(): any { return this.formManagerService?.getFormInfo(this._originToken ?? ''); }
419
+
420
+ setError(errorType: string | null, errorMessage: string | null, errorDetail: string | null): void {
421
+ this._errorType = errorType || '';
422
+ this.errorMessage = errorMessage || '';
423
+ this.errorDetail = errorDetail || '';
424
+ }
425
+
426
+ resetError(): void {
427
+ this.errorCode = NO_ERROR;
428
+ this.errorFullCode = '';
429
+ this.errorName = '';
430
+ this.errorMessage = '';
431
+ this.errorDetail = '';
432
+ }
433
+
434
+ getErrorType(): string { return this._errorType; }
435
+ getErrorMessage(): string { return this.errorMessage; }
436
+ getErrorDetail(): string { return this.errorDetail; }
437
+ getErrorName(): string { return this.errorName; }
438
+ getErrorFullCode(): string { return this.errorFullCode; }
439
+ getErrorCode(): string { return this.errorCode; }
440
+
441
+ getFormParameter(name: string): string {
442
+ return (name) ? (this.extraData?.[name] ?? null) : null;
443
+ }
444
+
445
+ preocessInputParams(params: any): string | null {
446
+ this._controlToken = params?.[TOKEN] ?? null;
447
+ this.formSubject = params?.[SUBJECT] ?? null;
448
+ const tokenInfo: any = (this._controlToken) ? this.formManagerService.getFormInfo(this._controlToken) : {};
449
+ const { token, subject, state, fields, extra, originToken } = tokenInfo;
450
+ if (token && this._controlToken === token) {
451
+ this.formSubject = this.formSubject ?? subject ?? null;
452
+ this.inputDataFields = fields;
453
+ this.extraData = extra;
454
+ this._originToken = originToken;
455
+ return state;
456
+ }
457
+ return null;
458
+ }
459
+
460
+ subscribeSectionActivation(): void {
461
+ const formSections = this._formStructure?.sections;
462
+ const sectionNames = Object.keys(formSections);
463
+ for (let index = 0; index < sectionNames.length; index++) {
464
+ const sectionName = sectionNames[index];
465
+ const section = formSections[sectionName];
466
+ section.activation.subscribe((code: string) => this.launchSectionActivation(code));
467
+ section.inactivation.subscribe((code: string) => this.launchSectionInactivation(code));
468
+ }
469
+ }
470
+
471
+ subscribeFieldsSubjects(): void {
472
+ const formFields = this._formStructure?.getFields();
473
+ if (Array.isArray(formFields)) {
474
+ formFields.forEach(field => {
475
+ field.editionFinish.subscribe(event => {
476
+ const { code, intrinsicValidation } = event;
477
+ this.startFieldValidation(code, intrinsicValidation);
478
+ });
479
+ field.editionPartial.subscribe(event => {
480
+ const { code, intrinsicValidation } = event;
481
+ this.startFieldInputValidation(code, intrinsicValidation);
482
+ });
483
+ field.detailRequest.subscribe(event => this.showFieldInfo(event.code, event.detail));
484
+ });
485
+ }
486
+ }
487
+
488
+ subscribeActionSubjects(): void {
489
+ const formActions = this._formStructure?.getActions();
490
+ if (Array.isArray(formActions)) {
491
+ formActions.forEach(action => {
492
+ action.actionActivated.subscribe(code => this.startAction(code));
493
+ });
494
+ }
495
+ }
496
+
497
+ subscribeTableSubjects(): void {
498
+ const formTables = this._formStructure?.getTables();
499
+ if (Array.isArray(formTables)) {
500
+ formTables.forEach(table => {
501
+ table.inlineActionTrigger.subscribe(event => this.startTableAction(event));
502
+ table.globalActionTrigger.subscribe(event => this.startTableGlobalAction(event));
503
+ table.recordSelectionTrigger.subscribe(event => this.startTableRecordSelection(event));
504
+ table.selectionActionTrigger.subscribe(event => this.startTableSelectionAction(event));
505
+ table.getDataTrigger.subscribe(event => this.startTableGetData(event));
506
+ });
507
+ }
508
+ }
509
+
510
+ async formInit(params): Promise<void> {
511
+ let initialState: string | null = this.preocessInputParams(params);
512
+ if (!this.name) { return; }
513
+ if (!this._definitionObtained) {
514
+ this.busy = true;
515
+ const formDefinition = await this.formManagerService.getFormDefinition(this.name);
516
+ this.busy = false;
517
+ this._formStructure = new FormStructureAndData(formDefinition, this.formConfig);
518
+ this.fields = this._formStructure?.fields;
519
+ this.actions = this._formStructure?.actions;
520
+ this.sections = this._formStructure?.sections;
521
+ this._definitionObtained = true;
522
+ } else {
523
+ this.cleanData();
524
+ }
525
+ if (!this.supportState(initialState)) {
526
+ initialState = this._formStructure?.defaultState ?? null;
527
+ }
528
+ this._formStructure?.changeState(initialState || this._formStructure?.defaultState);
529
+ const inputFieldNames = Object.keys(this.inputDataFields);
530
+ for (let index = 0; index < inputFieldNames.length; index++) {
531
+ const fieldCode = inputFieldNames[index];
532
+ const fieldValue = this.inputDataFields[fieldCode];
533
+ this.setFieldValue(fieldCode, fieldValue);
534
+ }
535
+ const recordResponse = await this.requestFormAction(formActions.getData);
536
+ this.checkErrorRecordReceived(recordResponse);
537
+ this.visible = true;
538
+ this.enabledSections = this._formStructure?.visibleSections ?? [];
539
+ this.subscribeSectionActivation();
540
+ this.subscribeFieldsSubjects();
541
+ this.subscribeActionSubjects();
542
+ this.subscribeTableSubjects();
543
+ this.customFormStart();
544
+ }
545
+
546
+ checkErrorRecordReceived(recordResponse: any): boolean {
547
+ const { error } = recordResponse;
548
+ if (!error) { return false; }
549
+ this.errorCode = recordResponse.errorCode;
550
+ this.errorFullCode = recordResponse.errorFullCode;
551
+ this.errorName = recordResponse.errorName;
552
+ this.errorMessage = recordResponse.errorMessage;
553
+ this.errorDetail = recordResponse.errorDetail;
554
+ return true;
555
+ }
556
+
557
+ errorOccured(): boolean {
558
+ return (this.errorCode !== NO_ERROR);
559
+ }
560
+
561
+ /**
562
+ * Soporte manejo de eventos de formulario
563
+ */
564
+
565
+ async requestFormAction(actionCode: string, actionSubject: any = {}): Promise<any> {
566
+ const actionDetail = {
567
+ formCode: this.name,
568
+ formSubject: this.formSubject,
569
+ currentMode: this._formStructure?.state,
570
+ actionCode,
571
+ actionSubject,
572
+ version: PAYLOAD_VERSION,
573
+ formData: this._formStructure?.getPayload(),
574
+ immutableData: this._formStructure?.immutableData,
575
+ };
576
+ this.errorCode = NO_ERROR;
577
+ this.errorFullCode = '';
578
+ this.errorName = '';
579
+ this.errorMessage = '';
580
+ this.errorDetail = '';
581
+ this.busy = true;
582
+ const formActionResponse: any = await this.formManagerService.execServerAction(actionDetail);
583
+ this.busy = false;
584
+ if (formActionResponse.hasError()) {
585
+ const error = formActionResponse.error;
586
+ this.errorCode = error.errorCode;
587
+ this.errorFullCode = error.errorFullCode;
588
+ this.errorName = error.errorName;
589
+ this.errorMessage = error.errorMessage;
590
+ this.errorDetail = error.errorDetail;
591
+ }
592
+ const formResponseData = formActionResponse.getData();
593
+ this.updateFormWithServerData(formResponseData);
594
+ return formResponseData;
595
+ }
596
+
597
+ updateFormWithServerData(formContent: any) {
598
+ const {
599
+ currentMode, formSubject, actions, fields, recordTables,
600
+ returnedFile, immutableData, extraInfo,
601
+ } = formContent;
602
+ currentMode && this.changeState(currentMode);
603
+ if (formSubject) { this.formSubject = formSubject; }
604
+ if (actions && actions.length > 0) {
605
+ for (const changedAction of actions) {
606
+ const actionObject = this.getAction(changedAction.actionCode);
607
+ if (actionObject) { actionObject.updateFromServer(changedAction); }
608
+ }
609
+ }
610
+ if (fields && fields.length > 0) {
611
+ for (const changedField of fields) {
612
+ const fieldObject = this.getField(changedField.fieldCode);
613
+ if (fieldObject) {
614
+ fieldObject.updateFromServer(changedField);
615
+ }
616
+ }
617
+ }
618
+ if (recordTables && recordTables.length > 0) {
619
+ for (const changedTable of recordTables) {
620
+ const tableObject = this.getTable(changedTable.tableCode);
621
+ if (tableObject) {
622
+ tableObject.updateFromServer(changedTable);
623
+ }
624
+ }
625
+ }
626
+ if (returnedFile && returnedFile.file) {
627
+ this.fileMgmtServices.saveFile(returnedFile.file, returnedFile.name, returnedFile.type);
628
+ }
629
+ if (this._formStructure) {
630
+ this._formStructure.immutableData = immutableData;
631
+ this._formStructure.extraInfo = extraInfo;
632
+ }
633
+ }
634
+
635
+ /**
636
+ * Manejo de event handlers para errores Server del formulario
637
+ */
638
+
639
+ cleanActionServerError() {
640
+ this._actionServerError = [];
641
+ }
642
+
643
+ cleanFieldServerError() {
644
+ this._fieldServerError = [];
645
+ }
646
+
647
+ cleanTableServerError() {
648
+ this._tableServerError = [];
649
+ }
650
+
651
+ onActionServerError(callback, properties = null) {
652
+ this._actionServerError.push({ callback, properties });
653
+ }
654
+
655
+ onValidationServerError(callback, properties = null) {
656
+ this._fieldServerError.push({ callback, properties });
657
+ }
658
+
659
+ onTableServerError(callback, properties = null) {
660
+ this._tableServerError.push({ callback, properties });
661
+ }
662
+
663
+ /**
664
+ * Manejo de event handlers para acciones sobre el formulario
665
+ */
666
+
667
+ onSectionActivation(codes: string[] | string | null, callback, properties = null) {
668
+ const sectionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
669
+ sectionSet.forEach((sectionName) => {
670
+ if (!this._formSectionsActivate[sectionName]) {
671
+ this._formSectionsActivate[sectionName] = [];
672
+ }
673
+ this._formSectionsActivate[sectionName].push({ callback, properties });
674
+ });
675
+ }
676
+
677
+ onSectionInactivation(codes: string[] | string | null, callback, properties = null) {
678
+ const sectionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
679
+ sectionSet.forEach((sectionName) => {
680
+ if (!this._formSectionsInactivate[sectionName]) {
681
+ this._formSectionsInactivate[sectionName] = [];
682
+ }
683
+ this._formSectionsInactivate[sectionName].push({ callback, properties });
684
+ });
685
+ }
686
+
687
+ onActionStart(codes: string[] | string | null, callback, properties = null) {
688
+ const actionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
689
+ actionSet.forEach((actionName) => {
690
+ if (!this._formActionsStart[actionName]) {
691
+ this._formActionsStart[actionName] = [];
692
+ }
693
+ this._formActionsStart[actionName].push({ callback, properties });
694
+ });
695
+ }
696
+
697
+ onActionFinish(codes: string[] | string | null, callback, properties = null) {
698
+ const actionSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
699
+ actionSet.forEach((actionName) => {
700
+ if (!this._formActionsFinish[actionName]) {
701
+ this._formActionsFinish[actionName] = [];
702
+ }
703
+ this._formActionsFinish[actionName].push({ callback, properties });
704
+ });
705
+ }
706
+
707
+ async launchSectionActivation(code: string) {
708
+ const sectionObject = this._formStructure?.getSection(code);
709
+ if (!sectionObject) { return; }
710
+ const clientSectionMethods = this._formSectionsActivate[code];
711
+ if (clientSectionMethods) {
712
+ for (const clientSectionMethod of clientSectionMethods) {
713
+ const { callback, properties } = clientSectionMethod;
714
+ callback(sectionObject);
715
+ }
716
+ }
717
+ }
718
+
719
+ async launchSectionInactivation(code: string) {
720
+ const sectionObject = this._formStructure?.getSection(code);
721
+ if (!sectionObject) { return; }
722
+ const clientSectionMethods = this._formSectionsInactivate[code];
723
+ if (clientSectionMethods) {
724
+ for (const clientSectionMethod of clientSectionMethods) {
725
+ const { callback, properties } = clientSectionMethod;
726
+ callback(sectionObject);
727
+ }
728
+ }
729
+ }
730
+
731
+ async startAction(code: string) {
732
+ const actionObject = this.getAction(code);
733
+ if (!actionObject) { return; }
734
+ this.resetError();
735
+ actionObject.start();
736
+ const clientActionMethods = this._formActionsStart[code];
737
+ if (clientActionMethods) {
738
+ const clientActionPromises: any[] = [];
739
+ for (const clientActionMethod of clientActionMethods) {
740
+ const { callback, properties } = clientActionMethod;
741
+ const continueActionPromise = callback(actionObject);
742
+ clientActionPromises.push(continueActionPromise);
743
+ }
744
+ const clientActionResults = await Promise.all(clientActionPromises);
745
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
746
+ if (!continueAction) {
747
+ actionObject.stop();
748
+ return;
749
+ }
750
+ }
751
+ this.startServerAction(actionObject);
752
+ }
753
+
754
+ async startServerAction(actionInput) {
755
+ const action = (typeof actionInput === 'string')
756
+ ? this.getAction(actionInput) : actionInput;
757
+ let serverError = false;
758
+ let actionResult = null;
759
+ if (action.backend) {
760
+ actionResult = await this.requestFormAction(action.actionCode);
761
+ serverError = !!this.errorOccured();
762
+ }
763
+ await this.finishAction(action, actionResult, serverError);
764
+ if (!serverError) {
765
+ action.newState && this.changeState(action.newState);
766
+ } else {
767
+ for (let index = 0; index < this._actionServerError.length; index++) {
768
+ const { callback, properties } = this._actionServerError[index];
769
+ callback(action);
770
+ }
771
+ }
772
+ action.stop();
773
+ }
774
+
775
+ async finishAction(action, actionResult, serverError = false) {
776
+ const finishActionMethods = this._formActionsFinish[action.actionCode];
777
+ if (finishActionMethods) {
778
+ const clientActionPromises: any[] = [];
779
+ for (const clientActionMethod of finishActionMethods) {
780
+ const { callback, properties } = clientActionMethod;
781
+ const continueOnError = properties?.continueOnError ?? false;
782
+ if (!serverError || continueOnError) {
783
+ clientActionPromises.push(callback(action, actionResult));
784
+ }
785
+ }
786
+ await Promise.all(clientActionPromises);
787
+ }
788
+ }
789
+
790
+ completeGlobalAction(action: any) {
791
+ return this.startServerAction(action);
792
+ }
793
+
794
+ /**
795
+ * Manejadores de eventos para validaciones sobre campos
796
+ */
797
+
798
+ onFieldInput(codes: string[] | string | null, callback, properties = null) {
799
+ const fieldSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
800
+ fieldSet.forEach((fieldCode) => {
801
+ if (!this._fieldInputValidation[fieldCode]) {
802
+ this._fieldInputValidation[fieldCode] = [];
803
+ }
804
+ this._fieldInputValidation[fieldCode].push({ callback, properties });
805
+ });
806
+ }
807
+
808
+ onFieldValidationStart(codes: string[] | string | null, callback, properties = null) {
809
+ const fieldSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
810
+ fieldSet.forEach((fieldCode) => {
811
+ if (!this._fieldValidationsStart[fieldCode]) {
812
+ this._fieldValidationsStart[fieldCode] = [];
813
+ }
814
+ this._fieldValidationsStart[fieldCode].push({ callback, properties });
815
+ });
816
+ }
817
+
818
+ onFieldValidationFinish(codes: string[] | string | null, callback, properties = null) {
819
+ const fieldSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
820
+ fieldSet.forEach((fieldCode) => {
821
+ if (!this._fieldValidationsFinish[fieldCode]) {
822
+ this._fieldValidationsFinish[fieldCode] = [];
823
+ }
824
+ this._fieldValidationsFinish[fieldCode].push({ callback, properties });
825
+ });
826
+ }
827
+
828
+ async startFieldInputValidation(fieldCode: string, intrinsicValidation: boolean = true) {
829
+ const fieldToValidate = this.getField(fieldCode);
830
+ if (!fieldToValidate) { return false; }
831
+ fieldToValidate.resetError();
832
+ const validationCallbacks = this._fieldInputValidation[fieldCode];
833
+ if (validationCallbacks) {
834
+ const clientValidationPromises: any[] = [];
835
+ for (const validationMethod of validationCallbacks) {
836
+ const { callback, properties } = validationMethod;
837
+ const continueValidationPromise = callback(fieldToValidate);
838
+ clientValidationPromises.push(continueValidationPromise);
839
+ }
840
+ await Promise.all(clientValidationPromises);
841
+ }
842
+ return true;
843
+ }
844
+
845
+ async startFieldValidation(fieldCode: string, intrinsicValidation: boolean = true) {
846
+ const fieldToValidate = this.getField(fieldCode);
847
+ if (!fieldToValidate) { return; }
848
+ fieldToValidate.resetError();
849
+ const validationCallbacks = this._fieldValidationsStart[fieldCode];
850
+ if (validationCallbacks) {
851
+ const clientValidationPromises: any[] = [];
852
+ for (const validationMethod of validationCallbacks) {
853
+ const { callback, properties } = validationMethod;
854
+ const clientValidationPromise = callback(fieldToValidate);
855
+ clientValidationPromises.push(clientValidationPromise);
856
+ }
857
+ const clientValidationResults = await Promise.all(clientValidationPromises);
858
+ const continueValidation = clientValidationResults.reduce((total, curr) => (total && (curr !== false)), true);
859
+ if (!continueValidation) {
860
+ return;
861
+ }
862
+ }
863
+ if (intrinsicValidation) {
864
+ this.startServerFieldValidation(fieldToValidate);
865
+ }
866
+ }
867
+
868
+ async startServerFieldValidation(inputField: string | FieldDescriptor) {
869
+ const fieldObj: FieldDescriptor | null = (typeof inputField === 'string')
870
+ ? this.getField(inputField) : inputField;
871
+ let serverError = false;
872
+ let validationResult: boolean = true;
873
+ if (!fieldObj) {
874
+ return;
875
+ }
876
+ if (fieldObj.backend) {
877
+ fieldObj.validating = true;
878
+ validationResult = await this
879
+ .requestFormAction(formActions.validate, fieldObj.fieldCode);
880
+ serverError = !!this.errorOccured();
881
+ }
882
+ await this.finishFieldValidation(fieldObj, validationResult, serverError);
883
+ if (serverError) {
884
+ fieldObj?.setErrorCode(this.errorCode);
885
+ fieldObj?.setErrorMessage(this.errorMessage);
886
+ for (let index = 0; index < this._fieldServerError.length; index++) {
887
+ const { callback, properties } = this._fieldServerError[index];
888
+ callback(fieldObj);
889
+ }
890
+ }
891
+ fieldObj.validating = false;
892
+ }
893
+
894
+ async finishFieldValidation(fieldObject: any, validationResult: boolean, serverError = false) {
895
+ const validationCallbacks = this._fieldValidationsFinish[fieldObject.fieldCode];
896
+ if (validationCallbacks) {
897
+ const clientActionPromises: any[] = [];
898
+ for (const validationMethod of validationCallbacks) {
899
+ const { callback, properties } = validationMethod;
900
+ const continueOnError = properties?.continueOnError ?? false;
901
+ if (!serverError || continueOnError) {
902
+ clientActionPromises.push(callback(fieldObject, validationResult));
903
+ }
904
+ }
905
+ await Promise.all(clientActionPromises);
906
+ }
907
+ }
908
+
909
+ async continueFieldValidation(fieldCode: string) {
910
+ return this.startServerFieldValidation(fieldCode);
911
+ }
912
+
913
+ /**
914
+ * Manejadores de eventos para acciones sobre Tablas
915
+ */
916
+
917
+ onTableActionStart(code: string, actionCode: string, callback, properties = null) {
918
+ const tableObject = this.getTable(code);
919
+ if (!tableObject) {
920
+ return;
921
+ }
922
+ const inlineActionObject = tableObject.getAction(actionCode);
923
+ if (!inlineActionObject) {
924
+ return;
925
+ }
926
+ let tableEventHandlers: any;
927
+ if (this._tableActionsStart[code]) {
928
+ tableEventHandlers = this._tableActionsStart[code];
929
+ } else {
930
+ tableEventHandlers = {};
931
+ this._tableActionsStart[code] = tableEventHandlers;
932
+ }
933
+ if (!tableEventHandlers[actionCode]) {
934
+ tableEventHandlers[actionCode] = [];
935
+ }
936
+ tableEventHandlers[actionCode].push({ callback, properties });
937
+ }
938
+
939
+ onTableActionFinish(code: string, actionCode: string, callback, properties = null) {
940
+ const tableObject = this.getTable(code);
941
+ if (!tableObject) {
942
+ return;
943
+ }
944
+ const inlineActionObject = tableObject.getAction(actionCode);
945
+ if (!inlineActionObject) {
946
+ return;
947
+ }
948
+ let tableEventHandlers: any;
949
+ if (this._tableActionsFinish[code]) {
950
+ tableEventHandlers = this._tableActionsFinish[code];
951
+ } else {
952
+ tableEventHandlers = {};
953
+ this._tableActionsFinish[code] = tableEventHandlers;
954
+ }
955
+ if (!tableEventHandlers[actionCode]) {
956
+ tableEventHandlers[actionCode] = [];
957
+ }
958
+ tableEventHandlers[actionCode].push({ callback, properties });
959
+ }
960
+
961
+ onTableSelectionStart(code: string, callback, properties = null) {
962
+ const tableObject = this.getTable(code);
963
+ if (!tableObject) { return; }
964
+ let tableEventHandlers: any[];
965
+ if (this._tableSelectionsStart[code]) {
966
+ tableEventHandlers = this._tableSelectionsStart[code];
967
+ } else {
968
+ tableEventHandlers = [];
969
+ this._tableSelectionsStart[code] = tableEventHandlers;
970
+ }
971
+ tableEventHandlers.push({ callback, properties });
972
+ }
973
+
974
+ onTableSelectionFinish(code: string, callback, properties = null) {
975
+ const tableObject = this.getTable(code);
976
+ if (!tableObject) { return; }
977
+ let tableEventHandlers: any[];
978
+ if (this._tableSelectionsFinish[code]) {
979
+ tableEventHandlers = this._tableSelectionsFinish[code];
980
+ } else {
981
+ tableEventHandlers = [];
982
+ this._tableSelectionsFinish[code] = tableEventHandlers;
983
+ }
984
+ tableEventHandlers.push({ callback, properties });
985
+ }
986
+
987
+ onTableGetDataStart(code: string, callback, properties = null) {
988
+ const tableObject = this.getTable(code);
989
+ if (!tableObject) {
990
+ return;
991
+ }
992
+ let tableEventHandlers: any[];
993
+ if (this._tableGetDataStart[code]) {
994
+ tableEventHandlers = this._tableGetDataStart[code];
995
+ } else {
996
+ tableEventHandlers = [];
997
+ this._tableGetDataStart[code] = tableEventHandlers;
998
+ }
999
+ tableEventHandlers.push({ callback, properties });
1000
+ }
1001
+
1002
+ onTableGetDataFinish(code: string, callback, properties = null) {
1003
+ const tableObject = this.getTable(code);
1004
+ if (!tableObject) {
1005
+ return;
1006
+ }
1007
+ let tableEventHandlers: any;
1008
+ if (this._tableGetDataFinish[code]) {
1009
+ tableEventHandlers = this._tableGetDataFinish[code];
1010
+ } else {
1011
+ tableEventHandlers = {};
1012
+ this._tableGetDataFinish[code] = tableEventHandlers;
1013
+ }
1014
+ tableEventHandlers[GET_DATA_ACTION] = { callback, properties };
1015
+ }
1016
+
1017
+ async startTableGlobalAction(tableActionEvent: any) {
1018
+ const { tableCode, actionCode } = tableActionEvent;
1019
+ const tableObject = this.getTable(tableCode);
1020
+ if (!tableObject || !actionCode) { return; }
1021
+ this.resetError();
1022
+ const action = tableObject.getAction(actionCode);
1023
+ if (!action) { return; }
1024
+ const tableActionDetail = {
1025
+ tableObject,
1026
+ action,
1027
+ tableCode,
1028
+ actionCode,
1029
+ };
1030
+ const tableEventHandlers = this._tableActionsStart[tableCode];
1031
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
1032
+ if (tableActionMethods) {
1033
+ const clientActionPromises: any[] = [];
1034
+ for (const tableActionMethod of tableActionMethods) {
1035
+ const { callback, properties } = tableActionMethod;
1036
+ const clientActionPromise = callback(tableActionDetail);
1037
+ clientActionPromises.push(clientActionPromise);
1038
+ }
1039
+ const clientActionResults = await Promise.all(clientActionPromises);
1040
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
1041
+ if (!continueAction) {
1042
+ return;
1043
+ }
1044
+ }
1045
+ this.startTableServerGlobalAction(tableActionDetail);
1046
+ }
1047
+
1048
+ async startTableServerGlobalAction(tableActionDetail: any) {
1049
+ const { tableObject, action, tableCode, actionCode } = tableActionDetail;
1050
+ if (!tableObject || !action) { return; }
1051
+ tableObject.putOnWait();
1052
+ let serverError = false;
1053
+ let actionResult = null;
1054
+ if (action.backend) {
1055
+ const actionSubject = {
1056
+ tableCode,
1057
+ actionType: GLOBAL_ACTION,
1058
+ actionCode
1059
+ };
1060
+ actionResult = await this
1061
+ .requestFormAction(formActions.tableAction, actionSubject);
1062
+ serverError = !!this.errorOccured();
1063
+ }
1064
+ await this.finishTableGlobalAction(tableActionDetail, actionResult, serverError);
1065
+ if (!serverError) {
1066
+ action.newState && this.changeState(action.newState);
1067
+ } else {
1068
+ for (let index = 0; index < this._tableServerError.length; index++) {
1069
+ const { callback, properties } = this._tableServerError[index];
1070
+ callback(tableObject);
1071
+ }
1072
+ }
1073
+ tableObject.freeWaiting();
1074
+ }
1075
+
1076
+ async finishTableGlobalAction(tableActionDetail: any, actionResult, serverError = false) {
1077
+ const { tableCode, actionCode } = tableActionDetail;
1078
+ const tableEventHandlers = this._tableActionsFinish[tableCode];
1079
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
1080
+ if (tableActionMethods) {
1081
+ const clientActionPromises: any[] = [];
1082
+ for (const tableActionMethod of tableActionMethods) {
1083
+ const { callback, properties } = tableActionMethod;
1084
+ const continueOnError = properties?.continueOnError ?? false;
1085
+ if (!serverError || continueOnError) {
1086
+ clientActionPromises.push(callback(tableActionDetail, actionResult));
1087
+ }
1088
+ }
1089
+ await Promise.all(clientActionPromises);
1090
+ }
1091
+ }
1092
+
1093
+ async startTableAction(tableActionEvent: any) {
1094
+ const { tableCode, actionCode, actionDetail } = tableActionEvent;
1095
+ const tableObject = this.getTable(tableCode);
1096
+ if (!tableObject || !actionCode) { return; }
1097
+ this.resetError();
1098
+ const { recordId, recordData } = actionDetail;
1099
+ const action = tableObject.getAction(actionCode);
1100
+ if (!action) { return; }
1101
+ const tableActionDetail = {
1102
+ tableObject,
1103
+ action,
1104
+ tableCode,
1105
+ actionCode,
1106
+ recordId,
1107
+ recordData
1108
+ };
1109
+ const tableEventHandlers = this._tableActionsStart[tableCode];
1110
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
1111
+ if (tableActionMethods) {
1112
+ const clientActionPromises: any[] = [];
1113
+ for (const tableActionMethod of tableActionMethods) {
1114
+ const { callback, properties } = tableActionMethod;
1115
+ const clientActionPromise = callback(tableActionDetail);
1116
+ clientActionPromises.push(clientActionPromise);
1117
+ }
1118
+ const clientActionResults = await Promise.all(clientActionPromises);
1119
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
1120
+ if (!continueAction) {
1121
+ return;
1122
+ }
1123
+ }
1124
+ this.startTableServerAction(tableActionDetail);
1125
+ }
1126
+
1127
+ async startTableServerAction(tableActionDetail: any) {
1128
+ const { tableObject, action, tableCode, actionCode, recordId, recordData } = tableActionDetail;
1129
+ if (!tableObject || !action) { return; }
1130
+ tableObject.putOnWait();
1131
+ let serverError = false;
1132
+ let actionResult = null;
1133
+ if (action.backend) {
1134
+ const actionSubject = {
1135
+ tableCode,
1136
+ actionType: this.formConfig.tableActions.inline,
1137
+ actionCode,
1138
+ tableRecordId: recordId,
1139
+ tableRecordData: recordData
1140
+ };
1141
+ actionResult = await this
1142
+ .requestFormAction(formActions.tableAction, actionSubject);
1143
+ serverError = !!this.errorOccured();
1144
+ }
1145
+ await this.finishTableAction(tableActionDetail, actionResult, serverError);
1146
+ if (!serverError) {
1147
+ action.newState && this.changeState(action.newState);
1148
+ } else {
1149
+ this.displayTableServerError();
1150
+ }
1151
+ tableObject.freeWaiting();
1152
+ }
1153
+
1154
+ completeInlineAction(tableAction: any) {
1155
+ return this.startTableServerAction(tableAction);
1156
+ }
1157
+
1158
+ async finishTableAction(tableActionDetail: any, actionResult, serverError = false) {
1159
+ const { tableCode, actionCode } = tableActionDetail;
1160
+ const tableEventHandlers = this._tableActionsFinish[tableCode];
1161
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
1162
+ if (tableActionMethods) {
1163
+ const clientActionPromises: any[] = [];
1164
+ for (const tableActionMethod of tableActionMethods) {
1165
+ const { callback, properties } = tableActionMethod;
1166
+ const continueOnError = properties?.continueOnError ?? false;
1167
+ if (!serverError || continueOnError) {
1168
+ clientActionPromises.push(callback(tableActionDetail, actionResult));
1169
+ }
1170
+ }
1171
+ await Promise.all(clientActionPromises);
1172
+ }
1173
+ }
1174
+
1175
+ async startTableRecordSelection(tableActionEvent: any) {
1176
+ const { tableCode, actionDetail } = tableActionEvent;
1177
+ const tableObject = this.getTable(tableCode);
1178
+ if (!tableObject) { return; }
1179
+ this.resetError();
1180
+ const { recordId, recordData } = actionDetail;
1181
+ const tableSelectionDetail = {
1182
+ tableObject,
1183
+ tableCode,
1184
+ recordId,
1185
+ recordData
1186
+ };
1187
+ const tableEventHandlers = this._tableSelectionsStart[tableCode];
1188
+ if (tableEventHandlers) {
1189
+ const clientActionPromises: any[] = [];
1190
+ for (const tableSelectionMethod of tableEventHandlers) {
1191
+ const { callback, properties } = tableSelectionMethod;
1192
+ const clientActionPromise = callback(tableSelectionDetail);
1193
+ clientActionPromises.push(clientActionPromise);
1194
+ }
1195
+ const clientActionResults = await Promise.all(clientActionPromises);
1196
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
1197
+ if (!continueAction) {
1198
+ return;
1199
+ }
1200
+ }
1201
+ this.startTableServerRecordSelection(tableSelectionDetail);
1202
+ }
1203
+
1204
+ async startTableServerRecordSelection(tableSelectionDetail: any) {
1205
+ const { tableObject, tableCode, recordId, recordData } = tableSelectionDetail;
1206
+ if (!tableObject) { return; }
1207
+ tableObject.putOnWait();
1208
+ let serverError = false;
1209
+ let actionResult = null;
1210
+ if (tableObject.selectionBackend) {
1211
+ const actionSubject: any = {
1212
+ tableCode,
1213
+ actionType: this.formConfig.tableActions.rowSelection,
1214
+ actionCode: null,
1215
+ tableRecordId: recordId,
1216
+ tableRecordData: recordData
1217
+ };
1218
+ actionResult = await this
1219
+ .requestFormAction(formActions.tableAction, actionSubject);
1220
+ serverError = !!this.errorOccured();
1221
+ }
1222
+ await this.finishTableRecordSelection(tableSelectionDetail, actionResult, serverError);
1223
+ if (serverError) {
1224
+ this.displayTableServerError();
1225
+ }
1226
+ tableObject.freeWaiting();
1227
+ }
1228
+
1229
+ async finishTableRecordSelection(tableSelectionDetail: any, actionResult, serverError = false) {
1230
+ const { tableCode } = tableSelectionDetail;
1231
+ const tableEventHandlers = this._tableSelectionsFinish[tableCode];
1232
+ if (tableEventHandlers) {
1233
+ const clientActionPromises: any[] = [];
1234
+ for (const tableSelectionMethod of tableEventHandlers) {
1235
+ const { callback, properties } = tableSelectionMethod;
1236
+ const continueOnError = properties?.continueOnError ?? false;
1237
+ if (!serverError || continueOnError) {
1238
+ clientActionPromises.push(callback(tableSelectionDetail, actionResult));
1239
+ }
1240
+ }
1241
+ await Promise.all(clientActionPromises);
1242
+ }
1243
+ }
1244
+
1245
+ async startTableSelectionAction(tableActionEvent: any) {
1246
+ const { tableCode, actionCode, actionDetail } = tableActionEvent;
1247
+ const tableObject = this.getTable(tableCode);
1248
+ if (!tableObject || !actionCode) { return; }
1249
+ this.resetError();
1250
+ const { selectedRecords } = actionDetail;
1251
+ const action = tableObject.getAction(actionCode);
1252
+ if (!action) { return; }
1253
+ const tableActionDetail = {
1254
+ tableObject,
1255
+ action,
1256
+ tableCode,
1257
+ actionCode,
1258
+ selectedRecords
1259
+ };
1260
+ const tableEventHandlers = this._tableActionsStart[tableCode];
1261
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
1262
+ if (tableActionMethods) {
1263
+ const clientActionPromises: any[] = [];
1264
+ for (const tableActionMethod of tableActionMethods) {
1265
+ const { callback, properties } = tableActionMethod;
1266
+ const clientActionPromise = callback(tableActionDetail);
1267
+ clientActionPromises.push(clientActionPromise);
1268
+ }
1269
+ const clientActionResults = await Promise.all(clientActionPromises);
1270
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
1271
+ if (!continueAction) {
1272
+ return;
1273
+ }
1274
+ }
1275
+ this.startTableServerSelectionAction(tableActionDetail);
1276
+ }
1277
+
1278
+ async startTableServerSelectionAction(tableActionDetail: any) {
1279
+ const { tableObject, action, tableCode, actionCode, selectedRecords } = tableActionDetail;
1280
+ if (!tableObject || !action) { return; }
1281
+ tableObject.putOnWait();
1282
+ let serverError = false;
1283
+ let actionResult = null;
1284
+ if (action.backend) {
1285
+ const actionSubject = {
1286
+ tableCode,
1287
+ actionType: this.formConfig.tableActions.selection,
1288
+ actionCode,
1289
+ selectedRecords
1290
+ };
1291
+ actionResult = await this
1292
+ .requestFormAction(formActions.tableAction, actionSubject);
1293
+ serverError = !!this.errorOccured();
1294
+ }
1295
+ await this.finishTableSelectionAction(tableActionDetail, actionResult, serverError);
1296
+ if (!serverError) {
1297
+ action.newState && this.changeState(action.newState);
1298
+ } else {
1299
+ this.displayTableServerError();
1300
+ }
1301
+ tableObject.freeWaiting();
1302
+ }
1303
+
1304
+ async finishTableSelectionAction(tableActionDetail: any, actionResult, serverError = false) {
1305
+ const { tableCode, actionCode } = tableActionDetail;
1306
+ const tableEventHandlers = this._tableActionsFinish[tableCode];
1307
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[actionCode] : null;
1308
+ if (tableActionMethods) {
1309
+ const clientActionPromises: any[] = [];
1310
+ for (const tableActionMethod of tableActionMethods) {
1311
+ const { callback, properties } = tableActionMethod;
1312
+ const continueOnError = properties?.continueOnError ?? false;
1313
+ if (!serverError || continueOnError) {
1314
+ clientActionPromises.push(callback(tableActionDetail, actionResult));
1315
+ }
1316
+ }
1317
+ await Promise.all(clientActionPromises);
1318
+ }
1319
+ }
1320
+
1321
+ async startTableGetData(tableActionEvent: any) {
1322
+ const { tableCode } = tableActionEvent;
1323
+ const tableObject = this.getTable(tableCode);
1324
+ const tableActionDetail = {
1325
+ tableObject,
1326
+ tableCode
1327
+ };
1328
+ this.resetError();
1329
+ const tableEventHandlers = this._tableGetDataStart[tableCode];
1330
+ if (tableEventHandlers) {
1331
+ const clientActionPromises: any[] = [];
1332
+ for (const tableActionMethod of tableEventHandlers) {
1333
+ const { callback, properties } = tableActionMethod;
1334
+ const clientActionPromise = callback(tableActionDetail);
1335
+ clientActionPromises.push(clientActionPromise);
1336
+ }
1337
+ const clientActionResults = await Promise.all(clientActionPromises);
1338
+ const continueAction = clientActionResults.reduce((total, curr) => (total && (curr !== false)), true);
1339
+ if (!continueAction) {
1340
+ return;
1341
+ }
1342
+ }
1343
+ this.startTableServerGetData(tableActionDetail);
1344
+ }
1345
+
1346
+ async startTableServerGetData(tableActionDetail: any) {
1347
+ const { tableObject, tableCode } = tableActionDetail;
1348
+ tableObject.putOnWait();
1349
+ let serverError = false;
1350
+ const actionSubject = { tableCode };
1351
+ const actionResult = await this
1352
+ .requestFormAction(formActions.getTableData, actionSubject);
1353
+ serverError = !!this.errorOccured();
1354
+ await this.finishTableGetData(tableActionDetail, actionResult, serverError);
1355
+ if (serverError) {
1356
+ this.displayTableServerError();
1357
+ }
1358
+ tableObject.freeWaiting();
1359
+ }
1360
+
1361
+ async finishTableGetData(tableActionDetail: any, actionResult, serverError = false) {
1362
+ const { tableCode, tableActionCode } = tableActionDetail;
1363
+ const tableEventHandlers = this._tableActionsFinish[tableCode];
1364
+ const tableActionMethods = (tableEventHandlers) ? tableEventHandlers[tableActionCode] : null;
1365
+ if (tableActionMethods) {
1366
+ const clientActionPromises: any[] = [];
1367
+ for (const tableActionMethod of tableActionMethods) {
1368
+ const { callback, properties } = tableActionMethod;
1369
+ const continueOnError = properties?.continueOnError ?? false;
1370
+ if (!serverError || continueOnError) {
1371
+ clientActionPromises.push(callback(tableActionDetail, actionResult));
1372
+ }
1373
+ }
1374
+ await Promise.all(clientActionPromises);
1375
+ }
1376
+ }
1377
+
1378
+ checkSectionRequiredFields(sectionCode: string, reqFieldMessage?: string) {
1379
+ this.cleanErrorFields(null, sectionCode);
1380
+ const requiredFieldMessage = reqFieldMessage ?? this.formConfig.formStandardErrors.requiredField
1381
+ const numErrors = this.tagFieldsWithError(requiredFieldMessage, this.getRequiredEmptyFields(null, sectionCode));
1382
+ return (numErrors === 0);
1383
+ }
1384
+
1385
+ validateSectionConsistency(sectionCode: string, reqFieldMessage?: string) {
1386
+ this.resetError();
1387
+ const completeFields = this.checkSectionRequiredFields(sectionCode, reqFieldMessage);
1388
+ if (!completeFields) {
1389
+ this.setError(this.formConfig.formStandardErrors.typeWarning,
1390
+ this.formConfig.formStandardErrors.validationTitle,
1391
+ this.formConfig.formStandardErrors.requiredFields);
1392
+ return false;
1393
+ }
1394
+ let validationError = false;
1395
+ const requiredEmptyFields: any[] = this.getRequiredEmptyFields(null, sectionCode) ?? [];
1396
+ if (requiredEmptyFields?.length > 0) {
1397
+ validationError = true;
1398
+ this.setError(this.formConfig.formStandardErrors.typeWarning,
1399
+ this.formConfig.formStandardErrors.validationTitle,
1400
+ this.formConfig.formStandardErrors.requiredFields);
1401
+ this.tagFieldsWithError(this.formConfig.formStandardErrors.requiredField, requiredEmptyFields);
1402
+ for (const fieldCode of requiredEmptyFields) {
1403
+ const requiredEmptyField = this.getField(fieldCode);
1404
+ requiredEmptyField?.focus();
1405
+ break;
1406
+ }
1407
+ }
1408
+ const validationIssueFields: any[] = this.getFieldsWithValidationIssues(null,
1409
+ sectionCode) ?? [];
1410
+ if (!validationError && validationIssueFields.length > 0) {
1411
+ validationError = true;
1412
+ this.setError(this.formConfig.formStandardErrors.typeWarning,
1413
+ this.formConfig.formStandardErrors.validationTitle,
1414
+ this.formConfig.formStandardErrors.validationFields);
1415
+ for (const fieldCode of validationIssueFields) {
1416
+ const validationIssueField = this.getField(fieldCode);
1417
+ if (validationIssueField) {
1418
+ validationIssueField.focus();
1419
+ }
1420
+ break;
1421
+ }
1422
+ }
1423
+ return validationError;
1424
+ }
1425
+
1426
+ copyTableRecordToFields(tableObj: any, mappingTable: any = null) {
1427
+ const tableObject = this.getTable(tableObj.tableCode);
1428
+ const tableRecord = tableObject?.getTableRecord(tableObj.recordId);
1429
+ const columnNames = tableObject?.columnNames;
1430
+ if (tableRecord && columnNames) {
1431
+ for (const columnName of columnNames) {
1432
+ const columnValue = tableRecord.getFieldValue(columnName) ?? '';
1433
+ const fieldCode = mappingTable?.[columnName] ?? columnName;
1434
+ this.setFieldValue(fieldCode, columnValue);
1435
+ }
1436
+ return true;
1437
+ }
1438
+ return false;
1439
+ }
1440
+
1441
+ /**
1442
+ * Métodos Legacy de compatibilidad hacia atrás
1443
+ */
1444
+
1445
+ addSectionActivation(codes: string[] | string | null, callback, properties = null) {
1446
+ return this.onSectionActivation(codes, callback, properties);
1447
+ }
1448
+
1449
+ addSectionInactivation(codes: string[] | string | null, callback, properties = null) {
1450
+ return this.onSectionInactivation(codes, callback, properties);
1451
+ }
1452
+
1453
+ addActionMethodStart(codes: string[] | string | null, callback, properties = null) {
1454
+ return this.onActionStart(codes, callback, properties);
1455
+ }
1456
+
1457
+ addActionMethodFinish(codes: string[] | string | null, callback, properties = null) {
1458
+ return this.onActionFinish(codes, callback, properties);
1459
+ }
1460
+
1461
+ addFieldInputValidation(codes: string[] | string | null, callback, properties = null) {
1462
+ return this.onFieldInput(codes, callback, properties);
1463
+ }
1464
+
1465
+ addFieldValidationStart(codes: string[] | string | null, callback, properties = null) {
1466
+ return this.onFieldValidationStart(codes, callback, properties);
1467
+ }
1468
+
1469
+ addFieldValidationFinish(codes: string[] | string | null, callback, properties = null) {
1470
+ return this.onFieldValidationFinish(codes, callback, properties);
1471
+ }
1472
+
1473
+ addTableActionStart(code: string, actionCode: string, callback, properties = null) {
1474
+ return this.onTableActionStart(code, actionCode, callback, properties);
1475
+ }
1476
+
1477
+ addTableActionFinish(code: string, actionCode: string, callback, properties = null) {
1478
+ return this.onTableActionFinish(code, actionCode, callback, properties);
1479
+ }
1480
+
1481
+ addTableSelectionStart(code: string, callback, properties = null) {
1482
+ return this.onTableSelectionStart(code, callback, properties);
1483
+ }
1484
+
1485
+ addTableSelectionFinish(code: string, callback, properties = null) {
1486
+ return this.onTableSelectionFinish(code, callback, properties);
1487
+ }
1488
+
1489
+ addTableGetDataStart(code: string, callback, properties = null) {
1490
+ return this.onTableGetDataStart(code, callback, properties);
1491
+ }
1492
+
1493
+ addTableGetDataFinish(code: string, callback, properties = null) {
1494
+ return this.onTableGetDataFinish(code, callback, properties);
1495
+ }
1496
+ }