Apply segments for validation, client side.
This commit is contained in:
@@ -322,7 +322,7 @@
|
||||
// find the urls for the currently selected language
|
||||
if (scope.node.variants.length > 1) {
|
||||
// nodes with variants
|
||||
scope.currentUrls = _.filter(scope.node.urls, (url) => scope.currentVariant.language.culture === url.culture);
|
||||
scope.currentUrls = _.filter(scope.node.urls, (url) => !scope.currentVariant.language || scope.currentVariant.language.culture === url.culture);
|
||||
} else {
|
||||
// invariant nodes
|
||||
scope.currentUrls = scope.node.urls;
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
|
||||
// find default.
|
||||
angular.forEach(scope.content.variants, function (variant) {
|
||||
if (variant.language.isDefault) {
|
||||
if (variant.language !== null && variant.language.isDefault) {
|
||||
scope.vm.defaultVariant = variant;
|
||||
}
|
||||
});
|
||||
@@ -82,10 +82,10 @@
|
||||
|
||||
|
||||
angular.forEach(scope.content.variants, function (variant) {
|
||||
unsubscribe.push(serverValidationManager.subscribe(null, variant.language.culture, null, onCultureValidation));
|
||||
unsubscribe.push(serverValidationManager.subscribe(null, variant.language !== null ? variant.language.culture : null, variant.segment, null, onCultureValidation));
|
||||
});
|
||||
|
||||
unsubscribe.push(serverValidationManager.subscribe(null, null, null, onCultureValidation));
|
||||
unsubscribe.push(serverValidationManager.subscribe(null, null, null, null, onCultureValidation));
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
|
||||
var currentProperty = umbPropCtrl.property;
|
||||
scope.currentProperty = currentProperty;
|
||||
var currentCulture = currentProperty.culture;
|
||||
var currentCulture = currentProperty.culture;
|
||||
var currentSegment = currentProperty.segment;
|
||||
|
||||
var labels = {};
|
||||
localizationService.localize("errors_propertyHasErrors").then(function (data) {
|
||||
@@ -51,7 +52,7 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
var currentVariant = umbVariantCtrl.editor.content;
|
||||
|
||||
// Lets check if we have variants and we are on the default language then ...
|
||||
if (umbVariantCtrl.content.variants.length > 1 && !currentVariant.language.isDefault && !currentCulture && !currentProperty.unlockInvariantValue) {
|
||||
if (umbVariantCtrl.content.variants.length > 1 && (!currentVariant.language || !currentVariant.language.isDefault) && !currentCulture && !currentSegment && !currentProperty.unlockInvariantValue) {
|
||||
//This property is locked cause its a invariant property shown on a non-default language.
|
||||
//Therefor do not validate this field.
|
||||
return;
|
||||
@@ -67,7 +68,7 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
//this can be null if no property was assigned
|
||||
if (scope.currentProperty) {
|
||||
//first try to get the error msg from the server collection
|
||||
var err = serverValidationManager.getPropertyError(scope.currentProperty.alias, null, "");
|
||||
var err = serverValidationManager.getPropertyError(scope.currentProperty.alias, null, null, "");
|
||||
//if there's an error message use it
|
||||
if (err && err.errorMsg) {
|
||||
return err.errorMsg;
|
||||
@@ -203,6 +204,7 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
if (scope.currentProperty) { //this can be null if no property was assigned
|
||||
unsubscribe.push(serverValidationManager.subscribe(scope.currentProperty.alias,
|
||||
currentCulture,
|
||||
currentSegment,
|
||||
"",
|
||||
function(isValid, propertyErrors, allErrors) {
|
||||
hasError = !isValid;
|
||||
|
||||
@@ -24,6 +24,7 @@ function valServer(serverValidationManager) {
|
||||
|
||||
var currentProperty = umbPropCtrl.property;
|
||||
var currentCulture = currentProperty.culture;
|
||||
var currentSegment = currentProperty.segment;
|
||||
|
||||
if (umbVariantCtrl) {
|
||||
//if we are inside of an umbVariantContent directive
|
||||
@@ -31,7 +32,7 @@ function valServer(serverValidationManager) {
|
||||
var currentVariant = umbVariantCtrl.editor.content;
|
||||
|
||||
// Lets check if we have variants and we are on the default language then ...
|
||||
if (umbVariantCtrl.content.variants.length > 1 && !currentVariant.language.isDefault && !currentCulture && !currentProperty.unlockInvariantValue) {
|
||||
if (umbVariantCtrl.content.variants.length > 1 && (!currentVariant.language || !currentVariant.language.isDefault) && !currentCulture && !currentSegment && !currentProperty.unlockInvariantValue) {
|
||||
//This property is locked cause its a invariant property shown on a non-default language.
|
||||
//Therefor do not validate this field.
|
||||
return;
|
||||
@@ -75,7 +76,7 @@ function valServer(serverValidationManager) {
|
||||
if (modelCtrl.$invalid) {
|
||||
modelCtrl.$setValidity('valServer', true);
|
||||
//clear the server validation entry
|
||||
serverValidationManager.removePropertyError(currentProperty.alias, currentCulture, fieldName);
|
||||
serverValidationManager.removePropertyError(currentProperty.alias, currentCulture, currentSegment, fieldName);
|
||||
stopWatch();
|
||||
}
|
||||
}, true);
|
||||
@@ -92,6 +93,7 @@ function valServer(serverValidationManager) {
|
||||
//subscribe to the server validation changes
|
||||
unsubscribe.push(serverValidationManager.subscribe(currentProperty.alias,
|
||||
currentCulture,
|
||||
currentSegment,
|
||||
fieldName,
|
||||
function(isValid, propertyErrors, allErrors) {
|
||||
if (!isValid) {
|
||||
|
||||
@@ -35,6 +35,7 @@ function valServerField(serverValidationManager) {
|
||||
|
||||
//subscribe to the server validation changes
|
||||
unsubscribe.push(serverValidationManager.subscribe(null,
|
||||
null,
|
||||
null,
|
||||
fieldName,
|
||||
function(isValid, fieldErrors, allErrors) {
|
||||
|
||||
@@ -179,16 +179,24 @@ function formHelper(angularHelper, serverValidationManager, notificationsService
|
||||
}
|
||||
}
|
||||
|
||||
//if it contains 3 '.' then we will wire it up to a property's html field
|
||||
htmlFieldReference = "";
|
||||
if (parts.length > 3) {
|
||||
//add an error with a reference to the field for which the validation belongs too
|
||||
serverValidationManager.addPropertyError(propertyAlias, culture, parts[3], modelState[e][0]);
|
||||
htmlFieldReference = parts[3] || "";
|
||||
}
|
||||
else {
|
||||
//add a generic error for the property, no reference to a specific html field
|
||||
serverValidationManager.addPropertyError(propertyAlias, culture, "", modelState[e][0]);
|
||||
|
||||
// SEGMENTS_TODO: Need to investigate wether we have updated validation to handle segments, plus could it be the third parameter, so we leave the HTML Field ref as optional and last?
|
||||
var segment = null;
|
||||
if (parts.length > 4) {
|
||||
segment = parts[4];
|
||||
//special check in case the string is formatted this way
|
||||
if (segment === "null") {
|
||||
segment = null;
|
||||
}
|
||||
}
|
||||
|
||||
// add a generic error for the property
|
||||
serverValidationManager.addPropertyError(propertyAlias, culture, segment, htmlFieldReference, modelState[e][0]);
|
||||
|
||||
} else {
|
||||
|
||||
//Everthing else is just a 'Field'... the field name could contain any level of 'parts' though, for example:
|
||||
|
||||
@@ -13,13 +13,14 @@ function serverValidationManager($timeout) {
|
||||
var callbacks = [];
|
||||
|
||||
/** calls the callback specified with the errors specified, used internally */
|
||||
function executeCallback(self, errorsForCallback, callback, culture) {
|
||||
function executeCallback(self, errorsForCallback, callback, culture, segment) {
|
||||
|
||||
callback.apply(self, [
|
||||
false, // pass in a value indicating it is invalid
|
||||
errorsForCallback, // pass in the errors for this item
|
||||
self.items, // pass in all errors in total
|
||||
culture // pass the culture that we are listing for.
|
||||
culture, // pass the culture that we are listing for.
|
||||
segment // pass the segment that we are listing for.
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -35,7 +36,7 @@ function serverValidationManager($timeout) {
|
||||
});
|
||||
}
|
||||
|
||||
function getPropertyErrors(self, propertyAlias, culture, fieldName) {
|
||||
function getPropertyErrors(self, propertyAlias, culture, segment, fieldName) {
|
||||
if (!angular.isString(propertyAlias)) {
|
||||
throw "propertyAlias must be a string";
|
||||
}
|
||||
@@ -46,22 +47,28 @@ function serverValidationManager($timeout) {
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
//find all errors for this property
|
||||
return _.filter(self.items, function (item) {
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && item.segment === segment && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
|
||||
});
|
||||
}
|
||||
|
||||
function getCultureErrors(self, culture) {
|
||||
function getVariantErrors(self, culture, segment) {
|
||||
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
//find all errors for this property
|
||||
return _.filter(self.items, function (item) {
|
||||
return (item.culture === culture);
|
||||
return (item.culture === culture && item.segment === segment);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,21 +78,21 @@ function serverValidationManager($timeout) {
|
||||
//its a field error callback
|
||||
var fieldErrors = getFieldErrors(self, callbacks[cb].fieldName);
|
||||
if (fieldErrors.length > 0) {
|
||||
executeCallback(self, fieldErrors, callbacks[cb].callback, callbacks[cb].culture);
|
||||
executeCallback(self, fieldErrors, callbacks[cb].callback, callbacks[cb].culture, callbacks[cb].segment);
|
||||
}
|
||||
}
|
||||
else if (callbacks[cb].propertyAlias != null) {
|
||||
//its a property error
|
||||
var propErrors = getPropertyErrors(self, callbacks[cb].propertyAlias, callbacks[cb].culture, callbacks[cb].fieldName);
|
||||
var propErrors = getPropertyErrors(self, callbacks[cb].propertyAlias, callbacks[cb].culture, callbacks[cb].segment, callbacks[cb].fieldName);
|
||||
if (propErrors.length > 0) {
|
||||
executeCallback(self, propErrors, callbacks[cb].callback, callbacks[cb].culture);
|
||||
executeCallback(self, propErrors, callbacks[cb].callback, callbacks[cb].culture, callbacks[cb].segment);
|
||||
}
|
||||
}
|
||||
else {
|
||||
//its a culture error
|
||||
var cultureErrors = getCultureErrors(self, callbacks[cb].culture);
|
||||
if (cultureErrors.length > 0) {
|
||||
executeCallback(self, cultureErrors, callbacks[cb].callback, callbacks[cb].culture);
|
||||
//its a variant error
|
||||
var variantErrors = getVariantErrors(self, callbacks[cb].culture, callbacks[cb].segment);
|
||||
if (variantErrors.length > 0) {
|
||||
executeCallback(self, variantErrors, callbacks[cb].callback, callbacks[cb].culture, callbacks[cb].segment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,20 +157,27 @@ function serverValidationManager($timeout) {
|
||||
* field alias to listen for.
|
||||
* If propertyAlias is null, then this subscription is for a field property (not a user defined property).
|
||||
*/
|
||||
subscribe: function (propertyAlias, culture, fieldName, callback) {
|
||||
subscribe: function (propertyAlias, culture, segment, fieldName, callback) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
var id = String.CreateGuid();
|
||||
|
||||
//normalize culture to "invariant"
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
//normalize segment to null
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
if (propertyAlias === null) {
|
||||
callbacks.push({
|
||||
propertyAlias: null,
|
||||
culture: culture,
|
||||
segment: segment,
|
||||
fieldName: fieldName,
|
||||
callback: callback,
|
||||
id: id
|
||||
@@ -175,6 +189,7 @@ function serverValidationManager($timeout) {
|
||||
callbacks.push({
|
||||
propertyAlias: propertyAlias,
|
||||
culture: culture,
|
||||
segment: segment,
|
||||
fieldName: fieldName,
|
||||
callback: callback,
|
||||
id: id
|
||||
@@ -199,25 +214,29 @@ function serverValidationManager($timeout) {
|
||||
* @param {} fieldName
|
||||
* @returns {}
|
||||
*/
|
||||
unsubscribe: function (propertyAlias, culture, fieldName) {
|
||||
unsubscribe: function (propertyAlias, culture, segment, fieldName) {
|
||||
|
||||
//normalize culture to null
|
||||
//normalize culture to "invariant"
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
//normalize segment to null
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
if (propertyAlias === null) {
|
||||
|
||||
//remove all callbacks for the content field
|
||||
callbacks = _.reject(callbacks, function (item) {
|
||||
return item.propertyAlias === null && item.culture === culture && item.fieldName === fieldName;
|
||||
return item.propertyAlias === null && item.culture === culture && item.segment === segment && item.fieldName === fieldName;
|
||||
});
|
||||
|
||||
}
|
||||
else if (propertyAlias !== undefined) {
|
||||
//remove all callbacks for the content property
|
||||
callbacks = _.reject(callbacks, function (item) {
|
||||
return item.propertyAlias === propertyAlias && item.culture === culture &&
|
||||
return item.propertyAlias === propertyAlias && item.culture === culture && item.segment === segment &&
|
||||
(item.fieldName === fieldName ||
|
||||
((item.fieldName === undefined || item.fieldName === "") && (fieldName === undefined || fieldName === "")));
|
||||
});
|
||||
@@ -238,14 +257,18 @@ function serverValidationManager($timeout) {
|
||||
*/
|
||||
getPropertyCallbacks: function (propertyAlias, culture, fieldName) {
|
||||
|
||||
//normalize culture to null
|
||||
//normalize culture to "invariant"
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
//normalize segment to null
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
var found = _.filter(callbacks, function (item) {
|
||||
//returns any callback that have been registered directly against the field and for only the property
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (item.fieldName === undefined || item.fieldName === "")));
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && item.segment === segment && (item.fieldName === fieldName || (item.fieldName === undefined || item.fieldName === "")));
|
||||
});
|
||||
return found;
|
||||
},
|
||||
@@ -262,7 +285,7 @@ function serverValidationManager($timeout) {
|
||||
getFieldCallbacks: function (fieldName) {
|
||||
var found = _.filter(callbacks, function (item) {
|
||||
//returns any callback that have been registered directly against the field
|
||||
return (item.propertyAlias === null && item.culture === "invariant" && item.fieldName === fieldName);
|
||||
return (item.propertyAlias === null && item.culture === "invariant" && item.segment === null && item.fieldName === fieldName);
|
||||
});
|
||||
return found;
|
||||
},
|
||||
@@ -303,6 +326,7 @@ function serverValidationManager($timeout) {
|
||||
this.items.push({
|
||||
propertyAlias: null,
|
||||
culture: "invariant",
|
||||
segment: null,
|
||||
fieldName: fieldName,
|
||||
errorMsg: errorMsg
|
||||
});
|
||||
@@ -327,7 +351,7 @@ function serverValidationManager($timeout) {
|
||||
* @description
|
||||
* Adds an error message for the content property
|
||||
*/
|
||||
addPropertyError: function (propertyAlias, culture, fieldName, errorMsg) {
|
||||
addPropertyError: function (propertyAlias, culture, segment, fieldName, errorMsg) {
|
||||
if (!propertyAlias) {
|
||||
return;
|
||||
}
|
||||
@@ -336,31 +360,36 @@ function serverValidationManager($timeout) {
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
//normalize segment to null
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
//only add the item if it doesn't exist
|
||||
if (!this.hasPropertyError(propertyAlias, culture, fieldName)) {
|
||||
if (!this.hasPropertyError(propertyAlias, culture, segment, fieldName)) {
|
||||
this.items.push({
|
||||
propertyAlias: propertyAlias,
|
||||
culture: culture,
|
||||
segment: segment,
|
||||
fieldName: fieldName,
|
||||
errorMsg: errorMsg
|
||||
});
|
||||
}
|
||||
|
||||
//find all errors for this item
|
||||
var errorsForCallback = getPropertyErrors(this, propertyAlias, culture, fieldName);
|
||||
var errorsForCallback = getPropertyErrors(this, propertyAlias, culture, segment, fieldName);
|
||||
//we should now call all of the call backs registered for this error
|
||||
var cbs = this.getPropertyCallbacks(propertyAlias, culture, fieldName);
|
||||
var cbs = this.getPropertyCallbacks(propertyAlias, culture, segment, fieldName);
|
||||
//call each callback for this error
|
||||
for (var cb in cbs) {
|
||||
executeCallback(this, errorsForCallback, cbs[cb].callback, culture);
|
||||
executeCallback(this, errorsForCallback, cbs[cb].callback, culture, segment);
|
||||
}
|
||||
|
||||
//execute culture specific callbacks here too when a propery error is added
|
||||
var cultureCbs = this.getCultureCallbacks(culture);
|
||||
//execute variant specific callbacks here too when a propery error is added
|
||||
var variantCbs = this.getVariantCallbacks(culture, segment);
|
||||
//call each callback for this error
|
||||
for (var cb in cultureCbs) {
|
||||
executeCallback(this, errorsForCallback, cultureCbs[cb].callback, culture);
|
||||
for (var cb in variantCbs) {
|
||||
executeCallback(this, errorsForCallback, variantCbs[cb].callback, culture, segment);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -373,7 +402,7 @@ function serverValidationManager($timeout) {
|
||||
* @description
|
||||
* Removes an error message for the content property
|
||||
*/
|
||||
removePropertyError: function (propertyAlias, culture, fieldName) {
|
||||
removePropertyError: function (propertyAlias, culture, segment, fieldName) {
|
||||
|
||||
if (!propertyAlias) {
|
||||
return;
|
||||
@@ -383,10 +412,14 @@ function serverValidationManager($timeout) {
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
//normalize segment to null
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
//remove the item
|
||||
this.items = _.reject(this.items, function (item) {
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && item.segment === segment && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
|
||||
});
|
||||
},
|
||||
|
||||
@@ -431,16 +464,20 @@ function serverValidationManager($timeout) {
|
||||
* @description
|
||||
* Gets the error message for the content property
|
||||
*/
|
||||
getPropertyError: function (propertyAlias, culture, fieldName) {
|
||||
getPropertyError: function (propertyAlias, culture, segment, fieldName) {
|
||||
|
||||
//normalize culture to null
|
||||
//normalize culture to "invariant"
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
//normalize segment to null
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
var err = _.find(this.items, function (item) {
|
||||
//return true if the property alias matches and if an empty field name is specified or the field name matches
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && item.segment === segment && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
|
||||
});
|
||||
return err;
|
||||
},
|
||||
@@ -457,7 +494,7 @@ function serverValidationManager($timeout) {
|
||||
getFieldError: function (fieldName) {
|
||||
var err = _.find(this.items, function (item) {
|
||||
//return true if the property alias matches and if an empty field name is specified or the field name matches
|
||||
return (item.propertyAlias === null && item.culture === "invariant" && item.fieldName === fieldName);
|
||||
return (item.propertyAlias === null && item.culture === "invariant" && item.segment === null && item.fieldName === fieldName);
|
||||
});
|
||||
return err;
|
||||
},
|
||||
@@ -471,16 +508,20 @@ function serverValidationManager($timeout) {
|
||||
* @description
|
||||
* Checks if the content property + culture + field name combo has an error
|
||||
*/
|
||||
hasPropertyError: function (propertyAlias, culture, fieldName) {
|
||||
hasPropertyError: function (propertyAlias, culture, segment, fieldName) {
|
||||
|
||||
//normalize culture to null
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
//normalize segment to null
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
var err = _.find(this.items, function (item) {
|
||||
//return true if the property alias matches and if an empty field name is specified or the field name matches
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
|
||||
return (item.propertyAlias === propertyAlias && item.culture === culture && item.segment === segment && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
|
||||
});
|
||||
return err ? true : false;
|
||||
},
|
||||
@@ -497,7 +538,7 @@ function serverValidationManager($timeout) {
|
||||
hasFieldError: function (fieldName) {
|
||||
var err = _.find(this.items, function (item) {
|
||||
//return true if the property alias matches and if an empty field name is specified or the field name matches
|
||||
return (item.propertyAlias === null && item.culture === "invariant" && item.fieldName === fieldName);
|
||||
return (item.propertyAlias === null && item.culture === "invariant" && item.segment === null && item.fieldName === fieldName);
|
||||
});
|
||||
return err ? true : false;
|
||||
},
|
||||
@@ -505,22 +546,26 @@ function serverValidationManager($timeout) {
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name hasCultureError
|
||||
* @name hasVariantError
|
||||
* @methodOf umbraco.services.serverValidationManager
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Checks if the given culture has an error
|
||||
*/
|
||||
hasCultureError: function (culture) {
|
||||
hasVariantError: function (culture, segment) {
|
||||
|
||||
//normalize culture to null
|
||||
if (!culture) {
|
||||
culture = "invariant";
|
||||
}
|
||||
//normalize segment to null
|
||||
if (!segment) {
|
||||
segment = null;
|
||||
}
|
||||
|
||||
var err = _.find(this.items, function (item) {
|
||||
return item.culture === culture;
|
||||
return (item.culture === culture && item.segment === segment);
|
||||
});
|
||||
return err ? true : false;
|
||||
},
|
||||
|
||||
@@ -61,12 +61,12 @@
|
||||
it('can retrieve property validation errors for a sub field', function () {
|
||||
|
||||
//arrange
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value2", "Another value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value2", "Another value 2");
|
||||
|
||||
//act
|
||||
var err1 = serverValidationManager.getPropertyError("myProperty", null, "value1");
|
||||
var err2 = serverValidationManager.getPropertyError("myProperty", null, "value2");
|
||||
var err1 = serverValidationManager.getPropertyError("myProperty", null, null, "value1");
|
||||
var err2 = serverValidationManager.getPropertyError("myProperty", null, null, "value2");
|
||||
|
||||
//assert
|
||||
expect(err1).not.toBeUndefined();
|
||||
@@ -85,14 +85,14 @@
|
||||
it('can retrieve property validation errors for a sub field for culture', function () {
|
||||
|
||||
//arrange
|
||||
serverValidationManager.addPropertyError("myProperty", "en-US", "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", "fr-FR", "value2", "Another value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", "en-US", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", "fr-FR", null, "value2", "Another value 2");
|
||||
|
||||
//act
|
||||
var err1 = serverValidationManager.getPropertyError("myProperty", "en-US", "value1");
|
||||
var err1NotFound = serverValidationManager.getPropertyError("myProperty", null, "value2");
|
||||
var err2 = serverValidationManager.getPropertyError("myProperty", "fr-FR", "value2");
|
||||
var err2NotFound = serverValidationManager.getPropertyError("myProperty", null, "value2");
|
||||
var err1 = serverValidationManager.getPropertyError("myProperty", "en-US", null, "value1");
|
||||
var err1NotFound = serverValidationManager.getPropertyError("myProperty", null, null, "value2");
|
||||
var err2 = serverValidationManager.getPropertyError("myProperty", "fr-FR", null, "value2");
|
||||
var err2NotFound = serverValidationManager.getPropertyError("myProperty", null, null, "value2");
|
||||
|
||||
|
||||
//assert
|
||||
@@ -115,8 +115,8 @@
|
||||
it('can add a property errors with multiple sub fields and it the first will be retreived with only the property alias', function () {
|
||||
|
||||
//arrange
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value2", "Another value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value2", "Another value 2");
|
||||
|
||||
//act
|
||||
var err = serverValidationManager.getPropertyError("myProperty");
|
||||
@@ -132,10 +132,10 @@
|
||||
it('will return null for a non-existing property error', function () {
|
||||
|
||||
//arrage
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value", "Required");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value", "Required");
|
||||
|
||||
//act
|
||||
var err = serverValidationManager.getPropertyError("DoesntExist", null, "value");
|
||||
var err = serverValidationManager.getPropertyError("DoesntExist", null, null, "value");
|
||||
|
||||
//assert
|
||||
expect(err).toBeUndefined();
|
||||
@@ -145,15 +145,15 @@
|
||||
it('detects if a property error exists', function () {
|
||||
|
||||
//arrange
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value2", "Another value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value2", "Another value 2");
|
||||
|
||||
//act
|
||||
var err1 = serverValidationManager.hasPropertyError("myProperty");
|
||||
var err2 = serverValidationManager.hasPropertyError("myProperty", null, "value1");
|
||||
var err3 = serverValidationManager.hasPropertyError("myProperty", null, "value2");
|
||||
var err2 = serverValidationManager.hasPropertyError("myProperty", null, null, "value1");
|
||||
var err3 = serverValidationManager.hasPropertyError("myProperty", null, null, "value2");
|
||||
var err4 = serverValidationManager.hasPropertyError("notFound");
|
||||
var err5 = serverValidationManager.hasPropertyError("myProperty", null, "notFound");
|
||||
var err5 = serverValidationManager.hasPropertyError("myProperty", null, null, "notFound");
|
||||
|
||||
//assert
|
||||
expect(err1).toBe(true);
|
||||
@@ -167,15 +167,15 @@
|
||||
it('can remove a property error with a sub field specified', function () {
|
||||
|
||||
//arrage
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value2", "Another value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value2", "Another value 2");
|
||||
|
||||
//act
|
||||
serverValidationManager.removePropertyError("myProperty", null, "value1");
|
||||
serverValidationManager.removePropertyError("myProperty", null, null, "value1");
|
||||
|
||||
//assert
|
||||
expect(serverValidationManager.hasPropertyError("myProperty", null, "value1")).toBe(false);
|
||||
expect(serverValidationManager.hasPropertyError("myProperty", null, "value2")).toBe(true);
|
||||
expect(serverValidationManager.hasPropertyError("myProperty", null, null, "value1")).toBe(false);
|
||||
expect(serverValidationManager.hasPropertyError("myProperty", null, null, "value2")).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
@@ -189,8 +189,8 @@
|
||||
serverValidationManager.removePropertyError("myProperty");
|
||||
|
||||
//assert
|
||||
expect(serverValidationManager.hasPropertyError("myProperty", null, "value1")).toBe(false);
|
||||
expect(serverValidationManager.hasPropertyError("myProperty", null, "value2")).toBe(false);
|
||||
expect(serverValidationManager.hasPropertyError("myProperty", null, null, "value1")).toBe(false);
|
||||
expect(serverValidationManager.hasPropertyError("myProperty", null, null, "value2")).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
@@ -201,16 +201,16 @@
|
||||
it('can retrieve culture validation errors', function () {
|
||||
|
||||
//arrange
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", "en-US", "value1", "Some value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value2", "Another value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", "fr-FR", "value2", "Another value 3");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", "en-US", null, "value1", "Some value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value2", "Another value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", "fr-FR", null, "value2", "Another value 3");
|
||||
|
||||
//assert
|
||||
expect(serverValidationManager.hasCultureError(null)).toBe(true);
|
||||
expect(serverValidationManager.hasCultureError("en-US")).toBe(true);
|
||||
expect(serverValidationManager.hasCultureError("fr-FR")).toBe(true);
|
||||
expect(serverValidationManager.hasCultureError("es-ES")).toBe(false);
|
||||
expect(serverValidationManager.hasVariantError(null, null)).toBe(true);
|
||||
expect(serverValidationManager.hasVariantError("en-US", null)).toBe(true);
|
||||
expect(serverValidationManager.hasVariantError("fr-FR", null)).toBe(true);
|
||||
expect(serverValidationManager.hasVariantError("es-ES", null)).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
@@ -222,7 +222,7 @@
|
||||
var args;
|
||||
|
||||
//arrange
|
||||
serverValidationManager.subscribe(null, null, "Name", function (isValid, propertyErrors, allErrors) {
|
||||
serverValidationManager.subscribe(null, null, null, "Name", function (isValid, propertyErrors, allErrors) {
|
||||
args = {
|
||||
isValid: isValid,
|
||||
propertyErrors: propertyErrors,
|
||||
@@ -232,7 +232,7 @@
|
||||
|
||||
//act
|
||||
serverValidationManager.addFieldError("Name", "Required");
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value1", "Some value 1");
|
||||
|
||||
//assert
|
||||
expect(args).not.toBeUndefined();
|
||||
@@ -249,8 +249,8 @@
|
||||
};
|
||||
var cb2 = function () {
|
||||
};
|
||||
serverValidationManager.subscribe(null, null, "Name", cb1);
|
||||
serverValidationManager.subscribe(null, null, "Title", cb2);
|
||||
serverValidationManager.subscribe(null, null, null, "Name", cb1);
|
||||
serverValidationManager.subscribe(null, null, null, "Title", cb2);
|
||||
|
||||
//act
|
||||
serverValidationManager.addFieldError("Name", "Required");
|
||||
@@ -278,7 +278,7 @@
|
||||
var numCalled = 0;
|
||||
|
||||
//arrange
|
||||
serverValidationManager.subscribe("myProperty", null, "value1", function (isValid, propertyErrors, allErrors) {
|
||||
serverValidationManager.subscribe("myProperty", null, null, "value1", function (isValid, propertyErrors, allErrors) {
|
||||
args1 = {
|
||||
isValid: isValid,
|
||||
propertyErrors: propertyErrors,
|
||||
@@ -286,7 +286,7 @@
|
||||
};
|
||||
});
|
||||
|
||||
serverValidationManager.subscribe("myProperty", null, "", function (isValid, propertyErrors, allErrors) {
|
||||
serverValidationManager.subscribe("myProperty", null, null, "", function (isValid, propertyErrors, allErrors) {
|
||||
numCalled++;
|
||||
args2 = {
|
||||
isValid: isValid,
|
||||
@@ -296,9 +296,9 @@
|
||||
});
|
||||
|
||||
//act
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value2", "Some value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", null, "", "Some value 3");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value2", "Some value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "", "Some value 3");
|
||||
|
||||
//assert
|
||||
expect(args1).not.toBeUndefined();
|
||||
@@ -328,7 +328,7 @@
|
||||
var numCalled = 0;
|
||||
|
||||
//arrange
|
||||
serverValidationManager.subscribe(null, "en-US", null, function (isValid, propertyErrors, allErrors) {
|
||||
serverValidationManager.subscribe(null, "en-US", null, null, function (isValid, propertyErrors, allErrors) {
|
||||
numCalled++;
|
||||
args1 = {
|
||||
isValid: isValid,
|
||||
@@ -337,7 +337,7 @@
|
||||
};
|
||||
});
|
||||
|
||||
serverValidationManager.subscribe(null, "es-ES", null, function (isValid, propertyErrors, allErrors) {
|
||||
serverValidationManager.subscribe(null, "es-ES", null, null, function (isValid, propertyErrors, allErrors) {
|
||||
numCalled++;
|
||||
args2 = {
|
||||
isValid: isValid,
|
||||
@@ -347,10 +347,10 @@
|
||||
});
|
||||
|
||||
//act
|
||||
serverValidationManager.addPropertyError("myProperty", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", "en-US", "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", "en-US", "value2", "Some value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", "fr-FR", "", "Some value 3");
|
||||
serverValidationManager.addPropertyError("myProperty", null, null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", "en-US", null, "value1", "Some value 1");
|
||||
serverValidationManager.addPropertyError("myProperty", "en-US", null, "value2", "Some value 2");
|
||||
serverValidationManager.addPropertyError("myProperty", "fr-FR", null, "", "Some value 3");
|
||||
|
||||
//assert
|
||||
expect(args1).not.toBeUndefined();
|
||||
|
||||
Reference in New Issue
Block a user