@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.
@@ -1656,37 +1656,52 @@
1656
1656
  }
1657
1657
  BaseEditComponent.prototype.isActionAdding = function () {
1658
1658
  var id = Utils.getValueByNameInQS("id");
1659
- if (typeof id === "undefined" || id === "")
1659
+ if (typeof id === 'undefined' || id == '')
1660
1660
  return true;
1661
1661
  return false;
1662
1662
  };
1663
1663
  BaseEditComponent.prototype.getEntityId = function () {
1664
1664
  return this.getQSId();
1665
1665
  };
1666
- BaseEditComponent.prototype.isItemInvalid = function (name) {
1667
- if (typeof name === "undefined" || name === "") {
1666
+ BaseEditComponent.prototype.isControlValid = function (name, formGroup) {
1667
+ if (formGroup === void 0) { formGroup = null; }
1668
+ return !this.isControlInvalid(name, formGroup);
1669
+ };
1670
+ BaseEditComponent.prototype.isControlInvalid = function (name, formGroup) {
1671
+ if (formGroup === void 0) { formGroup = null; }
1672
+ if (typeof name === 'undefined' || name == '') {
1668
1673
  return false;
1669
1674
  }
1670
- if (!this.formGroup) {
1675
+ var fg = (formGroup) ? formGroup : this.formGroup;
1676
+ if (!fg) {
1671
1677
  return false;
1672
1678
  }
1673
- if (this.formGroup.get(name)) {
1674
- return ((this.formSubmitted && this.formGroup.get(name).invalid) ||
1675
- (this.formGroup.get(name).touched && this.formGroup.get(name).invalid));
1679
+ if (fg.get(name)) {
1680
+ return (this.formSubmitted && fg.get(name).invalid) ||
1681
+ (fg.get(name).touched && fg.get(name).invalid);
1676
1682
  }
1677
1683
  return false;
1678
1684
  };
1679
- BaseEditComponent.prototype.getFormValue = function (name) {
1680
- return this.formGroup.controls[name].value;
1685
+ //FormGroup functions
1686
+ BaseEditComponent.prototype.getFormValue = function (name, formGroup) {
1687
+ if (formGroup === void 0) { formGroup = null; }
1688
+ var fg = (formGroup) ? formGroup : this.formGroup;
1689
+ return fg.controls[name].value;
1681
1690
  };
1682
- BaseEditComponent.prototype.setFormValue = function (name, value) {
1683
- this.formGroup.controls[name].setValue(value);
1691
+ BaseEditComponent.prototype.setFormValue = function (name, value, formGroup) {
1692
+ if (formGroup === void 0) { formGroup = null; }
1693
+ var fg = (formGroup) ? formGroup : this.formGroup;
1694
+ fg.controls[name].setValue(value);
1684
1695
  };
1685
- BaseEditComponent.prototype.getFormGroupValue = function (groupName, name) {
1686
- return this.formGroup.controls[groupName].get(name).value;
1696
+ BaseEditComponent.prototype.getFormGroupValue = function (groupName, name, formGroup) {
1697
+ if (formGroup === void 0) { formGroup = null; }
1698
+ var fg = (formGroup) ? formGroup : this.formGroup;
1699
+ return fg.controls[groupName].get(name).value;
1687
1700
  };
1688
- BaseEditComponent.prototype.setFormGroupValue = function (groupName, name, value) {
1689
- this.formGroup.controls[groupName].get(name).setValue(value);
1701
+ BaseEditComponent.prototype.setFormGroupValue = function (groupName, name, value, formGroup) {
1702
+ if (formGroup === void 0) { formGroup = null; }
1703
+ var fg = (formGroup) ? formGroup : this.formGroup;
1704
+ fg.controls[groupName].get(name).setValue(value);
1690
1705
  };
1691
1706
  return BaseEditComponent;
1692
1707
  }(BaseComponent));
@@ -1934,11 +1949,11 @@
1934
1949
  if (control.controls != null) {
1935
1950
  Object.keys(control.controls).forEach(function (k) {
1936
1951
  var child = control.controls[k];
1937
- _this.getValidationMessages(child, k).forEach(function (m) { return messages.push(m); });
1952
+ _this.getValidationMessages(child, _this.getControlName(child, k)).forEach(function (m) { return messages.push(m); });
1938
1953
  });
1939
1954
  }
1940
1955
  else {
1941
- _this.getValidationMessages(control, k).forEach(function (m) { return messages.push(m); });
1956
+ _this.getValidationMessages(control, _this.getControlName(control, k)).forEach(function (m) { return messages.push(m); });
1942
1957
  }
1943
1958
  });
1944
1959
  return messages;
@@ -1950,21 +1965,74 @@
1950
1965
  for (var errorName in state.errors) {
1951
1966
  if (state.errors.hasOwnProperty(errorName)) {
1952
1967
  switch (errorName) {
1953
- case "required":
1968
+ case 'required':
1954
1969
  messages.push(thing + " is required");
1955
1970
  break;
1956
- case "minlength":
1971
+ case 'minlength':
1957
1972
  messages.push(thing + " must be at least " + state.errors["minlength"].requiredLength + " characters");
1958
1973
  break;
1959
- case "pattern":
1974
+ case 'pattern':
1960
1975
  messages.push(thing + " contains illegal characters");
1961
1976
  break;
1977
+ case 'format':
1978
+ messages.push(thing + " format mismatch");
1979
+ break;
1980
+ case 'maxlength':
1981
+ messages.push(thing + " must have maximum " + state.errors["maxlength"].requiredLength + " characters");
1982
+ break;
1983
+ case 'specialcharacters':
1984
+ messages.push(thing + " contains special characters");
1985
+ break;
1962
1986
  }
1963
1987
  }
1964
1988
  }
1965
1989
  }
1966
1990
  return messages;
1967
1991
  };
1992
+ /**
1993
+ * Get Control Name
1994
+ * @param control
1995
+ * @param thingName
1996
+ */
1997
+ ValidationSummaryComponent.prototype.getControlName = function (control, thingName) {
1998
+ var value = this.getControlTitle(control);
1999
+ return value ? value : thingName;
2000
+ };
2001
+ /**
2002
+ * Retrieve tilte of control
2003
+ * @param control
2004
+ */
2005
+ ValidationSummaryComponent.prototype.getControlTitle = function (control) {
2006
+ if (control === null || control === void 0 ? void 0 : control.nativeElement) {
2007
+ var controlTitle = this.getTitleAttribute(control.nativeElement);
2008
+ if (controlTitle) {
2009
+ return controlTitle;
2010
+ }
2011
+ }
2012
+ return undefined;
2013
+ };
2014
+ /**
2015
+ * Return title attribute of form control
2016
+ */
2017
+ ValidationSummaryComponent.prototype.getTitleAttribute = function (nativeElement) {
2018
+ var _a, _b, _c, _d, _e, _f;
2019
+ var title;
2020
+ switch (nativeElement.tagName) {
2021
+ // For Kendo time and date picker element title is assigned to the 4th child control.
2022
+ case "KENDO-TIMEPICKER":
2023
+ case "KENDO-DATEPICKER":
2024
+ 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');
2025
+ break;
2026
+ // For Kendo numaric element title is assigned to the 2nd child control.
2027
+ case "KENDO-NUMERICTEXTBOX":
2028
+ title = (_f = (_e = nativeElement.children[0]) === null || _e === void 0 ? void 0 : _e.children[0]) === null || _f === void 0 ? void 0 : _f.getAttribute('title');
2029
+ break;
2030
+ default:
2031
+ title = nativeElement.getAttribute('title');
2032
+ break;
2033
+ }
2034
+ return title;
2035
+ };
1968
2036
  return ValidationSummaryComponent;
1969
2037
  }(BaseEditComponent));
