2 if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
4 function Registration($resource){
7 name: '', surname: '', inst: '', email: ''
13 authors:[ { name:'', surname:'', inst:'', email:'' } ]
15 symposium: { organizers: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1 }
17 this.Registration = $resource( '/data/conference/Registration/:id', { id:'' } );
18 this.Symposium = $resource( '/data/conference/Symposium/:id', { id:'' } );
20 this.$watch('$location.hashPath', this.hash_change);
22 Registration.$inject=['$resource'];
24 Registration.prototype = {
25 hash_change: function() {
26 var id = this.$location.hashPath;
27 console.debug( 'hash_change', id, this.registration.$id );
28 if ( id != this.registration.$id ) {
31 this.registration = this.Registration.get({ id: id }, function(registration) {
32 self.last_saved = angular.copy(registration);
33 if ( registration.type == 'symposium' ) {
34 var s_id = registration.symposium.$id || registration.$id;
35 // first registration doesn't have symposium.$id, but we used same $id
36 console.debug( 'load symposium ', s_id );
37 self.symposium = self.Symposium.get({ id: s_id });
45 console.debug( this.Registration );
46 var last = this.registration;
47 if ( last && last.type == 'symposium' ) {
48 if ( last.$id ) last.symposium.work_nr++; // only if saved
50 this.registration = new this.Registration( this.master );
52 this.registration.type = last.type;
53 this.registration.person = last.person;
55 if ( last.type == 'symposium' )
56 this.registration.symposium = last.symposium;
58 this.last_saved = angular.copy( this.registration ); // FIXME was: {};
59 console.debug( 'reset', this.registration, this.$location.hashPath, last );
63 this.registration.$save(function(registration){
64 self.$location.hashPath = registration.$id;
66 // save symposium to separate resource
67 if ( registration.type == 'symposium' ) {
68 if ( ! self.symposium ) {
69 self.registration.symposium.$id = registration.$id; // reuse $id of first work for symposium
70 self.symposium = new self.Symposium( registration.symposium );
71 self.symposium.works = [];
73 registration.work.$id = registration.$id; // preserve $id
74 self.symposium.works[ registration.symposium.work_nr - 1 ] = registration.work;
75 console.debug('save_symposium', self.symposium );
76 self.symposium.$save();
79 self.last_saved = angular.copy(registration);
84 angular.validator.max_length = function(input, len) {
85 var ok = input.length <= len;
86 console.debug( 'max_length', ok, input.length, len );
87 return ok ? '' : 'must be shorter than '+len+' characters';