diff --git a/src/app/auth/controller/auth_token_controller.js b/src/app/auth/controller/auth_token_controller.js index 944dda78..e7f1ea9c 100644 --- a/src/app/auth/controller/auth_token_controller.js +++ b/src/app/auth/controller/auth_token_controller.js @@ -22,8 +22,8 @@ */ angular.module('sb.auth').controller('AuthTokenController', - function ($state, $log, OpenId, Session, $searchParams, $window, UrlUtil, - LastLocation) { + function ($state, $log, OpenId, Session, $searchParams, UrlUtil, + LastLocation) { 'use strict'; // First, check for the edge case where the API returns an error code diff --git a/src/app/storyboard/module.js b/src/app/storyboard/module.js index 03b93cb8..f07d750d 100644 --- a/src/app/storyboard/module.js +++ b/src/app/storyboard/module.js @@ -64,7 +64,8 @@ angular.module('storyboard', } }); }) - .run(function ($log, $rootScope, $document) { + .run(function ($log, $rootScope, $document, $transitions, + LastLocation) { 'use strict'; var resolvingClassName = 'resolving'; @@ -73,28 +74,28 @@ angular.module('storyboard', // Apply a global class to the application when we're in the middle of // a state resolution, as well as a global scope variable that UI views // can switch on. - $rootScope.$on('$stateChangeStart', function () { + $transitions.onStart({}, function(transition){ body.addClass(resolvingClassName); $rootScope.isResolving = true; + LastLocation.onStateChange(transition); }); - $rootScope.$on('$stateChangeSuccess', function () { + $transitions.onSuccess({}, function(){ body.removeClass(resolvingClassName); $rootScope.isResolving = false; }); - $rootScope.$on('$stateChangeError', function () { + $transitions.onError({}, function(){ body.removeClass(resolvingClassName); $rootScope.isResolving = false; }); }) - .run(function ($log, $rootScope, $state) { + .run(function ($log, $rootScope, $state, $transitions) { 'use strict'; // Listen to changes on the root scope. If it's an error in the state // changes (i.e. a 404) take the user back to the index. - $rootScope.$on('$stateChangeError', - function () { - $state.go('sb.index'); - }); + $transitions.onError({}, function(){ + return false; + }); }) .run(function ($http, DSCacheFactory) { 'use strict'; diff --git a/src/app/util/service/last_location.js b/src/app/util/service/last_location.js index 5f6d6c2e..b5e84f95 100644 --- a/src/app/util/service/last_location.js +++ b/src/app/util/service/last_location.js @@ -21,32 +21,6 @@ angular.module('sb.util').factory('LastLocation', function ($rootScope, localStorageService, $state) { 'use strict'; - /** - * onStateChange handler. Stores the next destination state, and its - * parameters, so we can keep revisit the history after bouncing out - * for authentication. - * - * @param event The state change event. - * @param toState The destination state. - * @param toParams The parameters for that destination state. - */ - function onStateChange(event, toState, toParams) { - if (toState.name.indexOf('sb.auth') === -1) { - var data = { - 'name': toState.name, - 'params': toParams - }; - localStorageService.set('lastLocation', - angular.toJson(data)); - } - } - - // Add the listener to the application, remove it when the scope is - // destroyed. - $rootScope.$on('$destroy', - $rootScope.$on('$stateChangeStart', onStateChange) - ); - // The published API. return { @@ -64,6 +38,24 @@ angular.module('sb.util').factory('LastLocation', last = angular.fromJson(last); $state.go(last.name, last.params); } + }, + + /** + * onStateChange handler. Stores the next destination state, and its + * parameters, so we can keep revisit the history after bouncing out + * for authentication. + * + * @param transition The transition to record the state from. + */ + onStateChange: function(transition) { + if (transition.$to().name.indexOf('sb.auth') === -1) { + var data = { + 'name': transition.$to().name, + 'params': transition.params() + }; + localStorageService.set('lastLocation', + angular.toJson(data)); + } } }; });