resource triggers watch before loading
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 14 Dec 2012 10:25:23 +0000 (11:25 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 14 Dec 2012 10:25:23 +0000 (11:25 +0100)
app/js/controllers.js

index 4187b9a..984d546 100644 (file)
@@ -36,9 +36,9 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
                        });
                } else {
                        $scope.registration = new Registration({ user: {} });
-                       $log.info("new Registration", $scope.user);
                        $scope.user = $scope.registration.user;
                        $scope.work = $scope.registration.work;
+                       $log.info("new Registration", $scope.registration);
                }
 
                $log.info( $routeParams.registrationId );
@@ -47,6 +47,12 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
        $scope.$watch('user.registration_type', function( oldValue, newValue ) {
                $log.info("registration_type watch", oldValue, newValue );
 
+               if ( oldValue === newValue ) return; // triggers on resource, so ignore it
+               if ( ! $scope.user ) { // resource triggers watch before loading json
+                       $log.error("no user in scope");
+                       return;
+               }
+
                if (
                        $scope.user.registration_type == 'lecture' ||
                        $scope.user.registration_type == 'poster' ||