+
+ }
+
+ $scope.$watch('user.registration_type', function( oldValue, newValue ) {
+ $log.info("registration_type watch", oldValue, newValue );
+
+ if ( oldValue === newValue ) return; // triggers on resource, so ignore it
+ if ( ! $scope.user ) { // resource triggers watch before loading json
+ $log.error("no user in scope");
+ return;
+ }
+
+ if (
+ $scope.user.registration_type == 'lecture' ||
+ $scope.user.registration_type == 'poster' ||
+ $scope.user.registration_type == 'symposium' ||
+ $scope.user.registration_type == 'round'
+ ) {
+ if ( angular.isUndefined( $scope.registration.work ) ) {
+ $log.info('create empty work');
+ $scope.registration.work = { persons: [ $scope.user ] };
+ if ( angular.isUndefined( $scope.work ) )
+ $scope.work = $scope.registration.work;
+ }
+
+
+ $scope.work.type = $scope.user.registration_type;
+ $scope.has_work = true;
+ $log.info( $scope.user.registration_type, " type updated");
+
+ if ( $scope.user.registration_type == 'symposium' && ! $scope.work.symposium_works ) {
+ // create 4 empty symposium works
+ $scope.work.symposium_works = [
+ { persons: [{}] },
+ { persons: [{}] },
+ { persons: [{}] },
+ { persons: [{}] }
+ ];
+ $log.info('created symposium_works');
+ }
+
+ } else {
+ $log.info( $scope.user.registration_type, "NO work" );
+ $scope.has_work = false;
+ }
+ });
+
+ $scope.change_student = function() {
+ if ( $scope.user.student ) {
+ $scope.user.hpd_member = false;
+ $scope.user.dinner = false;
+ }
+ }
+
+ $scope.addPerson = function(persons) {
+ $log.info('addPerson', persons);
+ persons.push({ firstname: '' });
+ };
+
+ $scope.removePerson = function(persons,person) {
+ for (var i = 0, ii = persons.length; i < ii; i++) {
+ if (person === persons[i]) {
+ persons.splice(i, 1);
+ $log.info('removePerson', i, person);
+ }
+ }
+ };
+
+ $scope.add_symposium_work = function(works) {
+ works.push({ persons: [{}] });
+ }
+
+ $scope.symposium_work_remove = function(work_index) {
+ if ( ! angular.isNumber(work_index) ) {
+ $log.error("work_index", work_index);
+ return;
+ }
+ var works = $scope.work.symposium_works;
+ $log.info('symposium_work_remove', works, work_index);
+ var removed = works.splice( work_index, 1 );
+ if ( angular.isArray(removed) && removed[0] ) {
+ removed = removed[0];
+ removed.deleted = true;
+ if ( ! angular.isArray( $scope.work.symposium_works_deleted ) )
+ $scope.work.symposium_works_deleted = [];
+ $scope.work.symposium_works_deleted.push( removed );
+ $log.info("work deleted", works);
+ } else {
+ $log.warn("symposium_work_remove no work to remove", works, work);
+ }
+ }
+
+ $scope.abstract_class = function(work) {
+ if ( work === undefined ) return;
+ var abstract = work.abstract;
+ return angular.isString(abstract) && abstract.length <= 2000 ? 'ok' : 'ng-invalid';
+ }
+ $scope.abstract_length = function(work) {
+ if ( work === undefined ) return;
+ var abstract = work.abstract;
+ if ( ! abstract ) return 0;
+ return abstract.length <= 2000 ? abstract.length : 2000 - abstract.length;
+ }
+
+ $scope.change_state = function(new_state) {
+ if ( new_state == $scope.registration.state ) return;
+ $scope.info = { css_class: 'alert-warning', message: 'Changed state from "'+$scope.registration.state+'" to "'+new_state+'"' };
+ $scope.registration.state = new_state;
+ }
+
+ $scope.show_submission_type = function() {
+ // FIXME check if all submission are allowed by date and allow them!
+ if ( angular.isUndefined( $scope.user ) || angular.isUndefined( $scope.registration ) ) return false;
+ return (
+ angular.isUndefined( $scope.user.registration_type ) // new registration
+ || angular.isUndefined( $scope.registration.state ) // not saved yet
+ || $scope.registration.state == 'draft'
+ || $scope.registration.state == 'confirmation'
+ ) ? false : true;
+ }
+ $scope.show_registration_type = function() {
+ return true;