summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2014-01-27 10:17:33 +0200
committerGarren Smith <garren.smith@gmail.com>2014-01-29 15:48:54 +0200
commit652f8890212bc4c74446a5e3d2820c87ac6037a4 (patch)
tree1f02d1ebfcce1fd41218e5b124f509af29b0eabe
parent864e0d14de4c51e1fa52bb0b4e2c17f68001ca76 (diff)
downloadcouchdb-652f8890212bc4c74446a5e3d2820c87ac6037a4.tar.gz
Fixes from reviews
-rw-r--r--src/fauxton/app/addons/documents/resources.js17
-rw-r--r--src/fauxton/app/addons/documents/views.js2
-rw-r--r--src/fauxton/app/addons/fauxton/base.js28
-rw-r--r--src/fauxton/app/addons/fauxton/layout.js89
-rw-r--r--src/fauxton/app/addons/fauxton/tests/baseSpec.js11
-rw-r--r--src/fauxton/app/app.js2
-rw-r--r--src/fauxton/app/core/api.js3
-rw-r--r--src/fauxton/app/core/layout.js43
-rw-r--r--src/fauxton/app/router.js142
-rw-r--r--src/fauxton/test/mocha/testUtils.js2
10 files changed, 56 insertions, 283 deletions
diff --git a/src/fauxton/app/addons/documents/resources.js b/src/fauxton/app/addons/documents/resources.js
index 75cd541fd..831d5e3d0 100644
--- a/src/fauxton/app/addons/documents/resources.js
+++ b/src/fauxton/app/addons/documents/resources.js
@@ -18,21 +18,6 @@ define([
function(app, FauxtonAPI) {
var Documents = FauxtonAPI.addon();
- Documents.UUID = FauxtonAPI.Model.extend({
- initialize: function(options) {
- options = _.extend({count: 1}, options);
- this.count = options.count;
- },
-
- url: function() {
- return "/_uuids?count=" + this.count;
- },
-
- next: function() {
- return this.get("uuids").pop();
- }
- });
-
Documents.Doc = Backbone.Model.extend({
idAttribute: "_id",
documentation: function(){
@@ -273,7 +258,7 @@ function(app, FauxtonAPI) {
Documents.NewDoc = Documents.Doc.extend({
fetch: function() {
- var uuid = new Documents.UUID();
+ var uuid = new FauxtonAPI.UUID();
var deferred = this.deferred = $.Deferred();
var that = this;
diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js
index 6cdd1dbc9..aeb5983b1 100644
--- a/src/fauxton/app/addons/documents/views.js
+++ b/src/fauxton/app/addons/documents/views.js
@@ -264,7 +264,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
showModal: function () {
var showModal = this._showModal,
setDefaultIdValue = this.setDefaultIdValue,
- uuid = new Documents.UUID();
+ uuid = new FauxtonAPI.UUID();
uuid.fetch().then(function () {
setDefaultIdValue(uuid.next());
diff --git a/src/fauxton/app/addons/fauxton/base.js b/src/fauxton/app/addons/fauxton/base.js
index b42188e65..35babb5f6 100644
--- a/src/fauxton/app/addons/fauxton/base.js
+++ b/src/fauxton/app/addons/fauxton/base.js
@@ -30,14 +30,30 @@ function(app, FauxtonAPI, resizeColumns) {
return view.renderNotification();
};
+ FauxtonAPI.UUID = FauxtonAPI.Model.extend({
+ initialize: function(options) {
+ options = _.extend({count: 1}, options);
+ this.count = options.count;
+ },
+
+ url: function() {
+ return app.host + "/_uuids?count=" + this.count;
+ },
+
+ next: function() {
+ return this.get("uuids").pop();
+ }
+ });
+
+
Fauxton.initialize = function () {
app.footer = new Fauxton.Footer({el: "#footer-content"}),
app.navBar = new Fauxton.NavBar();
app.apiBar = new Fauxton.ApiBar();
FauxtonAPI.when.apply(null, app.footer.establish()).done(function() {
- FauxtonAPI.masterLayout.layout.setView("#primary-navbar", app.navBar);
- FauxtonAPI.masterLayout.layout.setView("#api-navbar", app.apiBar);
+ FauxtonAPI.masterLayout.setView("#primary-navbar", app.navBar, true);
+ FauxtonAPI.masterLayout.setView("#api-navbar", app.apiBar, true);
app.navBar.render();
app.apiBar.render();
@@ -57,13 +73,13 @@ function(app, FauxtonAPI, resizeColumns) {
});
FauxtonAPI.RouteObject.on('beforeEstablish', function (routeObject) {
- FauxtonAPI.masterLayout.clearBreadcrumbs();
+ FauxtonAPI.masterLayout.removeView('#breadcrumbs');
var crumbs = routeObject.get('crumbs');
if (crumbs.length) {
- FauxtonAPI.masterLayout.setBreadcrumbs(new Fauxton.Breadcrumbs({
+ FauxtonAPI.masterLayout.setView('#breadcrumbs', new Fauxton.Breadcrumbs({
crumbs: crumbs
- }));
+ }), true).render();
}
});
@@ -163,8 +179,6 @@ function(app, FauxtonAPI, resizeColumns) {
} else {
this.navLinks.push(link);
}
-
- //this.render();
},
removeLink: function (removeLink) {
diff --git a/src/fauxton/app/addons/fauxton/layout.js b/src/fauxton/app/addons/fauxton/layout.js
deleted file mode 100644
index baac86411..000000000
--- a/src/fauxton/app/addons/fauxton/layout.js
+++ /dev/null
@@ -1,89 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-define(["backbone"],
-
-function(Backbone) {
-
- // A wrapper of the main Backbone.layoutmanager
- // Allows the main layout of the page to be changed by any plugin.
- // Exposes the different views:
- // navBar -> the top navigation bar
- // dashboardContent -> Main display view
- // breadcrumbs -> Breadcrumbs navigation section
- var Layout = function () {
- this.layout = new Backbone.Layout({
- template: "templates/layouts/with_sidebar",
- });
-
- this.layoutViews = {};
- this.el = this.layout.el;
- };
-
- Layout.configure = function (options) {
- Backbone.Layout.configure(options);
- };
-
- // creatings the dashboard object same way backbone does
- _.extend(Layout.prototype, {
- render: function () {
- return this.layout.render();
- },
-
- setTemplate: function(template) {
- if (template.prefix){
- this.layout.template = template.prefix + template.name;
- } else{
- this.layout.template = "templates/layouts/" + template;
- }
- // If we're changing layouts all bets are off, so kill off all the
- // existing views in the layout.
- _.each(this.layoutViews, function(view){view.remove();});
- this.layoutViews = {};
- this.render();
- },
-
- setTabs: function(view){
- // TODO: Not sure I like this - seems fragile/repetitive
- this.tabs = this.layout.setView("#tabs", view);
- this.tabs.render();
- },
-
- setBreadcrumbs: function(view) {
- this.breadcrumbs = this.layout.setView("#breadcrumbs", view);
- this.breadcrumbs.render();
- },
-
- clearBreadcrumbs: function () {
- if (!this.breadcrumbs) {return ;}
-
- this.breadcrumbs.remove();
- },
-
- setView: function(selector, view) {
- this.layoutViews[selector] = this.layout.setView(selector, view, false);
- },
-
- renderView: function(selector) {
- var view = this.layoutViews[selector];
- if (!view) {
- return false;
- } else {
- return view.render();
- }
- }
-
- });
-
- return Layout;
-
-});
diff --git a/src/fauxton/app/addons/fauxton/tests/baseSpec.js b/src/fauxton/app/addons/fauxton/tests/baseSpec.js
index 644002cdf..7df4dfc9d 100644
--- a/src/fauxton/app/addons/fauxton/tests/baseSpec.js
+++ b/src/fauxton/app/addons/fauxton/tests/baseSpec.js
@@ -34,13 +34,18 @@ define([
testRouteObject = new TestRouteObject();
var apiBar = {};
apiBar.hide = sinon.spy();
+ var setViewSpy = sinon.stub();
+ setViewSpy.returns({
+ render: function () {}
+ });
// Need to find a better way of doing this
mockLayout = {
setTemplate: sinon.spy(),
clearBreadcrumbs: sinon.spy(),
- setView: sinon.spy(),
+ setView: setViewSpy,
renderView: sinon.spy(),
+ removeView: sinon.spy(),
hooks: [],
setBreadcrumbs: sinon.spy(),
apiBar: apiBar,
@@ -59,13 +64,13 @@ define([
it('Should clear breadcrumbs', function () {
FauxtonAPI.masterLayout = mockLayout;
testRouteObject.renderWith('the-route', mockLayout, 'args');
- assert.ok(mockLayout.clearBreadcrumbs.calledOnce, 'Clear Breadcrumbs called');
+ assert.ok(mockLayout.removeView.calledWith('#breadcrumbs'), 'Clear Breadcrumbs called');
});
it('Should set breadcrumbs when breadcrumbs exist', function () {
FauxtonAPI.masterLayout = mockLayout;
testRouteObject.renderWith('the-route', mockLayout, 'args');
- assert.ok(mockLayout.setBreadcrumbs.calledOnce, 'Set Breadcrumbs was called');
+ assert.ok(mockLayout.setView.calledOnce, 'Set Breadcrumbs was called');
});
});
diff --git a/src/fauxton/app/app.js b/src/fauxton/app/app.js
index 3ec2c99ac..521ad6c84 100644
--- a/src/fauxton/app/app.js
+++ b/src/fauxton/app/app.js
@@ -24,7 +24,7 @@ define([
"core/utils",
// Modules
"core/api",
- "core/couchdbSession",
+ "core/couchdbsession",
// Plugins.
"plugins/backbone.layoutmanager",
"plugins/jquery.form"
diff --git a/src/fauxton/app/core/api.js b/src/fauxton/app/core/api.js
index 5483f446f..1b21dca62 100644
--- a/src/fauxton/app/core/api.js
+++ b/src/fauxton/app/core/api.js
@@ -15,11 +15,10 @@ define([
"core/layout",
"core/router",
"core/routeObject",
- "core/couchdbSession",
"core/utils"
],
-function(FauxtonAPI, Layout, Router, RouteObject, CouchdbSession, utils) {
+function(FauxtonAPI, Layout, Router, RouteObject, utils) {
FauxtonAPI = _.extend(FauxtonAPI, {
Layout: Layout,
Router: Router,
diff --git a/src/fauxton/app/core/layout.js b/src/fauxton/app/core/layout.js
index a5ed88c36..ff339c72c 100644
--- a/src/fauxton/app/core/layout.js
+++ b/src/fauxton/app/core/layout.js
@@ -17,10 +17,6 @@ define([
// A wrapper of the main Backbone.layoutmanager
// Allows the main layout of the page to be changed by any plugin.
- // Exposes the different views:
- // navBar -> the top navigation bar
- // dashboardContent -> Main display view
- // breadcrumbs -> Breadcrumbs navigation section
var Layout = function () {
this.layout = new Backbone.Layout({
template: "templates/layouts/with_sidebar",
@@ -53,25 +49,14 @@ define([
this.render();
},
- setTabs: function(view){
- // TODO: Not sure I like this - seems fragile/repetitive
- this.tabs = this.layout.setView("#tabs", view);
- this.tabs.render();
- },
-
- setBreadcrumbs: function(view) {
- this.breadcrumbs = this.layout.setView("#breadcrumbs", view);
- this.breadcrumbs.render();
- },
-
- clearBreadcrumbs: function () {
- if (!this.breadcrumbs) {return ;}
+ setView: function(selector, view, keep) {
+ this.layout.setView(selector, view, false);
- this.breadcrumbs.remove();
- },
+ if (!keep) {
+ this.layoutViews[selector] = view;
+ }
- setView: function(selector, view) {
- this.layoutViews[selector] = this.layout.setView(selector, view, false);
+ return view;
},
renderView: function(selector) {
@@ -81,6 +66,22 @@ define([
} else {
return view.render();
}
+ },
+
+ removeView: function (selector) {
+ var view = this.layout.getView(selector);
+
+ if (!view) {
+ return false;
+ }
+
+ view.remove();
+
+ if (this.layoutViews[selector]) {
+ delete this.layoutViews[selector];
+ }
+
+ return true;
}
});
diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js
deleted file mode 100644
index 1e0caac79..000000000
--- a/src/fauxton/app/router.js
+++ /dev/null
@@ -1,142 +0,0 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
-// use this file except in compliance with the License. You may obtain a copy of
-// the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations under
-// the License.
-
-define([
- // Load require for use in nested requiring
- // as per the note in: http://requirejs.org/docs/api.html#multiversion
- "require",
-
- // Application.
- "app",
-
- // Initialize application
- "initialize",
-
- // Load Fauxton API
- "core/api",
-
- // Modules
- //"addons/fauxton/base",
- // Layout
- //"addons/fauxton/layout",
-
- "load_addons"
-],
-
-function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, LoadAddons) {
-
- var beforeUnloads = {};
-
- var Router = app.router = Backbone.Router.extend({
- routes: {},
-
- beforeUnload: function (name, fn) {
- beforeUnloads[name] = fn;
- },
-
- removeBeforeUnload: function (name) {
- delete beforeUnloads[name];
- },
-
- navigate: function (fragment, trigger) {
- var continueNav = true,
- msg = _.find(_.map(beforeUnloads, function (fn) { return fn(); }), function (beforeReturn) {
- if (beforeReturn) { return true; }
- });
-
- if (msg) {
- continueNav = window.confirm(msg);
- }
-
- if (continueNav) {
- Backbone.Router.prototype.navigate(fragment, trigger);
- }
- },
-
- addModuleRouteObject: function(RouteObject) {
- var that = this;
- var masterLayout = this.masterLayout,
- routeUrls = RouteObject.prototype.getRouteUrls();
-
- _.each(routeUrls, function(route) {
- this.route(route, route.toString(), function() {
- var args = Array.prototype.slice.call(arguments),
- roles = RouteObject.prototype.getRouteRoles(route),
- authPromise = app.auth.checkAccess(roles);
-
- authPromise.then(function () {
- if (!that.activeRouteObject || !that.activeRouteObject.hasRoute(route)) {
- if (that.activeRouteObject) {
- that.activeRouteObject.cleanup();
- }
- that.activeRouteObject = new RouteObject(route, masterLayout, args);
- }
-
- var routeObject = that.activeRouteObject;
- routeObject.routeCallback(route, args);
- routeObject.renderWith(route, masterLayout, args);
- }, function () {
- FauxtonAPI.auth.authDeniedCb();
- });
-
- });
- }, this);
- },
-
- setModuleRoutes: function() {
- _.each(LoadAddons.addons, function(module) {
- console.log('aa', module);
- if (module){
- module.initialize();
- // This is pure routes the addon provides
- if (module.RouteObjects) {
- _.each(module.RouteObjects, this.addModuleRouteObject, this);
- }
- }
- }, this);
- },
-
- initialize: function() {
- //TODO: It would be nice to handle this with a router
- this.navBar = app.navBar = new Fauxton.NavBar();
- this.apiBar = app.apiBar = new Fauxton.ApiBar();
- this.auth = app.auth = FauxtonAPI.auth;
- app.session = FauxtonAPI.session;
-
- app.masterLayout = this.masterLayout = new Layout(this.navBar, this.apiBar);
- app.footer = new Fauxton.Footer({el: "#footer-content"});
-
- // NOTE: This must be below creation of the layout
- // FauxtonAPI header links and others depend on existence of the layout
- this.setModuleRoutes();
-
- $("#app-container").html(this.masterLayout.el);
- this.masterLayout.render();
-
- // TODO: move this to a proper Fauxton.View
- $.when.apply(null, app.footer.establish()).done(function() {
- app.footer.render();
- });
- },
-
- triggerRouteEvent: function(event, args) {
- if (this.activeRouteObject) {
- var eventArgs = [event].concat(args);
- this.activeRouteObject.trigger.apply(this.activeRouteObject, eventArgs );
- this.activeRouteObject.renderWith(eventArgs, this.masterLayout, args);
- }
- }
- });
-
- return Router;
-
-});
diff --git a/src/fauxton/test/mocha/testUtils.js b/src/fauxton/test/mocha/testUtils.js
index 08b80c70d..2c418f915 100644
--- a/src/fauxton/test/mocha/testUtils.js
+++ b/src/fauxton/test/mocha/testUtils.js
@@ -25,7 +25,7 @@ function(FauxtonAPI,chai, sinonChai) {
_.extend(ViewSandbox.prototype, {
initialize: function () {
- this.$el = $('<div style="display:no1ne"></div>').appendTo('body');
+ this.$el = $('<div style="display:none"></div>').appendTo('body');
this.$ = this.$el.find;
},
views: [],