fix database name in view
[angular-mojolicious.git] / public / app / conference / registration.js
index c42c178..a4f93b3 100644 (file)
@@ -10,14 +10,19 @@ function Registration($resource,$xhr){
                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.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','$xhr'];
 
@@ -28,12 +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' ) {
-                                               //self.symposium = self.Symposium.get({ id: s_id });
-                                               self.load_symposium();
-                                       }
+                                       self.registration = registration; // needed for load_symposium below
+                                       self.load_symposium();
                                });
                        }
                        else this.reset();
@@ -80,9 +84,12 @@ console.debug( 'reset', this.registration, this.$location.hashPath, last );
        },
        load_symposium: function() {
                var self = this;
-               var s_id = self.registration.symposium.$id || self.registration.$id;
+               if ( self.registration.type != 'symposium' ) return;
+
+               var s_id = self.registration.$id;
+               if ( self.registration.symposium ) s_id = self.registration.symposium.$id;
 
-               if ( s_id = self.symposium.$id ) {
+               if ( self.symposium && self.symposium.$id == s_id ) {
                        console.debug('load_symposium ', s_id, ' allready loaded');
                        return;
                }
@@ -95,7 +102,7 @@ console.debug( 'load_symposium ', s_id, self.symposium );
 console.debug( self.$xhr );
 
                self.$xhr("JSON"
-                       , "http://localhost:5984/conference/_design/symposium/_view/works?callback=JSON_CALLBACK;key=" + s_id
+                       , "/" + 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) {