From e37434d816221cd949c1c9855993e8d3e9683d5d Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Sun, 29 Sep 2019 11:54:12 +0200 Subject: [PATCH] Don't keep appending the content name on each change of the language dropdown (cherry picked from 02c3a5a5b2797d59b229d1fbcc8ab6524f247e55 and 7de7e59f5543031fa0635499306509a42f57f3d7) --- .../umbeditorcontentheader.directive.js | 288 +++++++++--------- src/Umbraco.Web.UI.Client/src/init.js | 10 +- 2 files changed, 153 insertions(+), 145 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 8668d62d4f..b3948bd7c4 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 @@ -3,10 +3,10 @@ function EditorContentHeader(serverValidationManager, localizationService, editorState) { + function link(scope, el, attr, ctrl) { - var unsubscribe = []; - + if (!scope.serverValidationNameField) { scope.serverValidationNameField = "Name"; } @@ -15,15 +15,16 @@ } scope.isNew = scope.content.state == "NotCreated"; - + localizationService.localizeMany([ - scope.isNew ? "placeholders_a11yCreateItem" : "placeholders_a11yEdit", + scope.isNew ? "placeholders_a11yCreateItem" : "placeholders_a11yEdit", "placeholders_a11yName", - scope.isNew?"general_new":"general_edit"] + scope.isNew ? "general_new" : "general_edit"] ).then(function (data) { + scope.a11yMessage = data[0]; scope.a11yName = data[1]; - var title = data[2] +":"; + var title = data[2] + ": "; if (!scope.isNew) { scope.a11yMessage += " " + scope.content.name; title += scope.content.name; @@ -33,16 +34,17 @@ scope.a11yName = name + " " + scope.a11yName; title += name; } - scope.$root.locationTitle = title + " - " + scope.$root.locationTitle ; + + scope.$emit("$changeTitle", title); }); scope.vm = {}; scope.vm.dropdownOpen = false; scope.vm.currentVariant = ""; scope.vm.variantsWithError = []; scope.vm.defaultVariant = null; - + scope.vm.errorsOnOtherVariants = false;// indicating wether to show that other variants, than the current, have errors. - + function checkErrorsOnOtherVariants() { var check = false; angular.forEach(scope.content.variants, function (variant) { @@ -52,10 +54,10 @@ }); scope.vm.errorsOnOtherVariants = check; } - + function onCultureValidation(valid, errors, allErrors, culture) { var index = scope.vm.variantsWithError.indexOf(culture); - if(valid === true) { + if (valid === true) { if (index !== -1) { scope.vm.variantsWithError.splice(index, 1); } @@ -66,165 +68,165 @@ } checkErrorsOnOtherVariants(); } - + function onInit() { - + // find default. angular.forEach(scope.content.variants, function (variant) { if (variant.language.isDefault) { scope.vm.defaultVariant = variant; } }); - + setCurrentVariant(); - + angular.forEach(scope.content.apps, (app) => { if (app.alias === "umbContent") { app.anchors = scope.content.tabs; } }); - - - angular.forEach(scope.content.variants, function (variant) { - unsubscribe.push(serverValidationManager.subscribe(null, variant.language.culture, null, onCultureValidation)); - }); - - unsubscribe.push(serverValidationManager.subscribe(null, null, null, onCultureValidation)); - - - - } - function setCurrentVariant() { - angular.forEach(scope.content.variants, function (variant) { - if (variant.active) { - scope.vm.currentVariant = variant; - checkErrorsOnOtherVariants(); - } - }); - } - scope.goBack = function () { - if (scope.onBack) { - scope.onBack(); - } - }; + angular.forEach(scope.content.variants, function (variant) { + unsubscribe.push(serverValidationManager.subscribe(null, variant.language.culture, null, onCultureValidation)); + }); - scope.selectVariant = function (event, variant) { + unsubscribe.push(serverValidationManager.subscribe(null, null, null, onCultureValidation)); - if (scope.onSelectVariant) { - scope.vm.dropdownOpen = false; - scope.onSelectVariant({ "variant": variant }); - } - }; - 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.closeSplitView = function () { - if (scope.onCloseSplitView) { - scope.onCloseSplitView(); - } - }; - - scope.openInSplitView = function (event, variant) { - if (scope.onOpenInSplitView) { - scope.vm.dropdownOpen = false; - scope.onOpenInSplitView({ "variant": variant }); - } - }; - - /** - * keep track of open variants - this is used to prevent the same variant to be open in more than one split view - * @param {any} culture - */ - scope.variantIsOpen = function(culture) { - return (scope.openVariants.indexOf(culture) !== -1); - } - - /** - * Check whether a variant has a error, used to display errors in variant switcher. - * @param {any} culture - */ - scope.variantHasError = function(culture) { - // if we are looking for the default language we also want to check for invariant. - if (culture === scope.vm.defaultVariant.language.culture) { - if(scope.vm.variantsWithError.indexOf("invariant") !== -1) { - return true; - } - } - if(scope.vm.variantsWithError.indexOf(culture) !== -1) { - return true; - } - return false; - } - - onInit(); - - //watch for the active culture changing, if it changes, update the current variant - if (scope.content.variants) { - scope.$watch(function () { - for (var i = 0; i < scope.content.variants.length; i++) { - var v = scope.content.variants[i]; - if (v.active) { - return v.language.culture; - } - } - return scope.vm.currentVariant.language.culture; //should never get here - }, function (newValue, oldValue) { - if (newValue !== scope.vm.currentVariant.language.culture) { - setCurrentVariant(); - } - }); - } - - scope.$on('$destroy', function () { - for (var u in unsubscribe) { - unsubscribe[u](); + function setCurrentVariant() { + angular.forEach(scope.content.variants, function (variant) { + if (variant.active) { + scope.vm.currentVariant = variant; + checkErrorsOnOtherVariants(); } }); } - - var directive = { - transclude: true, - restrict: 'E', - replace: true, - templateUrl: 'views/components/editor/umb-editor-content-header.html', - scope: { - name: "=", - nameDisabled: "