tuain-ng-forms-lib 14.5.25 → 14.5.27

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.
@@ -513,8 +513,8 @@ class FormPiece {
513
513
  this._formState = '';
514
514
  this._absoluteVisible = true;
515
515
  this._absoluteDisabled = false;
516
- this.visibleStates = null;
517
- this.enabledStates = null;
516
+ this.visibleStates = [];
517
+ this.enabledStates = [];
518
518
  this._form = null;
519
519
  this._visible = true;
520
520
  this._disabled = false;
@@ -546,13 +546,35 @@ class FormPiece {
546
546
  const visibleStates = (!Array.isArray(newStates) && typeof newStates === 'string')
547
547
  ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
548
548
  : newStates;
549
- this.visibleStates = (Array.isArray(visibleStates)) ? visibleStates : [];
549
+ this.visibleStates = (Array.isArray(visibleStates)) ? [...(new Set(visibleStates))] : [];
550
+ }
551
+ addVisibleState(state) {
552
+ if (!this.visibleStates.includes(state)) {
553
+ this.visibleStates.push(state);
554
+ }
555
+ }
556
+ removeVisibleState(state) {
557
+ const existStateIdx = this.visibleStates.findIndex(st => st === state);
558
+ if (existStateIdx >= 0) {
559
+ this.visibleStates.splice(existStateIdx, 1);
560
+ }
550
561
  }
551
562
  setEnabledStates(newStates) {
552
563
  const enabledStates = (!Array.isArray(newStates) && typeof newStates === 'string')
553
564
  ? newStates.split(',').map(state => state.trim()).filter(state => state.length > 0)
554
565
  : newStates;
555
- this.enabledStates = (Array.isArray(enabledStates)) ? enabledStates : [];
566
+ this.enabledStates = (Array.isArray(enabledStates)) ? [...(new Set(enabledStates))] : [];
567
+ }
568
+ addEnabledState(state) {
569
+ if (!this.enabledStates.includes(state)) {
570
+ this.enabledStates.push(state);
571
+ }
572
+ }
573
+ removeEnabledState(state) {
574
+ const existStateIdx = this.enabledStates.findIndex(st => st === state);
575
+ if (existStateIdx >= 0) {
576
+ this.enabledStates.splice(existStateIdx, 1);
577
+ }
556
578
  }
557
579
  viewOnState(state) { return (this.visibleStates && state) ? this.visibleStates.includes(state) : false; }
558
580
  enabledOnState(state) { return (this.enabledStates && state) ? this.enabledStates.includes(state) : false; }
@@ -1619,23 +1641,70 @@ class RecordTable extends FormElement {
1619
1641
  }
1620
1642
  updateFromServer(tableReceived) {
1621
1643
  this.requestedPage = 1;
1622
- this.visible = tableReceived?.visible || true;
1623
- this.totalPages = tableReceived.totalPages || 1;
1624
- this.recordsNumber = tableReceived.recordsNumber;
1625
- this.setAttr(attrs.currentPage, +tableReceived?.currentPage || 1);
1626
- this.setAttr(attrs.recordsPerPage, +tableReceived.recordsPerPage);
1627
- this.setAttr(attrs.totalRecordsNumber, (this.clientPaging) ? tableReceived.tableRecords.length : +tableReceived.totalRecordsNumber);
1628
- this.setAttr(attrs.sorting, {
1629
- columnName: tableReceived.sortingColumn || '',
1630
- direction: tableReceived.sortingDirection || ''
1631
- });
1632
- this.waiting = false;
1633
- if (!this._appendPages) {
1634
- this.replaceRecords(tableReceived.tableRecords);
1644
+ const { visible = true, totalPages = 1, recordsNumber, currentPage = 1, recordsPerPage, totalRecordsNumber, sortingColumn, sortingDirection, tableRecords, actions, fields, } = tableReceived;
1645
+ this.visible = visible;
1646
+ if (actions) {
1647
+ Object.keys(actions).forEach(actionCode => {
1648
+ const tblAction = this.getAction(actionCode);
1649
+ const actionReceived = actions[actionCode];
1650
+ if (actionReceived.visible === true || actionReceived.visible === false) {
1651
+ (actionReceived.visible === true) && tblAction.show();
1652
+ (actionReceived.visible === false) && tblAction.hide();
1653
+ }
1654
+ if (actionReceived.enabled === true || actionReceived.enabled === false) {
1655
+ (actionReceived.enabled === true) && tblAction.enable();
1656
+ (actionReceived.enabled === false) && tblAction.disable();
1657
+ }
1658
+ if (actionReceived.showOnStates) {
1659
+ actionReceived.showOnStates?.forEach(newState => {
1660
+ tblAction.addVisibleState(newState);
1661
+ });
1662
+ }
1663
+ if (actionReceived.hideOnStates) {
1664
+ actionReceived.hideOnStates?.forEach(newState => {
1665
+ tblAction.removeVisibleState(newState);
1666
+ });
1667
+ }
1668
+ if (actionReceived.enableOnStates) {
1669
+ actionReceived.enableOnStates?.forEach(newState => {
1670
+ tblAction.addEnabledState(newState);
1671
+ });
1672
+ }
1673
+ if (actionReceived.disableOnStates) {
1674
+ actionReceived.disableOnStates?.forEach(newState => {
1675
+ tblAction.removeEnabledState(newState);
1676
+ });
1677
+ }
1678
+ });
1635
1679
  }
1636
- else {
1637
- this.appendRecords(tableReceived.tableRecords);
1680
+ if (fields) {
1681
+ Object.keys(fields).forEach(fieldCode => {
1682
+ const tblField = this.columnDefinition(fieldCode);
1683
+ const fieldReceived = fields[fieldCode];
1684
+ if (fieldReceived.visible === true || fieldReceived.visible === false) {
1685
+ (fieldReceived.visible === true) && tblField.show();
1686
+ (fieldReceived.visible === false) && tblField.hide();
1687
+ }
1688
+ });
1638
1689
  }
1690
+ if (tableRecords) {
1691
+ this.totalPages = totalPages;
1692
+ this.recordsNumber = recordsNumber;
1693
+ this.setAttr(attrs.currentPage, +currentPage);
1694
+ this.setAttr(attrs.recordsPerPage, +recordsPerPage);
1695
+ this.setAttr(attrs.totalRecordsNumber, (this.clientPaging) ? tableRecords.length : +totalRecordsNumber);
1696
+ this.setAttr(attrs.sorting, {
1697
+ columnName: sortingColumn || '',
1698
+ direction: sortingDirection || ''
1699
+ });
1700
+ if (!this._appendPages) {
1701
+ this.replaceRecords(tableRecords);
1702
+ }
1703
+ else {
1704
+ this.appendRecords(tableRecords);
1705
+ }
1706
+ }
1707
+ this.waiting = false;
1639
1708
  this.updateVisibleRecords();
1640
1709
  }
1641
1710
  getTableRecord(recordId) {
@@ -2188,7 +2257,7 @@ class FormStructureAndData {
2188
2257
  setFieldErrorMessage(code, message) { this.getField(code)?.setErrorMessage(message); }
2189
2258
  setFieldOptions(code, optionsArray, idAttribute, nameAttribute) {
2190
2259
  const field = this.getField(code);
2191
- if (field && optionsArray?.length > 0) {
2260
+ if (field && optionsArray) {
2192
2261
  const fieldOptions = optionsArray.map(item => ({
2193
2262
  fieldOptionId: item[idAttribute],
2194
2263
  fieldOptionValue: item[nameAttribute]