5 function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations, RegistrationStatus) {
7 $scope.$routeParams = $routeParams;
8 $scope.$location = $location;
9 $scope.organizations = [];
10 Organizations.getArrayPromise().then(function(data) {
11 $scope.organizations = data;
12 $log.info('organizations promise ', $scope.organizations);
14 $scope.RegistrationStatus = RegistrationStatus;
16 $scope.update = function(registration, state) {
18 registration.state = state;
20 if ( ! $scope.has_work && registration.work ) {
21 delete( registration.work );
22 $log.info("removed work");
25 registration.$save( function(registration) {
26 $log.info("saved", registration);
27 $log.info('id =', registration.id, 'state = ', registration.state);
28 if ( registration.id && registration.state ) {
29 $location.path( '/' + registration.state + '/' + registration.id );
31 $log.error("can't find id in ", registration);
36 $scope.reset = function() {
37 if ( $routeParams.registrationId ) {
38 $scope.registration = new Registration();
39 $scope.registration.$get({ registrationId: $routeParams.registrationId }, function(registration) {
40 $log.info("get Registration", registration);
41 $scope.user = registration.user;
42 $scope.work = registration.work;
45 $scope.registration = new Registration({ user: {}, work: { persons: [] } });
46 $scope.user = $scope.registration.user;
47 $scope.work = $scope.registration.work;
48 $scope.work.persons = [ $scope.user ]; // first author is person submitting work
49 $log.info("new Registration", $scope.registration);
52 $log.info( $routeParams.registrationId );
56 $scope.$watch('user.registration_type', function( oldValue, newValue ) {
57 $log.info("registration_type watch", oldValue, newValue );
59 if ( oldValue === newValue ) return; // triggers on resource, so ignore it
60 if ( ! $scope.user ) { // resource triggers watch before loading json
61 $log.error("no user in scope");
66 $scope.user.registration_type == 'lecture' ||
67 $scope.user.registration_type == 'poster' ||
68 $scope.user.registration_type == 'symposium' ||
69 $scope.user.registration_type == 'round'
71 $scope.work.type = $scope.user.registration_type;
72 $scope.has_work = true;
73 $log.info( $scope.user.registration_type, " type updated");
75 if ( $scope.user.registration_type == 'symposium' && ! $scope.work.symposium_works ) {
76 // create 4 empty symposium works
77 $scope.work.symposium_works = [
83 $log.info('created symposium_works');
87 $log.info( $scope.user.registration_type, "NO work" );
88 $scope.has_work = false;
92 $scope.change_student = function() {
93 if ( $scope.user.student ) {
94 $scope.user.hpd_member = false;
95 $scope.user.dinner = false;
99 $scope.addPerson = function(persons) {
100 $log.info('addPerson', persons);
101 persons.push({ firstname: '' });
104 $scope.removePerson = function(persons,person) {
105 for (var i = 0, ii = persons.length; i < ii; i++) {
106 if (person === persons[i]) {
107 persons.splice(i, 1);
108 $log.info('removePerson', i, person);
113 $scope.add_symposium_work = function(works) {
114 works.push({ persons: [{}] });
117 $scope.symposium_work_remove = function(work_index) {
118 if ( ! angular.isNumber(work_index) ) {
119 $log.error("work_index", work_index);
122 var works = $scope.work.symposium_works;
123 $log.info('symposium_work_remove', works, work_index);
124 var removed = works.splice( work_index, 1 );
125 if ( angular.isArray(removed) && removed[0] ) {
126 removed = removed[0];
127 removed.deleted = true;
128 if ( ! angular.isArray( $scope.work.symposium_works_deleted ) )
129 $scope.work.symposium_works_deleted = [];
130 $scope.work.symposium_works_deleted.push( removed );
131 $log.info("work deleted", works);
133 $log.warn("symposium_work_remove no work to remove", works, work);
137 $scope.abstract_class = function(work) {
138 if ( work === undefined ) return;
139 var abstract = work.abstract;
140 return angular.isString(abstract) && abstract.length <= 2000 ? 'ok' : 'ng-invalid';
142 $scope.abstract_length = function(work) {
143 if ( work === undefined ) return;
144 var abstract = work.abstract;
145 if ( ! abstract ) return 0;
146 return abstract.length <= 2000 ? abstract.length : 2000 - abstract.length;
151 RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations' ];
153 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter) {
156 $scope.list_results = 0;
164 $scope.ready = false;
165 $scope.filters = [ 'student', 'hpd_member', 'reception', 'dinner' ];
167 $scope.all_registrations = Registration.query( function() {
169 var inc_count = function(type) {
170 if ( ! angular.isNumber( Counts[type] ) ) {
176 angular.forEach( $scope.all_registrations, function(value, key) {
177 if ( ! value.user ) {
178 $log.error("all_registrations user corrupted for registration", key, value);
182 var type = value.user.registration_type;
184 inc_count( '' ); // total
185 angular.forEach( $scope.filters, function(subtype) {
186 var v = value.user[subtype];
187 if ( v === 'yes' || v === true ) {
188 inc_count( subtype );
189 inc_count( type + '+' + subtype );
190 inc_count( '+' + subtype ); // total
195 value.registration_type = type;
196 angular.forEach( $scope.filters, function(f) {
197 var v = value.user[f];
198 value[f] = v == true || v == 'yes' ? true : false;
201 // $log.info( key, value, Counts[type] );
203 $log.info('Counts', Counts);
204 $scope.Counts = Counts;
206 // $scope.list = $scope.all_registrations; // FIXME show all registrations on page loadyy
211 $scope.filter_list = function(newVal, oldVal) {
212 if ( newVal == oldVal ) return;
213 $log.info('filter_list', newVal, oldVal, 'search', $scope.search);
215 $filter('filter')($scope.all_registrations, $scope.search);
217 // $scope.pager.page = 1;
218 $scope.pager.results = filtered.length;
219 $scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
220 if ( $scope.pager.page > $scope.pager.last_page ) {
221 $scope.pager.page = 1;
223 $log.info('pager', $scope.pager);
225 var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
227 angular.forEach( filtered, function(v,k) {
228 if ( k >= from && k < from + $scope.pager.limit ) {
233 $log.info('list length=', $scope.list.length, "offset=", from);
235 angular.forEach( $scope.filters, function(f) {
236 $scope.$watch('search.'+f, $scope.filter_list);
237 $log.info('watch search.'+f);
239 $scope.$watch('search.registration_type', $scope.filter_list);
240 $scope.$watch('search.$', $scope.filter_list);
241 $scope.$watch('pager.page', $scope.filter_list);
242 $scope.$watch('pager.limit', $scope.filter_list);
244 $scope.RegistrationTypes = RegistrationTypes;
245 $log.info( "RegistrationTypes", RegistrationTypes );
249 ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter' ];