From 01589f0a35a30c15ef3b2a857ceba0b7635c42af Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 13 Nov 2013 20:14:33 +1100 Subject: [PATCH] Cleans up some more tree code that is not used or required, moves the ui.treeEventHandler to a local var in the nav service since it doesn't need to be exposed, fixes main controller redirecting due to an undefined check. --- .../common/directives/umbtree.directive.js | 8 ++--- .../directives/umbtreeitem.directive.js | 2 +- .../src/common/services/navigation.service.js | 36 +++++++++---------- .../src/views/common/main.controller.js | 2 +- 4 files changed, 22 insertions(+), 26 deletions(-) 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 27acd7650a..5e0b2f0b16 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 @@ -35,7 +35,7 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat ''; } template += '' + '' + ''; @@ -51,10 +51,7 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat // reload it. This saves a lot on processing if someone is navigating in and out of the same section many times // since it saves on data retreival and DOM processing. var lastSection = ""; - - //keeps track of the currently active tree being called by editors syncing - var activeTree; - + //setup a default internal handler if (!scope.eventhandler) { scope.eventhandler = $({}); @@ -346,7 +343,6 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat //store the new section to be loaded as the last section //clear any active trees to reset lookups lastSection = newVal; - activeTree = undefined; } }); diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/umbtreeitem.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/umbtreeitem.directive.js index 0c15e448ac..4aad227034 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/umbtreeitem.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/umbtreeitem.directive.js @@ -160,7 +160,7 @@ angular.module("umbraco.directives") $(element).find("i").attr("style", scope.node.style); } - var template = ''; + var template = ''; var newElement = angular.element(template); $compile(newElement)(scope); element.append(newElement); diff --git a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js index 009ba33022..8100e9270c 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js @@ -22,13 +22,13 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo var currentDialog = null; //tracks the screen size as a tablet var isTablet = false; + //the main tree event handler, which gets assigned via the setupTreeEvents method + var mainTreeEventHandler = null; //TODO: Once most of the state vars have been refactored out to use appState, this UI object will be internal ONLY and will not be // exposed from this service. var ui = { - currentPath: undefined, currentTree: undefined, - treeEventHandler: undefined, currentNode: undefined, //a string/name reference for the currently set ui mode @@ -197,10 +197,10 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo // node on the ui object?? This is a mess. setupTreeEvents: function(treeEventHandler, scope) { - this.ui.treeEventHandler = treeEventHandler; + mainTreeEventHandler = treeEventHandler; //when a tree node is synced this event will fire, this allows us to set the currentNode - this.ui.treeEventHandler.bind("treeSynced", function (ev, args) { + mainTreeEventHandler.bind("treeSynced", function (ev, args) { //set the global current node ui.currentNode = args.node; @@ -214,7 +214,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo }); //this reacts to the options item in the tree - this.ui.treeEventHandler.bind("treeOptionsClick", function(ev, args) { + mainTreeEventHandler.bind("treeOptionsClick", function(ev, args) { ev.stopPropagation(); ev.preventDefault(); @@ -231,7 +231,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo service.showMenu(ev, args); }); - this.ui.treeEventHandler.bind("treeNodeAltSelect", function(ev, args) { + mainTreeEventHandler.bind("treeNodeAltSelect", function(ev, args) { ev.stopPropagation(); ev.preventDefault(); @@ -244,7 +244,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo //this reacts to tree items themselves being clicked //the tree directive should not contain any handling, simply just bubble events - this.ui.treeEventHandler.bind("treeNodeSelect", function(ev, args) { + mainTreeEventHandler.bind("treeNodeSelect", function(ev, args) { var n = args.node; ev.stopPropagation(); ev.preventDefault(); @@ -314,8 +314,8 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo throw "args.tree cannot be null"; } - if (this.ui.treeEventHandler) { - this.ui.treeEventHandler.syncTree(args); + if (mainTreeEventHandler) { + mainTreeEventHandler.syncTree(args); } }, @@ -324,21 +324,21 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo have to set an active tree and then sync, the new API does this in one method by using syncTree */ _syncPath: function(path, forceReload) { - if (this.ui.treeEventHandler) { - this.ui.treeEventHandler.syncTree({ path: path, forceReload: forceReload }); + if (mainTreeEventHandler) { + mainTreeEventHandler.syncTree({ path: path, forceReload: forceReload }); } }, reloadNode: function(node) { - if (this.ui.treeEventHandler) { - this.ui.treeEventHandler.reloadNode(node); + if (mainTreeEventHandler) { + mainTreeEventHandler.reloadNode(node); } }, reloadSection: function(sectionAlias) { - if (this.ui.treeEventHandler) { - this.ui.treeEventHandler.clearCache({ section: sectionAlias }); - this.ui.treeEventHandler.load(sectionAlias); + if (mainTreeEventHandler) { + mainTreeEventHandler.clearCache({ section: sectionAlias }); + mainTreeEventHandler.load(sectionAlias); } }, @@ -347,8 +347,8 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo have to set an active tree and then sync, the new API does this in one method by using syncTreePath */ _setActiveTreeType: function (treeAlias, loadChildren) { - if (this.ui.treeEventHandler) { - this.ui.treeEventHandler._setActiveTreeType(treeAlias, loadChildren); + if (mainTreeEventHandler) { + mainTreeEventHandler._setActiveTreeType(treeAlias, loadChildren); } }, diff --git a/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js index 697507df36..b781000a0f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js @@ -89,7 +89,7 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ //if the user has changed we need to redirect to the root so they don't try to continue editing the //last item in the URL - if (data.lastUserId !== undefined && data.lastUserId !== data.user.id) { + if (data.lastUserId !== undefined && data.lastUserId !== null && data.lastUserId !== data.user.id) { $location.path("/").search(""); historyService.removeAll(); treeService.clearCache();