couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From deathb...@apache.org
Subject couchdb commit: updated refs/heads/2128-autocomplete-section-name to f62790d
Date Fri, 28 Feb 2014 17:45:30 GMT
Repository: couchdb
Updated Branches:
  refs/heads/2128-autocomplete-section-name [created] f62790d8c


Added autocomplete and form validation to the add section modal.


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

Branch: refs/heads/2128-autocomplete-section-name
Commit: f62790d8c26aa0963b7defbe9f4a1494f2bf8939
Parents: 929b3a0
Author: suelockwood <deathbear@apache.org>
Authored: Fri Feb 28 11:53:04 2014 -0500
Committer: suelockwood <deathbear@apache.org>
Committed: Fri Feb 28 12:44:19 2014 -0500

----------------------------------------------------------------------
 .../app/addons/config/assets/less/config.less   |   2 +-
 src/fauxton/app/addons/config/resources.js      | 126 +++++++++++++++----
 .../app/addons/config/templates/dashboard.html  |  29 +----
 .../app/addons/config/templates/modal.html      |  33 +++++
 src/fauxton/app/addons/fauxton/components.js    |  53 ++++----
 5 files changed, 166 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/f62790d8/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 88bbc66..c16b45a 100644
--- a/src/fauxton/app/addons/config/assets/less/config.less
+++ b/src/fauxton/app/addons/config/assets/less/config.less
@@ -26,7 +26,7 @@
   }
 }
 
-#add-section-modal {
+#add-section-modal .modal {
   width: 400px;
 }
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/f62790d8/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 227e80d..637177c 100644
--- a/src/fauxton/app/addons/config/resources.js
+++ b/src/fauxton/app/addons/config/resources.js
@@ -12,12 +12,15 @@
 
 define([
   "app",
-  "api"
+  "api",
+  "addons/fauxton/components"
 ],
 
-function (app, FauxtonAPI) {
+function (app, FauxtonAPI, Components) {
 
   var Config = FauxtonAPI.addon();
+  var Events = {};
+  Config.Events = _.extend(Events, Backbone.Events);
 
   Config.Model = Backbone.Model.extend({});
   Config.OptionModel = Backbone.Model.extend({
@@ -121,12 +124,62 @@ function (app, FauxtonAPI) {
     template: "addons/config/templates/dashboard",
 
     events: {
-      "click #add-section": "addSection",
-      "submit #add-section-form": "submitForm"
+      "click #add-section": "addSection"
     },
 
-    submitForm: function (event) {
+    initialize: function(){
+      Config.Events.on("newSection", this.render);
+    },
+
+    addSection: function (event) {
       event.preventDefault();
+      this.modal.show();
+    },
+
+    beforeRender: function() {
+      this.modal = this.insertView("#add-section-modal", new Config.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 Config.ViewItem({
+            model: new Config.OptionModel({
+              section: config.get("section"),
+              name: option.name,
+              value: option.value,
+              index: index
+            })
+          }));
+        }, this);
+      }, this);
+    },
+
+    establish: function() {
+      return [this.collection.fetch()];
+    }
+  });
+
+  Config.Modal = FauxtonAPI.View.extend({
+    className: "modal hide fade",
+    template:  "addons/config/templates/modal",
+    events: {
+      "submit #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(),
@@ -148,33 +201,52 @@ function (app, FauxtonAPI) {
         });
       }
 
-      this.$("#add-section-modal").modal('hide');
-      this.render();
-    },
+      this.hide();
+      Config.Events.trigger("newSection");
 
-    addSection: function (event) {
+    },
+    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();
+
+      if(!this.isSection()){
+        var notification = FauxtonAPI.addNotification({
+          msg: "You need to use an existing section.",
+          type: "error",
+          clear: true,
+          selector: ".form-error-config"
+        }); 
+      } else if (!name) {
+        var notification = FauxtonAPI.addNotification({
+          msg: "Add a name.",
+          type: "error",
+          clear: true,
+          selector: ".form-error-config"
+        });
+      } else if (!value) {
+        var notification = FauxtonAPI.addNotification({
+          msg: "Add a value",
+          type: "error",
+          clear: true,
+          selector: ".form-error-config"
+        });
+      } else {
+        this.submitForm();
+      }
     },
-
-    beforeRender: function() {
-      this.collection.each(function(config) {
-        _.each(config.get("options"), function (option, index) {
-          this.insertView("table.config tbody", new Config.ViewItem({
-            model: new Config.OptionModel({
-              section: config.get("section"),
-              name: option.name,
-              value: option.value,
-              index: index
-            })
-          }));
-        }, this);
-      }, this);
+    show: function(){
+      $(this.el).modal({show:true});
     },
-
-    establish: function() {
-      return [this.collection.fetch()];
+    hide: function(){
+      $(this.el).modal('hide');
     }
+
   });
 
   return Config;

http://git-wip-us.apache.org/repos/asf/couchdb/blob/f62790d8/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 b7dbc55..e569995 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.
 -->
 
 <div class="row">
-    <button id="add-section" href="#" class="btn btn-primary pull-right">
-      <i class="icon icon-plus icon-white"> </i>
-      Add Section
-    </button>
+  <button id="add-section" href="#" class="btn btn-primary pull-right">
+    <i class="icon icon-plus icon-white"> </i>
+    Add Section
+  </button>
 </div>
 <table class="config table table-striped table-bordered">
   <thead>
@@ -28,23 +28,4 @@ the License.
   <tbody>
   </tbody>
 </table>
-<div id="add-section-modal" class="modal hide fade">
-  <div class="modal-header">
-    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
-    <h3>Create Config Option</h3>
-  </div>
-  <div class="modal-body">
-    <form id="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">
-      <div class="modal-footer">
-        <button type="button" class="btn" data-dismiss="modal">Cancel</button>
-        <button type="submit" class="btn btn-primary"> Save </button>
-      </div>
-    </form>
-  </div>
-</div>
+<div id="add-section-modal"></div>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/f62790d8/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..2ba53ca
--- /dev/null
+++ b/src/fauxton/app/addons/config/templates/modal.html
@@ -0,0 +1,33 @@
+  <!--
+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.
+-->
+
+<div class="modal-header">
+  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+  <h3>Create Config Option</h3>
+</div>
+<div class="modal-body">
+  <div class="form-error-config"></div>
+  <form id="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">
+    <div class="modal-footer">
+      <button type="button" class="btn" data-dismiss="modal">Cancel</button>
+      <button type="submit" class="btn btn-primary"> Save </button>
+    </div>
+  </form>
+</div>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/f62790d8/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 71d78b1..b15e429 100644
--- a/src/fauxton/app/addons/fauxton/components.js
+++ b/src/fauxton/app/addons/fauxton/components.js
@@ -133,32 +133,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({
 
@@ -202,6 +177,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;


Mime
View raw message