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/6d4b5ee0 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/6d4b5ee0 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/6d4b5ee0 Branch: refs/heads/route-events Commit: 6d4b5ee0037951a39919d921bcf4882574456b19 Parents: 63e10fc Author: Russell Branca <[email protected]> Authored: Mon Apr 8 22:10:02 2013 -0400 Committer: Garren Smith <[email protected]> Committed: Thu May 9 09:59:58 2013 +0200 ---------------------------------------------------------------------- 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/6d4b5ee0/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/6d4b5ee0/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/6d4b5ee0/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) {
