From daee12736442b9ed8bf28aa6745aa54e669613ed Mon Sep 17 00:00:00 2001 From: janvanderhaegen Date: Fri, 1 May 2015 19:42:55 -0500 Subject: [PATCH] chore(all): prepare-release 0.2.4 Release 0.2.4 is a small release which introduced support setting up validation using BreezeJS or @ensure decorator syntax --- bower.json | 2 +- build/babel-options.js | 14 +- dist/amd/index.js | 53 +- dist/amd/resources/de-DE.js | 4 +- dist/amd/resources/en-US.js | 4 +- dist/amd/resources/es-MX.js | 4 +- dist/amd/resources/fr-FR.js | 4 +- dist/amd/resources/nl-BE.js | 4 +- dist/amd/resources/nl-NL.js | 4 +- dist/amd/resources/sv-SE.js | 4 +- dist/amd/resources/tr-TR.js | 4 +- dist/amd/validation/debouncer.js | 33 +- dist/amd/validation/decorators.js | 64 +- dist/amd/validation/path-observer.js | 173 +++--- dist/amd/validation/utilities.js | 62 +- ...validate-custom-attribute-view-strategy.js | 216 +++---- .../validation/validate-custom-attribute.js | 72 +-- dist/amd/validation/validation-config.js | 163 +++-- .../validation/validation-group-builder.js | 436 ++++++------- dist/amd/validation/validation-group.js | 579 ++++++++---------- dist/amd/validation/validation-locale.js | 107 ++-- dist/amd/validation/validation-property.js | 76 +-- dist/amd/validation/validation-result.js | 115 ++-- .../validation/validation-rules-collection.js | 293 ++++----- dist/amd/validation/validation-rules.js | 146 ++--- dist/amd/validation/validation.js | 34 +- dist/commonjs/index.js | 53 +- dist/commonjs/resources/de-DE.js | 4 +- dist/commonjs/resources/en-US.js | 4 +- dist/commonjs/resources/es-MX.js | 4 +- dist/commonjs/resources/fr-FR.js | 4 +- dist/commonjs/resources/nl-BE.js | 4 +- dist/commonjs/resources/nl-NL.js | 4 +- dist/commonjs/resources/sv-SE.js | 4 +- dist/commonjs/resources/tr-TR.js | 4 +- dist/commonjs/validation/debouncer.js | 33 +- dist/commonjs/validation/decorators.js | 64 +- dist/commonjs/validation/path-observer.js | 173 +++--- dist/commonjs/validation/utilities.js | 62 +- ...validate-custom-attribute-view-strategy.js | 216 +++---- .../validation/validate-custom-attribute.js | 72 +-- dist/commonjs/validation/validation-config.js | 163 +++-- .../validation/validation-group-builder.js | 442 ++++++------- dist/commonjs/validation/validation-group.js | 579 ++++++++---------- dist/commonjs/validation/validation-locale.js | 107 ++-- .../validation/validation-property.js | 76 +-- dist/commonjs/validation/validation-result.js | 115 ++-- .../validation/validation-rules-collection.js | 293 ++++----- dist/commonjs/validation/validation-rules.js | 146 ++--- dist/commonjs/validation/validation.js | 34 +- dist/system/validation/debouncer.js | 31 +- dist/system/validation/decorators.js | 62 +- dist/system/validation/path-observer.js | 171 +++--- dist/system/validation/utilities.js | 60 +- ...validate-custom-attribute-view-strategy.js | 214 +++---- .../validation/validate-custom-attribute.js | 68 +- dist/system/validation/validation-config.js | 161 +++-- .../validation/validation-group-builder.js | 434 ++++++------- dist/system/validation/validation-group.js | 577 ++++++++--------- dist/system/validation/validation-locale.js | 105 ++-- dist/system/validation/validation-property.js | 74 +-- dist/system/validation/validation-result.js | 113 ++-- .../validation/validation-rules-collection.js | 291 ++++----- dist/system/validation/validation-rules.js | 144 ++--- dist/system/validation/validation.js | 32 +- doc/CHANGELOG.md | 16 + package.json | 2 +- 67 files changed, 3540 insertions(+), 4345 deletions(-) diff --git a/bower.json b/bower.json index ff5e15d4..1c57c9ac 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-validation", - "version": "0.2.3", + "version": "0.2.4", "description": "A validation plugin for Aurelia.", "keywords": [ "aurelia", diff --git a/build/babel-options.js b/build/babel-options.js index 9504abb4..2c90b9bd 100644 --- a/build/babel-options.js +++ b/build/babel-options.js @@ -1,11 +1,19 @@ module.exports = { - modules: 'system', + filename: '', + filenameRelative: '', + modules: '', + sourceMap: true, + sourceMapName: '', + sourceRoot: '', + moduleRoot: '', moduleIds: false, + experimental: false, comments: false, compact: false, + code:true, stage:2, + loose: "all", optional: [ - "es7.decorators", - "es7.classProperties" + "es7.decorators" ] }; diff --git a/dist/amd/index.js b/dist/amd/index.js index ffbd963e..001d4518 100644 --- a/dist/amd/index.js +++ b/dist/amd/index.js @@ -5,57 +5,20 @@ define(['exports', './validation/validation-config', './validation/validation', var _defaults = function (obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; exports.configure = configure; - Object.defineProperty(exports, 'Utilities', { - enumerable: true, - get: function get() { - return _validationUtilities.Utilities; - } - }); - Object.defineProperty(exports, 'ValidationConfig', { - enumerable: true, - get: function get() { - return _validationValidationConfig.ValidationConfig; - } - }); - Object.defineProperty(exports, 'ValidationLocale', { - enumerable: true, - get: function get() { - return _validationValidationLocale.ValidationLocale; - } - }); + exports.Utilities = _validationUtilities.Utilities; + exports.ValidationConfig = _validationValidationConfig.ValidationConfig; + exports.ValidationLocale = _validationValidationLocale.ValidationLocale; _defaults(exports, _interopRequireWildcard(_validationValidationResult)); _defaults(exports, _interopRequireWildcard(_validationValidationRules)); - Object.defineProperty(exports, 'Validation', { - enumerable: true, - get: function get() { - return _validationValidation.Validation; - } - }); - Object.defineProperty(exports, 'ValidateCustomAttribute', { - enumerable: true, - get: function get() { - return _validationValidateCustomAttribute.ValidateCustomAttribute; - } - }); - Object.defineProperty(exports, 'ValidateCustomAttributeViewStrategy', { - enumerable: true, - get: function get() { - return _validationValidateCustomAttributeViewStrategy.ValidateCustomAttributeViewStrategy; - } - }); - Object.defineProperty(exports, 'ensure', { - enumerable: true, - get: function get() { - return _validationDecorators.ensure; - } - }); + exports.Validation = _validationValidation.Validation; + exports.ValidateCustomAttribute = _validationValidateCustomAttribute.ValidateCustomAttribute; + exports.ValidateCustomAttributeViewStrategy = _validationValidateCustomAttributeViewStrategy.ValidateCustomAttributeViewStrategy; + exports.ensure = _validationDecorators.ensure; function configure(aurelia, configCallback) { diff --git a/dist/amd/resources/de-DE.js b/dist/amd/resources/de-DE.js index 2cb073ec..14b15b8e 100644 --- a/dist/amd/resources/de-DE.js +++ b/dist/amd/resources/de-DE.js @@ -1,9 +1,7 @@ define(['exports', '../validation/utilities'], function (exports, _validationUtilities) { 'use strict'; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var data = { settings: { numericRegex: /^-?(?:\d+)(?:\,\d+)?$/ diff --git a/dist/amd/resources/en-US.js b/dist/amd/resources/en-US.js index 85647283..05ae10be 100644 --- a/dist/amd/resources/en-US.js +++ b/dist/amd/resources/en-US.js @@ -1,9 +1,7 @@ define(['exports', '../validation/utilities'], function (exports, _validationUtilities) { 'use strict'; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var data = { settings: { numericRegex: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/ diff --git a/dist/amd/resources/es-MX.js b/dist/amd/resources/es-MX.js index 50b41c7b..192b6217 100644 --- a/dist/amd/resources/es-MX.js +++ b/dist/amd/resources/es-MX.js @@ -1,9 +1,7 @@ define(['exports', '../validation/utilities'], function (exports, _validationUtilities) { 'use strict'; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var data = { settings: { numericRegex: /^-?(?:\d+)(?:\,\d+)?$/ diff --git a/dist/amd/resources/fr-FR.js b/dist/amd/resources/fr-FR.js index 3d4f4775..84563bf3 100644 --- a/dist/amd/resources/fr-FR.js +++ b/dist/amd/resources/fr-FR.js @@ -1,9 +1,7 @@ define(['exports', '../validation/utilities'], function (exports, _validationUtilities) { 'use strict'; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var data = { settings: { numericRegex: /^-?(?:\d+)(?:\,\d+)?$/ diff --git a/dist/amd/resources/nl-BE.js b/dist/amd/resources/nl-BE.js index 133f0800..917b148d 100644 --- a/dist/amd/resources/nl-BE.js +++ b/dist/amd/resources/nl-BE.js @@ -1,9 +1,7 @@ define(['exports', '../validation/utilities'], function (exports, _validationUtilities) { 'use strict'; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var data = { settings: { numericRegex: /^-?(?:\d+)(?:\,\d+)?$/ diff --git a/dist/amd/resources/nl-NL.js b/dist/amd/resources/nl-NL.js index 133f0800..917b148d 100644 --- a/dist/amd/resources/nl-NL.js +++ b/dist/amd/resources/nl-NL.js @@ -1,9 +1,7 @@ define(['exports', '../validation/utilities'], function (exports, _validationUtilities) { 'use strict'; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var data = { settings: { numericRegex: /^-?(?:\d+)(?:\,\d+)?$/ diff --git a/dist/amd/resources/sv-SE.js b/dist/amd/resources/sv-SE.js index 42dbe53f..92f35a5b 100644 --- a/dist/amd/resources/sv-SE.js +++ b/dist/amd/resources/sv-SE.js @@ -1,9 +1,7 @@ define(['exports', '../validation/utilities'], function (exports, _validationUtilities) { 'use strict'; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var data = { settings: { numericRegex: /^-?(?:\d+)(?:\,\d+)?$/ diff --git a/dist/amd/resources/tr-TR.js b/dist/amd/resources/tr-TR.js index 04d44576..a9414a57 100644 --- a/dist/amd/resources/tr-TR.js +++ b/dist/amd/resources/tr-TR.js @@ -1,9 +1,7 @@ define(['exports', '../validation/utilities'], function (exports, _validationUtilities) { 'use strict'; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var data = { settings: { numericRegex: /^-?(?:\d+)(?:\,\d+)?$/ diff --git a/dist/amd/validation/debouncer.js b/dist/amd/validation/debouncer.js index f18c89a2..cd26df15 100644 --- a/dist/amd/validation/debouncer.js +++ b/dist/amd/validation/debouncer.js @@ -3,11 +3,7 @@ define(['exports', '../validation/validation'], function (exports, _validationVa var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var Debouncer = (function () { function Debouncer(debounceTimeout) { @@ -17,22 +13,19 @@ define(['exports', '../validation/validation'], function (exports, _validationVa this.debounceTimeout = debounceTimeout; } - _createClass(Debouncer, [{ - key: 'debounce', - value: function debounce(func) { - var _this = this; - - this.currentFunction = func; - setTimeout(function () { - if (func !== null && func !== undefined) { - if (func === _this.currentFunction) { - _this.currentFunction = null; - func(); - } + Debouncer.prototype.debounce = function debounce(func) { + var _this = this; + + this.currentFunction = func; + setTimeout(function () { + if (func !== null && func !== undefined) { + if (func === _this.currentFunction) { + _this.currentFunction = null; + func(); } - }, this.debounceTimeout); - } - }]); + } + }, this.debounceTimeout); + }; return Debouncer; })(); diff --git a/dist/amd/validation/decorators.js b/dist/amd/validation/decorators.js index 7703c2b7..f86cb7b1 100644 --- a/dist/amd/validation/decorators.js +++ b/dist/amd/validation/decorators.js @@ -3,11 +3,7 @@ define(["exports"], function (exports) { var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, "__esModule", { - value: true - }); + exports.__esModule = true; exports.ensure = ensure; var ValidationMetadata = (function () { @@ -17,26 +13,22 @@ define(["exports"], function (exports) { this.properties = []; } - _createClass(ValidationMetadata, [{ - key: "getOrCreateProperty", - value: function getOrCreateProperty(propertyName) { - var property = this.properties.find(function (x) { - return x.propertyName === propertyName; - }); - if (property === undefined) { - property = new ValidationPropertyMetadata(propertyName); - this.properties.push(property); - } - return property; - } - }, { - key: "setup", - value: function setup(validation) { - this.properties.forEach(function (property) { - property.setup(validation); - }); + ValidationMetadata.prototype.getOrCreateProperty = function getOrCreateProperty(propertyName) { + var property = this.properties.find(function (x) { + return x.propertyName === propertyName; + }); + if (property === undefined) { + property = new ValidationPropertyMetadata(propertyName); + this.properties.push(property); } - }]); + return property; + }; + + ValidationMetadata.prototype.setup = function setup(validation) { + this.properties.forEach(function (property) { + property.setup(validation); + }); + }; return ValidationMetadata; })(); @@ -49,20 +41,16 @@ define(["exports"], function (exports) { this.setupSteps = []; } - _createClass(ValidationPropertyMetadata, [{ - key: "addSetupStep", - value: function addSetupStep(setupStep) { - this.setupSteps.push(setupStep); - } - }, { - key: "setup", - value: function setup(validation) { - validation.ensure(this.propertyName); - this.setupSteps.forEach(function (setupStep) { - setupStep(validation); - }); - } - }]); + ValidationPropertyMetadata.prototype.addSetupStep = function addSetupStep(setupStep) { + this.setupSteps.push(setupStep); + }; + + ValidationPropertyMetadata.prototype.setup = function setup(validation) { + validation.ensure(this.propertyName); + this.setupSteps.forEach(function (setupStep) { + setupStep(validation); + }); + }; return ValidationPropertyMetadata; })(); diff --git a/dist/amd/validation/path-observer.js b/dist/amd/validation/path-observer.js index 92fe69e5..7603e051 100644 --- a/dist/amd/validation/path-observer.js +++ b/dist/amd/validation/path-observer.js @@ -3,11 +3,7 @@ define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var PathObserver = (function () { function PathObserver(observerLocator, subject, path) { @@ -21,112 +17,105 @@ define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { if (this.path.length > 1) this.observeParts(); } - _createClass(PathObserver, [{ - key: 'observeParts', - value: function observeParts(propertyName) { - var _this = this; - - if (propertyName !== undefined && propertyName !== null) { - for (var i = this.observers.length - 1; i >= 0; i--) { - var currentObserver = this.observers[i]; - if (currentObserver.propertyName === propertyName) { - break; - } - var observer = this.observers.pop(); - if (observer && observer.subscription) { - observer.subscription(); - } + PathObserver.prototype.observeParts = function observeParts(propertyName) { + var _this = this; + + if (propertyName !== undefined && propertyName !== null) { + for (var i = this.observers.length - 1; i >= 0; i--) { + var currentObserver = this.observers[i]; + if (currentObserver.propertyName === propertyName) { + break; + } + var observer = this.observers.pop(); + if (observer && observer.subscription) { + observer.subscription(); } } + } - var currentSubject = this.subject; - - var observersAreComplete = this.observers.length === this.path.length; - - var _loop = function (i) { - var observer = _this.observers[i]; - if (!observer) { + var currentSubject = this.subject; - var currentPath = _this.path[i]; - observer = _this.observerLocator.getObserver(currentSubject, currentPath); - _this.observers.push(observer); - var subscription = observer.subscribe(function (newValue, oldValue) { - _this.observeParts(observer.propertyName); - }); - observer.subscription = subscription; - } + var observersAreComplete = this.observers.length === this.path.length; - var currentValue = observer.getValue(); - if (currentValue === undefined || currentValue === null) { - return 'break'; - } else { - currentSubject = currentValue; - } - }; + var _loop = function (i) { + var observer = _this.observers[i]; + if (!observer) { - for (var i = 0; i < this.path.length; i++) { - var _ret = _loop(i); - - if (_ret === 'break') break; + var currentPath = _this.path[i]; + observer = _this.observerLocator.getObserver(currentSubject, currentPath); + _this.observers.push(observer); + var subscription = observer.subscribe(function (newValue, oldValue) { + _this.observeParts(observer.propertyName); + }); + observer.subscription = subscription; } - if (!observersAreComplete && this.observers.length === this.path.length) { - var actualObserver = this.observers[this.observers.length - 1]; - for (var i = 0; i < this.callbacks.length; i++) { - actualObserver.subscribe(this.callbacks[i]); - } + var currentValue = observer.getValue(); + if (currentValue === undefined || currentValue === null) { + return 'break'; + } else { + currentSubject = currentValue; } + }; + + for (var i = 0; i < this.path.length; i++) { + var _ret = _loop(i); + + if (_ret === 'break') break; } - }, { - key: 'observePart', - value: function observePart(part) { - if (part !== this.path[this.path.length - 1]) { - this.observerParts(); + + if (!observersAreComplete && this.observers.length === this.path.length) { + var actualObserver = this.observers[this.observers.length - 1]; + for (var i = 0; i < this.callbacks.length; i++) { + actualObserver.subscribe(this.callbacks[i]); } } - }, { - key: 'getObserver', - value: function getObserver() { - if (this.path.length == 1) { - return this.observerLocator.getObserver(this.subject, this.path[0]); - }return this; + }; + + PathObserver.prototype.observePart = function observePart(part) { + if (part !== this.path[this.path.length - 1]) { + this.observerParts(); } - }, { - key: 'getValue', - value: function getValue() { - var expectedSubject = this.subject; - for (var i = 0; this.path.length; i++) { - var currentObserver = this.observers[i]; - if (currentObserver === null || currentObserver === undefined) { - this.observeParts(this.path[i]); - currentObserver = this.observers[i]; + }; + + PathObserver.prototype.getObserver = function getObserver() { + if (this.path.length == 1) { + return this.observerLocator.getObserver(this.subject, this.path[0]); + }return this; + }; + + PathObserver.prototype.getValue = function getValue() { + var expectedSubject = this.subject; + for (var i = 0; this.path.length; i++) { + var currentObserver = this.observers[i]; + if (currentObserver === null || currentObserver === undefined) { + this.observeParts(this.path[i]); + currentObserver = this.observers[i]; - if (currentObserver === null || currentObserver === undefined) { - break; - } + if (currentObserver === null || currentObserver === undefined) { + break; } - if (currentObserver.obj !== expectedSubject) { - this.observeParts(this.path[i - 1]); - break; - } - expectedSubject = currentObserver.getValue(); } + if (currentObserver.obj !== expectedSubject) { + this.observeParts(this.path[i - 1]); + break; + } + expectedSubject = currentObserver.getValue(); + } - if (this.observers.length !== this.path.length) { - return undefined; - } - var value = this.observers[this.observers.length - 1].getValue(); - return value; + if (this.observers.length !== this.path.length) { + return undefined; } - }, { - key: 'subscribe', - value: function subscribe(callback) { - this.callbacks.unshift(callback); - if (this.observers.length === this.path.length) { - return this.observers[this.observers.length - 1].subscribe(callback); - } + var value = this.observers[this.observers.length - 1].getValue(); + return value; + }; + + PathObserver.prototype.subscribe = function subscribe(callback) { + this.callbacks.unshift(callback); + if (this.observers.length === this.path.length) { + return this.observers[this.observers.length - 1].subscribe(callback); } - }]); + }; return PathObserver; })(); diff --git a/dist/amd/validation/utilities.js b/dist/amd/validation/utilities.js index 7acd5023..790a4f4c 100644 --- a/dist/amd/validation/utilities.js +++ b/dist/amd/validation/utilities.js @@ -3,51 +3,43 @@ define(['exports'], function (exports) { var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var Utilities = (function () { function Utilities() { _classCallCheck(this, Utilities); } - _createClass(Utilities, null, [{ - key: 'getValue', - value: function getValue(val) { - if (val !== undefined && typeof val === 'function') { - return val(); - } - return val; + Utilities.getValue = function getValue(val) { + if (val !== undefined && typeof val === 'function') { + return val(); } - }, { - key: 'isEmptyValue', - value: function isEmptyValue(val) { - if (val === undefined) { - return true; - } - if (val === null) { - return true; - } - if (val === '') { - return true; - } - if (typeof val === 'string') { - if (String.prototype.trim) { - val = val.trim(); - } else { - val = val.replace(/^\s+|\s+$/g, ''); - } - } + return val; + }; - if (val.length !== undefined) { - return 0 === val.length; + Utilities.isEmptyValue = function isEmptyValue(val) { + if (val === undefined) { + return true; + } + if (val === null) { + return true; + } + if (val === '') { + return true; + } + if (typeof val === 'string') { + if (String.prototype.trim) { + val = val.trim(); + } else { + val = val.replace(/^\s+|\s+$/g, ''); } - return false; } - }]); + + if (val.length !== undefined) { + return 0 === val.length; + } + return false; + }; return Utilities; })(); diff --git a/dist/amd/validation/validate-custom-attribute-view-strategy.js b/dist/amd/validation/validate-custom-attribute-view-strategy.js index 08af8d8b..a8cc2ac1 100644 --- a/dist/amd/validation/validate-custom-attribute-view-strategy.js +++ b/dist/amd/validation/validate-custom-attribute-view-strategy.js @@ -1,17 +1,11 @@ define(['exports'], function (exports) { 'use strict'; - var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidateCustomAttributeViewStrategyBase = (function () { function ValidateCustomAttributeViewStrategyBase() { @@ -20,37 +14,32 @@ define(['exports'], function (exports) { this.bindingPathAttributes = ['validate', 'value.bind', 'value.two-way']; } - _createClass(ValidateCustomAttributeViewStrategyBase, [{ - key: 'getValidationProperty', - value: function getValidationProperty(validation, element) { - var atts = element.attributes; - for (var i = 0; i < this.bindingPathAttributes.length; i++) { - var attributeName = this.bindingPathAttributes[i]; - if (atts[attributeName]) { - var bindingPath = atts[attributeName].value.trim(); - if (bindingPath.indexOf('|') != -1) bindingPath = bindingPath.split('|')[0].trim(); - var validationProperty = validation.result.properties[bindingPath]; - - if (attributeName == 'validate' && (validationProperty === null || validationProperty === undefined)) { - validation.ensure(bindingPath); - validationProperty = validation.result.properties[bindingPath]; - } - return validationProperty; + ValidateCustomAttributeViewStrategyBase.prototype.getValidationProperty = function getValidationProperty(validation, element) { + var atts = element.attributes; + for (var i = 0; i < this.bindingPathAttributes.length; i++) { + var attributeName = this.bindingPathAttributes[i]; + if (atts[attributeName]) { + var bindingPath = atts[attributeName].value.trim(); + if (bindingPath.indexOf('|') != -1) bindingPath = bindingPath.split('|')[0].trim(); + var validationProperty = validation.result.properties[bindingPath]; + + if (attributeName == 'validate' && (validationProperty === null || validationProperty === undefined)) { + validation.ensure(bindingPath); + validationProperty = validation.result.properties[bindingPath]; } + return validationProperty; } - return null; - } - }, { - key: 'prepareElement', - value: function prepareElement(validationProperty, element) { - throw Error('View strategy must implement prepareElement(validationProperty, element)'); } - }, { - key: 'updateElement', - value: function updateElement(validationProperty, element) { - throw Error('View strategy must implement updateElement(validationProperty, element)'); - } - }]); + return null; + }; + + ValidateCustomAttributeViewStrategyBase.prototype.prepareElement = function prepareElement(validationProperty, element) { + throw Error('View strategy must implement prepareElement(validationProperty, element)'); + }; + + ValidateCustomAttributeViewStrategyBase.prototype.updateElement = function updateElement(validationProperty, element) { + throw Error('View strategy must implement updateElement(validationProperty, element)'); + }; return ValidateCustomAttributeViewStrategyBase; })(); @@ -61,7 +50,7 @@ define(['exports'], function (exports) { function TWBootstrapViewStrategy(appendMessageToInput, appendMessageToLabel, helpBlockClass) { _classCallCheck(this, TWBootstrapViewStrategy); - _get(Object.getPrototypeOf(TWBootstrapViewStrategy.prototype), 'constructor', this).call(this); + _ValidateCustomAttributeViewStrategyBase.call(this); this.appendMessageToInput = appendMessageToInput; this.appendMessageToLabel = appendMessageToLabel; this.helpBlockClass = helpBlockClass; @@ -69,103 +58,94 @@ define(['exports'], function (exports) { _inherits(TWBootstrapViewStrategy, _ValidateCustomAttributeViewStrategyBase); - _createClass(TWBootstrapViewStrategy, [{ - key: 'searchFormGroup', - value: function searchFormGroup(currentElement, currentDepth) { - if (currentDepth === 5) { - return null; - } - if (currentElement.classList && currentElement.classList.contains('form-group')) { - return currentElement; - } - return this.searchFormGroup(currentElement.parentNode, 1 + currentDepth); + TWBootstrapViewStrategy.prototype.searchFormGroup = function searchFormGroup(currentElement, currentDepth) { + if (currentDepth === 5) { + return null; } - }, { - key: 'findLabels', - value: function findLabels(formGroup, inputId) { - var labels = []; - this.findLabelsRecursively(formGroup, inputId, labels, 0); - return labels; + if (currentElement.classList && currentElement.classList.contains('form-group')) { + return currentElement; + } + return this.searchFormGroup(currentElement.parentNode, 1 + currentDepth); + }; + + TWBootstrapViewStrategy.prototype.findLabels = function findLabels(formGroup, inputId) { + var labels = []; + this.findLabelsRecursively(formGroup, inputId, labels, 0); + return labels; + }; + + TWBootstrapViewStrategy.prototype.findLabelsRecursively = function findLabelsRecursively(currentElement, inputId, currentLabels, currentDepth) { + if (currentDepth === 5) { + return; + } + if (currentElement.nodeName === 'LABEL' && (currentElement.attributes['for'] && currentElement.attributes['for'].value === inputId || !currentElement.attributes['for'])) { + currentLabels.push(currentElement); } - }, { - key: 'findLabelsRecursively', - value: function findLabelsRecursively(currentElement, inputId, currentLabels, currentDepth) { - if (currentDepth === 5) { - return; - } - if (currentElement.nodeName === 'LABEL' && (currentElement.attributes['for'] && currentElement.attributes['for'].value === inputId || !currentElement.attributes['for'])) { - currentLabels.push(currentElement); - } - for (var i = 0; i < currentElement.children.length; i++) { - this.findLabelsRecursively(currentElement.children[i], inputId, currentLabels, 1 + currentDepth); - } + for (var i = 0; i < currentElement.children.length; i++) { + this.findLabelsRecursively(currentElement.children[i], inputId, currentLabels, 1 + currentDepth); } - }, { - key: 'appendMessageToElement', - value: function appendMessageToElement(element, validationProperty) { - var helpBlock = element.nextSibling; - if (helpBlock) { - if (!helpBlock.classList) { - helpBlock = null; - } else if (!helpBlock.classList.contains(this.helpBlockClass)) { - helpBlock = null; - } + }; + + TWBootstrapViewStrategy.prototype.appendMessageToElement = function appendMessageToElement(element, validationProperty) { + var helpBlock = element.nextSibling; + if (helpBlock) { + if (!helpBlock.classList) { + helpBlock = null; + } else if (!helpBlock.classList.contains(this.helpBlockClass)) { + helpBlock = null; } + } - if (!helpBlock) { - helpBlock = document.createElement('p'); - helpBlock.classList.add('help-block'); - helpBlock.classList.add(this.helpBlockClass); + if (!helpBlock) { + helpBlock = document.createElement('p'); + helpBlock.classList.add('help-block'); + helpBlock.classList.add(this.helpBlockClass); - if (element.nextSibling) { - element.parentNode.insertBefore(helpBlock, element.nextSibling); - } else { - element.parentNode.appendChild(helpBlock); - } + if (element.nextSibling) { + element.parentNode.insertBefore(helpBlock, element.nextSibling); + } else { + element.parentNode.appendChild(helpBlock); } - if (validationProperty) helpBlock.textContent = validationProperty.message;else helpBlock.textContent = ''; } - }, { - key: 'appendUIVisuals', - value: function appendUIVisuals(validationProperty, currentElement) { - var formGroup = this.searchFormGroup(currentElement, 0); - if (formGroup) { - if (validationProperty && validationProperty.isDirty) { - if (validationProperty.isValid) { - formGroup.classList.remove('has-warning'); - formGroup.classList.add('has-success'); - } else { - formGroup.classList.remove('has-success'); - formGroup.classList.add('has-warning'); - } - } else { + if (validationProperty) helpBlock.textContent = validationProperty.message;else helpBlock.textContent = ''; + }; + + TWBootstrapViewStrategy.prototype.appendUIVisuals = function appendUIVisuals(validationProperty, currentElement) { + var formGroup = this.searchFormGroup(currentElement, 0); + if (formGroup) { + if (validationProperty && validationProperty.isDirty) { + if (validationProperty.isValid) { formGroup.classList.remove('has-warning'); + formGroup.classList.add('has-success'); + } else { formGroup.classList.remove('has-success'); + formGroup.classList.add('has-warning'); } - if (this.appendMessageToInput) { - this.appendMessageToElement(currentElement, validationProperty); - } - if (this.appendMessageToLabel) { - var labels = this.findLabels(formGroup, currentElement.id); - for (var ii = 0; ii < labels.length; ii++) { - var label = labels[ii]; - this.appendMessageToElement(label, validationProperty); - } + } else { + formGroup.classList.remove('has-warning'); + formGroup.classList.remove('has-success'); + } + if (this.appendMessageToInput) { + this.appendMessageToElement(currentElement, validationProperty); + } + if (this.appendMessageToLabel) { + var labels = this.findLabels(formGroup, currentElement.id); + for (var ii = 0; ii < labels.length; ii++) { + var label = labels[ii]; + this.appendMessageToElement(label, validationProperty); } } } - }, { - key: 'prepareElement', - value: function prepareElement(validationProperty, element) { - this.appendUIVisuals(null, element); - } - }, { - key: 'updateElement', - value: function updateElement(validationProperty, element) { - this.appendUIVisuals(validationProperty, element); - } - }]); + }; + + TWBootstrapViewStrategy.prototype.prepareElement = function prepareElement(validationProperty, element) { + this.appendUIVisuals(null, element); + }; + + TWBootstrapViewStrategy.prototype.updateElement = function updateElement(validationProperty, element) { + this.appendUIVisuals(validationProperty, element); + }; return TWBootstrapViewStrategy; })(ValidateCustomAttributeViewStrategyBase); diff --git a/dist/amd/validation/validate-custom-attribute.js b/dist/amd/validation/validate-custom-attribute.js index a5515dd3..b615c6f3 100644 --- a/dist/amd/validation/validate-custom-attribute.js +++ b/dist/amd/validation/validate-custom-attribute.js @@ -3,11 +3,7 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-templating'], functi var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidateCustomAttribute = (function () { function ValidateCustomAttribute(element) { @@ -18,45 +14,39 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-templating'], functi this.viewStrategy = null; } - _createClass(ValidateCustomAttribute, [{ - key: 'valueChanged', - value: function valueChanged(newValue) { - if (this.value === null || this.value === undefined) { - return; - }this.processedValidation = this.value; - if (typeof this.value === 'string') { - return; - } else { - this.subscribeChangedHandlers(this.element); - } + ValidateCustomAttribute.prototype.valueChanged = function valueChanged(newValue) { + if (this.value === null || this.value === undefined) { + return; + }this.processedValidation = this.value; + if (typeof this.value === 'string') { + return; + } else { + this.subscribeChangedHandlers(this.element); } - }, { - key: 'subscribeChangedHandlers', - value: function subscribeChangedHandlers(currentElement) { - var _this = this; - - this.viewStrategy = this.value.config.getViewStrategy(); - var validationProperty = this.viewStrategy.getValidationProperty(this.value, currentElement); - if (validationProperty !== null && validationProperty !== undefined) { - this.viewStrategy.prepareElement(validationProperty, currentElement); - validationProperty.onValidate(function (vp) { - _this.viewStrategy.updateElement(vp, currentElement); - }); - } - var children = currentElement.children; - for (var i = 0; i < children.length; i++) { - this.subscribeChangedHandlers(children[i]); - } + }; + + ValidateCustomAttribute.prototype.subscribeChangedHandlers = function subscribeChangedHandlers(currentElement) { + var _this = this; + + this.viewStrategy = this.value.config.getViewStrategy(); + var validationProperty = this.viewStrategy.getValidationProperty(this.value, currentElement); + if (validationProperty !== null && validationProperty !== undefined) { + this.viewStrategy.prepareElement(validationProperty, currentElement); + validationProperty.onValidate(function (vp) { + _this.viewStrategy.updateElement(vp, currentElement); + }); } - }, { - key: 'detached', - value: function detached() {} - }, { - key: 'attached', - value: function attached() { - if (this.processedValidation === null || this.processedValidation === undefined) this.valueChanged(this.value); + var children = currentElement.children; + for (var i = 0; i < children.length; i++) { + this.subscribeChangedHandlers(children[i]); } - }]); + }; + + ValidateCustomAttribute.prototype.detached = function detached() {}; + + ValidateCustomAttribute.prototype.attached = function attached() { + if (this.processedValidation === null || this.processedValidation === undefined) this.valueChanged(this.value); + }; var _ValidateCustomAttribute = ValidateCustomAttribute; ValidateCustomAttribute = _aureliaTemplating.customAttribute('validate')(ValidateCustomAttribute) || ValidateCustomAttribute; diff --git a/dist/amd/validation/validation-config.js b/dist/amd/validation/validation-config.js index acc03961..f2434ec9 100644 --- a/dist/amd/validation/validation-config.js +++ b/dist/amd/validation/validation-config.js @@ -1,13 +1,9 @@ define(['exports', '../validation/validation-locale', '../validation/validate-custom-attribute-view-strategy'], function (exports, _validationValidationLocale, _validationValidateCustomAttributeViewStrategy) { 'use strict'; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidationConfigDefaults = function ValidationConfigDefaults() { _classCallCheck(this, ValidationConfigDefaults); @@ -37,97 +33,84 @@ define(['exports', '../validation/validation-locale', '../validation/validate-cu this.changedHandlers = new Map(); } - _createClass(ValidationConfig, [{ - key: 'getValue', - value: function getValue(identifier) { - if (this.values.hasOwnProperty(identifier) !== null && this.values[identifier] !== undefined) { - return this.values[identifier]; - } - if (this.innerConfig !== null) { - return this.innerConfig.getValue(identifier); - } - throw Error('Config not found: ' + identifier); - } - }, { - key: 'setValue', - value: function setValue(identifier, value) { - this.values[identifier] = value; - return this; - } - }, { - key: 'onLocaleChanged', - value: function onLocaleChanged(callback) { - var _this = this; - - if (this.innerConfig !== undefined) { - return this.innerConfig.onLocaleChanged(callback); - } else { - var _ret = (function () { - var id = ++ValidationConfig.uniqueListenerId; - _this.changedHandlers.set(id, callback); - return { - v: function () { - changedHandlers['delete'](id); - } - }; - })(); - - if (typeof _ret === 'object') { - return _ret.v; - } - } + ValidationConfig.prototype.getValue = function getValue(identifier) { + if (this.values.hasOwnProperty(identifier) !== null && this.values[identifier] !== undefined) { + return this.values[identifier]; } - }, { - key: 'getDebounceTimeout', - value: function getDebounceTimeout() { - return this.getValue('debounceTimeout'); + if (this.innerConfig !== null) { + return this.innerConfig.getValue(identifier); } - }, { - key: 'useDebounceTimeout', - value: function useDebounceTimeout(value) { - return this.setValue('debounceTimeout', value); - } - }, { - key: 'getDependencies', - value: function getDependencies() { - return this.getValue('dependencies'); - } - }, { - key: 'computedFrom', - value: function computedFrom(dependencies) { - var deps = dependencies; - if (typeof dependencies === 'string') { - deps = []; - deps.push(dependencies); - } - return this.setValue('dependencies', deps); - } - }, { - key: 'useLocale', - value: function useLocale(localeIdentifier) { - this.setValue('locale', localeIdentifier); - var callbacks = Array.from(this.changedHandlers.values()); - for (var i = 0; i < callbacks.length; i++) { - callbacks[i](); + throw Error('Config not found: ' + identifier); + }; + + ValidationConfig.prototype.setValue = function setValue(identifier, value) { + this.values[identifier] = value; + return this; + }; + + ValidationConfig.prototype.onLocaleChanged = function onLocaleChanged(callback) { + var _this = this; + + if (this.innerConfig !== undefined) { + return this.innerConfig.onLocaleChanged(callback); + } else { + var _ret = (function () { + var id = ++ValidationConfig.uniqueListenerId; + _this.changedHandlers.set(id, callback); + return { + v: function () { + changedHandlers['delete'](id); + } + }; + })(); + + if (typeof _ret === 'object') { + return _ret.v; } - return this; - } - }, { - key: 'locale', - value: function locale() { - return _validationValidationLocale.ValidationLocale.Repository.load(this.getValue('locale'), this.getValue('localeResources')); } - }, { - key: 'useViewStrategy', - value: function useViewStrategy(viewStrategy) { - return this.setValue('viewStrategy', viewStrategy); + }; + + ValidationConfig.prototype.getDebounceTimeout = function getDebounceTimeout() { + return this.getValue('debounceTimeout'); + }; + + ValidationConfig.prototype.useDebounceTimeout = function useDebounceTimeout(value) { + return this.setValue('debounceTimeout', value); + }; + + ValidationConfig.prototype.getDependencies = function getDependencies() { + return this.getValue('dependencies'); + }; + + ValidationConfig.prototype.computedFrom = function computedFrom(dependencies) { + var deps = dependencies; + if (typeof dependencies === 'string') { + deps = []; + deps.push(dependencies); } - }, { - key: 'getViewStrategy', - value: function getViewStrategy() { - return this.getValue('viewStrategy'); + return this.setValue('dependencies', deps); + }; + + ValidationConfig.prototype.useLocale = function useLocale(localeIdentifier) { + this.setValue('locale', localeIdentifier); + var callbacks = Array.from(this.changedHandlers.values()); + for (var i = 0; i < callbacks.length; i++) { + callbacks[i](); } - }]); + return this; + }; + + ValidationConfig.prototype.locale = function locale() { + return _validationValidationLocale.ValidationLocale.Repository.load(this.getValue('locale'), this.getValue('localeResources')); + }; + + ValidationConfig.prototype.useViewStrategy = function useViewStrategy(viewStrategy) { + return this.setValue('viewStrategy', viewStrategy); + }; + + ValidationConfig.prototype.getViewStrategy = function getViewStrategy() { + return this.getValue('viewStrategy'); + }; return ValidationConfig; })(); diff --git a/dist/amd/validation/validation-group-builder.js b/dist/amd/validation/validation-group-builder.js index cdf98a82..22bbed12 100644 --- a/dist/amd/validation/validation-group-builder.js +++ b/dist/amd/validation/validation-group-builder.js @@ -3,11 +3,7 @@ define(['exports', '../validation/validation-rules', '../validation/validation-r var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidationGroupBuilder = (function () { function ValidationGroupBuilder(observerLocator, validationGroup) { @@ -18,250 +14,214 @@ define(['exports', '../validation/validation-rules', '../validation/validation-r this.validationGroup = validationGroup; } - _createClass(ValidationGroupBuilder, [{ - key: 'ensure', - value: function ensure(propertyName, configurationCallback) { - var newValidationProperty = null; - this.validationRuleCollections = []; - - for (var i = 0; i < this.validationGroup.validationProperties.length; i++) { - if (this.validationGroup.validationProperties[i].propertyName === propertyName) { - newValidationProperty = this.validationGroup.validationProperties[i]; - if (configurationCallback !== undefined && typeof configurationCallback === 'function') { - throw Error('When creating validation rules on binding path ' + propertyName + ' a configuration callback function was provided, but validation rules have previously already been instantiated for this binding path'); - } - break; - } - } - if (newValidationProperty === null) { - var propertyResult = this.validationGroup.result.addProperty(propertyName); - var config = new _validationValidationConfig.ValidationConfig(this.validationGroup.config); + ValidationGroupBuilder.prototype.ensure = function ensure(propertyName, configurationCallback) { + var newValidationProperty = null; + this.validationRuleCollections = []; + + for (var i = 0; i < this.validationGroup.validationProperties.length; i++) { + if (this.validationGroup.validationProperties[i].propertyName === propertyName) { + newValidationProperty = this.validationGroup.validationProperties[i]; if (configurationCallback !== undefined && typeof configurationCallback === 'function') { - configurationCallback(config); + throw Error('When creating validation rules on binding path ' + propertyName + ' a configuration callback function was provided, but validation rules have previously already been instantiated for this binding path'); } - newValidationProperty = new _validationValidationProperty.ValidationProperty(this.observerLocator, propertyName, this.validationGroup, propertyResult, config); - this.validationGroup.validationProperties.push(newValidationProperty); - } - this.validationRuleCollections.unshift(newValidationProperty.collectionOfValidationRules); - return this.validationGroup; - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - this.validationRuleCollections[0].isNotEmpty(); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'isGreaterThan', - value: function isGreaterThan(minimumValue) { - return this.passesRule(new _validationValidationRules.MinimumValueValidationRule(minimumValue)); - } - }, { - key: 'isGreaterThanOrEqualTo', - value: function isGreaterThanOrEqualTo(minimumValue) { - return this.passesRule(new _validationValidationRules.MinimumInclusiveValueValidationRule(minimumValue)); - } - }, { - key: 'isBetween', - value: function isBetween(minimumValue, maximumValue) { - return this.passesRule(new _validationValidationRules.BetweenValueValidationRule(minimumValue, maximumValue)); - } - }, { - key: 'isIn', - value: function isIn(collection) { - return this.passesRule(new _validationValidationRules.InCollectionValidationRule(collection)); - } - }, { - key: 'isLessThan', - value: function isLessThan(maximumValue) { - return this.passesRule(new _validationValidationRules.MaximumValueValidationRule(maximumValue)); - } - }, { - key: 'isLessThanOrEqualTo', - value: function isLessThanOrEqualTo(maximumValue) { - return this.passesRule(new _validationValidationRules.MaximumInclusiveValueValidationRule(maximumValue)); - } - }, { - key: 'isEqualTo', - value: function isEqualTo(otherValue, otherValueLabel) { - if (!otherValueLabel) { - return this.passesRule(new _validationValidationRules.EqualityValidationRule(otherValue)); - } else { - return this.passesRule(new _validationValidationRules.EqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); + break; } } - }, { - key: 'isNotEqualTo', - value: function isNotEqualTo(otherValue, otherValueLabel) { - if (!otherValueLabel) { - return this.passesRule(new _validationValidationRules.InEqualityValidationRule(otherValue)); - } else { - return this.passesRule(new _validationValidationRules.InEqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); - } - } - }, { - key: 'isEmail', - value: function isEmail() { - return this.passesRule(new _validationValidationRules.EmailValidationRule()); - } - }, { - key: 'hasMinLength', - value: function hasMinLength(minimumValue) { - return this.passesRule(new _validationValidationRules.MinimumLengthValidationRule(minimumValue)); - } - }, { - key: 'hasMaxLength', - value: function hasMaxLength(maximumValue) { - return this.passesRule(new _validationValidationRules.MaximumLengthValidationRule(maximumValue)); - } - }, { - key: 'hasLengthBetween', - value: function hasLengthBetween(minimumValue, maximumValue) { - return this.passesRule(new _validationValidationRules.BetweenLengthValidationRule(minimumValue, maximumValue)); - } - }, { - key: 'isNumber', - value: function isNumber() { - return this.passesRule(new _validationValidationRules.NumericValidationRule()); - } - }, { - key: 'containsOnlyDigits', - value: function containsOnlyDigits() { - return this.passesRule(new _validationValidationRules.DigitValidationRule()); - } - }, { - key: 'containsOnlyAlpha', - value: function containsOnlyAlpha() { - return this.passesRule(new _validationValidationRules.AlphaValidationRule()); - } - }, { - key: 'containsOnlyAlphaOrWhitespace', - value: function containsOnlyAlphaOrWhitespace() { - return this.passesRule(new _validationValidationRules.AlphaOrWhitespaceValidationRule()); - } - }, { - key: 'containsOnlyAlphanumerics', - value: function containsOnlyAlphanumerics() { - return this.passesRule(new _validationValidationRules.AlphaNumericValidationRule()); - } - }, { - key: 'containsOnlyAlphanumericsOrWhitespace', - value: function containsOnlyAlphanumericsOrWhitespace() { - return this.passesRule(new _validationValidationRules.AlphaNumericOrWhitespaceValidationRule()); - } - }, { - key: 'isStrongPassword', - value: function isStrongPassword(minimumComplexityLevel) { - if (minimumComplexityLevel === 4) { - return this.passesRule(new _validationValidationRules.StrongPasswordValidationRule()); - } else { - return this.passesRule(new _validationValidationRules.MediumPasswordValidationRule(minimumComplexityLevel)); + if (newValidationProperty === null) { + var propertyResult = this.validationGroup.result.addProperty(propertyName); + var config = new _validationValidationConfig.ValidationConfig(this.validationGroup.config); + if (configurationCallback !== undefined && typeof configurationCallback === 'function') { + configurationCallback(config); } + newValidationProperty = new _validationValidationProperty.ValidationProperty(this.observerLocator, propertyName, this.validationGroup, propertyResult, config); + this.validationGroup.validationProperties.push(newValidationProperty); } - }, { - key: 'containsOnly', - value: function containsOnly(regex) { - return this.passesRule(new _validationValidationRules.ContainsOnlyValidationRule(regex)); - } - }, { - key: 'matches', - value: function matches(regex) { - return this.passesRule(new _validationValidationRules.RegexValidationRule(regex)); - } - }, { - key: 'passes', - value: function passes(customFunction, threshold) { - return this.passesRule(new _validationValidationRules.CustomFunctionValidationRule(customFunction, threshold)); - } - }, { - key: 'passesRule', - value: function passesRule(validationRule) { + this.validationRuleCollections.unshift(newValidationProperty.collectionOfValidationRules); + return this.validationGroup; + }; - this.validationRuleCollections[0].addValidationRule(validationRule); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'checkLast', - value: function checkLast() { - var validationProperty = this.validationGroup.validationProperties[this.validationGroup.validationProperties.length - 1]; - validationProperty.validateCurrentValue(false); - } - }, { - key: 'withMessage', - value: function withMessage(message) { - this.validationRuleCollections[0].withMessage(message); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'if', - value: function _if(conditionExpression) { - var conditionalCollection = new _validationValidationRulesCollection.SwitchCaseValidationRulesCollection(conditionExpression); - conditionalCollection['case'](true); - this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); - this.validationRuleCollections.unshift(conditionalCollection); - return this.validationGroup; - } - }, { - key: 'else', - value: function _else() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'else\''; + ValidationGroupBuilder.prototype.isNotEmpty = function isNotEmpty() { + this.validationRuleCollections[0].isNotEmpty(); + this.checkLast(); + return this.validationGroup; + }; - this.validationRuleCollections[0]['default'](); - return this.validationGroup; - } - }, { - key: 'endIf', - value: function endIf() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; - this.validationRuleCollections.shift(); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'switch', - value: function _switch(conditionExpression) { - var _this = this; - - var condition = conditionExpression; - if (condition === undefined) { - (function () { - var observer = _this.validationGroup.validationProperties[_this.validationGroup.validationProperties.length - 1].observer; - condition = function () { - return observer.getValue(); - }; - })(); - } - var conditionalCollection = new _validationValidationRulesCollection.SwitchCaseValidationRulesCollection(condition); - this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); - this.validationRuleCollections.unshift(conditionalCollection); - return this.validationGroup; - } - }, { - key: 'case', - value: function _case(caseLabel) { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; - this.validationRuleCollections[0]['case'](caseLabel); - return this.validationGroup; + ValidationGroupBuilder.prototype.isGreaterThan = function isGreaterThan(minimumValue) { + return this.passesRule(new _validationValidationRules.MinimumValueValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.isGreaterThanOrEqualTo = function isGreaterThanOrEqualTo(minimumValue) { + return this.passesRule(new _validationValidationRules.MinimumInclusiveValueValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.isBetween = function isBetween(minimumValue, maximumValue) { + return this.passesRule(new _validationValidationRules.BetweenValueValidationRule(minimumValue, maximumValue)); + }; + + ValidationGroupBuilder.prototype.isIn = function isIn(collection) { + return this.passesRule(new _validationValidationRules.InCollectionValidationRule(collection)); + }; + + ValidationGroupBuilder.prototype.isLessThan = function isLessThan(maximumValue) { + return this.passesRule(new _validationValidationRules.MaximumValueValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.isLessThanOrEqualTo = function isLessThanOrEqualTo(maximumValue) { + return this.passesRule(new _validationValidationRules.MaximumInclusiveValueValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.isEqualTo = function isEqualTo(otherValue, otherValueLabel) { + if (!otherValueLabel) { + return this.passesRule(new _validationValidationRules.EqualityValidationRule(otherValue)); + } else { + return this.passesRule(new _validationValidationRules.EqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); } - }, { - key: 'default', - value: function _default() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; - this.validationRuleCollections[0]['default'](); - return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.isNotEqualTo = function isNotEqualTo(otherValue, otherValueLabel) { + if (!otherValueLabel) { + return this.passesRule(new _validationValidationRules.InEqualityValidationRule(otherValue)); + } else { + return this.passesRule(new _validationValidationRules.InEqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); } - }, { - key: 'endSwitch', - value: function endSwitch() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; - this.validationRuleCollections.shift(); - this.checkLast(); - return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.isEmail = function isEmail() { + return this.passesRule(new _validationValidationRules.EmailValidationRule()); + }; + + ValidationGroupBuilder.prototype.hasMinLength = function hasMinLength(minimumValue) { + return this.passesRule(new _validationValidationRules.MinimumLengthValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.hasMaxLength = function hasMaxLength(maximumValue) { + return this.passesRule(new _validationValidationRules.MaximumLengthValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.hasLengthBetween = function hasLengthBetween(minimumValue, maximumValue) { + return this.passesRule(new _validationValidationRules.BetweenLengthValidationRule(minimumValue, maximumValue)); + }; + + ValidationGroupBuilder.prototype.isNumber = function isNumber() { + return this.passesRule(new _validationValidationRules.NumericValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyDigits = function containsOnlyDigits() { + return this.passesRule(new _validationValidationRules.DigitValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlpha = function containsOnlyAlpha() { + return this.passesRule(new _validationValidationRules.AlphaValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphaOrWhitespace = function containsOnlyAlphaOrWhitespace() { + return this.passesRule(new _validationValidationRules.AlphaOrWhitespaceValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphanumerics = function containsOnlyAlphanumerics() { + return this.passesRule(new _validationValidationRules.AlphaNumericValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphanumericsOrWhitespace = function containsOnlyAlphanumericsOrWhitespace() { + return this.passesRule(new _validationValidationRules.AlphaNumericOrWhitespaceValidationRule()); + }; + + ValidationGroupBuilder.prototype.isStrongPassword = function isStrongPassword(minimumComplexityLevel) { + if (minimumComplexityLevel === 4) { + return this.passesRule(new _validationValidationRules.StrongPasswordValidationRule()); + } else { + return this.passesRule(new _validationValidationRules.MediumPasswordValidationRule(minimumComplexityLevel)); } - }]); + }; + + ValidationGroupBuilder.prototype.containsOnly = function containsOnly(regex) { + return this.passesRule(new _validationValidationRules.ContainsOnlyValidationRule(regex)); + }; + + ValidationGroupBuilder.prototype.matches = function matches(regex) { + return this.passesRule(new _validationValidationRules.RegexValidationRule(regex)); + }; + + ValidationGroupBuilder.prototype.passes = function passes(customFunction, threshold) { + return this.passesRule(new _validationValidationRules.CustomFunctionValidationRule(customFunction, threshold)); + }; + + ValidationGroupBuilder.prototype.passesRule = function passesRule(validationRule) { + + this.validationRuleCollections[0].addValidationRule(validationRule); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.checkLast = function checkLast() { + var validationProperty = this.validationGroup.validationProperties[this.validationGroup.validationProperties.length - 1]; + validationProperty.validateCurrentValue(false); + }; + + ValidationGroupBuilder.prototype.withMessage = function withMessage(message) { + this.validationRuleCollections[0].withMessage(message); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['if'] = function _if(conditionExpression) { + var conditionalCollection = new _validationValidationRulesCollection.SwitchCaseValidationRulesCollection(conditionExpression); + conditionalCollection['case'](true); + this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); + this.validationRuleCollections.unshift(conditionalCollection); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['else'] = function _else() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'else\''; + + this.validationRuleCollections[0]['default'](); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.endIf = function endIf() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; + this.validationRuleCollections.shift(); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['switch'] = function _switch(conditionExpression) { + var _this = this; + + var condition = conditionExpression; + if (condition === undefined) { + (function () { + var observer = _this.validationGroup.validationProperties[_this.validationGroup.validationProperties.length - 1].observer; + condition = function () { + return observer.getValue(); + }; + })(); + } + var conditionalCollection = new _validationValidationRulesCollection.SwitchCaseValidationRulesCollection(condition); + this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); + this.validationRuleCollections.unshift(conditionalCollection); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['case'] = function _case(caseLabel) { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; + this.validationRuleCollections[0]['case'](caseLabel); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['default'] = function _default() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; + this.validationRuleCollections[0]['default'](); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.endSwitch = function endSwitch() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; + this.validationRuleCollections.shift(); + this.checkLast(); + return this.validationGroup; + }; return ValidationGroupBuilder; })(); diff --git a/dist/amd/validation/validation-group.js b/dist/amd/validation/validation-group.js index f476a445..56198bcf 100644 --- a/dist/amd/validation/validation-group.js +++ b/dist/amd/validation/validation-group.js @@ -3,11 +3,7 @@ define(['exports', '../validation/validation-group-builder', '../validation/vali var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidationGroup = (function () { function ValidationGroup(subject, observerLocator, config) { @@ -32,331 +28,288 @@ define(['exports', '../validation/validation-group-builder', '../validation/vali } } - _createClass(ValidationGroup, [{ - key: 'destroy', - value: function destroy() { - this.onDestroy(); - } - }, { - key: 'clear', - value: function clear() { - this.validationProperties.forEach(function (prop) { - prop.clear(); - }); - this.result.clear(); - } - }, { - key: 'onBreezeEntity', - value: function onBreezeEntity() { - var _this2 = this; - - var breezeEntity = this.subject; - var me = this; - this.onPropertyValidate(function (propertyBindingPath) { - _this2.passes(function () { - breezeEntity.entityAspect.validateProperty(propertyBindingPath); - var errors = breezeEntity.entityAspect.getValidationErrors(propertyBindingPath); - if (errors.length === 0) return true;else return errors[0].errorMessage; - }); - }); - this.onValidate(function () { - breezeEntity.entityAspect.validateEntity(); - return {}; + ValidationGroup.prototype.destroy = function destroy() { + this.onDestroy(); + }; + + ValidationGroup.prototype.clear = function clear() { + this.validationProperties.forEach(function (prop) { + prop.clear(); + }); + this.result.clear(); + }; + + ValidationGroup.prototype.onBreezeEntity = function onBreezeEntity() { + var _this2 = this; + + var breezeEntity = this.subject; + var me = this; + this.onPropertyValidate(function (propertyBindingPath) { + _this2.passes(function () { + breezeEntity.entityAspect.validateProperty(propertyBindingPath); + var errors = breezeEntity.entityAspect.getValidationErrors(propertyBindingPath); + if (errors.length === 0) return true;else return errors[0].errorMessage; }); + }); + this.onValidate(function () { + breezeEntity.entityAspect.validateEntity(); + return {}; + }); - breezeEntity.entityAspect.validationErrorsChanged.subscribe(function () { - breezeEntity.entityAspect.getValidationErrors().forEach(function (validationError) { - var propertyName = validationError.propertyName; - if (!me.result.properties[propertyName]) { - me.ensure(propertyName); - } + breezeEntity.entityAspect.validationErrorsChanged.subscribe(function () { + breezeEntity.entityAspect.getValidationErrors().forEach(function (validationError) { + var propertyName = validationError.propertyName; + if (!me.result.properties[propertyName]) { + me.ensure(propertyName); + } - var currentResultProp = me.result.addProperty(propertyName); - if (currentResultProp.isValid) { + var currentResultProp = me.result.addProperty(propertyName); + if (currentResultProp.isValid) { - currentResultProp.setValidity({ - isValid: false, - message: validationError.errorMessage, - failingRule: 'breeze', - latestValue: currentResultProp.latestValue - }, true); - } - }); + currentResultProp.setValidity({ + isValid: false, + message: validationError.errorMessage, + failingRule: 'breeze', + latestValue: currentResultProp.latestValue + }, true); + } }); - } - }, { - key: 'validate', - value: function validate() { - var _this3 = this; + }); + }; - var forceDirty = arguments[0] === undefined ? true : arguments[0]; - var forceExecution = arguments[1] === undefined ? true : arguments[1]; + ValidationGroup.prototype.validate = function validate() { + var _this3 = this; - this.isValidating = true; - var promise = Promise.resolve(true); + var forceDirty = arguments[0] === undefined ? true : arguments[0]; + var forceExecution = arguments[1] === undefined ? true : arguments[1]; - var _loop = function (i) { - var validatorProperty = _this3.validationProperties[i]; - promise = promise.then(function () { - return validatorProperty.validateCurrentValue(forceDirty, forceExecution); - }); - }; + this.isValidating = true; + var promise = Promise.resolve(true); - for (var i = this.validationProperties.length - 1; i >= 0; i--) { - _loop(i); - } - promise = promise['catch'](function () { - console.log('Should never get here: a validation property should always resolve to true/false!'); - debugger; - throw Error('Should never get here: a validation property should always resolve to true/false!'); + var _loop = function (i) { + var validatorProperty = _this3.validationProperties[i]; + promise = promise.then(function () { + return validatorProperty.validateCurrentValue(forceDirty, forceExecution); }); + }; - this.onValidateCallbacks.forEach(function (onValidateCallback) { - promise = promise.then(function () { - return _this3.config.locale(); - }).then(function (locale) { - return Promise.resolve(onValidateCallback.validationFunction()).then(function (callbackResult) { - for (var prop in callbackResult) { - if (!_this3.result.properties[prop]) { - _this3.ensure(prop); + for (var i = this.validationProperties.length - 1; i >= 0; i--) { + _loop(i); + } + promise = promise['catch'](function () { + console.log('Should never get here: a validation property should always resolve to true/false!'); + debugger; + throw Error('Should never get here: a validation property should always resolve to true/false!'); + }); + + this.onValidateCallbacks.forEach(function (onValidateCallback) { + promise = promise.then(function () { + return _this3.config.locale(); + }).then(function (locale) { + return Promise.resolve(onValidateCallback.validationFunction()).then(function (callbackResult) { + for (var prop in callbackResult) { + if (!_this3.result.properties[prop]) { + _this3.ensure(prop); + } + var resultProp = _this3.result.addProperty(prop); + var result = callbackResult[prop]; + var newPropResult = { + latestValue: resultProp.latestValue + }; + if (result === true || result === null || result === '') { + if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { + newPropResult.failingRule = null; + newPropResult.message = ''; + newPropResult.isValid = true; + resultProp.setValidity(newPropResult, true); } - var resultProp = _this3.result.addProperty(prop); - var result = callbackResult[prop]; - var newPropResult = { - latestValue: resultProp.latestValue - }; - if (result === true || result === null || result === '') { - if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { - newPropResult.failingRule = null; - newPropResult.message = ''; - newPropResult.isValid = true; - resultProp.setValidity(newPropResult, true); - } - } else { - if (resultProp.isValid) { - newPropResult.failingRule = 'onValidateCallback'; - newPropResult.isValid = false; - if (typeof result === 'string') { - newPropResult.message = result; - } else { - newPropResult.message = locale.translate(newPropResult.failingRule); - } - resultProp.setValidity(newPropResult, true); + } else { + if (resultProp.isValid) { + newPropResult.failingRule = 'onValidateCallback'; + newPropResult.isValid = false; + if (typeof result === 'string') { + newPropResult.message = result; + } else { + newPropResult.message = locale.translate(newPropResult.failingRule); } + resultProp.setValidity(newPropResult, true); } } - _this3.result.checkValidity(); - }, function (a, b, c, d, e) { - debugger; - _this3.result.isValid = false; - if (onValidateCallback.validationFunctionFailedCallback) { - onValidateCallback.validationFunctionFailedCallback(a, b, c, d, e); - } - }); + } + _this3.result.checkValidity(); + }, function (a, b, c, d, e) { + debugger; + _this3.result.isValid = false; + if (onValidateCallback.validationFunctionFailedCallback) { + onValidateCallback.validationFunctionFailedCallback(a, b, c, d, e); + } }); }); - promise = promise.then(function () { - _this3.isValidating = false; - if (_this3.result.isValid) { - return Promise.resolve(_this3.result); - } else { - return Promise.reject(_this3.result); - } - }); - return promise; - } - }, { - key: 'onValidate', - value: function onValidate(validationFunction, validationFunctionFailedCallback) { - this.onValidateCallbacks.push({ validationFunction: validationFunction, validationFunctionFailedCallback: validationFunctionFailedCallback }); - return this; - } - }, { - key: 'onPropertyValidate', - value: function onPropertyValidate(validationFunction) { - this.onPropertyValidationCallbacks.push(validationFunction); - return this; - } - }, { - key: 'ensure', - value: function ensure(bindingPath, configCallback) { - this.builder.ensure(bindingPath, configCallback); - this.onPropertyValidationCallbacks.forEach(function (callback) { - callback(bindingPath); - }); - return this; - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - return this.builder.isNotEmpty(); - } - }, { - key: 'isGreaterThanOrEqualTo', - value: function isGreaterThanOrEqualTo(minimumValue) { - return this.builder.isGreaterThanOrEqualTo(minimumValue); - } - }, { - key: 'isGreaterThan', - value: function isGreaterThan(minimumValue) { - return this.builder.isGreaterThan(minimumValue); - } - }, { - key: 'isBetween', - value: function isBetween(minimumValue, maximumValue) { - return this.builder.isBetween(minimumValue, maximumValue); - } - }, { - key: 'isLessThanOrEqualTo', - value: function isLessThanOrEqualTo(maximumValue) { - return this.builder.isLessThanOrEqualTo(maximumValue); - } - }, { - key: 'isLessThan', - value: function isLessThan(maximumValue) { - return this.builder.isLessThan(maximumValue); - } - }, { - key: 'isEqualTo', - value: function isEqualTo(otherValue, otherValueLabel) { - return this.builder.isEqualTo(otherValue, otherValueLabel); - } - }, { - key: 'isNotEqualTo', - value: function isNotEqualTo(otherValue, otherValueLabel) { - return this.builder.isNotEqualTo(otherValue, otherValueLabel); - } - }, { - key: 'isEmail', - value: function isEmail() { - return this.builder.isEmail(); - } - }, { - key: 'isIn', - value: function isIn(collection) { - return this.builder.isIn(collection); - } - }, { - key: 'hasMinLength', - value: function hasMinLength(minimumValue) { - return this.builder.hasMinLength(minimumValue); - } - }, { - key: 'hasMaxLength', - value: function hasMaxLength(maximumValue) { - return this.builder.hasMaxLength(maximumValue); - } - }, { - key: 'hasLengthBetween', - value: function hasLengthBetween(minimumValue, maximumValue) { - return this.builder.hasLengthBetween(minimumValue, maximumValue); - } - }, { - key: 'isNumber', - value: function isNumber() { - return this.builder.isNumber(); - } - }, { - key: 'containsOnlyDigits', - value: function containsOnlyDigits() { - return this.builder.containsOnlyDigits(); - } - }, { - key: 'containsOnly', - value: function containsOnly(regex) { - return this.builder.containsOnly(regex); - } - }, { - key: 'containsOnlyAlpha', - value: function containsOnlyAlpha() { - return this.builder.containsOnlyAlpha(); - } - }, { - key: 'containsOnlyAlphaOrWhitespace', - value: function containsOnlyAlphaOrWhitespace() { - return this.builder.containsOnlyAlphaOrWhitespace(); - } - }, { - key: 'containsOnlyLetters', - value: function containsOnlyLetters() { - return this.builder.containsOnlyAlpha(); - } - }, { - key: 'containsOnlyLettersOrWhitespace', - value: function containsOnlyLettersOrWhitespace() { - return this.builder.containsOnlyAlphaOrWhitespace(); - } - }, { - key: 'containsOnlyAlphanumerics', - value: function containsOnlyAlphanumerics() { - return this.builder.containsOnlyAlphanumerics(); - } - }, { - key: 'containsOnlyAlphanumericsOrWhitespace', - value: function containsOnlyAlphanumericsOrWhitespace() { - return this.builder.containsOnlyAlphanumericsOrWhitespace(); - } - }, { - key: 'isStrongPassword', - value: function isStrongPassword(minimumComplexityLevel) { - return this.builder.isStrongPassword(minimumComplexityLevel); - } - }, { - key: 'matches', - value: function matches(regex) { - return this.builder.matches(regex); - } - }, { - key: 'passes', - value: function passes(customFunction, threshold) { - return this.builder.passes(customFunction, threshold); - } - }, { - key: 'passesRule', - value: function passesRule(validationRule) { - return this.builder.passesRule(validationRule); - } - }, { - key: 'if', - value: function _if(conditionExpression, threshold) { - return this.builder['if'](conditionExpression, threshold); - } - }, { - key: 'else', - value: function _else() { - return this.builder['else'](); - } - }, { - key: 'endIf', - value: function endIf() { - return this.builder.endIf(); - } - }, { - key: 'switch', - value: function _switch(conditionExpression) { - return this.builder['switch'](conditionExpression); - } - }, { - key: 'case', - value: function _case(caseLabel) { - return this.builder['case'](caseLabel); - } - }, { - key: 'default', - value: function _default() { - return this.builder['default'](); - } - }, { - key: 'endSwitch', - value: function endSwitch() { - return this.builder.endSwitch(); - } - }, { - key: 'withMessage', - value: function withMessage(message) { - return this.builder.withMessage(message); - } - }]); + }); + promise = promise.then(function () { + _this3.isValidating = false; + if (_this3.result.isValid) { + return Promise.resolve(_this3.result); + } else { + return Promise.reject(_this3.result); + } + }); + return promise; + }; + + ValidationGroup.prototype.onValidate = function onValidate(validationFunction, validationFunctionFailedCallback) { + this.onValidateCallbacks.push({ validationFunction: validationFunction, validationFunctionFailedCallback: validationFunctionFailedCallback }); + return this; + }; + + ValidationGroup.prototype.onPropertyValidate = function onPropertyValidate(validationFunction) { + this.onPropertyValidationCallbacks.push(validationFunction); + return this; + }; + + ValidationGroup.prototype.ensure = function ensure(bindingPath, configCallback) { + this.builder.ensure(bindingPath, configCallback); + this.onPropertyValidationCallbacks.forEach(function (callback) { + callback(bindingPath); + }); + return this; + }; + + ValidationGroup.prototype.isNotEmpty = function isNotEmpty() { + return this.builder.isNotEmpty(); + }; + + ValidationGroup.prototype.isGreaterThanOrEqualTo = function isGreaterThanOrEqualTo(minimumValue) { + return this.builder.isGreaterThanOrEqualTo(minimumValue); + }; + + ValidationGroup.prototype.isGreaterThan = function isGreaterThan(minimumValue) { + return this.builder.isGreaterThan(minimumValue); + }; + + ValidationGroup.prototype.isBetween = function isBetween(minimumValue, maximumValue) { + return this.builder.isBetween(minimumValue, maximumValue); + }; + + ValidationGroup.prototype.isLessThanOrEqualTo = function isLessThanOrEqualTo(maximumValue) { + return this.builder.isLessThanOrEqualTo(maximumValue); + }; + + ValidationGroup.prototype.isLessThan = function isLessThan(maximumValue) { + return this.builder.isLessThan(maximumValue); + }; + + ValidationGroup.prototype.isEqualTo = function isEqualTo(otherValue, otherValueLabel) { + return this.builder.isEqualTo(otherValue, otherValueLabel); + }; + + ValidationGroup.prototype.isNotEqualTo = function isNotEqualTo(otherValue, otherValueLabel) { + return this.builder.isNotEqualTo(otherValue, otherValueLabel); + }; + + ValidationGroup.prototype.isEmail = function isEmail() { + return this.builder.isEmail(); + }; + + ValidationGroup.prototype.isIn = function isIn(collection) { + return this.builder.isIn(collection); + }; + + ValidationGroup.prototype.hasMinLength = function hasMinLength(minimumValue) { + return this.builder.hasMinLength(minimumValue); + }; + + ValidationGroup.prototype.hasMaxLength = function hasMaxLength(maximumValue) { + return this.builder.hasMaxLength(maximumValue); + }; + + ValidationGroup.prototype.hasLengthBetween = function hasLengthBetween(minimumValue, maximumValue) { + return this.builder.hasLengthBetween(minimumValue, maximumValue); + }; + + ValidationGroup.prototype.isNumber = function isNumber() { + return this.builder.isNumber(); + }; + + ValidationGroup.prototype.containsOnlyDigits = function containsOnlyDigits() { + return this.builder.containsOnlyDigits(); + }; + + ValidationGroup.prototype.containsOnly = function containsOnly(regex) { + return this.builder.containsOnly(regex); + }; + + ValidationGroup.prototype.containsOnlyAlpha = function containsOnlyAlpha() { + return this.builder.containsOnlyAlpha(); + }; + + ValidationGroup.prototype.containsOnlyAlphaOrWhitespace = function containsOnlyAlphaOrWhitespace() { + return this.builder.containsOnlyAlphaOrWhitespace(); + }; + + ValidationGroup.prototype.containsOnlyLetters = function containsOnlyLetters() { + return this.builder.containsOnlyAlpha(); + }; + + ValidationGroup.prototype.containsOnlyLettersOrWhitespace = function containsOnlyLettersOrWhitespace() { + return this.builder.containsOnlyAlphaOrWhitespace(); + }; + + ValidationGroup.prototype.containsOnlyAlphanumerics = function containsOnlyAlphanumerics() { + return this.builder.containsOnlyAlphanumerics(); + }; + + ValidationGroup.prototype.containsOnlyAlphanumericsOrWhitespace = function containsOnlyAlphanumericsOrWhitespace() { + return this.builder.containsOnlyAlphanumericsOrWhitespace(); + }; + + ValidationGroup.prototype.isStrongPassword = function isStrongPassword(minimumComplexityLevel) { + return this.builder.isStrongPassword(minimumComplexityLevel); + }; + + ValidationGroup.prototype.matches = function matches(regex) { + return this.builder.matches(regex); + }; + + ValidationGroup.prototype.passes = function passes(customFunction, threshold) { + return this.builder.passes(customFunction, threshold); + }; + + ValidationGroup.prototype.passesRule = function passesRule(validationRule) { + return this.builder.passesRule(validationRule); + }; + + ValidationGroup.prototype['if'] = function _if(conditionExpression, threshold) { + return this.builder['if'](conditionExpression, threshold); + }; + + ValidationGroup.prototype['else'] = function _else() { + return this.builder['else'](); + }; + + ValidationGroup.prototype.endIf = function endIf() { + return this.builder.endIf(); + }; + + ValidationGroup.prototype['switch'] = function _switch(conditionExpression) { + return this.builder['switch'](conditionExpression); + }; + + ValidationGroup.prototype['case'] = function _case(caseLabel) { + return this.builder['case'](caseLabel); + }; + + ValidationGroup.prototype['default'] = function _default() { + return this.builder['default'](); + }; + + ValidationGroup.prototype.endSwitch = function endSwitch() { + return this.builder.endSwitch(); + }; + + ValidationGroup.prototype.withMessage = function withMessage(message) { + return this.builder.withMessage(message); + }; return ValidationGroup; })(); diff --git a/dist/amd/validation/validation-locale.js b/dist/amd/validation/validation-locale.js index 6e36f2b1..ec6225fc 100644 --- a/dist/amd/validation/validation-locale.js +++ b/dist/amd/validation/validation-locale.js @@ -3,11 +3,7 @@ define(['exports'], function (exports) { var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidationLocale = (function () { function ValidationLocale(defaults, data) { @@ -17,41 +13,36 @@ define(['exports'], function (exports) { this.currentLocale = data; } - _createClass(ValidationLocale, [{ - key: 'getValueFor', - value: function getValueFor(identifier, category) { - if (this.currentLocale && this.currentLocale[category]) { - var currentLocaleSetting = this.currentLocale[category][identifier]; - if (currentLocaleSetting !== undefined && currentLocaleSetting !== null) { - return currentLocaleSetting; - } + ValidationLocale.prototype.getValueFor = function getValueFor(identifier, category) { + if (this.currentLocale && this.currentLocale[category]) { + var currentLocaleSetting = this.currentLocale[category][identifier]; + if (currentLocaleSetting !== undefined && currentLocaleSetting !== null) { + return currentLocaleSetting; } - if (this.defaults[category]) { - var defaultSetting = this.defaults[category][identifier]; - if (defaultSetting !== undefined && defaultSetting !== null) { - return defaultSetting; - } + } + if (this.defaults[category]) { + var defaultSetting = this.defaults[category][identifier]; + if (defaultSetting !== undefined && defaultSetting !== null) { + return defaultSetting; } - throw 'validation: I18N: Could not find: ' + identifier + ' in category: ' + category; } - }, { - key: 'setting', - value: function setting(settingIdentifier) { - return this.getValueFor(settingIdentifier, 'settings'); + throw 'validation: I18N: Could not find: ' + identifier + ' in category: ' + category; + }; + + ValidationLocale.prototype.setting = function setting(settingIdentifier) { + return this.getValueFor(settingIdentifier, 'settings'); + }; + + ValidationLocale.prototype.translate = function translate(translationIdentifier, newValue, threshold) { + var translation = this.getValueFor(translationIdentifier, 'messages'); + if (typeof translation === 'function') { + return translation(newValue, threshold); } - }, { - key: 'translate', - value: function translate(translationIdentifier, newValue, threshold) { - var translation = this.getValueFor(translationIdentifier, 'messages'); - if (typeof translation === 'function') { - return translation(newValue, threshold); - } - if (typeof translation === 'string') { - return translation; - } - throw 'Validation message for ' + translationIdentifier + 'was in an unsupported format'; + if (typeof translation === 'string') { + return translation; } - }]); + throw 'Validation message for ' + translationIdentifier + 'was in an unsupported format'; + }; return ValidationLocale; })(); @@ -72,33 +63,29 @@ define(['exports'], function (exports) { }; } - _createClass(ValidationLocaleRepository, [{ - key: 'load', - value: function load(localeIdentifier, basePath) { - var _this = this; + ValidationLocaleRepository.prototype.load = function load(localeIdentifier, basePath) { + var _this = this; - if (!basePath) basePath = 'aurelia-validation/resources/'; - return new Promise(function (resolve, reject) { - if (_this.instances.has(localeIdentifier)) { - var locale = _this.instances.get(localeIdentifier); + if (!basePath) basePath = 'aurelia-validation/resources/'; + return new Promise(function (resolve, reject) { + if (_this.instances.has(localeIdentifier)) { + var locale = _this.instances.get(localeIdentifier); + resolve(locale); + } else { + System['import'](basePath + localeIdentifier).then(function (resource) { + var locale = _this.addLocale(localeIdentifier, resource.data); resolve(locale); - } else { - System['import'](basePath + localeIdentifier).then(function (resource) { - var locale = _this.addLocale(localeIdentifier, resource.data); - resolve(locale); - }); - } - }); - } - }, { - key: 'addLocale', - value: function addLocale(localeIdentifier, data) { - var instance = new ValidationLocale(this.defaults, data); - this.instances.set(localeIdentifier, instance); - if (this['default'] === null) this['default'] = instance; - return instance; - } - }]); + }); + } + }); + }; + + ValidationLocaleRepository.prototype.addLocale = function addLocale(localeIdentifier, data) { + var instance = new ValidationLocale(this.defaults, data); + this.instances.set(localeIdentifier, instance); + if (this['default'] === null) this['default'] = instance; + return instance; + }; return ValidationLocaleRepository; })(); diff --git a/dist/amd/validation/validation-property.js b/dist/amd/validation/validation-property.js index 3715f26a..6ca1a94a 100644 --- a/dist/amd/validation/validation-property.js +++ b/dist/amd/validation/validation-property.js @@ -3,11 +3,7 @@ define(['exports', '../validation/validation-rules-collection', '../validation/p var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidationProperty = (function () { function ValidationProperty(observerLocator, propertyName, validationGroup, propertyResult, config) { @@ -48,46 +44,40 @@ define(['exports', '../validation/validation-rules-collection', '../validation/p } } - _createClass(ValidationProperty, [{ - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); - this.collectionOfValidationRules.addValidationRule(validationRule); - this.validateCurrentValue(false); - } - }, { - key: 'validateCurrentValue', - value: function validateCurrentValue(forceDirty, forceExecution) { - return this.validate(this.observer.getValue(), forceDirty, forceExecution); - } - }, { - key: 'clear', - value: function clear() { - this.latestValue = this.observer.getValue(); - this.propertyResult.clear(); - } - }, { - key: 'validate', - value: function validate(newValue, shouldBeDirty, forceExecution) { - var _this2 = this; - - if (!this.propertyResult.isDirty && shouldBeDirty || this.latestValue !== newValue || forceExecution) { - this.latestValue = newValue; - return this.config.locale().then(function (locale) { - return _this2.collectionOfValidationRules.validate(newValue, locale).then(function (validationResponse) { - if (_this2.latestValue === validationResponse.latestValue) _this2.propertyResult.setValidity(validationResponse, shouldBeDirty); - return validationResponse.isValid; - })['catch'](function (err) { - console.log('Unexpected behavior: a validation-rules-collection should always fulfil', err); - debugger; - throw Error('Unexpected behavior: a validation-rules-collection should always fulfil'); - }); - }, function () { - throw Error('An exception occurred while trying to load the locale'); + ValidationProperty.prototype.addValidationRule = function addValidationRule(validationRule) { + if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); + this.collectionOfValidationRules.addValidationRule(validationRule); + this.validateCurrentValue(false); + }; + + ValidationProperty.prototype.validateCurrentValue = function validateCurrentValue(forceDirty, forceExecution) { + return this.validate(this.observer.getValue(), forceDirty, forceExecution); + }; + + ValidationProperty.prototype.clear = function clear() { + this.latestValue = this.observer.getValue(); + this.propertyResult.clear(); + }; + + ValidationProperty.prototype.validate = function validate(newValue, shouldBeDirty, forceExecution) { + var _this2 = this; + + if (!this.propertyResult.isDirty && shouldBeDirty || this.latestValue !== newValue || forceExecution) { + this.latestValue = newValue; + return this.config.locale().then(function (locale) { + return _this2.collectionOfValidationRules.validate(newValue, locale).then(function (validationResponse) { + if (_this2.latestValue === validationResponse.latestValue) _this2.propertyResult.setValidity(validationResponse, shouldBeDirty); + return validationResponse.isValid; + })['catch'](function (err) { + console.log('Unexpected behavior: a validation-rules-collection should always fulfil', err); + debugger; + throw Error('Unexpected behavior: a validation-rules-collection should always fulfil'); }); - } + }, function () { + throw Error('An exception occurred while trying to load the locale'); + }); } - }]); + }; return ValidationProperty; })(); diff --git a/dist/amd/validation/validation-result.js b/dist/amd/validation/validation-result.js index eff643d0..e7b7beba 100644 --- a/dist/amd/validation/validation-result.js +++ b/dist/amd/validation/validation-result.js @@ -3,11 +3,7 @@ define(['exports'], function (exports) { var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidationResult = (function () { function ValidationResult() { @@ -17,31 +13,26 @@ define(['exports'], function (exports) { this.properties = {}; } - _createClass(ValidationResult, [{ - key: 'addProperty', - value: function addProperty(name) { - if (!this.properties[name]) { - this.properties[name] = new ValidationResultProperty(this); - } - return this.properties[name]; + ValidationResult.prototype.addProperty = function addProperty(name) { + if (!this.properties[name]) { + this.properties[name] = new ValidationResultProperty(this); } - }, { - key: 'checkValidity', - value: function checkValidity() { - for (var propertyName in this.properties) { - if (!this.properties[propertyName].isValid) { - this.isValid = false; - return; - } + return this.properties[name]; + }; + + ValidationResult.prototype.checkValidity = function checkValidity() { + for (var propertyName in this.properties) { + if (!this.properties[propertyName].isValid) { + this.isValid = false; + return; } - this.isValid = true; } - }, { - key: 'clear', - value: function clear() { - this.isValid = true; - } - }]); + this.isValid = true; + }; + + ValidationResult.prototype.clear = function clear() { + this.isValid = true; + }; return ValidationResult; })(); @@ -57,46 +48,40 @@ define(['exports'], function (exports) { this.clear(); } - _createClass(ValidationResultProperty, [{ - key: 'clear', - value: function clear() { - this.isValid = true; - this.isDirty = false; - this.message = ''; - this.failingRule = null; - this.latestValue = null; - this.notifyObserversOfChange(); - } - }, { - key: 'onValidate', - value: function onValidate(onValidateCallback) { - this.onValidateCallbacks.push(onValidateCallback); - } - }, { - key: 'notifyObserversOfChange', - value: function notifyObserversOfChange() { - for (var i = 0; i < this.onValidateCallbacks.length; i++) { - var callback = this.onValidateCallbacks[i]; - callback(this); - } + ValidationResultProperty.prototype.clear = function clear() { + this.isValid = true; + this.isDirty = false; + this.message = ''; + this.failingRule = null; + this.latestValue = null; + this.notifyObserversOfChange(); + }; + + ValidationResultProperty.prototype.onValidate = function onValidate(onValidateCallback) { + this.onValidateCallbacks.push(onValidateCallback); + }; + + ValidationResultProperty.prototype.notifyObserversOfChange = function notifyObserversOfChange() { + for (var i = 0; i < this.onValidateCallbacks.length; i++) { + var callback = this.onValidateCallbacks[i]; + callback(this); } - }, { - key: 'setValidity', - value: function setValidity(validationResponse, shouldBeDirty) { - var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; - - if (shouldBeDirty) this.isDirty = true; - this.message = validationResponse.message; - this.failingRule = validationResponse.failingRule; - this.isValid = validationResponse.isValid; - this.latestValue = validationResponse.latestValue; - if (this.isValid !== this.group.isValid) this.group.checkValidity(); - - if (notifyObservers) { - this.notifyObserversOfChange(); - } + }; + + ValidationResultProperty.prototype.setValidity = function setValidity(validationResponse, shouldBeDirty) { + var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; + + if (shouldBeDirty) this.isDirty = true; + this.message = validationResponse.message; + this.failingRule = validationResponse.failingRule; + this.isValid = validationResponse.isValid; + this.latestValue = validationResponse.latestValue; + if (this.isValid !== this.group.isValid) this.group.checkValidity(); + + if (notifyObservers) { + this.notifyObserversOfChange(); } - }]); + }; return ValidationResultProperty; })(); diff --git a/dist/amd/validation/validation-rules-collection.js b/dist/amd/validation/validation-rules-collection.js index 7104e04d..483cd4f4 100644 --- a/dist/amd/validation/validation-rules-collection.js +++ b/dist/amd/validation/validation-rules-collection.js @@ -3,11 +3,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidationRulesCollection = (function () { function ValidationRulesCollection() { @@ -19,103 +15,96 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] this.isRequiredMessage = null; } - _createClass(ValidationRulesCollection, [{ - key: 'validate', - value: function validate(newValue, locale) { - var _this = this; + ValidationRulesCollection.prototype.validate = function validate(newValue, locale) { + var _this = this; - if (locale === undefined) { - locale = _validationValidationLocale.ValidationLocale.Repository['default']; - } - newValue = _validationUtilities.Utilities.getValue(newValue); - var executeRules = true; - - if (_validationUtilities.Utilities.isEmptyValue(newValue)) { - if (this.isRequired) { - return Promise.resolve({ - isValid: false, - message: this.isRequiredMessage ? typeof this.isRequiredMessage === 'function' ? this.isRequiredMessage(newValue) : this.isRequiredMessage : locale.translate('isRequired'), - failingRule: 'isRequired', - latestValue: newValue - }); - } else { - executeRules = false; - } + if (locale === undefined) { + locale = _validationValidationLocale.ValidationLocale.Repository['default']; + } + newValue = _validationUtilities.Utilities.getValue(newValue); + var executeRules = true; + + if (_validationUtilities.Utilities.isEmptyValue(newValue)) { + if (this.isRequired) { + return Promise.resolve({ + isValid: false, + message: this.isRequiredMessage ? typeof this.isRequiredMessage === 'function' ? this.isRequiredMessage(newValue) : this.isRequiredMessage : locale.translate('isRequired'), + failingRule: 'isRequired', + latestValue: newValue + }); + } else { + executeRules = false; } + } - var checks = Promise.resolve({ - isValid: true, - message: '', - failingRule: null, - latestValue: newValue - }); - - if (executeRules) { - var _loop = function (i) { - var rule = _this.validationRules[i]; - checks = checks.then(function (previousRuleResult) { - if (previousRuleResult.isValid === false) { - return previousRuleResult; - } else { - return rule.validate(newValue, locale).then(function (thisRuleResult) { - if (thisRuleResult === false) { - return { - isValid: false, - message: rule.explain(), - failingRule: rule.ruleName, - latestValue: newValue - }; - } else { - if (!previousRuleResult.isValid) { - throw Error('ValidationRulesCollection.validate caught an unexpected result while validating it\'s chain of rules.'); - } - return previousRuleResult; + var checks = Promise.resolve({ + isValid: true, + message: '', + failingRule: null, + latestValue: newValue + }); + + if (executeRules) { + var _loop = function (i) { + var rule = _this.validationRules[i]; + checks = checks.then(function (previousRuleResult) { + if (previousRuleResult.isValid === false) { + return previousRuleResult; + } else { + return rule.validate(newValue, locale).then(function (thisRuleResult) { + if (thisRuleResult === false) { + return { + isValid: false, + message: rule.explain(), + failingRule: rule.ruleName, + latestValue: newValue + }; + } else { + if (!previousRuleResult.isValid) { + throw Error('ValidationRulesCollection.validate caught an unexpected result while validating it\'s chain of rules.'); } - }); - } - }); - }; - - for (var i = 0; i < this.validationRules.length; i++) { - _loop(i); - } - } - - var _loop2 = function (i) { - var validationCollection = _this.validationCollections[i]; - checks = checks.then(function (previousValidationResult) { - if (previousValidationResult.isValid) return validationCollection.validate(newValue, locale);else return previousValidationResult; + return previousRuleResult; + } + }); + } }); }; - for (var i = 0; i < this.validationCollections.length; i++) { - _loop2(i); + for (var i = 0; i < this.validationRules.length; i++) { + _loop(i); } - - return checks; - } - }, { - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); - this.validationRules.push(validationRule); - } - }, { - key: 'addValidationRuleCollection', - value: function addValidationRuleCollection(validationRulesCollection) { - this.validationCollections.push(validationRulesCollection); } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - this.isRequired = true; - } - }, { - key: 'withMessage', - value: function withMessage(message) { - if (this.validationRules.length === 0) this.isRequiredMessage = message;else this.validationRules[this.validationRules.length - 1].withMessage(message); + + var _loop2 = function (i) { + var validationCollection = _this.validationCollections[i]; + checks = checks.then(function (previousValidationResult) { + if (previousValidationResult.isValid) return validationCollection.validate(newValue, locale);else return previousValidationResult; + }); + }; + + for (var i = 0; i < this.validationCollections.length; i++) { + _loop2(i); } - }]); + + return checks; + }; + + ValidationRulesCollection.prototype.addValidationRule = function addValidationRule(validationRule) { + if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); + this.validationRules.push(validationRule); + }; + + ValidationRulesCollection.prototype.addValidationRuleCollection = function addValidationRuleCollection(validationRulesCollection) { + this.validationCollections.push(validationRulesCollection); + }; + + ValidationRulesCollection.prototype.isNotEmpty = function isNotEmpty() { + this.isRequired = true; + }; + + ValidationRulesCollection.prototype.withMessage = function withMessage(message) { + if (this.validationRules.length === 0) this.isRequiredMessage = message;else this.validationRules[this.validationRules.length - 1].withMessage(message); + }; return ValidationRulesCollection; })(); @@ -133,76 +122,66 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] this.defaultCaseLabel = { description: 'this is the case label for \'default\'' }; } - _createClass(SwitchCaseValidationRulesCollection, [{ - key: 'case', - value: function _case(caseLabel) { - this.caseLabel = caseLabel; - this.getCurrentCollection(caseLabel, true); - } - }, { - key: 'default', - value: function _default() { - this.caseLabel = this.defaultCaseLabel; - } - }, { - key: 'getCurrentCollection', - value: function getCurrentCollection(caseLabel) { - var createIfNotExists = arguments[1] === undefined ? false : arguments[1]; - - if (caseLabel === this.defaultCaseLabel) { - return this.defaultCollection; - }var currentCollection = null; - for (var i = 0; i < this.innerCollections.length; i++) { - currentCollection = this.innerCollections[i]; - if (currentCollection.caseLabel === caseLabel) { - return currentCollection.collection; - } - } - if (createIfNotExists) { - currentCollection = { - caseLabel: caseLabel, - collection: new ValidationRulesCollection() - }; - this.innerCollections.push(currentCollection); + SwitchCaseValidationRulesCollection.prototype['case'] = function _case(caseLabel) { + this.caseLabel = caseLabel; + this.getCurrentCollection(caseLabel, true); + }; + + SwitchCaseValidationRulesCollection.prototype['default'] = function _default() { + this.caseLabel = this.defaultCaseLabel; + }; + + SwitchCaseValidationRulesCollection.prototype.getCurrentCollection = function getCurrentCollection(caseLabel) { + var createIfNotExists = arguments[1] === undefined ? false : arguments[1]; + + if (caseLabel === this.defaultCaseLabel) { + return this.defaultCollection; + }var currentCollection = null; + for (var i = 0; i < this.innerCollections.length; i++) { + currentCollection = this.innerCollections[i]; + if (currentCollection.caseLabel === caseLabel) { return currentCollection.collection; } - return null; - } - }, { - key: 'validate', - value: function validate(newValue, locale) { - var collection = this.getCurrentCollection(this.conditionExpression(newValue)); - if (collection !== null) { - return collection.validate(newValue, locale); - } else { - return this.defaultCollection.validate(newValue, locale); - } - } - }, { - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - var currentCollection = this.getCurrentCollection(this.caseLabel, true); - currentCollection.addValidationRule(validationRule); } - }, { - key: 'addValidationRuleCollection', - value: function addValidationRuleCollection(validationRulesCollection) { - var currentCollection = this.getCurrentCollection(this.caseLabel, true); - currentCollection.addValidationRuleCollection(validationRulesCollection); - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - var collection = this.getCurrentCollection(this.caseLabel); - if (collection !== null) collection.isNotEmpty();else this.defaultCollection.isNotEmpty(); + if (createIfNotExists) { + currentCollection = { + caseLabel: caseLabel, + collection: new ValidationRulesCollection() + }; + this.innerCollections.push(currentCollection); + return currentCollection.collection; } - }, { - key: 'withMessage', - value: function withMessage(message) { - var collection = this.getCurrentCollection(this.caseLabel); - if (collection !== null) collection.withMessage(message);else this.defaultCollection.withMessage(message); + return null; + }; + + SwitchCaseValidationRulesCollection.prototype.validate = function validate(newValue, locale) { + var collection = this.getCurrentCollection(this.conditionExpression(newValue)); + if (collection !== null) { + return collection.validate(newValue, locale); + } else { + return this.defaultCollection.validate(newValue, locale); } - }]); + }; + + SwitchCaseValidationRulesCollection.prototype.addValidationRule = function addValidationRule(validationRule) { + var currentCollection = this.getCurrentCollection(this.caseLabel, true); + currentCollection.addValidationRule(validationRule); + }; + + SwitchCaseValidationRulesCollection.prototype.addValidationRuleCollection = function addValidationRuleCollection(validationRulesCollection) { + var currentCollection = this.getCurrentCollection(this.caseLabel, true); + currentCollection.addValidationRuleCollection(validationRulesCollection); + }; + + SwitchCaseValidationRulesCollection.prototype.isNotEmpty = function isNotEmpty() { + var collection = this.getCurrentCollection(this.caseLabel); + if (collection !== null) collection.isNotEmpty();else this.defaultCollection.isNotEmpty(); + }; + + SwitchCaseValidationRulesCollection.prototype.withMessage = function withMessage(message) { + var collection = this.getCurrentCollection(this.caseLabel); + if (collection !== null) collection.withMessage(message);else this.defaultCollection.withMessage(message); + }; return SwitchCaseValidationRulesCollection; })(); diff --git a/dist/amd/validation/validation-rules.js b/dist/amd/validation/validation-rules.js index 25bf6c57..fcecd45c 100644 --- a/dist/amd/validation/validation-rules.js +++ b/dist/amd/validation/validation-rules.js @@ -1,17 +1,11 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'], function (exports, _validationUtilities, _validationValidationLocale) { 'use strict'; - var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var ValidationRule = (function () { function ValidationRule(threshold, onValidate, message) { @@ -24,60 +18,54 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] this.ruleName = this.constructor.name; } - _createClass(ValidationRule, [{ - key: 'withMessage', - value: function withMessage(message) { - this.message = message; - } - }, { - key: 'explain', - value: function explain() { - return this.errorMessage; - } - }, { - key: 'setResult', - value: function setResult(result, currentValue, locale) { - if (result === true || result === undefined || result === null || result === '') { - this.errorMessage = null; - return true; + ValidationRule.prototype.withMessage = function withMessage(message) { + this.message = message; + }; + + ValidationRule.prototype.explain = function explain() { + return this.errorMessage; + }; + + ValidationRule.prototype.setResult = function setResult(result, currentValue, locale) { + if (result === true || result === undefined || result === null || result === '') { + this.errorMessage = null; + return true; + } else { + if (typeof result === 'string') { + this.errorMessage = result; } else { - if (typeof result === 'string') { - this.errorMessage = result; + if (this.message) { + if (typeof this.message === 'function') { + this.errorMessage = this.message(currentValue, this.threshold); + } else if (typeof this.message === 'string') { + this.errorMessage = this.message; + } else throw 'Unable to handle the error message:' + this.message; } else { - if (this.message) { - if (typeof this.message === 'function') { - this.errorMessage = this.message(currentValue, this.threshold); - } else if (typeof this.message === 'string') { - this.errorMessage = this.message; - } else throw 'Unable to handle the error message:' + this.message; - } else { - this.errorMessage = locale.translate(this.ruleName, currentValue, this.threshold); - } + this.errorMessage = locale.translate(this.ruleName, currentValue, this.threshold); } - return false; } + return false; } - }, { - key: 'validate', - value: function validate(currentValue, locale) { - var _this = this; - - if (locale === undefined) { - locale = _validationValidationLocale.ValidationLocale.Repository['default']; - } + }; - currentValue = _validationUtilities.Utilities.getValue(currentValue); - var result = this.onValidate(currentValue, this.threshold, locale); - var promise = Promise.resolve(result); + ValidationRule.prototype.validate = function validate(currentValue, locale) { + var _this = this; - var nextPromise = promise.then(function (promiseResult) { - return _this.setResult(promiseResult, currentValue, locale); - }, function (promiseFailure) { - if (typeof promiseFailure === 'string' && promiseFailure !== '') return _this.setResult(promiseFailure, currentValue, locale);else return _this.setResult(false, currentValue, locale); - }); - return nextPromise; + if (locale === undefined) { + locale = _validationValidationLocale.ValidationLocale.Repository['default']; } - }]); + + currentValue = _validationUtilities.Utilities.getValue(currentValue); + var result = this.onValidate(currentValue, this.threshold, locale); + var promise = Promise.resolve(result); + + var nextPromise = promise.then(function (promiseResult) { + return _this.setResult(promiseResult, currentValue, locale); + }, function (promiseFailure) { + if (typeof promiseFailure === 'string' && promiseFailure !== '') return _this.setResult(promiseFailure, currentValue, locale);else return _this.setResult(false, currentValue, locale); + }); + return nextPromise; + }; return ValidationRule; })(); @@ -90,7 +78,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] _classCallCheck(this, EmailValidationRule); - _get(Object.getPrototypeOf(EmailValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule.call(this, null, function (newValue, threshold) { if (/\s/.test(newValue)) { return false; } @@ -134,7 +122,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function MinimumLengthValidationRule(minimumLength) { _classCallCheck(this, MinimumLengthValidationRule); - _get(Object.getPrototypeOf(MinimumLengthValidationRule.prototype), 'constructor', this).call(this, minimumLength, function (newValue, minimumLength) { + _ValidationRule2.call(this, minimumLength, function (newValue, minimumLength) { return newValue.length !== undefined && newValue.length >= minimumLength; }); } @@ -150,7 +138,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function MaximumLengthValidationRule(maximumLength) { _classCallCheck(this, MaximumLengthValidationRule); - _get(Object.getPrototypeOf(MaximumLengthValidationRule.prototype), 'constructor', this).call(this, maximumLength, function (newValue, maximumLength) { + _ValidationRule3.call(this, maximumLength, function (newValue, maximumLength) { return newValue.length !== undefined && newValue.length <= maximumLength; }); } @@ -166,7 +154,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function BetweenLengthValidationRule(minimumLength, maximumLength) { _classCallCheck(this, BetweenLengthValidationRule); - _get(Object.getPrototypeOf(BetweenLengthValidationRule.prototype), 'constructor', this).call(this, { minimumLength: minimumLength, maximumLength: maximumLength }, function (newValue, threshold) { + _ValidationRule4.call(this, { minimumLength: minimumLength, maximumLength: maximumLength }, function (newValue, threshold) { return newValue.length !== undefined && newValue.length >= threshold.minimumLength && newValue.length <= threshold.maximumLength; }); } @@ -182,7 +170,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function CustomFunctionValidationRule(customFunction, threshold) { _classCallCheck(this, CustomFunctionValidationRule); - _get(Object.getPrototypeOf(CustomFunctionValidationRule.prototype), 'constructor', this).call(this, threshold, customFunction); + _ValidationRule5.call(this, threshold, customFunction); } _inherits(CustomFunctionValidationRule, _ValidationRule5); @@ -196,7 +184,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function NumericValidationRule() { _classCallCheck(this, NumericValidationRule); - _get(Object.getPrototypeOf(NumericValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold, locale) { + _ValidationRule6.call(this, null, function (newValue, threshold, locale) { var numericRegex = locale.setting('numericRegex'); var floatValue = parseFloat(newValue); return !Number.isNaN(parseFloat(floatValue)) && Number.isFinite(floatValue) && numericRegex.test(newValue); @@ -214,7 +202,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function RegexValidationRule(regex) { _classCallCheck(this, RegexValidationRule); - _get(Object.getPrototypeOf(RegexValidationRule.prototype), 'constructor', this).call(this, regex, function (newValue, regex) { + _ValidationRule7.call(this, regex, function (newValue, regex) { return regex.test(newValue); }); } @@ -230,7 +218,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function ContainsOnlyValidationRule(regex) { _classCallCheck(this, ContainsOnlyValidationRule); - _get(Object.getPrototypeOf(ContainsOnlyValidationRule.prototype), 'constructor', this).call(this, regex); + _RegexValidationRule.call(this, regex); } _inherits(ContainsOnlyValidationRule, _RegexValidationRule); @@ -244,7 +232,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function MinimumValueValidationRule(minimumValue) { _classCallCheck(this, MinimumValueValidationRule); - _get(Object.getPrototypeOf(MinimumValueValidationRule.prototype), 'constructor', this).call(this, minimumValue, function (newValue, minimumValue) { + _ValidationRule8.call(this, minimumValue, function (newValue, minimumValue) { return _validationUtilities.Utilities.getValue(minimumValue) < newValue; }); } @@ -260,7 +248,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function MinimumInclusiveValueValidationRule(minimumValue) { _classCallCheck(this, MinimumInclusiveValueValidationRule); - _get(Object.getPrototypeOf(MinimumInclusiveValueValidationRule.prototype), 'constructor', this).call(this, minimumValue, function (newValue, minimumValue) { + _ValidationRule9.call(this, minimumValue, function (newValue, minimumValue) { return _validationUtilities.Utilities.getValue(minimumValue) <= newValue; }); } @@ -276,7 +264,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function MaximumValueValidationRule(maximumValue) { _classCallCheck(this, MaximumValueValidationRule); - _get(Object.getPrototypeOf(MaximumValueValidationRule.prototype), 'constructor', this).call(this, maximumValue, function (newValue, maximumValue) { + _ValidationRule10.call(this, maximumValue, function (newValue, maximumValue) { return newValue < _validationUtilities.Utilities.getValue(maximumValue); }); } @@ -292,7 +280,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function MaximumInclusiveValueValidationRule(maximumValue) { _classCallCheck(this, MaximumInclusiveValueValidationRule); - _get(Object.getPrototypeOf(MaximumInclusiveValueValidationRule.prototype), 'constructor', this).call(this, maximumValue, function (newValue, maximumValue) { + _ValidationRule11.call(this, maximumValue, function (newValue, maximumValue) { return newValue <= _validationUtilities.Utilities.getValue(maximumValue); }); } @@ -308,7 +296,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function BetweenValueValidationRule(minimumValue, maximumValue) { _classCallCheck(this, BetweenValueValidationRule); - _get(Object.getPrototypeOf(BetweenValueValidationRule.prototype), 'constructor', this).call(this, { minimumValue: minimumValue, maximumValue: maximumValue }, function (newValue, threshold) { + _ValidationRule12.call(this, { minimumValue: minimumValue, maximumValue: maximumValue }, function (newValue, threshold) { return _validationUtilities.Utilities.getValue(threshold.minimumValue) <= newValue && newValue <= _validationUtilities.Utilities.getValue(threshold.maximumValue); }); } @@ -326,7 +314,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] _classCallCheck(this, DigitValidationRule); - _get(Object.getPrototypeOf(DigitValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule13.call(this, null, function (newValue, threshold) { return _this3.digitRegex.test(newValue); }); this.digitRegex = /^\d+$/; @@ -345,7 +333,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] _classCallCheck(this, AlphaNumericValidationRule); - _get(Object.getPrototypeOf(AlphaNumericValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule14.call(this, null, function (newValue, threshold) { return _this4.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z0-9]+$/i; @@ -364,7 +352,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] _classCallCheck(this, AlphaValidationRule); - _get(Object.getPrototypeOf(AlphaValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule15.call(this, null, function (newValue, threshold) { return _this5.alphaRegex.test(newValue); }); this.alphaRegex = /^[a-z]+$/i; @@ -383,7 +371,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] _classCallCheck(this, AlphaOrWhitespaceValidationRule); - _get(Object.getPrototypeOf(AlphaOrWhitespaceValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule16.call(this, null, function (newValue, threshold) { return _this6.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z\s]+$/i; @@ -402,7 +390,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] _classCallCheck(this, AlphaNumericOrWhitespaceValidationRule); - _get(Object.getPrototypeOf(AlphaNumericOrWhitespaceValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule17.call(this, null, function (newValue, threshold) { return _this7.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z0-9\s]+$/i; @@ -419,7 +407,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function MediumPasswordValidationRule(minimumComplexityLevel) { _classCallCheck(this, MediumPasswordValidationRule); - _get(Object.getPrototypeOf(MediumPasswordValidationRule.prototype), 'constructor', this).call(this, minimumComplexityLevel ? minimumComplexityLevel : 3, function (newValue, threshold) { + _ValidationRule18.call(this, minimumComplexityLevel ? minimumComplexityLevel : 3, function (newValue, threshold) { if (typeof newValue !== 'string') return false; var strength = 0; @@ -442,7 +430,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function StrongPasswordValidationRule() { _classCallCheck(this, StrongPasswordValidationRule); - _get(Object.getPrototypeOf(StrongPasswordValidationRule.prototype), 'constructor', this).call(this, 4); + _MediumPasswordValidationRule.call(this, 4); } _inherits(StrongPasswordValidationRule, _MediumPasswordValidationRule); @@ -456,7 +444,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function EqualityValidationRuleBase(otherValue, equality, otherValueLabel) { _classCallCheck(this, EqualityValidationRuleBase); - _get(Object.getPrototypeOf(EqualityValidationRuleBase.prototype), 'constructor', this).call(this, { + _ValidationRule19.call(this, { otherValue: otherValue, equality: equality, otherValueLabel: otherValueLabel @@ -478,7 +466,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function EqualityValidationRule(otherValue) { _classCallCheck(this, EqualityValidationRule); - _get(Object.getPrototypeOf(EqualityValidationRule.prototype), 'constructor', this).call(this, otherValue, true); + _EqualityValidationRuleBase.call(this, otherValue, true); } _inherits(EqualityValidationRule, _EqualityValidationRuleBase); @@ -492,7 +480,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function EqualityWithOtherLabelValidationRule(otherValue, otherLabel) { _classCallCheck(this, EqualityWithOtherLabelValidationRule); - _get(Object.getPrototypeOf(EqualityWithOtherLabelValidationRule.prototype), 'constructor', this).call(this, otherValue, true, otherLabel); + _EqualityValidationRuleBase2.call(this, otherValue, true, otherLabel); } _inherits(EqualityWithOtherLabelValidationRule, _EqualityValidationRuleBase2); @@ -506,7 +494,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function InEqualityValidationRule(otherValue) { _classCallCheck(this, InEqualityValidationRule); - _get(Object.getPrototypeOf(InEqualityValidationRule.prototype), 'constructor', this).call(this, otherValue, false); + _EqualityValidationRuleBase3.call(this, otherValue, false); } _inherits(InEqualityValidationRule, _EqualityValidationRuleBase3); @@ -520,7 +508,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function InEqualityWithOtherLabelValidationRule(otherValue, otherLabel) { _classCallCheck(this, InEqualityWithOtherLabelValidationRule); - _get(Object.getPrototypeOf(InEqualityWithOtherLabelValidationRule.prototype), 'constructor', this).call(this, otherValue, false, otherLabel); + _EqualityValidationRuleBase4.call(this, otherValue, false, otherLabel); } _inherits(InEqualityWithOtherLabelValidationRule, _EqualityValidationRuleBase4); @@ -534,7 +522,7 @@ define(['exports', '../validation/utilities', '../validation/validation-locale'] function InCollectionValidationRule(collection) { _classCallCheck(this, InCollectionValidationRule); - _get(Object.getPrototypeOf(InCollectionValidationRule.prototype), 'constructor', this).call(this, collection, function (newValue, threshold) { + _ValidationRule20.call(this, collection, function (newValue, threshold) { var collection = _validationUtilities.Utilities.getValue(threshold); for (var i = 0; i < collection.length; i++) { if (newValue === collection[i]) return true; diff --git a/dist/amd/validation/validation.js b/dist/amd/validation/validation.js index 2111ae5e..53d69116 100644 --- a/dist/amd/validation/validation.js +++ b/dist/amd/validation/validation.js @@ -3,11 +3,7 @@ define(['exports', 'aurelia-binding', '../validation/validation-rules', '../vali var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - Object.defineProperty(exports, '__esModule', { - value: true - }); + exports.__esModule = true; var Validation = (function () { function Validation(observerLocator, validationConfig) { @@ -17,23 +13,19 @@ define(['exports', 'aurelia-binding', '../validation/validation-rules', '../vali this.config = validationConfig ? validationConfig : Validation.defaults; } - _createClass(Validation, [{ - key: 'on', - value: function on(subject, configCallback) { - var conf = new _validationValidationConfig.ValidationConfig(this.config); - if (configCallback !== null && configCallback !== undefined && typeof configCallback === 'function') { - configCallback(conf); - } - return new _validationValidationGroup.ValidationGroup(subject, this.observerLocator, conf); - } - }, { - key: 'onBreezeEntity', - value: function onBreezeEntity(breezeEntity, configCallback) { - var validation = this.on(breezeEntity, configCallback); - validation.onBreezeEntity(); - return validation; + Validation.prototype.on = function on(subject, configCallback) { + var conf = new _validationValidationConfig.ValidationConfig(this.config); + if (configCallback !== null && configCallback !== undefined && typeof configCallback === 'function') { + configCallback(conf); } - }]); + return new _validationValidationGroup.ValidationGroup(subject, this.observerLocator, conf); + }; + + Validation.prototype.onBreezeEntity = function onBreezeEntity(breezeEntity, configCallback) { + var validation = this.on(breezeEntity, configCallback); + validation.onBreezeEntity(); + return validation; + }; var _Validation = Validation; Validation = _aureliaDependencyInjection.inject(_aureliaBinding.ObserverLocator)(Validation) || Validation; diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js index afc2b77e..202dfe8b 100644 --- a/dist/commonjs/index.js +++ b/dist/commonjs/index.js @@ -4,9 +4,7 @@ var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? ob var _defaults = function (obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; exports.configure = configure; var _ValidationConfig = require('./validation/validation-config'); @@ -15,27 +13,12 @@ var _Validation = require('./validation/validation'); var _Utilities = require('./validation/utilities'); -Object.defineProperty(exports, 'Utilities', { - enumerable: true, - get: function get() { - return _Utilities.Utilities; - } -}); -Object.defineProperty(exports, 'ValidationConfig', { - enumerable: true, - get: function get() { - return _ValidationConfig.ValidationConfig; - } -}); +exports.Utilities = _Utilities.Utilities; +exports.ValidationConfig = _ValidationConfig.ValidationConfig; var _ValidationLocale = require('./validation/validation-locale'); -Object.defineProperty(exports, 'ValidationLocale', { - enumerable: true, - get: function get() { - return _ValidationLocale.ValidationLocale; - } -}); +exports.ValidationLocale = _ValidationLocale.ValidationLocale; var _validationValidationResult = require('./validation/validation-result'); @@ -45,39 +28,19 @@ var _validationValidationRules = require('./validation/validation-rules'); _defaults(exports, _interopRequireWildcard(_validationValidationRules)); -Object.defineProperty(exports, 'Validation', { - enumerable: true, - get: function get() { - return _Validation.Validation; - } -}); +exports.Validation = _Validation.Validation; var _ValidateCustomAttribute = require('./validation/validate-custom-attribute'); -Object.defineProperty(exports, 'ValidateCustomAttribute', { - enumerable: true, - get: function get() { - return _ValidateCustomAttribute.ValidateCustomAttribute; - } -}); +exports.ValidateCustomAttribute = _ValidateCustomAttribute.ValidateCustomAttribute; var _ValidateCustomAttributeViewStrategy = require('./validation/validate-custom-attribute-view-strategy'); -Object.defineProperty(exports, 'ValidateCustomAttributeViewStrategy', { - enumerable: true, - get: function get() { - return _ValidateCustomAttributeViewStrategy.ValidateCustomAttributeViewStrategy; - } -}); +exports.ValidateCustomAttributeViewStrategy = _ValidateCustomAttributeViewStrategy.ValidateCustomAttributeViewStrategy; var _ensure = require('./validation/decorators'); -Object.defineProperty(exports, 'ensure', { - enumerable: true, - get: function get() { - return _ensure.ensure; - } -}); +exports.ensure = _ensure.ensure; function configure(aurelia, configCallback) { diff --git a/dist/commonjs/resources/de-DE.js b/dist/commonjs/resources/de-DE.js index 928b94c6..1a0ef27e 100644 --- a/dist/commonjs/resources/de-DE.js +++ b/dist/commonjs/resources/de-DE.js @@ -1,8 +1,6 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); diff --git a/dist/commonjs/resources/en-US.js b/dist/commonjs/resources/en-US.js index 7ccd14d7..06fbc343 100644 --- a/dist/commonjs/resources/en-US.js +++ b/dist/commonjs/resources/en-US.js @@ -1,8 +1,6 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); diff --git a/dist/commonjs/resources/es-MX.js b/dist/commonjs/resources/es-MX.js index 325ff2c1..a8b1a72d 100644 --- a/dist/commonjs/resources/es-MX.js +++ b/dist/commonjs/resources/es-MX.js @@ -1,8 +1,6 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); diff --git a/dist/commonjs/resources/fr-FR.js b/dist/commonjs/resources/fr-FR.js index bd4d607c..e2bad2ed 100644 --- a/dist/commonjs/resources/fr-FR.js +++ b/dist/commonjs/resources/fr-FR.js @@ -1,8 +1,6 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); diff --git a/dist/commonjs/resources/nl-BE.js b/dist/commonjs/resources/nl-BE.js index 4a2431f7..988c9910 100644 --- a/dist/commonjs/resources/nl-BE.js +++ b/dist/commonjs/resources/nl-BE.js @@ -1,8 +1,6 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); diff --git a/dist/commonjs/resources/nl-NL.js b/dist/commonjs/resources/nl-NL.js index 4a2431f7..988c9910 100644 --- a/dist/commonjs/resources/nl-NL.js +++ b/dist/commonjs/resources/nl-NL.js @@ -1,8 +1,6 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); diff --git a/dist/commonjs/resources/sv-SE.js b/dist/commonjs/resources/sv-SE.js index 7db1c0d6..3f424788 100644 --- a/dist/commonjs/resources/sv-SE.js +++ b/dist/commonjs/resources/sv-SE.js @@ -1,8 +1,6 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); diff --git a/dist/commonjs/resources/tr-TR.js b/dist/commonjs/resources/tr-TR.js index 3db0ee8d..5c778077 100644 --- a/dist/commonjs/resources/tr-TR.js +++ b/dist/commonjs/resources/tr-TR.js @@ -1,8 +1,6 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); diff --git a/dist/commonjs/validation/debouncer.js b/dist/commonjs/validation/debouncer.js index d2ba6904..b3d1862f 100644 --- a/dist/commonjs/validation/debouncer.js +++ b/dist/commonjs/validation/debouncer.js @@ -2,11 +2,7 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Validation = require('../validation/validation'); @@ -18,22 +14,19 @@ var Debouncer = (function () { this.debounceTimeout = debounceTimeout; } - _createClass(Debouncer, [{ - key: 'debounce', - value: function debounce(func) { - var _this = this; - - this.currentFunction = func; - setTimeout(function () { - if (func !== null && func !== undefined) { - if (func === _this.currentFunction) { - _this.currentFunction = null; - func(); - } + Debouncer.prototype.debounce = function debounce(func) { + var _this = this; + + this.currentFunction = func; + setTimeout(function () { + if (func !== null && func !== undefined) { + if (func === _this.currentFunction) { + _this.currentFunction = null; + func(); } - }, this.debounceTimeout); - } - }]); + } + }, this.debounceTimeout); + }; return Debouncer; })(); diff --git a/dist/commonjs/validation/decorators.js b/dist/commonjs/validation/decorators.js index c2269e64..cd69344e 100644 --- a/dist/commonjs/validation/decorators.js +++ b/dist/commonjs/validation/decorators.js @@ -2,11 +2,7 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, "__esModule", { - value: true -}); +exports.__esModule = true; exports.ensure = ensure; var ValidationMetadata = (function () { @@ -16,26 +12,22 @@ var ValidationMetadata = (function () { this.properties = []; } - _createClass(ValidationMetadata, [{ - key: "getOrCreateProperty", - value: function getOrCreateProperty(propertyName) { - var property = this.properties.find(function (x) { - return x.propertyName === propertyName; - }); - if (property === undefined) { - property = new ValidationPropertyMetadata(propertyName); - this.properties.push(property); - } - return property; - } - }, { - key: "setup", - value: function setup(validation) { - this.properties.forEach(function (property) { - property.setup(validation); - }); + ValidationMetadata.prototype.getOrCreateProperty = function getOrCreateProperty(propertyName) { + var property = this.properties.find(function (x) { + return x.propertyName === propertyName; + }); + if (property === undefined) { + property = new ValidationPropertyMetadata(propertyName); + this.properties.push(property); } - }]); + return property; + }; + + ValidationMetadata.prototype.setup = function setup(validation) { + this.properties.forEach(function (property) { + property.setup(validation); + }); + }; return ValidationMetadata; })(); @@ -48,20 +40,16 @@ var ValidationPropertyMetadata = (function () { this.setupSteps = []; } - _createClass(ValidationPropertyMetadata, [{ - key: "addSetupStep", - value: function addSetupStep(setupStep) { - this.setupSteps.push(setupStep); - } - }, { - key: "setup", - value: function setup(validation) { - validation.ensure(this.propertyName); - this.setupSteps.forEach(function (setupStep) { - setupStep(validation); - }); - } - }]); + ValidationPropertyMetadata.prototype.addSetupStep = function addSetupStep(setupStep) { + this.setupSteps.push(setupStep); + }; + + ValidationPropertyMetadata.prototype.setup = function setup(validation) { + validation.ensure(this.propertyName); + this.setupSteps.forEach(function (setupStep) { + setupStep(validation); + }); + }; return ValidationPropertyMetadata; })(); diff --git a/dist/commonjs/validation/path-observer.js b/dist/commonjs/validation/path-observer.js index c79cff3c..86e347d5 100644 --- a/dist/commonjs/validation/path-observer.js +++ b/dist/commonjs/validation/path-observer.js @@ -2,11 +2,7 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _ObserverLocator = require('aurelia-binding'); @@ -22,112 +18,105 @@ var PathObserver = (function () { if (this.path.length > 1) this.observeParts(); } - _createClass(PathObserver, [{ - key: 'observeParts', - value: function observeParts(propertyName) { - var _this = this; - - if (propertyName !== undefined && propertyName !== null) { - for (var i = this.observers.length - 1; i >= 0; i--) { - var currentObserver = this.observers[i]; - if (currentObserver.propertyName === propertyName) { - break; - } - var observer = this.observers.pop(); - if (observer && observer.subscription) { - observer.subscription(); - } + PathObserver.prototype.observeParts = function observeParts(propertyName) { + var _this = this; + + if (propertyName !== undefined && propertyName !== null) { + for (var i = this.observers.length - 1; i >= 0; i--) { + var currentObserver = this.observers[i]; + if (currentObserver.propertyName === propertyName) { + break; + } + var observer = this.observers.pop(); + if (observer && observer.subscription) { + observer.subscription(); } } + } - var currentSubject = this.subject; - - var observersAreComplete = this.observers.length === this.path.length; - - var _loop = function (i) { - var observer = _this.observers[i]; - if (!observer) { + var currentSubject = this.subject; - var currentPath = _this.path[i]; - observer = _this.observerLocator.getObserver(currentSubject, currentPath); - _this.observers.push(observer); - var subscription = observer.subscribe(function (newValue, oldValue) { - _this.observeParts(observer.propertyName); - }); - observer.subscription = subscription; - } + var observersAreComplete = this.observers.length === this.path.length; - var currentValue = observer.getValue(); - if (currentValue === undefined || currentValue === null) { - return 'break'; - } else { - currentSubject = currentValue; - } - }; + var _loop = function (i) { + var observer = _this.observers[i]; + if (!observer) { - for (var i = 0; i < this.path.length; i++) { - var _ret = _loop(i); - - if (_ret === 'break') break; + var currentPath = _this.path[i]; + observer = _this.observerLocator.getObserver(currentSubject, currentPath); + _this.observers.push(observer); + var subscription = observer.subscribe(function (newValue, oldValue) { + _this.observeParts(observer.propertyName); + }); + observer.subscription = subscription; } - if (!observersAreComplete && this.observers.length === this.path.length) { - var actualObserver = this.observers[this.observers.length - 1]; - for (var i = 0; i < this.callbacks.length; i++) { - actualObserver.subscribe(this.callbacks[i]); - } + var currentValue = observer.getValue(); + if (currentValue === undefined || currentValue === null) { + return 'break'; + } else { + currentSubject = currentValue; } + }; + + for (var i = 0; i < this.path.length; i++) { + var _ret = _loop(i); + + if (_ret === 'break') break; } - }, { - key: 'observePart', - value: function observePart(part) { - if (part !== this.path[this.path.length - 1]) { - this.observerParts(); + + if (!observersAreComplete && this.observers.length === this.path.length) { + var actualObserver = this.observers[this.observers.length - 1]; + for (var i = 0; i < this.callbacks.length; i++) { + actualObserver.subscribe(this.callbacks[i]); } } - }, { - key: 'getObserver', - value: function getObserver() { - if (this.path.length == 1) { - return this.observerLocator.getObserver(this.subject, this.path[0]); - }return this; + }; + + PathObserver.prototype.observePart = function observePart(part) { + if (part !== this.path[this.path.length - 1]) { + this.observerParts(); } - }, { - key: 'getValue', - value: function getValue() { - var expectedSubject = this.subject; - for (var i = 0; this.path.length; i++) { - var currentObserver = this.observers[i]; - if (currentObserver === null || currentObserver === undefined) { - this.observeParts(this.path[i]); - currentObserver = this.observers[i]; + }; + + PathObserver.prototype.getObserver = function getObserver() { + if (this.path.length == 1) { + return this.observerLocator.getObserver(this.subject, this.path[0]); + }return this; + }; + + PathObserver.prototype.getValue = function getValue() { + var expectedSubject = this.subject; + for (var i = 0; this.path.length; i++) { + var currentObserver = this.observers[i]; + if (currentObserver === null || currentObserver === undefined) { + this.observeParts(this.path[i]); + currentObserver = this.observers[i]; - if (currentObserver === null || currentObserver === undefined) { - break; - } + if (currentObserver === null || currentObserver === undefined) { + break; } - if (currentObserver.obj !== expectedSubject) { - this.observeParts(this.path[i - 1]); - break; - } - expectedSubject = currentObserver.getValue(); } + if (currentObserver.obj !== expectedSubject) { + this.observeParts(this.path[i - 1]); + break; + } + expectedSubject = currentObserver.getValue(); + } - if (this.observers.length !== this.path.length) { - return undefined; - } - var value = this.observers[this.observers.length - 1].getValue(); - return value; + if (this.observers.length !== this.path.length) { + return undefined; } - }, { - key: 'subscribe', - value: function subscribe(callback) { - this.callbacks.unshift(callback); - if (this.observers.length === this.path.length) { - return this.observers[this.observers.length - 1].subscribe(callback); - } + var value = this.observers[this.observers.length - 1].getValue(); + return value; + }; + + PathObserver.prototype.subscribe = function subscribe(callback) { + this.callbacks.unshift(callback); + if (this.observers.length === this.path.length) { + return this.observers[this.observers.length - 1].subscribe(callback); } - }]); + }; return PathObserver; })(); diff --git a/dist/commonjs/validation/utilities.js b/dist/commonjs/validation/utilities.js index c6b3fb8a..d0a78b41 100644 --- a/dist/commonjs/validation/utilities.js +++ b/dist/commonjs/validation/utilities.js @@ -2,51 +2,43 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var Utilities = (function () { function Utilities() { _classCallCheck(this, Utilities); } - _createClass(Utilities, null, [{ - key: 'getValue', - value: function getValue(val) { - if (val !== undefined && typeof val === 'function') { - return val(); - } - return val; + Utilities.getValue = function getValue(val) { + if (val !== undefined && typeof val === 'function') { + return val(); } - }, { - key: 'isEmptyValue', - value: function isEmptyValue(val) { - if (val === undefined) { - return true; - } - if (val === null) { - return true; - } - if (val === '') { - return true; - } - if (typeof val === 'string') { - if (String.prototype.trim) { - val = val.trim(); - } else { - val = val.replace(/^\s+|\s+$/g, ''); - } - } + return val; + }; - if (val.length !== undefined) { - return 0 === val.length; + Utilities.isEmptyValue = function isEmptyValue(val) { + if (val === undefined) { + return true; + } + if (val === null) { + return true; + } + if (val === '') { + return true; + } + if (typeof val === 'string') { + if (String.prototype.trim) { + val = val.trim(); + } else { + val = val.replace(/^\s+|\s+$/g, ''); } - return false; } - }]); + + if (val.length !== undefined) { + return 0 === val.length; + } + return false; + }; return Utilities; })(); diff --git a/dist/commonjs/validation/validate-custom-attribute-view-strategy.js b/dist/commonjs/validation/validate-custom-attribute-view-strategy.js index 3b1facb9..a0f5e46d 100644 --- a/dist/commonjs/validation/validate-custom-attribute-view-strategy.js +++ b/dist/commonjs/validation/validate-custom-attribute-view-strategy.js @@ -1,16 +1,10 @@ 'use strict'; -var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var ValidateCustomAttributeViewStrategyBase = (function () { function ValidateCustomAttributeViewStrategyBase() { @@ -19,37 +13,32 @@ var ValidateCustomAttributeViewStrategyBase = (function () { this.bindingPathAttributes = ['validate', 'value.bind', 'value.two-way']; } - _createClass(ValidateCustomAttributeViewStrategyBase, [{ - key: 'getValidationProperty', - value: function getValidationProperty(validation, element) { - var atts = element.attributes; - for (var i = 0; i < this.bindingPathAttributes.length; i++) { - var attributeName = this.bindingPathAttributes[i]; - if (atts[attributeName]) { - var bindingPath = atts[attributeName].value.trim(); - if (bindingPath.indexOf('|') != -1) bindingPath = bindingPath.split('|')[0].trim(); - var validationProperty = validation.result.properties[bindingPath]; - - if (attributeName == 'validate' && (validationProperty === null || validationProperty === undefined)) { - validation.ensure(bindingPath); - validationProperty = validation.result.properties[bindingPath]; - } - return validationProperty; + ValidateCustomAttributeViewStrategyBase.prototype.getValidationProperty = function getValidationProperty(validation, element) { + var atts = element.attributes; + for (var i = 0; i < this.bindingPathAttributes.length; i++) { + var attributeName = this.bindingPathAttributes[i]; + if (atts[attributeName]) { + var bindingPath = atts[attributeName].value.trim(); + if (bindingPath.indexOf('|') != -1) bindingPath = bindingPath.split('|')[0].trim(); + var validationProperty = validation.result.properties[bindingPath]; + + if (attributeName == 'validate' && (validationProperty === null || validationProperty === undefined)) { + validation.ensure(bindingPath); + validationProperty = validation.result.properties[bindingPath]; } + return validationProperty; } - return null; - } - }, { - key: 'prepareElement', - value: function prepareElement(validationProperty, element) { - throw Error('View strategy must implement prepareElement(validationProperty, element)'); } - }, { - key: 'updateElement', - value: function updateElement(validationProperty, element) { - throw Error('View strategy must implement updateElement(validationProperty, element)'); - } - }]); + return null; + }; + + ValidateCustomAttributeViewStrategyBase.prototype.prepareElement = function prepareElement(validationProperty, element) { + throw Error('View strategy must implement prepareElement(validationProperty, element)'); + }; + + ValidateCustomAttributeViewStrategyBase.prototype.updateElement = function updateElement(validationProperty, element) { + throw Error('View strategy must implement updateElement(validationProperty, element)'); + }; return ValidateCustomAttributeViewStrategyBase; })(); @@ -60,7 +49,7 @@ var TWBootstrapViewStrategy = (function (_ValidateCustomAttributeViewStrategyBas function TWBootstrapViewStrategy(appendMessageToInput, appendMessageToLabel, helpBlockClass) { _classCallCheck(this, TWBootstrapViewStrategy); - _get(Object.getPrototypeOf(TWBootstrapViewStrategy.prototype), 'constructor', this).call(this); + _ValidateCustomAttributeViewStrategyBase.call(this); this.appendMessageToInput = appendMessageToInput; this.appendMessageToLabel = appendMessageToLabel; this.helpBlockClass = helpBlockClass; @@ -68,103 +57,94 @@ var TWBootstrapViewStrategy = (function (_ValidateCustomAttributeViewStrategyBas _inherits(TWBootstrapViewStrategy, _ValidateCustomAttributeViewStrategyBase); - _createClass(TWBootstrapViewStrategy, [{ - key: 'searchFormGroup', - value: function searchFormGroup(currentElement, currentDepth) { - if (currentDepth === 5) { - return null; - } - if (currentElement.classList && currentElement.classList.contains('form-group')) { - return currentElement; - } - return this.searchFormGroup(currentElement.parentNode, 1 + currentDepth); + TWBootstrapViewStrategy.prototype.searchFormGroup = function searchFormGroup(currentElement, currentDepth) { + if (currentDepth === 5) { + return null; } - }, { - key: 'findLabels', - value: function findLabels(formGroup, inputId) { - var labels = []; - this.findLabelsRecursively(formGroup, inputId, labels, 0); - return labels; + if (currentElement.classList && currentElement.classList.contains('form-group')) { + return currentElement; + } + return this.searchFormGroup(currentElement.parentNode, 1 + currentDepth); + }; + + TWBootstrapViewStrategy.prototype.findLabels = function findLabels(formGroup, inputId) { + var labels = []; + this.findLabelsRecursively(formGroup, inputId, labels, 0); + return labels; + }; + + TWBootstrapViewStrategy.prototype.findLabelsRecursively = function findLabelsRecursively(currentElement, inputId, currentLabels, currentDepth) { + if (currentDepth === 5) { + return; + } + if (currentElement.nodeName === 'LABEL' && (currentElement.attributes['for'] && currentElement.attributes['for'].value === inputId || !currentElement.attributes['for'])) { + currentLabels.push(currentElement); } - }, { - key: 'findLabelsRecursively', - value: function findLabelsRecursively(currentElement, inputId, currentLabels, currentDepth) { - if (currentDepth === 5) { - return; - } - if (currentElement.nodeName === 'LABEL' && (currentElement.attributes['for'] && currentElement.attributes['for'].value === inputId || !currentElement.attributes['for'])) { - currentLabels.push(currentElement); - } - for (var i = 0; i < currentElement.children.length; i++) { - this.findLabelsRecursively(currentElement.children[i], inputId, currentLabels, 1 + currentDepth); - } + for (var i = 0; i < currentElement.children.length; i++) { + this.findLabelsRecursively(currentElement.children[i], inputId, currentLabels, 1 + currentDepth); } - }, { - key: 'appendMessageToElement', - value: function appendMessageToElement(element, validationProperty) { - var helpBlock = element.nextSibling; - if (helpBlock) { - if (!helpBlock.classList) { - helpBlock = null; - } else if (!helpBlock.classList.contains(this.helpBlockClass)) { - helpBlock = null; - } + }; + + TWBootstrapViewStrategy.prototype.appendMessageToElement = function appendMessageToElement(element, validationProperty) { + var helpBlock = element.nextSibling; + if (helpBlock) { + if (!helpBlock.classList) { + helpBlock = null; + } else if (!helpBlock.classList.contains(this.helpBlockClass)) { + helpBlock = null; } + } - if (!helpBlock) { - helpBlock = document.createElement('p'); - helpBlock.classList.add('help-block'); - helpBlock.classList.add(this.helpBlockClass); + if (!helpBlock) { + helpBlock = document.createElement('p'); + helpBlock.classList.add('help-block'); + helpBlock.classList.add(this.helpBlockClass); - if (element.nextSibling) { - element.parentNode.insertBefore(helpBlock, element.nextSibling); - } else { - element.parentNode.appendChild(helpBlock); - } + if (element.nextSibling) { + element.parentNode.insertBefore(helpBlock, element.nextSibling); + } else { + element.parentNode.appendChild(helpBlock); } - if (validationProperty) helpBlock.textContent = validationProperty.message;else helpBlock.textContent = ''; } - }, { - key: 'appendUIVisuals', - value: function appendUIVisuals(validationProperty, currentElement) { - var formGroup = this.searchFormGroup(currentElement, 0); - if (formGroup) { - if (validationProperty && validationProperty.isDirty) { - if (validationProperty.isValid) { - formGroup.classList.remove('has-warning'); - formGroup.classList.add('has-success'); - } else { - formGroup.classList.remove('has-success'); - formGroup.classList.add('has-warning'); - } - } else { + if (validationProperty) helpBlock.textContent = validationProperty.message;else helpBlock.textContent = ''; + }; + + TWBootstrapViewStrategy.prototype.appendUIVisuals = function appendUIVisuals(validationProperty, currentElement) { + var formGroup = this.searchFormGroup(currentElement, 0); + if (formGroup) { + if (validationProperty && validationProperty.isDirty) { + if (validationProperty.isValid) { formGroup.classList.remove('has-warning'); + formGroup.classList.add('has-success'); + } else { formGroup.classList.remove('has-success'); + formGroup.classList.add('has-warning'); } - if (this.appendMessageToInput) { - this.appendMessageToElement(currentElement, validationProperty); - } - if (this.appendMessageToLabel) { - var labels = this.findLabels(formGroup, currentElement.id); - for (var ii = 0; ii < labels.length; ii++) { - var label = labels[ii]; - this.appendMessageToElement(label, validationProperty); - } + } else { + formGroup.classList.remove('has-warning'); + formGroup.classList.remove('has-success'); + } + if (this.appendMessageToInput) { + this.appendMessageToElement(currentElement, validationProperty); + } + if (this.appendMessageToLabel) { + var labels = this.findLabels(formGroup, currentElement.id); + for (var ii = 0; ii < labels.length; ii++) { + var label = labels[ii]; + this.appendMessageToElement(label, validationProperty); } } } - }, { - key: 'prepareElement', - value: function prepareElement(validationProperty, element) { - this.appendUIVisuals(null, element); - } - }, { - key: 'updateElement', - value: function updateElement(validationProperty, element) { - this.appendUIVisuals(validationProperty, element); - } - }]); + }; + + TWBootstrapViewStrategy.prototype.prepareElement = function prepareElement(validationProperty, element) { + this.appendUIVisuals(null, element); + }; + + TWBootstrapViewStrategy.prototype.updateElement = function updateElement(validationProperty, element) { + this.appendUIVisuals(validationProperty, element); + }; return TWBootstrapViewStrategy; })(ValidateCustomAttributeViewStrategyBase); diff --git a/dist/commonjs/validation/validate-custom-attribute.js b/dist/commonjs/validation/validate-custom-attribute.js index 0930147b..64faf26d 100644 --- a/dist/commonjs/validation/validate-custom-attribute.js +++ b/dist/commonjs/validation/validate-custom-attribute.js @@ -2,11 +2,7 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _inject = require('aurelia-dependency-injection'); @@ -21,45 +17,39 @@ var ValidateCustomAttribute = (function () { this.viewStrategy = null; } - _createClass(ValidateCustomAttribute, [{ - key: 'valueChanged', - value: function valueChanged(newValue) { - if (this.value === null || this.value === undefined) { - return; - }this.processedValidation = this.value; - if (typeof this.value === 'string') { - return; - } else { - this.subscribeChangedHandlers(this.element); - } + ValidateCustomAttribute.prototype.valueChanged = function valueChanged(newValue) { + if (this.value === null || this.value === undefined) { + return; + }this.processedValidation = this.value; + if (typeof this.value === 'string') { + return; + } else { + this.subscribeChangedHandlers(this.element); } - }, { - key: 'subscribeChangedHandlers', - value: function subscribeChangedHandlers(currentElement) { - var _this = this; - - this.viewStrategy = this.value.config.getViewStrategy(); - var validationProperty = this.viewStrategy.getValidationProperty(this.value, currentElement); - if (validationProperty !== null && validationProperty !== undefined) { - this.viewStrategy.prepareElement(validationProperty, currentElement); - validationProperty.onValidate(function (vp) { - _this.viewStrategy.updateElement(vp, currentElement); - }); - } - var children = currentElement.children; - for (var i = 0; i < children.length; i++) { - this.subscribeChangedHandlers(children[i]); - } + }; + + ValidateCustomAttribute.prototype.subscribeChangedHandlers = function subscribeChangedHandlers(currentElement) { + var _this = this; + + this.viewStrategy = this.value.config.getViewStrategy(); + var validationProperty = this.viewStrategy.getValidationProperty(this.value, currentElement); + if (validationProperty !== null && validationProperty !== undefined) { + this.viewStrategy.prepareElement(validationProperty, currentElement); + validationProperty.onValidate(function (vp) { + _this.viewStrategy.updateElement(vp, currentElement); + }); } - }, { - key: 'detached', - value: function detached() {} - }, { - key: 'attached', - value: function attached() { - if (this.processedValidation === null || this.processedValidation === undefined) this.valueChanged(this.value); + var children = currentElement.children; + for (var i = 0; i < children.length; i++) { + this.subscribeChangedHandlers(children[i]); } - }]); + }; + + ValidateCustomAttribute.prototype.detached = function detached() {}; + + ValidateCustomAttribute.prototype.attached = function attached() { + if (this.processedValidation === null || this.processedValidation === undefined) this.valueChanged(this.value); + }; var _ValidateCustomAttribute = ValidateCustomAttribute; ValidateCustomAttribute = _customAttribute.customAttribute('validate')(ValidateCustomAttribute) || ValidateCustomAttribute; diff --git a/dist/commonjs/validation/validation-config.js b/dist/commonjs/validation/validation-config.js index 64f98bea..d113089a 100644 --- a/dist/commonjs/validation/validation-config.js +++ b/dist/commonjs/validation/validation-config.js @@ -1,12 +1,8 @@ 'use strict'; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _ValidationLocale = require('../validation/validation-locale'); @@ -40,97 +36,84 @@ var ValidationConfig = (function () { this.changedHandlers = new Map(); } - _createClass(ValidationConfig, [{ - key: 'getValue', - value: function getValue(identifier) { - if (this.values.hasOwnProperty(identifier) !== null && this.values[identifier] !== undefined) { - return this.values[identifier]; - } - if (this.innerConfig !== null) { - return this.innerConfig.getValue(identifier); - } - throw Error('Config not found: ' + identifier); - } - }, { - key: 'setValue', - value: function setValue(identifier, value) { - this.values[identifier] = value; - return this; - } - }, { - key: 'onLocaleChanged', - value: function onLocaleChanged(callback) { - var _this = this; - - if (this.innerConfig !== undefined) { - return this.innerConfig.onLocaleChanged(callback); - } else { - var _ret = (function () { - var id = ++ValidationConfig.uniqueListenerId; - _this.changedHandlers.set(id, callback); - return { - v: function () { - changedHandlers['delete'](id); - } - }; - })(); - - if (typeof _ret === 'object') { - return _ret.v; - } - } - } - }, { - key: 'getDebounceTimeout', - value: function getDebounceTimeout() { - return this.getValue('debounceTimeout'); - } - }, { - key: 'useDebounceTimeout', - value: function useDebounceTimeout(value) { - return this.setValue('debounceTimeout', value); - } - }, { - key: 'getDependencies', - value: function getDependencies() { - return this.getValue('dependencies'); + ValidationConfig.prototype.getValue = function getValue(identifier) { + if (this.values.hasOwnProperty(identifier) !== null && this.values[identifier] !== undefined) { + return this.values[identifier]; } - }, { - key: 'computedFrom', - value: function computedFrom(dependencies) { - var deps = dependencies; - if (typeof dependencies === 'string') { - deps = []; - deps.push(dependencies); - } - return this.setValue('dependencies', deps); + if (this.innerConfig !== null) { + return this.innerConfig.getValue(identifier); } - }, { - key: 'useLocale', - value: function useLocale(localeIdentifier) { - this.setValue('locale', localeIdentifier); - var callbacks = Array.from(this.changedHandlers.values()); - for (var i = 0; i < callbacks.length; i++) { - callbacks[i](); + throw Error('Config not found: ' + identifier); + }; + + ValidationConfig.prototype.setValue = function setValue(identifier, value) { + this.values[identifier] = value; + return this; + }; + + ValidationConfig.prototype.onLocaleChanged = function onLocaleChanged(callback) { + var _this = this; + + if (this.innerConfig !== undefined) { + return this.innerConfig.onLocaleChanged(callback); + } else { + var _ret = (function () { + var id = ++ValidationConfig.uniqueListenerId; + _this.changedHandlers.set(id, callback); + return { + v: function () { + changedHandlers['delete'](id); + } + }; + })(); + + if (typeof _ret === 'object') { + return _ret.v; } - return this; - } - }, { - key: 'locale', - value: function locale() { - return _ValidationLocale.ValidationLocale.Repository.load(this.getValue('locale'), this.getValue('localeResources')); } - }, { - key: 'useViewStrategy', - value: function useViewStrategy(viewStrategy) { - return this.setValue('viewStrategy', viewStrategy); + }; + + ValidationConfig.prototype.getDebounceTimeout = function getDebounceTimeout() { + return this.getValue('debounceTimeout'); + }; + + ValidationConfig.prototype.useDebounceTimeout = function useDebounceTimeout(value) { + return this.setValue('debounceTimeout', value); + }; + + ValidationConfig.prototype.getDependencies = function getDependencies() { + return this.getValue('dependencies'); + }; + + ValidationConfig.prototype.computedFrom = function computedFrom(dependencies) { + var deps = dependencies; + if (typeof dependencies === 'string') { + deps = []; + deps.push(dependencies); } - }, { - key: 'getViewStrategy', - value: function getViewStrategy() { - return this.getValue('viewStrategy'); + return this.setValue('dependencies', deps); + }; + + ValidationConfig.prototype.useLocale = function useLocale(localeIdentifier) { + this.setValue('locale', localeIdentifier); + var callbacks = Array.from(this.changedHandlers.values()); + for (var i = 0; i < callbacks.length; i++) { + callbacks[i](); } - }]); + return this; + }; + + ValidationConfig.prototype.locale = function locale() { + return _ValidationLocale.ValidationLocale.Repository.load(this.getValue('locale'), this.getValue('localeResources')); + }; + + ValidationConfig.prototype.useViewStrategy = function useViewStrategy(viewStrategy) { + return this.setValue('viewStrategy', viewStrategy); + }; + + ValidationConfig.prototype.getViewStrategy = function getViewStrategy() { + return this.getValue('viewStrategy'); + }; return ValidationConfig; })(); diff --git a/dist/commonjs/validation/validation-group-builder.js b/dist/commonjs/validation/validation-group-builder.js index 28890348..4b4adba7 100644 --- a/dist/commonjs/validation/validation-group-builder.js +++ b/dist/commonjs/validation/validation-group-builder.js @@ -4,11 +4,7 @@ var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? ob var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _import = require('../validation/validation-rules'); @@ -31,250 +27,214 @@ var ValidationGroupBuilder = (function () { this.validationGroup = validationGroup; } - _createClass(ValidationGroupBuilder, [{ - key: 'ensure', - value: function ensure(propertyName, configurationCallback) { - var newValidationProperty = null; - this.validationRuleCollections = []; - - for (var i = 0; i < this.validationGroup.validationProperties.length; i++) { - if (this.validationGroup.validationProperties[i].propertyName === propertyName) { - newValidationProperty = this.validationGroup.validationProperties[i]; - if (configurationCallback !== undefined && typeof configurationCallback === 'function') { - throw Error('When creating validation rules on binding path ' + propertyName + ' a configuration callback function was provided, but validation rules have previously already been instantiated for this binding path'); - } - break; - } - } - if (newValidationProperty === null) { - var propertyResult = this.validationGroup.result.addProperty(propertyName); - var config = new _ValidationConfig.ValidationConfig(this.validationGroup.config); + ValidationGroupBuilder.prototype.ensure = function ensure(propertyName, configurationCallback) { + var newValidationProperty = null; + this.validationRuleCollections = []; + + for (var i = 0; i < this.validationGroup.validationProperties.length; i++) { + if (this.validationGroup.validationProperties[i].propertyName === propertyName) { + newValidationProperty = this.validationGroup.validationProperties[i]; if (configurationCallback !== undefined && typeof configurationCallback === 'function') { - configurationCallback(config); + throw Error('When creating validation rules on binding path ' + propertyName + ' a configuration callback function was provided, but validation rules have previously already been instantiated for this binding path'); } - newValidationProperty = new _ValidationProperty.ValidationProperty(this.observerLocator, propertyName, this.validationGroup, propertyResult, config); - this.validationGroup.validationProperties.push(newValidationProperty); - } - this.validationRuleCollections.unshift(newValidationProperty.collectionOfValidationRules); - return this.validationGroup; - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - this.validationRuleCollections[0].isNotEmpty(); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'isGreaterThan', - value: function isGreaterThan(minimumValue) { - return this.passesRule(new AllRules.MinimumValueValidationRule(minimumValue)); - } - }, { - key: 'isGreaterThanOrEqualTo', - value: function isGreaterThanOrEqualTo(minimumValue) { - return this.passesRule(new AllRules.MinimumInclusiveValueValidationRule(minimumValue)); - } - }, { - key: 'isBetween', - value: function isBetween(minimumValue, maximumValue) { - return this.passesRule(new AllRules.BetweenValueValidationRule(minimumValue, maximumValue)); - } - }, { - key: 'isIn', - value: function isIn(collection) { - return this.passesRule(new AllRules.InCollectionValidationRule(collection)); - } - }, { - key: 'isLessThan', - value: function isLessThan(maximumValue) { - return this.passesRule(new AllRules.MaximumValueValidationRule(maximumValue)); - } - }, { - key: 'isLessThanOrEqualTo', - value: function isLessThanOrEqualTo(maximumValue) { - return this.passesRule(new AllRules.MaximumInclusiveValueValidationRule(maximumValue)); - } - }, { - key: 'isEqualTo', - value: function isEqualTo(otherValue, otherValueLabel) { - if (!otherValueLabel) { - return this.passesRule(new AllRules.EqualityValidationRule(otherValue)); - } else { - return this.passesRule(new AllRules.EqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); + break; } } - }, { - key: 'isNotEqualTo', - value: function isNotEqualTo(otherValue, otherValueLabel) { - if (!otherValueLabel) { - return this.passesRule(new AllRules.InEqualityValidationRule(otherValue)); - } else { - return this.passesRule(new AllRules.InEqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); + if (newValidationProperty === null) { + var propertyResult = this.validationGroup.result.addProperty(propertyName); + var config = new _ValidationConfig.ValidationConfig(this.validationGroup.config); + if (configurationCallback !== undefined && typeof configurationCallback === 'function') { + configurationCallback(config); } + newValidationProperty = new _ValidationProperty.ValidationProperty(this.observerLocator, propertyName, this.validationGroup, propertyResult, config); + this.validationGroup.validationProperties.push(newValidationProperty); } - }, { - key: 'isEmail', - value: function isEmail() { - return this.passesRule(new AllRules.EmailValidationRule()); - } - }, { - key: 'hasMinLength', - value: function hasMinLength(minimumValue) { - return this.passesRule(new AllRules.MinimumLengthValidationRule(minimumValue)); - } - }, { - key: 'hasMaxLength', - value: function hasMaxLength(maximumValue) { - return this.passesRule(new AllRules.MaximumLengthValidationRule(maximumValue)); - } - }, { - key: 'hasLengthBetween', - value: function hasLengthBetween(minimumValue, maximumValue) { - return this.passesRule(new AllRules.BetweenLengthValidationRule(minimumValue, maximumValue)); - } - }, { - key: 'isNumber', - value: function isNumber() { - return this.passesRule(new AllRules.NumericValidationRule()); - } - }, { - key: 'containsOnlyDigits', - value: function containsOnlyDigits() { - return this.passesRule(new AllRules.DigitValidationRule()); - } - }, { - key: 'containsOnlyAlpha', - value: function containsOnlyAlpha() { - return this.passesRule(new AllRules.AlphaValidationRule()); - } - }, { - key: 'containsOnlyAlphaOrWhitespace', - value: function containsOnlyAlphaOrWhitespace() { - return this.passesRule(new AllRules.AlphaOrWhitespaceValidationRule()); - } - }, { - key: 'containsOnlyAlphanumerics', - value: function containsOnlyAlphanumerics() { - return this.passesRule(new AllRules.AlphaNumericValidationRule()); - } - }, { - key: 'containsOnlyAlphanumericsOrWhitespace', - value: function containsOnlyAlphanumericsOrWhitespace() { - return this.passesRule(new AllRules.AlphaNumericOrWhitespaceValidationRule()); - } - }, { - key: 'isStrongPassword', - value: function isStrongPassword(minimumComplexityLevel) { - if (minimumComplexityLevel === 4) { - return this.passesRule(new AllRules.StrongPasswordValidationRule()); - } else { - return this.passesRule(new AllRules.MediumPasswordValidationRule(minimumComplexityLevel)); - } - } - }, { - key: 'containsOnly', - value: function containsOnly(regex) { - return this.passesRule(new AllRules.ContainsOnlyValidationRule(regex)); - } - }, { - key: 'matches', - value: function matches(regex) { - return this.passesRule(new AllRules.RegexValidationRule(regex)); - } - }, { - key: 'passes', - value: function passes(customFunction, threshold) { - return this.passesRule(new AllRules.CustomFunctionValidationRule(customFunction, threshold)); - } - }, { - key: 'passesRule', - value: function passesRule(validationRule) { + this.validationRuleCollections.unshift(newValidationProperty.collectionOfValidationRules); + return this.validationGroup; + }; - this.validationRuleCollections[0].addValidationRule(validationRule); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'checkLast', - value: function checkLast() { - var validationProperty = this.validationGroup.validationProperties[this.validationGroup.validationProperties.length - 1]; - validationProperty.validateCurrentValue(false); - } - }, { - key: 'withMessage', - value: function withMessage(message) { - this.validationRuleCollections[0].withMessage(message); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'if', - value: function _if(conditionExpression) { - var conditionalCollection = new AllCollections.SwitchCaseValidationRulesCollection(conditionExpression); - conditionalCollection['case'](true); - this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); - this.validationRuleCollections.unshift(conditionalCollection); - return this.validationGroup; - } - }, { - key: 'else', - value: function _else() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'else\''; + ValidationGroupBuilder.prototype.isNotEmpty = function isNotEmpty() { + this.validationRuleCollections[0].isNotEmpty(); + this.checkLast(); + return this.validationGroup; + }; - this.validationRuleCollections[0]['default'](); - return this.validationGroup; - } - }, { - key: 'endIf', - value: function endIf() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; - this.validationRuleCollections.shift(); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'switch', - value: function _switch(conditionExpression) { - var _this = this; - - var condition = conditionExpression; - if (condition === undefined) { - (function () { - var observer = _this.validationGroup.validationProperties[_this.validationGroup.validationProperties.length - 1].observer; - condition = function () { - return observer.getValue(); - }; - })(); - } - var conditionalCollection = new AllCollections.SwitchCaseValidationRulesCollection(condition); - this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); - this.validationRuleCollections.unshift(conditionalCollection); - return this.validationGroup; - } - }, { - key: 'case', - value: function _case(caseLabel) { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; - this.validationRuleCollections[0]['case'](caseLabel); - return this.validationGroup; - } - }, { - key: 'default', - value: function _default() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; - this.validationRuleCollections[0]['default'](); - return this.validationGroup; - } - }, { - key: 'endSwitch', - value: function endSwitch() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; - this.validationRuleCollections.shift(); - this.checkLast(); - return this.validationGroup; - } - }]); + ValidationGroupBuilder.prototype.isGreaterThan = function isGreaterThan(minimumValue) { + return this.passesRule(new AllRules.MinimumValueValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.isGreaterThanOrEqualTo = function isGreaterThanOrEqualTo(minimumValue) { + return this.passesRule(new AllRules.MinimumInclusiveValueValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.isBetween = function isBetween(minimumValue, maximumValue) { + return this.passesRule(new AllRules.BetweenValueValidationRule(minimumValue, maximumValue)); + }; + + ValidationGroupBuilder.prototype.isIn = function isIn(collection) { + return this.passesRule(new AllRules.InCollectionValidationRule(collection)); + }; + + ValidationGroupBuilder.prototype.isLessThan = function isLessThan(maximumValue) { + return this.passesRule(new AllRules.MaximumValueValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.isLessThanOrEqualTo = function isLessThanOrEqualTo(maximumValue) { + return this.passesRule(new AllRules.MaximumInclusiveValueValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.isEqualTo = function isEqualTo(otherValue, otherValueLabel) { + if (!otherValueLabel) { + return this.passesRule(new AllRules.EqualityValidationRule(otherValue)); + } else { + return this.passesRule(new AllRules.EqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); + } + }; + + ValidationGroupBuilder.prototype.isNotEqualTo = function isNotEqualTo(otherValue, otherValueLabel) { + if (!otherValueLabel) { + return this.passesRule(new AllRules.InEqualityValidationRule(otherValue)); + } else { + return this.passesRule(new AllRules.InEqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); + } + }; + + ValidationGroupBuilder.prototype.isEmail = function isEmail() { + return this.passesRule(new AllRules.EmailValidationRule()); + }; + + ValidationGroupBuilder.prototype.hasMinLength = function hasMinLength(minimumValue) { + return this.passesRule(new AllRules.MinimumLengthValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.hasMaxLength = function hasMaxLength(maximumValue) { + return this.passesRule(new AllRules.MaximumLengthValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.hasLengthBetween = function hasLengthBetween(minimumValue, maximumValue) { + return this.passesRule(new AllRules.BetweenLengthValidationRule(minimumValue, maximumValue)); + }; + + ValidationGroupBuilder.prototype.isNumber = function isNumber() { + return this.passesRule(new AllRules.NumericValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyDigits = function containsOnlyDigits() { + return this.passesRule(new AllRules.DigitValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlpha = function containsOnlyAlpha() { + return this.passesRule(new AllRules.AlphaValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphaOrWhitespace = function containsOnlyAlphaOrWhitespace() { + return this.passesRule(new AllRules.AlphaOrWhitespaceValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphanumerics = function containsOnlyAlphanumerics() { + return this.passesRule(new AllRules.AlphaNumericValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphanumericsOrWhitespace = function containsOnlyAlphanumericsOrWhitespace() { + return this.passesRule(new AllRules.AlphaNumericOrWhitespaceValidationRule()); + }; + + ValidationGroupBuilder.prototype.isStrongPassword = function isStrongPassword(minimumComplexityLevel) { + if (minimumComplexityLevel === 4) { + return this.passesRule(new AllRules.StrongPasswordValidationRule()); + } else { + return this.passesRule(new AllRules.MediumPasswordValidationRule(minimumComplexityLevel)); + } + }; + + ValidationGroupBuilder.prototype.containsOnly = function containsOnly(regex) { + return this.passesRule(new AllRules.ContainsOnlyValidationRule(regex)); + }; + + ValidationGroupBuilder.prototype.matches = function matches(regex) { + return this.passesRule(new AllRules.RegexValidationRule(regex)); + }; + + ValidationGroupBuilder.prototype.passes = function passes(customFunction, threshold) { + return this.passesRule(new AllRules.CustomFunctionValidationRule(customFunction, threshold)); + }; + + ValidationGroupBuilder.prototype.passesRule = function passesRule(validationRule) { + + this.validationRuleCollections[0].addValidationRule(validationRule); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.checkLast = function checkLast() { + var validationProperty = this.validationGroup.validationProperties[this.validationGroup.validationProperties.length - 1]; + validationProperty.validateCurrentValue(false); + }; + + ValidationGroupBuilder.prototype.withMessage = function withMessage(message) { + this.validationRuleCollections[0].withMessage(message); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['if'] = function _if(conditionExpression) { + var conditionalCollection = new AllCollections.SwitchCaseValidationRulesCollection(conditionExpression); + conditionalCollection['case'](true); + this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); + this.validationRuleCollections.unshift(conditionalCollection); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['else'] = function _else() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'else\''; + + this.validationRuleCollections[0]['default'](); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.endIf = function endIf() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; + this.validationRuleCollections.shift(); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['switch'] = function _switch(conditionExpression) { + var _this = this; + + var condition = conditionExpression; + if (condition === undefined) { + (function () { + var observer = _this.validationGroup.validationProperties[_this.validationGroup.validationProperties.length - 1].observer; + condition = function () { + return observer.getValue(); + }; + })(); + } + var conditionalCollection = new AllCollections.SwitchCaseValidationRulesCollection(condition); + this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); + this.validationRuleCollections.unshift(conditionalCollection); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['case'] = function _case(caseLabel) { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; + this.validationRuleCollections[0]['case'](caseLabel); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['default'] = function _default() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; + this.validationRuleCollections[0]['default'](); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.endSwitch = function endSwitch() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; + this.validationRuleCollections.shift(); + this.checkLast(); + return this.validationGroup; + }; return ValidationGroupBuilder; })(); diff --git a/dist/commonjs/validation/validation-group.js b/dist/commonjs/validation/validation-group.js index 9516d716..9ce8b88e 100644 --- a/dist/commonjs/validation/validation-group.js +++ b/dist/commonjs/validation/validation-group.js @@ -2,11 +2,7 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _ValidationGroupBuilder = require('../validation/validation-group-builder'); @@ -37,331 +33,288 @@ var ValidationGroup = (function () { } } - _createClass(ValidationGroup, [{ - key: 'destroy', - value: function destroy() { - this.onDestroy(); - } - }, { - key: 'clear', - value: function clear() { - this.validationProperties.forEach(function (prop) { - prop.clear(); - }); - this.result.clear(); - } - }, { - key: 'onBreezeEntity', - value: function onBreezeEntity() { - var _this2 = this; - - var breezeEntity = this.subject; - var me = this; - this.onPropertyValidate(function (propertyBindingPath) { - _this2.passes(function () { - breezeEntity.entityAspect.validateProperty(propertyBindingPath); - var errors = breezeEntity.entityAspect.getValidationErrors(propertyBindingPath); - if (errors.length === 0) return true;else return errors[0].errorMessage; - }); - }); - this.onValidate(function () { - breezeEntity.entityAspect.validateEntity(); - return {}; + ValidationGroup.prototype.destroy = function destroy() { + this.onDestroy(); + }; + + ValidationGroup.prototype.clear = function clear() { + this.validationProperties.forEach(function (prop) { + prop.clear(); + }); + this.result.clear(); + }; + + ValidationGroup.prototype.onBreezeEntity = function onBreezeEntity() { + var _this2 = this; + + var breezeEntity = this.subject; + var me = this; + this.onPropertyValidate(function (propertyBindingPath) { + _this2.passes(function () { + breezeEntity.entityAspect.validateProperty(propertyBindingPath); + var errors = breezeEntity.entityAspect.getValidationErrors(propertyBindingPath); + if (errors.length === 0) return true;else return errors[0].errorMessage; }); + }); + this.onValidate(function () { + breezeEntity.entityAspect.validateEntity(); + return {}; + }); - breezeEntity.entityAspect.validationErrorsChanged.subscribe(function () { - breezeEntity.entityAspect.getValidationErrors().forEach(function (validationError) { - var propertyName = validationError.propertyName; - if (!me.result.properties[propertyName]) { - me.ensure(propertyName); - } + breezeEntity.entityAspect.validationErrorsChanged.subscribe(function () { + breezeEntity.entityAspect.getValidationErrors().forEach(function (validationError) { + var propertyName = validationError.propertyName; + if (!me.result.properties[propertyName]) { + me.ensure(propertyName); + } - var currentResultProp = me.result.addProperty(propertyName); - if (currentResultProp.isValid) { + var currentResultProp = me.result.addProperty(propertyName); + if (currentResultProp.isValid) { - currentResultProp.setValidity({ - isValid: false, - message: validationError.errorMessage, - failingRule: 'breeze', - latestValue: currentResultProp.latestValue - }, true); - } - }); + currentResultProp.setValidity({ + isValid: false, + message: validationError.errorMessage, + failingRule: 'breeze', + latestValue: currentResultProp.latestValue + }, true); + } }); - } - }, { - key: 'validate', - value: function validate() { - var _this3 = this; + }); + }; - var forceDirty = arguments[0] === undefined ? true : arguments[0]; - var forceExecution = arguments[1] === undefined ? true : arguments[1]; + ValidationGroup.prototype.validate = function validate() { + var _this3 = this; - this.isValidating = true; - var promise = Promise.resolve(true); + var forceDirty = arguments[0] === undefined ? true : arguments[0]; + var forceExecution = arguments[1] === undefined ? true : arguments[1]; - var _loop = function (i) { - var validatorProperty = _this3.validationProperties[i]; - promise = promise.then(function () { - return validatorProperty.validateCurrentValue(forceDirty, forceExecution); - }); - }; + this.isValidating = true; + var promise = Promise.resolve(true); - for (var i = this.validationProperties.length - 1; i >= 0; i--) { - _loop(i); - } - promise = promise['catch'](function () { - console.log('Should never get here: a validation property should always resolve to true/false!'); - debugger; - throw Error('Should never get here: a validation property should always resolve to true/false!'); + var _loop = function (i) { + var validatorProperty = _this3.validationProperties[i]; + promise = promise.then(function () { + return validatorProperty.validateCurrentValue(forceDirty, forceExecution); }); + }; - this.onValidateCallbacks.forEach(function (onValidateCallback) { - promise = promise.then(function () { - return _this3.config.locale(); - }).then(function (locale) { - return Promise.resolve(onValidateCallback.validationFunction()).then(function (callbackResult) { - for (var prop in callbackResult) { - if (!_this3.result.properties[prop]) { - _this3.ensure(prop); + for (var i = this.validationProperties.length - 1; i >= 0; i--) { + _loop(i); + } + promise = promise['catch'](function () { + console.log('Should never get here: a validation property should always resolve to true/false!'); + debugger; + throw Error('Should never get here: a validation property should always resolve to true/false!'); + }); + + this.onValidateCallbacks.forEach(function (onValidateCallback) { + promise = promise.then(function () { + return _this3.config.locale(); + }).then(function (locale) { + return Promise.resolve(onValidateCallback.validationFunction()).then(function (callbackResult) { + for (var prop in callbackResult) { + if (!_this3.result.properties[prop]) { + _this3.ensure(prop); + } + var resultProp = _this3.result.addProperty(prop); + var result = callbackResult[prop]; + var newPropResult = { + latestValue: resultProp.latestValue + }; + if (result === true || result === null || result === '') { + if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { + newPropResult.failingRule = null; + newPropResult.message = ''; + newPropResult.isValid = true; + resultProp.setValidity(newPropResult, true); } - var resultProp = _this3.result.addProperty(prop); - var result = callbackResult[prop]; - var newPropResult = { - latestValue: resultProp.latestValue - }; - if (result === true || result === null || result === '') { - if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { - newPropResult.failingRule = null; - newPropResult.message = ''; - newPropResult.isValid = true; - resultProp.setValidity(newPropResult, true); - } - } else { - if (resultProp.isValid) { - newPropResult.failingRule = 'onValidateCallback'; - newPropResult.isValid = false; - if (typeof result === 'string') { - newPropResult.message = result; - } else { - newPropResult.message = locale.translate(newPropResult.failingRule); - } - resultProp.setValidity(newPropResult, true); + } else { + if (resultProp.isValid) { + newPropResult.failingRule = 'onValidateCallback'; + newPropResult.isValid = false; + if (typeof result === 'string') { + newPropResult.message = result; + } else { + newPropResult.message = locale.translate(newPropResult.failingRule); } + resultProp.setValidity(newPropResult, true); } } - _this3.result.checkValidity(); - }, function (a, b, c, d, e) { - debugger; - _this3.result.isValid = false; - if (onValidateCallback.validationFunctionFailedCallback) { - onValidateCallback.validationFunctionFailedCallback(a, b, c, d, e); - } - }); + } + _this3.result.checkValidity(); + }, function (a, b, c, d, e) { + debugger; + _this3.result.isValid = false; + if (onValidateCallback.validationFunctionFailedCallback) { + onValidateCallback.validationFunctionFailedCallback(a, b, c, d, e); + } }); }); - promise = promise.then(function () { - _this3.isValidating = false; - if (_this3.result.isValid) { - return Promise.resolve(_this3.result); - } else { - return Promise.reject(_this3.result); - } - }); - return promise; - } - }, { - key: 'onValidate', - value: function onValidate(validationFunction, validationFunctionFailedCallback) { - this.onValidateCallbacks.push({ validationFunction: validationFunction, validationFunctionFailedCallback: validationFunctionFailedCallback }); - return this; - } - }, { - key: 'onPropertyValidate', - value: function onPropertyValidate(validationFunction) { - this.onPropertyValidationCallbacks.push(validationFunction); - return this; - } - }, { - key: 'ensure', - value: function ensure(bindingPath, configCallback) { - this.builder.ensure(bindingPath, configCallback); - this.onPropertyValidationCallbacks.forEach(function (callback) { - callback(bindingPath); - }); - return this; - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - return this.builder.isNotEmpty(); - } - }, { - key: 'isGreaterThanOrEqualTo', - value: function isGreaterThanOrEqualTo(minimumValue) { - return this.builder.isGreaterThanOrEqualTo(minimumValue); - } - }, { - key: 'isGreaterThan', - value: function isGreaterThan(minimumValue) { - return this.builder.isGreaterThan(minimumValue); - } - }, { - key: 'isBetween', - value: function isBetween(minimumValue, maximumValue) { - return this.builder.isBetween(minimumValue, maximumValue); - } - }, { - key: 'isLessThanOrEqualTo', - value: function isLessThanOrEqualTo(maximumValue) { - return this.builder.isLessThanOrEqualTo(maximumValue); - } - }, { - key: 'isLessThan', - value: function isLessThan(maximumValue) { - return this.builder.isLessThan(maximumValue); - } - }, { - key: 'isEqualTo', - value: function isEqualTo(otherValue, otherValueLabel) { - return this.builder.isEqualTo(otherValue, otherValueLabel); - } - }, { - key: 'isNotEqualTo', - value: function isNotEqualTo(otherValue, otherValueLabel) { - return this.builder.isNotEqualTo(otherValue, otherValueLabel); - } - }, { - key: 'isEmail', - value: function isEmail() { - return this.builder.isEmail(); - } - }, { - key: 'isIn', - value: function isIn(collection) { - return this.builder.isIn(collection); - } - }, { - key: 'hasMinLength', - value: function hasMinLength(minimumValue) { - return this.builder.hasMinLength(minimumValue); - } - }, { - key: 'hasMaxLength', - value: function hasMaxLength(maximumValue) { - return this.builder.hasMaxLength(maximumValue); - } - }, { - key: 'hasLengthBetween', - value: function hasLengthBetween(minimumValue, maximumValue) { - return this.builder.hasLengthBetween(minimumValue, maximumValue); - } - }, { - key: 'isNumber', - value: function isNumber() { - return this.builder.isNumber(); - } - }, { - key: 'containsOnlyDigits', - value: function containsOnlyDigits() { - return this.builder.containsOnlyDigits(); - } - }, { - key: 'containsOnly', - value: function containsOnly(regex) { - return this.builder.containsOnly(regex); - } - }, { - key: 'containsOnlyAlpha', - value: function containsOnlyAlpha() { - return this.builder.containsOnlyAlpha(); - } - }, { - key: 'containsOnlyAlphaOrWhitespace', - value: function containsOnlyAlphaOrWhitespace() { - return this.builder.containsOnlyAlphaOrWhitespace(); - } - }, { - key: 'containsOnlyLetters', - value: function containsOnlyLetters() { - return this.builder.containsOnlyAlpha(); - } - }, { - key: 'containsOnlyLettersOrWhitespace', - value: function containsOnlyLettersOrWhitespace() { - return this.builder.containsOnlyAlphaOrWhitespace(); - } - }, { - key: 'containsOnlyAlphanumerics', - value: function containsOnlyAlphanumerics() { - return this.builder.containsOnlyAlphanumerics(); - } - }, { - key: 'containsOnlyAlphanumericsOrWhitespace', - value: function containsOnlyAlphanumericsOrWhitespace() { - return this.builder.containsOnlyAlphanumericsOrWhitespace(); - } - }, { - key: 'isStrongPassword', - value: function isStrongPassword(minimumComplexityLevel) { - return this.builder.isStrongPassword(minimumComplexityLevel); - } - }, { - key: 'matches', - value: function matches(regex) { - return this.builder.matches(regex); - } - }, { - key: 'passes', - value: function passes(customFunction, threshold) { - return this.builder.passes(customFunction, threshold); - } - }, { - key: 'passesRule', - value: function passesRule(validationRule) { - return this.builder.passesRule(validationRule); - } - }, { - key: 'if', - value: function _if(conditionExpression, threshold) { - return this.builder['if'](conditionExpression, threshold); - } - }, { - key: 'else', - value: function _else() { - return this.builder['else'](); - } - }, { - key: 'endIf', - value: function endIf() { - return this.builder.endIf(); - } - }, { - key: 'switch', - value: function _switch(conditionExpression) { - return this.builder['switch'](conditionExpression); - } - }, { - key: 'case', - value: function _case(caseLabel) { - return this.builder['case'](caseLabel); - } - }, { - key: 'default', - value: function _default() { - return this.builder['default'](); - } - }, { - key: 'endSwitch', - value: function endSwitch() { - return this.builder.endSwitch(); - } - }, { - key: 'withMessage', - value: function withMessage(message) { - return this.builder.withMessage(message); - } - }]); + }); + promise = promise.then(function () { + _this3.isValidating = false; + if (_this3.result.isValid) { + return Promise.resolve(_this3.result); + } else { + return Promise.reject(_this3.result); + } + }); + return promise; + }; + + ValidationGroup.prototype.onValidate = function onValidate(validationFunction, validationFunctionFailedCallback) { + this.onValidateCallbacks.push({ validationFunction: validationFunction, validationFunctionFailedCallback: validationFunctionFailedCallback }); + return this; + }; + + ValidationGroup.prototype.onPropertyValidate = function onPropertyValidate(validationFunction) { + this.onPropertyValidationCallbacks.push(validationFunction); + return this; + }; + + ValidationGroup.prototype.ensure = function ensure(bindingPath, configCallback) { + this.builder.ensure(bindingPath, configCallback); + this.onPropertyValidationCallbacks.forEach(function (callback) { + callback(bindingPath); + }); + return this; + }; + + ValidationGroup.prototype.isNotEmpty = function isNotEmpty() { + return this.builder.isNotEmpty(); + }; + + ValidationGroup.prototype.isGreaterThanOrEqualTo = function isGreaterThanOrEqualTo(minimumValue) { + return this.builder.isGreaterThanOrEqualTo(minimumValue); + }; + + ValidationGroup.prototype.isGreaterThan = function isGreaterThan(minimumValue) { + return this.builder.isGreaterThan(minimumValue); + }; + + ValidationGroup.prototype.isBetween = function isBetween(minimumValue, maximumValue) { + return this.builder.isBetween(minimumValue, maximumValue); + }; + + ValidationGroup.prototype.isLessThanOrEqualTo = function isLessThanOrEqualTo(maximumValue) { + return this.builder.isLessThanOrEqualTo(maximumValue); + }; + + ValidationGroup.prototype.isLessThan = function isLessThan(maximumValue) { + return this.builder.isLessThan(maximumValue); + }; + + ValidationGroup.prototype.isEqualTo = function isEqualTo(otherValue, otherValueLabel) { + return this.builder.isEqualTo(otherValue, otherValueLabel); + }; + + ValidationGroup.prototype.isNotEqualTo = function isNotEqualTo(otherValue, otherValueLabel) { + return this.builder.isNotEqualTo(otherValue, otherValueLabel); + }; + + ValidationGroup.prototype.isEmail = function isEmail() { + return this.builder.isEmail(); + }; + + ValidationGroup.prototype.isIn = function isIn(collection) { + return this.builder.isIn(collection); + }; + + ValidationGroup.prototype.hasMinLength = function hasMinLength(minimumValue) { + return this.builder.hasMinLength(minimumValue); + }; + + ValidationGroup.prototype.hasMaxLength = function hasMaxLength(maximumValue) { + return this.builder.hasMaxLength(maximumValue); + }; + + ValidationGroup.prototype.hasLengthBetween = function hasLengthBetween(minimumValue, maximumValue) { + return this.builder.hasLengthBetween(minimumValue, maximumValue); + }; + + ValidationGroup.prototype.isNumber = function isNumber() { + return this.builder.isNumber(); + }; + + ValidationGroup.prototype.containsOnlyDigits = function containsOnlyDigits() { + return this.builder.containsOnlyDigits(); + }; + + ValidationGroup.prototype.containsOnly = function containsOnly(regex) { + return this.builder.containsOnly(regex); + }; + + ValidationGroup.prototype.containsOnlyAlpha = function containsOnlyAlpha() { + return this.builder.containsOnlyAlpha(); + }; + + ValidationGroup.prototype.containsOnlyAlphaOrWhitespace = function containsOnlyAlphaOrWhitespace() { + return this.builder.containsOnlyAlphaOrWhitespace(); + }; + + ValidationGroup.prototype.containsOnlyLetters = function containsOnlyLetters() { + return this.builder.containsOnlyAlpha(); + }; + + ValidationGroup.prototype.containsOnlyLettersOrWhitespace = function containsOnlyLettersOrWhitespace() { + return this.builder.containsOnlyAlphaOrWhitespace(); + }; + + ValidationGroup.prototype.containsOnlyAlphanumerics = function containsOnlyAlphanumerics() { + return this.builder.containsOnlyAlphanumerics(); + }; + + ValidationGroup.prototype.containsOnlyAlphanumericsOrWhitespace = function containsOnlyAlphanumericsOrWhitespace() { + return this.builder.containsOnlyAlphanumericsOrWhitespace(); + }; + + ValidationGroup.prototype.isStrongPassword = function isStrongPassword(minimumComplexityLevel) { + return this.builder.isStrongPassword(minimumComplexityLevel); + }; + + ValidationGroup.prototype.matches = function matches(regex) { + return this.builder.matches(regex); + }; + + ValidationGroup.prototype.passes = function passes(customFunction, threshold) { + return this.builder.passes(customFunction, threshold); + }; + + ValidationGroup.prototype.passesRule = function passesRule(validationRule) { + return this.builder.passesRule(validationRule); + }; + + ValidationGroup.prototype['if'] = function _if(conditionExpression, threshold) { + return this.builder['if'](conditionExpression, threshold); + }; + + ValidationGroup.prototype['else'] = function _else() { + return this.builder['else'](); + }; + + ValidationGroup.prototype.endIf = function endIf() { + return this.builder.endIf(); + }; + + ValidationGroup.prototype['switch'] = function _switch(conditionExpression) { + return this.builder['switch'](conditionExpression); + }; + + ValidationGroup.prototype['case'] = function _case(caseLabel) { + return this.builder['case'](caseLabel); + }; + + ValidationGroup.prototype['default'] = function _default() { + return this.builder['default'](); + }; + + ValidationGroup.prototype.endSwitch = function endSwitch() { + return this.builder.endSwitch(); + }; + + ValidationGroup.prototype.withMessage = function withMessage(message) { + return this.builder.withMessage(message); + }; return ValidationGroup; })(); diff --git a/dist/commonjs/validation/validation-locale.js b/dist/commonjs/validation/validation-locale.js index 968efd3b..976ad6a7 100644 --- a/dist/commonjs/validation/validation-locale.js +++ b/dist/commonjs/validation/validation-locale.js @@ -2,11 +2,7 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var ValidationLocale = (function () { function ValidationLocale(defaults, data) { @@ -16,41 +12,36 @@ var ValidationLocale = (function () { this.currentLocale = data; } - _createClass(ValidationLocale, [{ - key: 'getValueFor', - value: function getValueFor(identifier, category) { - if (this.currentLocale && this.currentLocale[category]) { - var currentLocaleSetting = this.currentLocale[category][identifier]; - if (currentLocaleSetting !== undefined && currentLocaleSetting !== null) { - return currentLocaleSetting; - } + ValidationLocale.prototype.getValueFor = function getValueFor(identifier, category) { + if (this.currentLocale && this.currentLocale[category]) { + var currentLocaleSetting = this.currentLocale[category][identifier]; + if (currentLocaleSetting !== undefined && currentLocaleSetting !== null) { + return currentLocaleSetting; } - if (this.defaults[category]) { - var defaultSetting = this.defaults[category][identifier]; - if (defaultSetting !== undefined && defaultSetting !== null) { - return defaultSetting; - } + } + if (this.defaults[category]) { + var defaultSetting = this.defaults[category][identifier]; + if (defaultSetting !== undefined && defaultSetting !== null) { + return defaultSetting; } - throw 'validation: I18N: Could not find: ' + identifier + ' in category: ' + category; } - }, { - key: 'setting', - value: function setting(settingIdentifier) { - return this.getValueFor(settingIdentifier, 'settings'); + throw 'validation: I18N: Could not find: ' + identifier + ' in category: ' + category; + }; + + ValidationLocale.prototype.setting = function setting(settingIdentifier) { + return this.getValueFor(settingIdentifier, 'settings'); + }; + + ValidationLocale.prototype.translate = function translate(translationIdentifier, newValue, threshold) { + var translation = this.getValueFor(translationIdentifier, 'messages'); + if (typeof translation === 'function') { + return translation(newValue, threshold); } - }, { - key: 'translate', - value: function translate(translationIdentifier, newValue, threshold) { - var translation = this.getValueFor(translationIdentifier, 'messages'); - if (typeof translation === 'function') { - return translation(newValue, threshold); - } - if (typeof translation === 'string') { - return translation; - } - throw 'Validation message for ' + translationIdentifier + 'was in an unsupported format'; + if (typeof translation === 'string') { + return translation; } - }]); + throw 'Validation message for ' + translationIdentifier + 'was in an unsupported format'; + }; return ValidationLocale; })(); @@ -71,33 +62,29 @@ var ValidationLocaleRepository = (function () { }; } - _createClass(ValidationLocaleRepository, [{ - key: 'load', - value: function load(localeIdentifier, basePath) { - var _this = this; + ValidationLocaleRepository.prototype.load = function load(localeIdentifier, basePath) { + var _this = this; - if (!basePath) basePath = 'aurelia-validation/resources/'; - return new Promise(function (resolve, reject) { - if (_this.instances.has(localeIdentifier)) { - var locale = _this.instances.get(localeIdentifier); + if (!basePath) basePath = 'aurelia-validation/resources/'; + return new Promise(function (resolve, reject) { + if (_this.instances.has(localeIdentifier)) { + var locale = _this.instances.get(localeIdentifier); + resolve(locale); + } else { + System['import'](basePath + localeIdentifier).then(function (resource) { + var locale = _this.addLocale(localeIdentifier, resource.data); resolve(locale); - } else { - System['import'](basePath + localeIdentifier).then(function (resource) { - var locale = _this.addLocale(localeIdentifier, resource.data); - resolve(locale); - }); - } - }); - } - }, { - key: 'addLocale', - value: function addLocale(localeIdentifier, data) { - var instance = new ValidationLocale(this.defaults, data); - this.instances.set(localeIdentifier, instance); - if (this['default'] === null) this['default'] = instance; - return instance; - } - }]); + }); + } + }); + }; + + ValidationLocaleRepository.prototype.addLocale = function addLocale(localeIdentifier, data) { + var instance = new ValidationLocale(this.defaults, data); + this.instances.set(localeIdentifier, instance); + if (this['default'] === null) this['default'] = instance; + return instance; + }; return ValidationLocaleRepository; })(); diff --git a/dist/commonjs/validation/validation-property.js b/dist/commonjs/validation/validation-property.js index 02244a81..d2f9b92a 100644 --- a/dist/commonjs/validation/validation-property.js +++ b/dist/commonjs/validation/validation-property.js @@ -4,11 +4,7 @@ var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? ob var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _import = require('../validation/validation-rules-collection'); @@ -57,46 +53,40 @@ var ValidationProperty = (function () { } } - _createClass(ValidationProperty, [{ - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); - this.collectionOfValidationRules.addValidationRule(validationRule); - this.validateCurrentValue(false); - } - }, { - key: 'validateCurrentValue', - value: function validateCurrentValue(forceDirty, forceExecution) { - return this.validate(this.observer.getValue(), forceDirty, forceExecution); - } - }, { - key: 'clear', - value: function clear() { - this.latestValue = this.observer.getValue(); - this.propertyResult.clear(); - } - }, { - key: 'validate', - value: function validate(newValue, shouldBeDirty, forceExecution) { - var _this2 = this; - - if (!this.propertyResult.isDirty && shouldBeDirty || this.latestValue !== newValue || forceExecution) { - this.latestValue = newValue; - return this.config.locale().then(function (locale) { - return _this2.collectionOfValidationRules.validate(newValue, locale).then(function (validationResponse) { - if (_this2.latestValue === validationResponse.latestValue) _this2.propertyResult.setValidity(validationResponse, shouldBeDirty); - return validationResponse.isValid; - })['catch'](function (err) { - console.log('Unexpected behavior: a validation-rules-collection should always fulfil', err); - debugger; - throw Error('Unexpected behavior: a validation-rules-collection should always fulfil'); - }); - }, function () { - throw Error('An exception occurred while trying to load the locale'); + ValidationProperty.prototype.addValidationRule = function addValidationRule(validationRule) { + if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); + this.collectionOfValidationRules.addValidationRule(validationRule); + this.validateCurrentValue(false); + }; + + ValidationProperty.prototype.validateCurrentValue = function validateCurrentValue(forceDirty, forceExecution) { + return this.validate(this.observer.getValue(), forceDirty, forceExecution); + }; + + ValidationProperty.prototype.clear = function clear() { + this.latestValue = this.observer.getValue(); + this.propertyResult.clear(); + }; + + ValidationProperty.prototype.validate = function validate(newValue, shouldBeDirty, forceExecution) { + var _this2 = this; + + if (!this.propertyResult.isDirty && shouldBeDirty || this.latestValue !== newValue || forceExecution) { + this.latestValue = newValue; + return this.config.locale().then(function (locale) { + return _this2.collectionOfValidationRules.validate(newValue, locale).then(function (validationResponse) { + if (_this2.latestValue === validationResponse.latestValue) _this2.propertyResult.setValidity(validationResponse, shouldBeDirty); + return validationResponse.isValid; + })['catch'](function (err) { + console.log('Unexpected behavior: a validation-rules-collection should always fulfil', err); + debugger; + throw Error('Unexpected behavior: a validation-rules-collection should always fulfil'); }); - } + }, function () { + throw Error('An exception occurred while trying to load the locale'); + }); } - }]); + }; return ValidationProperty; })(); diff --git a/dist/commonjs/validation/validation-result.js b/dist/commonjs/validation/validation-result.js index 5c6ac55d..7846133a 100644 --- a/dist/commonjs/validation/validation-result.js +++ b/dist/commonjs/validation/validation-result.js @@ -2,11 +2,7 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var ValidationResult = (function () { function ValidationResult() { @@ -16,31 +12,26 @@ var ValidationResult = (function () { this.properties = {}; } - _createClass(ValidationResult, [{ - key: 'addProperty', - value: function addProperty(name) { - if (!this.properties[name]) { - this.properties[name] = new ValidationResultProperty(this); - } - return this.properties[name]; + ValidationResult.prototype.addProperty = function addProperty(name) { + if (!this.properties[name]) { + this.properties[name] = new ValidationResultProperty(this); } - }, { - key: 'checkValidity', - value: function checkValidity() { - for (var propertyName in this.properties) { - if (!this.properties[propertyName].isValid) { - this.isValid = false; - return; - } + return this.properties[name]; + }; + + ValidationResult.prototype.checkValidity = function checkValidity() { + for (var propertyName in this.properties) { + if (!this.properties[propertyName].isValid) { + this.isValid = false; + return; } - this.isValid = true; } - }, { - key: 'clear', - value: function clear() { - this.isValid = true; - } - }]); + this.isValid = true; + }; + + ValidationResult.prototype.clear = function clear() { + this.isValid = true; + }; return ValidationResult; })(); @@ -56,46 +47,40 @@ var ValidationResultProperty = (function () { this.clear(); } - _createClass(ValidationResultProperty, [{ - key: 'clear', - value: function clear() { - this.isValid = true; - this.isDirty = false; - this.message = ''; - this.failingRule = null; - this.latestValue = null; - this.notifyObserversOfChange(); - } - }, { - key: 'onValidate', - value: function onValidate(onValidateCallback) { - this.onValidateCallbacks.push(onValidateCallback); - } - }, { - key: 'notifyObserversOfChange', - value: function notifyObserversOfChange() { - for (var i = 0; i < this.onValidateCallbacks.length; i++) { - var callback = this.onValidateCallbacks[i]; - callback(this); - } + ValidationResultProperty.prototype.clear = function clear() { + this.isValid = true; + this.isDirty = false; + this.message = ''; + this.failingRule = null; + this.latestValue = null; + this.notifyObserversOfChange(); + }; + + ValidationResultProperty.prototype.onValidate = function onValidate(onValidateCallback) { + this.onValidateCallbacks.push(onValidateCallback); + }; + + ValidationResultProperty.prototype.notifyObserversOfChange = function notifyObserversOfChange() { + for (var i = 0; i < this.onValidateCallbacks.length; i++) { + var callback = this.onValidateCallbacks[i]; + callback(this); } - }, { - key: 'setValidity', - value: function setValidity(validationResponse, shouldBeDirty) { - var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; - - if (shouldBeDirty) this.isDirty = true; - this.message = validationResponse.message; - this.failingRule = validationResponse.failingRule; - this.isValid = validationResponse.isValid; - this.latestValue = validationResponse.latestValue; - if (this.isValid !== this.group.isValid) this.group.checkValidity(); - - if (notifyObservers) { - this.notifyObserversOfChange(); - } + }; + + ValidationResultProperty.prototype.setValidity = function setValidity(validationResponse, shouldBeDirty) { + var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; + + if (shouldBeDirty) this.isDirty = true; + this.message = validationResponse.message; + this.failingRule = validationResponse.failingRule; + this.isValid = validationResponse.isValid; + this.latestValue = validationResponse.latestValue; + if (this.isValid !== this.group.isValid) this.group.checkValidity(); + + if (notifyObservers) { + this.notifyObserversOfChange(); } - }]); + }; return ValidationResultProperty; })(); diff --git a/dist/commonjs/validation/validation-rules-collection.js b/dist/commonjs/validation/validation-rules-collection.js index 84d7008a..3384ea86 100644 --- a/dist/commonjs/validation/validation-rules-collection.js +++ b/dist/commonjs/validation/validation-rules-collection.js @@ -2,11 +2,7 @@ var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); @@ -22,103 +18,96 @@ var ValidationRulesCollection = (function () { this.isRequiredMessage = null; } - _createClass(ValidationRulesCollection, [{ - key: 'validate', - value: function validate(newValue, locale) { - var _this = this; + ValidationRulesCollection.prototype.validate = function validate(newValue, locale) { + var _this = this; - if (locale === undefined) { - locale = _ValidationLocale.ValidationLocale.Repository['default']; - } - newValue = _Utilities.Utilities.getValue(newValue); - var executeRules = true; - - if (_Utilities.Utilities.isEmptyValue(newValue)) { - if (this.isRequired) { - return Promise.resolve({ - isValid: false, - message: this.isRequiredMessage ? typeof this.isRequiredMessage === 'function' ? this.isRequiredMessage(newValue) : this.isRequiredMessage : locale.translate('isRequired'), - failingRule: 'isRequired', - latestValue: newValue - }); - } else { - executeRules = false; - } + if (locale === undefined) { + locale = _ValidationLocale.ValidationLocale.Repository['default']; + } + newValue = _Utilities.Utilities.getValue(newValue); + var executeRules = true; + + if (_Utilities.Utilities.isEmptyValue(newValue)) { + if (this.isRequired) { + return Promise.resolve({ + isValid: false, + message: this.isRequiredMessage ? typeof this.isRequiredMessage === 'function' ? this.isRequiredMessage(newValue) : this.isRequiredMessage : locale.translate('isRequired'), + failingRule: 'isRequired', + latestValue: newValue + }); + } else { + executeRules = false; } + } - var checks = Promise.resolve({ - isValid: true, - message: '', - failingRule: null, - latestValue: newValue - }); - - if (executeRules) { - var _loop = function (i) { - var rule = _this.validationRules[i]; - checks = checks.then(function (previousRuleResult) { - if (previousRuleResult.isValid === false) { - return previousRuleResult; - } else { - return rule.validate(newValue, locale).then(function (thisRuleResult) { - if (thisRuleResult === false) { - return { - isValid: false, - message: rule.explain(), - failingRule: rule.ruleName, - latestValue: newValue - }; - } else { - if (!previousRuleResult.isValid) { - throw Error('ValidationRulesCollection.validate caught an unexpected result while validating it\'s chain of rules.'); - } - return previousRuleResult; + var checks = Promise.resolve({ + isValid: true, + message: '', + failingRule: null, + latestValue: newValue + }); + + if (executeRules) { + var _loop = function (i) { + var rule = _this.validationRules[i]; + checks = checks.then(function (previousRuleResult) { + if (previousRuleResult.isValid === false) { + return previousRuleResult; + } else { + return rule.validate(newValue, locale).then(function (thisRuleResult) { + if (thisRuleResult === false) { + return { + isValid: false, + message: rule.explain(), + failingRule: rule.ruleName, + latestValue: newValue + }; + } else { + if (!previousRuleResult.isValid) { + throw Error('ValidationRulesCollection.validate caught an unexpected result while validating it\'s chain of rules.'); } - }); - } - }); - }; - - for (var i = 0; i < this.validationRules.length; i++) { - _loop(i); - } - } - - var _loop2 = function (i) { - var validationCollection = _this.validationCollections[i]; - checks = checks.then(function (previousValidationResult) { - if (previousValidationResult.isValid) return validationCollection.validate(newValue, locale);else return previousValidationResult; + return previousRuleResult; + } + }); + } }); }; - for (var i = 0; i < this.validationCollections.length; i++) { - _loop2(i); + for (var i = 0; i < this.validationRules.length; i++) { + _loop(i); } - - return checks; - } - }, { - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); - this.validationRules.push(validationRule); - } - }, { - key: 'addValidationRuleCollection', - value: function addValidationRuleCollection(validationRulesCollection) { - this.validationCollections.push(validationRulesCollection); } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - this.isRequired = true; - } - }, { - key: 'withMessage', - value: function withMessage(message) { - if (this.validationRules.length === 0) this.isRequiredMessage = message;else this.validationRules[this.validationRules.length - 1].withMessage(message); + + var _loop2 = function (i) { + var validationCollection = _this.validationCollections[i]; + checks = checks.then(function (previousValidationResult) { + if (previousValidationResult.isValid) return validationCollection.validate(newValue, locale);else return previousValidationResult; + }); + }; + + for (var i = 0; i < this.validationCollections.length; i++) { + _loop2(i); } - }]); + + return checks; + }; + + ValidationRulesCollection.prototype.addValidationRule = function addValidationRule(validationRule) { + if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); + this.validationRules.push(validationRule); + }; + + ValidationRulesCollection.prototype.addValidationRuleCollection = function addValidationRuleCollection(validationRulesCollection) { + this.validationCollections.push(validationRulesCollection); + }; + + ValidationRulesCollection.prototype.isNotEmpty = function isNotEmpty() { + this.isRequired = true; + }; + + ValidationRulesCollection.prototype.withMessage = function withMessage(message) { + if (this.validationRules.length === 0) this.isRequiredMessage = message;else this.validationRules[this.validationRules.length - 1].withMessage(message); + }; return ValidationRulesCollection; })(); @@ -136,76 +125,66 @@ var SwitchCaseValidationRulesCollection = (function () { this.defaultCaseLabel = { description: 'this is the case label for \'default\'' }; } - _createClass(SwitchCaseValidationRulesCollection, [{ - key: 'case', - value: function _case(caseLabel) { - this.caseLabel = caseLabel; - this.getCurrentCollection(caseLabel, true); - } - }, { - key: 'default', - value: function _default() { - this.caseLabel = this.defaultCaseLabel; - } - }, { - key: 'getCurrentCollection', - value: function getCurrentCollection(caseLabel) { - var createIfNotExists = arguments[1] === undefined ? false : arguments[1]; - - if (caseLabel === this.defaultCaseLabel) { - return this.defaultCollection; - }var currentCollection = null; - for (var i = 0; i < this.innerCollections.length; i++) { - currentCollection = this.innerCollections[i]; - if (currentCollection.caseLabel === caseLabel) { - return currentCollection.collection; - } - } - if (createIfNotExists) { - currentCollection = { - caseLabel: caseLabel, - collection: new ValidationRulesCollection() - }; - this.innerCollections.push(currentCollection); + SwitchCaseValidationRulesCollection.prototype['case'] = function _case(caseLabel) { + this.caseLabel = caseLabel; + this.getCurrentCollection(caseLabel, true); + }; + + SwitchCaseValidationRulesCollection.prototype['default'] = function _default() { + this.caseLabel = this.defaultCaseLabel; + }; + + SwitchCaseValidationRulesCollection.prototype.getCurrentCollection = function getCurrentCollection(caseLabel) { + var createIfNotExists = arguments[1] === undefined ? false : arguments[1]; + + if (caseLabel === this.defaultCaseLabel) { + return this.defaultCollection; + }var currentCollection = null; + for (var i = 0; i < this.innerCollections.length; i++) { + currentCollection = this.innerCollections[i]; + if (currentCollection.caseLabel === caseLabel) { return currentCollection.collection; } - return null; - } - }, { - key: 'validate', - value: function validate(newValue, locale) { - var collection = this.getCurrentCollection(this.conditionExpression(newValue)); - if (collection !== null) { - return collection.validate(newValue, locale); - } else { - return this.defaultCollection.validate(newValue, locale); - } - } - }, { - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - var currentCollection = this.getCurrentCollection(this.caseLabel, true); - currentCollection.addValidationRule(validationRule); } - }, { - key: 'addValidationRuleCollection', - value: function addValidationRuleCollection(validationRulesCollection) { - var currentCollection = this.getCurrentCollection(this.caseLabel, true); - currentCollection.addValidationRuleCollection(validationRulesCollection); - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - var collection = this.getCurrentCollection(this.caseLabel); - if (collection !== null) collection.isNotEmpty();else this.defaultCollection.isNotEmpty(); + if (createIfNotExists) { + currentCollection = { + caseLabel: caseLabel, + collection: new ValidationRulesCollection() + }; + this.innerCollections.push(currentCollection); + return currentCollection.collection; } - }, { - key: 'withMessage', - value: function withMessage(message) { - var collection = this.getCurrentCollection(this.caseLabel); - if (collection !== null) collection.withMessage(message);else this.defaultCollection.withMessage(message); + return null; + }; + + SwitchCaseValidationRulesCollection.prototype.validate = function validate(newValue, locale) { + var collection = this.getCurrentCollection(this.conditionExpression(newValue)); + if (collection !== null) { + return collection.validate(newValue, locale); + } else { + return this.defaultCollection.validate(newValue, locale); } - }]); + }; + + SwitchCaseValidationRulesCollection.prototype.addValidationRule = function addValidationRule(validationRule) { + var currentCollection = this.getCurrentCollection(this.caseLabel, true); + currentCollection.addValidationRule(validationRule); + }; + + SwitchCaseValidationRulesCollection.prototype.addValidationRuleCollection = function addValidationRuleCollection(validationRulesCollection) { + var currentCollection = this.getCurrentCollection(this.caseLabel, true); + currentCollection.addValidationRuleCollection(validationRulesCollection); + }; + + SwitchCaseValidationRulesCollection.prototype.isNotEmpty = function isNotEmpty() { + var collection = this.getCurrentCollection(this.caseLabel); + if (collection !== null) collection.isNotEmpty();else this.defaultCollection.isNotEmpty(); + }; + + SwitchCaseValidationRulesCollection.prototype.withMessage = function withMessage(message) { + var collection = this.getCurrentCollection(this.caseLabel); + if (collection !== null) collection.withMessage(message);else this.defaultCollection.withMessage(message); + }; return SwitchCaseValidationRulesCollection; })(); diff --git a/dist/commonjs/validation/validation-rules.js b/dist/commonjs/validation/validation-rules.js index d755e643..94287864 100644 --- a/dist/commonjs/validation/validation-rules.js +++ b/dist/commonjs/validation/validation-rules.js @@ -1,16 +1,10 @@ 'use strict'; -var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _Utilities = require('../validation/utilities'); @@ -27,60 +21,54 @@ var ValidationRule = (function () { this.ruleName = this.constructor.name; } - _createClass(ValidationRule, [{ - key: 'withMessage', - value: function withMessage(message) { - this.message = message; - } - }, { - key: 'explain', - value: function explain() { - return this.errorMessage; - } - }, { - key: 'setResult', - value: function setResult(result, currentValue, locale) { - if (result === true || result === undefined || result === null || result === '') { - this.errorMessage = null; - return true; + ValidationRule.prototype.withMessage = function withMessage(message) { + this.message = message; + }; + + ValidationRule.prototype.explain = function explain() { + return this.errorMessage; + }; + + ValidationRule.prototype.setResult = function setResult(result, currentValue, locale) { + if (result === true || result === undefined || result === null || result === '') { + this.errorMessage = null; + return true; + } else { + if (typeof result === 'string') { + this.errorMessage = result; } else { - if (typeof result === 'string') { - this.errorMessage = result; + if (this.message) { + if (typeof this.message === 'function') { + this.errorMessage = this.message(currentValue, this.threshold); + } else if (typeof this.message === 'string') { + this.errorMessage = this.message; + } else throw 'Unable to handle the error message:' + this.message; } else { - if (this.message) { - if (typeof this.message === 'function') { - this.errorMessage = this.message(currentValue, this.threshold); - } else if (typeof this.message === 'string') { - this.errorMessage = this.message; - } else throw 'Unable to handle the error message:' + this.message; - } else { - this.errorMessage = locale.translate(this.ruleName, currentValue, this.threshold); - } + this.errorMessage = locale.translate(this.ruleName, currentValue, this.threshold); } - return false; } + return false; } - }, { - key: 'validate', - value: function validate(currentValue, locale) { - var _this = this; - - if (locale === undefined) { - locale = _ValidationLocale.ValidationLocale.Repository['default']; - } + }; - currentValue = _Utilities.Utilities.getValue(currentValue); - var result = this.onValidate(currentValue, this.threshold, locale); - var promise = Promise.resolve(result); + ValidationRule.prototype.validate = function validate(currentValue, locale) { + var _this = this; - var nextPromise = promise.then(function (promiseResult) { - return _this.setResult(promiseResult, currentValue, locale); - }, function (promiseFailure) { - if (typeof promiseFailure === 'string' && promiseFailure !== '') return _this.setResult(promiseFailure, currentValue, locale);else return _this.setResult(false, currentValue, locale); - }); - return nextPromise; + if (locale === undefined) { + locale = _ValidationLocale.ValidationLocale.Repository['default']; } - }]); + + currentValue = _Utilities.Utilities.getValue(currentValue); + var result = this.onValidate(currentValue, this.threshold, locale); + var promise = Promise.resolve(result); + + var nextPromise = promise.then(function (promiseResult) { + return _this.setResult(promiseResult, currentValue, locale); + }, function (promiseFailure) { + if (typeof promiseFailure === 'string' && promiseFailure !== '') return _this.setResult(promiseFailure, currentValue, locale);else return _this.setResult(false, currentValue, locale); + }); + return nextPromise; + }; return ValidationRule; })(); @@ -93,7 +81,7 @@ var EmailValidationRule = (function (_ValidationRule) { _classCallCheck(this, EmailValidationRule); - _get(Object.getPrototypeOf(EmailValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule.call(this, null, function (newValue, threshold) { if (/\s/.test(newValue)) { return false; } @@ -137,7 +125,7 @@ var MinimumLengthValidationRule = (function (_ValidationRule2) { function MinimumLengthValidationRule(minimumLength) { _classCallCheck(this, MinimumLengthValidationRule); - _get(Object.getPrototypeOf(MinimumLengthValidationRule.prototype), 'constructor', this).call(this, minimumLength, function (newValue, minimumLength) { + _ValidationRule2.call(this, minimumLength, function (newValue, minimumLength) { return newValue.length !== undefined && newValue.length >= minimumLength; }); } @@ -153,7 +141,7 @@ var MaximumLengthValidationRule = (function (_ValidationRule3) { function MaximumLengthValidationRule(maximumLength) { _classCallCheck(this, MaximumLengthValidationRule); - _get(Object.getPrototypeOf(MaximumLengthValidationRule.prototype), 'constructor', this).call(this, maximumLength, function (newValue, maximumLength) { + _ValidationRule3.call(this, maximumLength, function (newValue, maximumLength) { return newValue.length !== undefined && newValue.length <= maximumLength; }); } @@ -169,7 +157,7 @@ var BetweenLengthValidationRule = (function (_ValidationRule4) { function BetweenLengthValidationRule(minimumLength, maximumLength) { _classCallCheck(this, BetweenLengthValidationRule); - _get(Object.getPrototypeOf(BetweenLengthValidationRule.prototype), 'constructor', this).call(this, { minimumLength: minimumLength, maximumLength: maximumLength }, function (newValue, threshold) { + _ValidationRule4.call(this, { minimumLength: minimumLength, maximumLength: maximumLength }, function (newValue, threshold) { return newValue.length !== undefined && newValue.length >= threshold.minimumLength && newValue.length <= threshold.maximumLength; }); } @@ -185,7 +173,7 @@ var CustomFunctionValidationRule = (function (_ValidationRule5) { function CustomFunctionValidationRule(customFunction, threshold) { _classCallCheck(this, CustomFunctionValidationRule); - _get(Object.getPrototypeOf(CustomFunctionValidationRule.prototype), 'constructor', this).call(this, threshold, customFunction); + _ValidationRule5.call(this, threshold, customFunction); } _inherits(CustomFunctionValidationRule, _ValidationRule5); @@ -199,7 +187,7 @@ var NumericValidationRule = (function (_ValidationRule6) { function NumericValidationRule() { _classCallCheck(this, NumericValidationRule); - _get(Object.getPrototypeOf(NumericValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold, locale) { + _ValidationRule6.call(this, null, function (newValue, threshold, locale) { var numericRegex = locale.setting('numericRegex'); var floatValue = parseFloat(newValue); return !Number.isNaN(parseFloat(floatValue)) && Number.isFinite(floatValue) && numericRegex.test(newValue); @@ -217,7 +205,7 @@ var RegexValidationRule = (function (_ValidationRule7) { function RegexValidationRule(regex) { _classCallCheck(this, RegexValidationRule); - _get(Object.getPrototypeOf(RegexValidationRule.prototype), 'constructor', this).call(this, regex, function (newValue, regex) { + _ValidationRule7.call(this, regex, function (newValue, regex) { return regex.test(newValue); }); } @@ -233,7 +221,7 @@ var ContainsOnlyValidationRule = (function (_RegexValidationRule) { function ContainsOnlyValidationRule(regex) { _classCallCheck(this, ContainsOnlyValidationRule); - _get(Object.getPrototypeOf(ContainsOnlyValidationRule.prototype), 'constructor', this).call(this, regex); + _RegexValidationRule.call(this, regex); } _inherits(ContainsOnlyValidationRule, _RegexValidationRule); @@ -247,7 +235,7 @@ var MinimumValueValidationRule = (function (_ValidationRule8) { function MinimumValueValidationRule(minimumValue) { _classCallCheck(this, MinimumValueValidationRule); - _get(Object.getPrototypeOf(MinimumValueValidationRule.prototype), 'constructor', this).call(this, minimumValue, function (newValue, minimumValue) { + _ValidationRule8.call(this, minimumValue, function (newValue, minimumValue) { return _Utilities.Utilities.getValue(minimumValue) < newValue; }); } @@ -263,7 +251,7 @@ var MinimumInclusiveValueValidationRule = (function (_ValidationRule9) { function MinimumInclusiveValueValidationRule(minimumValue) { _classCallCheck(this, MinimumInclusiveValueValidationRule); - _get(Object.getPrototypeOf(MinimumInclusiveValueValidationRule.prototype), 'constructor', this).call(this, minimumValue, function (newValue, minimumValue) { + _ValidationRule9.call(this, minimumValue, function (newValue, minimumValue) { return _Utilities.Utilities.getValue(minimumValue) <= newValue; }); } @@ -279,7 +267,7 @@ var MaximumValueValidationRule = (function (_ValidationRule10) { function MaximumValueValidationRule(maximumValue) { _classCallCheck(this, MaximumValueValidationRule); - _get(Object.getPrototypeOf(MaximumValueValidationRule.prototype), 'constructor', this).call(this, maximumValue, function (newValue, maximumValue) { + _ValidationRule10.call(this, maximumValue, function (newValue, maximumValue) { return newValue < _Utilities.Utilities.getValue(maximumValue); }); } @@ -295,7 +283,7 @@ var MaximumInclusiveValueValidationRule = (function (_ValidationRule11) { function MaximumInclusiveValueValidationRule(maximumValue) { _classCallCheck(this, MaximumInclusiveValueValidationRule); - _get(Object.getPrototypeOf(MaximumInclusiveValueValidationRule.prototype), 'constructor', this).call(this, maximumValue, function (newValue, maximumValue) { + _ValidationRule11.call(this, maximumValue, function (newValue, maximumValue) { return newValue <= _Utilities.Utilities.getValue(maximumValue); }); } @@ -311,7 +299,7 @@ var BetweenValueValidationRule = (function (_ValidationRule12) { function BetweenValueValidationRule(minimumValue, maximumValue) { _classCallCheck(this, BetweenValueValidationRule); - _get(Object.getPrototypeOf(BetweenValueValidationRule.prototype), 'constructor', this).call(this, { minimumValue: minimumValue, maximumValue: maximumValue }, function (newValue, threshold) { + _ValidationRule12.call(this, { minimumValue: minimumValue, maximumValue: maximumValue }, function (newValue, threshold) { return _Utilities.Utilities.getValue(threshold.minimumValue) <= newValue && newValue <= _Utilities.Utilities.getValue(threshold.maximumValue); }); } @@ -329,7 +317,7 @@ var DigitValidationRule = (function (_ValidationRule13) { _classCallCheck(this, DigitValidationRule); - _get(Object.getPrototypeOf(DigitValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule13.call(this, null, function (newValue, threshold) { return _this3.digitRegex.test(newValue); }); this.digitRegex = /^\d+$/; @@ -348,7 +336,7 @@ var AlphaNumericValidationRule = (function (_ValidationRule14) { _classCallCheck(this, AlphaNumericValidationRule); - _get(Object.getPrototypeOf(AlphaNumericValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule14.call(this, null, function (newValue, threshold) { return _this4.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z0-9]+$/i; @@ -367,7 +355,7 @@ var AlphaValidationRule = (function (_ValidationRule15) { _classCallCheck(this, AlphaValidationRule); - _get(Object.getPrototypeOf(AlphaValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule15.call(this, null, function (newValue, threshold) { return _this5.alphaRegex.test(newValue); }); this.alphaRegex = /^[a-z]+$/i; @@ -386,7 +374,7 @@ var AlphaOrWhitespaceValidationRule = (function (_ValidationRule16) { _classCallCheck(this, AlphaOrWhitespaceValidationRule); - _get(Object.getPrototypeOf(AlphaOrWhitespaceValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule16.call(this, null, function (newValue, threshold) { return _this6.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z\s]+$/i; @@ -405,7 +393,7 @@ var AlphaNumericOrWhitespaceValidationRule = (function (_ValidationRule17) { _classCallCheck(this, AlphaNumericOrWhitespaceValidationRule); - _get(Object.getPrototypeOf(AlphaNumericOrWhitespaceValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule17.call(this, null, function (newValue, threshold) { return _this7.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z0-9\s]+$/i; @@ -422,7 +410,7 @@ var MediumPasswordValidationRule = (function (_ValidationRule18) { function MediumPasswordValidationRule(minimumComplexityLevel) { _classCallCheck(this, MediumPasswordValidationRule); - _get(Object.getPrototypeOf(MediumPasswordValidationRule.prototype), 'constructor', this).call(this, minimumComplexityLevel ? minimumComplexityLevel : 3, function (newValue, threshold) { + _ValidationRule18.call(this, minimumComplexityLevel ? minimumComplexityLevel : 3, function (newValue, threshold) { if (typeof newValue !== 'string') return false; var strength = 0; @@ -445,7 +433,7 @@ var StrongPasswordValidationRule = (function (_MediumPasswordValidationRule) { function StrongPasswordValidationRule() { _classCallCheck(this, StrongPasswordValidationRule); - _get(Object.getPrototypeOf(StrongPasswordValidationRule.prototype), 'constructor', this).call(this, 4); + _MediumPasswordValidationRule.call(this, 4); } _inherits(StrongPasswordValidationRule, _MediumPasswordValidationRule); @@ -459,7 +447,7 @@ var EqualityValidationRuleBase = (function (_ValidationRule19) { function EqualityValidationRuleBase(otherValue, equality, otherValueLabel) { _classCallCheck(this, EqualityValidationRuleBase); - _get(Object.getPrototypeOf(EqualityValidationRuleBase.prototype), 'constructor', this).call(this, { + _ValidationRule19.call(this, { otherValue: otherValue, equality: equality, otherValueLabel: otherValueLabel @@ -481,7 +469,7 @@ var EqualityValidationRule = (function (_EqualityValidationRuleBase) { function EqualityValidationRule(otherValue) { _classCallCheck(this, EqualityValidationRule); - _get(Object.getPrototypeOf(EqualityValidationRule.prototype), 'constructor', this).call(this, otherValue, true); + _EqualityValidationRuleBase.call(this, otherValue, true); } _inherits(EqualityValidationRule, _EqualityValidationRuleBase); @@ -495,7 +483,7 @@ var EqualityWithOtherLabelValidationRule = (function (_EqualityValidationRuleBas function EqualityWithOtherLabelValidationRule(otherValue, otherLabel) { _classCallCheck(this, EqualityWithOtherLabelValidationRule); - _get(Object.getPrototypeOf(EqualityWithOtherLabelValidationRule.prototype), 'constructor', this).call(this, otherValue, true, otherLabel); + _EqualityValidationRuleBase2.call(this, otherValue, true, otherLabel); } _inherits(EqualityWithOtherLabelValidationRule, _EqualityValidationRuleBase2); @@ -509,7 +497,7 @@ var InEqualityValidationRule = (function (_EqualityValidationRuleBase3) { function InEqualityValidationRule(otherValue) { _classCallCheck(this, InEqualityValidationRule); - _get(Object.getPrototypeOf(InEqualityValidationRule.prototype), 'constructor', this).call(this, otherValue, false); + _EqualityValidationRuleBase3.call(this, otherValue, false); } _inherits(InEqualityValidationRule, _EqualityValidationRuleBase3); @@ -523,7 +511,7 @@ var InEqualityWithOtherLabelValidationRule = (function (_EqualityValidationRuleB function InEqualityWithOtherLabelValidationRule(otherValue, otherLabel) { _classCallCheck(this, InEqualityWithOtherLabelValidationRule); - _get(Object.getPrototypeOf(InEqualityWithOtherLabelValidationRule.prototype), 'constructor', this).call(this, otherValue, false, otherLabel); + _EqualityValidationRuleBase4.call(this, otherValue, false, otherLabel); } _inherits(InEqualityWithOtherLabelValidationRule, _EqualityValidationRuleBase4); @@ -537,7 +525,7 @@ var InCollectionValidationRule = (function (_ValidationRule20) { function InCollectionValidationRule(collection) { _classCallCheck(this, InCollectionValidationRule); - _get(Object.getPrototypeOf(InCollectionValidationRule.prototype), 'constructor', this).call(this, collection, function (newValue, threshold) { + _ValidationRule20.call(this, collection, function (newValue, threshold) { var collection = _Utilities.Utilities.getValue(threshold); for (var i = 0; i < collection.length; i++) { if (newValue === collection[i]) return true; diff --git a/dist/commonjs/validation/validation.js b/dist/commonjs/validation/validation.js index f36a78d1..e49d7874 100644 --- a/dist/commonjs/validation/validation.js +++ b/dist/commonjs/validation/validation.js @@ -4,11 +4,7 @@ var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? ob var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -Object.defineProperty(exports, '__esModule', { - value: true -}); +exports.__esModule = true; var _ObserverLocator = require('aurelia-binding'); @@ -34,23 +30,19 @@ var Validation = (function () { this.config = validationConfig ? validationConfig : Validation.defaults; } - _createClass(Validation, [{ - key: 'on', - value: function on(subject, configCallback) { - var conf = new _ValidationConfig.ValidationConfig(this.config); - if (configCallback !== null && configCallback !== undefined && typeof configCallback === 'function') { - configCallback(conf); - } - return new _ValidationGroup.ValidationGroup(subject, this.observerLocator, conf); - } - }, { - key: 'onBreezeEntity', - value: function onBreezeEntity(breezeEntity, configCallback) { - var validation = this.on(breezeEntity, configCallback); - validation.onBreezeEntity(); - return validation; + Validation.prototype.on = function on(subject, configCallback) { + var conf = new _ValidationConfig.ValidationConfig(this.config); + if (configCallback !== null && configCallback !== undefined && typeof configCallback === 'function') { + configCallback(conf); } - }]); + return new _ValidationGroup.ValidationGroup(subject, this.observerLocator, conf); + }; + + Validation.prototype.onBreezeEntity = function onBreezeEntity(breezeEntity, configCallback) { + var validation = this.on(breezeEntity, configCallback); + validation.onBreezeEntity(); + return validation; + }; var _Validation = Validation; Validation = _inject.inject(_ObserverLocator.ObserverLocator)(Validation) || Validation; diff --git a/dist/system/validation/debouncer.js b/dist/system/validation/debouncer.js index 7bef6049..d8da43bf 100644 --- a/dist/system/validation/debouncer.js +++ b/dist/system/validation/debouncer.js @@ -1,5 +1,5 @@ System.register(['../validation/validation'], function (_export) { - var Validation, _classCallCheck, _createClass, Debouncer; + var Validation, _classCallCheck, Debouncer; return { setters: [function (_validationValidation) { @@ -10,8 +10,6 @@ System.register(['../validation/validation'], function (_export) { _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - Debouncer = (function () { function Debouncer(debounceTimeout) { _classCallCheck(this, Debouncer); @@ -20,22 +18,19 @@ System.register(['../validation/validation'], function (_export) { this.debounceTimeout = debounceTimeout; } - _createClass(Debouncer, [{ - key: 'debounce', - value: function debounce(func) { - var _this = this; - - this.currentFunction = func; - setTimeout(function () { - if (func !== null && func !== undefined) { - if (func === _this.currentFunction) { - _this.currentFunction = null; - func(); - } + Debouncer.prototype.debounce = function debounce(func) { + var _this = this; + + this.currentFunction = func; + setTimeout(function () { + if (func !== null && func !== undefined) { + if (func === _this.currentFunction) { + _this.currentFunction = null; + func(); } - }, this.debounceTimeout); - } - }]); + } + }, this.debounceTimeout); + }; return Debouncer; })(); diff --git a/dist/system/validation/decorators.js b/dist/system/validation/decorators.js index d196d534..effe3d06 100644 --- a/dist/system/validation/decorators.js +++ b/dist/system/validation/decorators.js @@ -1,5 +1,5 @@ System.register([], function (_export) { - var _classCallCheck, _createClass, ValidationMetadata, ValidationPropertyMetadata; + var _classCallCheck, ValidationMetadata, ValidationPropertyMetadata; _export("ensure", ensure); @@ -20,8 +20,6 @@ System.register([], function (_export) { _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidationMetadata = (function () { function ValidationMetadata() { _classCallCheck(this, ValidationMetadata); @@ -29,26 +27,22 @@ System.register([], function (_export) { this.properties = []; } - _createClass(ValidationMetadata, [{ - key: "getOrCreateProperty", - value: function getOrCreateProperty(propertyName) { - var property = this.properties.find(function (x) { - return x.propertyName === propertyName; - }); - if (property === undefined) { - property = new ValidationPropertyMetadata(propertyName); - this.properties.push(property); - } - return property; - } - }, { - key: "setup", - value: function setup(validation) { - this.properties.forEach(function (property) { - property.setup(validation); - }); + ValidationMetadata.prototype.getOrCreateProperty = function getOrCreateProperty(propertyName) { + var property = this.properties.find(function (x) { + return x.propertyName === propertyName; + }); + if (property === undefined) { + property = new ValidationPropertyMetadata(propertyName); + this.properties.push(property); } - }]); + return property; + }; + + ValidationMetadata.prototype.setup = function setup(validation) { + this.properties.forEach(function (property) { + property.setup(validation); + }); + }; return ValidationMetadata; })(); @@ -61,20 +55,16 @@ System.register([], function (_export) { this.setupSteps = []; } - _createClass(ValidationPropertyMetadata, [{ - key: "addSetupStep", - value: function addSetupStep(setupStep) { - this.setupSteps.push(setupStep); - } - }, { - key: "setup", - value: function setup(validation) { - validation.ensure(this.propertyName); - this.setupSteps.forEach(function (setupStep) { - setupStep(validation); - }); - } - }]); + ValidationPropertyMetadata.prototype.addSetupStep = function addSetupStep(setupStep) { + this.setupSteps.push(setupStep); + }; + + ValidationPropertyMetadata.prototype.setup = function setup(validation) { + validation.ensure(this.propertyName); + this.setupSteps.forEach(function (setupStep) { + setupStep(validation); + }); + }; return ValidationPropertyMetadata; })(); diff --git a/dist/system/validation/path-observer.js b/dist/system/validation/path-observer.js index 6114a615..6efbe9cb 100644 --- a/dist/system/validation/path-observer.js +++ b/dist/system/validation/path-observer.js @@ -1,5 +1,5 @@ System.register(['aurelia-binding'], function (_export) { - var ObserverLocator, _classCallCheck, _createClass, PathObserver; + var ObserverLocator, _classCallCheck, PathObserver; return { setters: [function (_aureliaBinding) { @@ -10,8 +10,6 @@ System.register(['aurelia-binding'], function (_export) { _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - PathObserver = (function () { function PathObserver(observerLocator, subject, path) { _classCallCheck(this, PathObserver); @@ -24,112 +22,105 @@ System.register(['aurelia-binding'], function (_export) { if (this.path.length > 1) this.observeParts(); } - _createClass(PathObserver, [{ - key: 'observeParts', - value: function observeParts(propertyName) { - var _this = this; - - if (propertyName !== undefined && propertyName !== null) { - for (var i = this.observers.length - 1; i >= 0; i--) { - var currentObserver = this.observers[i]; - if (currentObserver.propertyName === propertyName) { - break; - } - var observer = this.observers.pop(); - if (observer && observer.subscription) { - observer.subscription(); - } + PathObserver.prototype.observeParts = function observeParts(propertyName) { + var _this = this; + + if (propertyName !== undefined && propertyName !== null) { + for (var i = this.observers.length - 1; i >= 0; i--) { + var currentObserver = this.observers[i]; + if (currentObserver.propertyName === propertyName) { + break; + } + var observer = this.observers.pop(); + if (observer && observer.subscription) { + observer.subscription(); } } + } - var currentSubject = this.subject; - - var observersAreComplete = this.observers.length === this.path.length; - - var _loop = function (i) { - var observer = _this.observers[i]; - if (!observer) { + var currentSubject = this.subject; - var currentPath = _this.path[i]; - observer = _this.observerLocator.getObserver(currentSubject, currentPath); - _this.observers.push(observer); - var subscription = observer.subscribe(function (newValue, oldValue) { - _this.observeParts(observer.propertyName); - }); - observer.subscription = subscription; - } + var observersAreComplete = this.observers.length === this.path.length; - var currentValue = observer.getValue(); - if (currentValue === undefined || currentValue === null) { - return 'break'; - } else { - currentSubject = currentValue; - } - }; + var _loop = function (i) { + var observer = _this.observers[i]; + if (!observer) { - for (var i = 0; i < this.path.length; i++) { - var _ret = _loop(i); - - if (_ret === 'break') break; + var currentPath = _this.path[i]; + observer = _this.observerLocator.getObserver(currentSubject, currentPath); + _this.observers.push(observer); + var subscription = observer.subscribe(function (newValue, oldValue) { + _this.observeParts(observer.propertyName); + }); + observer.subscription = subscription; } - if (!observersAreComplete && this.observers.length === this.path.length) { - var actualObserver = this.observers[this.observers.length - 1]; - for (var i = 0; i < this.callbacks.length; i++) { - actualObserver.subscribe(this.callbacks[i]); - } + var currentValue = observer.getValue(); + if (currentValue === undefined || currentValue === null) { + return 'break'; + } else { + currentSubject = currentValue; } + }; + + for (var i = 0; i < this.path.length; i++) { + var _ret = _loop(i); + + if (_ret === 'break') break; } - }, { - key: 'observePart', - value: function observePart(part) { - if (part !== this.path[this.path.length - 1]) { - this.observerParts(); + + if (!observersAreComplete && this.observers.length === this.path.length) { + var actualObserver = this.observers[this.observers.length - 1]; + for (var i = 0; i < this.callbacks.length; i++) { + actualObserver.subscribe(this.callbacks[i]); } } - }, { - key: 'getObserver', - value: function getObserver() { - if (this.path.length == 1) { - return this.observerLocator.getObserver(this.subject, this.path[0]); - }return this; + }; + + PathObserver.prototype.observePart = function observePart(part) { + if (part !== this.path[this.path.length - 1]) { + this.observerParts(); } - }, { - key: 'getValue', - value: function getValue() { - var expectedSubject = this.subject; - for (var i = 0; this.path.length; i++) { - var currentObserver = this.observers[i]; - if (currentObserver === null || currentObserver === undefined) { - this.observeParts(this.path[i]); - currentObserver = this.observers[i]; + }; + + PathObserver.prototype.getObserver = function getObserver() { + if (this.path.length == 1) { + return this.observerLocator.getObserver(this.subject, this.path[0]); + }return this; + }; + + PathObserver.prototype.getValue = function getValue() { + var expectedSubject = this.subject; + for (var i = 0; this.path.length; i++) { + var currentObserver = this.observers[i]; + if (currentObserver === null || currentObserver === undefined) { + this.observeParts(this.path[i]); + currentObserver = this.observers[i]; - if (currentObserver === null || currentObserver === undefined) { - break; - } + if (currentObserver === null || currentObserver === undefined) { + break; } - if (currentObserver.obj !== expectedSubject) { - this.observeParts(this.path[i - 1]); - break; - } - expectedSubject = currentObserver.getValue(); } + if (currentObserver.obj !== expectedSubject) { + this.observeParts(this.path[i - 1]); + break; + } + expectedSubject = currentObserver.getValue(); + } - if (this.observers.length !== this.path.length) { - return undefined; - } - var value = this.observers[this.observers.length - 1].getValue(); - return value; + if (this.observers.length !== this.path.length) { + return undefined; } - }, { - key: 'subscribe', - value: function subscribe(callback) { - this.callbacks.unshift(callback); - if (this.observers.length === this.path.length) { - return this.observers[this.observers.length - 1].subscribe(callback); - } + var value = this.observers[this.observers.length - 1].getValue(); + return value; + }; + + PathObserver.prototype.subscribe = function subscribe(callback) { + this.callbacks.unshift(callback); + if (this.observers.length === this.path.length) { + return this.observers[this.observers.length - 1].subscribe(callback); } - }]); + }; return PathObserver; })(); diff --git a/dist/system/validation/utilities.js b/dist/system/validation/utilities.js index 37a0cf54..07558dd3 100644 --- a/dist/system/validation/utilities.js +++ b/dist/system/validation/utilities.js @@ -1,5 +1,5 @@ System.register([], function (_export) { - var _classCallCheck, _createClass, Utilities; + var _classCallCheck, Utilities; return { setters: [], @@ -8,47 +8,41 @@ System.register([], function (_export) { _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - Utilities = (function () { function Utilities() { _classCallCheck(this, Utilities); } - _createClass(Utilities, null, [{ - key: 'getValue', - value: function getValue(val) { - if (val !== undefined && typeof val === 'function') { - return val(); - } - return val; + Utilities.getValue = function getValue(val) { + if (val !== undefined && typeof val === 'function') { + return val(); } - }, { - key: 'isEmptyValue', - value: function isEmptyValue(val) { - if (val === undefined) { - return true; - } - if (val === null) { - return true; - } - if (val === '') { - return true; - } - if (typeof val === 'string') { - if (String.prototype.trim) { - val = val.trim(); - } else { - val = val.replace(/^\s+|\s+$/g, ''); - } - } + return val; + }; - if (val.length !== undefined) { - return 0 === val.length; + Utilities.isEmptyValue = function isEmptyValue(val) { + if (val === undefined) { + return true; + } + if (val === null) { + return true; + } + if (val === '') { + return true; + } + if (typeof val === 'string') { + if (String.prototype.trim) { + val = val.trim(); + } else { + val = val.replace(/^\s+|\s+$/g, ''); } - return false; } - }]); + + if (val.length !== undefined) { + return 0 === val.length; + } + return false; + }; return Utilities; })(); diff --git a/dist/system/validation/validate-custom-attribute-view-strategy.js b/dist/system/validation/validate-custom-attribute-view-strategy.js index 492b8412..180fec02 100644 --- a/dist/system/validation/validate-custom-attribute-view-strategy.js +++ b/dist/system/validation/validate-custom-attribute-view-strategy.js @@ -1,19 +1,15 @@ System.register([], function (_export) { - var _get, _inherits, _classCallCheck, _createClass, ValidateCustomAttributeViewStrategyBase, TWBootstrapViewStrategy, ValidateCustomAttributeViewStrategy; + var _inherits, _classCallCheck, ValidateCustomAttributeViewStrategyBase, TWBootstrapViewStrategy, ValidateCustomAttributeViewStrategy; return { setters: [], execute: function () { 'use strict'; - _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidateCustomAttributeViewStrategyBase = (function () { function ValidateCustomAttributeViewStrategyBase() { _classCallCheck(this, ValidateCustomAttributeViewStrategyBase); @@ -21,37 +17,32 @@ System.register([], function (_export) { this.bindingPathAttributes = ['validate', 'value.bind', 'value.two-way']; } - _createClass(ValidateCustomAttributeViewStrategyBase, [{ - key: 'getValidationProperty', - value: function getValidationProperty(validation, element) { - var atts = element.attributes; - for (var i = 0; i < this.bindingPathAttributes.length; i++) { - var attributeName = this.bindingPathAttributes[i]; - if (atts[attributeName]) { - var bindingPath = atts[attributeName].value.trim(); - if (bindingPath.indexOf('|') != -1) bindingPath = bindingPath.split('|')[0].trim(); - var validationProperty = validation.result.properties[bindingPath]; - - if (attributeName == 'validate' && (validationProperty === null || validationProperty === undefined)) { - validation.ensure(bindingPath); - validationProperty = validation.result.properties[bindingPath]; - } - return validationProperty; + ValidateCustomAttributeViewStrategyBase.prototype.getValidationProperty = function getValidationProperty(validation, element) { + var atts = element.attributes; + for (var i = 0; i < this.bindingPathAttributes.length; i++) { + var attributeName = this.bindingPathAttributes[i]; + if (atts[attributeName]) { + var bindingPath = atts[attributeName].value.trim(); + if (bindingPath.indexOf('|') != -1) bindingPath = bindingPath.split('|')[0].trim(); + var validationProperty = validation.result.properties[bindingPath]; + + if (attributeName == 'validate' && (validationProperty === null || validationProperty === undefined)) { + validation.ensure(bindingPath); + validationProperty = validation.result.properties[bindingPath]; } + return validationProperty; } - return null; - } - }, { - key: 'prepareElement', - value: function prepareElement(validationProperty, element) { - throw Error('View strategy must implement prepareElement(validationProperty, element)'); } - }, { - key: 'updateElement', - value: function updateElement(validationProperty, element) { - throw Error('View strategy must implement updateElement(validationProperty, element)'); - } - }]); + return null; + }; + + ValidateCustomAttributeViewStrategyBase.prototype.prepareElement = function prepareElement(validationProperty, element) { + throw Error('View strategy must implement prepareElement(validationProperty, element)'); + }; + + ValidateCustomAttributeViewStrategyBase.prototype.updateElement = function updateElement(validationProperty, element) { + throw Error('View strategy must implement updateElement(validationProperty, element)'); + }; return ValidateCustomAttributeViewStrategyBase; })(); @@ -62,7 +53,7 @@ System.register([], function (_export) { function TWBootstrapViewStrategy(appendMessageToInput, appendMessageToLabel, helpBlockClass) { _classCallCheck(this, TWBootstrapViewStrategy); - _get(Object.getPrototypeOf(TWBootstrapViewStrategy.prototype), 'constructor', this).call(this); + _ValidateCustomAttributeViewStrategyBase.call(this); this.appendMessageToInput = appendMessageToInput; this.appendMessageToLabel = appendMessageToLabel; this.helpBlockClass = helpBlockClass; @@ -70,103 +61,94 @@ System.register([], function (_export) { _inherits(TWBootstrapViewStrategy, _ValidateCustomAttributeViewStrategyBase); - _createClass(TWBootstrapViewStrategy, [{ - key: 'searchFormGroup', - value: function searchFormGroup(currentElement, currentDepth) { - if (currentDepth === 5) { - return null; - } - if (currentElement.classList && currentElement.classList.contains('form-group')) { - return currentElement; - } - return this.searchFormGroup(currentElement.parentNode, 1 + currentDepth); + TWBootstrapViewStrategy.prototype.searchFormGroup = function searchFormGroup(currentElement, currentDepth) { + if (currentDepth === 5) { + return null; } - }, { - key: 'findLabels', - value: function findLabels(formGroup, inputId) { - var labels = []; - this.findLabelsRecursively(formGroup, inputId, labels, 0); - return labels; + if (currentElement.classList && currentElement.classList.contains('form-group')) { + return currentElement; + } + return this.searchFormGroup(currentElement.parentNode, 1 + currentDepth); + }; + + TWBootstrapViewStrategy.prototype.findLabels = function findLabels(formGroup, inputId) { + var labels = []; + this.findLabelsRecursively(formGroup, inputId, labels, 0); + return labels; + }; + + TWBootstrapViewStrategy.prototype.findLabelsRecursively = function findLabelsRecursively(currentElement, inputId, currentLabels, currentDepth) { + if (currentDepth === 5) { + return; + } + if (currentElement.nodeName === 'LABEL' && (currentElement.attributes['for'] && currentElement.attributes['for'].value === inputId || !currentElement.attributes['for'])) { + currentLabels.push(currentElement); } - }, { - key: 'findLabelsRecursively', - value: function findLabelsRecursively(currentElement, inputId, currentLabels, currentDepth) { - if (currentDepth === 5) { - return; - } - if (currentElement.nodeName === 'LABEL' && (currentElement.attributes['for'] && currentElement.attributes['for'].value === inputId || !currentElement.attributes['for'])) { - currentLabels.push(currentElement); - } - for (var i = 0; i < currentElement.children.length; i++) { - this.findLabelsRecursively(currentElement.children[i], inputId, currentLabels, 1 + currentDepth); - } + for (var i = 0; i < currentElement.children.length; i++) { + this.findLabelsRecursively(currentElement.children[i], inputId, currentLabels, 1 + currentDepth); } - }, { - key: 'appendMessageToElement', - value: function appendMessageToElement(element, validationProperty) { - var helpBlock = element.nextSibling; - if (helpBlock) { - if (!helpBlock.classList) { - helpBlock = null; - } else if (!helpBlock.classList.contains(this.helpBlockClass)) { - helpBlock = null; - } + }; + + TWBootstrapViewStrategy.prototype.appendMessageToElement = function appendMessageToElement(element, validationProperty) { + var helpBlock = element.nextSibling; + if (helpBlock) { + if (!helpBlock.classList) { + helpBlock = null; + } else if (!helpBlock.classList.contains(this.helpBlockClass)) { + helpBlock = null; } + } - if (!helpBlock) { - helpBlock = document.createElement('p'); - helpBlock.classList.add('help-block'); - helpBlock.classList.add(this.helpBlockClass); + if (!helpBlock) { + helpBlock = document.createElement('p'); + helpBlock.classList.add('help-block'); + helpBlock.classList.add(this.helpBlockClass); - if (element.nextSibling) { - element.parentNode.insertBefore(helpBlock, element.nextSibling); - } else { - element.parentNode.appendChild(helpBlock); - } + if (element.nextSibling) { + element.parentNode.insertBefore(helpBlock, element.nextSibling); + } else { + element.parentNode.appendChild(helpBlock); } - if (validationProperty) helpBlock.textContent = validationProperty.message;else helpBlock.textContent = ''; } - }, { - key: 'appendUIVisuals', - value: function appendUIVisuals(validationProperty, currentElement) { - var formGroup = this.searchFormGroup(currentElement, 0); - if (formGroup) { - if (validationProperty && validationProperty.isDirty) { - if (validationProperty.isValid) { - formGroup.classList.remove('has-warning'); - formGroup.classList.add('has-success'); - } else { - formGroup.classList.remove('has-success'); - formGroup.classList.add('has-warning'); - } - } else { + if (validationProperty) helpBlock.textContent = validationProperty.message;else helpBlock.textContent = ''; + }; + + TWBootstrapViewStrategy.prototype.appendUIVisuals = function appendUIVisuals(validationProperty, currentElement) { + var formGroup = this.searchFormGroup(currentElement, 0); + if (formGroup) { + if (validationProperty && validationProperty.isDirty) { + if (validationProperty.isValid) { formGroup.classList.remove('has-warning'); + formGroup.classList.add('has-success'); + } else { formGroup.classList.remove('has-success'); + formGroup.classList.add('has-warning'); } - if (this.appendMessageToInput) { - this.appendMessageToElement(currentElement, validationProperty); - } - if (this.appendMessageToLabel) { - var labels = this.findLabels(formGroup, currentElement.id); - for (var ii = 0; ii < labels.length; ii++) { - var label = labels[ii]; - this.appendMessageToElement(label, validationProperty); - } + } else { + formGroup.classList.remove('has-warning'); + formGroup.classList.remove('has-success'); + } + if (this.appendMessageToInput) { + this.appendMessageToElement(currentElement, validationProperty); + } + if (this.appendMessageToLabel) { + var labels = this.findLabels(formGroup, currentElement.id); + for (var ii = 0; ii < labels.length; ii++) { + var label = labels[ii]; + this.appendMessageToElement(label, validationProperty); } } } - }, { - key: 'prepareElement', - value: function prepareElement(validationProperty, element) { - this.appendUIVisuals(null, element); - } - }, { - key: 'updateElement', - value: function updateElement(validationProperty, element) { - this.appendUIVisuals(validationProperty, element); - } - }]); + }; + + TWBootstrapViewStrategy.prototype.prepareElement = function prepareElement(validationProperty, element) { + this.appendUIVisuals(null, element); + }; + + TWBootstrapViewStrategy.prototype.updateElement = function updateElement(validationProperty, element) { + this.appendUIVisuals(validationProperty, element); + }; return TWBootstrapViewStrategy; })(ValidateCustomAttributeViewStrategyBase); diff --git a/dist/system/validation/validate-custom-attribute.js b/dist/system/validation/validate-custom-attribute.js index 13ca583a..c44cdd5e 100644 --- a/dist/system/validation/validate-custom-attribute.js +++ b/dist/system/validation/validate-custom-attribute.js @@ -1,5 +1,5 @@ System.register(['aurelia-dependency-injection', 'aurelia-templating'], function (_export) { - var inject, customAttribute, Behavior, _classCallCheck, _createClass, ValidateCustomAttribute; + var inject, customAttribute, Behavior, _classCallCheck, ValidateCustomAttribute; return { setters: [function (_aureliaDependencyInjection) { @@ -13,8 +13,6 @@ System.register(['aurelia-dependency-injection', 'aurelia-templating'], function _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidateCustomAttribute = (function () { function ValidateCustomAttribute(element) { _classCallCheck(this, _ValidateCustomAttribute); @@ -24,45 +22,39 @@ System.register(['aurelia-dependency-injection', 'aurelia-templating'], function this.viewStrategy = null; } - _createClass(ValidateCustomAttribute, [{ - key: 'valueChanged', - value: function valueChanged(newValue) { - if (this.value === null || this.value === undefined) { - return; - }this.processedValidation = this.value; - if (typeof this.value === 'string') { - return; - } else { - this.subscribeChangedHandlers(this.element); - } + ValidateCustomAttribute.prototype.valueChanged = function valueChanged(newValue) { + if (this.value === null || this.value === undefined) { + return; + }this.processedValidation = this.value; + if (typeof this.value === 'string') { + return; + } else { + this.subscribeChangedHandlers(this.element); } - }, { - key: 'subscribeChangedHandlers', - value: function subscribeChangedHandlers(currentElement) { - var _this = this; + }; + + ValidateCustomAttribute.prototype.subscribeChangedHandlers = function subscribeChangedHandlers(currentElement) { + var _this = this; - this.viewStrategy = this.value.config.getViewStrategy(); - var validationProperty = this.viewStrategy.getValidationProperty(this.value, currentElement); - if (validationProperty !== null && validationProperty !== undefined) { - this.viewStrategy.prepareElement(validationProperty, currentElement); - validationProperty.onValidate(function (vp) { - _this.viewStrategy.updateElement(vp, currentElement); - }); - } - var children = currentElement.children; - for (var i = 0; i < children.length; i++) { - this.subscribeChangedHandlers(children[i]); - } + this.viewStrategy = this.value.config.getViewStrategy(); + var validationProperty = this.viewStrategy.getValidationProperty(this.value, currentElement); + if (validationProperty !== null && validationProperty !== undefined) { + this.viewStrategy.prepareElement(validationProperty, currentElement); + validationProperty.onValidate(function (vp) { + _this.viewStrategy.updateElement(vp, currentElement); + }); } - }, { - key: 'detached', - value: function detached() {} - }, { - key: 'attached', - value: function attached() { - if (this.processedValidation === null || this.processedValidation === undefined) this.valueChanged(this.value); + var children = currentElement.children; + for (var i = 0; i < children.length; i++) { + this.subscribeChangedHandlers(children[i]); } - }]); + }; + + ValidateCustomAttribute.prototype.detached = function detached() {}; + + ValidateCustomAttribute.prototype.attached = function attached() { + if (this.processedValidation === null || this.processedValidation === undefined) this.valueChanged(this.value); + }; var _ValidateCustomAttribute = ValidateCustomAttribute; ValidateCustomAttribute = customAttribute('validate')(ValidateCustomAttribute) || ValidateCustomAttribute; diff --git a/dist/system/validation/validation-config.js b/dist/system/validation/validation-config.js index 89b352fe..58d492d8 100644 --- a/dist/system/validation/validation-config.js +++ b/dist/system/validation/validation-config.js @@ -1,5 +1,5 @@ System.register(['../validation/validation-locale', '../validation/validate-custom-attribute-view-strategy'], function (_export) { - var ValidationLocale, ValidateCustomAttributeViewStrategy, _createClass, _classCallCheck, ValidationConfigDefaults, ValidationConfig; + var ValidationLocale, ValidateCustomAttributeViewStrategy, _classCallCheck, ValidationConfigDefaults, ValidationConfig; return { setters: [function (_validationValidationLocale) { @@ -10,8 +10,6 @@ System.register(['../validation/validation-locale', '../validation/validate-cust execute: function () { 'use strict'; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; ValidationConfigDefaults = function ValidationConfigDefaults() { @@ -42,97 +40,84 @@ System.register(['../validation/validation-locale', '../validation/validate-cust this.changedHandlers = new Map(); } - _createClass(ValidationConfig, [{ - key: 'getValue', - value: function getValue(identifier) { - if (this.values.hasOwnProperty(identifier) !== null && this.values[identifier] !== undefined) { - return this.values[identifier]; - } - if (this.innerConfig !== null) { - return this.innerConfig.getValue(identifier); - } - throw Error('Config not found: ' + identifier); - } - }, { - key: 'setValue', - value: function setValue(identifier, value) { - this.values[identifier] = value; - return this; - } - }, { - key: 'onLocaleChanged', - value: function onLocaleChanged(callback) { - var _this = this; - - if (this.innerConfig !== undefined) { - return this.innerConfig.onLocaleChanged(callback); - } else { - var _ret = (function () { - var id = ++ValidationConfig.uniqueListenerId; - _this.changedHandlers.set(id, callback); - return { - v: function () { - changedHandlers['delete'](id); - } - }; - })(); - - if (typeof _ret === 'object') { - return _ret.v; - } - } + ValidationConfig.prototype.getValue = function getValue(identifier) { + if (this.values.hasOwnProperty(identifier) !== null && this.values[identifier] !== undefined) { + return this.values[identifier]; } - }, { - key: 'getDebounceTimeout', - value: function getDebounceTimeout() { - return this.getValue('debounceTimeout'); + if (this.innerConfig !== null) { + return this.innerConfig.getValue(identifier); } - }, { - key: 'useDebounceTimeout', - value: function useDebounceTimeout(value) { - return this.setValue('debounceTimeout', value); - } - }, { - key: 'getDependencies', - value: function getDependencies() { - return this.getValue('dependencies'); - } - }, { - key: 'computedFrom', - value: function computedFrom(dependencies) { - var deps = dependencies; - if (typeof dependencies === 'string') { - deps = []; - deps.push(dependencies); - } - return this.setValue('dependencies', deps); - } - }, { - key: 'useLocale', - value: function useLocale(localeIdentifier) { - this.setValue('locale', localeIdentifier); - var callbacks = Array.from(this.changedHandlers.values()); - for (var i = 0; i < callbacks.length; i++) { - callbacks[i](); + throw Error('Config not found: ' + identifier); + }; + + ValidationConfig.prototype.setValue = function setValue(identifier, value) { + this.values[identifier] = value; + return this; + }; + + ValidationConfig.prototype.onLocaleChanged = function onLocaleChanged(callback) { + var _this = this; + + if (this.innerConfig !== undefined) { + return this.innerConfig.onLocaleChanged(callback); + } else { + var _ret = (function () { + var id = ++ValidationConfig.uniqueListenerId; + _this.changedHandlers.set(id, callback); + return { + v: function () { + changedHandlers['delete'](id); + } + }; + })(); + + if (typeof _ret === 'object') { + return _ret.v; } - return this; - } - }, { - key: 'locale', - value: function locale() { - return ValidationLocale.Repository.load(this.getValue('locale'), this.getValue('localeResources')); } - }, { - key: 'useViewStrategy', - value: function useViewStrategy(viewStrategy) { - return this.setValue('viewStrategy', viewStrategy); + }; + + ValidationConfig.prototype.getDebounceTimeout = function getDebounceTimeout() { + return this.getValue('debounceTimeout'); + }; + + ValidationConfig.prototype.useDebounceTimeout = function useDebounceTimeout(value) { + return this.setValue('debounceTimeout', value); + }; + + ValidationConfig.prototype.getDependencies = function getDependencies() { + return this.getValue('dependencies'); + }; + + ValidationConfig.prototype.computedFrom = function computedFrom(dependencies) { + var deps = dependencies; + if (typeof dependencies === 'string') { + deps = []; + deps.push(dependencies); } - }, { - key: 'getViewStrategy', - value: function getViewStrategy() { - return this.getValue('viewStrategy'); + return this.setValue('dependencies', deps); + }; + + ValidationConfig.prototype.useLocale = function useLocale(localeIdentifier) { + this.setValue('locale', localeIdentifier); + var callbacks = Array.from(this.changedHandlers.values()); + for (var i = 0; i < callbacks.length; i++) { + callbacks[i](); } - }]); + return this; + }; + + ValidationConfig.prototype.locale = function locale() { + return ValidationLocale.Repository.load(this.getValue('locale'), this.getValue('localeResources')); + }; + + ValidationConfig.prototype.useViewStrategy = function useViewStrategy(viewStrategy) { + return this.setValue('viewStrategy', viewStrategy); + }; + + ValidationConfig.prototype.getViewStrategy = function getViewStrategy() { + return this.getValue('viewStrategy'); + }; return ValidationConfig; })(); diff --git a/dist/system/validation/validation-group-builder.js b/dist/system/validation/validation-group-builder.js index 1e655ef8..9fe809bd 100644 --- a/dist/system/validation/validation-group-builder.js +++ b/dist/system/validation/validation-group-builder.js @@ -1,5 +1,5 @@ System.register(['../validation/validation-rules', '../validation/validation-rules-collection', '../validation/validation-property', '../validation/validation-config'], function (_export) { - var AllRules, AllCollections, ValidationProperty, ValidationConfig, _classCallCheck, _createClass, ValidationGroupBuilder; + var AllRules, AllCollections, ValidationProperty, ValidationConfig, _classCallCheck, ValidationGroupBuilder; return { setters: [function (_validationValidationRules) { @@ -16,8 +16,6 @@ System.register(['../validation/validation-rules', '../validation/validation-rul _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidationGroupBuilder = (function () { function ValidationGroupBuilder(observerLocator, validationGroup) { _classCallCheck(this, ValidationGroupBuilder); @@ -27,250 +25,214 @@ System.register(['../validation/validation-rules', '../validation/validation-rul this.validationGroup = validationGroup; } - _createClass(ValidationGroupBuilder, [{ - key: 'ensure', - value: function ensure(propertyName, configurationCallback) { - var newValidationProperty = null; - this.validationRuleCollections = []; - - for (var i = 0; i < this.validationGroup.validationProperties.length; i++) { - if (this.validationGroup.validationProperties[i].propertyName === propertyName) { - newValidationProperty = this.validationGroup.validationProperties[i]; - if (configurationCallback !== undefined && typeof configurationCallback === 'function') { - throw Error('When creating validation rules on binding path ' + propertyName + ' a configuration callback function was provided, but validation rules have previously already been instantiated for this binding path'); - } - break; - } - } - if (newValidationProperty === null) { - var propertyResult = this.validationGroup.result.addProperty(propertyName); - var config = new ValidationConfig(this.validationGroup.config); + ValidationGroupBuilder.prototype.ensure = function ensure(propertyName, configurationCallback) { + var newValidationProperty = null; + this.validationRuleCollections = []; + + for (var i = 0; i < this.validationGroup.validationProperties.length; i++) { + if (this.validationGroup.validationProperties[i].propertyName === propertyName) { + newValidationProperty = this.validationGroup.validationProperties[i]; if (configurationCallback !== undefined && typeof configurationCallback === 'function') { - configurationCallback(config); + throw Error('When creating validation rules on binding path ' + propertyName + ' a configuration callback function was provided, but validation rules have previously already been instantiated for this binding path'); } - newValidationProperty = new ValidationProperty(this.observerLocator, propertyName, this.validationGroup, propertyResult, config); - this.validationGroup.validationProperties.push(newValidationProperty); - } - this.validationRuleCollections.unshift(newValidationProperty.collectionOfValidationRules); - return this.validationGroup; - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - this.validationRuleCollections[0].isNotEmpty(); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'isGreaterThan', - value: function isGreaterThan(minimumValue) { - return this.passesRule(new AllRules.MinimumValueValidationRule(minimumValue)); - } - }, { - key: 'isGreaterThanOrEqualTo', - value: function isGreaterThanOrEqualTo(minimumValue) { - return this.passesRule(new AllRules.MinimumInclusiveValueValidationRule(minimumValue)); - } - }, { - key: 'isBetween', - value: function isBetween(minimumValue, maximumValue) { - return this.passesRule(new AllRules.BetweenValueValidationRule(minimumValue, maximumValue)); - } - }, { - key: 'isIn', - value: function isIn(collection) { - return this.passesRule(new AllRules.InCollectionValidationRule(collection)); - } - }, { - key: 'isLessThan', - value: function isLessThan(maximumValue) { - return this.passesRule(new AllRules.MaximumValueValidationRule(maximumValue)); - } - }, { - key: 'isLessThanOrEqualTo', - value: function isLessThanOrEqualTo(maximumValue) { - return this.passesRule(new AllRules.MaximumInclusiveValueValidationRule(maximumValue)); - } - }, { - key: 'isEqualTo', - value: function isEqualTo(otherValue, otherValueLabel) { - if (!otherValueLabel) { - return this.passesRule(new AllRules.EqualityValidationRule(otherValue)); - } else { - return this.passesRule(new AllRules.EqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); + break; } } - }, { - key: 'isNotEqualTo', - value: function isNotEqualTo(otherValue, otherValueLabel) { - if (!otherValueLabel) { - return this.passesRule(new AllRules.InEqualityValidationRule(otherValue)); - } else { - return this.passesRule(new AllRules.InEqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); - } - } - }, { - key: 'isEmail', - value: function isEmail() { - return this.passesRule(new AllRules.EmailValidationRule()); - } - }, { - key: 'hasMinLength', - value: function hasMinLength(minimumValue) { - return this.passesRule(new AllRules.MinimumLengthValidationRule(minimumValue)); - } - }, { - key: 'hasMaxLength', - value: function hasMaxLength(maximumValue) { - return this.passesRule(new AllRules.MaximumLengthValidationRule(maximumValue)); - } - }, { - key: 'hasLengthBetween', - value: function hasLengthBetween(minimumValue, maximumValue) { - return this.passesRule(new AllRules.BetweenLengthValidationRule(minimumValue, maximumValue)); - } - }, { - key: 'isNumber', - value: function isNumber() { - return this.passesRule(new AllRules.NumericValidationRule()); - } - }, { - key: 'containsOnlyDigits', - value: function containsOnlyDigits() { - return this.passesRule(new AllRules.DigitValidationRule()); - } - }, { - key: 'containsOnlyAlpha', - value: function containsOnlyAlpha() { - return this.passesRule(new AllRules.AlphaValidationRule()); - } - }, { - key: 'containsOnlyAlphaOrWhitespace', - value: function containsOnlyAlphaOrWhitespace() { - return this.passesRule(new AllRules.AlphaOrWhitespaceValidationRule()); - } - }, { - key: 'containsOnlyAlphanumerics', - value: function containsOnlyAlphanumerics() { - return this.passesRule(new AllRules.AlphaNumericValidationRule()); - } - }, { - key: 'containsOnlyAlphanumericsOrWhitespace', - value: function containsOnlyAlphanumericsOrWhitespace() { - return this.passesRule(new AllRules.AlphaNumericOrWhitespaceValidationRule()); - } - }, { - key: 'isStrongPassword', - value: function isStrongPassword(minimumComplexityLevel) { - if (minimumComplexityLevel === 4) { - return this.passesRule(new AllRules.StrongPasswordValidationRule()); - } else { - return this.passesRule(new AllRules.MediumPasswordValidationRule(minimumComplexityLevel)); + if (newValidationProperty === null) { + var propertyResult = this.validationGroup.result.addProperty(propertyName); + var config = new ValidationConfig(this.validationGroup.config); + if (configurationCallback !== undefined && typeof configurationCallback === 'function') { + configurationCallback(config); } + newValidationProperty = new ValidationProperty(this.observerLocator, propertyName, this.validationGroup, propertyResult, config); + this.validationGroup.validationProperties.push(newValidationProperty); } - }, { - key: 'containsOnly', - value: function containsOnly(regex) { - return this.passesRule(new AllRules.ContainsOnlyValidationRule(regex)); - } - }, { - key: 'matches', - value: function matches(regex) { - return this.passesRule(new AllRules.RegexValidationRule(regex)); - } - }, { - key: 'passes', - value: function passes(customFunction, threshold) { - return this.passesRule(new AllRules.CustomFunctionValidationRule(customFunction, threshold)); - } - }, { - key: 'passesRule', - value: function passesRule(validationRule) { + this.validationRuleCollections.unshift(newValidationProperty.collectionOfValidationRules); + return this.validationGroup; + }; - this.validationRuleCollections[0].addValidationRule(validationRule); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'checkLast', - value: function checkLast() { - var validationProperty = this.validationGroup.validationProperties[this.validationGroup.validationProperties.length - 1]; - validationProperty.validateCurrentValue(false); - } - }, { - key: 'withMessage', - value: function withMessage(message) { - this.validationRuleCollections[0].withMessage(message); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'if', - value: function _if(conditionExpression) { - var conditionalCollection = new AllCollections.SwitchCaseValidationRulesCollection(conditionExpression); - conditionalCollection['case'](true); - this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); - this.validationRuleCollections.unshift(conditionalCollection); - return this.validationGroup; - } - }, { - key: 'else', - value: function _else() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'else\''; + ValidationGroupBuilder.prototype.isNotEmpty = function isNotEmpty() { + this.validationRuleCollections[0].isNotEmpty(); + this.checkLast(); + return this.validationGroup; + }; - this.validationRuleCollections[0]['default'](); - return this.validationGroup; - } - }, { - key: 'endIf', - value: function endIf() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; - this.validationRuleCollections.shift(); - this.checkLast(); - return this.validationGroup; - } - }, { - key: 'switch', - value: function _switch(conditionExpression) { - var _this = this; - - var condition = conditionExpression; - if (condition === undefined) { - (function () { - var observer = _this.validationGroup.validationProperties[_this.validationGroup.validationProperties.length - 1].observer; - condition = function () { - return observer.getValue(); - }; - })(); - } - var conditionalCollection = new AllCollections.SwitchCaseValidationRulesCollection(condition); - this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); - this.validationRuleCollections.unshift(conditionalCollection); - return this.validationGroup; - } - }, { - key: 'case', - value: function _case(caseLabel) { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; - this.validationRuleCollections[0]['case'](caseLabel); - return this.validationGroup; + ValidationGroupBuilder.prototype.isGreaterThan = function isGreaterThan(minimumValue) { + return this.passesRule(new AllRules.MinimumValueValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.isGreaterThanOrEqualTo = function isGreaterThanOrEqualTo(minimumValue) { + return this.passesRule(new AllRules.MinimumInclusiveValueValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.isBetween = function isBetween(minimumValue, maximumValue) { + return this.passesRule(new AllRules.BetweenValueValidationRule(minimumValue, maximumValue)); + }; + + ValidationGroupBuilder.prototype.isIn = function isIn(collection) { + return this.passesRule(new AllRules.InCollectionValidationRule(collection)); + }; + + ValidationGroupBuilder.prototype.isLessThan = function isLessThan(maximumValue) { + return this.passesRule(new AllRules.MaximumValueValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.isLessThanOrEqualTo = function isLessThanOrEqualTo(maximumValue) { + return this.passesRule(new AllRules.MaximumInclusiveValueValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.isEqualTo = function isEqualTo(otherValue, otherValueLabel) { + if (!otherValueLabel) { + return this.passesRule(new AllRules.EqualityValidationRule(otherValue)); + } else { + return this.passesRule(new AllRules.EqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); } - }, { - key: 'default', - value: function _default() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; - this.validationRuleCollections[0]['default'](); - return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.isNotEqualTo = function isNotEqualTo(otherValue, otherValueLabel) { + if (!otherValueLabel) { + return this.passesRule(new AllRules.InEqualityValidationRule(otherValue)); + } else { + return this.passesRule(new AllRules.InEqualityWithOtherLabelValidationRule(otherValue, otherValueLabel)); } - }, { - key: 'endSwitch', - value: function endSwitch() { - if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; - this.validationRuleCollections.shift(); - this.checkLast(); - return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.isEmail = function isEmail() { + return this.passesRule(new AllRules.EmailValidationRule()); + }; + + ValidationGroupBuilder.prototype.hasMinLength = function hasMinLength(minimumValue) { + return this.passesRule(new AllRules.MinimumLengthValidationRule(minimumValue)); + }; + + ValidationGroupBuilder.prototype.hasMaxLength = function hasMaxLength(maximumValue) { + return this.passesRule(new AllRules.MaximumLengthValidationRule(maximumValue)); + }; + + ValidationGroupBuilder.prototype.hasLengthBetween = function hasLengthBetween(minimumValue, maximumValue) { + return this.passesRule(new AllRules.BetweenLengthValidationRule(minimumValue, maximumValue)); + }; + + ValidationGroupBuilder.prototype.isNumber = function isNumber() { + return this.passesRule(new AllRules.NumericValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyDigits = function containsOnlyDigits() { + return this.passesRule(new AllRules.DigitValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlpha = function containsOnlyAlpha() { + return this.passesRule(new AllRules.AlphaValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphaOrWhitespace = function containsOnlyAlphaOrWhitespace() { + return this.passesRule(new AllRules.AlphaOrWhitespaceValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphanumerics = function containsOnlyAlphanumerics() { + return this.passesRule(new AllRules.AlphaNumericValidationRule()); + }; + + ValidationGroupBuilder.prototype.containsOnlyAlphanumericsOrWhitespace = function containsOnlyAlphanumericsOrWhitespace() { + return this.passesRule(new AllRules.AlphaNumericOrWhitespaceValidationRule()); + }; + + ValidationGroupBuilder.prototype.isStrongPassword = function isStrongPassword(minimumComplexityLevel) { + if (minimumComplexityLevel === 4) { + return this.passesRule(new AllRules.StrongPasswordValidationRule()); + } else { + return this.passesRule(new AllRules.MediumPasswordValidationRule(minimumComplexityLevel)); } - }]); + }; + + ValidationGroupBuilder.prototype.containsOnly = function containsOnly(regex) { + return this.passesRule(new AllRules.ContainsOnlyValidationRule(regex)); + }; + + ValidationGroupBuilder.prototype.matches = function matches(regex) { + return this.passesRule(new AllRules.RegexValidationRule(regex)); + }; + + ValidationGroupBuilder.prototype.passes = function passes(customFunction, threshold) { + return this.passesRule(new AllRules.CustomFunctionValidationRule(customFunction, threshold)); + }; + + ValidationGroupBuilder.prototype.passesRule = function passesRule(validationRule) { + + this.validationRuleCollections[0].addValidationRule(validationRule); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.checkLast = function checkLast() { + var validationProperty = this.validationGroup.validationProperties[this.validationGroup.validationProperties.length - 1]; + validationProperty.validateCurrentValue(false); + }; + + ValidationGroupBuilder.prototype.withMessage = function withMessage(message) { + this.validationRuleCollections[0].withMessage(message); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['if'] = function _if(conditionExpression) { + var conditionalCollection = new AllCollections.SwitchCaseValidationRulesCollection(conditionExpression); + conditionalCollection['case'](true); + this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); + this.validationRuleCollections.unshift(conditionalCollection); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['else'] = function _else() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'else\''; + + this.validationRuleCollections[0]['default'](); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.endIf = function endIf() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; + this.validationRuleCollections.shift(); + this.checkLast(); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['switch'] = function _switch(conditionExpression) { + var _this = this; + + var condition = conditionExpression; + if (condition === undefined) { + (function () { + var observer = _this.validationGroup.validationProperties[_this.validationGroup.validationProperties.length - 1].observer; + condition = function () { + return observer.getValue(); + }; + })(); + } + var conditionalCollection = new AllCollections.SwitchCaseValidationRulesCollection(condition); + this.validationRuleCollections[0].addValidationRuleCollection(conditionalCollection); + this.validationRuleCollections.unshift(conditionalCollection); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['case'] = function _case(caseLabel) { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; + this.validationRuleCollections[0]['case'](caseLabel); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype['default'] = function _default() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'case\''; + this.validationRuleCollections[0]['default'](); + return this.validationGroup; + }; + + ValidationGroupBuilder.prototype.endSwitch = function endSwitch() { + if (!this.validationRuleCollections[0]['default']) throw 'Invalid statement: \'endIf\''; + this.validationRuleCollections.shift(); + this.checkLast(); + return this.validationGroup; + }; return ValidationGroupBuilder; })(); diff --git a/dist/system/validation/validation-group.js b/dist/system/validation/validation-group.js index b9ec6e69..f8bbd2db 100644 --- a/dist/system/validation/validation-group.js +++ b/dist/system/validation/validation-group.js @@ -1,5 +1,5 @@ System.register(['../validation/validation-group-builder', '../validation/validation-result', '../validation/validation-locale'], function (_export) { - var ValidationGroupBuilder, ValidationResult, ValidationLocale, _classCallCheck, _createClass, ValidationGroup; + var ValidationGroupBuilder, ValidationResult, ValidationLocale, _classCallCheck, ValidationGroup; return { setters: [function (_validationValidationGroupBuilder) { @@ -14,8 +14,6 @@ System.register(['../validation/validation-group-builder', '../validation/valida _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidationGroup = (function () { function ValidationGroup(subject, observerLocator, config) { var _this = this; @@ -39,331 +37,288 @@ System.register(['../validation/validation-group-builder', '../validation/valida } } - _createClass(ValidationGroup, [{ - key: 'destroy', - value: function destroy() { - this.onDestroy(); - } - }, { - key: 'clear', - value: function clear() { - this.validationProperties.forEach(function (prop) { - prop.clear(); - }); - this.result.clear(); - } - }, { - key: 'onBreezeEntity', - value: function onBreezeEntity() { - var _this2 = this; - - var breezeEntity = this.subject; - var me = this; - this.onPropertyValidate(function (propertyBindingPath) { - _this2.passes(function () { - breezeEntity.entityAspect.validateProperty(propertyBindingPath); - var errors = breezeEntity.entityAspect.getValidationErrors(propertyBindingPath); - if (errors.length === 0) return true;else return errors[0].errorMessage; - }); - }); - this.onValidate(function () { - breezeEntity.entityAspect.validateEntity(); - return {}; + ValidationGroup.prototype.destroy = function destroy() { + this.onDestroy(); + }; + + ValidationGroup.prototype.clear = function clear() { + this.validationProperties.forEach(function (prop) { + prop.clear(); + }); + this.result.clear(); + }; + + ValidationGroup.prototype.onBreezeEntity = function onBreezeEntity() { + var _this2 = this; + + var breezeEntity = this.subject; + var me = this; + this.onPropertyValidate(function (propertyBindingPath) { + _this2.passes(function () { + breezeEntity.entityAspect.validateProperty(propertyBindingPath); + var errors = breezeEntity.entityAspect.getValidationErrors(propertyBindingPath); + if (errors.length === 0) return true;else return errors[0].errorMessage; }); + }); + this.onValidate(function () { + breezeEntity.entityAspect.validateEntity(); + return {}; + }); - breezeEntity.entityAspect.validationErrorsChanged.subscribe(function () { - breezeEntity.entityAspect.getValidationErrors().forEach(function (validationError) { - var propertyName = validationError.propertyName; - if (!me.result.properties[propertyName]) { - me.ensure(propertyName); - } + breezeEntity.entityAspect.validationErrorsChanged.subscribe(function () { + breezeEntity.entityAspect.getValidationErrors().forEach(function (validationError) { + var propertyName = validationError.propertyName; + if (!me.result.properties[propertyName]) { + me.ensure(propertyName); + } - var currentResultProp = me.result.addProperty(propertyName); - if (currentResultProp.isValid) { + var currentResultProp = me.result.addProperty(propertyName); + if (currentResultProp.isValid) { - currentResultProp.setValidity({ - isValid: false, - message: validationError.errorMessage, - failingRule: 'breeze', - latestValue: currentResultProp.latestValue - }, true); - } - }); + currentResultProp.setValidity({ + isValid: false, + message: validationError.errorMessage, + failingRule: 'breeze', + latestValue: currentResultProp.latestValue + }, true); + } }); - } - }, { - key: 'validate', - value: function validate() { - var _this3 = this; + }); + }; - var forceDirty = arguments[0] === undefined ? true : arguments[0]; - var forceExecution = arguments[1] === undefined ? true : arguments[1]; + ValidationGroup.prototype.validate = function validate() { + var _this3 = this; - this.isValidating = true; - var promise = Promise.resolve(true); + var forceDirty = arguments[0] === undefined ? true : arguments[0]; + var forceExecution = arguments[1] === undefined ? true : arguments[1]; - var _loop = function (i) { - var validatorProperty = _this3.validationProperties[i]; - promise = promise.then(function () { - return validatorProperty.validateCurrentValue(forceDirty, forceExecution); - }); - }; + this.isValidating = true; + var promise = Promise.resolve(true); - for (var i = this.validationProperties.length - 1; i >= 0; i--) { - _loop(i); - } - promise = promise['catch'](function () { - console.log('Should never get here: a validation property should always resolve to true/false!'); - debugger; - throw Error('Should never get here: a validation property should always resolve to true/false!'); + var _loop = function (i) { + var validatorProperty = _this3.validationProperties[i]; + promise = promise.then(function () { + return validatorProperty.validateCurrentValue(forceDirty, forceExecution); }); + }; - this.onValidateCallbacks.forEach(function (onValidateCallback) { - promise = promise.then(function () { - return _this3.config.locale(); - }).then(function (locale) { - return Promise.resolve(onValidateCallback.validationFunction()).then(function (callbackResult) { - for (var prop in callbackResult) { - if (!_this3.result.properties[prop]) { - _this3.ensure(prop); + for (var i = this.validationProperties.length - 1; i >= 0; i--) { + _loop(i); + } + promise = promise['catch'](function () { + console.log('Should never get here: a validation property should always resolve to true/false!'); + debugger; + throw Error('Should never get here: a validation property should always resolve to true/false!'); + }); + + this.onValidateCallbacks.forEach(function (onValidateCallback) { + promise = promise.then(function () { + return _this3.config.locale(); + }).then(function (locale) { + return Promise.resolve(onValidateCallback.validationFunction()).then(function (callbackResult) { + for (var prop in callbackResult) { + if (!_this3.result.properties[prop]) { + _this3.ensure(prop); + } + var resultProp = _this3.result.addProperty(prop); + var result = callbackResult[prop]; + var newPropResult = { + latestValue: resultProp.latestValue + }; + if (result === true || result === null || result === '') { + if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { + newPropResult.failingRule = null; + newPropResult.message = ''; + newPropResult.isValid = true; + resultProp.setValidity(newPropResult, true); } - var resultProp = _this3.result.addProperty(prop); - var result = callbackResult[prop]; - var newPropResult = { - latestValue: resultProp.latestValue - }; - if (result === true || result === null || result === '') { - if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { - newPropResult.failingRule = null; - newPropResult.message = ''; - newPropResult.isValid = true; - resultProp.setValidity(newPropResult, true); - } - } else { - if (resultProp.isValid) { - newPropResult.failingRule = 'onValidateCallback'; - newPropResult.isValid = false; - if (typeof result === 'string') { - newPropResult.message = result; - } else { - newPropResult.message = locale.translate(newPropResult.failingRule); - } - resultProp.setValidity(newPropResult, true); + } else { + if (resultProp.isValid) { + newPropResult.failingRule = 'onValidateCallback'; + newPropResult.isValid = false; + if (typeof result === 'string') { + newPropResult.message = result; + } else { + newPropResult.message = locale.translate(newPropResult.failingRule); } + resultProp.setValidity(newPropResult, true); } } - _this3.result.checkValidity(); - }, function (a, b, c, d, e) { - debugger; - _this3.result.isValid = false; - if (onValidateCallback.validationFunctionFailedCallback) { - onValidateCallback.validationFunctionFailedCallback(a, b, c, d, e); - } - }); + } + _this3.result.checkValidity(); + }, function (a, b, c, d, e) { + debugger; + _this3.result.isValid = false; + if (onValidateCallback.validationFunctionFailedCallback) { + onValidateCallback.validationFunctionFailedCallback(a, b, c, d, e); + } }); }); - promise = promise.then(function () { - _this3.isValidating = false; - if (_this3.result.isValid) { - return Promise.resolve(_this3.result); - } else { - return Promise.reject(_this3.result); - } - }); - return promise; - } - }, { - key: 'onValidate', - value: function onValidate(validationFunction, validationFunctionFailedCallback) { - this.onValidateCallbacks.push({ validationFunction: validationFunction, validationFunctionFailedCallback: validationFunctionFailedCallback }); - return this; - } - }, { - key: 'onPropertyValidate', - value: function onPropertyValidate(validationFunction) { - this.onPropertyValidationCallbacks.push(validationFunction); - return this; - } - }, { - key: 'ensure', - value: function ensure(bindingPath, configCallback) { - this.builder.ensure(bindingPath, configCallback); - this.onPropertyValidationCallbacks.forEach(function (callback) { - callback(bindingPath); - }); - return this; - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - return this.builder.isNotEmpty(); - } - }, { - key: 'isGreaterThanOrEqualTo', - value: function isGreaterThanOrEqualTo(minimumValue) { - return this.builder.isGreaterThanOrEqualTo(minimumValue); - } - }, { - key: 'isGreaterThan', - value: function isGreaterThan(minimumValue) { - return this.builder.isGreaterThan(minimumValue); - } - }, { - key: 'isBetween', - value: function isBetween(minimumValue, maximumValue) { - return this.builder.isBetween(minimumValue, maximumValue); - } - }, { - key: 'isLessThanOrEqualTo', - value: function isLessThanOrEqualTo(maximumValue) { - return this.builder.isLessThanOrEqualTo(maximumValue); - } - }, { - key: 'isLessThan', - value: function isLessThan(maximumValue) { - return this.builder.isLessThan(maximumValue); - } - }, { - key: 'isEqualTo', - value: function isEqualTo(otherValue, otherValueLabel) { - return this.builder.isEqualTo(otherValue, otherValueLabel); - } - }, { - key: 'isNotEqualTo', - value: function isNotEqualTo(otherValue, otherValueLabel) { - return this.builder.isNotEqualTo(otherValue, otherValueLabel); - } - }, { - key: 'isEmail', - value: function isEmail() { - return this.builder.isEmail(); - } - }, { - key: 'isIn', - value: function isIn(collection) { - return this.builder.isIn(collection); - } - }, { - key: 'hasMinLength', - value: function hasMinLength(minimumValue) { - return this.builder.hasMinLength(minimumValue); - } - }, { - key: 'hasMaxLength', - value: function hasMaxLength(maximumValue) { - return this.builder.hasMaxLength(maximumValue); - } - }, { - key: 'hasLengthBetween', - value: function hasLengthBetween(minimumValue, maximumValue) { - return this.builder.hasLengthBetween(minimumValue, maximumValue); - } - }, { - key: 'isNumber', - value: function isNumber() { - return this.builder.isNumber(); - } - }, { - key: 'containsOnlyDigits', - value: function containsOnlyDigits() { - return this.builder.containsOnlyDigits(); - } - }, { - key: 'containsOnly', - value: function containsOnly(regex) { - return this.builder.containsOnly(regex); - } - }, { - key: 'containsOnlyAlpha', - value: function containsOnlyAlpha() { - return this.builder.containsOnlyAlpha(); - } - }, { - key: 'containsOnlyAlphaOrWhitespace', - value: function containsOnlyAlphaOrWhitespace() { - return this.builder.containsOnlyAlphaOrWhitespace(); - } - }, { - key: 'containsOnlyLetters', - value: function containsOnlyLetters() { - return this.builder.containsOnlyAlpha(); - } - }, { - key: 'containsOnlyLettersOrWhitespace', - value: function containsOnlyLettersOrWhitespace() { - return this.builder.containsOnlyAlphaOrWhitespace(); - } - }, { - key: 'containsOnlyAlphanumerics', - value: function containsOnlyAlphanumerics() { - return this.builder.containsOnlyAlphanumerics(); - } - }, { - key: 'containsOnlyAlphanumericsOrWhitespace', - value: function containsOnlyAlphanumericsOrWhitespace() { - return this.builder.containsOnlyAlphanumericsOrWhitespace(); - } - }, { - key: 'isStrongPassword', - value: function isStrongPassword(minimumComplexityLevel) { - return this.builder.isStrongPassword(minimumComplexityLevel); - } - }, { - key: 'matches', - value: function matches(regex) { - return this.builder.matches(regex); - } - }, { - key: 'passes', - value: function passes(customFunction, threshold) { - return this.builder.passes(customFunction, threshold); - } - }, { - key: 'passesRule', - value: function passesRule(validationRule) { - return this.builder.passesRule(validationRule); - } - }, { - key: 'if', - value: function _if(conditionExpression, threshold) { - return this.builder['if'](conditionExpression, threshold); - } - }, { - key: 'else', - value: function _else() { - return this.builder['else'](); - } - }, { - key: 'endIf', - value: function endIf() { - return this.builder.endIf(); - } - }, { - key: 'switch', - value: function _switch(conditionExpression) { - return this.builder['switch'](conditionExpression); - } - }, { - key: 'case', - value: function _case(caseLabel) { - return this.builder['case'](caseLabel); - } - }, { - key: 'default', - value: function _default() { - return this.builder['default'](); - } - }, { - key: 'endSwitch', - value: function endSwitch() { - return this.builder.endSwitch(); - } - }, { - key: 'withMessage', - value: function withMessage(message) { - return this.builder.withMessage(message); - } - }]); + }); + promise = promise.then(function () { + _this3.isValidating = false; + if (_this3.result.isValid) { + return Promise.resolve(_this3.result); + } else { + return Promise.reject(_this3.result); + } + }); + return promise; + }; + + ValidationGroup.prototype.onValidate = function onValidate(validationFunction, validationFunctionFailedCallback) { + this.onValidateCallbacks.push({ validationFunction: validationFunction, validationFunctionFailedCallback: validationFunctionFailedCallback }); + return this; + }; + + ValidationGroup.prototype.onPropertyValidate = function onPropertyValidate(validationFunction) { + this.onPropertyValidationCallbacks.push(validationFunction); + return this; + }; + + ValidationGroup.prototype.ensure = function ensure(bindingPath, configCallback) { + this.builder.ensure(bindingPath, configCallback); + this.onPropertyValidationCallbacks.forEach(function (callback) { + callback(bindingPath); + }); + return this; + }; + + ValidationGroup.prototype.isNotEmpty = function isNotEmpty() { + return this.builder.isNotEmpty(); + }; + + ValidationGroup.prototype.isGreaterThanOrEqualTo = function isGreaterThanOrEqualTo(minimumValue) { + return this.builder.isGreaterThanOrEqualTo(minimumValue); + }; + + ValidationGroup.prototype.isGreaterThan = function isGreaterThan(minimumValue) { + return this.builder.isGreaterThan(minimumValue); + }; + + ValidationGroup.prototype.isBetween = function isBetween(minimumValue, maximumValue) { + return this.builder.isBetween(minimumValue, maximumValue); + }; + + ValidationGroup.prototype.isLessThanOrEqualTo = function isLessThanOrEqualTo(maximumValue) { + return this.builder.isLessThanOrEqualTo(maximumValue); + }; + + ValidationGroup.prototype.isLessThan = function isLessThan(maximumValue) { + return this.builder.isLessThan(maximumValue); + }; + + ValidationGroup.prototype.isEqualTo = function isEqualTo(otherValue, otherValueLabel) { + return this.builder.isEqualTo(otherValue, otherValueLabel); + }; + + ValidationGroup.prototype.isNotEqualTo = function isNotEqualTo(otherValue, otherValueLabel) { + return this.builder.isNotEqualTo(otherValue, otherValueLabel); + }; + + ValidationGroup.prototype.isEmail = function isEmail() { + return this.builder.isEmail(); + }; + + ValidationGroup.prototype.isIn = function isIn(collection) { + return this.builder.isIn(collection); + }; + + ValidationGroup.prototype.hasMinLength = function hasMinLength(minimumValue) { + return this.builder.hasMinLength(minimumValue); + }; + + ValidationGroup.prototype.hasMaxLength = function hasMaxLength(maximumValue) { + return this.builder.hasMaxLength(maximumValue); + }; + + ValidationGroup.prototype.hasLengthBetween = function hasLengthBetween(minimumValue, maximumValue) { + return this.builder.hasLengthBetween(minimumValue, maximumValue); + }; + + ValidationGroup.prototype.isNumber = function isNumber() { + return this.builder.isNumber(); + }; + + ValidationGroup.prototype.containsOnlyDigits = function containsOnlyDigits() { + return this.builder.containsOnlyDigits(); + }; + + ValidationGroup.prototype.containsOnly = function containsOnly(regex) { + return this.builder.containsOnly(regex); + }; + + ValidationGroup.prototype.containsOnlyAlpha = function containsOnlyAlpha() { + return this.builder.containsOnlyAlpha(); + }; + + ValidationGroup.prototype.containsOnlyAlphaOrWhitespace = function containsOnlyAlphaOrWhitespace() { + return this.builder.containsOnlyAlphaOrWhitespace(); + }; + + ValidationGroup.prototype.containsOnlyLetters = function containsOnlyLetters() { + return this.builder.containsOnlyAlpha(); + }; + + ValidationGroup.prototype.containsOnlyLettersOrWhitespace = function containsOnlyLettersOrWhitespace() { + return this.builder.containsOnlyAlphaOrWhitespace(); + }; + + ValidationGroup.prototype.containsOnlyAlphanumerics = function containsOnlyAlphanumerics() { + return this.builder.containsOnlyAlphanumerics(); + }; + + ValidationGroup.prototype.containsOnlyAlphanumericsOrWhitespace = function containsOnlyAlphanumericsOrWhitespace() { + return this.builder.containsOnlyAlphanumericsOrWhitespace(); + }; + + ValidationGroup.prototype.isStrongPassword = function isStrongPassword(minimumComplexityLevel) { + return this.builder.isStrongPassword(minimumComplexityLevel); + }; + + ValidationGroup.prototype.matches = function matches(regex) { + return this.builder.matches(regex); + }; + + ValidationGroup.prototype.passes = function passes(customFunction, threshold) { + return this.builder.passes(customFunction, threshold); + }; + + ValidationGroup.prototype.passesRule = function passesRule(validationRule) { + return this.builder.passesRule(validationRule); + }; + + ValidationGroup.prototype['if'] = function _if(conditionExpression, threshold) { + return this.builder['if'](conditionExpression, threshold); + }; + + ValidationGroup.prototype['else'] = function _else() { + return this.builder['else'](); + }; + + ValidationGroup.prototype.endIf = function endIf() { + return this.builder.endIf(); + }; + + ValidationGroup.prototype['switch'] = function _switch(conditionExpression) { + return this.builder['switch'](conditionExpression); + }; + + ValidationGroup.prototype['case'] = function _case(caseLabel) { + return this.builder['case'](caseLabel); + }; + + ValidationGroup.prototype['default'] = function _default() { + return this.builder['default'](); + }; + + ValidationGroup.prototype.endSwitch = function endSwitch() { + return this.builder.endSwitch(); + }; + + ValidationGroup.prototype.withMessage = function withMessage(message) { + return this.builder.withMessage(message); + }; return ValidationGroup; })(); diff --git a/dist/system/validation/validation-locale.js b/dist/system/validation/validation-locale.js index a859a2a0..49f63e8f 100644 --- a/dist/system/validation/validation-locale.js +++ b/dist/system/validation/validation-locale.js @@ -1,5 +1,5 @@ System.register([], function (_export) { - var _classCallCheck, _createClass, ValidationLocale, ValidationLocaleRepository; + var _classCallCheck, ValidationLocale, ValidationLocaleRepository; return { setters: [], @@ -8,8 +8,6 @@ System.register([], function (_export) { _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidationLocale = (function () { function ValidationLocale(defaults, data) { _classCallCheck(this, ValidationLocale); @@ -18,41 +16,36 @@ System.register([], function (_export) { this.currentLocale = data; } - _createClass(ValidationLocale, [{ - key: 'getValueFor', - value: function getValueFor(identifier, category) { - if (this.currentLocale && this.currentLocale[category]) { - var currentLocaleSetting = this.currentLocale[category][identifier]; - if (currentLocaleSetting !== undefined && currentLocaleSetting !== null) { - return currentLocaleSetting; - } + ValidationLocale.prototype.getValueFor = function getValueFor(identifier, category) { + if (this.currentLocale && this.currentLocale[category]) { + var currentLocaleSetting = this.currentLocale[category][identifier]; + if (currentLocaleSetting !== undefined && currentLocaleSetting !== null) { + return currentLocaleSetting; } - if (this.defaults[category]) { - var defaultSetting = this.defaults[category][identifier]; - if (defaultSetting !== undefined && defaultSetting !== null) { - return defaultSetting; - } + } + if (this.defaults[category]) { + var defaultSetting = this.defaults[category][identifier]; + if (defaultSetting !== undefined && defaultSetting !== null) { + return defaultSetting; } - throw 'validation: I18N: Could not find: ' + identifier + ' in category: ' + category; } - }, { - key: 'setting', - value: function setting(settingIdentifier) { - return this.getValueFor(settingIdentifier, 'settings'); + throw 'validation: I18N: Could not find: ' + identifier + ' in category: ' + category; + }; + + ValidationLocale.prototype.setting = function setting(settingIdentifier) { + return this.getValueFor(settingIdentifier, 'settings'); + }; + + ValidationLocale.prototype.translate = function translate(translationIdentifier, newValue, threshold) { + var translation = this.getValueFor(translationIdentifier, 'messages'); + if (typeof translation === 'function') { + return translation(newValue, threshold); } - }, { - key: 'translate', - value: function translate(translationIdentifier, newValue, threshold) { - var translation = this.getValueFor(translationIdentifier, 'messages'); - if (typeof translation === 'function') { - return translation(newValue, threshold); - } - if (typeof translation === 'string') { - return translation; - } - throw 'Validation message for ' + translationIdentifier + 'was in an unsupported format'; + if (typeof translation === 'string') { + return translation; } - }]); + throw 'Validation message for ' + translationIdentifier + 'was in an unsupported format'; + }; return ValidationLocale; })(); @@ -73,33 +66,29 @@ System.register([], function (_export) { }; } - _createClass(ValidationLocaleRepository, [{ - key: 'load', - value: function load(localeIdentifier, basePath) { - var _this = this; + ValidationLocaleRepository.prototype.load = function load(localeIdentifier, basePath) { + var _this = this; - if (!basePath) basePath = 'aurelia-validation/resources/'; - return new Promise(function (resolve, reject) { - if (_this.instances.has(localeIdentifier)) { - var locale = _this.instances.get(localeIdentifier); + if (!basePath) basePath = 'aurelia-validation/resources/'; + return new Promise(function (resolve, reject) { + if (_this.instances.has(localeIdentifier)) { + var locale = _this.instances.get(localeIdentifier); + resolve(locale); + } else { + System['import'](basePath + localeIdentifier).then(function (resource) { + var locale = _this.addLocale(localeIdentifier, resource.data); resolve(locale); - } else { - System['import'](basePath + localeIdentifier).then(function (resource) { - var locale = _this.addLocale(localeIdentifier, resource.data); - resolve(locale); - }); - } - }); - } - }, { - key: 'addLocale', - value: function addLocale(localeIdentifier, data) { - var instance = new ValidationLocale(this.defaults, data); - this.instances.set(localeIdentifier, instance); - if (this['default'] === null) this['default'] = instance; - return instance; - } - }]); + }); + } + }); + }; + + ValidationLocaleRepository.prototype.addLocale = function addLocale(localeIdentifier, data) { + var instance = new ValidationLocale(this.defaults, data); + this.instances.set(localeIdentifier, instance); + if (this['default'] === null) this['default'] = instance; + return instance; + }; return ValidationLocaleRepository; })(); diff --git a/dist/system/validation/validation-property.js b/dist/system/validation/validation-property.js index d7bb5add..18772a5c 100644 --- a/dist/system/validation/validation-property.js +++ b/dist/system/validation/validation-property.js @@ -1,5 +1,5 @@ System.register(['../validation/validation-rules-collection', '../validation/path-observer', '../validation/debouncer'], function (_export) { - var AllCollections, PathObserver, Debouncer, _classCallCheck, _createClass, ValidationProperty; + var AllCollections, PathObserver, Debouncer, _classCallCheck, ValidationProperty; return { setters: [function (_validationValidationRulesCollection) { @@ -14,8 +14,6 @@ System.register(['../validation/validation-rules-collection', '../validation/pat _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidationProperty = (function () { function ValidationProperty(observerLocator, propertyName, validationGroup, propertyResult, config) { var _this = this; @@ -55,46 +53,40 @@ System.register(['../validation/validation-rules-collection', '../validation/pat } } - _createClass(ValidationProperty, [{ - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); - this.collectionOfValidationRules.addValidationRule(validationRule); - this.validateCurrentValue(false); - } - }, { - key: 'validateCurrentValue', - value: function validateCurrentValue(forceDirty, forceExecution) { - return this.validate(this.observer.getValue(), forceDirty, forceExecution); - } - }, { - key: 'clear', - value: function clear() { - this.latestValue = this.observer.getValue(); - this.propertyResult.clear(); - } - }, { - key: 'validate', - value: function validate(newValue, shouldBeDirty, forceExecution) { - var _this2 = this; - - if (!this.propertyResult.isDirty && shouldBeDirty || this.latestValue !== newValue || forceExecution) { - this.latestValue = newValue; - return this.config.locale().then(function (locale) { - return _this2.collectionOfValidationRules.validate(newValue, locale).then(function (validationResponse) { - if (_this2.latestValue === validationResponse.latestValue) _this2.propertyResult.setValidity(validationResponse, shouldBeDirty); - return validationResponse.isValid; - })['catch'](function (err) { - console.log('Unexpected behavior: a validation-rules-collection should always fulfil', err); - debugger; - throw Error('Unexpected behavior: a validation-rules-collection should always fulfil'); - }); - }, function () { - throw Error('An exception occurred while trying to load the locale'); + ValidationProperty.prototype.addValidationRule = function addValidationRule(validationRule) { + if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); + this.collectionOfValidationRules.addValidationRule(validationRule); + this.validateCurrentValue(false); + }; + + ValidationProperty.prototype.validateCurrentValue = function validateCurrentValue(forceDirty, forceExecution) { + return this.validate(this.observer.getValue(), forceDirty, forceExecution); + }; + + ValidationProperty.prototype.clear = function clear() { + this.latestValue = this.observer.getValue(); + this.propertyResult.clear(); + }; + + ValidationProperty.prototype.validate = function validate(newValue, shouldBeDirty, forceExecution) { + var _this2 = this; + + if (!this.propertyResult.isDirty && shouldBeDirty || this.latestValue !== newValue || forceExecution) { + this.latestValue = newValue; + return this.config.locale().then(function (locale) { + return _this2.collectionOfValidationRules.validate(newValue, locale).then(function (validationResponse) { + if (_this2.latestValue === validationResponse.latestValue) _this2.propertyResult.setValidity(validationResponse, shouldBeDirty); + return validationResponse.isValid; + })['catch'](function (err) { + console.log('Unexpected behavior: a validation-rules-collection should always fulfil', err); + debugger; + throw Error('Unexpected behavior: a validation-rules-collection should always fulfil'); }); - } + }, function () { + throw Error('An exception occurred while trying to load the locale'); + }); } - }]); + }; return ValidationProperty; })(); diff --git a/dist/system/validation/validation-result.js b/dist/system/validation/validation-result.js index 687302e4..418d3e3b 100644 --- a/dist/system/validation/validation-result.js +++ b/dist/system/validation/validation-result.js @@ -1,5 +1,5 @@ System.register([], function (_export) { - var _classCallCheck, _createClass, ValidationResult, ValidationResultProperty; + var _classCallCheck, ValidationResult, ValidationResultProperty; return { setters: [], @@ -8,8 +8,6 @@ System.register([], function (_export) { _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidationResult = (function () { function ValidationResult() { _classCallCheck(this, ValidationResult); @@ -18,31 +16,26 @@ System.register([], function (_export) { this.properties = {}; } - _createClass(ValidationResult, [{ - key: 'addProperty', - value: function addProperty(name) { - if (!this.properties[name]) { - this.properties[name] = new ValidationResultProperty(this); - } - return this.properties[name]; + ValidationResult.prototype.addProperty = function addProperty(name) { + if (!this.properties[name]) { + this.properties[name] = new ValidationResultProperty(this); } - }, { - key: 'checkValidity', - value: function checkValidity() { - for (var propertyName in this.properties) { - if (!this.properties[propertyName].isValid) { - this.isValid = false; - return; - } + return this.properties[name]; + }; + + ValidationResult.prototype.checkValidity = function checkValidity() { + for (var propertyName in this.properties) { + if (!this.properties[propertyName].isValid) { + this.isValid = false; + return; } - this.isValid = true; } - }, { - key: 'clear', - value: function clear() { - this.isValid = true; - } - }]); + this.isValid = true; + }; + + ValidationResult.prototype.clear = function clear() { + this.isValid = true; + }; return ValidationResult; })(); @@ -58,46 +51,40 @@ System.register([], function (_export) { this.clear(); } - _createClass(ValidationResultProperty, [{ - key: 'clear', - value: function clear() { - this.isValid = true; - this.isDirty = false; - this.message = ''; - this.failingRule = null; - this.latestValue = null; - this.notifyObserversOfChange(); - } - }, { - key: 'onValidate', - value: function onValidate(onValidateCallback) { - this.onValidateCallbacks.push(onValidateCallback); - } - }, { - key: 'notifyObserversOfChange', - value: function notifyObserversOfChange() { - for (var i = 0; i < this.onValidateCallbacks.length; i++) { - var callback = this.onValidateCallbacks[i]; - callback(this); - } + ValidationResultProperty.prototype.clear = function clear() { + this.isValid = true; + this.isDirty = false; + this.message = ''; + this.failingRule = null; + this.latestValue = null; + this.notifyObserversOfChange(); + }; + + ValidationResultProperty.prototype.onValidate = function onValidate(onValidateCallback) { + this.onValidateCallbacks.push(onValidateCallback); + }; + + ValidationResultProperty.prototype.notifyObserversOfChange = function notifyObserversOfChange() { + for (var i = 0; i < this.onValidateCallbacks.length; i++) { + var callback = this.onValidateCallbacks[i]; + callback(this); } - }, { - key: 'setValidity', - value: function setValidity(validationResponse, shouldBeDirty) { - var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; - - if (shouldBeDirty) this.isDirty = true; - this.message = validationResponse.message; - this.failingRule = validationResponse.failingRule; - this.isValid = validationResponse.isValid; - this.latestValue = validationResponse.latestValue; - if (this.isValid !== this.group.isValid) this.group.checkValidity(); - - if (notifyObservers) { - this.notifyObserversOfChange(); - } + }; + + ValidationResultProperty.prototype.setValidity = function setValidity(validationResponse, shouldBeDirty) { + var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; + + if (shouldBeDirty) this.isDirty = true; + this.message = validationResponse.message; + this.failingRule = validationResponse.failingRule; + this.isValid = validationResponse.isValid; + this.latestValue = validationResponse.latestValue; + if (this.isValid !== this.group.isValid) this.group.checkValidity(); + + if (notifyObservers) { + this.notifyObserversOfChange(); } - }]); + }; return ValidationResultProperty; })(); diff --git a/dist/system/validation/validation-rules-collection.js b/dist/system/validation/validation-rules-collection.js index d69b0bcb..e379cf89 100644 --- a/dist/system/validation/validation-rules-collection.js +++ b/dist/system/validation/validation-rules-collection.js @@ -1,5 +1,5 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function (_export) { - var Utilities, ValidationLocale, _classCallCheck, _createClass, ValidationRulesCollection, SwitchCaseValidationRulesCollection; + var Utilities, ValidationLocale, _classCallCheck, ValidationRulesCollection, SwitchCaseValidationRulesCollection; return { setters: [function (_validationUtilities) { @@ -12,8 +12,6 @@ System.register(['../validation/utilities', '../validation/validation-locale'], _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidationRulesCollection = (function () { function ValidationRulesCollection() { _classCallCheck(this, ValidationRulesCollection); @@ -24,103 +22,96 @@ System.register(['../validation/utilities', '../validation/validation-locale'], this.isRequiredMessage = null; } - _createClass(ValidationRulesCollection, [{ - key: 'validate', - value: function validate(newValue, locale) { - var _this = this; + ValidationRulesCollection.prototype.validate = function validate(newValue, locale) { + var _this = this; - if (locale === undefined) { - locale = ValidationLocale.Repository['default']; - } - newValue = Utilities.getValue(newValue); - var executeRules = true; - - if (Utilities.isEmptyValue(newValue)) { - if (this.isRequired) { - return Promise.resolve({ - isValid: false, - message: this.isRequiredMessage ? typeof this.isRequiredMessage === 'function' ? this.isRequiredMessage(newValue) : this.isRequiredMessage : locale.translate('isRequired'), - failingRule: 'isRequired', - latestValue: newValue - }); - } else { - executeRules = false; - } + if (locale === undefined) { + locale = ValidationLocale.Repository['default']; + } + newValue = Utilities.getValue(newValue); + var executeRules = true; + + if (Utilities.isEmptyValue(newValue)) { + if (this.isRequired) { + return Promise.resolve({ + isValid: false, + message: this.isRequiredMessage ? typeof this.isRequiredMessage === 'function' ? this.isRequiredMessage(newValue) : this.isRequiredMessage : locale.translate('isRequired'), + failingRule: 'isRequired', + latestValue: newValue + }); + } else { + executeRules = false; } + } - var checks = Promise.resolve({ - isValid: true, - message: '', - failingRule: null, - latestValue: newValue - }); - - if (executeRules) { - var _loop = function (i) { - var rule = _this.validationRules[i]; - checks = checks.then(function (previousRuleResult) { - if (previousRuleResult.isValid === false) { - return previousRuleResult; - } else { - return rule.validate(newValue, locale).then(function (thisRuleResult) { - if (thisRuleResult === false) { - return { - isValid: false, - message: rule.explain(), - failingRule: rule.ruleName, - latestValue: newValue - }; - } else { - if (!previousRuleResult.isValid) { - throw Error('ValidationRulesCollection.validate caught an unexpected result while validating it\'s chain of rules.'); - } - return previousRuleResult; + var checks = Promise.resolve({ + isValid: true, + message: '', + failingRule: null, + latestValue: newValue + }); + + if (executeRules) { + var _loop = function (i) { + var rule = _this.validationRules[i]; + checks = checks.then(function (previousRuleResult) { + if (previousRuleResult.isValid === false) { + return previousRuleResult; + } else { + return rule.validate(newValue, locale).then(function (thisRuleResult) { + if (thisRuleResult === false) { + return { + isValid: false, + message: rule.explain(), + failingRule: rule.ruleName, + latestValue: newValue + }; + } else { + if (!previousRuleResult.isValid) { + throw Error('ValidationRulesCollection.validate caught an unexpected result while validating it\'s chain of rules.'); } - }); - } - }); - }; - - for (var i = 0; i < this.validationRules.length; i++) { - _loop(i); - } - } - - var _loop2 = function (i) { - var validationCollection = _this.validationCollections[i]; - checks = checks.then(function (previousValidationResult) { - if (previousValidationResult.isValid) return validationCollection.validate(newValue, locale);else return previousValidationResult; + return previousRuleResult; + } + }); + } }); }; - for (var i = 0; i < this.validationCollections.length; i++) { - _loop2(i); + for (var i = 0; i < this.validationRules.length; i++) { + _loop(i); } - - return checks; - } - }, { - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); - this.validationRules.push(validationRule); - } - }, { - key: 'addValidationRuleCollection', - value: function addValidationRuleCollection(validationRulesCollection) { - this.validationCollections.push(validationRulesCollection); } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - this.isRequired = true; - } - }, { - key: 'withMessage', - value: function withMessage(message) { - if (this.validationRules.length === 0) this.isRequiredMessage = message;else this.validationRules[this.validationRules.length - 1].withMessage(message); + + var _loop2 = function (i) { + var validationCollection = _this.validationCollections[i]; + checks = checks.then(function (previousValidationResult) { + if (previousValidationResult.isValid) return validationCollection.validate(newValue, locale);else return previousValidationResult; + }); + }; + + for (var i = 0; i < this.validationCollections.length; i++) { + _loop2(i); } - }]); + + return checks; + }; + + ValidationRulesCollection.prototype.addValidationRule = function addValidationRule(validationRule) { + if (validationRule.validate === undefined) throw new exception('That\'s not a valid validationRule'); + this.validationRules.push(validationRule); + }; + + ValidationRulesCollection.prototype.addValidationRuleCollection = function addValidationRuleCollection(validationRulesCollection) { + this.validationCollections.push(validationRulesCollection); + }; + + ValidationRulesCollection.prototype.isNotEmpty = function isNotEmpty() { + this.isRequired = true; + }; + + ValidationRulesCollection.prototype.withMessage = function withMessage(message) { + if (this.validationRules.length === 0) this.isRequiredMessage = message;else this.validationRules[this.validationRules.length - 1].withMessage(message); + }; return ValidationRulesCollection; })(); @@ -138,76 +129,66 @@ System.register(['../validation/utilities', '../validation/validation-locale'], this.defaultCaseLabel = { description: 'this is the case label for \'default\'' }; } - _createClass(SwitchCaseValidationRulesCollection, [{ - key: 'case', - value: function _case(caseLabel) { - this.caseLabel = caseLabel; - this.getCurrentCollection(caseLabel, true); - } - }, { - key: 'default', - value: function _default() { - this.caseLabel = this.defaultCaseLabel; - } - }, { - key: 'getCurrentCollection', - value: function getCurrentCollection(caseLabel) { - var createIfNotExists = arguments[1] === undefined ? false : arguments[1]; - - if (caseLabel === this.defaultCaseLabel) { - return this.defaultCollection; - }var currentCollection = null; - for (var i = 0; i < this.innerCollections.length; i++) { - currentCollection = this.innerCollections[i]; - if (currentCollection.caseLabel === caseLabel) { - return currentCollection.collection; - } - } - if (createIfNotExists) { - currentCollection = { - caseLabel: caseLabel, - collection: new ValidationRulesCollection() - }; - this.innerCollections.push(currentCollection); + SwitchCaseValidationRulesCollection.prototype['case'] = function _case(caseLabel) { + this.caseLabel = caseLabel; + this.getCurrentCollection(caseLabel, true); + }; + + SwitchCaseValidationRulesCollection.prototype['default'] = function _default() { + this.caseLabel = this.defaultCaseLabel; + }; + + SwitchCaseValidationRulesCollection.prototype.getCurrentCollection = function getCurrentCollection(caseLabel) { + var createIfNotExists = arguments[1] === undefined ? false : arguments[1]; + + if (caseLabel === this.defaultCaseLabel) { + return this.defaultCollection; + }var currentCollection = null; + for (var i = 0; i < this.innerCollections.length; i++) { + currentCollection = this.innerCollections[i]; + if (currentCollection.caseLabel === caseLabel) { return currentCollection.collection; } - return null; - } - }, { - key: 'validate', - value: function validate(newValue, locale) { - var collection = this.getCurrentCollection(this.conditionExpression(newValue)); - if (collection !== null) { - return collection.validate(newValue, locale); - } else { - return this.defaultCollection.validate(newValue, locale); - } - } - }, { - key: 'addValidationRule', - value: function addValidationRule(validationRule) { - var currentCollection = this.getCurrentCollection(this.caseLabel, true); - currentCollection.addValidationRule(validationRule); } - }, { - key: 'addValidationRuleCollection', - value: function addValidationRuleCollection(validationRulesCollection) { - var currentCollection = this.getCurrentCollection(this.caseLabel, true); - currentCollection.addValidationRuleCollection(validationRulesCollection); - } - }, { - key: 'isNotEmpty', - value: function isNotEmpty() { - var collection = this.getCurrentCollection(this.caseLabel); - if (collection !== null) collection.isNotEmpty();else this.defaultCollection.isNotEmpty(); + if (createIfNotExists) { + currentCollection = { + caseLabel: caseLabel, + collection: new ValidationRulesCollection() + }; + this.innerCollections.push(currentCollection); + return currentCollection.collection; } - }, { - key: 'withMessage', - value: function withMessage(message) { - var collection = this.getCurrentCollection(this.caseLabel); - if (collection !== null) collection.withMessage(message);else this.defaultCollection.withMessage(message); + return null; + }; + + SwitchCaseValidationRulesCollection.prototype.validate = function validate(newValue, locale) { + var collection = this.getCurrentCollection(this.conditionExpression(newValue)); + if (collection !== null) { + return collection.validate(newValue, locale); + } else { + return this.defaultCollection.validate(newValue, locale); } - }]); + }; + + SwitchCaseValidationRulesCollection.prototype.addValidationRule = function addValidationRule(validationRule) { + var currentCollection = this.getCurrentCollection(this.caseLabel, true); + currentCollection.addValidationRule(validationRule); + }; + + SwitchCaseValidationRulesCollection.prototype.addValidationRuleCollection = function addValidationRuleCollection(validationRulesCollection) { + var currentCollection = this.getCurrentCollection(this.caseLabel, true); + currentCollection.addValidationRuleCollection(validationRulesCollection); + }; + + SwitchCaseValidationRulesCollection.prototype.isNotEmpty = function isNotEmpty() { + var collection = this.getCurrentCollection(this.caseLabel); + if (collection !== null) collection.isNotEmpty();else this.defaultCollection.isNotEmpty(); + }; + + SwitchCaseValidationRulesCollection.prototype.withMessage = function withMessage(message) { + var collection = this.getCurrentCollection(this.caseLabel); + if (collection !== null) collection.withMessage(message);else this.defaultCollection.withMessage(message); + }; return SwitchCaseValidationRulesCollection; })(); diff --git a/dist/system/validation/validation-rules.js b/dist/system/validation/validation-rules.js index 648a1fce..1533fd76 100644 --- a/dist/system/validation/validation-rules.js +++ b/dist/system/validation/validation-rules.js @@ -1,5 +1,5 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function (_export) { - var Utilities, ValidationLocale, _get, _inherits, _classCallCheck, _createClass, ValidationRule, EmailValidationRule, MinimumLengthValidationRule, MaximumLengthValidationRule, BetweenLengthValidationRule, CustomFunctionValidationRule, NumericValidationRule, RegexValidationRule, ContainsOnlyValidationRule, MinimumValueValidationRule, MinimumInclusiveValueValidationRule, MaximumValueValidationRule, MaximumInclusiveValueValidationRule, BetweenValueValidationRule, DigitValidationRule, AlphaNumericValidationRule, AlphaValidationRule, AlphaOrWhitespaceValidationRule, AlphaNumericOrWhitespaceValidationRule, MediumPasswordValidationRule, StrongPasswordValidationRule, EqualityValidationRuleBase, EqualityValidationRule, EqualityWithOtherLabelValidationRule, InEqualityValidationRule, InEqualityWithOtherLabelValidationRule, InCollectionValidationRule; + var Utilities, ValidationLocale, _inherits, _classCallCheck, ValidationRule, EmailValidationRule, MinimumLengthValidationRule, MaximumLengthValidationRule, BetweenLengthValidationRule, CustomFunctionValidationRule, NumericValidationRule, RegexValidationRule, ContainsOnlyValidationRule, MinimumValueValidationRule, MinimumInclusiveValueValidationRule, MaximumValueValidationRule, MaximumInclusiveValueValidationRule, BetweenValueValidationRule, DigitValidationRule, AlphaNumericValidationRule, AlphaValidationRule, AlphaOrWhitespaceValidationRule, AlphaNumericOrWhitespaceValidationRule, MediumPasswordValidationRule, StrongPasswordValidationRule, EqualityValidationRuleBase, EqualityValidationRule, EqualityWithOtherLabelValidationRule, InEqualityValidationRule, InEqualityWithOtherLabelValidationRule, InCollectionValidationRule; return { setters: [function (_validationUtilities) { @@ -10,14 +10,10 @@ System.register(['../validation/utilities', '../validation/validation-locale'], execute: function () { 'use strict'; - _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - ValidationRule = (function () { function ValidationRule(threshold, onValidate, message) { _classCallCheck(this, ValidationRule); @@ -29,60 +25,54 @@ System.register(['../validation/utilities', '../validation/validation-locale'], this.ruleName = this.constructor.name; } - _createClass(ValidationRule, [{ - key: 'withMessage', - value: function withMessage(message) { - this.message = message; - } - }, { - key: 'explain', - value: function explain() { - return this.errorMessage; - } - }, { - key: 'setResult', - value: function setResult(result, currentValue, locale) { - if (result === true || result === undefined || result === null || result === '') { - this.errorMessage = null; - return true; + ValidationRule.prototype.withMessage = function withMessage(message) { + this.message = message; + }; + + ValidationRule.prototype.explain = function explain() { + return this.errorMessage; + }; + + ValidationRule.prototype.setResult = function setResult(result, currentValue, locale) { + if (result === true || result === undefined || result === null || result === '') { + this.errorMessage = null; + return true; + } else { + if (typeof result === 'string') { + this.errorMessage = result; } else { - if (typeof result === 'string') { - this.errorMessage = result; + if (this.message) { + if (typeof this.message === 'function') { + this.errorMessage = this.message(currentValue, this.threshold); + } else if (typeof this.message === 'string') { + this.errorMessage = this.message; + } else throw 'Unable to handle the error message:' + this.message; } else { - if (this.message) { - if (typeof this.message === 'function') { - this.errorMessage = this.message(currentValue, this.threshold); - } else if (typeof this.message === 'string') { - this.errorMessage = this.message; - } else throw 'Unable to handle the error message:' + this.message; - } else { - this.errorMessage = locale.translate(this.ruleName, currentValue, this.threshold); - } + this.errorMessage = locale.translate(this.ruleName, currentValue, this.threshold); } - return false; } + return false; } - }, { - key: 'validate', - value: function validate(currentValue, locale) { - var _this = this; - - if (locale === undefined) { - locale = ValidationLocale.Repository['default']; - } + }; - currentValue = Utilities.getValue(currentValue); - var result = this.onValidate(currentValue, this.threshold, locale); - var promise = Promise.resolve(result); + ValidationRule.prototype.validate = function validate(currentValue, locale) { + var _this = this; - var nextPromise = promise.then(function (promiseResult) { - return _this.setResult(promiseResult, currentValue, locale); - }, function (promiseFailure) { - if (typeof promiseFailure === 'string' && promiseFailure !== '') return _this.setResult(promiseFailure, currentValue, locale);else return _this.setResult(false, currentValue, locale); - }); - return nextPromise; + if (locale === undefined) { + locale = ValidationLocale.Repository['default']; } - }]); + + currentValue = Utilities.getValue(currentValue); + var result = this.onValidate(currentValue, this.threshold, locale); + var promise = Promise.resolve(result); + + var nextPromise = promise.then(function (promiseResult) { + return _this.setResult(promiseResult, currentValue, locale); + }, function (promiseFailure) { + if (typeof promiseFailure === 'string' && promiseFailure !== '') return _this.setResult(promiseFailure, currentValue, locale);else return _this.setResult(false, currentValue, locale); + }); + return nextPromise; + }; return ValidationRule; })(); @@ -95,7 +85,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], _classCallCheck(this, EmailValidationRule); - _get(Object.getPrototypeOf(EmailValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule.call(this, null, function (newValue, threshold) { if (/\s/.test(newValue)) { return false; } @@ -139,7 +129,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function MinimumLengthValidationRule(minimumLength) { _classCallCheck(this, MinimumLengthValidationRule); - _get(Object.getPrototypeOf(MinimumLengthValidationRule.prototype), 'constructor', this).call(this, minimumLength, function (newValue, minimumLength) { + _ValidationRule2.call(this, minimumLength, function (newValue, minimumLength) { return newValue.length !== undefined && newValue.length >= minimumLength; }); } @@ -155,7 +145,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function MaximumLengthValidationRule(maximumLength) { _classCallCheck(this, MaximumLengthValidationRule); - _get(Object.getPrototypeOf(MaximumLengthValidationRule.prototype), 'constructor', this).call(this, maximumLength, function (newValue, maximumLength) { + _ValidationRule3.call(this, maximumLength, function (newValue, maximumLength) { return newValue.length !== undefined && newValue.length <= maximumLength; }); } @@ -171,7 +161,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function BetweenLengthValidationRule(minimumLength, maximumLength) { _classCallCheck(this, BetweenLengthValidationRule); - _get(Object.getPrototypeOf(BetweenLengthValidationRule.prototype), 'constructor', this).call(this, { minimumLength: minimumLength, maximumLength: maximumLength }, function (newValue, threshold) { + _ValidationRule4.call(this, { minimumLength: minimumLength, maximumLength: maximumLength }, function (newValue, threshold) { return newValue.length !== undefined && newValue.length >= threshold.minimumLength && newValue.length <= threshold.maximumLength; }); } @@ -187,7 +177,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function CustomFunctionValidationRule(customFunction, threshold) { _classCallCheck(this, CustomFunctionValidationRule); - _get(Object.getPrototypeOf(CustomFunctionValidationRule.prototype), 'constructor', this).call(this, threshold, customFunction); + _ValidationRule5.call(this, threshold, customFunction); } _inherits(CustomFunctionValidationRule, _ValidationRule5); @@ -201,7 +191,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function NumericValidationRule() { _classCallCheck(this, NumericValidationRule); - _get(Object.getPrototypeOf(NumericValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold, locale) { + _ValidationRule6.call(this, null, function (newValue, threshold, locale) { var numericRegex = locale.setting('numericRegex'); var floatValue = parseFloat(newValue); return !Number.isNaN(parseFloat(floatValue)) && Number.isFinite(floatValue) && numericRegex.test(newValue); @@ -219,7 +209,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function RegexValidationRule(regex) { _classCallCheck(this, RegexValidationRule); - _get(Object.getPrototypeOf(RegexValidationRule.prototype), 'constructor', this).call(this, regex, function (newValue, regex) { + _ValidationRule7.call(this, regex, function (newValue, regex) { return regex.test(newValue); }); } @@ -235,7 +225,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function ContainsOnlyValidationRule(regex) { _classCallCheck(this, ContainsOnlyValidationRule); - _get(Object.getPrototypeOf(ContainsOnlyValidationRule.prototype), 'constructor', this).call(this, regex); + _RegexValidationRule.call(this, regex); } _inherits(ContainsOnlyValidationRule, _RegexValidationRule); @@ -249,7 +239,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function MinimumValueValidationRule(minimumValue) { _classCallCheck(this, MinimumValueValidationRule); - _get(Object.getPrototypeOf(MinimumValueValidationRule.prototype), 'constructor', this).call(this, minimumValue, function (newValue, minimumValue) { + _ValidationRule8.call(this, minimumValue, function (newValue, minimumValue) { return Utilities.getValue(minimumValue) < newValue; }); } @@ -265,7 +255,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function MinimumInclusiveValueValidationRule(minimumValue) { _classCallCheck(this, MinimumInclusiveValueValidationRule); - _get(Object.getPrototypeOf(MinimumInclusiveValueValidationRule.prototype), 'constructor', this).call(this, minimumValue, function (newValue, minimumValue) { + _ValidationRule9.call(this, minimumValue, function (newValue, minimumValue) { return Utilities.getValue(minimumValue) <= newValue; }); } @@ -281,7 +271,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function MaximumValueValidationRule(maximumValue) { _classCallCheck(this, MaximumValueValidationRule); - _get(Object.getPrototypeOf(MaximumValueValidationRule.prototype), 'constructor', this).call(this, maximumValue, function (newValue, maximumValue) { + _ValidationRule10.call(this, maximumValue, function (newValue, maximumValue) { return newValue < Utilities.getValue(maximumValue); }); } @@ -297,7 +287,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function MaximumInclusiveValueValidationRule(maximumValue) { _classCallCheck(this, MaximumInclusiveValueValidationRule); - _get(Object.getPrototypeOf(MaximumInclusiveValueValidationRule.prototype), 'constructor', this).call(this, maximumValue, function (newValue, maximumValue) { + _ValidationRule11.call(this, maximumValue, function (newValue, maximumValue) { return newValue <= Utilities.getValue(maximumValue); }); } @@ -313,7 +303,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function BetweenValueValidationRule(minimumValue, maximumValue) { _classCallCheck(this, BetweenValueValidationRule); - _get(Object.getPrototypeOf(BetweenValueValidationRule.prototype), 'constructor', this).call(this, { minimumValue: minimumValue, maximumValue: maximumValue }, function (newValue, threshold) { + _ValidationRule12.call(this, { minimumValue: minimumValue, maximumValue: maximumValue }, function (newValue, threshold) { return Utilities.getValue(threshold.minimumValue) <= newValue && newValue <= Utilities.getValue(threshold.maximumValue); }); } @@ -331,7 +321,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], _classCallCheck(this, DigitValidationRule); - _get(Object.getPrototypeOf(DigitValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule13.call(this, null, function (newValue, threshold) { return _this3.digitRegex.test(newValue); }); this.digitRegex = /^\d+$/; @@ -350,7 +340,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], _classCallCheck(this, AlphaNumericValidationRule); - _get(Object.getPrototypeOf(AlphaNumericValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule14.call(this, null, function (newValue, threshold) { return _this4.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z0-9]+$/i; @@ -369,7 +359,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], _classCallCheck(this, AlphaValidationRule); - _get(Object.getPrototypeOf(AlphaValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule15.call(this, null, function (newValue, threshold) { return _this5.alphaRegex.test(newValue); }); this.alphaRegex = /^[a-z]+$/i; @@ -388,7 +378,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], _classCallCheck(this, AlphaOrWhitespaceValidationRule); - _get(Object.getPrototypeOf(AlphaOrWhitespaceValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule16.call(this, null, function (newValue, threshold) { return _this6.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z\s]+$/i; @@ -407,7 +397,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], _classCallCheck(this, AlphaNumericOrWhitespaceValidationRule); - _get(Object.getPrototypeOf(AlphaNumericOrWhitespaceValidationRule.prototype), 'constructor', this).call(this, null, function (newValue, threshold) { + _ValidationRule17.call(this, null, function (newValue, threshold) { return _this7.alphaNumericRegex.test(newValue); }); this.alphaNumericRegex = /^[a-z0-9\s]+$/i; @@ -424,7 +414,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function MediumPasswordValidationRule(minimumComplexityLevel) { _classCallCheck(this, MediumPasswordValidationRule); - _get(Object.getPrototypeOf(MediumPasswordValidationRule.prototype), 'constructor', this).call(this, minimumComplexityLevel ? minimumComplexityLevel : 3, function (newValue, threshold) { + _ValidationRule18.call(this, minimumComplexityLevel ? minimumComplexityLevel : 3, function (newValue, threshold) { if (typeof newValue !== 'string') return false; var strength = 0; @@ -447,7 +437,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function StrongPasswordValidationRule() { _classCallCheck(this, StrongPasswordValidationRule); - _get(Object.getPrototypeOf(StrongPasswordValidationRule.prototype), 'constructor', this).call(this, 4); + _MediumPasswordValidationRule.call(this, 4); } _inherits(StrongPasswordValidationRule, _MediumPasswordValidationRule); @@ -461,7 +451,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function EqualityValidationRuleBase(otherValue, equality, otherValueLabel) { _classCallCheck(this, EqualityValidationRuleBase); - _get(Object.getPrototypeOf(EqualityValidationRuleBase.prototype), 'constructor', this).call(this, { + _ValidationRule19.call(this, { otherValue: otherValue, equality: equality, otherValueLabel: otherValueLabel @@ -483,7 +473,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function EqualityValidationRule(otherValue) { _classCallCheck(this, EqualityValidationRule); - _get(Object.getPrototypeOf(EqualityValidationRule.prototype), 'constructor', this).call(this, otherValue, true); + _EqualityValidationRuleBase.call(this, otherValue, true); } _inherits(EqualityValidationRule, _EqualityValidationRuleBase); @@ -497,7 +487,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function EqualityWithOtherLabelValidationRule(otherValue, otherLabel) { _classCallCheck(this, EqualityWithOtherLabelValidationRule); - _get(Object.getPrototypeOf(EqualityWithOtherLabelValidationRule.prototype), 'constructor', this).call(this, otherValue, true, otherLabel); + _EqualityValidationRuleBase2.call(this, otherValue, true, otherLabel); } _inherits(EqualityWithOtherLabelValidationRule, _EqualityValidationRuleBase2); @@ -511,7 +501,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function InEqualityValidationRule(otherValue) { _classCallCheck(this, InEqualityValidationRule); - _get(Object.getPrototypeOf(InEqualityValidationRule.prototype), 'constructor', this).call(this, otherValue, false); + _EqualityValidationRuleBase3.call(this, otherValue, false); } _inherits(InEqualityValidationRule, _EqualityValidationRuleBase3); @@ -525,7 +515,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function InEqualityWithOtherLabelValidationRule(otherValue, otherLabel) { _classCallCheck(this, InEqualityWithOtherLabelValidationRule); - _get(Object.getPrototypeOf(InEqualityWithOtherLabelValidationRule.prototype), 'constructor', this).call(this, otherValue, false, otherLabel); + _EqualityValidationRuleBase4.call(this, otherValue, false, otherLabel); } _inherits(InEqualityWithOtherLabelValidationRule, _EqualityValidationRuleBase4); @@ -539,7 +529,7 @@ System.register(['../validation/utilities', '../validation/validation-locale'], function InCollectionValidationRule(collection) { _classCallCheck(this, InCollectionValidationRule); - _get(Object.getPrototypeOf(InCollectionValidationRule.prototype), 'constructor', this).call(this, collection, function (newValue, threshold) { + _ValidationRule20.call(this, collection, function (newValue, threshold) { var collection = Utilities.getValue(threshold); for (var i = 0; i < collection.length; i++) { if (newValue === collection[i]) return true; diff --git a/dist/system/validation/validation.js b/dist/system/validation/validation.js index d23fc86c..1dc66cf4 100644 --- a/dist/system/validation/validation.js +++ b/dist/system/validation/validation.js @@ -1,5 +1,5 @@ System.register(['aurelia-binding', '../validation/validation-rules', '../validation/validation-rules-collection', '../validation/validation-group', 'aurelia-dependency-injection', '../validation/validation-config'], function (_export) { - var ObserverLocator, AllRules, AllCollections, ValidationGroup, inject, ValidationConfig, _classCallCheck, _createClass, Validation; + var ObserverLocator, AllRules, AllCollections, ValidationGroup, inject, ValidationConfig, _classCallCheck, Validation; return { setters: [function (_aureliaBinding) { @@ -20,8 +20,6 @@ System.register(['aurelia-binding', '../validation/validation-rules', '../valida _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - Validation = (function () { function Validation(observerLocator, validationConfig) { _classCallCheck(this, _Validation); @@ -30,23 +28,19 @@ System.register(['aurelia-binding', '../validation/validation-rules', '../valida this.config = validationConfig ? validationConfig : Validation.defaults; } - _createClass(Validation, [{ - key: 'on', - value: function on(subject, configCallback) { - var conf = new ValidationConfig(this.config); - if (configCallback !== null && configCallback !== undefined && typeof configCallback === 'function') { - configCallback(conf); - } - return new ValidationGroup(subject, this.observerLocator, conf); - } - }, { - key: 'onBreezeEntity', - value: function onBreezeEntity(breezeEntity, configCallback) { - var validation = this.on(breezeEntity, configCallback); - validation.onBreezeEntity(); - return validation; + Validation.prototype.on = function on(subject, configCallback) { + var conf = new ValidationConfig(this.config); + if (configCallback !== null && configCallback !== undefined && typeof configCallback === 'function') { + configCallback(conf); } - }]); + return new ValidationGroup(subject, this.observerLocator, conf); + }; + + Validation.prototype.onBreezeEntity = function onBreezeEntity(breezeEntity, configCallback) { + var validation = this.on(breezeEntity, configCallback); + validation.onBreezeEntity(); + return validation; + }; var _Validation = Validation; Validation = inject(ObserverLocator)(Validation) || Validation; diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 997d23a9..890dd3da 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,19 @@ +### 0.2.4 (2015-05-01) + + +#### Bug Fixes + +* **decorators:** @ensure was imported, not exported ([d421c299](https://github.com/aurelia/validation/commit/d421c29957d4afb2a6d6b5c4efb8817b17401201)) + +#### Features + +* **breeze:** + * documentation ([6751be32](https://github.com/aurelia/validation/commit/6751be32000280ece9e5e00c20b097fc2c3decac)) + * further development ([772f332b](https://github.com/aurelia/validation/commit/772f332b852407e1163c6a461571e75506d48a98)) + * initial binding to breeze entities ([acb3e26a](https://github.com/aurelia/validation/commit/acb3e26af1cff4e9e09a3e875c5db3bab3a24a56)) +* **decorators:** introducing the @ensure property decorator ([784e73f2](https://github.com/aurelia/validation/commit/784e73f28ed44a357d78528ac9ddc4b26a7cf794)) + + ### 0.2.3 (2015-04-26) diff --git a/package.json b/package.json index 308fae18..114d2744 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-validation", - "version": "0.2.3", + "version": "0.2.4", "description": "A validation plugin for Aurelia.", "keywords": [ "aurelia",