@osovitny/anatoly 2.0.19 → 2.0.21

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,12 +1,12 @@
1
1
  import Swal from 'sweetalert2';
2
2
  import { v4 } from 'uuid';
3
- import { Injectable, ɵɵdefineInjectable, Injector, NgModule, Optional, SkipSelf, Component, Input } from '@angular/core';
3
+ import { Injectable, ɵɵdefineInjectable, Injector, NgModule, Optional, SkipSelf, Component, Input, Directive, ElementRef } from '@angular/core';
4
4
  import { ActivatedRoute, Router } from '@angular/router';
5
5
  import { HttpClient, HttpResponse } from '@angular/common/http';
6
6
  import { map, tap } from 'rxjs/operators';
7
7
  import { BehaviorSubject } from 'rxjs';
8
8
  import { CommonModule } from '@angular/common';
9
- import { ReactiveFormsModule, FormsModule } from '@angular/forms';
9
+ import { NgControl, ReactiveFormsModule, FormsModule } from '@angular/forms';
10
10
  import { FroalaEditorModule, FroalaViewModule } from 'angular-froala-wysiwyg';
11
11
 
12
12
  /*
@@ -1382,38 +1382,47 @@ class BaseEditComponent extends BaseComponent {
1382
1382
  this.formSubmitted = false;
1383
1383
  }
1384
1384
  isActionAdding() {
1385
- let id = Utils.getValueByNameInQS("id");
1386
- if (typeof id === "undefined" || id === "")
1385
+ var id = Utils.getValueByNameInQS("id");
1386
+ if (typeof id === 'undefined' || id == '')
1387
1387
  return true;
1388
1388
  return false;
1389
1389
  }
1390
1390
  getEntityId() {
1391
1391
  return this.getQSId();
1392
1392
  }
1393
- isItemInvalid(name) {
1394
- if (typeof name === "undefined" || name === "") {
1393
+ isControlValid(name, formGroup = null) {
1394
+ return !this.isControlInvalid(name, formGroup);
1395
+ }
1396
+ isControlInvalid(name, formGroup = null) {
1397
+ if (typeof name === 'undefined' || name == '') {
1395
1398
  return false;
1396
1399
  }
1397
- if (!this.formGroup) {
1400
+ let fg = (formGroup) ? formGroup : this.formGroup;
1401
+ if (!fg) {
1398
1402
  return false;
1399
1403
  }
1400
- if (this.formGroup.get(name)) {
1401
- return ((this.formSubmitted && this.formGroup.get(name).invalid) ||
1402
- (this.formGroup.get(name).touched && this.formGroup.get(name).invalid));
1404
+ if (fg.get(name)) {
1405
+ return (this.formSubmitted && fg.get(name).invalid) ||
1406
+ (fg.get(name).touched && fg.get(name).invalid);
1403
1407
  }
1404
1408
  return false;
1405
1409
  }
1406
- getFormValue(name) {
1407
- return this.formGroup.controls[name].value;
1410
+ //FormGroup functions
1411
+ getFormValue(name, formGroup = null) {
1412
+ let fg = (formGroup) ? formGroup : this.formGroup;
1413
+ return fg.controls[name].value;
1408
1414
  }
1409
- setFormValue(name, value) {
1410
- this.formGroup.controls[name].setValue(value);
1415
+ setFormValue(name, value, formGroup = null) {
1416
+ let fg = (formGroup) ? formGroup : this.formGroup;
1417
+ fg.controls[name].setValue(value);
1411
1418
  }
1412
- getFormGroupValue(groupName, name) {
1413
- return this.formGroup.controls[groupName].get(name).value;
1419
+ getFormGroupValue(groupName, name, formGroup = null) {
1420
+ let fg = (formGroup) ? formGroup : this.formGroup;
1421
+ return fg.controls[groupName].get(name).value;
1414
1422
  }
1415
- setFormGroupValue(groupName, name, value) {
1416
- this.formGroup.controls[groupName].get(name).setValue(value);
1423
+ setFormGroupValue(groupName, name, value, formGroup = null) {
1424
+ let fg = (formGroup) ? formGroup : this.formGroup;
1425
+ fg.controls[groupName].get(name).setValue(value);
1417
1426
  }
1418
1427
  }
1419
1428
  BaseEditComponent.propDecorators = {
@@ -1717,16 +1726,16 @@ class ValidationSummaryComponent extends BaseEditComponent {
1717
1726
  }
1718
1727
  getFormValidationMessages() {
1719
1728
  let messages = [];
1720
- Object.keys(this.formGroup.controls).forEach((k) => {
1729
+ Object.keys(this.formGroup.controls).forEach(k => {
1721
1730
  var control = this.formGroup.controls[k];
1722
1731
  if (control.controls != null) {
1723
- Object.keys(control.controls).forEach((k) => {
1732
+ Object.keys(control.controls).forEach(k => {
1724
1733
  var child = control.controls[k];
1725
- this.getValidationMessages(child, k).forEach((m) => messages.push(m));
1734
+ this.getValidationMessages(child, this.getControlName(child, k)).forEach(m => messages.push(m));
1726
1735
  });
1727
1736
  }
1728
1737
  else {
1729
- this.getValidationMessages(control, k).forEach((m) => messages.push(m));
1738
+ this.getValidationMessages(control, this.getControlName(control, k)).forEach(m => messages.push(m));
1730
1739
  }
1731
1740
  });
1732
1741
  return messages;
@@ -1738,21 +1747,74 @@ class ValidationSummaryComponent extends BaseEditComponent {
1738
1747
  for (let errorName in state.errors) {
1739
1748
  if (state.errors.hasOwnProperty(errorName)) {
1740
1749
  switch (errorName) {
1741
- case "required":
1750
+ case 'required':
1742
1751
  messages.push(`${thing} is required`);
1743
1752
  break;
1744
- case "minlength":
1753
+ case 'minlength':
1745
1754
  messages.push(`${thing} must be at least ${state.errors["minlength"].requiredLength} characters`);
1746
1755
  break;
1747
- case "pattern":
1756
+ case 'pattern':
1748
1757
  messages.push(`${thing} contains illegal characters`);
1749
1758
  break;
1759
+ case 'format':
1760
+ messages.push(`${thing} format mismatch`);
1761
+ break;
1762
+ case 'maxlength':
1763
+ messages.push(`${thing} must have maximum ${state.errors["maxlength"].requiredLength} characters`);
1764
+ break;
1765
+ case 'specialcharacters':
1766
+ messages.push(`${thing} contains special characters`);
1767
+ break;
1750
1768
  }
1751
1769
  }
1752
1770
  }
1753
1771
  }
1754
1772
  return messages;
1755
1773
  }
1774
+ /**
1775
+ * Get Control Name
1776
+ * @param control
1777
+ * @param thingName
1778
+ */
1779
+ getControlName(control, thingName) {
1780
+ let value = this.getControlTitle(control);
1781
+ return value ? value : thingName;
1782
+ }
1783
+ /**
1784
+ * Retrieve tilte of control
1785
+ * @param control
1786
+ */
1787
+ getControlTitle(control) {
1788
+ if (control === null || control === void 0 ? void 0 : control.nativeElement) {
1789
+ let controlTitle = this.getTitleAttribute(control.nativeElement);
1790
+ if (controlTitle) {
1791
+ return controlTitle;
1792
+ }
1793
+ }
1794
+ return undefined;
1795
+ }
1796
+ /**
1797
+ * Return title attribute of form control
1798
+ */
1799
+ getTitleAttribute(nativeElement) {
1800
+ var _a, _b, _c, _d, _e, _f;
1801
+ let title;
1802
+ switch (nativeElement.tagName) {
1803
+ // For Kendo time and date picker element title is assigned to the 4th child control.
1804
+ case "KENDO-TIMEPICKER":
1805
+ case "KENDO-DATEPICKER":
1806
+ title = (_d = (_c = (_b = (_a = nativeElement.children[0]) === null || _a === void 0 ? void 0 : _a.children[0]) === null || _b === void 0 ? void 0 : _b.children[0]) === null || _c === void 0 ? void 0 : _c.children[0]) === null || _d === void 0 ? void 0 : _d.getAttribute('title');
1807
+ break;
1808
+ // For Kendo numaric element title is assigned to the 2nd child control.
1809
+ case "KENDO-NUMERICTEXTBOX":
1810
+ title = (_f = (_e = nativeElement.children[0]) === null || _e === void 0 ? void 0 : _e.children[0]) === null || _f === void 0 ? void 0 : _f.getAttribute('title');
1811
+ break;
1812
+ default:
1813
+ title = nativeElement.getAttribute('title');
1814
+ break;
1815
+ }
1816
+ return title;
1817
+ }
1756
1818
  }
