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!
180 if ( angular.isUndefined( $scope.user ) || angular.isUndefined( $scope.registration ) ) return false;
182 angular.isUndefined( $scope.user.registration_type ) // new registration
183 || angular.isUndefined( $scope.registration.state ) // not saved yet
184 || $scope.registration.state == 'draft'
185 || $scope.registration.state == 'confirmation'
188 $scope.show_registration_type = function() {
194 RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'View', 'ValidStates' ];
196 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
199 $scope.list_results = 0;
208 $scope.ready = false;
210 { select: 'user.student', label: 'student', name: 'filter_student' },
211 { select: 'user.hpd_member', label: 'HPD', name: 'filter_hpd' },
212 { select: 'user.reception', label: 'reception', name: 'filter_reception' },
213 { select: 'user.dinner', label: 'dinner', name: 'filter_dinner' },
214 { select: 'payment.received', label: 'payment', name: 'filter_payment' },
215 { select: 'user.org_member', label: 'organisation', name: 'filter_org' }
218 registration_type: true,
224 $scope.ValidStates = ValidStates();
226 $scope.create_counts = function( array ) {
227 $log.info('create_counts', array.length );
229 var inc_count = function(type) {
230 if ( ! angular.isNumber( Counts[type] ) ) {
236 angular.forEach( array, function(value, key) {
237 if ( ! value.user ) {
238 $log.error("create_counts user corrupted for registration", key, value);
242 var type = value.user.registration_type;
244 inc_count( '' ); // total
245 angular.forEach( $scope.filters, function(filter) {
246 var s = filter.select.split(/\./);
248 if ( angular.isDefined( v ) ) {
251 if ( v === 'yes' || v === true ) {
252 inc_count( filter.name );
253 inc_count( type + '+' + filter.name );
254 inc_count( '+' + filter.name ); // total
255 value[filter.name] = true;
257 value[filter.name] = false;
262 value.registration_type = type;
264 // count registration state
265 inc_count( 'state+' + value.state );
267 // $log.info( key, value );
269 $log.info('Counts', Counts);
270 $scope.Counts = Counts;
274 $scope.all_registrations = Registration.query( function(result) {
276 $log.info('Reqistration.query callback', result);
280 $scope.filter_list = function(newVal, oldVal) {
281 if ( newVal == oldVal ) return;
282 $log.info('filter_list', newVal, oldVal, 'search', $scope.search);
284 $filter('filter')($scope.all_registrations, $scope.search);
286 $scope.create_counts( filtered );
288 $log.info('pager before apply', $scope.pager);
290 $scope.pager.results = filtered.length;
291 $scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
292 if ( $scope.pager.page < 1 ) $scope.pager.page = 1;
293 if ( $scope.pager.page > $scope.pager.last_page ) $scope.pager.page = $scope.pager.last_page;
294 $log.info('pager', $scope.pager);
296 var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
298 angular.forEach( filtered, function(v,k) {
299 if ( k >= from && k < from + $scope.pager.limit || $scope.pager.show_all ) {
304 $log.info('list length=', $scope.list.length, "offset=", from);
306 $scope.$watch('search', $scope.filter_list, true);
307 $scope.$watch('search.$', $scope.filter_list); // FIXME not included in search true because of $
308 $scope.$watch('pager', $scope.filter_list, true);
310 $scope.RegistrationTypes = RegistrationTypes;
311 $log.info( "RegistrationTypes", RegistrationTypes );
313 $scope.reset = function() {
314 $scope.search = { registration_type: '' };
315 $log.info('reset', $scope.search );
316 $scope.pager.page = 1;
323 toggle: function(v) {
324 $log.info('print_hide', v);
325 $scope.print.layout = ! $scope.print.layout;
327 $scope.print.center = 'print-center';
328 $scope.print.bold = 'print-bold';
330 $scope.print.center = '';
331 $scope.print.bold = '';
337 ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'ValidStates' ];
340 function AuthorsCtrl($scope, $log, View ) {
341 $scope.message = 'Loading data...';
342 $scope.ready = false;
343 View.getPromise('authors?format=key_distinct').then(function(data) {
344 if ( angular.isArray(data.rows) ) {
346 $scope.authors = $scope.data.rows;
348 $log.info('authors promise ', data);
350 $log.info('no rows in', data);
351 $scope.message = 'No rows found';
356 AuthorsCtrl.$inject = [ '$scope', '$log', 'View' ];