-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
55 lines (46 loc) · 1.27 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var app = angular.module('todo', []);
app.directive('ngFocusout', function(){
return function(scope, elem, attrs){
elem.bind('blur', function(){
scope.$apply(attrs.ngFocusout);
});
};
});
app.controller('TodoCtrl', function ($scope, filterFilter, $http, $location){
$scope.todos = [];
$scope.placeholder = "Chargement";
$scope.statusFilter = {};
$http.get('todos.php').success(function(data){
$scope.todos = data;
$scope.placeholder = "Nouvelle tache";
});
$scope.$watch('todos', function(){
$scope.remaining = filterFilter($scope.todos, {completed:false}).length;
$scope.allchecked = !$scope.remaining;
}, true);
if($location.path() == '') {
$location.path("/");
}
$scope.locationPath = $location;
$scope.$watch('locationPath.path()', function(path){
$scope.statusFilter = (path == "/active")? {completed:false} : (path == "/done")? {completed:true} : null;
});
$scope.removeTodo = function(index){
$scope.todos.splice(index,1);
};
$scope.addTodo = function(){
$scope.todos.push({
name : $scope.newtodo,
completed : false
});
$scope.newtodo = "";
};
$scope.checkAllTodo = function(){
$scope.todos.forEach(function(todo){
todo.completed = $scope.allchecked;
});
};
$scope.editTodo = function(todo){
todo.editing = false;
}
});