change state of registration with div alert
[angular-drzb] / app / js / controllers.js
index 8b9cf1d..c3f74b7 100644 (file)
@@ -13,7 +13,9 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
        });
        $scope.RegistrationState = RegistrationState;
 
-       $scope.update = function(registration, state) {
+       $scope.info = { message: '', css_class: '' } ; // alert box
+
+       $scope.update = function(registration, state, info_message) {
 
                registration.state = state;
 
@@ -23,10 +25,13 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
                }
 
                registration.$save( function(registration) {
-                       $log.info("saved", registration);
                        $log.info('id =', registration.id, 'state = ', registration.state);
                        if ( registration.id && registration.state ) {
-                               $location.path( '/' + registration.state + '/' + registration.id );
+                               if ( ! info_message ) {
+                                       $location.path( '/' + registration.state + '/' + registration.id );
+                               } else {
+                                       $scope.info = { message: info_message, css_class: 'alert-success' };
+                               }
                        } else {
                                $log.error("can't find id in ", registration);
                        }
@@ -146,6 +151,12 @@ function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $
                return abstract.length <= 2000 ? abstract.length : 2000 - abstract.length;
        }
 
+       $scope.change_state = function(new_state) {
+               if ( new_state == $scope.registration.state ) return;
+               $scope.info = { css_class: 'alert-warning', message: 'Changed state from "'+$scope.registration.state+'" to "'+new_state+'"' };
+               $scope.registration.state = new_state;
+       }
+
        $scope.reset();
 }
 RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations', 'RegistrationState' ];