diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js index a69f13677a..c044a1edd2 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js @@ -60,7 +60,6 @@ angular.module("umbraco.directives") if (scope.eventhandler) { $(scope.eventhandler).trigger(eventName, args); } - // $rootScope.$broadcast(eventName, args); } /** Method to load in the tree data */ @@ -93,7 +92,7 @@ angular.module("umbraco.directives") * When changing sections we don't want all of the tree-ndoes to do their 'leave' animations. */ scope.animation = function () { - if (enableDeleteAnimations && scope.tree.root.expanded) { + if (enableDeleteAnimations && scope.tree && scope.tree.root && scope.tree.root.expanded) { return { leave: 'tree-node-delete-leave' }; } else { @@ -126,8 +125,17 @@ angular.module("umbraco.directives") } }); - //initial change - loadTree(); + //When the user logs in + scope.$on("authenticated", function (evt, data) { + //populate the tree if the user has changed + if (data.lastUserId !== data.user.id) { + treeService.clearCache(); + scope.tree = null; + loadTree(); + } + }); + + }; } }; diff --git a/src/Umbraco.Web.UI.Client/src/common/services/tree.service.js b/src/Umbraco.Web.UI.Client/src/common/services/tree.service.js index db8a892618..a2b8961879 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/tree.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/tree.service.js @@ -8,8 +8,10 @@ * The tree service factory, used internally by the umbTree and umbTreeItem directives */ function treeService($q, treeResource, iconHelper, notificationsService, $rootScope) { - //implement this in local storage + + //TODO: implement this in local storage var treeArray = []; + var standardCssClass = 'icon umb-tree-icon sprTree'; return { @@ -58,6 +60,11 @@ function treeService($q, treeResource, iconHelper, notificationsService, $rootSc } }, + /** clears the tree cache */ + clearCache: function() { + treeArray = []; + }, + /** * @ngdoc method * @name umbraco.services.treeService#loadNodeChildren @@ -259,6 +266,7 @@ function treeService($q, treeResource, iconHelper, notificationsService, $rootSc return data; }); } + }; } diff --git a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js index 5bf23e97c3..626b11b98f 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js @@ -38,8 +38,10 @@ angular.module('umbraco.services') securityRetryQueue.onItemAddedCallbacks.push(function (retryItem) { if (securityRetryQueue.hasMore()) { - //clear the user - lastUserId = currentUser.id; + //store the last user id and clear the user + if (currentUser && currentUser.id !== undefined) { + lastUserId = currentUser.id; + } currentUser = null; //broadcast a global event that the user is no longer logged in @@ -63,7 +65,7 @@ angular.module('umbraco.services') } else { - var result = { user: data, authenticated: true }; + var result = { user: data, authenticated: true, lastUserId: lastUserId }; if (args.broadcastEvent) { //broadcast a global event, will inform listening controllers to load in the user specific data @@ -86,7 +88,7 @@ angular.module('umbraco.services') //when it's successful, return the user data currentUser = data; - var result = { user: data, authenticated: true, previousUserId: lastUserId }; + var result = { user: data, authenticated: true, lastUserId: lastUserId }; //broadcast a global event $rootScope.$broadcast("authenticated", result); diff --git a/src/Umbraco.Web.UI.Client/src/views/common/navigation.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/navigation.controller.js index 35f6b82b73..2f12a2a40d 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/navigation.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/navigation.controller.js @@ -33,19 +33,16 @@ function NavigationController($scope,$rootScope, $location, $log, $routeParams, $scope.selectedId = navigationService.currentId; $scope.sections = navigationService.sections; - - //When the user logs out or times out - $scope.$on("notAuthenticated", function () { - - }); //When the user logs in $scope.$on("authenticated", function (evt, data) { - //populate their sections if the user hasn't changed - sectionResource.getSections() - .then(function(result) { - $scope.sections = result; - }); + //populate their sections if the user has changed + if (data.lastUserId !== data.user.id) { + sectionResource.getSections() + .then(function (result) { + $scope.sections = result; + }); + } }); //This reacts to clicks passed to the body element which emits a global call to close all dialogs