summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2013-12-04 10:33:57 +0200
committerGarren Smith <garren.smith@gmail.com>2013-12-04 16:31:26 +0200
commit844ddfa3c4ae1695327de17f9816b28d19fdceb7 (patch)
treee185946e5391219efa4a70dbf2831ee891b8da05
parent9c942b509037c94bd88d6d6ff43fe877afd3365c (diff)
downloadcouchdb-844ddfa3c4ae1695327de17f9816b28d19fdceb7.tar.gz
Fauxton: Fix search button
-rw-r--r--src/fauxton/Gruntfile.js5
-rw-r--r--src/fauxton/app/modules/databases/views.js20
-rw-r--r--src/fauxton/app/modules/fauxton/components.js12
3 files changed, 29 insertions, 8 deletions
diff --git a/src/fauxton/Gruntfile.js b/src/fauxton/Gruntfile.js
index 42e5e17aa..6a8a73a5b 100644
--- a/src/fauxton/Gruntfile.js
+++ b/src/fauxton/Gruntfile.js
@@ -142,12 +142,13 @@ module.exports = function(grunt) {
// The jshint option for scripturl is set to lax, because the anchor
// override inside main.js needs to test for them so as to not accidentally
- // route.
+ // route. Settings expr true so we can do `migtBeNullObject && mightBeNullObject.coolFunction()`
jshint: {
all: ['app/**/*.js', 'Gruntfile.js', "test/core/*.js"],
options: {
scripturl: true,
- evil: true
+ evil: true,
+ expr: true
}
},
diff --git a/src/fauxton/app/modules/databases/views.js b/src/fauxton/app/modules/databases/views.js
index 0f67d365e..9a197a9bb 100644
--- a/src/fauxton/app/modules/databases/views.js
+++ b/src/fauxton/app/modules/databases/views.js
@@ -38,7 +38,8 @@ function(app, Components, FauxtonAPI) {
template: "templates/databases/list",
events: {
"click button.all": "selectAll",
- "submit form.database-search": "switchDatabase"
+ "submit form.database-search": "switchDatabase",
+ "click label.fonticon-search": "switchDatabase"
},
initialize: function(options) {
@@ -52,10 +53,15 @@ function(app, Components, FauxtonAPI) {
};
},
- switchDatabase: function(event) {
- event.preventDefault();
+ switchDatabase: function(event, selectedName) {
+ event && event.preventDefault();
+
var dbname = this.$el.find("input.search-query").val();
+ if (selectedName) {
+ dbname = selectedName;
+ }
+
if (dbname) {
// TODO: switch to using a model, or Databases.databaseUrl()
// Neither of which are in scope right now
@@ -77,7 +83,6 @@ function(app, Components, FauxtonAPI) {
collection: this.collection
}));
-
_.each(this.paginated(), function(database) {
this.insertView("table.databases tbody", new Views.Item({
model: database
@@ -99,9 +104,14 @@ function(app, Components, FauxtonAPI) {
},
afterRender: function() {
+ var that = this;
this.dbSearchTypeahead = new Components.DbSearchTypeahead({
dbLimit: this.dbLimit,
- el: "input.search-query"
+ el: "input.search-query",
+ onUpdate: function (item) {
+ console.log('boom', item);
+ that.switchDatabase(null, item);
+ }
});
this.dbSearchTypeahead.render();
diff --git a/src/fauxton/app/modules/fauxton/components.js b/src/fauxton/app/modules/fauxton/components.js
index 0443573dd..bcc9226e8 100644
--- a/src/fauxton/app/modules/fauxton/components.js
+++ b/src/fauxton/app/modules/fauxton/components.js
@@ -116,8 +116,17 @@ function(app, FauxtonAPI, ace) {
},
afterRender: function () {
+ var onUpdate = this.onUpdate;
+
this.$el.typeahead({
- source: this.source
+ source: this.source,
+ updater: function (item) {
+ if (onUpdate) {
+ onUpdate(item);
+ }
+
+ return item;
+ }
});
}
@@ -127,6 +136,7 @@ function(app, FauxtonAPI, ace) {
Components.DbSearchTypeahead = Components.Typeahead.extend({
initialize: function (options) {
this.dbLimit = options.dbLimit || 30;
+ this.onUpdate = options.onUpdate;
_.bindAll(this);
},
source: function(query, process) {