1757
1819
 
1758
1820
  /*
@@ -1776,22 +1838,44 @@ class ValidationSummaryComponent extends BaseEditComponent {
1776
1838
  class FormValidationSummaryComponent extends ValidationSummaryComponent {
1777
1839
  constructor() {
1778
1840
  super();
1779
- this.isVisible = false;
1841
+ this.visible = false;
1842
+ this.customerrors = [];
1843
+ /*
1844
+ 0 - only FormValidation messages
1845
+ 1 - only Custom messages
1846
+ 2 - all
1847
+ */
1848
+ this.viewtype = 0;
1780
1849
  }
1781
1850
  getErrors() {
1782
- const messages = this.getFormValidationMessages();
1851
+ if (this.viewtype == 1) {
1852
+ return this.customerrors;
1853
+ }
1854
+ let formValidationMessages = this.getFormValidationMessages();
1855
+ if (this.viewtype == 0) {
1856
+ return formValidationMessages;
1857
+ }
1858
+ var messages = [];
1859
+ if (formValidationMessages.length > 0) {
1860
+ messages.push(...formValidationMessages);
1861
+ }
1862
+ if (this.customerrors.length > 0) {
1863
+ messages.push(...this.customerrors);
1864
+ }
1783
1865
  return messages;
1784
1866
  }
