Fauxton: focus input on doubleclick Fauxton: hide field if Esc if pressed Fauxton: fix small typo Fauxton: save value, when I press Enter
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/e671933c Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/e671933c Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/e671933c Branch: refs/heads/2041-update-ibrowse Commit: e671933c2f4d83735ce918d00d8dfe5c1130f727 Parents: f3ca960 Author: Robert Kowalski <[email protected]> Authored: Wed Mar 12 22:49:35 2014 +0100 Committer: suelockwood <[email protected]> Committed: Thu Mar 13 10:43:23 2014 -0400 ---------------------------------------------------------------------- src/fauxton/app/addons/config/resources.js | 31 ++++++++++++++++---- .../app/addons/config/tests/resourcesSpec.js | 29 +++++++++++++++++- src/fauxton/app/core/tests/layoutSpec.js | 2 +- 3 files changed, 55 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/e671933c/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 8f9ab08..e5ebe65 100644 --- a/src/fauxton/app/addons/config/resources.js +++ b/src/fauxton/app/addons/config/resources.js @@ -22,7 +22,7 @@ function (app, FauxtonAPI) { Config.Model = Backbone.Model.extend({}); Config.OptionModel = Backbone.Model.extend({ documentation: "config", - + url: function () { return app.host + '/_config/' + this.get("section") + '/' + this.get("name"); }, @@ -84,7 +84,8 @@ function (app, FauxtonAPI) { "dblclick .js-edit-value": "editValue", "click .js-delete-value": "deleteValue", "click .js-cancel-value": "cancelEdit", - "click .js-save-value": "saveValue" + "click .js-save-value": "saveValue", + "keyup .js-value-input": "processKeyEvents" }, deleteValue: function (event) { @@ -99,20 +100,40 @@ function (app, FauxtonAPI) { 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(); + } }, saveValue: function (event) { - this.model.save({value: this.$(".js-value-input").val()}); - this.render(); + this.saveAndRender(); }, - cancelEdit: function (event) { + 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(); } }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/e671933c/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 98f6569..b9b8d09 100644 --- a/src/fauxton/app/addons/config/tests/resourcesSpec.js +++ b/src/fauxton/app/addons/config/tests/resourcesSpec.js @@ -17,7 +17,7 @@ define([ var assert = testUtils.assert, ViewSandbox = testUtils.ViewSandbox; - describe("ViewItem", function () { + describe("Config: ViewItem", function () { var tabMenu, optionModel; beforeEach(function () { @@ -52,6 +52,33 @@ define([ assert.ok(renderSpy.calledOnce); assert.ok(saveSpy.calledOnce); }); + + it("pressing enter should save the model and render", function () { + var renderSpy = sinon.stub(tabMenu, 'render'); + var saveSpy = sinon.stub(optionModel, 'save'); + + var e = $.Event("keyup"); + e.keyCode = 13; + tabMenu.$('.js-value-input').trigger(e); + + assert.ok(renderSpy.calledOnce); + assert.ok(saveSpy.calledOnce); + }); + + it("pressing Esc hides the field", function () { + var e = $.Event("keyup"); + e.keyCode = 27; + tabMenu.$('.js-value-input').trigger(e); + + assert.ok(tabMenu.$('.js-edit-value-form').hasClass('js-hidden')); + }); + + it("pressing Cancel hides the field", function () { + tabMenu.$('.js-edit-value').trigger('dblclick'); + tabMenu.$('.js-cancel-value').trigger('click'); + + assert.ok(tabMenu.$('.js-edit-value-form').hasClass('js-hidden')); + }); }); }); }); http://git-wip-us.apache.org/repos/asf/couchdb/blob/e671933c/src/fauxton/app/core/tests/layoutSpec.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/core/tests/layoutSpec.js b/src/fauxton/app/core/tests/layoutSpec.js index b58966b..40b1947 100644 --- a/src/fauxton/app/core/tests/layoutSpec.js +++ b/src/fauxton/app/core/tests/layoutSpec.js @@ -15,7 +15,7 @@ define([ ], function (FauxtonAPI, testUtils) { var assert = testUtils.assert; - describe("Faxuton Layout", function () { + describe("Fauxton Layout", function () { var layout; beforeEach(function () {
