Commit 9fd0c4f7 authored by addyosmani's avatar addyosmani

First set of fixes for model level routing.

parent 15c813f3
// Load the application once the DOM is ready, using `jQuery.ready`: // Load the application once the DOM is ready, using `jQuery.ready`:
$(function(){ $(function(){
var currentFilter = "";
// Todo Model // Todo Model
// ---------- // ----------
...@@ -172,7 +174,7 @@ $(function(){ ...@@ -172,7 +174,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.adcompleted, this); Todos.on('add', this.addOne, 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);
...@@ -207,14 +209,28 @@ $(function(){ ...@@ -207,14 +209,28 @@ $(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>`.
adcompleted: function(todo) { addOne: 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.adcompleted, this);
this.$("#todo-list").html('');
switch(currentFilter){
case "active":
_.each(Todos.remaining(), this.addOne);
break;
case "completed":
_.each(Todos.completed(), this.addOne);
break;
default:
Todos.each(this.addOne, this);
break;
}
}, },
// Generate the attributes for a new Todo item. // Generate the attributes for a new Todo item.
...@@ -253,36 +269,22 @@ $(function(){ ...@@ -253,36 +269,22 @@ $(function(){
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes:{ routes:{
"/:filter": "filter", "/:filter": "setFilter",
"/:*": "filter" "/:*": "setFilter"
}, },
filter: function(param){ setFilter: function(param){
//this.$todos = $('#todo-list'); currentFilter = param;
//this.$todoItems = this.$todos.find('li'); Todos.trigger('reset');
//this.$todoscompleted = this.$todos.find('.completed');
switch(param){
default:
//this.$todoItems.show();
console.log(Todos);
break;
case 'active':
//this.$todoItems.show().not('.completed').hide();
console.log(Todos.remaining());
break;
case 'completed':
console.log(Todos.completed());
//this.$todoItems.show();
//this.$todoscompleted.hide();
break;
}
// Currently not working on navigation.
$('#filters li a') $('#filters li a')
.removeClass('selected') .removeClass('selected')
.filter("[href='#/" + param + "']") .filter("[href='#/" + param + "']")
.addClass('selected'); .addClass('selected');
} }
}); });
......
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