log as info not error
[angular-drzb] / app / js / controllers.js
index 6ff5079..7b47fb5 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,13 +11,18 @@ 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
 
        $scope.update = function(registration, state, info_message) {
 
-               registration.state = state;
+               if ( $scope.ValidStates.indexOf( state ) > $scope.ValidStates.indexOf( registration.state ) ) {
+                       registration.state = state;
+                       $log.info( 'registration.state updated to ',state);
+               } else {
+                       $log.info('registration.state NOT changed');
+               }
 
                if ( ! $scope.has_work && registration.work ) {
                        delete( registration.work );
@@ -27,7 +32,7 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
                registration.$save( function(registration) {
                        $log.info('id =', registration.id, 'state = ', registration.state);
                        if ( registration.id && registration.state ) {
-                               $log.error( $location.path(), registration.state, $routeParams );
+                               $log.info( 'have id && state', $location.path(), registration.state, $routeParams );
                                if ( $location.path().split(/\//)[1] != registration.state ) {
                                        $location.path( '/' + registration.state + '/' + registration.id );
                                } else {
@@ -74,6 +79,14 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
                        $scope.user.registration_type == 'symposium' ||
                        $scope.user.registration_type == 'round'
                ) {
+                       if ( angular.isUndefined( $scope.registration.work ) ) {
+                               $log.info('create empty work');
+                               $scope.registration.work = { persons: [ $scope.user ] };
+                               if ( angular.isUndefined( $scope.work ) )
+                                       $scope.work = $scope.registration.work;
+                       }
+
+
                        $scope.work.type = $scope.user.registration_type;
                        $scope.has_work = true;
                        $log.info( $scope.user.registration_type, " type updated");
@@ -160,6 +173,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 +187,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;
@@ -183,7 +197,8 @@ function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, Regist
                page: 1,
                limit: 10,
                results: 1,
-               last_page: 1
+               last_page: 1,
+               show_all: false
        };
        $scope.search = {};
        $scope.ready = false;
@@ -195,7 +210,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 );
@@ -267,7 +282,7 @@ function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, Regist
                var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
                $scope.list = [];
                angular.forEach( filtered, function(v,k) {
-                       if ( k >= from && k < from + $scope.pager.limit ) {
+                       if ( k >= from && k < from + $scope.pager.limit || $scope.pager.show_all ) {
                                v.nr = k + 1;
                                this.push(v);
                        }
@@ -288,5 +303,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' ];