Commit 534e6832 authored by Cliff Hall's avatar Cliff Hall

Fix outstanding issues

> Add new items to end of list
> Escape key abandons todo edit
parent a0b2178c
...@@ -110,7 +110,7 @@ puremvc.define({ ...@@ -110,7 +110,7 @@ puremvc.define({
addTodo: function( newTodo ) { addTodo: function( newTodo ) {
newTodo.id = this.getUuid(); newTodo.id = this.getUuid();
this.todos.push( newTodo ); this.todos.unshift( newTodo );
this.todosModified(); this.todosModified();
}, },
......
...@@ -49,7 +49,8 @@ puremvc.define({ ...@@ -49,7 +49,8 @@ puremvc.define({
// INSTANCE MEMBERS // INSTANCE MEMBERS
{ {
ENTER_KEY: 13, ENTER_KEY: 13,
ESC_KEY: 27,
addEventListener: function ( type, listener, useCapture ){ addEventListener: function ( type, listener, useCapture ){
todomvc.view.event.AppEvents.addEventListener ( this.todoApp, type, listener, useCapture ); todomvc.view.event.AppEvents.addEventListener ( this.todoApp, type, listener, useCapture );
...@@ -63,6 +64,18 @@ puremvc.define({ ...@@ -63,6 +64,18 @@ puremvc.define({
todomvc.view.event.AppEvents.dispatchEvent( this.todoApp, event ); todomvc.view.event.AppEvents.dispatchEvent( this.todoApp, event );
}, },
abandonEditTodo: function( event ) {
var todo, todoId, div, inputEditTodo;
inputEditTodo = event.target;
todoId = inputEditTodo.getAttribute( 'data-todo-id' )
todo = this.getTodoById( todoId );
inputEditTodo.value = todo.title;
inputEditTodo.completed = todo.completed;
div = document.getElementById( 'li_' + todoId );
div.className = 'view';
this.newTodoField.focus();
},
dispatchToggleComplete: function( event ) { dispatchToggleComplete: function( event ) {
var todo, toggleItemCompleteEvent; var todo, toggleItemCompleteEvent;
todo = this.getTodoById( event.target.getAttribute( 'data-todo-id' ) ); todo = this.getTodoById( event.target.getAttribute( 'data-todo-id' ) );
...@@ -167,6 +180,7 @@ puremvc.define({ ...@@ -167,6 +180,7 @@ puremvc.define({
todoId = this.getAttribute( 'data-todo-id' ); todoId = this.getAttribute( 'data-todo-id' );
div = document.getElementById( 'li_' + todoId ); div = document.getElementById( 'li_' + todoId );
inputEditTodo = document.getElementById( 'input_' + todoId ); inputEditTodo = document.getElementById( 'input_' + todoId );
inputEditTodo.setAttribute( 'data-todo-id', todoId );
div.className = 'editing'; div.className = 'editing';
inputEditTodo.focus(); inputEditTodo.focus();
...@@ -184,6 +198,13 @@ puremvc.define({ ...@@ -184,6 +198,13 @@ puremvc.define({
this.component.dispatchUpdateTodo( event ); this.component.dispatchUpdateTodo( event );
} }
}); });
todomvc.view.event.AppEvents.addEventListener( inputEditTodo, 'keydown', function( event ) {
if ( event.keyCode === this.component.ESC_KEY ) {
this.component.abandonEditTodo( event );
}
});
todomvc.view.event.AppEvents.addEventListener( inputEditTodo, 'blur', function( event ) { todomvc.view.event.AppEvents.addEventListener( inputEditTodo, 'blur', function( event ) {
this.component.dispatchUpdateTodo( event ); this.component.dispatchUpdateTodo( event );
}); });
......
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