Commit 1cf5060a authored by Dave Methvin's avatar Dave Methvin

spine: Fix the "mark all complete" checkbox

Fixes #795
parent 74ceed6e
// Generated by CoffeeScript 1.9.1
// Generated by CoffeeScript 1.10.0
(function() {
var TodoApp,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
......@@ -96,13 +96,15 @@
};
TodoApp.prototype.toggleAll = function(e) {
var checked;
checked = e.target.checked;
return Todo.each(function(todo) {
/*
TODO: Model updateAttribute sometimes won't stick:
https://github.com/maccman/spine/issues/219
*/
todo.updateAttribute('completed', e.target.checked);
todo.updateAttribute('completed', checked);
return todo.trigger('update', todo);
});
};
......@@ -112,14 +114,13 @@
};
TodoApp.prototype.toggleElems = function() {
var isTodos;
isTodos = !!Todo.count();
this.main.toggle(isTodos);
this.footer.toggle(isTodos);
this.clearCompleted.toggle(!!Todo.completed().length);
if (!Todo.completed().length) {
return this.toggleAllElem.removeAttr('checked');
}
var completed, total;
completed = Todo.completed().length;
total = Todo.count();
this.main.toggle(total !== 0);
this.footer.toggle(total !== 0);
this.toggleAllElem.prop('checked', completed === total);
return this.clearCompleted.toggle(completed !== 0);
};
TodoApp.prototype.renderFooter = function() {
......
......@@ -57,23 +57,25 @@ class TodoApp extends Spine.Controller
@addNew todo for todo in @getByFilter()
toggleAll: (e) ->
checked = e.target.checked
Todo.each (todo) ->
###
TODO: Model updateAttribute sometimes won't stick:
https://github.com/maccman/spine/issues/219
###
todo.updateAttribute 'completed', e.target.checked
todo.updateAttribute 'completed', checked
todo.trigger 'update', todo
clearCompletedItem: ->
Todo.destroyCompleted()
toggleElems: =>
isTodos = !!Todo.count()
@main.toggle isTodos
@footer.toggle isTodos
@clearCompleted.toggle !!Todo.completed().length
@toggleAllElem.removeAttr 'checked' if !Todo.completed().length
completed = Todo.completed().length
total = Todo.count()
@main.toggle total != 0
@footer.toggle total != 0
@toggleAllElem.prop 'checked', completed == total
@clearCompleted.toggle completed != 0
renderFooter: =>
text = (count) -> if count is 1 then 'item' else 'items'
......
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