tuain-ng-forms-lib 14.4.93 → 14.4.96

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