Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 12F8B10243 for ; Thu, 13 Mar 2014 16:02:10 +0000 (UTC) Received: (qmail 87637 invoked by uid 500); 13 Mar 2014 16:02:01 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 86629 invoked by uid 500); 13 Mar 2014 16:01:56 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 86255 invoked by uid 99); 13 Mar 2014 16:01:50 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Mar 2014 16:01:50 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 97F0694481F; Thu, 13 Mar 2014 16:01:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: deathbear@apache.org To: commits@couchdb.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: couchdb commit: updated refs/heads/master to e01079c Date: Thu, 13 Mar 2014 16:01:50 +0000 (UTC) Repository: couchdb Updated Branches: refs/heads/master 4913c6e07 -> e01079ccb Config refactor- Move views into their own file and out of resources. Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/e01079cc Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/e01079cc Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/e01079cc Branch: refs/heads/master Commit: e01079ccbeb01f6fa702af239f9af8969ffbce4a Parents: 4913c6e Author: suelockwood Authored: Thu Mar 13 12:01:39 2014 -0400 Committer: suelockwood Committed: Thu Mar 13 12:01:39 2014 -0400 ---------------------------------------------------------------------- src/Makefile.am | 1 + src/fauxton/app/addons/config/base.js | 6 +- src/fauxton/app/addons/config/resources.js | 120 ---------------- src/fauxton/app/addons/config/routes.js | 7 +- .../app/addons/config/tests/resourcesSpec.js | 7 +- src/fauxton/app/addons/config/views.js | 144 +++++++++++++++++++ 6 files changed, 157 insertions(+), 128 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/e01079cc/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index a213baa..a5eea39 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 \ http://git-wip-us.apache.org/repos/asf/couchdb/blob/e01079cc/src/fauxton/app/addons/config/base.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/config/base.js b/src/fauxton/app/addons/config/base.js index 8362cb5..589cb14 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'}); }; http://git-wip-us.apache.org/repos/asf/couchdb/blob/e01079cc/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 c0e103a..ec8cc98 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; }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/e01079cc/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..519e25f 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 () { http://git-wip-us.apache.org/repos/asf/couchdb/blob/e01079cc/src/fauxton/app/addons/config/tests/resourcesSpec.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/config/tests/resourcesSpec.js b/src/fauxton/app/addons/config/tests/resourcesSpec.js index b9b8d09..c78bc85 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 }); }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/e01079cc/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..bd05652 --- /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; +});