1785
1867
  }
1786
1868
  FormValidationSummaryComponent.decorators = [
1787
1869
  { type: Component, args: [{
1788
1870
  selector: "anatoly-form-validation-summary",
1789
- template: "<div class=\"callout callout-danger\" *ngIf=\"isVisible\">\r\n <h4 class=\"box-title\">There are problems with the form</h4>\r\n <p *ngFor=\"let error of getErrors()\">\r\n <span class=\"help-block\" style=\"color: white;\">{{ error }}</span>\r\n </p>\r\n</div>\r\n"
1871
+ template: "<div class=\"callout callout-danger\" *ngIf=\"visible\">\r\n <h6 class=\"box-title\">There are problems with the form</h6>\r\n <ul>\r\n <li *ngFor=\"let error of getErrors()\"><span>{{error}}</span></li>\r\n </ul>\r\n</div>\r\n\r\n"
1790
1872
  },] }
1791
1873
  ];
1792
1874
  FormValidationSummaryComponent.ctorParameters = () => [];
1793
1875
  FormValidationSummaryComponent.propDecorators = {
1794
- isVisible: [{ type: Input }]
1876
+ visible: [{ type: Input }],
1877
+ customerrors: [{ type: Input }],
1878
+ viewtype: [{ type: Input }]
1795
1879
  };
1796
1880
 
