You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by de...@apache.org on 2014/03/05 21:51:57 UTC

[2/2] couchdb commit: updated refs/heads/2128-autocomplete-section-name to 9482eed

Split Config Views out into their own file seperate from resources.


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

Branch: refs/heads/2128-autocomplete-section-name
Commit: 9482eed3b6612067ec165e9928f61abc20c93c9e
Parents: 324564b
Author: suelockwood <de...@apache.org>
Authored: Wed Mar 5 15:51:52 2014 -0500
Committer: suelockwood <de...@apache.org>
Committed: Wed Mar 5 15:51:52 2014 -0500

----------------------------------------------------------------------
 src/Makefile.am                            |   1 +
 src/fauxton/app/addons/config/resources.js | 180 +--------------------
 src/fauxton/app/addons/config/routes.js    |  10 +-
 src/fauxton/app/addons/config/views.js     | 205 ++++++++++++++++++++++++
 4 files changed, 211 insertions(+), 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/9482eed3/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 59aa6bf..df64e9c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,6 +69,7 @@ FAUXTON_FILES = \
     fauxton/app/addons/config/base.js \
     fauxton/app/addons/config/resources.js \
     fauxton/app/addons/config/routes.js \
+    fauxton/app/addons/config/views.js \
     fauxton/app/addons/config/templates/dashboard.html \
     fauxton/app/addons/config/templates/item.html \
     fauxton/app/addons/contribute/base.js \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/9482eed3/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 3f65c5d..275867d 100644
--- a/src/fauxton/app/addons/config/resources.js
+++ b/src/fauxton/app/addons/config/resources.js
@@ -78,185 +78,7 @@ function (app, FauxtonAPI, Components) {
     }
   });
 
-  Config.ViewItem = FauxtonAPI.View.extend({
-    tagName: "tr",
-    className: "config-item",
-    template: "addons/config/templates/item",
-
-    events: {
-      "click .edit-button": "editValue",
-      "click #delete-value": "deleteValue",
-      "click #cancel-value": "cancelEdit",
-      "click #save-value": "saveValue"
-    },
-
-    deleteValue: function (event) {
-      var result = confirm("Are you sure you want to delete this configuration value?");
-
-      if (!result) { return; }
-
-      this.model.destroy();
-      this.remove();
-    },
-
-    editValue: function (event) {
-      this.$("#show-value").hide();
-      this.$("#edit-value-form").show();
-    },
-
-    saveValue: function (event) {
-      this.model.save({value: this.$(".value-input").val()});
-      this.render();
-    },
-
-    cancelEdit: function (event) {
-      this.$("#edit-value-form").hide();
-      this.$("#show-value").show();
-    },
-
-    serialize: function () {
-      return {option: this.model.toJSON()};
-    }
-
-  });
-
-  Config.View = FauxtonAPI.View.extend({
-    template: "addons/config/templates/dashboard",
-
-    events: {
-      "click #add-section": "addSection"
-    },
-
-    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(),
-        value: this.$('input[name="value"]').val()
-      });
-
-      option.save();
-
-      var section = this.collection.find(function (section) {
-        return section.get("section") === option.get("section");
-      });
-
-      if (section) {
-        section.get("options").push(option.attributes);
-      } else {
-        this.collection.add({
-          section: option.get("section"),
-          options: [option.attributes]
-        });
-      }
-
-      this.hide();
-      Config.Events.trigger("newSection");
-
-    },
-    isNew: function(){
-      var section = this.$('input[name="section"]').val(),
-          name = this.$('input[name="name"]').val(),
-          sectionFilter = _.find(this.sourceArray, function(item){ return item === section; });
-          console.log(sectionFilter);
-          return false;
-    },
-    isSection: function(){
-      var section = this.$('input[name="section"]').val();
-      return _.find(this.sourceArray, function(item){ return item === section; });
-    },
-    validate: function (event){
-      event.preventDefault();
-      var section = this.$('input[name="section"]').val(),
-          name = this.$('input[name="name"]').val(),
-          value = this.$('input[name="value"]').val();
-
-      if(!this.isSection()){
-        FauxtonAPI.addNotification({
-          msg: "You need to use an existing section.",
-          type: "error",
-          clear: true,
-          selector: ".form-error-config"
-        }); 
-      } else if (!name) {
-        FauxtonAPI.addNotification({
-          msg: "Add a name.",
-          type: "error",
-          clear: true,
-          selector: ".form-error-config"
-        });
-      } else if (!value) {
-        FauxtonAPI.addNotification({
-          msg: "Add a value",
-          type: "error",
-          clear: true,
-          selector: ".form-error-config"
-        });
-      } else if (this.isNew()){
-        console.log("nooo");
-      } else {
-        this.submitForm();
-      }
-    },
-    show: function(){
-      $(this.el).modal({show:true});
-    },
-    hide: function(){
-      $(this.el).modal('hide');
-    }
-
-  });
+ 
 
   return Config;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/9482eed3/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 6af8157..cb3f287 100644
