6 function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route) {
8 $scope.$routeParams = $routeParams;
9 $scope.$location = $location;
11 $scope.update = function(registration) {
13 if ( ! $scope.has_work && registration.work ) {
14 delete( registration.work );
15 $log.info("removed work");
18 registration.$save( function(registration) {
19 $log.info("saved", registration);
20 $log.info('id =', registration.id);
21 if ( registration.id ) {
22 $location.path( '/registration-finished/' + registration.id );
24 $log.error("can't find id in ", registration);
29 $scope.reset = function() {
30 if ( $routeParams.registrationId ) {
31 $scope.registration = new Registration();
32 $scope.registration.$get({ registrationId: $routeParams.registrationId }, function(registration) {
33 $log.info("get Registration", registration);
34 $scope.user = registration.user;
35 $scope.work = registration.work;
38 $scope.registration = new Registration({ user: {}, work: { persons: [] } });
39 $scope.user = $scope.registration.user;
40 $scope.work = $scope.registration.work;
41 $scope.work.persons = [ $scope.user ]; // first author is person submitting work
42 $log.info("new Registration", $scope.registration);
45 $log.info( $routeParams.registrationId );
48 $scope.$watch('user.registration_type', function( oldValue, newValue ) {
49 $log.info("registration_type watch", oldValue, newValue );
51 if ( oldValue === newValue ) return; // triggers on resource, so ignore it
52 if ( ! $scope.user ) { // resource triggers watch before loading json
53 $log.error("no user in scope");
58 $scope.user.registration_type == 'lecture' ||
59 $scope.user.registration_type == 'poster' ||
60 $scope.user.registration_type == 'symposium' ||
61 $scope.user.registration_type == 'round'
63 $scope.work.type = $scope.user.registration_type;
64 $scope.has_work = true;
65 $log.info( $scope.user.registration_type, " type updated");
67 if ( $scope.user.registration_type == 'symposium' && ! $scope.work.symposium_works ) {
68 // create 4 empty symposium works
69 $scope.work.symposium_works = [
75 $log.info('created symposium_works');
79 $log.info( $scope.user.registration_type, "NO work" );
80 $scope.has_work = false;
84 $scope.change_student = function() {
85 if ( $scope.user.student ) {
86 $scope.user.hpd_member = false;
87 $scope.user.reception = false;
88 $scope.user.dinner = false;
92 $scope.addPerson = function(persons) {
93 $log.info('addPerson', persons);
94 persons.push({ firstname: '' });
97 $scope.removePerson = function(persons,person) {
98 for (var i = 0, ii = persons.length; i < ii; i++) {
99 if (person === persons[i]) {
100 persons.splice(i, 1);
101 $log.info('removePerson', i, person);
106 $scope.add_symposium_work = function(works) {
107 works.push({ persons: [{}] });
112 //RegistrationCtrl.$inject = [ '$scope', '$log' ];
114 function ListCtrl($scope, $log, Registration, RegistrationTypes) {
116 $scope.list = Registration.query( function() {
117 var RegistrationTypeCount = { '': 0 };
118 angular.forEach( $scope.list, function(value, key) {
119 var type = value.user.registration_type;
120 if ( ! angular.isNumber( RegistrationTypeCount[type] ) ) {
121 RegistrationTypeCount[type] = 1;
123 RegistrationTypeCount[type]++;
125 RegistrationTypeCount['']++;
127 value.registration_type = type; // for search
129 // $log.info( key, value.user.registration_type, RegistrationTypeCount[type] );
131 $log.info('RegistrationTypeCount', RegistrationTypeCount);
132 $scope.RegistrationTypeCount = RegistrationTypeCount;
136 $scope.RegistrationTypes = RegistrationTypes;
137 $log.info( "RegistrationTypes", RegistrationTypes );
138 $scope.search = { '$': '' };
144 MyCtrl2.$inject = [];