couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [1/4] fauxton commit: updated refs/heads/master to bacf6fd
Date Mon, 08 Sep 2014 13:24:15 GMT
Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master c33249069 -> bacf6fd71


Config: allow creation of new sections

closes COUCHDB-2302


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/bacf6fd7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/bacf6fd7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/bacf6fd7

Branch: refs/heads/master
Commit: bacf6fd71daaa348030a992f1d56f5f5c5d5a1b0
Parents: 410b055
Author: Robert Kowalski <rok@kowalski.gd>
Authored: Fri Sep 5 19:46:12 2014 +0200
Committer: Robert Kowalski <rok@kowalski.gd>
Committed: Mon Sep 8 15:25:41 2014 +0200

----------------------------------------------------------------------
 app/addons/config/resources.js         |  8 +++++++-
 app/addons/config/templates/modal.html |  1 -
 app/addons/config/tests/configSpec.js  | 14 ++++++++++++++
 app/addons/config/views.js             | 26 ++++++++++++++++++--------
 4 files changed, 39 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bacf6fd7/app/addons/config/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/config/resources.js b/app/addons/config/resources.js
index 28087ed..806615c 100644
--- a/app/addons/config/resources.js
+++ b/app/addons/config/resources.js
@@ -67,7 +67,13 @@ function (app, FauxtonAPI) {
 
     findEntryInSection: function (sectionName, entry) {
       var section = _.findWhere(this.toJSON(), {"section": sectionName}),
-          options = _.findWhere(section.options, {name: entry});
+          options;
+
+      if (!section) {
+        return false;
+      }
+
+      options = _.findWhere(section.options, {name: entry});
 
       return options;
     },

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bacf6fd7/app/addons/config/templates/modal.html
----------------------------------------------------------------------
diff --git a/app/addons/config/templates/modal.html b/app/addons/config/templates/modal.html
index f32bd10..ca50db9 100644
--- a/app/addons/config/templates/modal.html
+++ b/app/addons/config/templates/modal.html
@@ -21,7 +21,6 @@ the License.
   <form id="js-add-section-form" class="form well">
     <label>Section</label>
     <input type="text" name="section" placeholder="Section" >
-    <span class="help-block">Enter an existing section name to add to it.</span>
     <input type="text" name="name" placeholder="Name">
     <br/>
     <input type="text" name="value" placeholder="Value">

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bacf6fd7/app/addons/config/tests/configSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/config/tests/configSpec.js b/app/addons/config/tests/configSpec.js
index 67301de..346ab43 100644
--- a/app/addons/config/tests/configSpec.js
+++ b/app/addons/config/tests/configSpec.js
@@ -63,6 +63,16 @@ define([
       modal.$('input[name="name"]').val("testname2");
       assert.notOk(modal.isUniqueEntryInSection(collection));
     });
+
+    it("does not send an error for a new section", function () {
+      modal.$('input[name="section"]').val("newsection");
+      modal.$('input[name="name"]').val("testname");
+      modal.$('input[name="value"]').val("testvalue");
+      var spy = sinon.spy(modal, "errorMessage");
+
+      modal.validate();
+      assert.notOk(spy.called);
+    });
   });
 
   describe("Config: Collection", function () {
@@ -70,6 +80,10 @@ define([
       assert.ok(collection.findEntryInSection("foo1", "testname"));
       assert.notOk(collection.findEntryInSection("foo1", "testname2"));
     });
+
+    it("returns false if findEntryInSection does not have the section", function () {
+      assert.notOk(collection.findEntryInSection("foo-not-exists", "testname"));
+    });
   });
 
   describe("Config: TableRow", function () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bacf6fd7/app/addons/config/views.js
----------------------------------------------------------------------
diff --git a/app/addons/config/views.js b/app/addons/config/views.js
index 87b57c9..d6d9518 100644
--- a/app/addons/config/views.js
+++ b/app/addons/config/views.js
@@ -151,23 +151,28 @@ function(app, FauxtonAPI, Config, Components) {
 
   Views.Modal = FauxtonAPI.View.extend({
     className: "modal hide fade",
+
     template:  "addons/config/templates/modal",
+
     events: {
-      "submit #js-add-section-form": "validate"
+      "submit #js-add-section-form": "submitClick"
     },
+
     initialize: function () {
       this.sourceArray = _.map(this.collection.toJSON(), function (item, key) {
         return item.section;
       });
     },
-    afterRender: function(){
+
+    afterRender: function () {
       this.sectionTypeAhead = new Components.Typeahead({
         source: this.sourceArray,
         el: 'input[name="section"]'
       });
       this.sectionTypeAhead.render();
     },
-    submitForm: function (event) {
+
+    submitForm: function () {
       var option = new Config.OptionModel({
         section: this.$('input[name="section"]').val(),
         name: this.$('input[name="name"]').val(),
@@ -193,26 +198,31 @@ function(app, FauxtonAPI, Config, Components) {
       Views.Events.trigger("newSection");
 
     },
+
     isUniqueEntryInSection: function (collection) {
       var sectionName = this.$('input[name="section"]').val(),
           entry = this.$('input[name="name"]').val();
 
       return collection.findEntryInSection(sectionName, entry);
     },
-    isSection: function(){
+
+    isSection: function () {
       var section = this.$('input[name="section"]').val();
       return _.find(this.sourceArray, function(item){ return item === section; });
     },
-    validate: function (event){
+
+    submitClick: function (event) {
       event.preventDefault();
+      this.validate();
+    },
+
+    validate: function () {
       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) {
+      if (!name) {
         this.errorMessage("Add a name");
       } else if (!value) {
         this.errorMessage("Add a value");


Mime
View raw message