You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/05/09 16:01:32 UTC
[35/50] git commit: updated refs/heads/route-events to c33e390
Working route objects
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/63e10fce
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/63e10fce
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/63e10fce
Branch: refs/heads/route-events
Commit: 63e10fce4b2a48f6d37f097f578f11b74acf250c
Parents: 2f138a9
Author: Russell Branca <ch...@gmail.com>
Authored: Mon Apr 8 22:08:07 2013 -0400
Committer: Garren Smith <ga...@gmail.com>
Committed: Thu May 9 09:59:58 2013 +0200
----------------------------------------------------------------------
src/fauxton/app/api.js | 56 ++++++++++++++++++++++
src/fauxton/app/modules/databases/routes.js | 53 ++++++++++++++++++++-
2 files changed, 107 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/63e10fce/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index 52e8611..c44efa1 100644
--- a/src/fauxton/app/api.js
+++ b/src/fauxton/app/api.js
@@ -96,6 +96,62 @@ function(app, Fauxton) {
}
});
+ FauxtonAPI.RouteObject = function(options) {
+ this._options = options;
+
+ this._configure(options || {});
+ this.initialize.apply(this, arguments);
+ this.addEvents();
+ };
+
+ var routeObjectOptions = ["views", "routes", "events", "data", "crumbs", "layout", "apiUrl", "establish"];
+
+ _.extend(FauxtonAPI.RouteObject.prototype, Backbone.Events, {
+ // Should these be default vals or empty funcs?
+ views: {},
+ routes: {},
+ events: {},
+ data: {},
+ crumbs: [],
+ layout: null,
+ apiUrl: null,
+ establish: null
+ }, {
+ route: function() {},
+ initialize: function() {},
+ renderWith: function(layout) {
+ },
+ get: function(key) {
+ return _.isFunction(this[key]) ? this[key]() : this[key];
+ },
+ addEvents: function(events) {
+ events = events || this.get('events');
+ _.each(events, function(method, event) {
+ if (!_.isFunction(method) && !_.isFunction(this[method])) {
+ throw new Error("Invalid method: "+method);
+ }
+ method = _.isFunction(method) ? method : this[method];
+
+ this.on(event, method);
+ }, this);
+ },
+ _configure: function(options) {
+ /*
+ _.each(_.intersection(_.keys(options), routeObjectOptions), function(key) {
+ this[key] = options[key];
+ }, this);
+ */
+ _.each(options, function(val, key) { this[key] = val; }, this);
+ },
+ setView: function(selector, view) {
+ this.views[selector] = view;
+ return view;
+ },
+ getViews: function() {
+ return this.views;
+ }
+ });
+
app.fauxtonAPI = FauxtonAPI;
return app.fauxtonAPI;
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/63e10fce/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 2ba59d7..f6a6226 100644
--- a/src/fauxton/app/modules/databases/routes.js
+++ b/src/fauxton/app/modules/databases/routes.js
@@ -16,10 +16,59 @@ define([
"api",
// Modules
- "modules/databases/resources"
+ "modules/databases/resources",
+ // TODO:: fix the include flow modules so we don't have to require views here
+ "modules/databases/views"
],
-function(app, FauxtonAPI, Databases) {
+function(app, FauxtonAPI, Databases, Views) {
+ var allDbsRouteObject = Databases.AllDbsRouteObject = new FauxtonAPI.RouteObject({
+ layout: "with_sidebar",
+
+ crumbs: [
+ {"name": "Databases", "link": "/_all_dbs"}
+ ],
+
+ apiUrl: function() {
+ return this.databases.url();
+ },
+
+ initialize: function() {
+ this.databases = new Databases.List();
+ this.deferred = FauxtonAPI.Deferred();
+
+ this.setView("#dashboard-content", new Views.List({
+ collection: this.databases
+ }));
+ this.setView("#sidebar-content", new Views.Sidebar({
+ collection: this.databases
+ }));
+ },
+
+ establish: function() {
+ var databases = this.databases;
+ var deferred = this.deferred;
+
+ databases.fetch().done(function(resp) {
+ $.when.apply(null, databases.map(function(database) {
+ return database.status.fetch();
+ })).done(function(resp) {
+ deferred.resolve();
+ });
+ });
+
+ return [deferred];
+ },
+
+ mrEvent: function() {
+ console.log("Triggering a most excellent event!!!!");
+ },
+
+ events: {
+ "myrandom_event": "mrEvent"
+ }
+ });
+
var allDbsCallback = function() {
var data = {
databases: new Databases.List()