summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Kowalski <rok@kowalski.gd>2014-03-12 22:49:35 +0100
committersuelockwood <deathbear@apache.org>2014-03-13 10:43:23 -0400
commite671933c2f4d83735ce918d00d8dfe5c1130f727 (patch)
tree25a5f5bcae5da79053d6b6f198659050cbd8ec69
parentf3ca96026a8da409756e30c8cf8efd05968feeab (diff)
downloadcouchdb-e671933c2f4d83735ce918d00d8dfe5c1130f727.tar.gz
Fauxton: focus input on doubleclick
Fauxton: hide field if Esc if pressed Fauxton: fix small typo Fauxton: save value, when I press Enter
-rw-r--r--src/fauxton/app/addons/config/resources.js31
-rw-r--r--src/fauxton/app/addons/config/tests/resourcesSpec.js29
-rw-r--r--src/fauxton/app/core/tests/layoutSpec.js2
3 files changed, 55 insertions, 7 deletions
diff --git a/src/fauxton/app/addons/config/resources.js b/src/fauxton/app/addons/config/resources.js
index 8f9ab082c..e5ebe65b9 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();
}
});
diff --git a/src/fauxton/app/addons/config/tests/resourcesSpec.js b/src/fauxton/app/addons/config/tests/resourcesSpec.js
index 98f65691a..b9b8d0954 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'));
+ });
});
});
});
diff --git a/src/fauxton/app/core/tests/layoutSpec.js b/src/fauxton/app/core/tests/layoutSpec.js
index b58966bc8..40b19475a 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 () {