don't die on undefined registration or user
[angular-drzb] / app / js / controllers.js
index 3561aff..4ddca47 100644 (file)
@@ -2,7 +2,7 @@
 
 /* Controllers */
 
-function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations, RegistrationState) {
+function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations, ValidStates) {
 
        $scope.$routeParams = $routeParams;
        $scope.$location = $location;
@@ -11,7 +11,7 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
                $scope.organizations = data;
                $log.info('organizations promise ', $scope.organizations);
        });
-       $scope.RegistrationState = RegistrationState();
+       $scope.ValidStates = ValidStates();
 
        $scope.info = { message: '', css_class: '' } ; // alert box
 
@@ -160,6 +160,7 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
 
        $scope.show_submission_type = function() {
                // FIXME check if all submission are allowed by date and allow them!
+               if ( angular.isUndefined( $scope.user ) || angular.isUndefined( $scope.registration ) ) return false;
                return (
                        angular.isUndefined( $scope.user.registration_type ) // new registration
                        || angular.isUndefined( $scope.registration.state ) // not saved yet
@@ -173,9 +174,9 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
 
        $scope.reset();
 }
-RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations', 'RegistrationState' ];
+RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations', 'ValidStates' ];
 
-function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, RegistrationState ) {
+function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
 
        $scope.list = [];
        $scope.list_results = 0;
@@ -196,7 +197,7 @@ function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, Regist
                states: true,
                pager_numeric: false
        };
-       $scope.RegistrationState = RegistrationState();
+       $scope.ValidStates = ValidStates();
 
        $scope.create_counts = function( array ) {
                $log.info('create_counts', array.length );
@@ -289,5 +290,5 @@ function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, Regist
        }
 }
 
-ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'RegistrationState' ];
+ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'ValidStates' ];