--- a/src/fauxton/app/addons/config/routes.js
+++ b/src/fauxton/app/addons/config/routes.js
@@ -12,14 +12,12 @@
 
 define([
        "app",
-
        "api",
-
-       // Modules
-       "addons/config/resources"
+       "addons/config/resources",
+       "addons/config/views"
 ],
 
-function(app, FauxtonAPI, Config) {
+function(app, FauxtonAPI, Config, View) {
 
   var ConfigRouteObject = FauxtonAPI.RouteObject.extend({
     layout: "one_pane",
@@ -45,7 +43,7 @@ function(app, FauxtonAPI, Config) {
     },
 
     config: function () {
-      this.setView("#dashboard-content", new Config.View({collection: this.configs}));
+      this.setView("#dashboard-content", new View.Table({collection: this.configs}));
     },
 
     establish: function () {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/9482eed3/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
new file mode 100644
index 0000000..a7d0499
--- /dev/null
+++ b/src/fauxton/app/addons/config/views.js
@@ -0,0 +1,205 @@
+// 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.
+
+define([
+  "app",
+  "api",
+  "addons/config/resources"
+
+],
+function(app, FauxtonAPI, Config) {
+  var Views ={};
+
+
+  Views.ViewItem = FauxtonAPI.View.extend({
+    tagName: "tr",
+    className: "config-item",
+    template: "addons/config/templates/item",
+
+    events: {
+      "click .edit-button": "editValue",
+      "click #delete-value": "deleteValue",
+      "click #cancel-value": "cancelEdit",
+      "click #save-value": "saveValue"
+    },
+
+    deleteValue: function (event) {
+      var result = confirm("Are you sure you want to delete this configuration value?");
+
+      if (!result) { return; }
+
+      this.model.destroy();
+      this.remove();
+    },
+
+    editValue: function (event) {
+      this.$("#show-value").hide();
+      this.$("#edit-value-form").show();
+    },
+
+    saveValue: function (event) {
+      this.model.save({value: this.$(".value-input").val()});
+      this.render();
+    },
+
+    cancelEdit: function (event) {
+      this.$("#edit-value-form").hide();
+      this.$("#show-value").show();
+    },
+
+    serialize: function () {
+      return {option: this.model.toJSON()};
+    }
+
+  });
+
+  Views.Table = FauxtonAPI.View.extend({
+    template: "addons/config/templates/dashboard",
+
+    events: {
+      "click #add-section": "addSection"
+    },
+
+    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 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.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()];
+    }
+  });
+
+  Views.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(),
+        value: this.$('input[name="value"]').val()
+      });
+
+      option.save();
+
+      var section = this.collection.find(function (section) {
+        return section.get("section") === option.get("section");
+      });
+
+      if (section) {
+        section.get("options").push(option.attributes);
+      } else {
+        this.collection.add({
+          section: option.get("section"),
+          options: [option.attributes]
+        });
+      }
+
+      this.hide();
+      Config.Events.trigger("newSection");
+
+    },
+    isNew: function(){
+      var section = this.$('input[name="section"]').val(),
+          name = this.$('input[name="name"]').val(),
+          sectionFilter = _.find(this.sourceArray, function(item){ return item === section; });
+          console.log(sectionFilter);
+          return false;
+    },
+    isSection: function(){
+      var section = this.$('input[name="section"]').val();
+      return _.find(this.sourceArray, function(item){ return item === section; });
+    },
+    validate: function (event){
+      event.preventDefault();
+      var section = this.$('input[name="section"]').val(),
+          name = this.$('input[name="name"]').val(),
+          value = this.$('input[name="value"]').val();
+
+      if(!this.isSection()){
+        FauxtonAPI.addNotification({
+          msg: "You need to use an existing section.",
+          type: "error",
+          clear: true,
+          selector: ".form-error-config"
+        }); 
+      } else if (!name) {
+        FauxtonAPI.addNotification({
+          msg: "Add a name.",
+          type: "error",
+          clear: true,
+          selector: ".form-error-config"
+        });
+      } else if (!value) {
+        FauxtonAPI.addNotification({
+          msg: "Add a value",
+          type: "error",
+          clear: true,
+          selector: ".form-error-config"
+        });
+      } else if (this.isNew()){
+        console.log("nooo");
+      } else {
+        this.submitForm();
+      }
+    },
+    show: function(){
+      $(this.el).modal({show:true});
+    },
+    hide: function(){
+      $(this.el).modal('hide');
+    }
+
+  });
+
+  return Views;
+
+});