1970
2038
 
@@ -1972,11 +2040,31 @@
1972
2040
  __extends(FormValidationSummaryComponent, _super);
1973
2041
  function FormValidationSummaryComponent() {
1974
2042
  var _this = _super.call(this) || this;
1975
- _this.isVisible = false;
2043
+ _this.visible = false;
2044
+ _this.customerrors = [];
2045
+ /*
2046
+ 0 - only FormValidation messages
2047
+ 1 - only Custom messages
2048
+ 2 - all
2049
+ */
2050
+ _this.viewtype = 0;
1976
2051
  return _this;
1977
2052
  }
1978
2053
  FormValidationSummaryComponent.prototype.getErrors = function () {
1979
- var messages = this.getFormValidationMessages();
2054
+ if (this.viewtype == 1) {
2055
+ return this.customerrors;
2056
+ }
2057
+ var formValidationMessages = this.getFormValidationMessages();
2058
+ if (this.viewtype == 0) {
2059
+ return formValidationMessages;
2060
+ }
2061
+ var messages = [];
2062
+ if (formValidationMessages.length > 0) {
2063
+ messages.push.apply(messages, __spread(formValidationMessages));
2064
+ }
2065
+ if (this.customerrors.length > 0) {
2066
+ messages.push.apply(messages, __spread(this.customerrors));
2067
+ }
1980
2068
  return messages;
1981
2069
  };
1982
2070
  return FormValidationSummaryComponent;
