Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1C8DD10B60 for ; Tue, 9 Apr 2013 20:20:25 +0000 (UTC) Received: (qmail 27634 invoked by uid 500); 9 Apr 2013 20:20:25 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 27592 invoked by uid 500); 9 Apr 2013 20:20:25 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 27584 invoked by uid 99); 9 Apr 2013 20:20:24 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Apr 2013 20:20:24 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9EF25817AD1; Tue, 9 Apr 2013 20:20:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chewbranca@apache.org To: commits@couchdb.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/route-events to 3ecdc2a Date: Tue, 9 Apr 2013 20:20:24 +0000 (UTC) Updated Branches: refs/heads/route-events 35eee36b7 -> 3ecdc2af0 Port editors to route objects Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/3ecdc2af Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/3ecdc2af Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/3ecdc2af Branch: refs/heads/route-events Commit: 3ecdc2af0177979996b7aa061acdf80a734a0d7f Parents: 35eee36 Author: Russell Branca Authored: Tue Apr 9 16:20:26 2013 -0400 Committer: Russell Branca Committed: Tue Apr 9 16:20:26 2013 -0400 ---------------------------------------------------------------------- src/fauxton/app/api.js | 2 +- src/fauxton/app/modules/documents/resources.js | 4 +- src/fauxton/app/modules/documents/routes.js | 202 +++++---------- src/fauxton/app/router.js | 4 +- .../templates/documents/doc_field_editor_tabs.html | 2 +- 5 files changed, 66 insertions(+), 148 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ecdc2af/src/fauxton/app/api.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js index 085291d..2c68086 100644 --- a/src/fauxton/app/api.js +++ b/src/fauxton/app/api.js @@ -134,7 +134,7 @@ function(app, Fauxton) { // immediately if its already done, but this way the RouteObject.route // function can rebuild the deferred as needed render: function(route, masterLayout, args) { - this.route.apply(this, args); + this.route.call(this, route, args); if (this.renderedState === true) { this.rerender.apply(this, arguments); http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ecdc2af/src/fauxton/app/modules/documents/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js index 3f07238..f1a07c3 100644 --- a/src/fauxton/app/modules/documents/resources.js +++ b/src/fauxton/app/modules/documents/resources.js @@ -35,9 +35,11 @@ function(app, FauxtonAPI, Views) { } }, - initialize: function() { + initialize: function(_attrs, options) { if (this.collection && this.collection.database) { this.database = this.collection.database; + } else if (options.database) { + this.database = options.database; } }, http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ecdc2af/src/fauxton/app/modules/documents/routes.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js index 34b00d8..ffed186 100644 --- a/src/fauxton/app/modules/documents/routes.js +++ b/src/fauxton/app/modules/documents/routes.js @@ -25,51 +25,69 @@ function(app, FauxtonAPI, Documents, Databases) { // var Documents = require("modules/documents/models_collections"); // var Databases = require("modules/databases/module"); - var codeEditorCallback = function(databaseName, docID) { - var data = { - database: new Databases.Model({id:databaseName}), - doc: new Documents.Doc({ - "_id": docID - }), - selected: "code_editor" - }; - data.doc.database = data.database; - data.designDocs = new Documents.AllDocs(null, { - database: data.database, - params: {startkey: '"_design"', - endkey: '"_design1"', - include_docs: true} - }); + // TODO:: expand this for new docs and design docs + var DocEditorRouteObject = FauxtonAPI.RouteObject.extend({ + layout: "one_pane", - var options = app.getParams(); - options.include_docs = true; - data.database.buildAllDocs(options); + initialize: function() { + this.selected = false; + }, - return { - layout: "one_pane", + routes: function() { + return _.keys(this.selectedRoutes); + }, - data: data, + selectedRoutes: { + "database/:database/:doc/field_editor": "field_editor", + "database/:database/:doc/code_editor": "code_editor", + "database/:database/:doc": "code_editor" + }, - crumbs: [ + crumbs: function() { + return [ {"name": "Databases", "link": "/_all_dbs"}, - {"name": data.database.id, "link": Databases.databaseUrl(data.database)}, - {"name": docID, "link": "#"} - ], + {"name": this.database.id, "link": Databases.databaseUrl(this.database)}, + {"name": this.docID, "link": "#"} + ]; + }, - views: { - "#dashboard-content": new Documents.Views.Doc({ - model: data.doc - }), + setEditorView: function() { + if (this.selected === "field_editor") { + this.docView = this.setView("#dashboard-content", new Documents.Views.DocFieldEditor({ + model: this.doc + })); + } else { + this.docView = this.setView("#dashboard-content", new Documents.Views.Doc({ + model: this.doc + })); + } + }, - "#tabs": new Documents.Views.FieldEditorTabs({ - selected: data.selected, - model: data.doc - }) - }, + route: function(route, args) { + var databaseName = args[0], docID = args[1]; - apiUrl: data.doc.url() - }; - }; + this.database = this.database || new Databases.Model({id: databaseName}); + this.doc = this.doc || new Documents.Doc({ + _id: docID + }, { + database: this.database + }); + + if (this.selected !== this.selectedRoutes[route]) { + this.selected = this.selectedRoutes[route]; + this.setEditorView(); + } + + this.tabsView = this.setView("#tabs", new Documents.Views.FieldEditorTabs({ + selected: this.selected, + model: this.doc + })); + }, + + apiUrl: function() { + return this.doc.url(); + } + }); var newViewEditorCallback = function(databaseName) { var data = { @@ -161,117 +179,13 @@ function(app, FauxtonAPI, Documents, Databases) { }; Documents.Routes = { - "database/:database/:doc/field_editor": function(databaseName, docID) { - var data = { - database: new Databases.Model({id:databaseName}), - doc: new Documents.Doc({ - "_id": docID - }), - selected: "field_editor" - }; - data.doc.database = data.database; - data.designDocs = new Documents.AllDocs(null, { - database: data.database, - params: {startkey: '"_design"', - endkey: '"_design1"', - include_docs: true} - }); - - var options = app.getParams(); - options.include_docs = true; - data.database.buildAllDocs(options); - - return { - layout: "one_pane", - - data: data, - - crumbs: [ - {"name": "Databases", "link": "/_all_dbs"}, - {"name": data.database.id, "link": Databases.databaseUrl(data.database)}, - {"name": docID, "link": "#"} - ], - - views: { - "#dashboard-content": new Documents.Views.DocFieldEditor({ - model: data.doc - }), - - "#tabs": new Documents.Views.FieldEditorTabs({ - selected: data.selected, - model: data.doc - }) - }, - - apiUrl: data.doc.url() - }; - }, - - "database/:database/:doc/code_editor": codeEditorCallback, - "database/:database/:doc": codeEditorCallback, + //"database/:database/:doc/code_editor": codeEditorCallback, + //"database/:database/:doc": codeEditorCallback, "database/:database/_design%2F:doc": function(database, doc) { var docID = "_design/"+doc; return codeEditorCallback(database, docID); }, - // HACK - // The ordering of routes is different in this object that the - // routes object in the Backbone.Router. As a result, the - // declaration order of show doc and _handler methods has been - // switched. This is a brittle solution that needs to be fixed. - // Conflicts with route: "database/:database/_:handler" - // - // TODO: add support for regex based rotues - // Javascript does not handle a regex as an object key very well, - // and it turns it into its string representation when you use in - // non object literal form, which does get recast back as a regex - // when we need it. - // The inability to use regex based routes here is a design flaw - // and should be rectified. - "old_database/:database/:doc": function(databaseName, docID) { - var data = { - database: new Databases.Model({id:databaseName}), - doc: new Documents.Doc({ - "_id": docID - }) - }; - data.doc.database = data.database; - data.designDocs = new Documents.AllDocs(null, { - database: data.database, - params: {startkey: '"_design"', - endkey: '"_design1"', - include_docs: true} - }); - - var options = app.getParams(); - options.include_docs = true; - data.database.buildAllDocs(options); - - return { - layout: "with_sidebar", - - data: data, - - crumbs: [ - {"name": "Databases", "link": "/_all_dbs"}, - {"name": data.database.id, "link": Databases.databaseUrl(data.database)}, - {"name": docID, "link": "#"} - ], - - views: { - "#dashboard-content": new Documents.Views.Doc({ - model: data.doc - }), - - "#sidebar-content": new Documents.Views.Sidebar({ - collection: data.designDocs - }) - }, - - apiUrl: data.doc.url() - }; - }, - "database/:database/_all_docs(:extra)": function(databaseName, page) { var data = { database: new Databases.Model({id:databaseName}) @@ -422,5 +336,7 @@ function(app, FauxtonAPI, Documents, Databases) { } }; + Documents.RouteObjects = [new DocEditorRouteObject()]; + return Documents; }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ecdc2af/src/fauxton/app/router.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js index d75fe5a..45fd282 100644 --- a/src/fauxton/app/router.js +++ b/src/fauxton/app/router.js @@ -109,10 +109,10 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases, Documents addModuleRouteObject: function(routeObject) { var masterLayout = this.masterLayout; - _.each(routeObject.routes, function(route) { + _.each(routeObject.get('routes'), function(route) { //this.route(route, route.toString(), _.partial(routeObject.renderWith, route, this.masterLayout)); this.route(route, route.toString(), function() { - routeObject.render(route, masterLayout, arguments); + routeObject.render(route, masterLayout, Array.prototype.slice.call(arguments)); }); }, this); }, http://git-wip-us.apache.org/repos/asf/couchdb/blob/3ecdc2af/src/fauxton/app/templates/documents/doc_field_editor_tabs.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/templates/documents/doc_field_editor_tabs.html b/src/fauxton/app/templates/documents/doc_field_editor_tabs.html index ecb0e48..bb16d73 100644 --- a/src/fauxton/app/templates/documents/doc_field_editor_tabs.html +++ b/src/fauxton/app/templates/documents/doc_field_editor_tabs.html @@ -13,7 +13,7 @@ the License. -->