tuain-ng-forms-lib 14.4.91 → 14.4.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/.browserslistrc +16 -0
  2. package/.yarn/cache/nanoid-npm-4.0.0-924f5c6312-7d5946df5c.zip +0 -0
  3. package/.yarn/cache/tslib-npm-2.4.1-36f0ed04db-19480d6e03.zip +0 -0
  4. package/.yarn/cache/yn-npm-5.0.0-b001dab23c-f0ec7710d3.zip +0 -0
  5. package/.yarn/install-state.gz +0 -0
  6. package/karma.conf.js +44 -0
  7. package/ng-package.json +11 -0
  8. package/package.json +6 -24
  9. package/src/lib/classes/forms/action.ts +56 -0
  10. package/src/lib/classes/forms/element.ts +29 -0
  11. package/src/lib/classes/forms/field.ts +500 -0
  12. package/src/lib/classes/forms/form.constants.ts +28 -0
  13. package/src/lib/classes/forms/form.ts +508 -0
  14. package/src/lib/classes/forms/piece-propagate.ts +46 -0
  15. package/src/lib/classes/forms/piece.ts +122 -0
  16. package/src/lib/classes/forms/section.ts +152 -0
  17. package/src/lib/classes/forms/subsection.ts +90 -0
  18. package/src/lib/classes/forms/table/action.ts +32 -0
  19. package/src/lib/classes/forms/table/column.ts +94 -0
  20. package/src/lib/classes/forms/table/row-data.ts +121 -0
  21. package/src/lib/classes/forms/table/table.ts +478 -0
  22. package/src/lib/components/elements/action.component.ts +59 -0
  23. package/src/lib/components/elements/field.component.ts +92 -0
  24. package/src/lib/components/elements/layout/element.component.ts +13 -0
  25. package/src/lib/components/elements/layout/form-error.component.ts +11 -0
  26. package/src/lib/components/elements/layout/form-header.component.ts +17 -0
  27. package/src/lib/components/elements/layout/piece.component.ts +34 -0
  28. package/src/lib/components/elements/layout/section.component.ts +31 -0
  29. package/src/lib/components/elements/layout/sub-section.component.ts +31 -0
  30. package/src/lib/components/elements/tables/table-record-action.component.ts +50 -0
  31. package/src/lib/components/elements/tables/table-record-field.component.ts +20 -0
  32. package/src/lib/components/elements/tables/table.component.ts +86 -0
  33. package/src/lib/components/forms/basic-form.ts +1588 -0
  34. package/src/lib/services/event-manager.service.ts +21 -0
  35. package/src/lib/services/file-manager.service.ts +6 -0
  36. package/src/lib/services/form-manager.service.ts +89 -0
  37. package/src/lib/services/icon-dictionary.service.ts +159 -0
  38. package/src/lib/tuain-ng-forms-lib.module.ts +40 -0
  39. package/{public-api.d.ts → src/public-api.ts} +5 -0
  40. package/src/test.ts +27 -0
  41. package/tsconfig.lib.json +15 -0
  42. package/tsconfig.lib.prod.json +10 -0
  43. package/tsconfig.spec.json +17 -0
  44. package/esm2020/lib/classes/forms/action.mjs +0 -35
  45. package/esm2020/lib/classes/forms/element.mjs +0 -26
  46. package/esm2020/lib/classes/forms/field.mjs +0 -444
  47. package/esm2020/lib/classes/forms/form.constants.mjs +0 -26
  48. package/esm2020/lib/classes/forms/form.mjs +0 -431
  49. package/esm2020/lib/classes/forms/piece-propagate.mjs +0 -30
  50. package/esm2020/lib/classes/forms/piece.mjs +0 -95
  51. package/esm2020/lib/classes/forms/section.mjs +0 -137
  52. package/esm2020/lib/classes/forms/subsection.mjs +0 -80
  53. package/esm2020/lib/classes/forms/table/action.mjs +0 -18
  54. package/esm2020/lib/classes/forms/table/column.mjs +0 -74
  55. package/esm2020/lib/classes/forms/table/row-data.mjs +0 -116
  56. package/esm2020/lib/classes/forms/table/table.mjs +0 -415
  57. package/esm2020/lib/components/elements/action.component.mjs +0 -71
  58. package/esm2020/lib/components/elements/field.component.mjs +0 -80
  59. package/esm2020/lib/components/elements/layout/element.component.mjs +0 -20
  60. package/esm2020/lib/components/elements/layout/form-error.component.mjs +0 -20
  61. package/esm2020/lib/components/elements/layout/form-header.component.mjs +0 -31
  62. package/esm2020/lib/components/elements/layout/piece.component.mjs +0 -22
  63. package/esm2020/lib/components/elements/layout/section.component.mjs +0 -37
  64. package/esm2020/lib/components/elements/layout/sub-section.component.mjs +0 -37
  65. package/esm2020/lib/components/elements/tables/table-record-action.component.mjs +0 -56
  66. package/esm2020/lib/components/elements/tables/table-record-field.component.mjs +0 -30
  67. package/esm2020/lib/components/elements/tables/table.component.mjs +0 -93
  68. package/esm2020/lib/components/forms/basic-form.mjs +0 -1514
  69. package/esm2020/lib/services/event-manager.service.mjs +0 -18
  70. package/esm2020/lib/services/file-manager.service.mjs +0 -6
  71. package/esm2020/lib/services/form-manager.service.mjs +0 -80
  72. package/esm2020/lib/tuain-ng-forms-lib.module.mjs +0 -71
  73. package/esm2020/public-api.mjs +0 -19
  74. package/esm2020/tuain-ng-forms-lib.mjs +0 -5
  75. package/fesm2015/tuain-ng-forms-lib.mjs +0 -4230
  76. package/fesm2015/tuain-ng-forms-lib.mjs.map +0 -1
  77. package/fesm2020/tuain-ng-forms-lib.mjs +0 -4048
  78. package/fesm2020/tuain-ng-forms-lib.mjs.map +0 -1
  79. package/lib/classes/forms/action.d.ts +0 -22
  80. package/lib/classes/forms/element.d.ts +0 -17
  81. package/lib/classes/forms/field.d.ts +0 -205
  82. package/lib/classes/forms/form.constants.d.ts +0 -25
  83. package/lib/classes/forms/form.d.ts +0 -137
  84. package/lib/classes/forms/piece-propagate.d.ts +0 -11
  85. package/lib/classes/forms/piece.d.ts +0 -41
  86. package/lib/classes/forms/section.d.ts +0 -32
  87. package/lib/classes/forms/subsection.d.ts +0 -24
  88. package/lib/classes/forms/table/action.d.ts +0 -15
  89. package/lib/classes/forms/table/column.d.ts +0 -33
  90. package/lib/classes/forms/table/row-data.d.ts +0 -14
  91. package/lib/classes/forms/table/table.d.ts +0 -100
  92. package/lib/components/elements/action.component.d.ts +0 -17
  93. package/lib/components/elements/field.component.d.ts +0 -38
  94. package/lib/components/elements/layout/element.component.d.ts +0 -9
  95. package/lib/components/elements/layout/form-error.component.d.ts +0 -8
  96. package/lib/components/elements/layout/form-header.component.d.ts +0 -12
  97. package/lib/components/elements/layout/piece.component.d.ts +0 -10
  98. package/lib/components/elements/layout/section.component.d.ts +0 -11
  99. package/lib/components/elements/layout/sub-section.component.d.ts +0 -11
  100. package/lib/components/elements/tables/table-record-action.component.d.ts +0 -16
  101. package/lib/components/elements/tables/table-record-field.component.d.ts +0 -12
  102. package/lib/components/elements/tables/table.component.d.ts +0 -35
  103. package/lib/components/forms/basic-form.d.ts +0 -353
  104. package/lib/services/event-manager.service.d.ts +0 -9
  105. package/lib/services/file-manager.service.d.ts +0 -5
  106. package/lib/services/form-manager.service.d.ts +0 -28
  107. package/lib/tuain-ng-forms-lib.module.d.ts +0 -20
  108. package/tuain-ng-forms-lib.d.ts +0 -5