@@ -1984,12 +2072,14 @@
1984
2072
  FormValidationSummaryComponent.decorators = [
1985
2073
  { type: i0.Component, args: [{
1986
2074
  selector: "anatoly-form-validation-summary",
1987
- 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"
2075
+ 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"
1988
2076
  },] }
1989
2077
  ];
1990
2078
  FormValidationSummaryComponent.ctorParameters = function () { return []; };
1991
2079
  FormValidationSummaryComponent.propDecorators = {
1992
- isVisible: [{ type: i0.Input }]
2080
+ visible: [{ type: i0.Input }],
2081
+ customerrors: [{ type: i0.Input }],
2082
+ viewtype: [{ type: i0.Input }]
1993
2083
  };
1994
2084
 
1995
2085
  var ItemValidationSummaryComponent = /** @class */ (function (_super) {
@@ -2002,7 +2092,7 @@
2002
2092
  ItemValidationSummaryComponent.decorators = [
2003
2093
  { type: i0.Component, args: [{
2004
2094
  selector: "anatoly-item-validation-summary",
2005
- 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"
2095
+ 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"
2006
2096
  },] }
2007
2097
  ];
2008
2098
  ItemValidationSummaryComponent.ctorParameters = function () { return []; };
@@ -2011,6 +2101,45 @@
2011
2101
  controlTitle: [{ type: i0.Input }]
2012
2102
  };
2013
2103
 
2104
+ /*
2105
+ <file>
2106
+ Project:
2107
+ @osovitny/anatoly
2108
+
2109
+ Authors:
2110
+ Vadim Osovitny
2111
+ Anatoly Osovitny
2112
+
2113
+ Created:
2114
+ 28 Jun 2020
2115
+
2116
+ Version:
2117
+ 1.0
2118
+
2119
+ Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
2120
+ </file>
2121
+ */
2122
+ var NativeElementDirective = /** @class */ (function () {
2123
+ function NativeElementDirective(el, control) {
2124
+ this.el = el;
2125
+ this.control = control;
2126
+ }
2127
+ NativeElementDirective.prototype.ngOnInit = function () {
2128
+ // sets the localization key to the control
2129
+ this.control.control.nativeElement = this.el.nativeElement;
2130
+ };
2131
+ return NativeElementDirective;
2132
+ }());
2133
+ NativeElementDirective.decorators = [
2134
+ { type: i0.Directive, args: [{
2135
+ selector: '[formControl], [formControlName]'
2136
+ },] }
2137
+ ];
2138
+ NativeElementDirective.ctorParameters = function () { return [
2139
+ { type: i0.ElementRef },
2140
+ { type: forms.NgControl }
2141
+ ]; };
2142
+
2014
2143
  /*
2015
2144
  <file>
2016
2145
  Project:
@@ -2045,7 +2174,7 @@
2045
2174
  FroalaEditorModuleWithProviders,
2046
2175
  FroalaViewModuleWithProviders,
2047
2176
  ],
2048
- declarations: [
2177
+ exports: [
2049
2178
  SubscribePlanButtonComponent,
2050
2179
  UpgradePlanButtonComponent,
2051
2180
  BuyAccessButtonComponent,
@@ -2056,9 +2185,11 @@
2056
2185
  ItemValidationSummaryComponent,
2057
2186
  HtmlEditorComponent,
2058
2187
  FormsHtmlEditorComponent,
2059
- ContentHeaderComponent
2188
+ ContentHeaderComponent,
2189
+ //Directives
2190
+ NativeElementDirective
2060
2191
  ],
2061
- exports: [
2192
+ declarations: [
2062
2193
  SubscribePlanButtonComponent,
2063
2194
  UpgradePlanButtonComponent,
2064
2195
  BuyAccessButtonComponent,
@@ -2069,8 +2200,10 @@
2069
2200
  ItemValidationSummaryComponent,
2070
2201
  HtmlEditorComponent,
2071
2202
  FormsHtmlEditorComponent,
2072
- ContentHeaderComponent
2073
- ],
2203
+ ContentHeaderComponent,
2204
+ //Directives
2205
+ NativeElementDirective
2206
+ ]
2074
2207
  },] }
2075
2208
  ];
2076
2209
 
@@ -2126,6 +2259,7 @@
2126
2259
  exports.ItemValidationSummaryComponent = ItemValidationSummaryComponent;
2127
2260
  exports.LoadingService = LoadingService;
2128
2261
  exports.LoggingService = LoggingService;
2262
+ exports.NativeElementDirective = NativeElementDirective;
2129
2263
  exports.SignInButtonComponent = SignInButtonComponent;
2130
2264
  exports.SignOutButtonComponent = SignOutButtonComponent;
2131
2265
  exports.SignUpButtonComponent = SignUpButtonComponent;