1797
1881
  /*
@@ -1820,7 +1904,7 @@ class ItemValidationSummaryComponent extends ValidationSummaryComponent {
1820
1904
  ItemValidationSummaryComponent.decorators = [
1821
1905
  { type: Component, args: [{
1822
1906
  selector: "anatoly-item-validation-summary",
1823
- template: "<ul class=\"list-unstyled\" *ngIf=\"isItemInvalid(controlName)\">\r\n <li *ngFor=\"let error of getValidationMessages(formGroup.get(controlName), controlTitle)\">\r\n <span class=\"help-block\">{{ error }}</span>\r\n </li>\r\n</ul>\r\n"
1907
+ template: "<ul class=\"list-unstyled\" *ngIf=\"isControlInvalid(controlName)\">\r\n <li *ngFor=\"let error of getValidationMessages(formGroup.get(controlName), controlTitle)\">\r\n <span class=\"help-block\">{{ error }}</span>\r\n </li>\r\n</ul>\r\n\r\n"
1824
1908
  },] }
1825
1909
  ];
1826
1910
  ItemValidationSummaryComponent.ctorParameters = () => [];
@@ -1829,6 +1913,44 @@ ItemValidationSummaryComponent.propDecorators = {
1829
1913
  controlTitle: [{ type: Input }]
1830
1914
  };
1831
1915
 
1916
+ /*
1917
+ <file>
1918
+ Project:
1919
+ @osovitny/anatoly
1920
+
1921
+ Authors:
1922
+ Vadim Osovitny
1923
+ Anatoly Osovitny
1924
+
1925
+ Created:
1926
+ 28 Jun 2020
1927
+
1928
+ Version:
1929
+ 1.0
1930
+
1931
+ Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
1932
+ </file>
1933
+ */
1934
+ class NativeElementDirective {
1935
+ constructor(el, control) {
1936
+ this.el = el;
1937
+ this.control = control;
1938
+ }
1939
+ ngOnInit() {
1940
+ // sets the localization key to the control
1941
+ this.control.control.nativeElement = this.el.nativeElement;
1942
+ }
1943
+ }
1944
+ NativeElementDirective.decorators = [
1945
+ { type: Directive, args: [{
1946
+ selector: '[formControl], [formControlName]'
1947
+ },] }
1948
+ ];
1949
+ NativeElementDirective.ctorParameters = () => [
1950
+ { type: ElementRef },
1951
+ { type: NgControl }
1952
+ ];
1953
+
1832
1954
  /*
1833
1955
  <file>
1834
1956
  Project:
@@ -1860,7 +1982,7 @@ AnatolyUIModule.decorators = [
1860
1982
  FroalaEditorModuleWithProviders,
1861
1983
  FroalaViewModuleWithProviders,
1862
1984
  ],
1863
- declarations: [
1985
+ exports: [
1864
1986
  SubscribePlanButtonComponent,
1865
1987
  UpgradePlanButtonComponent,
1866
1988
  BuyAccessButtonComponent,
@@ -1871,9 +1993,11 @@ AnatolyUIModule.decorators = [
1871
1993
  ItemValidationSummaryComponent,
1872
1994
  HtmlEditorComponent,
1873
1995
  FormsHtmlEditorComponent,
1874
- ContentHeaderComponent
1996
+ ContentHeaderComponent,
1997
+ //Directives
1998
+ NativeElementDirective
1875
1999
  ],
1876
- exports: [
2000
+ declarations: [
1877
2001
  SubscribePlanButtonComponent,
1878
2002
  UpgradePlanButtonComponent,
1879
2003
  BuyAccessButtonComponent,
@@ -1884,8 +2008,10 @@ AnatolyUIModule.decorators = [
1884
2008
  ItemValidationSummaryComponent,
1885
2009
  HtmlEditorComponent,
1886
2010
  FormsHtmlEditorComponent,
1887
- ContentHeaderComponent
1888
- ],
2011
+ ContentHeaderComponent,
2012
+ //Directives
2013
+ NativeElementDirective
2014
+ ]
1889
2015
  },] }
1890
2016
  ];
1891
2017
 
@@ -1916,5 +2042,5 @@ AnatolyUIModule.decorators = [
1916
2042
  * Generated bundle index. Do not edit.
1917
2043
  */
1918
2044
 
1919
- export { Alerts, AnatolyCoreModule, AnatolyDataModule, AnatolyHttpInterceptor, AnatolyUIModule, AppContextService, AppCoreSettings, BaseApiService, BaseComponent, BaseEditComponent, BaseGoService, BaseGridEditService, BaseGridReadService, BillingApiService, BuyAccessButtonComponent, ContentHeaderComponent, ContextInitState, FormValidationSummaryComponent, FormsHtmlEditorComponent, GlobalErrorHandler, Guid, HtmlEditorComponent, ItemValidationSummaryComponent, LoadingService, LoggingService, SignInButtonComponent, SignOutButtonComponent, SignUpButtonComponent, Subs, SubscribePlanButtonComponent, UpgradePlanButtonComponent, Utils, ValidationSummaryComponent, throwIfAlreadyLoaded };
2045
+ export { Alerts, AnatolyCoreModule, AnatolyDataModule, AnatolyHttpInterceptor, AnatolyUIModule, AppContextService, AppCoreSettings, BaseApiService, BaseComponent, BaseEditComponent, BaseGoService, BaseGridEditService, BaseGridReadService, BillingApiService, BuyAccessButtonComponent, ContentHeaderComponent, ContextInitState, FormValidationSummaryComponent, FormsHtmlEditorComponent, GlobalErrorHandler, Guid, HtmlEditorComponent, ItemValidationSummaryComponent, LoadingService, LoggingService, NativeElementDirective, SignInButtonComponent, SignOutButtonComponent, SignUpButtonComponent, Subs, SubscribePlanButtonComponent, UpgradePlanButtonComponent, Utils, ValidationSummaryComponent, throwIfAlreadyLoaded };
1920
2046
  //# sourceMappingURL=osovitny-anatoly.js.map