summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2013-10-28 14:57:07 +0200
committerGarren Smith <garren.smith@gmail.com>2013-10-28 18:15:18 +0200
commitb7c5531583df21b729cec2b7b054454d79e02e37 (patch)
tree582474986654cc455265aeaaa73b6b2d3c5bff29
parent7fe76c960a1983507eca5c8ca1f127666fe63fd9 (diff)
downloadcouchdb-b7c5531583df21b729cec2b7b054454d79e02e37.tar.gz
Fauxton: Hide new view when no docs in database
-rw-r--r--src/fauxton/app/modules/documents/routes.js15
-rw-r--r--src/fauxton/app/modules/documents/views.js38
-rw-r--r--src/fauxton/app/templates/documents/sidebar.html12
3 files changed, 31 insertions, 34 deletions
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index df8c07da4..fae5c5cd3 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -21,9 +21,6 @@ define([
],
function(app, FauxtonAPI, Documents, Databases) {
- // TODO: look at using:
- // var Documents = require("modules/documents/models_collections");
- // var Databases = require("modules/databases/module");
var DocEditorRouteObject = FauxtonAPI.RouteObject.extend({
layout: "one_pane",
@@ -203,6 +200,9 @@ function(app, FauxtonAPI, Documents, Databases) {
}
if (this.viewEditor) { this.viewEditor.remove(); }
+
+ this.listenTo(this.data.database.allDocs, 'reset', this.checkExistingDocs);
+ this.listenTo(this.data.database.allDocs, 'remove', this.checkExistingDocs);
this.toolsView = this.setView("#dashboard-upper-menu", new Documents.Views.JumpToDoc({
database: this.data.database,
@@ -360,7 +360,16 @@ function(app, FauxtonAPI, Documents, Databases) {
if (event && event.selectedTab) {
this.sidebar.setSelectedTab(event.selectedTab);
}
+ },
+
+ checkExistingDocs: function () {
+ if (this.data.database.allDocs.length > 0) {
+ this.sidebar.toggleNewView(true);
+ } else {
+ this.sidebar.toggleNewView(false);
+ }
}
+
});
var ChangesRouteObject = FauxtonAPI.RouteObject.extend({
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index 55ca40569..f822544a6 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -683,7 +683,6 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
this.insertView('#documents-pagination', this.pagination);
var docs = this.expandDocs ? this.collection : this.collection.simple();
- console.log('docs', docs);
docs.each(function(doc) {
this.rows[doc.id] = this.insertView("table.all-docs tbody", new this.nestedView({
@@ -1633,18 +1632,16 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
Views.Sidebar = FauxtonAPI.View.extend({
template: "templates/documents/sidebar",
events: {
- "click a.new#index": "newIndex",
"click button#delete-database": "deleteDatabase"
},
initialize: function(options) {
this.database = options.database;
+ this.showNewView = true;
if (options.ddocInfo) {
this.ddocID = options.ddocInfo.id;
this.currView = options.ddocInfo.currView;
}
- // this.listenTo(this.collection, "add", this.render);
- // this.listenTo(this.collection, "remove", this.render);
},
deleteDatabase: function (event) {
@@ -1674,34 +1671,14 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
changes_url: '#' + this.database.url('changes'),
permissions_url: '#' + this.database.url('app') + '/permissions',
db_url: '#' + this.database.url('index') + '?limit=100',
- index: [1,2,3],
- view: [1,2],
database: this.collection.database,
database_url: '#' + this.database.url('app'),
- docLinks: docLinks
+ docLinks: docLinks,
+ showNewView: this.showNewView
};
},
- newIndex: function(event){
- event.preventDefault();
- $.contribute(
- 'Create a new view.',
- 'app/addons/documents/views.js'
- );
- },
-
- toggleView: function(event){
- event.preventDefault();
- $.contribute(
- 'Filter data by type or view',
- 'app/addons/databases/views.js'
- );
- url = event.currentTarget.href.split('#')[1];
- app.router.navigate(url);
- },
-
buildIndexList: function(collection, selector, design){
-
_.each(_.keys(collection), function(key){
var selected = this.ddocID == "_design/"+design;
this.insertView("ul.nav." + selector, new Views.IndexItem({
@@ -1734,8 +1711,15 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
this.selectedTab = selectedTab;
this.$('li').removeClass('active');
this.$('#' + selectedTab).parent().addClass('active');
- }
+ },
+ toggleNewView: function (show) {
+ // only render if there is a change
+ if (show !== this.showNewView) {
+ this.showNewView = show;
+ this.render();
+ }
+ },
});
Views.Indexed = FauxtonAPI.View.extend({});
diff --git a/src/fauxton/app/templates/documents/sidebar.html b/src/fauxton/app/templates/documents/sidebar.html
index 881309f94..93bddc905 100644
--- a/src/fauxton/app/templates/documents/sidebar.html
+++ b/src/fauxton/app/templates/documents/sidebar.html
@@ -43,9 +43,11 @@ the License.
<li>
<a id="doc" href="#<%= database.url('app') %>/new">New doc</a>
</li>
- <li>
- <a href="#<%= database.url('app') %>/new_view">New view</a>
- </li>
+ <% if (showNewView) { %>
+ <li>
+ <a href="#<%= database.url('app') %>/new_view">New view</a>
+ </li>
+ <% } %>
</ul>
</div>
</div>
@@ -62,7 +64,9 @@ the License.
</ul>
<ul class="nav nav-list views">
<li class="nav-header">Secondary Indices</li>
- <li><a id="new-view" href="#<%= database.url('app') %>/new_view" class="new"><i class="icon-plus"></i> New</a></li>
+ <% if (showNewView) { %>
+ <li><a id="new-view" href="#<%= database.url('app') %>/new_view" class="new"><i class="icon-plus"></i> New</a></li>
+ <% } %>
</ul>
</nav>
</div>