From 1c5b144cbb5b4259d872954ef69540dfc23dd3fd Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 26 Jun 2020 15:44:27 +1000 Subject: [PATCH] fixes issue with umbeditorcontentheader.directive which will throw an exception during validatino preventing all validation from working when working with invariant content (ouch) --- .../umbeditorcontentheader.directive.js | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorcontentheader.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorcontentheader.directive.js index 9b8f92d7c3..fdec4c98d0 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorcontentheader.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorcontentheader.directive.js @@ -2,10 +2,10 @@ 'use strict'; function EditorContentHeader(serverValidationManager, localizationService, editorState) { - function link(scope) { + function link(scope) { var unsubscribe = []; - + if (!scope.serverValidationNameField) { scope.serverValidationNameField = "Name"; } @@ -46,55 +46,55 @@ scope.vm.variantsWithError = []; scope.vm.defaultVariant = null; scope.vm.errorsOnOtherVariants = false;// indicating wether to show that other variants, than the current, have errors. - + function updateVaraintErrors() { - scope.content.variants.forEach( function (variant) { + scope.content.variants.forEach(function (variant) { variant.hasError = scope.variantHasError(variant); - + }); checkErrorsOnOtherVariants(); } function checkErrorsOnOtherVariants() { var check = false; - scope.content.variants.forEach( function (variant) { + scope.content.variants.forEach(function (variant) { if (variant.active !== true && variant.hasError) { check = true; } }); scope.vm.errorsOnOtherVariants = check; } - + function onVariantValidation(valid, errors, allErrors, culture, segment) { // only want to react to property errors: - if(errors.findIndex(error => {return error.propertyAlias !== null;}) === -1) { + if (errors.findIndex(error => { return error.propertyAlias !== null; }) === -1) { // we dont have any errors for properties, meaning we will back out. return; } // If error coming back is invariant, we will assign the error to the default variant by picking the defaultVariant language. - if(culture === "invariant") { + if (culture === "invariant" && scope.vm.defaultVariant) { culture = scope.vm.defaultVariant.language.culture; } var index = scope.vm.variantsWithError.findIndex((item) => item.culture === culture && item.segment === segment) - if(valid === true) { + if (valid === true) { if (index !== -1) { scope.vm.variantsWithError.splice(index, 1); } } else { if (index === -1) { - scope.vm.variantsWithError.push({"culture": culture, "segment": segment}); + scope.vm.variantsWithError.push({ "culture": culture, "segment": segment }); } } scope.$evalAsync(updateVaraintErrors); } - + function onInit() { - + // find default + check if we have variants. - scope.content.variants.forEach( function (variant) { + scope.content.variants.forEach(function (variant) { if (variant.language !== null && variant.language.isDefault) { scope.vm.defaultVariant = variant; } @@ -113,41 +113,41 @@ scope.vm.variantMenu = []; if (scope.vm.hasCulture) { - scope.content.variants.forEach( (v) => { + scope.content.variants.forEach((v) => { if (v.language !== null && v.segment === null) { var variantMenuEntry = { key: String.CreateGuid(), open: v.language && v.language.culture === scope.editor.culture, variant: v, - subVariants: scope.content.variants.filter( (subVariant) => subVariant.language.culture === v.language.culture && subVariant.segment !== null) + subVariants: scope.content.variants.filter((subVariant) => subVariant.language.culture === v.language.culture && subVariant.segment !== null) }; scope.vm.variantMenu.push(variantMenuEntry); } }); } else { - scope.content.variants.forEach( (v) => { + scope.content.variants.forEach((v) => { scope.vm.variantMenu.push({ key: String.CreateGuid(), variant: v }); }); } - - scope.editor.variantApps.forEach( (app) => { + + scope.editor.variantApps.forEach((app) => { if (app.alias === "umbContent") { app.anchors = scope.editor.content.tabs; } }); - scope.content.variants.forEach( function (variant) { - + scope.content.variants.forEach(function (variant) { + // if we are looking for the variant with default language then we also want to check for invariant variant. - if (variant.language && variant.language.culture === scope.vm.defaultVariant.language.culture && variant.segment === null) { + if (variant.language && scope.vm.defaultVariant && variant.language.culture === scope.vm.defaultVariant.language.culture && variant.segment === null) { unsubscribe.push(serverValidationManager.subscribe(null, "invariant", null, onVariantValidation, null)); } unsubscribe.push(serverValidationManager.subscribe(null, variant.language !== null ? variant.language.culture : null, null, onVariantValidation, variant.segment)); }); - + } scope.goBack = function () { @@ -164,15 +164,15 @@ } }; - scope.selectNavigationItem = function(item) { - if(scope.onSelectNavigationItem) { - scope.onSelectNavigationItem({"item": item}); + scope.selectNavigationItem = function (item) { + if (scope.onSelectNavigationItem) { + scope.onSelectNavigationItem({ "item": item }); } } - scope.selectAnchorItem = function(item, anchor) { - if(scope.onSelectAnchorItem) { - scope.onSelectAnchorItem({"item": item, "anchor": anchor}); + scope.selectAnchorItem = function (item, anchor) { + if (scope.onSelectAnchorItem) { + scope.onSelectAnchorItem({ "item": item, "anchor": anchor }); } } @@ -188,20 +188,20 @@ scope.onOpenInSplitView({ "variant": variant }); } }; - + /** * Check whether a variant has a error, used to display errors in variant switcher. * @param {any} culture */ - scope.variantHasError = function(variant) { - if(scope.vm.variantsWithError.find((item) => (!variant.language || item.culture === variant.language.culture) && item.segment === variant.segment) !== undefined) { + scope.variantHasError = function (variant) { + if (scope.vm.variantsWithError.find((item) => (!variant.language || item.culture === variant.language.culture) && item.segment === variant.segment) !== undefined) { return true; } return false; } onInit(); - + scope.$on('$destroy', function () { for (var u in unsubscribe) { unsubscribe[u]();