Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
Conflicts:
	dist/es6/validation/validation-group.js
	src/validation/validation-group.js
  • Loading branch information
janvanderhaegen committed Apr 26, 2015
2 parents acb3e26 + ff92803 commit 09f090f
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 107 deletions.
17 changes: 9 additions & 8 deletions dist/amd/validation/validation-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ define(['exports', '../validation/validation-group-builder', '../validation/vali
var newPropResult = {
latestValue: resultProp.latestValue
};

if (result === true || result === null || result === '') {
if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') {
newPropResult.failingRule = null;
Expand All @@ -120,14 +119,16 @@ define(['exports', '../validation/validation-group-builder', '../validation/vali
resultProp.setValidity(newPropResult, true);
}
} else {
newPropResult.failingRule = 'onValidateCallback';
newPropResult.isValid = false;
if (typeof result === 'string') {
newPropResult.message = result;
} else {
newPropResult.message = locale.translate(newPropResult.failingRule);
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);
}
resultProp.setValidity(newPropResult, true);
}
}
_this3.result.checkValidity();
Expand Down
55 changes: 37 additions & 18 deletions dist/amd/validation/validation-result.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
define(["exports"], function (exports) {
"use strict";
define(['exports'], function (exports) {
'use strict';

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
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; }; })();
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", {
Object.defineProperty(exports, '__esModule', {
value: true
});

Expand All @@ -18,15 +18,15 @@ define(["exports"], function (exports) {
}

_createClass(ValidationResult, [{
key: "addProperty",
key: 'addProperty',
value: function addProperty(name) {
if (!this.properties[name]) {
this.properties[name] = new ValidationResultProperty(this);
}
return this.properties[name];
}
}, {
key: "checkValidity",
key: 'checkValidity',
value: function checkValidity() {
for (var propertyName in this.properties) {
if (!this.properties[propertyName].isValid) {
Expand All @@ -36,6 +36,14 @@ define(["exports"], function (exports) {
}
this.isValid = true;
}
}, {
key: 'clear',
value: function clear() {
for (var propertyName in this.properties) {
this.properties[propertyName].clear();
}
this.isValid = true;
}
}]);

return ValidationResult;
Expand All @@ -48,21 +56,35 @@ define(["exports"], function (exports) {
_classCallCheck(this, ValidationResultProperty);

this.group = group;
this.isValid = true;
this.isDirty = false;
this.message = null;
this.failingRule = null;
this.onValidateCallbacks = [];
this.latestValue = null;
this.clear();
}

_createClass(ValidationResultProperty, [{
key: "onValidate",
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: "setValidity",
key: 'notifyObserversOfChange',
value: 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;

Expand All @@ -74,10 +96,7 @@ define(["exports"], function (exports) {
if (this.isValid !== this.group.isValid) this.group.checkValidity();

if (notifyObservers) {
for (var i = 0; i < this.onValidateCallbacks.length; i++) {
var callback = this.onValidateCallbacks[i];
callback(this);
}
this.notifyObserversOfChange();
}
}
}]);
Expand Down
17 changes: 9 additions & 8 deletions dist/commonjs/validation/validation-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ var ValidationGroup = (function () {
var newPropResult = {
latestValue: resultProp.latestValue
};

if (result === true || result === null || result === '') {
if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') {
newPropResult.failingRule = null;
Expand All @@ -125,14 +124,16 @@ var ValidationGroup = (function () {
resultProp.setValidity(newPropResult, true);
}
} else {
newPropResult.failingRule = 'onValidateCallback';
newPropResult.isValid = false;
if (typeof result === 'string') {
newPropResult.message = result;
} else {
newPropResult.message = locale.translate(newPropResult.failingRule);
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);
}
resultProp.setValidity(newPropResult, true);
}
}
_this3.result.checkValidity();
Expand Down
53 changes: 36 additions & 17 deletions dist/commonjs/validation/validation-result.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
'use strict';

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
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; }; })();
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", {
Object.defineProperty(exports, '__esModule', {
value: true
});

Expand All @@ -17,15 +17,15 @@ var ValidationResult = (function () {
}

_createClass(ValidationResult, [{
key: "addProperty",
key: 'addProperty',
value: function addProperty(name) {
if (!this.properties[name]) {
this.properties[name] = new ValidationResultProperty(this);
}
return this.properties[name];
}
}, {
key: "checkValidity",
key: 'checkValidity',
value: function checkValidity() {
for (var propertyName in this.properties) {
if (!this.properties[propertyName].isValid) {
Expand All @@ -35,6 +35,14 @@ var ValidationResult = (function () {
}
this.isValid = true;
}
}, {
key: 'clear',
value: function clear() {
for (var propertyName in this.properties) {
this.properties[propertyName].clear();
}
this.isValid = true;
}
}]);

return ValidationResult;
Expand All @@ -47,21 +55,35 @@ var ValidationResultProperty = (function () {
_classCallCheck(this, ValidationResultProperty);

this.group = group;
this.isValid = true;
this.isDirty = false;
this.message = null;
this.failingRule = null;
this.onValidateCallbacks = [];
this.latestValue = null;
this.clear();
}

_createClass(ValidationResultProperty, [{
key: "onValidate",
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: "setValidity",
key: 'notifyObserversOfChange',
value: 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;

Expand All @@ -73,10 +95,7 @@ var ValidationResultProperty = (function () {
if (this.isValid !== this.group.isValid) this.group.checkValidity();

if (notifyObservers) {
for (var i = 0; i < this.onValidateCallbacks.length; i++) {
var callback = this.onValidateCallbacks[i];
callback(this);
}
this.notifyObserversOfChange();
}
}
}]);
Expand Down
19 changes: 10 additions & 9 deletions dist/es6/validation/validation-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export class ValidationGroup {
let newPropResult = {
latestValue : resultProp.latestValue
};

if (result === true || result === null || result === '' ) {
if(!resultProp.isValid && resultProp.failingRule === 'onValidateCallback' ) {
newPropResult.failingRule = null;
Expand All @@ -110,15 +109,17 @@ export class ValidationGroup {
}
}
else {
newPropResult.failingRule = 'onValidateCallback';
newPropResult.isValid = false;
if (typeof(result) === 'string') {
newPropResult.message = result;
}
else {
newPropResult.message = locale.translate(newPropResult.failingRule);
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);
}
resultProp.setValidity(newPropResult, true);
}
}
this.result.checkValidity();
Expand Down
27 changes: 21 additions & 6 deletions dist/es6/validation/validation-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,41 @@ export class ValidationResult {
}
this.isValid = true;
}
clear() {
for (let propertyName in this.properties) {
this.properties[propertyName].clear();
}
this.isValid = true;
}
}

export class ValidationResultProperty {
constructor(group) {
this.group = group;
this.onValidateCallbacks = [];
this.clear();
}

clear(){
this.isValid = true;
this.isDirty = false;
this.message = null;
this.message = '';
this.failingRule = null;
this.onValidateCallbacks = [];
this.latestValue = null;
this.notifyObserversOfChange();
}

onValidate(onValidateCallback) {
this.onValidateCallbacks.push(onValidateCallback);
}

notifyObserversOfChange(){
for (var i = 0; i < this.onValidateCallbacks.length; i++) {
var callback = this.onValidateCallbacks[i];
callback(this);
}
}

setValidity(validationResponse, shouldBeDirty) {
var notifyObservers = (!this.isDirty && shouldBeDirty)
|| (this.isValid !== validationResponse.isValid)
Expand All @@ -53,10 +71,7 @@ export class ValidationResultProperty {
this.group.checkValidity();

if (notifyObservers) {
for (var i = 0; i < this.onValidateCallbacks.length; i++) {
var callback = this.onValidateCallbacks[i];
callback(this);
}
this.notifyObserversOfChange();
}
}
}
17 changes: 9 additions & 8 deletions dist/system/validation/validation-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ System.register(['../validation/validation-group-builder', '../validation/valida
var newPropResult = {
latestValue: resultProp.latestValue
};

if (result === true || result === null || result === '') {
if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') {
newPropResult.failingRule = null;
Expand All @@ -127,14 +126,16 @@ System.register(['../validation/validation-group-builder', '../validation/valida
resultProp.setValidity(newPropResult, true);
}
} else {
newPropResult.failingRule = 'onValidateCallback';
newPropResult.isValid = false;
if (typeof result === 'string') {
newPropResult.message = result;
} else {
newPropResult.message = locale.translate(newPropResult.failingRule);
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);
}
resultProp.setValidity(newPropResult, true);
}
}
_this3.result.checkValidity();
Expand Down
Loading

0 comments on commit 09f090f

Please sign in to comment.