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/conference/Registration/:id', { id:'' } );
19 this.$watch('$location.hashPath', this.hash_change);
22 Registration.$inject=['$resource','$xhr'];
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.get({ id: id }, function(registration) {
32 console.debug('registration', id, registration);
33 self.last_saved = angular.copy(registration);
34 self.registration = registration; // needed for load_symposium below
35 self.load_symposium();
42 console.debug( this.Registration );
43 var last = this.registration;
44 if ( last && last.type == 'symposium' ) {
45 if ( last.$id ) last.symposium.work_nr++; // only if saved
47 this.registration = new this.Registration( this.master );
49 this.registration.type = last.type;
50 this.registration.person = last.person;
52 if ( last.type == 'symposium' )
53 this.registration.symposium = last.symposium;
55 this.last_saved = angular.copy( this.registration ); // FIXME was: {};
56 console.debug( 'reset', this.registration, this.$location.hashPath, last );
60 this.registration.$save(function(registration){
61 self.$location.hashPath = registration.$id;
63 // save symposium to separate resource
64 if ( registration.type == 'symposium' ) {
65 if ( ! self.symposium ) {
66 registration.symposium.$id = registration.$id; // reuse $id of first work for symposium
67 self.symposium = angular.copy( self.registration.symposium );
68 self.symposium.works = [];
70 registration.work.$id = registration.$id; // preserve $id
71 self.symposium.works[ registration.symposium.work_nr - 1 ] = registration.work;
73 //self.symposium.$save();
74 //self.load_symposium();
77 self.last_saved = angular.copy(registration);
80 load_symposium: function() {
82 if ( self.registration.type != 'symposium' ) return;
84 var s_id = self.registration.$id;
85 if ( self.registration.symposium ) s_id = self.registration.symposium.$id;
87 if ( self.symposium && self.symposium.$id == s_id ) {
88 console.debug('load_symposium ', s_id, ' allready loaded');
92 self.symposium = angular.copy( self.registration.symposium );
93 self.symposium.works = [];
94 // first registration doesn't have symposium.$id, but we used same $id
95 console.debug( 'load_symposium ', s_id, self.symposium );
97 console.debug( self.$xhr );
100 , "http://localhost:5984/conference/_design/symposium/_view/works?callback=JSON_CALLBACK;key=" + s_id
101 , function(code, response){
102 console.log('symposium/_view/works', code, response);
103 angular.foreach( response.rows, function(row) {
104 var work = row.value.work;
105 work.$id = row.value.$id; // copy $id so we can select correct one in list
106 self.symposium.works.push( work );
108 console.debug( 'symposium', self.symposium );
114 angular.validator.max_length = function(input, len) {
115 var ok = input.length <= len;
116 console.debug( 'max_length', ok, input.length, len );
117 return ok ? '' : 'must be shorter than '+len+' characters';