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 A355E1019E for ; Thu, 20 Mar 2014 10:21:40 +0000 (UTC) Received: (qmail 69967 invoked by uid 500); 20 Mar 2014 10:21:39 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 69924 invoked by uid 500); 20 Mar 2014 10:21:37 -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 68655 invoked by uid 99); 20 Mar 2014 10:21:26 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Mar 2014 10:21:26 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 15E8E985B7A; Thu, 20 Mar 2014 10:21:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: garren@apache.org To: commits@couchdb.apache.org Date: Thu, 20 Mar 2014 10:21:26 -0000 Message-Id: <2ca6d22f3db646b6a4a83e0434fce387@git.apache.org> In-Reply-To: <8ac32f2b378f4c7dbad778ac36a8f1f3@git.apache.org> References: <8ac32f2b378f4c7dbad778ac36a8f1f3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [02/26] couchdb commit: updated refs/heads/Query-Options-UI to cf93bbf Added Autocomplete for config sections Form Validation Updating selectors with the js-prefix Added modal to makefile. Removed debugging alert. Cleaned up error messaging to be consistent. Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/33b6e350 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/33b6e350 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/33b6e350 Branch: refs/heads/Query-Options-UI Commit: 33b6e3509880ac271be26d75e1094e2296c139f6 Parents: a355997 Author: suelockwood Authored: Fri Mar 14 11:04:26 2014 -0400 Committer: suelockwood Committed: Fri Mar 14 11:08:50 2014 -0400 ---------------------------------------------------------------------- src/Makefile.am | 2 + .../app/addons/config/assets/less/config.less | 2 +- src/fauxton/app/addons/config/resources.js | 4 + src/fauxton/app/addons/config/routes.js | 1 - .../app/addons/config/templates/dashboard.html | 29 +--- .../app/addons/config/templates/modal.html | 33 +++++ src/fauxton/app/addons/config/views.js | 136 +++++++++++++++---- src/fauxton/app/addons/fauxton/components.js | 53 ++++---- 8 files changed, 179 insertions(+), 81 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/33b6e350/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index a5eea39..89a6afd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -70,6 +70,8 @@ FAUXTON_FILES = \ fauxton/app/addons/config/resources.js \ fauxton/app/addons/config/views.js \ fauxton/app/addons/config/routes.js \ + fauxton/app/addons/config/views.js \ + fauxton/app/addons/config/templates/modal.html \ fauxton/app/addons/config/templates/dashboard.html \ fauxton/app/addons/config/templates/item.html \ fauxton/app/addons/config/tests/resourcesSpec.js \ http://git-wip-us.apache.org/repos/asf/couchdb/blob/33b6e350/src/fauxton/app/addons/config/assets/less/config.less ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/config/assets/less/config.less b/src/fauxton/app/addons/config/assets/less/config.less index 44311de..2807708 100644 --- a/src/fauxton/app/addons/config/assets/less/config.less +++ b/src/fauxton/app/addons/config/assets/less/config.less @@ -27,7 +27,7 @@ button {width: 7%;} } -#add-section-modal { +#add-section-modal .modal { width: 400px; } http://git-wip-us.apache.org/repos/asf/couchdb/blob/33b6e350/src/fauxton/app/addons/config/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/config/resources.js b/src/fauxton/app/addons/config/resources.js index ec8cc98..317e355 100644 --- a/src/fauxton/app/addons/config/resources.js +++ b/src/fauxton/app/addons/config/resources.js @@ -13,12 +13,14 @@ define([ "app", "api" + ], function (app, FauxtonAPI) { var Config = FauxtonAPI.addon(); + Config.Model = Backbone.Model.extend({}); Config.OptionModel = Backbone.Model.extend({ documentation: "config", @@ -75,5 +77,7 @@ function (app, FauxtonAPI) { } }); + + return Config; }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/33b6e350/src/fauxton/app/addons/config/routes.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/config/routes.js b/src/fauxton/app/addons/config/routes.js index 519e25f..affb453 100644 --- a/src/fauxton/app/addons/config/routes.js +++ b/src/fauxton/app/addons/config/routes.js @@ -12,7 +12,6 @@ define([ "app", - "api", // Modules http://git-wip-us.apache.org/repos/asf/couchdb/blob/33b6e350/src/fauxton/app/addons/config/templates/dashboard.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/config/templates/dashboard.html b/src/fauxton/app/addons/config/templates/dashboard.html index c14402c..37ae634 100644 --- a/src/fauxton/app/addons/config/templates/dashboard.html +++ b/src/fauxton/app/addons/config/templates/dashboard.html @@ -13,10 +13,10 @@ the License. -->
- +
@@ -28,23 +28,4 @@ the License.
- +
http://git-wip-us.apache.org/repos/asf/couchdb/blob/33b6e350/src/fauxton/app/addons/config/templates/modal.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/config/templates/modal.html b/src/fauxton/app/addons/config/templates/modal.html new file mode 100644 index 0000000..f32bd10 --- /dev/null +++ b/src/fauxton/app/addons/config/templates/modal.html @@ -0,0 +1,33 @@ + + + + http://git-wip-us.apache.org/repos/asf/couchdb/blob/33b6e350/src/fauxton/app/addons/config/views.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/config/views.js b/src/fauxton/app/addons/config/views.js index bd05652..0468cd1 100644 --- a/src/fauxton/app/addons/config/views.js +++ b/src/fauxton/app/addons/config/views.js @@ -1,4 +1,4 @@ - // Licensed under the Apache License, Version 2.0 (the "License"); you may not +// 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 // @@ -14,11 +14,13 @@ define([ "app", "api", "addons/config/resources", + "addons/fauxton/components" ], +function(app, FauxtonAPI, Config, Components) { + var Views ={}, + Events = {}; -function (app, FauxtonAPI, Config) { - - var Views = {}; + Views.Events = _.extend(Events, Backbone.Events); Views.TableRow = FauxtonAPI.View.extend({ tagName: "tr", @@ -59,7 +61,6 @@ function (app, FauxtonAPI, Config) { } }, - discardValue: function (event) { this.$(".js-edit-value-form").addClass("js-hidden"); this.$(".js-show-value").removeClass("js-hidden"); @@ -84,12 +85,63 @@ function (app, FauxtonAPI, Config) { template: "addons/config/templates/dashboard", events: { - "click #add-section": "addSection", - "submit #add-section-form": "submitForm" + "click #js-add-section": "addSection" }, - submitForm: function (event) { + initialize: function(){ + this.listenTo(Views.Events, "newSection", this.render); + }, + + addSection: function (event) { event.preventDefault(); + this.modal.show(); + }, + + beforeRender: function() { + this.modal = this.insertView("#add-section-modal", new Views.Modal({ + collection: this.collection + })); + + this.modal.render(); + + this.collection.each(function(config) { + _.each(config.get("options"), function (option, index) { + this.insertView("table.config tbody", new Views.TableRow({ + model: new Config.OptionModel({ + section: config.get("section"), + name: option.name, + value: option.value, + index: index + }) + })); + }, this); + }, this); + }, + + establish: function() { + return [this.collection.fetch()]; + } + }); + + Views.Modal = FauxtonAPI.View.extend({ + className: "modal hide fade", + template: "addons/config/templates/modal", + events: { + "submit #js-add-section-form": "validate" + }, + initialize: function(){ + this.sourceArray = _.map(this.collection.toJSON(), function(item, key){ + return item.section; + }); + }, + afterRender: function(){ + this.sectionTypeAhead = new Components.Typeahead({ + source: this.sourceArray, + el: 'input[name="section"]' + }); + this.sectionTypeAhead.render(); + }, + submitForm: function (event) { var option = new Config.OptionModel({ section: this.$('input[name="section"]').val(), name: this.$('input[name="name"]').val(), @@ -111,34 +163,58 @@ function (app, FauxtonAPI, Config) { }); } - this.$("#add-section-modal").modal('hide'); - this.render(); - }, + this.hide(); + Views.Events.trigger("newSection"); - addSection: function (event) { + }, + isNew: function(collection){ + var sectionName = this.$('input[name="section"]').val(), + name = this.$('input[name="name"]').val(); + var section = _.findWhere(collection.toJSON(), {"section":sectionName}); + var options = _.findWhere(section.options, {name: name}); + + return options; + }, + isSection: function(){ + var section = this.$('input[name="section"]').val(); + return _.find(this.sourceArray, function(item){ return item === section; }); + }, + validate: function (event){ event.preventDefault(); - this.$("#add-section-modal").modal({show:true}); + var section = this.$('input[name="section"]').val(), + name = this.$('input[name="name"]').val(), + value = this.$('input[name="value"]').val(), + collection = this.collection; + + if(!this.isSection()){ + this.errorMessage("You need to use an existing section"); + } else if (!name) { + this.errorMessage("Add a name"); + } else if (!value) { + this.errorMessage("Add a value"); + } else if (this.isNew(collection)){ + this.errorMessage("Must have a unique name"); + } else { + this.submitForm(); + } }, - - beforeRender: function() { - this.collection.each(function(config) { - _.each(config.get("options"), function (option, index) { - this.insertView("table.config tbody", new Views.TableRow({ - model: new Config.OptionModel({ - section: config.get("section"), - name: option.name, - value: option.value, - index: index - }) - })); - }, this); - }, this); + errorMessage: function(msg){ + this.error = FauxtonAPI.addNotification({ + msg: msg, + type: "error", + clear: true, + selector: ".js-form-error-config" + }); }, - - establish: function() { - return [this.collection.fetch()]; + show: function(){ + this.$el.modal({show:true}); + }, + hide: function(){ + this.$el.modal('hide'); } + }); return Views; + }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/33b6e350/src/fauxton/app/addons/fauxton/components.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/fauxton/components.js b/src/fauxton/app/addons/fauxton/components.js index 96af169..25f623c 100644 --- a/src/fauxton/app/addons/fauxton/components.js +++ b/src/fauxton/app/addons/fauxton/components.js @@ -210,32 +210,7 @@ function(app, FauxtonAPI, ace, spin) { }); - //TODO allow more of the typeahead options. - //Current this just does what we need but we - //need to support the other typeahead options. - Components.Typeahead = FauxtonAPI.View.extend({ - - initialize: function (options) { - this.source = options.source; - _.bindAll(this); - }, - afterRender: function () { - var onUpdate = this.onUpdate; - - this.$el.typeahead({ - source: this.source, - updater: function (item) { - if (onUpdate) { - onUpdate(item); - } - - return item; - } - }); - } - - }); Components.ModalView = FauxtonAPI.View.extend({ @@ -279,6 +254,34 @@ function(app, FauxtonAPI, ace, spin) { } }); + //TODO allow more of the typeahead options. + //Current this just does what we need but we + //need to support the other typeahead options. + Components.Typeahead = FauxtonAPI.View.extend({ + + initialize: function (options) { + this.source = options.source; + this.onUpdate = options.onUpdate; + _.bindAll(this); + }, + + afterRender: function () { + var onUpdate = this.onUpdate; + + this.$el.typeahead({ + source: this.source, + updater: function (item) { + if (onUpdate) { + onUpdate(item); + } + + return item; + } + }); + } + + }); + Components.DbSearchTypeahead = Components.Typeahead.extend({ initialize: function (options) { this.dbLimit = options.dbLimit || 30;