tuain-ng-forms-lib 12.0.32 → 12.0.38

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.
@@ -1,6 +1,7 @@
1
1
  import { Component, Input, EventEmitter, Output, ChangeDetectionStrategy, NgModule } from '@angular/core';
2
2
  import { Subject, ReplaySubject } from 'rxjs';
3
3
  import { __awaiter } from 'tslib';
4
+ import yn from 'yn';
4
5
  import { nanoid } from 'nanoid';
5
6
  import { CommonModule } from '@angular/common';
6
7
  import { RouterModule } from '@angular/router';
@@ -59,7 +60,8 @@ ActionComponent.propDecorators = {
59
60
  showLabel: [{ type: Input }]
60
61
  };
61
62
 
62
- const VALUE = '';
63
+ const VALUE = 'value';
64
+ const FOCUS = 'focus';
63
65
  class FieldComponent {
64
66
  ngOnInit() {
65
67
  var _a, _b;
@@ -68,44 +70,50 @@ class FieldComponent {
68
70
  // Inicialización
69
71
  const mapping = Object.entries(this.formConfig.componentFieldAttrMap);
70
72
  for (let index = 0; index < mapping.length; index++) {
71
- const [fieldAttr, compAttr1] = mapping[index];
73
+ const [fieldAttr1, compAttr1] = mapping[index];
72
74
  const compAttr = compAttr1.toString();
73
- if (compAttr === VALUE) {
74
- this.updateValue();
75
- }
76
- else {
77
- this[compAttr] = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr.toString()];
78
- }
75
+ const fieldAttr = fieldAttr1.toString();
76
+ const attributeValue = (_b = this.field) === null || _b === void 0 ? void 0 : _b[fieldAttr];
77
+ this.dafaultProcessFieldChange(compAttr, attributeValue);
78
+ this.processFieldChange(compAttr, attributeValue);
79
79
  }
80
80
  // Subscripción a cambios en atributos
81
81
  this.field.attributeChange.subscribe(event => {
82
82
  const { name: fieldAttr, value } = event;
83
83
  const compAttr = this.formConfig.componentFieldAttrMap[fieldAttr];
84
- if (compAttr === VALUE) {
85
- this.updateValue();
86
- }
87
- else {
88
- this[compAttr] = value;
89
- }
84
+ this.dafaultProcessFieldChange(compAttr, value);
85
+ this.processFieldChange(compAttr, value);
90
86
  });
91
87
  }
92
88
  this.start();
93
89
  }
90
+ dafaultProcessFieldChange(attribute, value) {
91
+ if (attribute === VALUE) {
92
+ this.updateValue();
93
+ }
94
+ else if (attribute === FOCUS) {
95
+ this.focus();
96
+ }
97
+ else {
98
+ this[attribute] = value;
99
+ }
100
+ }
101
+ processFieldChange(attribute, value) { }
94
102
  start() { }
95
103
  focus() { }
96
104
  updateObject() {
97
- this.field._fieldValue = this.value;
105
+ this.field.setValue(this.value);
98
106
  }
99
107
  inputChanged() {
100
- this.field._fieldValue = this.value;
108
+ this.field.setValue(this.value);
101
109
  this.onChangeContent();
102
110
  }
103
111
  inputTyped() {
104
- this.field._fieldValue = this.value;
112
+ this.field.setValue(this.value);
105
113
  this.onInputChange();
106
114
  }
107
115
  updateValue() {
108
- this.value = this.field._fieldValue;
116
+ this.value = this.field.getValue();
109
117
  }
