X-Git-Url: http://git.rot13.org/?p=angular-mojolicious.git;a=blobdiff_plain;f=public%2Fapp%2Fconference%2Fregistration.js;h=a4f93b3b54b83735ad72fd45f3b3cb72f5af9128;hp=ceda744f6ab3264f783e46ee2af02a9b406e7def;hb=HEAD;hpb=6bc532911a0098a3b99b5ec08d3c25fd0ba3a89c diff --git a/public/app/conference/registration.js b/public/app/conference/registration.js index ceda744..a4f93b3 100644 --- a/public/app/conference/registration.js +++ b/public/app/conference/registration.js @@ -1,7 +1,7 @@ if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug -function Registration($resource){ +function Registration($resource,$xhr){ this.master = { person: { name: '', surname: '', inst: '', email: '' @@ -10,16 +10,21 @@ function Registration($resource){ work: { title: '', abstract: '', - authors:[ { name:'', surname:'', inst:'', email:'' } ] + authors:[ { name:'', surname:'', inst:'', email:'' } ], + organizers: [] }, - symposium: { organizers: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1 } + symposium: { + organizers: [], + work_nr: 1 + } }; - this.Registration = $resource( '/data/conference/Registration/:id', { id:'' } ); - this.Symposium = $resource( '/data/conference/Symposium/:id', { id:'' } ); + this.Registration = $resource( '/data/:database/Registration/:id', { id:'', database: database } ); this.reset(); this.$watch('$location.hashPath', this.hash_change); + this.$xhr = $xhr; + console.debug( 'database', database ); } -Registration.$inject=['$resource']; +Registration.$inject=['$resource','$xhr']; Registration.prototype = { hash_change: function() { @@ -28,14 +33,11 @@ console.debug( 'hash_change', id, this.registration.$id ); if ( id != this.registration.$id ) { if (id) { var self = this; - this.registration = this.Registration.get({ id: id }, function(registration) { + this.Registration.get({ id: id }, function(registration) { +console.debug('registration', id, registration); self.last_saved = angular.copy(registration); - if ( registration.type == 'symposium' ) { - var s_id = registration.symposium.$id || registration.$id; - // first registration doesn't have symposium.$id, but we used same $id -console.debug( 'load symposium ', s_id ); - self.symposium = self.Symposium.get({ id: s_id }); - } + self.registration = registration; // needed for load_symposium below + self.load_symposium(); }); } else this.reset(); @@ -66,18 +68,51 @@ console.debug( 'reset', this.registration, this.$location.hashPath, last ); // save symposium to separate resource if ( registration.type == 'symposium' ) { if ( ! self.symposium ) { - self.registration.symposium.$id = registration.$id; // reuse $id of first work for symposium - self.symposium = new self.Symposium( registration.symposium ); + registration.symposium.$id = registration.$id; // reuse $id of first work for symposium + self.symposium = angular.copy( self.registration.symposium ); self.symposium.works = []; } registration.work.$id = registration.$id; // preserve $id self.symposium.works[ registration.symposium.work_nr - 1 ] = registration.work; -console.debug('save_symposium', self.symposium ); - self.symposium.$save(); + + //self.symposium.$save(); + //self.load_symposium(); } self.last_saved = angular.copy(registration); }); + }, + load_symposium: function() { + var self = this; + if ( self.registration.type != 'symposium' ) return; + + var s_id = self.registration.$id; + if ( self.registration.symposium ) s_id = self.registration.symposium.$id; + + if ( self.symposium && self.symposium.$id == s_id ) { + console.debug('load_symposium ', s_id, ' allready loaded'); + return; + } + + self.symposium = angular.copy( self.registration.symposium ); + self.symposium.works = []; + // first registration doesn't have symposium.$id, but we used same $id +console.debug( 'load_symposium ', s_id, self.symposium ); + +console.debug( self.$xhr ); + + self.$xhr("JSON" + , "/" + database + "/_design/symposium/_view/works?callback=JSON_CALLBACK;key=" + s_id + , function(code, response){ +console.log('symposium/_view/works', code, response); + angular.foreach( response.rows, function(row) { + var work = row.value.work; + work.$id = row.value.$id; // copy $id so we can select correct one in list + self.symposium.works.push( work ); + } ); +console.debug( 'symposium', self.symposium ); + } + ); } };