couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [21/50] [abbrv] fauxton commit: updated refs/heads/import-master to b32c617
Date Tue, 01 Apr 2014 09:14:37 GMT
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-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/79967cd1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/79967cd1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/79967cd1

Branch: refs/heads/import-master
Commit: 79967cd14172ec642b7681e4ed7474680a14d412
Parents: 4266f84
Author: Robert Kowalski <rok@kowalski.gd>
Authored: Wed Mar 12 22:49:35 2014 +0100
Committer: suelockwood <deathbear@apache.org>
Committed: Thu Mar 13 10:43:23 2014 -0400

----------------------------------------------------------------------
 app/addons/config/resources.js           | 31 ++++++++++++++++++++++-----
 app/addons/config/tests/resourcesSpec.js | 29 ++++++++++++++++++++++++-
 app/core/tests/layoutSpec.js             |  2 +-
 3 files changed, 55 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/79967cd1/app/addons/config/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/config/resources.js b/app/addons/config/resources.js
index 8f9ab08..e5ebe65 100644
--- a/app/addons/config/resources.js
+++ b/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-fauxton/blob/79967cd1/app/addons/config/tests/resourcesSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/config/tests/resourcesSpec.js b/app/addons/config/tests/resourcesSpec.js
index 98f6569..b9b8d09 100644
--- a/app/addons/config/tests/resourcesSpec.js
+++ b/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-fauxton/blob/79967cd1/app/core/tests/layoutSpec.js
----------------------------------------------------------------------
diff --git a/app/core/tests/layoutSpec.js b/app/core/tests/layoutSpec.js
index b58966b..40b1947 100644
--- a/app/core/tests/layoutSpec.js
+++ b/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 () {


Mime
View raw message