110
118
  onInputChange() {
111
119
  setTimeout(() => this.field.notifyEditionPartial(), 50);
@@ -293,7 +301,6 @@ class FormElement {
293
301
  this._visibleForced = false;
294
302
  this.disabled = (_a = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.disabled) !== null && _a !== void 0 ? _a : false;
295
303
  this.setVisibility((_b = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.visible) !== null && _b !== void 0 ? _b : true);
296
- this.widget = null;
297
304
  this.customAttributes = (_c = elementDefinition === null || elementDefinition === void 0 ? void 0 : elementDefinition.customAttributes) !== null && _c !== void 0 ? _c : {};
298
305
  }
299
306
  getCustomAttribute(name) { var _a, _b; return (_b = (_a = this.customAttributes) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : null; }
@@ -994,7 +1001,6 @@ class LibTableComponent {
994
1001
  this.tableFieldStyles = this.formConfig.tableFieldStyles;
995
1002
  this.selectable = this.table.selectable;
996
1003
  this.hasActions = this.table.hasActions;
997
- this.table.widget = this;
998
1004
  this.inlineActions = this.table.getActions(this.formConfig.tableActions.inline);
999
1005
  this.globalActions = this.table.getActions(this.formConfig.tableActions.global);
1000
1006
  this.selectionActions = this.table.getActions(this.formConfig.tableActions.selection);
@@ -1145,11 +1151,12 @@ const STD_MAX_LENGTH = 50;
1145
1151
  const BIG_MAX_LENGTH = 500;
1146
1152
  const fldAttr = {
1147
1153
  validateOnServer: 'validateOnServer',
1148
- value: '_fieldValue',
1154
+ value: '_value',
1149
1155
  minValue: '_minValue',
1150
1156
  maxValue: '_maxValue',
1151
1157
  maxLength: '_maxLength',
1152
1158
  onValidation: '_onValidation',
1159
+ focus: 'focus',
1153
1160
  intrinsicErrorMessage: '_intrinsicErrorMessage',
1154
1161
  code: 'fieldCode',
1155
1162
  info: 'fieldInfo',
@@ -1222,6 +1229,7 @@ class FieldDescriptor extends FormElement {
1222
1229
  get info() { return this.fieldInfo; }
1223
1230
  get validating() { return this._onValidation; }
1224
1231
  set validating(isValidating) { this.setAttr(fldAttr.onValidation, isValidating); }
1232
+ focus() { this.setAttr(fldAttr.focus, true); }
1225
1233
  setIntrinsicErrorMessage(message) { this.setAttr(fldAttr.intrinsicErrorMessage, message); }
1226
1234
  set intrinsicErrorMessage(message) { this.setIntrinsicErrorMessage(message); }
1227
1235
  get fieldValue() { return this.getValue(); }
@@ -1272,7 +1280,6 @@ class FieldDescriptor extends FormElement {
1272
1280
  hideLabel() { this.setVisibleLabel(false); }
1273
1281
  setChanged(hasChanged) { this.setAttr(fldAttr.hasChanged, hasChanged); }
1274
1282
  changed() { this.setChanged(true); }
1275
- getRawValue() { return this._fieldValue; }
1276
1283
  setLabel(label) { this.setAttr(fldAttr.title, label); }
1277
1284
  clean() { this.setValue(this.defaultValue || ''); this.resetError(); }
1278
1285
  get backend() { return this.validateOnServer; }
@@ -1305,22 +1312,11 @@ class FieldDescriptor extends FormElement {
1305
1312
  return fieldCurrentValue === '';
1306
1313
  }
1307
1314
  getValue() {
1308
- var _a, _b;
1309
- switch (this.fieldType) {
1310
- case this._formConfig.fieldTypes.boolean:
1311
- return (_a = this._fieldValue) !== null && _a !== void 0 ? _a : false;
1312
- break;
1313
- case this._formConfig.fieldTypes.check:
1314
- return (_b = this._fieldValue) !== null && _b !== void 0 ? _b : false;
1315
- break;
1316
- case this._formConfig.fieldTypes.currency:
1317
- return (typeof this._fieldValue === 'string')
1318
- ? this._fieldValue.replace(',', '') : this._fieldValue;
1319
- break;
1320
- default:
1321
- return this._fieldValue;
1322
- break;
1315
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
1316
+ || this.fieldType === this._formConfig.fieldTypes.check) {
1317
+ return yn(this._value);
1323
1318
  }
1319
+ return this._value;
1324
1320
  }
1325
1321
  updateFromServer(fld) {
1326
1322
  var _a;
@@ -1347,39 +1343,25 @@ class FieldDescriptor extends FormElement {
1347
1343
  setFieldType(inputFieldType) {
1348
1344
  this.setAttr(fldAttr.type, inputFieldType);
1349
1345
  }
1350
- setMinValue(minValue) {
1351
- var _a, _b, _c;
1352
- if (this.fieldType === this._formConfig.fieldTypes.date
1353
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMinValue)) {
1354
- this.setAttr(fldAttr.minValue, minValue);
1355
- if (!minValue) {
1356
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMinValue(false);
1357
- }
1358
- else {
1359
- const minDate = new Date(minValue);
1360
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMinValue(minDate);
1361
- }
1346
+ setMinValue(inputMinValue) {
1347
+ let minValue = inputMinValue;
1348
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1349
+ minValue = new Date(minValue);
1362
1350
  }
1351
+ this.setAttr(fldAttr.minValue, minValue);
1363
1352
  }
1364
- setMaxValue(maxValue) {
1365
- var _a, _b, _c;
1366
- if (this.fieldType === this._formConfig.fieldTypes.date
1367
- && ((_a = this.widget) === null || _a === void 0 ? void 0 : _a.setMaxValue)) {
1368
- this.setAttr(fldAttr.maxValue, maxValue);
1369
- if (!maxValue) {
1370
- (_b = this.widget) === null || _b === void 0 ? void 0 : _b.setMaxValue(false);
1371
- }
1372
- else {
1373
- const maxDate = new Date(maxValue);
1374
- (_c = this.widget) === null || _c === void 0 ? void 0 : _c.setMaxValue(maxDate);
1375
- }
1353
+ setMaxValue(inputMaxValue) {
1354
+ let maxValue = inputMaxValue;
1355
+ if (this.fieldType === this._formConfig.fieldTypes.date) {
1356
+ maxValue = new Date(maxValue);
1376
1357
  }
1358
+ this.setAttr(fldAttr.maxValue, maxValue);
1377
1359
  }
1378
1360
  getFieldOptions() {
1379
1361
  return JSON.parse(JSON.stringify(this.fieldOptions));
1380
1362
  }
1381
1363
  setFieldOptions(newOptions) {
1382
- var _a, _b, _c, _d;
1364
+ var _a;
1383
1365
  if ((this.captureType !== 'LIST' && this.captureType !== 'RADIO')
1384
1366
  || typeof newOptions === UNDEFINED || !newOptions
1385
1367
  || !Array.isArray(newOptions)) {
@@ -1395,17 +1377,14 @@ class FieldDescriptor extends FormElement {
1395
1377
  fieldOptions = (fieldOptions && Array.isArray(fieldOptions)
1396
1378
  && fieldOptions.length > 0) ? fieldOptions : [];
1397
1379
  this.setAttr(fldAttr.options, fieldOptions);
1398
- if (this.fieldType === this._formConfig.fieldTypes.array && this.widget) {
1399
- return (_a = this.widget) === null || _a === void 0 ? void 0 : _a.refereshContent();
1400
- }
1401
- if (this._fieldValue) {
1402
- if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._fieldValue)) {
1403
- const fieldValue = (_b = this._fieldValue) === null || _b === void 0 ? void 0 : _b.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
1380
+ if (this._value) {
1381
+ if (this.fieldType === this._formConfig.fieldTypes.array && Array.isArray(this._value)) {
1382
+ const fieldValue = (_a = this._value) === null || _a === void 0 ? void 0 : _a.filter(item => this.fieldOptions.find(opt => opt.fieldOptionId === item));
1404
1383
  this.setAttr(fldAttr.value, fieldValue);
1405
1384
  }
1406
1385
  else {
1407
1386
  const valInOptions = this.fieldOptions
1408
- .find(item => item.fieldOptionId === this._fieldValue);
1387
+ .find(item => item.fieldOptionId === this._value);
1409
1388
  if (!valInOptions) {
1410
1389
  this.setValue('');
1411
1390
  }
@@ -1413,56 +1392,40 @@ class FieldDescriptor extends FormElement {
1413
1392
  }
1414
1393
  if (this.fieldRequired && this.fieldOptions.length === 1) {
1415
1394
  this.setValue(this.fieldOptions[0].fieldOptionId);
1416
- if ((_c = this.widget) === null || _c === void 0 ? void 0 : _c.onChangeContent) {
1417
- (_d = this.widget) === null || _d === void 0 ? void 0 : _d.onChangeContent();
1418
- }
1419
1395
  }
1420
1396
  }
1421
1397
  setValue(newValue, widgetUpdate = true) {
1422
- var _a;
1423
1398
  if (typeof newValue === UNDEFINED || newValue === null) {
1424
1399
  return true;
1425
1400
  }
1426
1401
  let newFinalValue;
1427
- switch (this.fieldType) {
1428
- case 'BOOLEAN':
1429
- newFinalValue = !!newValue;
1430
- break;
1431
- case this._formConfig.fieldTypes.boolean:
1432
- newFinalValue = !!newValue;
1433
- break;
1434
- case this._formConfig.fieldTypes.check:
1435
- newFinalValue = !!newValue;
1436
- break;
1437
- case this._formConfig.fieldTypes.array:
1438
- if (newValue === null || newValue === '') {
1439
- newFinalValue = [];
1440
- }
1441
- else if (!Array.isArray(newValue)) {
1442
- if (typeof (newValue) !== 'string') {
1443
- newValue = newValue.toString();
1444
- }
1445
- newFinalValue = newValue.split(',');
1446
- }
1447
- else {
1448
- newFinalValue = newValue;
1449
- }
1450
- break;
1451
- case this._formConfig.fieldTypes.map:
1452
- newFinalValue = newValue;
1453
- if (newFinalValue && this.widget && widgetUpdate) {
1454
- const latitude = parseFloat(newFinalValue[0]);
1455
- const longitude = parseFloat(newFinalValue[1]);
1456
- (_a = this.widget) === null || _a === void 0 ? void 0 : _a.setLocation(latitude, longitude);
1457
- }
1458
- break;
1459
- default:
1402
+ if (this.fieldType === this._formConfig.fieldTypes.boolean
1403
+ || this.fieldType === this._formConfig.fieldTypes.check) {
1404
+ newFinalValue = yn(newValue);
1405
+ }
1406
+ else if (this.fieldType === this._formConfig.fieldTypes.array
1407
+ || this.fieldType === this._formConfig.fieldTypes.map) {
1408
+ if (newValue === null || newValue === '') {
1409
+ newFinalValue = [];
1410
+ }
1411
+ else if (Array.isArray(newValue)) {
1460
1412
  newFinalValue = newValue;
1461
- break;
1413
+ }
1414
+ else {
1415
+ newFinalValue = newValue.toString().split(',');
1416
+ }
1462
1417
  }
1463
- if (this._fieldValue !== newFinalValue) {
1418
+ else {
1419
+ newFinalValue = newValue;
1420
+ }
1421
+ if (this._value !== newFinalValue) {
1464
1422
  this.setChanged(true);
1465
- this.setAttr(fldAttr.value, newFinalValue);
1423
+ if (widgetUpdate) {
1424
+ this.setAttr(fldAttr.value, newFinalValue);
1425
+ }
1426
+ else {
1427
+ this._value = newFinalValue;
1428
+ }
1466
1429
  }
1467
1430
  return true;
1468
1431
  }
@@ -3549,11 +3512,8 @@ class BasicFormComponent {
3549
3512
  this.tagFieldsWithError(requiredEmptyFields, null, this.formConfig.formStandardErrors.requiredField);
3550
3513
  for (const fieldCode of requiredEmptyFields) {
3551
3514
  const requiredEmptyField = this.getField(fieldCode);
3552
- if (requiredEmptyField && requiredEmptyField.widget
3553
- && requiredEmptyField.widget.focus) {
3554
- requiredEmptyField.widget.focus();
3555
- break;
3556
- }
3515
+ requiredEmptyField === null || requiredEmptyField === void 0 ? void 0 : requiredEmptyField.focus();
3516
+ break;
3557
3517
  }
3558
3518
  }
3559
3519
  const validationIssueFields = this.getFieldsWithValidationIssues(null, sectionCode);
@@ -3562,11 +3522,8 @@ class BasicFormComponent {
3562
3522
  this.setError(this.formConfig.formStandardErrors.typeWarning, this.formConfig.formStandardErrors.validationTitle, this.formConfig.formStandardErrors.validationFields);
3563
3523
  for (const fieldCode of validationIssueFields) {
3564
3524
  const validationIssueField = this.getField(fieldCode);
3565
- if (validationIssueField && validationIssueField.widget
3566
- && validationIssueField.widget.focus) {
3567
- validationIssueField.widget.focus();
3568
- break;
3569
- }
3525
+ validationIssueField.focus();
3526
+ break;
3570
3527
  }
3571
3528
  }
3572
3529
  return validationError;