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:'' } ]
15 symposium: { organizers: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1 }
17 this.Registration = $resource( '/data/:database/Registration/:id', { id:'', database: database } );
19 this.$watch('$location.hashPath', this.hash_change);
21 console.debug( 'database', database );
23 Registration.$inject=['$resource','$xhr'];
25 Registration.prototype = {
26 hash_change: function() {
27 var id = this.$location.hashPath;
28 console.debug( 'hash_change', id, this.registration.$id );
29 if ( id != this.registration.$id ) {
32 this.Registration.get({ id: id }, function(registration) {
33 console.debug('registration', id, registration);
34 self.last_saved = angular.copy(registration);
35 self.registration = registration; // needed for load_symposium below
36 self.load_symposium();
43 console.debug( this.Registration );
44 var last = this.registration;
45 if ( last && last.type == 'symposium' ) {
46 if ( last.$id ) last.symposium.work_nr++; // only if saved
48 this.registration = new this.Registration( this.master );
50 this.registration.type = last.type;
51 this.registration.person = last.person;
53 if ( last.type == 'symposium' )
54 this.registration.symposium = last.symposium;
56 this.last_saved = angular.copy( this.registration ); // FIXME was: {};
57 console.debug( 'reset', this.registration, this.$location.hashPath, last );
61 this.registration.$save(function(registration){
62 self.$location.hashPath = registration.$id;
64 // save symposium to separate resource
65 if ( registration.type == 'symposium' ) {
66 if ( ! self.symposium ) {
67 registration.symposium.$id = registration.$id; // reuse $id of first work for symposium
68 self.symposium = angular.copy( self.registration.symposium );
69 self.symposium.works = [];
71 registration.work.$id = registration.$id; // preserve $id
72 self.symposium.works[ registration.symposium.work_nr - 1 ] = registration.work;
74 //self.symposium.$save();
75 //self.load_symposium();
78 self.last_saved = angular.copy(registration);
81 load_symposium: function() {
83 if ( self.registration.type != 'symposium' ) return;
85 var s_id = self.registration.$id;
86 if ( self.registration.symposium ) s_id = self.registration.symposium.$id;
88 if ( self.symposium && self.symposium.$id == s_id ) {
89 console.debug('load_symposium ', s_id, ' allready loaded');
93 self.symposium = angular.copy( self.registration.symposium );
94 self.symposium.works = [];
95 // first registration doesn't have symposium.$id, but we used same $id
96 console.debug( 'load_symposium ', s_id, self.symposium );
98 console.debug( self.$xhr );
101 , "/conference/_design/symposium/_view/works?callback=JSON_CALLBACK;key=" + s_id
102 , function(code, response){
103 console.log('symposium/_view/works', code, response);
104 angular.foreach( response.rows, function(row) {
105 var work = row.value.work;
106 work.$id = row.value.$id; // copy $id so we can select correct one in list
107 self.symposium.works.push( work );
109 console.debug( 'symposium', self.symposium );
115 angular.validator.max_length = function(input, len) {
116 var ok = input.length <= len;
117 console.debug( 'max_length', ok, input.length, len );
118 return ok ? '' : 'must be shorter than '+len+' characters';