added symposium works
[angular-drzb] / app / js / controllers.js
1 'use strict';
2
3 /* Controllers */
4
5
6 function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route) {
7
8         $scope.$routeParams = $routeParams;
9         $scope.$location = $location;
10
11         $scope.update = function(registration) {
12
13                 if ( ! $scope.has_work && registration.work ) {
14                         delete( registration.work );
15                         $log.info("removed work");
16                 }
17
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 );
23                         } else {
24                                 $log.error("can't find id in ", registration);
25                         }
26                 });
27         }
28
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;
36                         });
37                 } else {
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);
43                 }
44
45                 $log.info( $routeParams.registrationId );
46         }
47
48         $scope.$watch('user.registration_type', function( oldValue, newValue ) {
49                 $log.info("registration_type watch", oldValue, newValue );
50
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");
54                         return;
55                 }
56
57                 if (
58                         $scope.user.registration_type == 'lecture' ||
59                         $scope.user.registration_type == 'poster' ||
60                         $scope.user.registration_type == 'symposium' ||
61                         $scope.user.registration_type == 'round'
62                 ) {
63                         $scope.work.type = $scope.user.registration_type;
64                         $scope.has_work = true;
65                         $log.info( $scope.user.registration_type, " type updated");
66
67                         if ( $scope.user.registration_type == 'symposium' && ! $scope.work.symposium_works ) {
68                                 $scope.work.symposium_works = [{ persons: [{}] }]; // create first empty symposium work
69                                 $log.info('created symposium_works');
70                         }
71
72                 } else {
73                         $log.info( $scope.user.registration_type, "NO work" );
74                         $scope.has_work = false;
75                 }
76         });
77
78         $scope.change_student = function() {
79                 if ( $scope.user.student ) {
80                         $scope.user.hpd_member = false;
81                         $scope.user.reception = false;
82                         $scope.user.dinner = false;
83                 }
84         }
85
86         $scope.addPerson = function(persons) {
87                 $log.info('addPerson', persons);
88                 persons.push({ firstname: '' });
89         };
90  
91         $scope.removePerson = function(persons,person) {
92                 for (var i = 0, ii = persons.length; i < ii; i++) {
93                         if (person === persons[i]) {
94                                 persons.splice(i, 1);
95                                 $log.info('removePerson', i, person);
96                         }
97                 }
98         };
99
100         $scope.reset();
101 }
102 //RegistrationCtrl.$inject = [ '$scope', '$log' ];
103
104
105 function MyCtrl2() {
106 }
107 MyCtrl2.$inject = [];