5 function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, View, ValidStates) {
7 $scope.$routeParams = $routeParams;
8 $scope.$location = $location;
9 $scope.organizations = [];
10 View.getArrayPromise('organizations?group=true;format=key_array').then(function(data) {
11 $scope.organizations = data;
12 $log.info('organizations promise ', $scope.organizations);
14 $scope.ValidStates = ValidStates();
16 $scope.info = { message: '', css_class: '' } ; // alert box
18 $scope.update = function(registration, state, info_message) {
20 if ( $scope.ValidStates.indexOf( state ) > $scope.ValidStates.indexOf( registration.state ) ) {
21 registration.state = state;
22 $log.info( 'registration.state updated to ',state);
24 $log.info('registration.state NOT changed');
27 if ( ! $scope.has_work && registration.work ) {
28 delete( registration.work );
29 $log.info("removed work");
32 registration.$save( function(registration) {
33 $log.info('id =', registration.id, 'state = ', registration.state);
34 if ( registration.id && registration.state ) {
35 $log.info( 'have id && state', $location.path(), registration.state, $routeParams );
36 if ( $location.path().split(/\//)[1] != registration.state ) {
37 $location.path( '/' + registration.state + '/' + registration.id );
39 $scope.info = { message: info_message, css_class: 'alert-success' };
42 $log.error("can't find id in ", registration);
47 $scope.reset = function() {
48 if ( $routeParams.registrationId ) {
49 $scope.registration = new Registration();
50 $scope.registration.$get({ registrationId: $routeParams.registrationId }, function(registration) {
51 $log.info("get Registration", registration);
52 $scope.user = registration.user;
53 $scope.work = registration.work;
56 $scope.registration = new Registration({ user: {}, work: { persons: [] } });
57 $scope.user = $scope.registration.user;
58 $scope.work = $scope.registration.work;
59 $scope.work.persons = [ $scope.user ]; // first author is person submitting work
60 $log.info("new Registration", $scope.registration);
63 $log.info( $routeParams.registrationId );
67 $scope.$watch('user.registration_type', function( oldValue, newValue ) {
68 $log.info("registration_type watch", oldValue, newValue );
70 if ( oldValue === newValue ) return; // triggers on resource, so ignore it
71 if ( ! $scope.user ) { // resource triggers watch before loading json
72 $log.error("no user in scope");
77 $scope.user.registration_type == 'lecture' ||
78 $scope.user.registration_type == 'poster' ||
79 $scope.user.registration_type == 'symposium' ||
80 $scope.user.registration_type == 'round'
82 if ( angular.isUndefined( $scope.registration.work ) ) {
83 $log.info('create empty work');
84 $scope.registration.work = { persons: [ $scope.user ] };
85 if ( angular.isUndefined( $scope.work ) )
86 $scope.work = $scope.registration.work;
90 $scope.work.type = $scope.user.registration_type;
91 $scope.has_work = true;
92 $log.info( $scope.user.registration_type, " type updated");
94 if ( $scope.user.registration_type == 'symposium' && ! $scope.work.symposium_works ) {
95 // create 4 empty symposium works
96 $scope.work.symposium_works = [
102 $log.info('created symposium_works');
106 $log.info( $scope.user.registration_type, "NO work" );
107 $scope.has_work = false;
111 $scope.change_student = function() {
112 if ( $scope.user.student ) {
113 $scope.user.hpd_member = false;
114 $scope.user.dinner = false;
118 $scope.addPerson = function(persons) {
119 $log.info('addPerson', persons);
120 persons.push({ firstname: '' });
123 $scope.removePerson = function(persons,person) {
124 for (var i = 0, ii = persons.length; i < ii; i++) {
125 if (person === persons[i]) {
126 persons.splice(i, 1);
127 $log.info('removePerson', i, person);
132 $scope.add_symposium_work = function(works) {
133 works.push({ persons: [{}] });
136 $scope.symposium_work_remove = function(work_index) {
137 if ( ! angular.isNumber(work_index) ) {
138 $log.error("work_index", work_index);
141 var works = $scope.work.symposium_works;
142 $log.info('symposium_work_remove', works, work_index);
143 var removed = works.splice( work_index, 1 );
144 if ( angular.isArray(removed) && removed[0] ) {
145 removed = removed[0];
146 removed.deleted = true;
147 if ( ! angular.isArray( $scope.work.symposium_works_deleted ) )
148 $scope.work.symposium_works_deleted = [];
149 $scope.work.symposium_works_deleted.push( removed );
150 $log.info("work deleted", works);
152 $log.warn("symposium_work_remove no work to remove", works, work);
156 $scope.abstract_class = function(work) {
157 if ( work === undefined ) return;
158 var abstract = work.abstract;
159 return angular.isString(abstract) && abstract.length <= 2000 ? 'ok' : 'ng-invalid';
161 $scope.abstract_length = function(work) {
162 if ( work === undefined ) return;
163 var abstract = work.abstract;
164 if ( ! abstract ) return 0;
165 return abstract.length <= 2000 ? abstract.length : 2000 - abstract.length;
168 $scope.change_state = function(new_state) {
169 if ( new_state == $scope.registration.state ) return;
170 $scope.info = { css_class: 'alert-warning', message: 'Changed state from "'+$scope.registration.state+'" to "'+new_state+'"' };
171 $scope.registration.state = new_state;
174 $scope.show_submission_type = function() {
175 // FIXME check if all submission are allowed by date and allow them!
176 if ( angular.isUndefined( $scope.user ) || angular.isUndefined( $scope.registration ) ) return false;
178 angular.isUndefined( $scope.user.registration_type ) // new registration
179 || angular.isUndefined( $scope.registration.state ) // not saved yet
180 || $scope.registration.state == 'draft'
181 || $scope.registration.state == 'confirmation'
184 $scope.show_registration_type = function() {
190 RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'View', 'ValidStates' ];
192 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
195 $scope.list_results = 0;
204 $scope.ready = false;
206 { select: 'user.student', label: 'student', name: 'filter_student' },
207 { select: 'user.hpd_member', label: 'HPD', name: 'filter_hpd' },
208 { select: 'user.reception', label: 'reception', name: 'filter_reception' },
209 { select: 'user.dinner', label: 'dinner', name: 'filter_dinner' },
210 { select: 'payment.received', label: 'payment', name: 'filter_payment' }
213 registration_type: true,
219 $scope.ValidStates = ValidStates();
221 $scope.create_counts = function( array ) {
222 $log.info('create_counts', array.length );
224 var inc_count = function(type) {
225 if ( ! angular.isNumber( Counts[type] ) ) {
231 angular.forEach( array, function(value, key) {
232 if ( ! value.user ) {
233 $log.error("create_counts user corrupted for registration", key, value);
237 var type = value.user.registration_type;
239 inc_count( '' ); // total
240 angular.forEach( $scope.filters, function(filter) {
241 var s = filter.select.split(/\./);
243 if ( angular.isDefined( v ) ) {
246 if ( v === 'yes' || v === true ) {
247 inc_count( filter.name );
248 inc_count( type + '+' + filter.name );
249 inc_count( '+' + filter.name ); // total
250 value[filter.name] = true;
252 value[filter.name] = false;
257 value.registration_type = type;
259 // count registration state
260 inc_count( 'state+' + value.state );
262 // $log.info( key, value );
264 $log.info('Counts', Counts);
265 $scope.Counts = Counts;
269 $scope.all_registrations = Registration.query( function(result) {
271 $log.info('Reqistration.query callback', result);
275 $scope.filter_list = function(newVal, oldVal) {
276 if ( newVal == oldVal ) return;
277 $log.info('filter_list', newVal, oldVal, 'search', $scope.search);
279 $filter('filter')($scope.all_registrations, $scope.search);
281 $scope.create_counts( filtered );
283 $log.info('pager before apply', $scope.pager);
285 $scope.pager.results = filtered.length;
286 $scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
287 if ( $scope.pager.page < 1 ) $scope.pager.page = 1;
288 if ( $scope.pager.page > $scope.pager.last_page ) $scope.pager.page = $scope.pager.last_page;
289 $log.info('pager', $scope.pager);
291 var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
293 angular.forEach( filtered, function(v,k) {
294 if ( k >= from && k < from + $scope.pager.limit || $scope.pager.show_all ) {
299 $log.info('list length=', $scope.list.length, "offset=", from);
301 $scope.$watch('search', $scope.filter_list, true);
302 $scope.$watch('search.$', $scope.filter_list); // FIXME not included in search true because of $
303 $scope.$watch('pager', $scope.filter_list, true);
305 $scope.RegistrationTypes = RegistrationTypes;
306 $log.info( "RegistrationTypes", RegistrationTypes );
308 $scope.reset = function() {
309 $scope.search = { registration_type: '' };
310 $log.info('reset', $scope.search );
311 $scope.pager.page = 1;
318 toggle: function(v) {
319 $log.info('print_hide', v);
320 $scope.print.layout = ! $scope.print.layout;
322 $scope.print.center = 'print-center';
323 $scope.print.bold = 'print-bold';
325 $scope.print.center = '';
326 $scope.print.bold = '';
332 ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'ValidStates' ];