Skip to content

Commit

Permalink
In addition to #6236 - now this now longer keeps appending the conten…
Browse files Browse the repository at this point in the history
…t name on each change of the language dropdown
  • Loading branch information
nul800sebastiaan committed Sep 26, 2019
1 parent 5831cd9 commit 02c3a5a
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

function EditorContentHeader(serverValidationManager, localizationService, editorState) {


function link(scope, el, attr, ctrl) {

var unsubscribe = [];

if (!scope.serverValidationNameField) {
scope.serverValidationNameField = "Name";
}
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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: "<?",
menu: "=",
hideActionsMenu: "<?",
content: "=",
openVariants: "<",
hideChangeVariant: "<?",
onSelectNavigationItem: "&?",
onSelectAnchorItem: "&?",
showBackButton: "<?",
onBack: "&?",
splitViewOpen: "=?",
onOpenInSplitView: "&?",
onCloseSplitView: "&?",
onSelectVariant: "&?",
serverValidationNameField: "@?",
serverValidationAliasField: "@?"
},
link: link
};

return directive;
}
var directive = {
transclude: true,
restrict: 'E',
replace: true,
templateUrl: 'views/components/editor/umb-editor-content-header.html',
scope: {
name: "=",
nameDisabled: "<?",
menu: "=",
hideActionsMenu: "<?",
content: "=",
openVariants: "<",
hideChangeVariant: "<?",
onSelectNavigationItem: "&?",
onSelectAnchorItem: "&?",
showBackButton: "<?",
onBack: "&?",
splitViewOpen: "=?",
onOpenInSplitView: "&?",
onCloseSplitView: "&?",
onSelectVariant: "&?",
serverValidationNameField: "@?",
serverValidationAliasField: "@?"
},
link: link
};

return directive;
}

angular.module('umbraco.directives').directive('umbEditorContentHeader', EditorContentHeader);

})();
}) ();
10 changes: 8 additions & 2 deletions src/Umbraco.Web.UI.Client/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ app.run(['$rootScope', '$route', '$location', 'urlHelper', 'navigationService',
}

var currentRouteParams = null;


var originalTitle = "";

$rootScope.$on('$changeTitle',function (event, titlePrefix) {
$rootScope.locationTitle = titlePrefix;
});

/** execute code on each successful route */
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {

Expand Down Expand Up @@ -90,7 +96,7 @@ app.run(['$rootScope', '$route', '$location', 'urlHelper', 'navigationService',

$rootScope.locationTitle = "Umbraco - " + $location.$$host;
}

originalTitle = $rootScope.locationTitle;
});

/** When the route change is rejected - based on checkAuth - we'll prevent the rejected route from executing including
Expand Down

0 comments on commit 02c3a5a

Please sign in to comment.