You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2013/04/09 04:10:05 UTC

[2/2] git commit: updated refs/heads/route-events to 88eab77

Now working with the router


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/88eab777
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/88eab777
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/88eab777

Branch: refs/heads/route-events
Commit: 88eab777756f145cc3a5953d093dccc0a358ba9c
Parents: feda2cd
Author: Russell Branca <ch...@gmail.com>
Authored: Mon Apr 8 22:10:02 2013 -0400
Committer: Russell Branca <ch...@gmail.com>
Committed: Mon Apr 8 22:10:02 2013 -0400

----------------------------------------------------------------------
 src/fauxton/app/api.js                      |   45 ++++++++++++++++++++-
 src/fauxton/app/modules/databases/routes.js |    6 +++
 src/fauxton/app/router.js                   |   11 +++++
 3 files changed, 59 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/88eab777/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index c44efa1..b82107e 100644
--- a/src/fauxton/app/api.js
+++ b/src/fauxton/app/api.js
@@ -113,13 +113,52 @@ function(app, Fauxton) {
     events: {},
     data: {},
     crumbs: [],
-    layout: null,
+    layout: "with_sidebar",
     apiUrl: null,
-    establish: null
+    establish: function() {}
   }, {
     route: function() {},
     initialize: function() {},
-    renderWith: function(layout) {
+    renderWith: function(route, masterLayout, args) {
+      var routeObject = this;
+      this.route.apply(this, args);
+
+      masterLayout.setTemplate(this.layout);
+      masterLayout.clearBreadcrumbs();
+
+      if (this.crumbs.length) {
+        masterLayout.setBreadcrumbs(new Fauxton.Breadcrumbs({
+          crumbs: this.crumbs
+        }));
+      }
+
+      $.when.apply(this, this.establish()).done(function(resp) {
+        _.each(routeObject.views, function(view, selector) {
+          masterLayout.setView(selector, view);
+
+          $.when.apply(null, view.establish()).then(function(resp) {
+            masterLayout.renderView(selector);
+          }, function(resp) {
+            view.establishError = {
+              error: true,
+              reason: resp
+            };
+            masterLayout.renderView(selector);
+          });
+
+          var hooks = masterLayout.hooks[selector];
+
+          if(hooks){
+            _.each(hooks, function(hook){
+              if (_.any(hook.routes, function(route){return route == boundRoute;})){
+                hook.callback(view);
+              }
+            });
+          }
+        });
+      });
+
+      if (this.get('apiUrl')) masterLayout.apiBar.update(this.get('apiUrl'));
     },
     get: function(key) {
       return _.isFunction(this[key]) ? this[key]() : this[key];

http://git-wip-us.apache.org/repos/asf/couchdb/blob/88eab777/src/fauxton/app/modules/databases/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/databases/routes.js b/src/fauxton/app/modules/databases/routes.js
index f6a6226..376a94a 100644
--- a/src/fauxton/app/modules/databases/routes.js
+++ b/src/fauxton/app/modules/databases/routes.js
@@ -29,6 +29,8 @@ function(app, FauxtonAPI, Databases, Views) {
       {"name": "Databases", "link": "/_all_dbs"}
     ],
 
+    routes: ["", "index.html", "_all_dbs(:params)"],
+
     apiUrl: function() {
       return this.databases.url();
     },
@@ -109,11 +111,15 @@ function(app, FauxtonAPI, Databases, Views) {
     };
   };
 
+  /*
   Databases.Routes = {
     "": allDbsCallback,
     "index.html": allDbsCallback,
     "_all_dbs(:params)": allDbsCallback
   };
+  */
+
+  Databases.RouteObjects = [allDbsRouteObject];
 
   return Databases;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/88eab777/src/fauxton/app/router.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js
index 77cc36b..efd7cad 100644
--- a/src/fauxton/app/router.js
+++ b/src/fauxton/app/router.js
@@ -107,10 +107,21 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases, Documents
       this.route(route, route.toString(), generateRoute(generator, route));
     },
 
+    addModuleRouteObject: function(routeObject) {
+      var masterLayout = this.masterLayout;
+      _.each(routeObject.routes, function(route) {
+        //this.route(route, route.toString(), _.partial(routeObject.renderWith, route, this.masterLayout));
+        this.route(route, route.toString(), function() {
+          routeObject.renderWith(route, masterLayout, arguments);
+        });
+      }, this);
+    },
+
     setModuleRoutes: function() {
       _.each(modules, function(module) {
         if (module){
           _.each(module.Routes, this.addModuleRoute, this);
+          _.each(module.RouteObjects, this.addModuleRouteObject, this);
         }
       }, this);
       _.each(LoadAddons.addons, function(module) {