Skip to content

Commit

Permalink
Display a button to remove all completed todos
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislopresto committed Mar 12, 2015
1 parent 2de790d commit 3b58db0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/controllers/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import Ember from 'ember';

export default Ember.ArrayController.extend({
actions: {
clearCompleted: function() {
var completed = this.filterBy('isCompleted', true);
completed.invoke('deleteRecord');
completed.invoke('save');
},

createTodo: function() {
// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');
Expand All @@ -21,6 +27,14 @@ export default Ember.ArrayController.extend({
}
},

hasCompleted: function() {
return this.get('completed') > 0;
}.property('completed'),

completed: function() {
return this.filterBy('isCompleted', true).get('length');
}.property('@each.isCompleted'),

remaining: function() {
return this.filterBy('isCompleted', false).get('length');
}.property('@each.isCompleted'),
Expand Down
8 changes: 5 additions & 3 deletions app/templates/todos.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
</li>
</ul>

<button id="clear-completed">
Clear completed (1)
</button>
{{#if hasCompleted}}
<button id="clear-completed" {{action "clearCompleted"}}>
Clear completed ({{completed}})
</button>
{{/if}}
</footer>
</section>

Expand Down

0 comments on commit 3b58db0

Please sign in to comment.