Permalink
Browse files

bringing filter upp to app scope

  • Loading branch information...
1 parent b3d3585 commit 3ed88abeeee3b8149b7e5809a46f12edba9c840e @jsoverson jsoverson committed Aug 25, 2012
@@ -1,7 +1,7 @@
-#todo-list.filter-active .completed {
+#todoapp.filter-active #todo-list .completed {
display:none
}
-#todo-list.filter-completed .active {
+#todoapp.filter-completed #todo-list .active {
display:none
}
@@ -1,3 +1,4 @@
+/*global $*/
define(
['marionette','vent','collections/TodoList','views/Header','views/TodoListCompositeView','views/Footer'],
function(marionette, vent, TodoList, Header, TodoListCompositeView, Footer){
@@ -38,6 +39,11 @@ define(
}
}
+ vent.on('todoList:filter',function(filter) {
+ filter = filter || 'all';
+ $('#todoapp').attr('class', 'filter-' + filter);
+ });
+
vent.on('todoList:clear:completed',function(){
function destroy(todo) { todo.destroy(); }
@@ -8,16 +8,15 @@ define(['marionette','templates','vent','views/TodoItemView'], function (Marione
itemView : ItemView,
ui : {
- list : '#todo-list',
- toggleAll : '#toggle-all'
+ list : '#todo-list',
+ toggle : '#toggle-all'
},
events : {
'click #toggle-all' : 'onToggleAllClick'
},
initialize : function() {
- this.bindTo(vent, 'todoList:filter', this.setFilter, this);
this.bindTo(this.collection, 'all', this.updateToggleCheckbox, this);
},
@@ -28,18 +27,13 @@ define(['marionette','templates','vent','views/TodoItemView'], function (Marione
updateToggleCheckbox : function() {
function reduceCompleted(left, right) { return left && right.get('completed'); }
var allCompleted = this.collection.reduce(reduceCompleted,true);
- this.ui.toggleAll.prop('checked', allCompleted);
+ this.ui.toggle.prop('checked', allCompleted);
},
appendHtml : function(collectionView, itemView) {
this.ui.list.append(itemView.el);
},
- setFilter : function(filter) {
- this.ui.list.removeClass('filter-completed filter-active');
- if (filter) this.ui.list.addClass('filter-' + filter );
- },
-
onToggleAllClick : function(evt) {
var isChecked = evt.currentTarget.checked;
this.collection.each(function(todo){

0 comments on commit 3ed88ab

Please sign in to comment.