Merge branch 'app'
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 15 Nov 2010 20:03:13 +0000 (21:03 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 15 Nov 2010 20:03:13 +0000 (21:03 +0100)
angular-server.pl
public/app/conference/registration.js
public/app/conference/symposiums.js

index 9450517..d8d9b9e 100755 (executable)
@@ -171,6 +171,17 @@ get '/app/:database/angular.js' => sub {
        $self->render_static( $ANGULAR_JS );
 };
 
+# CouchDB proxy for _design _view
+
+get '/:database/_design/:design/_view/:view' => sub {
+       my $self = shift;
+       my $url = join('/', $self->param('database'),'_design',$self->param('design'),'_view',$self->param('view') );
+       my $param = $self->req->url->query->clone->remove('callback')->to_string;
+       $url .= '?' . $param if $param;
+       warn "CouchDB proxy $url";
+       _render_jsonp( $self, _couchdb_get($url));
+};
+
 app->start;
 __DATA__
 
index c42c178..1551a95 100644 (file)
@@ -28,12 +28,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 +79,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;
 
-               if ( s_id = self.symposium.$id ) {
+               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;
                }
@@ -95,7 +97,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
+                       , "/conference/_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) {
index 7502e76..3713664 100644 (file)
@@ -10,7 +10,7 @@ function Symposiums(xhr, route){
        this.data = data;
 
        this.xhr("JSON"
-               , "http://localhost:5984/conference/_design/symposium/_view/work_nr%2Ctitle?callback=JSON_CALLBACK"
+               , "/conference/_design/symposium/_view/work_nr%2Ctitle?callback=JSON_CALLBACK"
                , function(code, response){ 
                        console.log(code, response, data);
                        data.response = response;