summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsuelockwood <deathbear@apache.org>2014-03-13 12:01:39 -0400
committersuelockwood <deathbear@apache.org>2014-03-13 12:01:39 -0400
commite01079ccbeb01f6fa702af239f9af8969ffbce4a (patch)
tree749f9a2607a5469515c8adebcdce396eea074eae
parent4913c6e07b47755b7116aabcfec3d529f8ad32c4 (diff)
downloadcouchdb-e01079ccbeb01f6fa702af239f9af8969ffbce4a.tar.gz
Config refactor- Move views into their own file and out of resources.
-rw-r--r--src/Makefile.am1
-rw-r--r--src/fauxton/app/addons/config/base.js6
-rw-r--r--src/fauxton/app/addons/config/resources.js120
-rw-r--r--src/fauxton/app/addons/config/routes.js7
-rw-r--r--src/fauxton/app/addons/config/tests/resourcesSpec.js7
-rw-r--r--src/fauxton/app/addons/config/views.js144
6 files changed, 157 insertions, 128 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a213baa75..a5eea390d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -68,6 +68,7 @@ FAUXTON_FILES = \
fauxton/app/addons/compaction/views.js \
fauxton/app/addons/config/base.js \
fauxton/app/addons/config/resources.js \
+ fauxton/app/addons/config/views.js \
fauxton/app/addons/config/routes.js \
fauxton/app/addons/config/templates/dashboard.html \
fauxton/app/addons/config/templates/item.html \
diff --git a/src/fauxton/app/addons/config/base.js b/src/fauxton/app/addons/config/base.js
index 8362cb582..589cb1466 100644
--- a/src/fauxton/app/addons/config/base.js
+++ b/src/fauxton/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'});
};
diff --git a/src/fauxton/app/addons/config/resources.js b/src/fauxton/app/addons/config/resources.js
index c0e103a21..ec8cc98e9 100644
--- a/src/fauxton/app/addons/config/resources.js
+++ b/src/fauxton/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;
});
diff --git a/src/fauxton/app/addons/config/routes.js b/src/fauxton/app/addons/config/routes.js
index 6af81572f..519e25fb8 100644
--- a/src/fauxton/app/addons/config/routes.js
+++ b/src/fauxton/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 () {
diff --git a/src/fauxton/app/addons/config/tests/resourcesSpec.js b/src/fauxton/app/addons/config/tests/resourcesSpec.js
index b9b8d0954..c78bc85e8 100644
--- a/src/fauxton/app/addons/config/tests/resourcesSpec.js
+++ b/src/fauxton/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
});
});
diff --git a/src/fauxton/app/addons/config/views.js b/src/fauxton/app/addons/config/views.js
new file mode 100644
index 000000000..bd0565205
--- /dev/null
+++ b/src/fauxton/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;
+});