Aspect creation modal now creates an aspect when pressing enter
This commit is contained in:
parent
db00bd1b03
commit
61edda0fca
2 changed files with 27 additions and 1 deletions
|
|
@ -4,7 +4,8 @@ app.views.AspectCreate = app.views.Base.extend({
|
||||||
templateName: "aspect_create_modal",
|
templateName: "aspect_create_modal",
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
"click .btn.btn-primary": "createAspect"
|
"click .btn.btn-primary": "createAspect",
|
||||||
|
"keypress input#aspect_name": "inputKeypress"
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function(opts) {
|
initialize: function(opts) {
|
||||||
|
|
@ -30,6 +31,13 @@ app.views.AspectCreate = app.views.Base.extend({
|
||||||
return this.$("#aspect_name").val();
|
return this.$("#aspect_name").val();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
inputKeypress: function(evt) {
|
||||||
|
if(evt.which === 13) {
|
||||||
|
evt.preventDefault();
|
||||||
|
this.createAspect();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
createAspect: function() {
|
createAspect: function() {
|
||||||
var aspect = new app.models.Aspect({
|
var aspect = new app.models.Aspect({
|
||||||
"person_id": this._personId,
|
"person_id": this._personId,
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,24 @@ describe("app.views.AspectCreate", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#inputKeypress", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
this.view.render();
|
||||||
|
spyOn(this.view, "createAspect");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call createAspect if the enter key was pressed", function() {
|
||||||
|
var e = $.Event("keypress", { which: 13 });
|
||||||
|
this.view.inputKeypress(e);
|
||||||
|
expect(this.view.createAspect).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shouldn't call createAspect if another key was pressed", function() {
|
||||||
|
var e = $.Event("keypress", { which: 42 });
|
||||||
|
this.view.inputKeypress(e);
|
||||||
|
expect(this.view.createAspect).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#createAspect", function() {
|
describe("#createAspect", function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue