2 if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
4 function Registration($resource,$xhr){
7 name: '', surname: '', inst: '', email: ''
13 authors:[ { name:'', surname:'', inst:'', email:'' } ],
21 this.Registration = $resource( '/data/:database/Registration/:id', { id:'', database: database } );
23 this.$watch('$location.hashPath', this.hash_change);
25 console.debug( 'database', database );
27 Registration.$inject=['$resource','$xhr'];
29 Registration.prototype = {
30 hash_change: function() {
31 var id = this.$location.hashPath;
32 console.debug( 'hash_change', id, this.registration.$id );
33 if ( id != this.registration.$id ) {
36 this.Registration.get({ id: id }, function(registration) {
37 console.debug('registration', id, registration);
38 self.last_saved = angular.copy(registration);
39 self.registration = registration; // needed for load_symposium below
40 self.load_symposium();
47 console.debug( this.Registration );
48 var last = this.registration;
49 if ( last && last.type == 'symposium' ) {
50 if ( last.$id ) last.symposium.work_nr++; // only if saved
52 this.registration = new this.Registration( this.master );
54 this.registration.type = last.type;
55 this.registration.person = last.person;
57 if ( last.type == 'symposium' )
58 this.registration.symposium = last.symposium;
60 this.last_saved = angular.copy( this.registration ); // FIXME was: {};
61 console.debug( 'reset', this.registration, this.$location.hashPath, last );
65 this.registration.$save(function(registration){
66 self.$location.hashPath = registration.$id;
68 // save symposium to separate resource
69 if ( registration.type == 'symposium' ) {
70 if ( ! self.symposium ) {
71 registration.symposium.$id = registration.$id; // reuse $id of first work for symposium
72 self.symposium = angular.copy( self.registration.symposium );
73 self.symposium.works = [];
75 registration.work.$id = registration.$id; // preserve $id
76 self.symposium.works[ registration.symposium.work_nr - 1 ] = registration.work;
78 //self.symposium.$save();
79 //self.load_symposium();
82 self.last_saved = angular.copy(registration);
85 load_symposium: function() {
87 if ( self.registration.type != 'symposium' ) return;
89 var s_id = self.registration.$id;
90 if ( self.registration.symposium ) s_id = self.registration.symposium.$id;
92 if ( self.symposium && self.symposium.$id == s_id ) {
93 console.debug('load_symposium ', s_id, ' allready loaded');
97 self.symposium = angular.copy( self.registration.symposium );
98 self.symposium.works = [];
99 // first registration doesn't have symposium.$id, but we used same $id
100 console.debug( 'load_symposium ', s_id, self.symposium );
102 console.debug( self.$xhr );
105 , "/conference/_design/symposium/_view/works?callback=JSON_CALLBACK;key=" + s_id
106 , function(code, response){
107 console.log('symposium/_view/works', code, response);
108 angular.foreach( response.rows, function(row) {
109 var work = row.value.work;
110 work.$id = row.value.$id; // copy $id so we can select correct one in list
111 self.symposium.works.push( work );
113 console.debug( 'symposium', self.symposium );
119 angular.validator.max_length = function(input, len) {
120 var ok = input.length <= len;
121 console.debug( 'max_length', ok, input.length, len );
122 return ok ? '' : 'must be shorter than '+len+' characters';