From 662cd9671a9119dec7274631783d4a78e073e9cc Mon Sep 17 00:00:00 2001 From: Trek Glowacki Date: Thu, 14 Mar 2013 21:53:35 -0500 Subject: [PATCH 01/10] Accepting Edits --- index.html | 3 ++- js/controllers/todo_controller.js | 16 ++++++++++++++++ js/views/edit_todo_view.js | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 js/views/edit_todo_view.js diff --git a/index.html b/index.html index 0938c0d..1ad8fe6 100644 --- a/index.html +++ b/index.html @@ -20,7 +20,7 @@

todos

{{#each itemController="todo"}}
  • {{#if isEditing}} - + {{edit-todo class="edit" value=title focus-out="acceptChanges" insert-newline="acceptChanges"}} {{else}} {{input type="checkbox" checked=isCompleted class="toggle"}} @@ -68,5 +68,6 @@

    todos

    + diff --git a/js/controllers/todo_controller.js b/js/controllers/todo_controller.js index 47b50b3..2480a14 100644 --- a/js/controllers/todo_controller.js +++ b/js/controllers/todo_controller.js @@ -2,6 +2,22 @@ Todos.TodoController = Ember.ObjectController.extend({ actions: { editTodo: function () { this.set('isEditing', true); + }, + acceptChanges: function () { + if (this.get('isEditing')) { + this.set('isEditing', false); + + if (Ember.isEmpty(this.get('model.title'))) { + this.send('removeTodo'); + } else { + this.get('model').save(); + } + } + }, + removeTodo: function () { + var todo = this.get('model'); + todo.deleteRecord(); + todo.save(); } }, diff --git a/js/views/edit_todo_view.js b/js/views/edit_todo_view.js new file mode 100644 index 0000000..8156654 --- /dev/null +++ b/js/views/edit_todo_view.js @@ -0,0 +1,7 @@ +Todos.EditTodoView = Ember.TextField.extend({ + didInsertElement: function () { + this.$().focus(); + } +}); + +Ember.Handlebars.helper('edit-todo', Todos.EditTodoView); From 6d987a7601d2f7466d48674f20c0b73f88b7d25b Mon Sep 17 00:00:00 2001 From: Trek Glowacki Date: Sat, 16 Mar 2013 11:32:01 -0500 Subject: [PATCH 02/10] Deleting a Model --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 1ad8fe6..4f1cd21 100644 --- a/index.html +++ b/index.html @@ -23,7 +23,7 @@

    todos

    {{edit-todo class="edit" value=title focus-out="acceptChanges" insert-newline="acceptChanges"}} {{else}} {{input type="checkbox" checked=isCompleted class="toggle"}} - + {{/if}}
  • {{/each}} From 72f19ea2a8661572e41166bcc04ecdb8529caf9a Mon Sep 17 00:00:00 2001 From: Trek Glowacki Date: Thu, 14 Mar 2013 22:30:54 -0500 Subject: [PATCH 03/10] Transitioning between routes --- index.html | 29 ++++++++++++++++------------- js/router.js | 10 +++++++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index 4f1cd21..9fc1d98 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,21 @@ + + + diff --git a/js/app.js b/js/app.js index c9fdf29..f8b336e 100644 --- a/js/app.js +++ b/js/app.js @@ -1,3 +1,5 @@ window.Todos = Ember.Application.create(); -Todos.ApplicationAdapter = DS.FixtureAdapter.extend(); +Todos.ApplicationAdapter = DS.LSAdapter.extend({ + namespace: 'todos-emberjs' +});