trasnalted rest of form to Croatian
[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                                 // create 4 empty symposium works
69                                 $scope.work.symposium_works = [
70                                         { persons: [{}] },
71                                         { persons: [{}] },
72                                         { persons: [{}] },
73                                         { persons: [{}] }
74                                 ];
75                                 $log.info('created symposium_works');
76                                 $scope.is_symposium = true;
77                         } else {
78                                 $scope.is_symposium = false;
79                         }
80
81                 } else {
82                         $log.info( $scope.user.registration_type, "NO work" );
83                         $scope.has_work = false;
84                 }
85         });
86
87         $scope.change_student = function() {
88                 if ( $scope.user.student ) {
89                         $scope.user.hpd_member = false;
90                         $scope.user.reception = false;
91                         $scope.user.dinner = false;
92                 }
93         }
94
95         $scope.addPerson = function(persons) {
96                 $log.info('addPerson', persons);
97                 persons.push({ firstname: '' });
98         };
99  
100         $scope.removePerson = function(persons,person) {
101                 for (var i = 0, ii = persons.length; i < ii; i++) {
102                         if (person === persons[i]) {
103                                 persons.splice(i, 1);
104                                 $log.info('removePerson', i, person);
105                         }
106                 }
107         };
108
109         $scope.add_symposium_work = function(works) {
110                 works.push({ persons: [{}] });
111         }
112
113         $scope.reset();
114 }
115 //RegistrationCtrl.$inject = [ '$scope', '$log' ];
116
117
118 function MyCtrl2() {
119 }
120 MyCtrl2.$inject = [];