5 function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, View, ValidStates) {
7 $scope.$routeParams = $routeParams;
8 $scope.$location = $location;
9 $scope.organizations = [];
10 View.getPromise('organizations?group=true;format=key_array').then(function(data) {
11 if ( angular.isArray(data.rows) ) {
12 $scope.organizations = data.rows;
13 $log.info('organizations promise ', $scope.organizations);
15 $log.info('no rows in', data);
18 $scope.ValidStates = ValidStates();
20 $scope.info = { message: '', css_class: '' } ; // alert box
22 $scope.update = function(registration, state, info_message) {
24 if ( $scope.ValidStates.indexOf( state ) > $scope.ValidStates.indexOf( registration.state ) ) {
25 registration.state = state;
26 $log.info( 'registration.state updated to ',state);
28 $log.info('registration.state NOT changed');
31 if ( ! $scope.has_work && registration.work ) {
32 delete( registration.work );
33 $log.info("removed work");
36 registration.$save( function(registration) {
37 $log.info('id =', registration.id, 'state = ', registration.state);
38 if ( registration.id && registration.state ) {
39 $log.info( 'have id && state', $location.path(), registration.state, $routeParams );
40 if ( $location.path().split(/\//)[1] != registration.state ) {
41 $location.path( '/' + registration.state + '/' + registration.id );
43 $scope.info = { message: info_message, css_class: 'alert-success' };
46 $log.error("can't find id in ", registration);
51 $scope.reset = function() {
52 if ( $routeParams.registrationId ) {
53 $scope.registration = new Registration();
54 $scope.registration.$get({ registrationId: $routeParams.registrationId }, function(registration) {
55 $log.info("get Registration", registration);
56 $scope.user = registration.user;
57 $scope.work = registration.work;
60 $scope.registration = new Registration({ user: {}, work: { persons: [] } });
61 $scope.user = $scope.registration.user;
62 $scope.work = $scope.registration.work;
63 $scope.work.persons = [ $scope.user ]; // first author is person submitting work
64 $log.info("new Registration", $scope.registration);
67 $log.info( $routeParams.registrationId );
71 $scope.$watch('user.registration_type', function( oldValue, newValue ) {
72 $log.info("registration_type watch", oldValue, newValue );
74 if ( oldValue === newValue ) return; // triggers on resource, so ignore it
75 if ( ! $scope.user ) { // resource triggers watch before loading json
76 $log.error("no user in scope");
81 $scope.user.registration_type == 'lecture' ||
82 $scope.user.registration_type == 'poster' ||
83 $scope.user.registration_type == 'symposium' ||
84 $scope.user.registration_type == 'round'
86 if ( angular.isUndefined( $scope.registration.work ) ) {
87 $log.info('create empty work');
88 $scope.registration.work = { persons: [ $scope.user ] };
89 if ( angular.isUndefined( $scope.work ) )
90 $scope.work = $scope.registration.work;
94 $scope.work.type = $scope.user.registration_type;
95 $scope.has_work = true;
96 $log.info( $scope.user.registration_type, " type updated");
98 if ( $scope.user.registration_type == 'symposium' && ! $scope.work.symposium_works ) {
99 // create 4 empty symposium works
100 $scope.work.symposium_works = [
106 $log.info('created symposium_works');
110 $log.info( $scope.user.registration_type, "NO work" );
111 $scope.has_work = false;
115 $scope.change_student = function() {
116 if ( $scope.user.student ) {
117 $scope.user.hpd_member = false;
118 $scope.user.dinner = false;
122 $scope.addPerson = function(persons) {
123 $log.info('addPerson', persons);
124 persons.push({ firstname: '' });
127 $scope.removePerson = function(persons,person) {
128 for (var i = 0, ii = persons.length; i < ii; i++) {
129 if (person === persons[i]) {
130 persons.splice(i, 1);
131 $log.info('removePerson', i, person);
136 $scope.add_symposium_work = function(works) {
137 works.push({ persons: [{}] });
140 $scope.symposium_work_remove = function(work_index) {
141 if ( ! angular.isNumber(work_index) ) {
142 $log.error("work_index", work_index);
145 var works = $scope.work.symposium_works;
146 $log.info('symposium_work_remove', works, work_index);
147 var removed = works.splice( work_index, 1 );
148 if ( angular.isArray(removed) && removed[0] ) {
149 removed = removed[0];
150 removed.deleted = true;
151 if ( ! angular.isArray( $scope.work.symposium_works_deleted ) )
152 $scope.work.symposium_works_deleted = [];
153 $scope.work.symposium_works_deleted.push( removed );
154 $log.info("work deleted", works);
156 $log.warn("symposium_work_remove no work to remove", works, work);
160 $scope.abstract_class = function(work) {
161 if ( work === undefined ) return;
162 var abstract = work.abstract;
163 return angular.isString(abstract) && abstract.length <= 2000 ? 'ok' : 'ng-invalid';
165 $scope.abstract_length = function(work) {
166 if ( work === undefined ) return;
167 var abstract = work.abstract;
168 if ( ! abstract ) return 0;
169 return abstract.length <= 2000 ? abstract.length : 2000 - abstract.length;
172 $scope.change_state = function(new_state) {
173 if ( new_state == $scope.registration.state ) return;
174 $scope.info = { css_class: 'alert-warning', message: 'Changed state from "'+$scope.registration.state+'" to "'+new_state+'"' };
175 $scope.registration.state = new_state;
178 $scope.show_submission_type = function() {
179 // FIXME check if all submission are allowed by date and allow them!
182 if ( angular.isUndefined( $scope.user ) || angular.isUndefined( $scope.registration ) ) return false;
184 angular.isUndefined( $scope.user.registration_type ) // new registration
185 || angular.isUndefined( $scope.registration.state ) // not saved yet
186 || $scope.registration.state == 'draft'
187 || $scope.registration.state == 'confirmation'
190 $scope.show_registration_type = function() {
196 RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'View', 'ValidStates' ];
198 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
201 $scope.list_results = 0;
210 $scope.ready = false;
212 { select: 'user.student', label: 'student', name: 'filter_student' },
213 { select: 'user.hpd_member', label: 'HPD', name: 'filter_hpd' },
214 { select: 'user.reception', label: 'reception', name: 'filter_reception' },
215 { select: 'user.dinner', label: 'dinner', name: 'filter_dinner' },
216 { select: 'payment.received', label: 'payment', name: 'filter_payment' },
217 { select: 'user.org_member', label: 'organisation', name: 'filter_org' }
220 registration_type: true,
226 $scope.ValidStates = ValidStates();
228 $scope.create_counts = function( array ) {
229 $log.info('create_counts', array.length );
231 var inc_count = function(type) {
232 if ( ! angular.isNumber( Counts[type] ) ) {
238 angular.forEach( array, function(value, key) {
239 if ( ! value.user ) {
240 $log.error("create_counts user corrupted for registration", key, value);
244 var type = value.user.registration_type;
246 inc_count( '' ); // total
247 angular.forEach( $scope.filters, function(filter) {
248 var s = filter.select.split(/\./);
250 if ( angular.isDefined( v ) ) {
253 if ( v === 'yes' || v === true ) {
254 inc_count( filter.name );
255 inc_count( type + '+' + filter.name );
256 inc_count( '+' + filter.name ); // total
257 value[filter.name] = true;
259 value[filter.name] = false;
264 value.registration_type = type;
266 // count registration state
267 inc_count( 'state+' + value.state );
269 // $log.info( key, value );
271 $log.info('Counts', Counts);
272 $scope.Counts = Counts;
276 $scope.all_registrations = Registration.query( function(result) {
278 $log.info('Reqistration.query callback', result);
282 $scope.filter_list = function(newVal, oldVal) {
283 if ( newVal == oldVal ) return;
284 $log.info('filter_list', newVal, oldVal, 'search', $scope.search);
286 $filter('filter')($scope.all_registrations, $scope.search);
288 $scope.create_counts( filtered );
290 $log.info('pager before apply', $scope.pager);
292 $scope.pager.results = filtered.length;
293 $scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
294 if ( $scope.pager.page < 1 ) $scope.pager.page = 1;
295 if ( $scope.pager.page > $scope.pager.last_page ) $scope.pager.page = $scope.pager.last_page;
296 $log.info('pager', $scope.pager);
298 var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
300 angular.forEach( filtered, function(v,k) {
301 if ( k >= from && k < from + $scope.pager.limit || $scope.pager.show_all ) {
306 $log.info('list length=', $scope.list.length, "offset=", from);
308 $scope.$watch('search', $scope.filter_list, true);
309 $scope.$watch('search.$', $scope.filter_list); // FIXME not included in search true because of $
310 $scope.$watch('pager', $scope.filter_list, true);
312 $scope.RegistrationTypes = RegistrationTypes;
313 $log.info( "RegistrationTypes", RegistrationTypes );
315 $scope.reset = function() {
316 $scope.search = { registration_type: '' };
317 $log.info('reset', $scope.search );
318 $scope.pager.page = 1;
325 toggle: function(v) {
326 $log.info('print_hide', v);
327 $scope.print.layout = ! $scope.print.layout;
329 $scope.print.center = 'print-center';
330 $scope.print.bold = 'print-bold';
332 $scope.print.center = '';
333 $scope.print.bold = '';
339 ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'ValidStates' ];
342 function AuthorsCtrl($scope, $log, View ) {
343 $scope.message = 'Loading data...';
344 $scope.ready = false;
345 View.getPromise('authors?format=key_distinct').then(function(data) {
346 if ( angular.isArray(data.rows) ) {
348 $scope.authors = $scope.data.rows;
350 $log.info('authors promise ', data);
352 $log.info('no rows in', data);
353 $scope.message = 'No rows found';
358 AuthorsCtrl.$inject = [ '$scope', '$log', 'View' ];