change state of registration with div alert
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 24 Jan 2013 15:02:09 +0000 (16:02 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 24 Jan 2013 15:02:09 +0000 (16:02 +0100)
app/js/controllers.js
app/partials/verified.html.ep

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' ];
index fb0e033..77d04cd 100644 (file)
@@ -2,6 +2,10 @@
 
 <form ng-controller="RegistrationCtrl" name="RegistrationForm" class="form-horizontal">
 
+<div class="alert" ng-class="info.css_class" ng-show="info.message">
+{{info.message}}
+</div>
+
 <fieldset>
 <legend>
 <%= locale en => 'Registration', hr => 'Registracija' %>
@@ -10,7 +14,7 @@
 <input
        type="checkbox"
        ng-model="registration.verified"
-       ng-change="registration.state = 'verified'"
+       ng-change="change_state('verified')"
        class="my-label-input"
        label="<%= locale en => 'Verified', hr => 'Provjerena' %>"
 >
@@ -48,7 +52,9 @@
 
 </fieldset>
 
-<button class="btn btn-primary" ng-click="update(registration, registration.state)" ng-show="RegistrationForm.$dirty">Save changes</button>
+<button class="btn btn-primary" ng-click="update(registration, registration.state, '<%= locale en => 'Registration saved', hr => 'Registracija spremljena' %>')" ng-show="RegistrationForm.$dirty">
+<%= locale en => 'Save changes', hr => 'Spremi promjene' %>
+</button>
 
 %= $lang =~ m/-dev/ ? '{{registration.payment}} {{registration.state}}' : ''