Commit 15c813f3 authored by addyosmani's avatar addyosmani

Changes to fix done -> completed

parent 3e9a320e
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<script type="text/template" id="item-template"> <script type="text/template" id="item-template">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" <%= done ? 'checked="checked"' : '' %> /> <input class="toggle" type="checkbox" <%= completed ? 'checked="checked"' : '' %> />
<label><%- title %></label> <label><%- title %></label>
<button class="destroy"></button> <button class="destroy"></button>
</div> </div>
...@@ -54,8 +54,8 @@ ...@@ -54,8 +54,8 @@
<a href="#/completed">Completed</a> <a href="#/completed">Completed</a>
</li> </li>
</ul> </ul>
<% if (done) { %> <% if (completed) { %>
<button id="clear-completed">Clear <%- done %> completed <%= done == 1 ? 'item' : 'items' %></button> <button id="clear-completed">Clear <%- completed %> completed <%= completed == 1 ? 'item' : 'items' %></button>
<% } %> <% } %>
</script> </script>
</body> </body>
......
...@@ -4,13 +4,13 @@ $(function(){ ...@@ -4,13 +4,13 @@ $(function(){
// Todo Model // Todo Model
// ---------- // ----------
// Our basic **Todo** model has `title`, `order`, and `done` attributes. // Our basic **Todo** model has `title`, `order`, and `completed` attributes.
var Todo = Backbone.Model.extend({ var Todo = Backbone.Model.extend({
// Default attributes for the todo. // Default attributes for the todo.
defaults: { defaults: {
title: "empty todo...", title: "empty todo...",
done: false completed: false
}, },
// Ensure that each todo created has `title`. // Ensure that each todo created has `title`.
...@@ -20,9 +20,9 @@ $(function(){ ...@@ -20,9 +20,9 @@ $(function(){
} }
}, },
// Toggle the `done` state of this todo item. // Toggle the `completed` state of this todo item.
toggle: function() { toggle: function() {
this.save({done: !this.get("done")}); this.save({completed: !this.get("completed")});
}, },
// Remove this Todo from *localStorage* and delete its view. // Remove this Todo from *localStorage* and delete its view.
...@@ -46,13 +46,13 @@ $(function(){ ...@@ -46,13 +46,13 @@ $(function(){
localStorage: new Store("todos-backbone"), localStorage: new Store("todos-backbone"),
// Filter down the list of all todo items that are finished. // Filter down the list of all todo items that are finished.
done: function() { completed: function() {
return this.filter(function(todo){ return todo.get('done'); }); return this.filter(function(todo){ return todo.get('completed'); });
}, },
// Filter down the list to only todo items that are still not finished. // Filter down the list to only todo items that are still not finished.
remaining: function() { remaining: function() {
return this.without.apply(this, this.done()); return this.without.apply(this, this.completed());
}, },
// We keep the Todos in sequential order, despite being saved by unordered // We keep the Todos in sequential order, despite being saved by unordered
...@@ -85,7 +85,7 @@ $(function(){ ...@@ -85,7 +85,7 @@ $(function(){
// The DOM events specific to an item. // The DOM events specific to an item.
events: { events: {
"click .toggle" : "toggleDone", "click .toggle" : "togglecompleted",
"dblclick .view" : "edit", "dblclick .view" : "edit",
"click .destroy" : "clear", "click .destroy" : "clear",
"keypress .edit" : "updateOnEnter", "keypress .edit" : "updateOnEnter",
...@@ -104,14 +104,14 @@ $(function(){ ...@@ -104,14 +104,14 @@ $(function(){
render: function() { render: function() {
var $el = $(this.el); var $el = $(this.el);
$el.html(this.template(this.model.toJSON())); $el.html(this.template(this.model.toJSON()));
$el.toggleClass('done', this.model.get('done')); $el.toggleClass('completed', this.model.get('completed'));
this.input = this.$('.edit'); this.input = this.$('.edit');
return this; return this;
}, },
// Toggle the `"done"` state of the model. // Toggle the `"completed"` state of the model.
toggleDone: function() { togglecompleted: function() {
this.model.toggle(); this.model.toggle();
}, },
...@@ -172,7 +172,7 @@ $(function(){ ...@@ -172,7 +172,7 @@ $(function(){
this.input = this.$("#new-todo"); this.input = this.$("#new-todo");
this.allCheckbox = this.$("#toggle-all")[0]; this.allCheckbox = this.$("#toggle-all")[0];
Todos.on('add', this.addOne, this); Todos.on('add', this.adcompleted, this);
Todos.on('reset', this.addAll, this); Todos.on('reset', this.addAll, this);
Todos.on('all', this.render, this); Todos.on('all', this.render, this);
...@@ -185,7 +185,7 @@ $(function(){ ...@@ -185,7 +185,7 @@ $(function(){
// Re-rendering the App just means refreshing the statistics -- the rest // Re-rendering the App just means refreshing the statistics -- the rest
// of the app doesn't change. // of the app doesn't change.
render: function() { render: function() {
var done = Todos.done().length; var completed = Todos.completed().length;
var remaining = Todos.remaining().length; var remaining = Todos.remaining().length;
if (Todos.length) { if (Todos.length) {
...@@ -193,7 +193,7 @@ $(function(){ ...@@ -193,7 +193,7 @@ $(function(){
this.$footer.show(); this.$footer.show();
this.$footer.html(this.statsTemplate({ this.$footer.html(this.statsTemplate({
done: done, completed: completed,
remaining: remaining remaining: remaining
})); }));
...@@ -207,14 +207,14 @@ $(function(){ ...@@ -207,14 +207,14 @@ $(function(){
// Add a single todo item to the list by creating a view for it, and // Add a single todo item to the list by creating a view for it, and
// appending its element to the `<ul>`. // appending its element to the `<ul>`.
addOne: function(todo) { adcompleted: function(todo) {
var view = new TodoView({model: todo}); var view = new TodoView({model: todo});
this.$("#todo-list").append(view.render().el); this.$("#todo-list").append(view.render().el);
}, },
// Add all items in the **Todos** collection at once. // Add all items in the **Todos** collection at once.
addAll: function() { addAll: function() {
Todos.each(this.addOne, this); Todos.each(this.adcompleted, this);
}, },
// Generate the attributes for a new Todo item. // Generate the attributes for a new Todo item.
...@@ -222,7 +222,7 @@ $(function(){ ...@@ -222,7 +222,7 @@ $(function(){
return { return {
title: this.input.val().trim(), title: this.input.val().trim(),
order: Todos.nextOrder(), order: Todos.nextOrder(),
done: false completed: false
}; };
}, },
...@@ -236,15 +236,15 @@ $(function(){ ...@@ -236,15 +236,15 @@ $(function(){
this.input.val(''); this.input.val('');
}, },
// Clear all done todo items, destroying their models. // Clear all completed todo items, destroying their models.
clearCompleted: function() { clearCompleted: function() {
_.each(Todos.done(), function(todo){ todo.clear(); }); _.each(Todos.completed(), function(todo){ todo.clear(); });
return false; return false;
}, },
toggleAllComplete: function () { toggleAllComplete: function () {
var done = this.allCheckbox.checked; var completed = this.allCheckbox.checked;
Todos.each(function (todo) { todo.save({'done': done}); }); Todos.each(function (todo) { todo.save({'completed': completed}); });
} }
}); });
...@@ -259,20 +259,23 @@ $(function(){ ...@@ -259,20 +259,23 @@ $(function(){
filter: function(param){ filter: function(param){
this.$todos = $('#todo-list'); //this.$todos = $('#todo-list');
this.$todoItems = this.$todos.find('li'); //this.$todoItems = this.$todos.find('li');
this.$todosDone = this.$todos.find('.done'); //this.$todoscompleted = this.$todos.find('.completed');
switch(param){ switch(param){
default: default:
this.$todoItems.show(); //this.$todoItems.show();
console.log(Todos);
break; break;
case 'active': case 'active':
this.$todoItems.show().not('.done').hide(); //this.$todoItems.show().not('.completed').hide();
console.log(Todos.remaining());
break; break;
case 'completed': case 'completed':
this.$todoItems.show(); console.log(Todos.completed());
this.$todosDone.hide(); //this.$todoItems.show();
//this.$todoscompleted.hide();
break; break;
} }
......
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