@@ -0,0 +1,500 @@
1
+ import { Subject } from 'rxjs';
2
+ import yn from 'yn';
3
+ import { elementTypes, NO_ERROR } from './form.constants';
4
+ import { FormElement } from './element';
5
+
6
+ const UNDEFINED = 'undefined';
7
+
8
+ const DEFAULT_ERROR_TYPE = 'error';
9
+ const DEFAULT_CAPTURE_TYPE = 'INPUT';
10
+ const DEFAULT_ALIGNMENT = 'left';
11
+
12
+ const STD_MAX_LENGTH = 50;
13
+ const BIG_MAX_LENGTH = 500;
14
+
15
+ const directChanges = [
16
+ 'defaultEditable', 'defaultValue', 'alignment', 'required', 'errorCode', 'errorMessage', 'errorType',
17
+ 'tooltip', 'info', 'format', 'intrinsicErrorMessage', 'outputOnly', 'captureType', 'title', 'type',
18
+ 'maxLength', 'maxValue', 'minLength', 'minValue', 'validateOnServer', 'serverAction', 'visibleLabel',
19
+ 'options',
20
+ ];
21
+
22
+ const attrs = {
23
+ _captureType: { name: '_captureType', propagate: 'captureType' },
24
+ _errorCode: { name: '_errorCode', propagate: 'errorCode' },
25
+ _errorMessage: { name: '_errorMessage', propagate: 'errorMessage' },
26
+ _errorType: { name: '_errorType', propagate: 'errorType' },
27
+ _defaultValue: { name: '_defaultValue', propagate: 'defaultValue' },
28
+ _defaultEditable: { name: '_defaultEditable', propagate: 'defaultEditable' },
29
+ _fieldAlignment: { name: '_fieldAlignment', propagate: 'alignment' },
30
+ _fieldCode: { name: '_fieldCode', propagate: 'code' },
31
+ _fieldInfo: { name: '_fieldInfo', propagate: 'info' },
32
+ _fieldRequired: { name: '_fieldRequired', propagate: 'required' },
33
+ _fieldTitle: { name: '_fieldTitle', propagate: 'title' },
34
+ _fieldType: { name: '_fieldType', propagate: 'type' },
35
+ _fieldFormat: { name: '_fieldFormat', propagate: 'format' },
36
+ _fieldOptions: { name: '_fieldOptions', propagate: 'options' },
37
+ _focus: { name: '_focus', propagate: 'focus' },
38
+ _hasChanged: { name: '_hasChanged', propagate: 'hasChanged' },
39
+ _intrinsicErrorMessage: { name: '_intrinsicErrorMessage', propagate: null },
40
+ _maxLength: { name: '_maxLength', propagate: 'maxLength' },
41
+ _maxValue: { name: '_maxValue', propagate: 'maxValue' },
42
+ _minLength: { name: '_minLength', propagate: 'minLength' },
43
+ _minValue: { name: '_minValue', propagate: 'minValue' },
44
+ _onValidation: { name: '_onValidation', propagate: 'onValidation' },
45
+ _outputOnly: { name: '_outputOnly', propagate: 'outputOnly' },
46
+ _tooltipText: { name: '_tooltipText', propagate: 'tooltip' },
47
+ _validateOnServer: { name: '_validateOnServer', propagate: 'validateOnServer' },
48
+ _value: { name: '_value', propagate: 'value' },
49
+ _visibleLabel: { name: '_visibleLabel', propagate: 'visibleLabel' },
50
+ };
51
+
52
+ export interface DetailEvent {
53
+ code: string;
54
+ detail: any;
55
+ }
56
+
57
+ export interface FieldOption {
58
+ fieldOptionValue: string;
59
+ fieldOptionId: string;
60
+ }
61
+
62
+ export class FieldDescriptor extends FormElement {
63
+ private readonly _editionFinish = new Subject<any>();
64
+ private readonly _editionPartial = new Subject<any>();
65
+ private readonly _detailRequest = new Subject<DetailEvent>();
66
+
67
+ private _errorType: string = '';
68
+ private _errorCode: string = '';
69
+ private _errorMessage: string = '';
70
+ private _fieldCode: string = '';
71
+ private _intrinsicErrorMessage: string = '';
72
+ private _minValue: any;
73
+ private _maxValue: any;
74
+ private _maxLength: number = 0;
75
+ private _minLength: number = 0;
76
+ private _focus: boolean = false;
77
+ private _onValidation: boolean = false;
78
+ private _validateOnServer: boolean = false;
79
+ private _value: any;
80
+ private _visibleLabel: boolean = false;
81
+
82
+ private _captureType: string = '';
83
+ private _defaultValue: string = '';
84
+ private _defaultEditable: boolean = false;
85
+ private _externalValue: any;
86
+ private _fieldAlignment: string = '';
87
+ private _fieldInfo: string = '';
88
+ private _fieldRequired: boolean = false;
89
+ private _fieldTitle: string = '';
90
+ private _fieldType: string = '';
91
+ private _fieldFormat: RegExp | null = null;
92
+ private _fieldOptions: FieldOption[] | null = null;
93
+ private _hasChanged: boolean = false;
94
+ private _outputOnly: boolean = false;
95
+ private _tooltipText: string = '';
96
+
97
+ constructor(inputFieldReceived, formConfig) {
98
+ super(inputFieldReceived, formConfig);
99
+ this.propagationCustomAttributes = this._formConfig?.propagationCustomAttributes?.fields ?? [];
100
+ this.elementType = elementTypes.field;
101
+ const fld = (inputFieldReceived) ? inputFieldReceived : {};
102
+ this.setAttr(attrs._fieldCode, fld.fieldCode);
103
+ this.title = fld.fieldTitle ?? this._fieldCode;
104
+ this.type = fld.fieldTypeCode;
105
+ this.captureType = fld.captureType ?? DEFAULT_CAPTURE_TYPE;
106
+
107
+ const defaultValue = fld.defaultValue ?? null;
108
+ if (this._fieldType === this._formConfig.fieldTypes.boolean) {
109
+ this.defaultValue = defaultValue ?? false;
110
+ } else {
111
+ this.defaultValue = defaultValue;
112
+ }
113
+ const defaultTypeAlignment = (this._formConfig.tableFieldStyles[this._fieldType] != null)
114
+ ? this._formConfig.tableFieldStyles[this._fieldType]['text-align'] : DEFAULT_ALIGNMENT;
115
+ const fieldAlignment = (fld.alignment != null) ? fld.alignment.toLowerCase() : defaultTypeAlignment;
116
+ this.alignment = fieldAlignment;
117
+ this.info = fld.info || '';
118
+ let fieldFormat;
119
+ try {
120
+ fieldFormat = (fld.format) ? new RegExp(fld.format) : null;
121
+ } catch (e) {
122
+ fieldFormat = null;
123
+ }
124
+ this.format = fieldFormat;
125
+ this.validateOnServer = fld.serverAction ?? false;
126
+ this.tooltip = fld.tooltip || '';
127
+ this.defaultEditable = this.enabled;
128
+ this.required = fld.required ?? false;
129
+ this.outputOnly = fld.outputOnly ?? false;
130
+ this.maxLength = fld.maxLength || (this._captureType === 'TEXTAREA' ? BIG_MAX_LENGTH : STD_MAX_LENGTH);
131
+ this.intrinsicErrorMessage = this._formConfig?.fieldValidations?.[this._fieldType]?.message
132
+ ?? this._formConfig?.fieldValidations?.DEFAULT?.message ?? '';
133
+
134
+ this.setError(fld.errorCode, fld.errorMessage, fld.errorType ?? DEFAULT_ERROR_TYPE);
135
+ this.setEditable(fld.editable ?? true);
136
+ this.visibleLabel = fld.visibleLabel ?? true;
137
+ this.setVisibility(fld.visible);
138
+ this.options = fld.fieldOptions;
139
+ this._setValue(fld.fieldValue ?? this._defaultValue ?? '');
140
+ }
141
+
142
+ get alignment() { return this._fieldAlignment; }
143
+ set alignment(alignment) { this.setAttr(attrs._fieldAlignment, alignment); }
144
+ get backend() { return this._validateOnServer; }
145
+
146
+ get captureType() { return this._captureType; }
147
+ set captureType(captureType) { this.setAttr(attrs._captureType, captureType); }
148
+ get code() { return this._fieldCode; }
149
+ get fieldCode() { return this._fieldCode; }
150
+ get defaultValue() { return this._defaultValue; }
151
+ set defaultValue(defaultValue) { this.setAttr(attrs._defaultValue, defaultValue); }
152
+ get defaultEditable() { return this._defaultEditable; }
153
+ set defaultEditable(editable) { this.setAttr(attrs._defaultEditable, editable); }
154
+ get detailRequest() { return this._detailRequest; }
155
+ get editionFinish() { return this._editionFinish; }
156
+ get editionPartial() { return this._editionPartial; }
157
+
158
+ get empty(): boolean {
159
+ const fieldCurrentValue = this.value;
160
+ if (fieldCurrentValue === undefined || fieldCurrentValue === null) {
161
+ return true;
162
+ }
163
+ if (this._fieldType === this._formConfig.fieldTypes.array
164
+ && Array.isArray(fieldCurrentValue) && fieldCurrentValue.length === 0) {
165
+ return true;
166
+ };
167
+ if (this._fieldType === this._formConfig.fieldTypes.phone) {
168
+ if (!Array.isArray(fieldCurrentValue)) {
169
+ return true;
170
+ }
171
+ if (fieldCurrentValue.length !== 2 || !fieldCurrentValue[0] || !fieldCurrentValue[1]) {
172
+ return true;
173
+ }
174
+ return false;
175
+ };
176
+ return fieldCurrentValue === '';
177
+ }
178
+
179
+
180
+
181
+ get error() { return { type: this._errorType, code: this._errorCode, message: this._errorMessage }; }
182
+ set error(errorObj) { this.setError(errorObj.code, errorObj.message, errorObj.type ?? DEFAULT_ERROR_TYPE) }
183
+ get errorCode() { return this._errorCode; }
184
+ set errorCode(code) { this.setError(code, this._errorMessage); }
185
+ get errorMessage() { return this._errorMessage; }
186
+ set errorMessage(msg) { this.setError(this._errorCode, msg); }
187
+ get errorType() { return this._errorType; }
188
+ get externalValue() { return this._externalValue; }
189
+ get format() { return this._fieldFormat; }
190
+ set format(format) { this.setAttr(attrs._fieldFormat, format); }
191
+ get hasChanged() { return this._hasChanged; }
192
+ set hasChanged(hasChanged) { this.setAttr(attrs._hasChanged, hasChanged); }
193
+
194
+ get info() { return this._fieldInfo; }
195
+ set info(newInfo: string) { this.setAttr(attrs._fieldInfo, newInfo); }
196
+ set intrinsicErrorMessage(message: string) { this.setAttr(attrs._intrinsicErrorMessage, message); }
197
+ get maxLength() { return (this._maxLength > 0) ? this._maxLength.toString() : ''; }
198
+ set maxLength(requiredMaxLength: any) { this.setAttr(attrs._maxLength, requiredMaxLength ? +requiredMaxLength : null); }
199
+ get maxValue() { return this._maxValue; }
200
+
201
+ set maxValue(inputMaxValue) {
202
+ let maxValue = inputMaxValue;
203
+ if (this._fieldType === this._formConfig.fieldTypes.date) {
204
+ maxValue = new Date(maxValue);
205
+ }
206
+ this.setAttr(attrs._maxValue, maxValue);
207
+ }
208
+
209
+ get minLength() { return this._minLength; }
210
+ set minLength(requiredMinLength: number) { this.setAttr(attrs._minLength, requiredMinLength ? +requiredMinLength : null); }
211
+ get minValue() { return this._minValue; }
212
+
213
+ set minValue(inputMinValue) {
214
+ let minValue = inputMinValue;
215
+ if (this._fieldType === this._formConfig.fieldTypes.date) {
216
+ minValue = new Date(minValue);
217
+ }
218
+ this.setAttr(attrs._minValue, minValue);
219
+ }
220
+
221
+ get name() { return this._fieldCode; }
222
+
223
+ get options(): FieldOption[] | null {
224
+ return this._fieldOptions?.map(option => {
225
+ const optionCopy: FieldOption = { ...option };
226
+ return optionCopy;
227
+ }) ?? null;
228
+ }
229
+
230
+ set options(newOptions) {
231
+ if ((!this._formConfig.captureTypesWithOptions.includes(this._captureType))
232
+ || typeof newOptions === UNDEFINED || !newOptions
233
+ || !Array.isArray(newOptions)) {
234
+ return;
235
+ }
236
+ let fieldOptions = newOptions.map((option: any) => {
237
+ if (option.text !== undefined && option.text !== null
238
+ && option.value !== undefined && option.value !== null) {
239
+ return { fieldOptionValue: option.text, fieldOptionId: option.value };
240
+ }
241
+ return option;
242
+ });
243
+ fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
244
+ && fieldOptions.length > 0) ? fieldOptions : [];
245
+ this.setAttr(attrs._fieldOptions, fieldOptions);
246
+ if (this._value) {
247
+ if (this._fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
248
+ const fieldValue = this._value?.filter(item =>
249
+ this._fieldOptions?.find(opt => opt.fieldOptionId === item)
250
+ );
251
+ this.setAttr(attrs._value, fieldValue);
252
+ } else {
253
+ const valInOptions = this._fieldOptions?.find(item => item.fieldOptionId === this._value);
254
+ if (!valInOptions) {
255
+ this._setValue('');
256
+ }
257
+ }
258
+ }
259
+ if (this._fieldRequired && this._fieldOptions?.length === 1 && this._value !== this._fieldOptions?.[0].fieldOptionId) {
260
+ this._setValue(this._fieldOptions?.[0].fieldOptionId);
261
+ this.notifyEditionFinish();
262
+ }
263
+ }
264
+
265
+ get optionText() { return this._fieldOptions?.find(item => item.fieldOptionId === this._value)?.fieldOptionValue ?? null; }
266
+ get outputOnly() { return this._outputOnly; }
267
+ set outputOnly(outputOnly) { this.setAttr(attrs._outputOnly, outputOnly); }
268
+ get required(): boolean { return this._fieldRequired; }
269
+ set required(required: boolean) { this.setAttr(attrs._fieldRequired, required ?? false); }
270
+ get title() { return this._fieldTitle; }
271
+ set title(title) { this.setAttr(attrs._fieldTitle, title?.toString() ?? ''); }
272
+ get tooltip() { return this._tooltipText; }
273
+ set tooltip(tooltip) { this.setAttr(attrs._tooltipText, tooltip); }
274
+ get type() { return this._fieldType; }
275
+ set type(fieldType) { this.setAttr(attrs._fieldType, fieldType); }
276
+ get validating() { return this._onValidation; }
277
+ set validating(isValidating: boolean) { this.setAttr(attrs._onValidation, isValidating); }
278
+ get value() {
279
+ return (this._fieldType === this._formConfig.fieldTypes.boolean
280
+ || this._fieldType === this._formConfig.fieldTypes.check) ? yn(this._value) : this._value;
281
+ }
282
+ get validateOnServer() { return this._validateOnServer; }
283
+ set validateOnServer(validateOnServer) { this.setAttr(attrs._validateOnServer, validateOnServer); }
284
+ get serverAction() { return this._validateOnServer; }
285
+ set serverAction(validateOnServer: boolean) { this.validateOnServer = validateOnServer; }
286
+
287
+ set value(newValue) { this._setValue(newValue); }
288
+ get visibleLabel() { return this._visibleLabel; }
289
+ set visibleLabel(visibleLabel: boolean) { this.setAttr(attrs._visibleLabel, visibleLabel); }
290
+
291
+ /**
292
+ * @deprecated Use options
293
+ */
294
+ get fieldOptions() { return this._fieldOptions; }
295
+
296
+ /**
297
+ * @deprecated Use options
298
+ */
299
+ set fieldOptions(options) { this.options = options; }
300
+
301
+ /**
302
+ * @deprecated Use value
303
+ */
304
+ get fieldValue() { return this.value; }
305
+
306
+ /**
307
+ * @deprecated Use hasChanged
308
+ */
309
+ changed(hasChanged = true) { this.hasChanged = hasChanged; }
310
+
311
+ clean() { this._setValue(this._defaultValue || ''); this.resetError(); }
312
+ focus() { this.setAttr(attrs._focus, true); }
313
+ getErrorCode() { return this.error.code; }
314
+ setErrorCode(code) { this.setError(code, this._errorMessage); }
315
+ getErrorMessage() { return this.error.message; }
316
+ setErrorMessage(msg) { this.setError(this._errorCode, msg); }
317
+ getRequired() { return this.required; }
318
+ hasError() { return this._errorCode !== NO_ERROR; }
319
+ hideLabel() { this.visibleLabel = false; }
320
+ resetError() { (this._errorCode !== NO_ERROR) && this.setError(NO_ERROR, null); }
321
+ setEditable(editable: boolean = true) { (editable) ? this.enable() : this.disable(); }
322
+ setValue(newValue, widgetUpdate = true) { this._setValue(newValue, widgetUpdate); }
323
+ showLabel() { this.visibleLabel = true; }
324
+
325
+ /**
326
+ * @deprecated Use title
327
+ */
328
+ setLabel(label) { this.title = label; }
329
+
330
+ /**
331
+ * @deprecated Use required
332
+ */
333
+ setRequired(required: boolean) { this.required = required; }
334
+
335
+ /**
336
+ * @deprecated Use changed
337
+ */
338
+ setChanged(hasChanged: boolean) { this.changed(hasChanged); }
339
+
340
+ /**
341
+ * @deprecated Use value
342
+ */
343
+ getValue(): any { return this.value; }
344
+
345
+ /**
346
+ * @deprecated Use empty
347
+ */
348
+ isEmpty(): boolean { return this.empty }
349
+
350
+ /**
351
+ * @deprecated Use error
352
+ */
353
+ getError() { return this.error; }
354
+
355
+ /**
356
+ * @deprecated Use optionText
357
+ */
358
+ getOptionText() { return this.optionText; }
359
+
360
+ /**
361
+ * @deprecated Use options
362
+ */
363
+ getFieldOptions() { return this.options; }
364
+
365
+ /**
366
+ * @deprecated Use options
367
+ */
368
+ setFieldOptions(newOptions) { return this.options = newOptions; }
369
+
370
+ /**
371
+ * @deprecated Use intrinsicErrorMessage
372
+ */
373
+ setIntrinsicErrorMessage(message: string) { this.intrinsicErrorMessage = message; }
374
+
375
+ /**
376
+ * @deprecated Use maxValue
377
+ */
378
+ setMaxValue(inputMaxValue) { this.maxValue = inputMaxValue; }
379
+
380
+ /**
381
+ * @deprecated Use minValue
382
+ */
383
+ setMinValue(inputMinValue) { this.minValue = inputMinValue; }
384
+
385
+ /**
386
+ * @deprecated Use showLabel
387
+ */
388
+ setVisibleLabel(visibleLabel: boolean) { this.visibleLabel = visibleLabel; }
389
+
390
+
391
+ notifyEditionPartial() {
392
+ this.resetError();
393
+ this._editionPartial.next({ code: this._fieldCode, intrinsicValidation: true });
394
+ }
395
+
396
+ notifyEditionFinish() {
397
+ const fieldValue = this.value;
398
+ this.resetError();
399
+ const validationConfig = this._formConfig.fieldValidations?.[this._fieldType] ?? {};
400
+ const { type, validation } = validationConfig;
401
+ let message = validationConfig?.message;
402
+ let intrinsicValidation = true;
403
+ if (fieldValue && (validation || this._fieldFormat)) {
404
+ if (type === 'regexp') {
405
+ intrinsicValidation = (validation?.test(fieldValue) ?? true)
406
+ && (this._fieldFormat?.test(fieldValue) ?? true);
407
+ } else if (type === 'function' && typeof validation === 'function') {
408
+ const { valid, message: customMessage } = validation(fieldValue, this);
409
+ intrinsicValidation = valid;
410
+ message = customMessage;
411
+ }
412
+ if (!intrinsicValidation) {
413
+ this.setError('99', message ?? this._intrinsicErrorMessage);
414
+ }
415
+ }
416
+ if (intrinsicValidation && fieldValue && this._minValue && fieldValue < this._minValue) {
417
+ intrinsicValidation = false;
418
+ this.setError('99', 'Campo con valor inferior al mínimo');
419
+ }
420
+ if (intrinsicValidation && fieldValue && this._maxValue && fieldValue > this._maxValue) {
421
+ intrinsicValidation = false;
422
+ this.setError('99', 'Campo con valor superior al máximo');
423
+ }
424
+ if (intrinsicValidation && fieldValue && typeof fieldValue === 'string'
425
+ && this._minLength && fieldValue?.length < this._minLength) {
426
+ intrinsicValidation = false;
427
+ this.setError('99', `Longitud de ${this._fieldTitle} debe ser de al menos ${this._minLength}`);
428
+ }
429
+ this._editionFinish.next({ code: this._fieldCode, intrinsicValidation });
430
+ }
431
+
432
+ notifyEditionDetailRequest(detail: any) {
433
+ const detailEvent: DetailEvent = { code: this._fieldCode, detail };
434
+ this._detailRequest.next(detailEvent);
435
+ }
436
+
437
+ setError(code, message, type = DEFAULT_ERROR_TYPE) {
438
+ this.setAttr(attrs._errorCode, code ?? NO_ERROR);
439
+ this.setAttr(attrs._errorType, (this._errorCode === NO_ERROR) ? '' : type);
440
+ this.setAttr(attrs._errorMessage, message ?? '');
441
+ }
442
+
443
+ updateFromServer(fld) {
444
+ const fieldKeys = Object.keys(fld);
445
+ for (let index = 0; index < fieldKeys.length; index++) {
446
+ const attrName = fieldKeys[index];
447
+ const attrValue = fld[attrName];
448
+ if (directChanges.includes(attrName)) {
449
+ this[attrName] = attrValue;
450
+ } else {
451
+ (attrName === 'label') && (this.title = attrValue);
452
+ (attrName === 'labelVisible') && (this.visibleLabel = attrValue);
453
+ (attrName === 'editable') && this.setEditable(attrValue);
454
+ (attrName === 'visible') && this.setVisibility(attrValue);
455
+ (attrName === 'value') && (this._setValue(attrValue) && (this.hasChanged = false));
456
+ (attrName === 'fieldValue') && (this._setValue(attrValue) && (this.hasChanged = false));
457
+
458
+ (attrName === 'fieldOptions') && (this.options = attrValue);
459
+ (attrName === 'fieldTitle') && (this.title = attrValue);
460
+ (attrName === 'fieldTypeCode') && (this.type = attrValue);
461
+ (attrName === 'fieldType') && (this.type = attrValue);
462
+ (attrName === 'tooltipText') && (this.tooltip = attrValue);
463
+ }
464
+ }
465
+ }
466
+
467
+ private _setValue(newValue, widgetUpdate = true) {
468
+ if (typeof newValue === UNDEFINED) {
469
+ return true;
470
+ }
471
+ if (newValue === null && this.required) {
472
+ return true;
473
+ }
474
+ let newFinalValue;
475
+ if (this._fieldType === this._formConfig.fieldTypes.boolean
476
+ || this._fieldType === this._formConfig.fieldTypes.check) {
477
+ newFinalValue = yn(newValue) ?? false;
478
+ } else if (this._fieldType === this._formConfig.fieldTypes.array
479
+ || this._fieldType === this._formConfig.fieldTypes.map) {
480
+ if (newValue === null || newValue === '') {
481
+ newFinalValue = [];
482
+ } else if (Array.isArray(newValue)) {
483
+ newFinalValue = newValue;
484
+ } else {
485
+ newFinalValue = newValue.toString().split(',');
486
+ }
487
+ } else {
488
+ newFinalValue = newValue;
489
+ }
490
+ if (this._value !== newFinalValue) {
491
+ this.hasChanged = true;
492
+ if (widgetUpdate) {
493
+ this.setAttr(attrs._value, newFinalValue);
494
+ } else {
495
+ this._value = newFinalValue;
496
+ }
497
+ }
498
+ return true;
499
+ }
500
+ }
@@ -0,0 +1,28 @@
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
+ };