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 registration.state = state;
22 if ( ! $scope.has_work && registration.work ) {
23 delete( registration.work );
24 $log.info("removed work");
27 registration.$save( function(registration) {
28 $log.info('id =', registration.id, 'state = ', registration.state);
29 if ( registration.id && registration.state ) {
30 $log.error( $location.path(), registration.state, $routeParams );
31 if ( $location.path().split(/\//)[1] != registration.state ) {
32 $location.path( '/' + registration.state + '/' + registration.id );
34 $scope.info = { message: info_message, css_class: 'alert-success' };
37 $log.error("can't find id in ", registration);
42 $scope.reset = function() {
43 if ( $routeParams.registrationId ) {
44 $scope.registration = new Registration();
45 $scope.registration.$get({ registrationId: $routeParams.registrationId }, function(registration) {
46 $log.info("get Registration", registration);
47 $scope.user = registration.user;
48 $scope.work = registration.work;
51 $scope.registration = new Registration({ user: {}, work: { persons: [] } });
52 $scope.user = $scope.registration.user;
53 $scope.work = $scope.registration.work;
54 $scope.work.persons = [ $scope.user ]; // first author is person submitting work
55 $log.info("new Registration", $scope.registration);
58 $log.info( $routeParams.registrationId );
62 $scope.$watch('user.registration_type', function( oldValue, newValue ) {
63 $log.info("registration_type watch", oldValue, newValue );
65 if ( oldValue === newValue ) return; // triggers on resource, so ignore it
66 if ( ! $scope.user ) { // resource triggers watch before loading json
67 $log.error("no user in scope");
72 $scope.user.registration_type == 'lecture' ||
73 $scope.user.registration_type == 'poster' ||
74 $scope.user.registration_type == 'symposium' ||
75 $scope.user.registration_type == 'round'
77 $scope.work.type = $scope.user.registration_type;
78 $scope.has_work = true;
79 $log.info( $scope.user.registration_type, " type updated");
81 if ( $scope.user.registration_type == 'symposium' && ! $scope.work.symposium_works ) {
82 // create 4 empty symposium works
83 $scope.work.symposium_works = [
89 $log.info('created symposium_works');
93 $log.info( $scope.user.registration_type, "NO work" );
94 $scope.has_work = false;
98 $scope.change_student = function() {
99 if ( $scope.user.student ) {
100 $scope.user.hpd_member = false;
101 $scope.user.dinner = false;
105 $scope.addPerson = function(persons) {
106 $log.info('addPerson', persons);
107 persons.push({ firstname: '' });
110 $scope.removePerson = function(persons,person) {
111 for (var i = 0, ii = persons.length; i < ii; i++) {
112 if (person === persons[i]) {
113 persons.splice(i, 1);
114 $log.info('removePerson', i, person);
119 $scope.add_symposium_work = function(works) {
120 works.push({ persons: [{}] });
123 $scope.symposium_work_remove = function(work_index) {
124 if ( ! angular.isNumber(work_index) ) {
125 $log.error("work_index", work_index);
128 var works = $scope.work.symposium_works;
129 $log.info('symposium_work_remove', works, work_index);
130 var removed = works.splice( work_index, 1 );
131 if ( angular.isArray(removed) && removed[0] ) {
132 removed = removed[0];
133 removed.deleted = true;
134 if ( ! angular.isArray( $scope.work.symposium_works_deleted ) )
135 $scope.work.symposium_works_deleted = [];
136 $scope.work.symposium_works_deleted.push( removed );
137 $log.info("work deleted", works);
139 $log.warn("symposium_work_remove no work to remove", works, work);
143 $scope.abstract_class = function(work) {
144 if ( work === undefined ) return;
145 var abstract = work.abstract;
146 return angular.isString(abstract) && abstract.length <= 2000 ? 'ok' : 'ng-invalid';
148 $scope.abstract_length = function(work) {
149 if ( work === undefined ) return;
150 var abstract = work.abstract;
151 if ( ! abstract ) return 0;
152 return abstract.length <= 2000 ? abstract.length : 2000 - abstract.length;
155 $scope.change_state = function(new_state) {
156 if ( new_state == $scope.registration.state ) return;
157 $scope.info = { css_class: 'alert-warning', message: 'Changed state from "'+$scope.registration.state+'" to "'+new_state+'"' };
158 $scope.registration.state = new_state;
161 $scope.show_submission_type = function() {
162 // FIXME check if all submission are allowed by date and allow them!
163 if ( angular.isUndefined( $scope.user ) || angular.isUndefined( $scope.registration ) ) return false;
165 angular.isUndefined( $scope.user.registration_type ) // new registration
166 || angular.isUndefined( $scope.registration.state ) // not saved yet
167 || $scope.registration.state == 'draft'
168 || $scope.registration.state == 'confirmation'
171 $scope.show_registration_type = function() {
177 RegistrationCtrl.$inject = [ '$scope', '$log', 'Registration', '$routeParams', '$location', '$route', 'Organizations', 'ValidStates' ];
179 function ListCtrl($scope, $log, Registration, RegistrationTypes, $filter, ValidStates ) {
182 $scope.list_results = 0;
191 $scope.ready = false;
192 $scope.filters = [ 'student', 'hpd_member', 'reception', 'dinner' ];
194 registration_type: true,
200 $scope.ValidStates = ValidStates();
202 $scope.create_counts = function( array ) {
203 $log.info('create_counts', array.length );
205 var inc_count = function(type) {
206 if ( ! angular.isNumber( Counts[type] ) ) {
212 angular.forEach( array, function(value, key) {
213 if ( ! value.user ) {
214 $log.error("create_counts user corrupted for registration", key, value);
218 var type = value.user.registration_type;
220 inc_count( '' ); // total
221 angular.forEach( $scope.filters, function(subtype) {
222 var v = value.user[subtype];
223 if ( v === 'yes' || v === true ) {
224 inc_count( subtype );
225 inc_count( type + '+' + subtype );
226 inc_count( '+' + subtype ); // total
231 value.registration_type = type;
232 angular.forEach( $scope.filters, function(f) {
233 var v = value.user[f];
234 value[f] = v == true || v == 'yes' ? true : false;
237 // count registration state
238 inc_count( 'state+' + value.state );
240 // $log.info( key, value, Counts[type] );
242 $log.info('Counts', Counts);
243 $scope.Counts = Counts;
247 $scope.all_registrations = Registration.query( function(result) {
249 $log.info('Reqistration.query callback', result);
253 $scope.filter_list = function(newVal, oldVal) {
254 if ( newVal == oldVal ) return;
255 $log.info('filter_list', newVal, oldVal, 'search', $scope.search);
257 $filter('filter')($scope.all_registrations, $scope.search);
259 $scope.create_counts( filtered );
261 $log.info('pager before apply', $scope.pager);
263 $scope.pager.results = filtered.length;
264 $scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
265 if ( $scope.pager.page < 1 ) $scope.pager.page = 1;
266 if ( $scope.pager.page > $scope.pager.last_page ) $scope.pager.page = $scope.pager.last_page;
267 $log.info('pager', $scope.pager);
269 var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
271 angular.forEach( filtered, function(v,k) {
272 if ( k >= from && k < from + $scope.pager.limit || $scope.pager.show_all ) {
277 $log.info('list length=', $scope.list.length, "offset=", from);
279 $scope.$watch('search', $scope.filter_list, true);
280 $scope.$watch('search.$', $scope.filter_list); // FIXME not included in search true because of $
281 $scope.$watch('pager', $scope.filter_list, true);
283 $scope.RegistrationTypes = RegistrationTypes;
284 $log.info( "RegistrationTypes", RegistrationTypes );
286 $scope.reset = function() {
287 $scope.search = { registration_type: '' };
288 $log.info('reset', $scope.search );
289 $scope.pager.page = 1;
293 ListCtrl.$inject = [ '$scope', '$log', 'Registration', 'RegistrationTypes', '$filter', 'ValidStates' ];