Commit 6a8987ed authored by Christoph Burgdorf's avatar Christoph Burgdorf

bound "mark all as complete"

parent 500a7d48
......@@ -18,7 +18,7 @@
</header>
<!-- TODO: figure out if its spec compliant to remove the #main id if its getting into the way?-->
<section id="main" ng:show="hasTodos()">
<input id="toggle-all" type="checkbox">
<input id="toggle-all" type="checkbox" name="allChecked" ng:click="toggleAllStates()">
<label for="toggle-all">Mark all as complete</label>
<ul id="todo-list">
<li ng:repeat="todo in todos" my:dblclick="editTodo(todo)" ng:class="(todo.done && ' done ') + (todo.editing && ' editing ')">
......@@ -27,7 +27,9 @@
<label>{{ todo.content }}</label>
<a class="destroy" ng:click="removeTodo(todo)"></a>
</div>
<input class="edit" type="text" name="todo.content">
<form ng:submit="finishEditing(todo)">
<input class="edit" type="text" name="todo.content" my:focus="todo.editing" my:blur="finishEditing(todo)">
</form>
</li>
</ul>
</section>
......
......@@ -44,7 +44,7 @@ App.Controllers.TodoController = function () {
var pluralize = function( count, word ) {
return count === 1 ? word : word + 's';
}
};
self.remainingTodos = countTodos("undone");
......@@ -57,7 +57,7 @@ App.Controllers.TodoController = function () {
self.clearItemsText = function(){
var finishedTodos = self.finishedTodos();
return 'Clear ' + finishedTodos + ' completed ' + pluralize(finishedTodos, 'item');
}
};
self.clearCompletedItems = function() {
var oldTodos = self.todos;
......@@ -67,6 +67,12 @@ App.Controllers.TodoController = function () {
});
};
self.toggleAllStates = function(){
angular.forEach(self.todos, function(todo){
todo.done = self.allChecked;
})
};
self.hasFinishedTodos = function() {
return self.finishedTodos() > 0;
};
......@@ -74,19 +80,4 @@ App.Controllers.TodoController = function () {
self.hasTodos = function() {
return self.todos.length > 0;
};
/*
The following code deals with hiding the hint *while* you are typing,
showing it once you did *finish* typing (aka 500 ms since you hit the last key)
*in case* the result is a non empty string
*/
Rx.Observable.FromAngularScope(self, "newTodo")
.Do(function() {
self.showHitEnterHint = false;
})
.Throttle(500)
.Select(function(x) {
return x.length > 0;
})
.ToOutputProperty(self, "showHitEnterHint");
};
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