tuain-ng-forms-lib 14.0.0 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.browserslistrc +16 -0
- 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 +44 -0
- package/ng-package.json +11 -0
- package/package.json +2 -22
- package/src/lib/classes/forms/action.ts +55 -0
- package/src/lib/classes/forms/element.ts +98 -0
- package/src/lib/classes/forms/field.ts +408 -0
- package/src/lib/classes/forms/form.constants.ts +28 -0
- package/src/lib/classes/forms/form.ts +495 -0
- package/src/lib/classes/forms/section.ts +154 -0
- package/src/lib/classes/forms/subsection.ts +91 -0
- package/src/lib/classes/forms/table/action.ts +41 -0
- package/src/lib/classes/forms/table/column.ts +91 -0
- package/src/lib/classes/forms/table/row-data.ts +118 -0
- package/src/lib/classes/forms/table/table.ts +438 -0
- package/src/lib/components/elements/action.component.ts +53 -0
- package/src/lib/components/elements/field.component.ts +118 -0
- package/src/lib/components/elements/layout/element.component.ts +28 -0
- package/src/lib/components/elements/layout/form-error.component.ts +11 -0
- package/src/lib/components/elements/layout/form-header.component.ts +17 -0
- package/src/lib/components/elements/layout/section.component.ts +16 -0
- package/src/lib/components/elements/layout/sub-section.component.ts +17 -0
- package/src/lib/components/elements/tables/table-record-action.component.ts +37 -0
- package/src/lib/components/elements/tables/table-record-field.component.ts +19 -0
- package/src/lib/components/elements/tables/table.component.ts +102 -0
- package/src/lib/components/forms/basic-form.ts +1496 -0
- package/src/lib/services/event-manager.service.ts +21 -0
- package/src/lib/services/file-manager.service.ts +6 -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/esm2020/lib/classes/forms/action.mjs +0 -35
- package/esm2020/lib/classes/forms/element.mjs +0 -76
- package/esm2020/lib/classes/forms/field.mjs +0 -321
- package/esm2020/lib/classes/forms/form.constants.mjs +0 -26
- package/esm2020/lib/classes/forms/form.mjs +0 -422
- package/esm2020/lib/classes/forms/section.mjs +0 -132
- package/esm2020/lib/classes/forms/subsection.mjs +0 -70
- package/esm2020/lib/classes/forms/table/action.mjs +0 -22
- package/esm2020/lib/classes/forms/table/column.mjs +0 -61
- package/esm2020/lib/classes/forms/table/row-data.mjs +0 -111
- package/esm2020/lib/classes/forms/table/table.mjs +0 -372
- package/esm2020/lib/components/elements/action.component.mjs +0 -58
- package/esm2020/lib/components/elements/field.component.mjs +0 -90
- package/esm2020/lib/components/elements/layout/element.component.mjs +0 -31
- package/esm2020/lib/components/elements/layout/form-error.component.mjs +0 -20
- package/esm2020/lib/components/elements/layout/form-header.component.mjs +0 -30
- package/esm2020/lib/components/elements/layout/section.component.mjs +0 -22
- package/esm2020/lib/components/elements/layout/sub-section.component.mjs +0 -24
- package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +0 -40
- package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +0 -25
- package/esm2020/lib/components/elements/tables/table.component.mjs +0 -95
- package/esm2020/lib/components/forms/basic-form.mjs +0 -1425
- package/esm2020/lib/services/event-manager.service.mjs +0 -18
- package/esm2020/lib/services/file-manager.service.mjs +0 -6
- package/esm2020/lib/services/form-manager.service.mjs +0 -80
- package/esm2020/lib/tuain-ng-forms-lib.module.mjs +0 -71
- package/esm2020/public-api.mjs +0 -19
- package/esm2020/tuain-ng-forms-lib.mjs +0 -5
- package/fesm2015/tuain-ng-forms-lib.mjs +0 -3803
- package/fesm2015/tuain-ng-forms-lib.mjs.map +0 -1
- package/fesm2020/tuain-ng-forms-lib.mjs +0 -3634
- package/fesm2020/tuain-ng-forms-lib.mjs.map +0 -1
- package/lib/classes/forms/action.d.ts +0 -22
- package/lib/classes/forms/element.d.ts +0 -41
- package/lib/classes/forms/field.d.ts +0 -109
- package/lib/classes/forms/form.constants.d.ts +0 -25
- package/lib/classes/forms/form.d.ts +0 -134
- package/lib/classes/forms/section.d.ts +0 -39
- package/lib/classes/forms/subsection.d.ts +0 -26
- package/lib/classes/forms/table/action.d.ts +0 -20
- 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 -100
- package/lib/components/elements/action.component.d.ts +0 -21
- package/lib/components/elements/field.component.d.ts +0 -43
- package/lib/components/elements/layout/element.component.d.ts +0 -14
- package/lib/components/elements/layout/form-error.component.d.ts +0 -8
- package/lib/components/elements/layout/form-header.component.d.ts +0 -12
- package/lib/components/elements/layout/section.component.d.ts +0 -10
- package/lib/components/elements/layout/sub-section.component.d.ts +0 -11
- package/lib/components/elements/tables/table-record-action.component.d.ts +0 -15
- package/lib/components/elements/tables/table-record-field.component.d.ts +0 -11
- package/lib/components/elements/tables/table.component.d.ts +0 -47
- package/lib/components/forms/basic-form.d.ts +0 -307
- package/lib/services/event-manager.service.d.ts +0 -9
- package/lib/services/file-manager.service.d.ts +0 -5
- package/lib/services/form-manager.service.d.ts +0 -28
- package/lib/tuain-ng-forms-lib.module.d.ts +0 -20
- package/tuain-ng-forms-lib.d.ts +0 -5
package/.browserslistrc
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
|
|
2
|
+
# For additional information regarding the format and rule options, please see:
|
|
3
|
+
# https://github.com/browserslist/browserslist#queries
|
|
4
|
+
|
|
5
|
+
# For the full list of supported browsers by the Angular framework, please see:
|
|
6
|
+
# https://angular.io/guide/browser-support
|
|
7
|
+
|
|
8
|
+
# You can see what browsers were selected by your queries by running:
|
|
9
|
+
# npx browserslist
|
|
10
|
+
|
|
11
|
+
last 1 Chrome version
|
|
12
|
+
last 1 Firefox version
|
|
13
|
+
last 2 Edge major versions
|
|
14
|
+
last 2 Safari major versions
|
|
15
|
+
last 2 iOS major versions
|
|
16
|
+
Firefox ESR
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/karma.conf.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Karma configuration file, see link for more information
|
|
2
|
+
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
|
3
|
+
|
|
4
|
+
module.exports = function (config) {
|
|
5
|
+
config.set({
|
|
6
|
+
basePath: '',
|
|
7
|
+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
|
8
|
+
plugins: [
|
|
9
|
+
require('karma-jasmine'),
|
|
10
|
+
require('karma-chrome-launcher'),
|
|
11
|
+
require('karma-jasmine-html-reporter'),
|
|
12
|
+
require('karma-coverage'),
|
|
13
|
+
require('@angular-devkit/build-angular/plugins/karma')
|
|
14
|
+
],
|
|
15
|
+
client: {
|
|
16
|
+
jasmine: {
|
|
17
|
+
// you can add configuration options for Jasmine here
|
|
18
|
+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
|
19
|
+
// for example, you can disable the random execution with `random: false`
|
|
20
|
+
// or set a specific seed with `seed: 4321`
|
|
21
|
+
},
|
|
22
|
+
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
|
23
|
+
},
|
|
24
|
+
jasmineHtmlReporter: {
|
|
25
|
+
suppressAll: true // removes the duplicated traces
|
|
26
|
+
},
|
|
27
|
+
coverageReporter: {
|
|
28
|
+
dir: require('path').join(__dirname, '../../coverage/tuain-ng-forms-lib'),
|
|
29
|
+
subdir: '.',
|
|
30
|
+
reporters: [
|
|
31
|
+
{ type: 'html' },
|
|
32
|
+
{ type: 'text-summary' }
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
reporters: ['progress', 'kjhtml'],
|
|
36
|
+
port: 9876,
|
|
37
|
+
colors: true,
|
|
38
|
+
logLevel: config.LOG_INFO,
|
|
39
|
+
autoWatch: true,
|
|
40
|
+
browsers: ['Chrome'],
|
|
41
|
+
singleRun: false,
|
|
42
|
+
restartOnFileChange: true
|
|
43
|
+
});
|
|
44
|
+
};
|
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuain-ng-forms-lib",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.1",
|
|
4
4
|
"description": "Componentes y Clases Angular para la gestión de formularios TUAIN",
|
|
5
5
|
"author": "Mauricio Méndez, Imix Consulting",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,25 +22,5 @@
|
|
|
22
22
|
"nanoid": "^4.0.0",
|
|
23
23
|
"tslib": "^2.4.0",
|
|
24
24
|
"yn": "^5.0.0"
|
|
25
|
-
}
|
|
26
|
-
"module": "fesm2015/tuain-ng-forms-lib.mjs",
|
|
27
|
-
"es2020": "fesm2020/tuain-ng-forms-lib.mjs",
|
|
28
|
-
"esm2020": "esm2020/tuain-ng-forms-lib.mjs",
|
|
29
|
-
"fesm2020": "fesm2020/tuain-ng-forms-lib.mjs",
|
|
30
|
-
"fesm2015": "fesm2015/tuain-ng-forms-lib.mjs",
|
|
31
|
-
"typings": "tuain-ng-forms-lib.d.ts",
|
|
32
|
-
"exports": {
|
|
33
|
-
"./package.json": {
|
|
34
|
-
"default": "./package.json"
|
|
35
|
-
},
|
|
36
|
-
".": {
|
|
37
|
-
"types": "./tuain-ng-forms-lib.d.ts",
|
|
38
|
-
"esm2020": "./esm2020/tuain-ng-forms-lib.mjs",
|
|
39
|
-
"es2020": "./fesm2020/tuain-ng-forms-lib.mjs",
|
|
40
|
-
"es2015": "./fesm2015/tuain-ng-forms-lib.mjs",
|
|
41
|
-
"node": "./fesm2015/tuain-ng-forms-lib.mjs",
|
|
42
|
-
"default": "./fesm2020/tuain-ng-forms-lib.mjs"
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"sideEffects": false
|
|
25
|
+
}
|
|
46
26
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,408 @@
|
|
|
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
|
+
}
|