6 function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, View) {
8 $scope.$routeParams = $routeParams;
9 $scope.$location = $location;
10 $scope.organizations = [];
12 $scope.update = function(registration) {
14 if ( ! $scope.has_work && registration.work ) {
15 delete( registration.work );
16 $log.info("removed work");
19 registration.$save( function(registration) {
20 $log.info("saved", registration);
21 $log.info('id =', registration.id);
22 if ( registration.id ) {
23 $location.path( '/confirmation/' + registration.id );
25 $log.error("can't find id in ", registration);
30 $scope.reset = function() {
31 if ( $routeParams.registrationId ) {
32 $scope.registration = new Registration();
33 $scope.registration.$get({ registrationId: $routeParams.registrationId }, function(registration) {
34 $log.info("get Registration", registration);
35 $scope.user = registration.user;
36 $scope.work = registration.work;
39 $scope.registration = new Registration({ user: {}, work: { persons: [] } });
40 $scope.user = $scope.registration.user;
41 $scope.work = $scope.registration.work;
42 $scope.work.persons = [ $scope.user ]; // first author is person submitting work
43 $log.info("new Registration", $scope.registration);
46 $log.info( $routeParams.registrationId );
48 $scope.view = new View();
50 $scope.view.$get({ view: 'organizations' }, function(result) {
51 $log.info('View organizations', result);
52 angular.forEach( result.rows, function(value, key) {
53 this.push( value.key ); // name of organization
54 }, $scope.organizations );
55 $log.info('organizations', $scope.organizations);
58 $scope.view.$key_array({ view: 'organizations' }, function(result) {
59 $log.info('key_array', result);
60 // $scope.organizations = result.rows; // FIXME doesn't refresh bs-typeahead
61 angular.forEach( result.rows, function(o) {
63 }, $scope.organizations );
64 $log.info('organizations', $scope.organizations);
69 $scope.$watch('user.registration_type', function( oldValue, newValue ) {
70 $log.info("registration_type watch", oldValue, newValue );
72 if ( oldValue === newValue ) return; // triggers on resource, so ignore it
73 if ( ! $scope.user ) { // resource triggers watch before loading json
74 $log.error("no user in scope");
79 $scope.user.registration_type == 'lecture' ||
80 $scope.user.registration_type == 'poster' ||
81 $scope.user.registration_type == 'symposium' ||
82 $scope.user.registration_type == 'round'
84 $scope.work.type = $scope.user.registration_type;
85 $scope.has_work = true;
86 $log.info( $scope.user.registration_type, " type updated");
88 if ( $scope.user.registration_type == 'symposium' && ! $scope.work.symposium_works ) {
89 // create 4 empty symposium works
90 $scope.work.symposium_works = [
96 $log.info('created symposium_works');
100 $log.info( $scope.user.registration_type, "NO work" );
101 $scope.has_work = false;
105 $scope.change_student = function() {
106 if ( $scope.user.student ) {
107 $scope.user.hpd_member = false;
108 $scope.user.reception = false;
109 $scope.user.dinner = false;
113 $scope.addPerson = function(persons) {
114 $log.info('addPerson', persons);
115 persons.push({ firstname: '' });
118 $scope.removePerson = function(persons,person) {
119 for (var i = 0, ii = persons.length; i < ii; i++) {
120 if (person === persons[i]) {
121 persons.splice(i, 1);
122 $log.info('removePerson', i, person);
127 $scope.add_symposium_work = function(works) {
128 works.push({ persons: [{}] });
133 //RegistrationCtrl.$inject = [ '$scope', '$log' ];
135 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter) {
139 $scope.ready = false;
141 $scope.all_registrations = Registration.query( function() {
142 var RegistrationTypeCount = { '': 0 };
143 angular.forEach( $scope.all_registrations, function(value, key) {
144 var type = value.user.registration_type;
145 if ( ! angular.isNumber( RegistrationTypeCount[type] ) ) {
146 RegistrationTypeCount[type] = 1;
148 RegistrationTypeCount[type]++;
150 RegistrationTypeCount['']++;
152 value.registration_type = type; // for search
154 // $log.info( key, value.user.registration_type, RegistrationTypeCount[type] );
156 $log.info('RegistrationTypeCount', RegistrationTypeCount);
157 $scope.RegistrationTypeCount = RegistrationTypeCount;
159 // $scope.list = $scope.all_registrations; // FIXME show all registrations on page load
163 $scope.filter_list = function(newVal, oldVal) {
164 $scope.list = $filter('filter')($scope.all_registrations, $scope.search);
165 $log.info('filter_list', newVal, oldVal, 'search', $scope.search, 'results', $scope.list);
167 $scope.$watch('search.registration_type', $scope.filter_list);
168 $scope.$watch('search.$', $scope.filter_list); // $ is skipped by search watch!!
170 $scope.RegistrationTypes = RegistrationTypes;
171 $log.info( "RegistrationTypes", RegistrationTypes );
177 MyCtrl2.$inject = [];