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