couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [23/50] [abbrv] fauxton commit: updated refs/heads/import-master to b32c617
Date Tue, 01 Apr 2014 09:14:39 GMT
Config refactor-  Move views into their own file and out of resources.


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

Branch: refs/heads/import-master
Commit: 0aac0f2ccf64a5e53ccbdc0f8aecb4a147cea29e
Parents: 2c7a8d8
Author: suelockwood <deathbear@apache.org>
Authored: Thu Mar 13 12:01:39 2014 -0400
Committer: suelockwood <deathbear@apache.org>
Committed: Thu Mar 13 12:01:39 2014 -0400

----------------------------------------------------------------------
 app/addons/config/base.js                |   6 +-
 app/addons/config/resources.js           | 120 ---------------------
 app/addons/config/routes.js              |   7 +-
 app/addons/config/tests/resourcesSpec.js |   7 +-
 app/addons/config/views.js               | 144 ++++++++++++++++++++++++++
 5 files changed, 156 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0aac0f2c/app/addons/config/base.js
----------------------------------------------------------------------
diff --git a/app/addons/config/base.js b/app/addons/config/base.js
index 8362cb5..589cb14 100644
--- a/app/addons/config/base.js
+++ b/app/addons/config/base.js
@@ -16,10 +16,12 @@ define([
   "api",
 
   // Modules
-  "addons/config/routes"
+  "addons/config/routes",
+  "addons/config/views"
 ],
 
-function(app, FauxtonAPI, Config) {
+function(app, FauxtonAPI, Config, Views) {
+	Config.Views = Views;
   Config.initialize = function() {
     FauxtonAPI.addHeaderLink({title: "Config", href: "#_config", icon:"fonticon-cog", className:
'config'});
   };

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0aac0f2c/app/addons/config/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/config/resources.js b/app/addons/config/resources.js
index c0e103a..ec8cc98 100644
--- a/app/addons/config/resources.js
+++ b/app/addons/config/resources.js
@@ -75,125 +75,5 @@ function (app, FauxtonAPI) {
     }
   });
 
-  Config.ViewItem = FauxtonAPI.View.extend({
-    tagName: "tr",
-    className: "config-item",
-    template: "addons/config/templates/item",
-
-    events: {
-      "dblclick .js-edit-value": "editValue",
-      "click .js-delete-value": "deleteValue",
-      "click .js-cancel-value": "cancelEdit",
-      "click .js-save-value": "saveAndRender",
-      "keyup .js-value-input": "processKeyEvents"
-    },
-
-    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.$(".js-show-value").addClass("js-hidden");
-      this.$(".js-edit-value-form").removeClass("js-hidden");
-      this.$(".js-value-input").focus();
-    },
-
-    processKeyEvents: function (event) {
-      // Enter key
-      if (event.keyCode === 13) {
-        return this.saveAndRender();
-      }
-      // Esc key
-      if (event.keyCode === 27) {
-        return this.discardValue();
-      }
-    },
-
-
-    discardValue: function (event) {
-      this.$(".js-edit-value-form").addClass("js-hidden");
-      this.$(".js-show-value").removeClass("js-hidden");
-    },
-
-    cancelEdit: function (event) {
-      this.discardValue();
-    },
-
-    serialize: function () {
-      return {option: this.model.toJSON()};
-    },
-
-    saveAndRender: function () {
-      this.model.save({value: this.$(".js-value-input").val()});
-      this.render();
-    }
-
-  });
-
-  Config.View = FauxtonAPI.View.extend({
-    template: "addons/config/templates/dashboard",
-
-    events: {
-      "click #add-section": "addSection",
-      "submit #add-section-form": "submitForm"
-    },
-
-    submitForm: function (event) {
-      event.preventDefault();
-      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.$("#add-section-modal").modal('hide');
-      this.render();
-    },
-
-    addSection: function (event) {
-      event.preventDefault();
-      this.$("#add-section-modal").modal({show:true});
-    },
-
-    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);
-    },
-
-    establish: function() {
-      return [this.collection.fetch()];
-    }
-  });
-
   return Config;
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0aac0f2c/app/addons/config/routes.js
----------------------------------------------------------------------
diff --git a/app/addons/config/routes.js b/app/addons/config/routes.js
index 6af8157..519e25f 100644
--- a/app/addons/config/routes.js
+++ b/app/addons/config/routes.js
@@ -16,10 +16,11 @@ define([
        "api",
 
        // Modules
-       "addons/config/resources"
+       "addons/config/resources",
+       "addons/config/views"
 ],
 
-function(app, FauxtonAPI, Config) {
+function(app, FauxtonAPI, Config, Views) {
 
   var ConfigRouteObject = FauxtonAPI.RouteObject.extend({
     layout: "one_pane",
@@ -45,7 +46,7 @@ function(app, FauxtonAPI, Config) {
     },
 
     config: function () {
-      this.setView("#dashboard-content", new Config.View({collection: this.configs}));
+      this.setView("#dashboard-content", new Views.Table({collection: this.configs}));
     },
 
     establish: function () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0aac0f2c/app/addons/config/tests/resourcesSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/config/tests/resourcesSpec.js b/app/addons/config/tests/resourcesSpec.js
index b9b8d09..c78bc85 100644
--- a/app/addons/config/tests/resourcesSpec.js
+++ b/app/addons/config/tests/resourcesSpec.js
@@ -12,12 +12,13 @@
 define([
       'api',
       'addons/config/resources',
+      'addons/config/views',
       'testUtils'
-], function (FauxtonAPI, Resources, testUtils) {
+], function (FauxtonAPI, Resources, Views, testUtils) {
   var assert = testUtils.assert,
       ViewSandbox = testUtils.ViewSandbox;
 
-  describe("Config: ViewItem", function () {
+  describe("Config: TableRow", function () {
     var tabMenu, optionModel;
 
     beforeEach(function () {
@@ -26,7 +27,7 @@ define([
         name: "bar"
       });
 
-      tabMenu = new Resources.ViewItem({
+      tabMenu = new Views.TableRow({
         model: optionModel
       });
     });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0aac0f2c/app/addons/config/views.js
----------------------------------------------------------------------
diff --git a/app/addons/config/views.js b/app/addons/config/views.js
new file mode 100644
index 0000000..bd05652
--- /dev/null
+++ b/app/addons/config/views.js
@@ -0,0 +1,144 @@
+ // 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.TableRow = FauxtonAPI.View.extend({
+    tagName: "tr",
+    className: "config-item",
+    template: "addons/config/templates/item",
+
+    events: {
+      "dblclick .js-edit-value": "editValue",
+      "click .js-delete-value": "deleteValue",
+      "click .js-cancel-value": "cancelEdit",
+      "click .js-save-value": "saveAndRender",
+      "keyup .js-value-input": "processKeyEvents"
+    },
+
+    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.$(".js-show-value").addClass("js-hidden");
+      this.$(".js-edit-value-form").removeClass("js-hidden");
+      this.$(".js-value-input").focus();
+    },
+
+    processKeyEvents: function (event) {
+      // Enter key
+      if (event.keyCode === 13) {
+        return this.saveAndRender();
+      }
+      // Esc key
+      if (event.keyCode === 27) {
+        return this.discardValue();
+      }
+    },
+
+
+    discardValue: function (event) {
+      this.$(".js-edit-value-form").addClass("js-hidden");
+      this.$(".js-show-value").removeClass("js-hidden");
+    },
+
+    cancelEdit: function (event) {
+      this.discardValue();
+    },
+
+    serialize: function () {
+      return {option: this.model.toJSON()};
+    },
+
+    saveAndRender: function () {
+      this.model.save({value: this.$(".js-value-input").val()});
+      this.render();
+    }
+
+  });
+
+  Views.Table = FauxtonAPI.View.extend({
+    template: "addons/config/templates/dashboard",
+
+    events: {
+      "click #add-section": "addSection",
+      "submit #add-section-form": "submitForm"
+    },
+
+    submitForm: function (event) {
+      event.preventDefault();
+      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.$("#add-section-modal").modal('hide');
+      this.render();
+    },
+
+    addSection: function (event) {
+      event.preventDefault();
+      this.$("#add-section-modal").modal({show:true});
+    },
+
+    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);
+    },
+
+    establish: function() {
+      return [this.collection.fetch()];
+    }
+  });
+
+  return Views;
+});


Mime
View raw message