Commit 62aa202f authored by Pascal Hartig's avatar Pascal Hartig

knockback: Allow editing completed items

Close #458
+ ENTER_KEY extracted
parent 60edd6b8
......@@ -2,7 +2,9 @@
(function() {
window.TodoViewModel = function(model) {
var _this = this;
var ENTER_KEY,
_this = this;
ENTER_KEY = 13;
this.editing = ko.observable(false);
this.completed = kb.observable(model, {
key: 'completed',
......@@ -32,13 +34,13 @@
return model.destroy();
};
this.onCheckEditBegin = function() {
if (!_this.editing() && !_this.completed()) {
if (!_this.editing()) {
_this.editing(true);
return $('.todo-input').focus();
}
};
this.onCheckEditEnd = function(view_model, event) {
if ((event.keyCode === 13) || (event.type === 'blur')) {
if ((event.keyCode === ENTER_KEY) || (event.type === 'blur')) {
$('.todo-input').blur();
return _this.editing(false);
}
......
window.TodoViewModel = (model) ->
ENTER_KEY = 13
@editing = ko.observable(false)
@completed = kb.observable(model, {key: 'completed', read: (-> return model.completed()), write: ((completed) -> model.completed(completed)) }, @)
......@@ -13,12 +15,12 @@ window.TodoViewModel = (model) ->
@onDestroyTodo = => model.destroy()
@onCheckEditBegin = =>
if not @editing() and not @completed()
if not @editing()
@editing(true)
$('.todo-input').focus()
@onCheckEditEnd = (view_model, event) =>
if (event.keyCode == 13) or (event.type == 'blur')
if (event.keyCode == ENTER_KEY) or (event.type == 'blur')
$('.todo-input').blur()
@editing(false)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment