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