From 52c4a572473a47daed3973285a5798b424f4b83f Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 26 Sep 2019 18:43:09 +0200 Subject: [PATCH] In addition to #6236 - now this now longer keeps appending the content name on each change of the language dropdown --- .../umbeditorcontentheader.directive.js | 268 +++++++++--------- src/Umbraco.Web.UI.Client/src/init.js | 10 +- 2 files changed, 143 insertions(+), 135 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 8668d62d4fac..b26113c9d10f 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 ; + + $rootScope.$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}); + + } + + 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(); } + }; - scope.selectAnchorItem = function(item, anchor) { - if(scope.onSelectAnchorItem) { - scope.onSelectAnchorItem({"item": item, "anchor": anchor}); - } + scope.selectVariant = function (event, variant) { + + if (scope.onSelectVariant) { + scope.vm.dropdownOpen = false; + scope.onSelectVariant({ "variant": variant }); } + }; - scope.closeSplitView = function () { - if (scope.onCloseSplitView) { - scope.onCloseSplitView(); - } - }; + scope.selectNavigationItem = function (item) { + if (scope.onSelectNavigationItem) { + scope.onSelectNavigationItem({ "item": item }); + } + } - 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); + scope.selectAnchorItem = function (item, anchor) { + if (scope.onSelectAnchorItem) { + scope.onSelectAnchorItem({ "item": item, "anchor": anchor }); } - - /** - * 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) { + } + + 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; } - return false; } + if (scope.vm.variantsWithError.indexOf(culture) !== -1) { + return true; + } + return false; + } - onInit(); + 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; - } + //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](); + } + 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](); + } + }); + } - var directive = { - transclude: true, - restrict: 'E', - replace: true, - templateUrl: 'views/components/editor/umb-editor-content-header.html', - scope: { - name: "=", - nameDisabled: "