diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/umbcontextmenu.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/umbcontextmenu.directive.js index f734c40d19..fe76931c1e 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/umbcontextmenu.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/umbcontextmenu.directive.js @@ -8,6 +8,7 @@ angular.module("umbraco.directives") //setup scope vars scope.currentSection = appState.getSectionState("currentSection"); + scope.showMenu = appState.getMenuState("showMenu"); //listen for section change scope.$on("appState.sectionState.changed", function(e, args) { @@ -15,6 +16,13 @@ angular.module("umbraco.directives") scope.currentSection = args.value; } }); + + //listen for menu change + scope.$on("appState.menuState.changed", function (e, args) { + if (args.key === "showMenu") { + scope.showMenu = args.value; + } + }); //adds a handler to the context menu item click, we need to handle this differently //depending on what the menu item is supposed to do. diff --git a/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js b/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js index d288431635..b1a95fee7c 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js @@ -29,7 +29,9 @@ function appState($rootScope) { var menuState = { //The basic entity that is having an action performed on it currentEntity: null, - //Whether the menu is being shown or not + //Whether the menu's dialog is being shown or not + showMenuDialog: null, + //Whether the context menu is being shown or not showMenu: null }; 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 ac4e0b6e61..f64e16b262 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,7 +22,6 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo //Define all sub-properties for the UI object here var ui = { tablet: false, - showContextMenu: false, stickyNavigation: false, showTray: false, currentPath: undefined, @@ -51,8 +50,8 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo case 'tree': ui.currentMode = "tree"; appState.setGlobalState("showNavigation", true); - ui.showContextMenu = false; appState.setMenuState("showMenu", false); + appState.setMenuState("showMenuDialog", false); ui.stickyNavigation = false; ui.showTray = false; @@ -61,25 +60,26 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo case 'menu': ui.currentMode = "menu"; appState.setGlobalState("showNavigation", true); - ui.showContextMenu = true; - appState.setMenuState("showMenu", false); + appState.setMenuState("showMenu", true); + appState.setMenuState("showMenuDialog", false); ui.stickyNavigation = true; break; case 'dialog': ui.currentMode = "dialog"; ui.stickyNavigation = true; appState.setGlobalState("showNavigation", true); - ui.showContextMenu = false; - appState.setMenuState("showMenu", true); + appState.setMenuState("showMenu", false); + appState.setMenuState("showMenuDialog", true); break; case 'search': ui.currentMode = "search"; ui.stickyNavigation = false; appState.setGlobalState("showNavigation", true); - ui.showContextMenu = false; - appState.setSectionState("showSearchResults", true); appState.setMenuState("showMenu", false); + appState.setSectionState("showSearchResults", true); + appState.setMenuState("showMenuDialog", false); + //TODO: This would be much better off in the search field controller listening to appState changes $timeout(function() { $("#search-field").focus(); }); @@ -87,8 +87,8 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo break; default: ui.currentMode = "default"; - ui.showContextMenu = false; appState.setMenuState("showMenu", false); + appState.setMenuState("showMenuDialog", false); appState.setSectionState("showSearchResults", false); ui.stickyNavigation = false; ui.showTray = false; @@ -122,6 +122,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo appState.setSectionState("currentSection", newVal); }); + //TODO: This does not belong here - would be much better off in a directive $(window).bind("resize", function() { setTreeMode(); }); diff --git a/src/Umbraco.Web.UI.Client/src/init.js b/src/Umbraco.Web.UI.Client/src/init.js new file mode 100644 index 0000000000..78aab7383b --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/init.js @@ -0,0 +1,29 @@ +/** Executed when the application starts */ +app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', function (userService, $log, $rootScope, $location, navigationService) { + + var firstRun = true; + + /** when we have a successful first route that is not the login page - meaning the user is authenticated + we'll get the current user from the user service and ensure it broadcasts it's events. If the route + is successful from after a login then this will not actually do anything since the authenticated event would + have alraedy fired, but if the user is loading the angularjs app for the first time and they are already authenticated + then this is when the authenticated event will be fired. + */ + $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { + if (firstRun && !$location.url().toLowerCase().startsWith("/login")) { + firstRun = false; + userService.getCurrentUser({ broadcastEvent: true }); + } + }); + + /** When the route change is rejected - based on checkAuth - we'll prevent the rejected route from executing including + wiring up it's controller, etc... and then redirect to the rejected URL. */ + $rootScope.$on('$routeChangeError', function (event, current, previous, rejection) { + event.preventDefault(); + $location.path(rejection.path).search(rejection.search); + }); + + /* this will initialize the navigation service once the application has started */ + navigationService.init(); + +}]); diff --git a/src/Umbraco.Web.UI.Client/src/loader.js b/src/Umbraco.Web.UI.Client/src/loader.js index b06ecd0905..62b05ea2d6 100644 --- a/src/Umbraco.Web.UI.Client/src/loader.js +++ b/src/Umbraco.Web.UI.Client/src/loader.js @@ -57,7 +57,8 @@ yepnope({ 'js/umbraco.services.js', 'js/umbraco.security.js', 'js/umbraco.controllers.js', - 'js/routes.js' + 'js/routes.js', + 'js/init.js' ], complete: function () { diff --git a/src/Umbraco.Web.UI.Client/src/routes.js b/src/Umbraco.Web.UI.Client/src/routes.js index 3d4b1dbd8a..15f08ec2cc 100644 --- a/src/Umbraco.Web.UI.Client/src/routes.js +++ b/src/Umbraco.Web.UI.Client/src/routes.js @@ -119,31 +119,4 @@ app.config(function ($routeProvider) { //$locationProvider.html5Mode(false).hashPrefix('!'); //turn html5 mode off // $locationProvider.html5Mode(true); //turn html5 mode on -}); - - -app.run(['userService', '$log', '$rootScope', '$location', function (userService, $log, $rootScope, $location) { - - var firstRun = true; - - /** when we have a successful first route that is not the login page - meaning the user is authenticated - we'll get the current user from the user service and ensure it broadcasts it's events. If the route - is successful from after a login then this will not actually do anything since the authenticated event would - have alraedy fired, but if the user is loading the angularjs app for the first time and they are already authenticated - then this is when the authenticated event will be fired. - */ - $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { - if (firstRun && !$location.url().toLowerCase().startsWith("/login")) { - firstRun = false; - userService.getCurrentUser({ broadcastEvent: true }); - } - }); - - /** When the route change is rejected - based on checkAuth - we'll prevent the rejected route from executing including - wiring up it's controller, etc... and then redirect to the rejected URL. */ - $rootScope.$on('$routeChangeError', function (event, current, previous, rejection) { - event.preventDefault(); - $location.path(rejection.path).search(rejection.search); - }); - -}]); +}); \ No newline at end of file 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 262a5ba1d1..e13c379aa1 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 @@ -8,7 +8,7 @@ * The main application controller * */ -function MainController($scope, $rootScope, $location, $routeParams, $rootScope, $timeout, $http, $log, notificationsService, userService, navigationService, historyService, legacyJsLoader, updateChecker) { +function MainController($scope, $rootScope, $location, $routeParams, $timeout, $http, $log, notificationsService, userService, navigationService, historyService, legacyJsLoader, updateChecker) { var legacyTreeJsLoaded = false; 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 728514cfa6..c2616bd84b 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 @@ -11,9 +11,7 @@ */ function NavigationController($scope, $rootScope, $location, $log, $routeParams, appState, navigationService, keyboardService, dialogService, historyService, sectionResource, angularHelper) { - //TODO: Put all of this nav service init in the main controller ! - or on the appStart not here! - //initialize nav service - navigationService.init(); + //TODO: Put all of this nav service init in the main controller ! - or on the appStart not here! //the tree event handler i used to subscribe to the main tree click events $scope.treeEventHandler = $({}); navigationService.setupTreeEvents($scope.treeEventHandler, $scope); @@ -51,7 +49,7 @@ function NavigationController($scope, $rootScope, $location, $log, $routeParams, //Listen for menu state changes $scope.$on("appState.menuState.changed", function(e, args) { - if (args.key === "showMenu") { + if (args.key === "showMenuDialog") { $scope.showContextMenuDialog = args.value; } }); diff --git a/src/Umbraco.Web.UI.Client/src/views/directives/umb-contextmenu.html b/src/Umbraco.Web.UI.Client/src/views/directives/umb-contextmenu.html index 135feb628c..8b7fcb8f12 100644 --- a/src/Umbraco.Web.UI.Client/src/views/directives/umb-contextmenu.html +++ b/src/Umbraco.Web.UI.Client/src/views/directives/umb-contextmenu.html @@ -1,6 +1,6 @@