tuain-ng-forms-lib 14.0.1 → 14.0.3
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/esm2020/lib/classes/forms/action.mjs +35 -0
- package/esm2020/lib/classes/forms/element.mjs +76 -0
- package/esm2020/lib/classes/forms/field.mjs +321 -0
- package/esm2020/lib/classes/forms/form.constants.mjs +26 -0
- package/esm2020/lib/classes/forms/form.mjs +422 -0
- package/esm2020/lib/classes/forms/section.mjs +132 -0
- package/esm2020/lib/classes/forms/subsection.mjs +70 -0
- package/esm2020/lib/classes/forms/table/action.mjs +22 -0
- package/esm2020/lib/classes/forms/table/column.mjs +61 -0
- package/esm2020/lib/classes/forms/table/row-data.mjs +111 -0
- package/esm2020/lib/classes/forms/table/table.mjs +372 -0
- package/esm2020/lib/components/elements/action.component.mjs +58 -0
- package/esm2020/lib/components/elements/field.component.mjs +90 -0
- package/esm2020/lib/components/elements/layout/element.component.mjs +31 -0
- package/esm2020/lib/components/elements/layout/form-error.component.mjs +20 -0
- package/esm2020/lib/components/elements/layout/form-header.component.mjs +30 -0
- package/esm2020/lib/components/elements/layout/section.component.mjs +22 -0
- package/esm2020/lib/components/elements/layout/sub-section.component.mjs +24 -0
- package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +40 -0
- package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +25 -0
- package/esm2020/lib/components/elements/tables/table.component.mjs +95 -0
- package/esm2020/lib/components/forms/basic-form.mjs +1425 -0
- package/esm2020/lib/services/event-manager.service.mjs +18 -0
- package/esm2020/lib/services/file-manager.service.mjs +6 -0
- package/esm2020/lib/services/form-manager.service.mjs +80 -0
- package/esm2020/lib/tuain-ng-forms-lib.module.mjs +71 -0
- package/esm2020/public-api.mjs +19 -0
- package/esm2020/tuain-ng-forms-lib.mjs +5 -0
- package/fesm2015/tuain-ng-forms-lib.mjs +3803 -0
- package/fesm2015/tuain-ng-forms-lib.mjs.map +1 -0
- package/fesm2020/tuain-ng-forms-lib.mjs +3634 -0
- package/fesm2020/tuain-ng-forms-lib.mjs.map +1 -0
- package/lib/classes/forms/action.d.ts +22 -0
- package/lib/classes/forms/element.d.ts +41 -0
- package/lib/classes/forms/field.d.ts +109 -0
- package/lib/classes/forms/form.constants.d.ts +25 -0
- package/lib/classes/forms/form.d.ts +134 -0
- package/lib/classes/forms/section.d.ts +39 -0
- package/lib/classes/forms/subsection.d.ts +26 -0
- package/lib/classes/forms/table/action.d.ts +20 -0
- package/lib/classes/forms/table/column.d.ts +33 -0
- package/lib/classes/forms/table/row-data.d.ts +14 -0
- package/lib/classes/forms/table/table.d.ts +100 -0
- package/lib/components/elements/action.component.d.ts +21 -0
- package/lib/components/elements/field.component.d.ts +43 -0
- package/lib/components/elements/layout/element.component.d.ts +14 -0
- package/lib/components/elements/layout/form-error.component.d.ts +8 -0
- package/lib/components/elements/layout/form-header.component.d.ts +12 -0
- package/lib/components/elements/layout/section.component.d.ts +10 -0
- package/lib/components/elements/layout/sub-section.component.d.ts +11 -0
- package/lib/components/elements/tables/table-record-action.component.d.ts +15 -0
- package/lib/components/elements/tables/table-record-field.component.d.ts +11 -0
- package/lib/components/elements/tables/table.component.d.ts +47 -0
- package/lib/components/forms/basic-form.d.ts +307 -0
- package/lib/services/event-manager.service.d.ts +9 -0
- package/lib/services/file-manager.service.d.ts +5 -0
- package/lib/services/form-manager.service.d.ts +28 -0
- package/lib/tuain-ng-forms-lib.module.d.ts +20 -0
- package/package.json +22 -2
- package/{src/public-api.ts → public-api.d.ts} +0 -5
- package/tuain-ng-forms-lib.d.ts +5 -0
- package/.browserslistrc +0 -16
- package/.yarn/cache/nanoid-npm-4.0.0-924f5c6312-7d5946df5c.zip +0 -0
- package/.yarn/cache/tslib-npm-2.4.0-9cb6dc5030-8c4aa6a3c5.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 +0 -44
- package/ng-package.json +0 -11
- package/src/lib/classes/forms/action.ts +0 -55
- package/src/lib/classes/forms/element.ts +0 -98
- package/src/lib/classes/forms/field.ts +0 -408
- package/src/lib/classes/forms/form.constants.ts +0 -28
- package/src/lib/classes/forms/form.ts +0 -495
- package/src/lib/classes/forms/section.ts +0 -154
- package/src/lib/classes/forms/subsection.ts +0 -91
- package/src/lib/classes/forms/table/action.ts +0 -41
- package/src/lib/classes/forms/table/column.ts +0 -91
- package/src/lib/classes/forms/table/row-data.ts +0 -118
- package/src/lib/classes/forms/table/table.ts +0 -438
- package/src/lib/components/elements/action.component.ts +0 -53
- package/src/lib/components/elements/field.component.ts +0 -118
- package/src/lib/components/elements/layout/element.component.ts +0 -28
- package/src/lib/components/elements/layout/form-error.component.ts +0 -11
- package/src/lib/components/elements/layout/form-header.component.ts +0 -17
- package/src/lib/components/elements/layout/section.component.ts +0 -16
- package/src/lib/components/elements/layout/sub-section.component.ts +0 -17
- package/src/lib/components/elements/tables/table-record-action.component.ts +0 -37
- package/src/lib/components/elements/tables/table-record-field.component.ts +0 -19
- package/src/lib/components/elements/tables/table.component.ts +0 -102
- package/src/lib/components/forms/basic-form.ts +0 -1496
- package/src/lib/services/event-manager.service.ts +0 -21
- package/src/lib/services/file-manager.service.ts +0 -6
- package/src/lib/services/form-manager.service.ts +0 -89
- package/src/lib/services/icon-dictionary.service.ts +0 -159
- package/src/lib/tuain-ng-forms-lib.module.ts +0 -40
- package/src/test.ts +0 -27
- package/tsconfig.lib.json +0 -15
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
2
|
-
import { elementTypes } from './form.constants';
|
|
3
|
-
import { FormElement } from './element';
|
|
4
|
-
|
|
5
|
-
const HEADER = 'HEADER';
|
|
6
|
-
|
|
7
|
-
export class FormAction extends FormElement {
|
|
8
|
-
private readonly _actionActivated = new Subject<string>();
|
|
9
|
-
|
|
10
|
-
inProgress = false;
|
|
11
|
-
newState: string;
|
|
12
|
-
backend: boolean;
|
|
13
|
-
|
|
14
|
-
actionCode: string;
|
|
15
|
-
actionName: string;
|
|
16
|
-
iconName: string;
|
|
17
|
-
|
|
18
|
-
restrictedOnField: string;
|
|
19
|
-
restrictedOnOperator: string;
|
|
20
|
-
restrictedOnValue: string;
|
|
21
|
-
customValidation: any;
|
|
22
|
-
|
|
23
|
-
constructor(actionDefinition, formConfig) {
|
|
24
|
-
super(actionDefinition, formConfig);
|
|
25
|
-
this.elementType = elementTypes.action;
|
|
26
|
-
this.actionCode = actionDefinition.actionCode ? actionDefinition.actionCode.toString() : '';
|
|
27
|
-
this.actionName = actionDefinition.actionTitle;
|
|
28
|
-
this.iconName = actionDefinition.iconName || this.actionCode;
|
|
29
|
-
this.setCustomAttribute('location', actionDefinition.position || HEADER);
|
|
30
|
-
this.backend = actionDefinition?.serverAction ?? false;
|
|
31
|
-
this.newState = actionDefinition?.newState;
|
|
32
|
-
|
|
33
|
-
this.restrictedOnField = actionDefinition.fieldRestrictedCode ? actionDefinition.fieldRestrictedCode.toString() : '';
|
|
34
|
-
this.restrictedOnOperator = actionDefinition.operatorRestricted || '';
|
|
35
|
-
this.restrictedOnValue = actionDefinition.valueRestricted ?? '';
|
|
36
|
-
this.customValidation = () => true;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get actionActivated() { return this._actionActivated; }
|
|
40
|
-
|
|
41
|
-
start() { this.inProgress = true; }
|
|
42
|
-
stop() { this.inProgress = false; }
|
|
43
|
-
|
|
44
|
-
notifyActivation() { this._actionActivated.next(this.actionCode); }
|
|
45
|
-
|
|
46
|
-
updateFromServer(receivedAction) {
|
|
47
|
-
for (const propertyName in receivedAction) {
|
|
48
|
-
if (propertyName !== 'actionCode' && propertyName !== 'actionId') {
|
|
49
|
-
this[propertyName] = receivedAction[propertyName];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
setCustomValidation(callback) { this.customValidation = () => callback(); }
|
|
55
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { elementTypes } from './form.constants';
|
|
2
|
-
export class FormElement {
|
|
3
|
-
protected _visible: boolean;
|
|
4
|
-
protected _visibleForced: boolean;
|
|
5
|
-
protected _isForced: boolean;
|
|
6
|
-
_formConfig: any;
|
|
7
|
-
disabled: boolean;
|
|
8
|
-
visibleStates: string[];
|
|
9
|
-
enabledStates: string[];
|
|
10
|
-
elementType: string;
|
|
11
|
-
customAttributes: any;
|
|
12
|
-
|
|
13
|
-
constructor(elementDefinition: any, formConfig: any) {
|
|
14
|
-
this._formConfig = formConfig;
|
|
15
|
-
this._isForced = false;
|
|
16
|
-
this.setVisibleStates(elementDefinition.visibleStates);
|
|
17
|
-
this.setEnabledStates(elementDefinition.enabledStates);
|
|
18
|
-
this._visibleForced = false;
|
|
19
|
-
this.disabled = elementDefinition?.disabled ?? false;
|
|
20
|
-
this.setVisibility(elementDefinition?.visible ?? true);
|
|
21
|
-
this.customAttributes = elementDefinition?.customAttributes ?? {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getCustomAttribute(name: string): any { return this.customAttributes?.[name] ?? null; }
|
|
25
|
-
setCustomAttribute(name: string, value: any): void { if (name) { this.customAttributes[name] = value; } }
|
|
26
|
-
matchAttribute(name: string, value: string): boolean { return this.customAttributes?.[name] === value; }
|
|
27
|
-
|
|
28
|
-
isField(): boolean { return this.elementType === elementTypes.field; }
|
|
29
|
-
isAction(): boolean { return this.elementType === elementTypes.action; }
|
|
30
|
-
isTable(): boolean { return this.elementType === elementTypes.table; }
|
|
31
|
-
|
|
32
|
-
setVisibleStates(newStates: any): void {
|
|
33
|
-
const visibleStates = (!Array.isArray(newStates) && typeof newStates === 'string')
|
|
34
|
-
? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
|
|
35
|
-
: newStates;
|
|
36
|
-
this.visibleStates = (Array.isArray(visibleStates)) ? visibleStates : [];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
setEnabledStates(newStates: any): void {
|
|
40
|
-
const enabledStates = (!Array.isArray(newStates) && typeof newStates === 'string')
|
|
41
|
-
? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
|
|
42
|
-
: newStates;
|
|
43
|
-
this.enabledStates = (Array.isArray(enabledStates)) ? enabledStates : [];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
viewOnState(state: string): boolean { return (this.visibleStates && state) ? this.visibleStates.includes(state) : false; }
|
|
47
|
-
enabledOnState(state: string): boolean { return (this.enabledStates && state) ? this.enabledStates.includes(state) : false; }
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @deprecated Utilizar viewOnState
|
|
51
|
-
*/
|
|
52
|
-
supportState(state: string): boolean { return this.viewOnState(state); }
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated Utilizar viewOnState
|
|
56
|
-
*/
|
|
57
|
-
supportMode(state: string): boolean { return this.viewOnState(state); }
|
|
58
|
-
|
|
59
|
-
get visible(): boolean { return (this._isForced) ? this._visibleForced : this._visible; }
|
|
60
|
-
set visible(visible: boolean) { this.setVisibility(visible); }
|
|
61
|
-
|
|
62
|
-
visibleOn(state: string): boolean {
|
|
63
|
-
return this.visible && this.viewOnState(state);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
enabledOn(state: string): boolean {
|
|
67
|
-
return !this.disabled && this.enabledOnState(state);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
setVisibility(visible: boolean, forced: boolean = null): void {
|
|
71
|
-
this._visible = visible && true;
|
|
72
|
-
if (forced != null) {
|
|
73
|
-
this._isForced = forced;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
show(forced?: boolean): void {
|
|
78
|
-
this._visible = true;
|
|
79
|
-
if (forced !== null) {
|
|
80
|
-
this._isForced = forced;
|
|
81
|
-
this._visibleForced = true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
hide(forced?: boolean): void {
|
|
86
|
-
this._visible = false;
|
|
87
|
-
if (forced !== null) {
|
|
88
|
-
this._isForced = forced;
|
|
89
|
-
this._visibleForced = false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
enable(): void { this.disabled = false; }
|
|
94
|
-
disable(): void { this.disabled = true; }
|
|
95
|
-
|
|
96
|
-
get enabled(): boolean { return !this.disabled; }
|
|
97
|
-
get editable(): boolean { return !this.disabled; }
|
|
98
|
-
}
|
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
2
|
-
import yn from 'yn';
|
|
3
|
-
import { elementTypes, NO_ERROR } from './form.constants';
|
|
4
|
-
import { FormElement } from './element';
|
|
5
|
-
import { isNgTemplate } from '@angular/compiler';
|
|
6
|
-
|
|
7
|
-
const UNDEFINED = 'undefined';
|
|
8
|
-
|
|
9
|
-
const DEFAULT_ERROR_TYPE = 'error';
|
|
10
|
-
const DEFAULT_CAPTURE_TYPE = 'INPUT';
|
|
11
|
-
const DEFAULT_ALIGNMENT = 'left';
|
|
12
|
-
|
|
13
|
-
const STD_MAX_LENGTH = 50;
|
|
14
|
-
const BIG_MAX_LENGTH = 500;
|
|
15
|
-
|
|
16
|
-
const fldAttr = {
|
|
17
|
-
validateOnServer: 'validateOnServer',
|
|
18
|
-
value: '_value',
|
|
19
|
-
minValue: '_minValue',
|
|
20
|
-
maxValue: '_maxValue',
|
|
21
|
-
maxLength: '_maxLength',
|
|
22
|
-
onValidation: '_onValidation',
|
|
23
|
-
focus: 'focus',
|
|
24
|
-
intrinsicErrorMessage: '_intrinsicErrorMessage',
|
|
25
|
-
code: 'fieldCode',
|
|
26
|
-
info: 'fieldInfo',
|
|
27
|
-
defaultValue: 'defaultValue',
|
|
28
|
-
defaultEditable: 'defaultEditable',
|
|
29
|
-
visibleLabel: 'visibleLabel',
|
|
30
|
-
required: 'fieldRequired',
|
|
31
|
-
hasChanged: 'hasChanged',
|
|
32
|
-
outputOnly: 'outputOnly',
|
|
33
|
-
captureType: 'captureType',
|
|
34
|
-
title: 'fieldTitle',
|
|
35
|
-
type: 'fieldType',
|
|
36
|
-
alignment: 'fieldAlignment',
|
|
37
|
-
format: 'fieldFormat',
|
|
38
|
-
externalValue: 'externalValue',
|
|
39
|
-
tooltipText: 'tooltipText',
|
|
40
|
-
errorType: 'errorType',
|
|
41
|
-
errorCode: 'errorCode',
|
|
42
|
-
errorMessage: 'errorMessage',
|
|
43
|
-
options: 'fieldOptions',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export interface DetailEvent {
|
|
47
|
-
code: string;
|
|
48
|
-
detail: any;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface FieldOption {
|
|
52
|
-
fieldOptionValue: string;
|
|
53
|
-
fieldOptionId: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class FieldDescriptor extends FormElement {
|
|
57
|
-
private readonly _editionFinish = new Subject<any>();
|
|
58
|
-
private readonly _editionPartial = new Subject<any>();
|
|
59
|
-
private readonly _detailRequest = new Subject<DetailEvent>();
|
|
60
|
-
private readonly _attributeChange = new Subject<any>();
|
|
61
|
-
|
|
62
|
-
private validateOnServer: boolean;
|
|
63
|
-
|
|
64
|
-
private _value: any;
|
|
65
|
-
private _focus: boolean;
|
|
66
|
-
|
|
67
|
-
private _minValue: any;
|
|
68
|
-
private _maxValue: any;
|
|
69
|
-
private _maxLength: number;
|
|
70
|
-
_onValidation: boolean;
|
|
71
|
-
_intrinsicErrorMessage: string;
|
|
72
|
-
|
|
73
|
-
fieldCode: string;
|
|
74
|
-
fieldInfo: string;
|
|
75
|
-
defaultValue: string;
|
|
76
|
-
defaultEditable: boolean;
|
|
77
|
-
|
|
78
|
-
visibleLabel: boolean;
|
|
79
|
-
fieldRequired: boolean;
|
|
80
|
-
hasChanged: boolean;
|
|
81
|
-
outputOnly: boolean;
|
|
82
|
-
captureType: string;
|
|
83
|
-
fieldTitle: string;
|
|
84
|
-
fieldType: string;
|
|
85
|
-
fieldAlignment: string;
|
|
86
|
-
fieldFormat: RegExp;
|
|
87
|
-
externalValue: any;
|
|
88
|
-
tooltipText: string;
|
|
89
|
-
|
|
90
|
-
errorType: string;
|
|
91
|
-
errorCode: string;
|
|
92
|
-
errorMessage: string;
|
|
93
|
-
|
|
94
|
-
fieldOptions: FieldOption[];
|
|
95
|
-
|
|
96
|
-
constructor(inputFieldReceived, formConfig) {
|
|
97
|
-
super(inputFieldReceived, formConfig);
|
|
98
|
-
this.elementType = elementTypes.field;
|
|
99
|
-
const fld = (inputFieldReceived) ? inputFieldReceived : {};
|
|
100
|
-
|
|
101
|
-
this.setAttr(fldAttr.code, fld.fieldCode);
|
|
102
|
-
this.setAttr(fldAttr.title, fld.fieldTitle ?? this.fieldCode);
|
|
103
|
-
this.setAttr(fldAttr.type, fld.fieldTypeCode)
|
|
104
|
-
this.setAttr(fldAttr.captureType, fld.captureType ?? DEFAULT_CAPTURE_TYPE);
|
|
105
|
-
const defaultValue = fld.defaultValue ?? null;
|
|
106
|
-
if (this.fieldType === this._formConfig.fieldTypes.boolean) {
|
|
107
|
-
this.setAttr(fldAttr.defaultValue, defaultValue ?? false);
|
|
108
|
-
} else {
|
|
109
|
-
this.setAttr(fldAttr.defaultValue, defaultValue);
|
|
110
|
-
}
|
|
111
|
-
const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this.fieldType] != null)
|
|
112
|
-
? this._formConfig.tableFieldStyles[this.fieldType]['text-align'] : DEFAULT_ALIGNMENT;
|
|
113
|
-
const fieldAlignment = (fld.alignment != null) ? fld.alignment.toLowerCase() : defaultTypeAlignment;
|
|
114
|
-
this.setAttr(fldAttr.alignment, fieldAlignment);
|
|
115
|
-
this.setAttr(fldAttr.info, fld.info || '');
|
|
116
|
-
let fieldFormat;
|
|
117
|
-
try {
|
|
118
|
-
fieldFormat = (fld.format) ? new RegExp(fld.format) : null;
|
|
119
|
-
} catch (e) {
|
|
120
|
-
fieldFormat = null;
|
|
121
|
-
}
|
|
122
|
-
this.setAttr(fldAttr.format, fieldFormat);
|
|
123
|
-
|
|
124
|
-
this.setAttr(fldAttr.validateOnServer, fld.serverAction ?? false);
|
|
125
|
-
|
|
126
|
-
this.setAttr(fldAttr.tooltipText, fld.tooltip || '');
|
|
127
|
-
this.setAttr(fldAttr.defaultEditable, this.enabled);
|
|
128
|
-
this.setAttr(fldAttr.required, fld.required ?? false);
|
|
129
|
-
this.setError(fld.errorCode, fld.errorMessage, fld.errorType ?? DEFAULT_ERROR_TYPE);
|
|
130
|
-
this.setAttr(fldAttr.outputOnly, fld.outputOnly ?? false);
|
|
131
|
-
const maxLength = fld.maxLength ?? (this.captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
|
|
132
|
-
this.setAttr(fldAttr.maxLength, maxLength);
|
|
133
|
-
this.setAttr(fldAttr.intrinsicErrorMessage, this._formConfig.fieldTypeErrMsg[this.fieldType] ?? this._formConfig.fieldTypeErrMsg.DEFAULT);
|
|
134
|
-
|
|
135
|
-
this.setEditable(fld.editable ?? true);
|
|
136
|
-
this.setVisibleLabel(fld.visibleLabel ?? true);
|
|
137
|
-
this.setVisibility(fld.visible);
|
|
138
|
-
this.setFieldOptions(fld.fieldOptions);
|
|
139
|
-
this.setValue(fld.fieldValue ?? this.defaultValue ?? '');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
get name() { return this.fieldCode; }
|
|
143
|
-
get editionFinish() { return this._editionFinish; }
|
|
144
|
-
get attributeChange() { return this._attributeChange; }
|
|
145
|
-
|
|
146
|
-
get editionPartial() { return this._editionPartial; }
|
|
147
|
-
get detailRequest() { return this._detailRequest; }
|
|
148
|
-
get info() { return this.fieldInfo; }
|
|
149
|
-
|
|
150
|
-
get validating() { return this._onValidation; }
|
|
151
|
-
set validating(isValidating: boolean) { this.setAttr(fldAttr.onValidation, isValidating); }
|
|
152
|
-
|
|
153
|
-
focus() { this.setAttr(fldAttr.focus, true); }
|
|
154
|
-
|
|
155
|
-
setIntrinsicErrorMessage(message: string) { this.setAttr(fldAttr.intrinsicErrorMessage, message); }
|
|
156
|
-
set intrinsicErrorMessage(message: string) { this.setIntrinsicErrorMessage(message); }
|
|
157
|
-
|
|
158
|
-
get fieldValue() { return this.getValue(); }
|
|
159
|
-
|
|
160
|
-
getRequired() { return this.required; }
|
|
161
|
-
setRequired(required: boolean) { this.required = required; }
|
|
162
|
-
|
|
163
|
-
get required(): boolean { return this.fieldRequired; }
|
|
164
|
-
set required(required: boolean) { this.setAttr(fldAttr.required, required ?? false); }
|
|
165
|
-
get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
|
|
166
|
-
set maxLength(requiredMaxLength: any) {
|
|
167
|
-
if (typeof requiredMaxLength === 'string') {
|
|
168
|
-
this.setAttr(fldAttr.maxLength, parseInt(requiredMaxLength, 10));
|
|
169
|
-
} else if (typeof requiredMaxLength === 'number') {
|
|
170
|
-
this.setAttr(fldAttr.maxLength, requiredMaxLength);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
get value() { return this.getValue(); }
|
|
174
|
-
set value(newValue) { this.setValue(newValue); }
|
|
175
|
-
|
|
176
|
-
notifyEditionPartial() {
|
|
177
|
-
this._editionPartial.next({ code: this.fieldCode, intrinsicValidation: true });
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
notifyEditionFinish() {
|
|
181
|
-
console.log('1. notifyEditionFinish');
|
|
182
|
-
let intrinsicValidation = true;
|
|
183
|
-
const fieldDefaultFormat = this._formConfig.fieldTypesPatterns?.[this.fieldType] ?? null;
|
|
184
|
-
const fieldValue = this.getValue();
|
|
185
|
-
console.log(`2. notifyEditionFinish fieldDefaultFormat: ${fieldDefaultFormat} fieldValue:${fieldValue}`);
|
|
186
|
-
|
|
187
|
-
if (fieldValue && (fieldDefaultFormat || this.fieldFormat)) {
|
|
188
|
-
console.log(`3. notifyEditionFinish this.fieldFormat: ${this.fieldFormat}`);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
intrinsicValidation = (fieldDefaultFormat?.test(fieldValue) ?? true)
|
|
192
|
-
&& (this.fieldFormat?.test(fieldValue) ?? true);
|
|
193
|
-
|
|
194
|
-
console.log(`4. notifyEditionFinish intrinsicValidation: ${intrinsicValidation}`);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (!intrinsicValidation) {
|
|
198
|
-
this.setError('99', this._intrinsicErrorMessage);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
|
|
202
|
-
intrinsicValidation = false;
|
|
203
|
-
this.setError('99', 'Campo con valor inferior al mínimo');
|
|
204
|
-
}
|
|
205
|
-
if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
|
|
206
|
-
intrinsicValidation = false;
|
|
207
|
-
this.setError('99', 'Campo con valor superior al máximo');
|
|
208
|
-
}
|
|
209
|
-
console.log('5. notifyEditionFinish END');
|
|
210
|
-
|
|
211
|
-
this._editionFinish.next({ code: this.fieldCode, intrinsicValidation });
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
setAttr(name: string, value: any) {
|
|
215
|
-
this[name] = value;
|
|
216
|
-
if (this._formConfig.monitoredFieldAttributes.includes(name)) {
|
|
217
|
-
this._attributeChange.next({ name, value });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
notifyEditionDetailRequest(detail: any) {
|
|
222
|
-
const detailEvent: DetailEvent = {
|
|
223
|
-
code: this.fieldCode,
|
|
224
|
-
detail,
|
|
225
|
-
};
|
|
226
|
-
this._detailRequest.next(detailEvent);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
setVisibleLabel(visibleLabel: boolean) { this.setAttr(fldAttr.visibleLabel, visibleLabel); }
|
|
230
|
-
showLabel() { this.setVisibleLabel(true); }
|
|
231
|
-
hideLabel() { this.setVisibleLabel(false); }
|
|
232
|
-
|
|
233
|
-
setChanged(hasChanged: boolean) { this.setAttr(fldAttr.hasChanged, hasChanged); }
|
|
234
|
-
changed() { this.setChanged(true); }
|
|
235
|
-
|
|
236
|
-
setLabel(label) { this.setAttr(fldAttr.title, label); }
|
|
237
|
-
clean() { this.setValue(this.defaultValue || ''); this.resetError(); }
|
|
238
|
-
get backend() { return this.validateOnServer; }
|
|
239
|
-
|
|
240
|
-
setEditable(editable: boolean = true) { (editable) ? this.enable() : this.disable(); }
|
|
241
|
-
|
|
242
|
-
hasError() { return this.errorCode !== NO_ERROR; }
|
|
243
|
-
resetError() { (this.errorCode !== NO_ERROR) && this.setError(NO_ERROR, null); }
|
|
244
|
-
setError(code, message, type = DEFAULT_ERROR_TYPE) {
|
|
245
|
-
this.setAttr(fldAttr.errorCode, code ?? NO_ERROR);
|
|
246
|
-
this.setAttr(fldAttr.errorType, (this.errorCode === NO_ERROR) ? '' : type);
|
|
247
|
-
this.setAttr(fldAttr.errorMessage, message ?? '');
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
getError() { return { type: this.errorType, code: this.errorCode, message: this.errorMessage }; }
|
|
251
|
-
get error() { return this.getError(); }
|
|
252
|
-
set error(errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type ?? DEFAULT_ERROR_TYPE) }
|
|
253
|
-
|
|
254
|
-
getErrorCode() { return this.getError().code; }
|
|
255
|
-
setErrorCode(code) { this.setError(code, this.errorMessage); }
|
|
256
|
-
getErrorMessage() { return this.getError().message; }
|
|
257
|
-
setErrorMessage(msg) { this.setError(this.errorCode, msg); }
|
|
258
|
-
|
|
259
|
-
get empty(): boolean { return this.isEmpty(); }
|
|
260
|
-
|
|
261
|
-
isEmpty(): boolean {
|
|
262
|
-
const fieldCurrentValue = this.getValue();
|
|
263
|
-
if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
|
-
if (this.fieldType === this._formConfig.fieldTypes.array
|
|
267
|
-
&& Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
|
|
268
|
-
return true;
|
|
269
|
-
};
|
|
270
|
-
if (this.fieldType === this._formConfig.fieldTypes.phone) {
|
|
271
|
-
if (!Array.isArray(fieldCurrentValue)) {
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
if (fieldCurrentValue.length !== 2 || !fieldCurrentValue[0] || !fieldCurrentValue[1]) {
|
|
275
|
-
return true;
|
|
276
|
-
}
|
|
277
|
-
return false;
|
|
278
|
-
};
|
|
279
|
-
return fieldCurrentValue === '';
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
getValue(): any {
|
|
283
|
-
if (this.fieldType === this._formConfig.fieldTypes.boolean
|
|
284
|
-
|| this.fieldType === this._formConfig.fieldTypes.check) {
|
|
285
|
-
return yn(this._value);
|
|
286
|
-
}
|
|
287
|
-
return this._value;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
getOptionText() {
|
|
291
|
-
return this.fieldOptions?.find(item => item.fieldOptionId === this._value)?.fieldOptionValue ?? null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
updateFromServer(fld) {
|
|
295
|
-
const fieldKeys = Object.keys(fld);
|
|
296
|
-
for (let index = 0; index < fieldKeys.length; index++) {
|
|
297
|
-
const attrName = fieldKeys[index];
|
|
298
|
-
const attrValue = fld[attrName];
|
|
299
|
-
(attrName === this._formConfig.apiFieldAttrs.visible) && this.setVisibility(attrValue);
|
|
300
|
-
(attrName === this._formConfig.apiFieldAttrs.labelVisible) && this.setVisibleLabel(fld.visibleLabel);
|
|
301
|
-
(attrName === this._formConfig.apiFieldAttrs.required) && this.setAttr(fldAttr.required, fld.required ?? false);
|
|
302
|
-
(attrName === this._formConfig.apiFieldAttrs.errorCode) && this.setAttr(fldAttr.errorCode, fld.errorCode);
|
|
303
|
-
(attrName === this._formConfig.apiFieldAttrs.errorMessage) && this.setAttr(fldAttr.errorMessage, fld.errorMessage);
|
|
304
|
-
(attrName === this._formConfig.apiFieldAttrs.tooltip) && this.setAttr(fldAttr.tooltipText, fld.tooltip);
|
|
305
|
-
(attrName === this._formConfig.apiFieldAttrs.info) && this.setAttr(fldAttr.info, fld.info);
|
|
306
|
-
(attrName === this._formConfig.apiFieldAttrs.editable) && this.setEditable(fld.editable);
|
|
307
|
-
(attrName === this._formConfig.apiFieldAttrs.title) && this.setLabel(fld.fieldTitle.toString());
|
|
308
|
-
(attrName === this._formConfig.apiFieldAttrs.value) && (this.setValue(fld.fieldValue) && this.setChanged(false));
|
|
309
|
-
(attrName === this._formConfig.apiFieldAttrs.options) && this.setFieldOptions(fld.fieldOptions);
|
|
310
|
-
(attrName === this._formConfig.apiFieldAttrs.captureType) && this.setAttr(fldAttr.captureType, fld.captureType || 'INPUT');
|
|
311
|
-
(attrName === this._formConfig.apiFieldAttrs.type) && this.setAttr(fldAttr.type, fld.fieldTypeCode);
|
|
312
|
-
(attrName === this._formConfig.apiFieldAttrs.maxLength) && this.setAttr(fldAttr.maxLength, fld.maxLength);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
setMinValue(inputMinValue) {
|
|
317
|
-
let minValue = inputMinValue;
|
|
318
|
-
if (this.fieldType === this._formConfig.fieldTypes.date) {
|
|
319
|
-
minValue = new Date(minValue);
|
|
320
|
-
}
|
|
321
|
-
this.setAttr(fldAttr.minValue, minValue);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
setMaxValue(inputMaxValue) {
|
|
325
|
-
let maxValue = inputMaxValue;
|
|
326
|
-
if (this.fieldType === this._formConfig.fieldTypes.date) {
|
|
327
|
-
maxValue = new Date(maxValue);
|
|
328
|
-
}
|
|
329
|
-
this.setAttr(fldAttr.maxValue, maxValue);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
getFieldOptions(): FieldOption[] {
|
|
333
|
-
return this.fieldOptions.map(option => {
|
|
334
|
-
const optionCopy: FieldOption = { ...option };
|
|
335
|
-
return optionCopy;
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
setFieldOptions(newOptions) {
|
|
341
|
-
if ((!this._formConfig.captureTypesWithOptions.includes(this.captureType))
|
|
342
|
-
|| typeof newOptions === UNDEFINED || !newOptions
|
|
343
|
-
|| !Array.isArray(newOptions)) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
let fieldOptions = newOptions.map(option => {
|
|
347
|
-
if (option.text !== undefined && option.text !== null
|
|
348
|
-
&& option.value !== undefined && option.value !== null) {
|
|
349
|
-
return { fieldOptionValue: option.text, fieldOptionId: option.value };
|
|
350
|
-
}
|
|
351
|
-
return { ...option };
|
|
352
|
-
});
|
|
353
|
-
fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
|
|
354
|
-
&& fieldOptions.length > 0) ? fieldOptions : [];
|
|
355
|
-
this.setAttr(fldAttr.options, fieldOptions);
|
|
356
|
-
if (this._value) {
|
|
357
|
-
if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
|
|
358
|
-
const fieldValue = this._value?.filter(item =>
|
|
359
|
-
this.fieldOptions.find(opt => opt.fieldOptionId === item)
|
|
360
|
-
);
|
|
361
|
-
this.setAttr(fldAttr.value, fieldValue);
|
|
362
|
-
} else {
|
|
363
|
-
const valInOptions = this.fieldOptions
|
|
364
|
-
.find(item => item.fieldOptionId === this._value);
|
|
365
|
-
if (!valInOptions) {
|
|
366
|
-
this.setValue('');
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
if (this.fieldRequired && this.fieldOptions.length === 1) {
|
|
371
|
-
this.setValue(this.fieldOptions[0].fieldOptionId);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
setValue(newValue, widgetUpdate = true) {
|
|
376
|
-
if (typeof newValue === UNDEFINED) {
|
|
377
|
-
return true;
|
|
378
|
-
}
|
|
379
|
-
if (newValue === null && this.required) {
|
|
380
|
-
return true;
|
|
381
|
-
}
|
|
382
|
-
let newFinalValue;
|
|
383
|
-
if (this.fieldType === this._formConfig.fieldTypes.boolean
|
|
384
|
-
|| this.fieldType === this._formConfig.fieldTypes.check) {
|
|
385
|
-
newFinalValue = yn(newValue) ?? false;
|
|
386
|
-
} else if (this.fieldType === this._formConfig.fieldTypes.array
|
|
387
|
-
|| this.fieldType === this._formConfig.fieldTypes.map) {
|
|
388
|
-
if (newValue === null || newValue === '') {
|
|
389
|
-
newFinalValue = [];
|
|
390
|
-
} else if (Array.isArray(newValue)) {
|
|
391
|
-
newFinalValue = newValue;
|
|
392
|
-
} else {
|
|
393
|
-
newFinalValue = newValue.toString().split(',');
|
|
394
|
-
}
|
|
395
|
-
} else {
|
|
396
|
-
newFinalValue = newValue;
|
|
397
|
-
}
|
|
398
|
-
if (this._value !== newFinalValue) {
|
|
399
|
-
this.setChanged(true);
|
|
400
|
-
if (widgetUpdate) {
|
|
401
|
-
this.setAttr(fldAttr.value, newFinalValue);
|
|
402
|
-
} else {
|
|
403
|
-
this._value = newFinalValue;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return true;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const NO_ERROR = '00';
|
|
2
|
-
export const HEADER = 'HEADER';
|
|
3
|
-
|
|
4
|
-
export const elementTypes = {
|
|
5
|
-
action: 'ACTION',
|
|
6
|
-
field: 'FIELD',
|
|
7
|
-
table: 'TABLE',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const formActions = {
|
|
11
|
-
tableAction: 'TABLEACTION',
|
|
12
|
-
getData: 'GETDATA',
|
|
13
|
-
getTableData: 'GETTABLEDATA',
|
|
14
|
-
validate: 'VALIDATE',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const operators = {
|
|
18
|
-
G: 'G',
|
|
19
|
-
L: 'L',
|
|
20
|
-
GE: 'GE',
|
|
21
|
-
LE: 'LE',
|
|
22
|
-
EQ: 'EQ',
|
|
23
|
-
NEQ: 'NEQ',
|
|
24
|
-
HAS: 'HAS',
|
|
25
|
-
NOTHAS: 'NOTHAS',
|
|
26
|
-
BETWEEN: 'BETWEEN',
|
|
27
|
-
IN: 'IN',
|
|
28
|
-
};
|