5 function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, Organizations, ValidStates) {
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.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.error( $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', 'Organizations', 'ValidStates' ];
192 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
195 $scope.list_results = 0;
204 $scope.ready = false;
205 $scope.filters = [ 'student', 'hpd_member', 'reception', 'dinner' ];
207 registration_type: true,
213 $scope.ValidStates = ValidStates();
215 $scope.create_counts = function( array ) {
216 $log.info('create_counts', array.length );
218 var inc_count = function(type) {
219 if ( ! angular.isNumber( Counts[type] ) ) {
225 angular.forEach( array, function(value, key) {
226 if ( ! value.user ) {
227 $log.error("create_counts user corrupted for registration", key, value);
231 var type = value.user.registration_type;
233 inc_count( '' ); // total
234 angular.forEach( $scope.filters, function(subtype) {
235 var v = value.user[subtype];
236 if ( v === 'yes' || v === true ) {
237 inc_count( subtype );
238 inc_count( type + '+' + subtype );
239 inc_count( '+' + subtype ); // total
244 value.registration_type = type;
245 angular.forEach( $scope.filters, function(f) {
246 var v = value.user[f];
247 value[f] = v == true || v == 'yes' ? true : false;
250 // count registration state
251 inc_count( 'state+' + value.state );
253 // $log.info( key, value, Counts[type] );
255 $log.info('Counts', Counts);
256 $scope.Counts = Counts;
260 $scope.all_registrations = Registration.query( function(result) {
262 $log.info('Reqistration.query callback', result);
266 $scope.filter_list = function(newVal, oldVal) {
267 if ( newVal == oldVal ) return;
268 $log.info('filter_list', newVal, oldVal, 'search', $scope.search);
270 $filter('filter')($scope.all_registrations, $scope.search);
272 $scope.create_counts( filtered );
274 $log.info('pager before apply', $scope.pager);
276 $scope.pager.results = filtered.length;
277 $scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
278 if ( $scope.pager.page < 1 ) $scope.pager.page = 1;
279 if ( $scope.pager.page > $scope.pager.last_page ) $scope.pager.page = $scope.pager.last_page;
280 $log.info('pager', $scope.pager);
282 var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
284 angular.forEach( filtered, function(v,k) {
285 if ( k >= from && k < from + $scope.pager.limit || $scope.pager.show_all ) {
290 $log.info('list length=', $scope.list.length, "offset=", from);
292 $scope.$watch('search', $scope.filter_list, true);
293 $scope.$watch('search.$', $scope.filter_list); // FIXME not included in search true because of $
294 $scope.$watch('pager', $scope.filter_list, true);
296 $scope.RegistrationTypes = RegistrationTypes;
297 $log.info( "RegistrationTypes", RegistrationTypes );
299 $scope.reset = function() {
300 $scope.search = { registration_type: '' };
301 $log.info('reset', $scope.search );
302 $scope.pager.page = 1;
306 ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'ValidStates' ];