-
Notifications
You must be signed in to change notification settings - Fork 1
/
todo.js
55 lines (46 loc) · 1.31 KB
/
todo.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
(function(){
var module = angular.module("todoMod",[]);
module.run(function() {
AV.initialize("5kjccy0bb5dbwkz7bnhzpi189y8yljro8mdszjc8oqwpn3jg", "6kk41eo4lbv0yydm6qsc0ax0tol52qpijm3zx413eou2xliz");
});
module.controller("todoCtrl",['$http', '$scope', function($http, $scope){
$scope.todos = [];
$scope.newTodo = {text:"", done: false};
$scope.getTodos = function() {
var Todo = AV.Object.extend("Todo");
var query = new AV.Query(Todo);
query.find({
success:function (results){
$scope.$apply(function(){
$scope.todos = JSON.parse(JSON.stringify(results));;
})
}
})
}
$scope.addTodo = function () {
var Todo = AV.Object.extend("Todo");
var todo = new Todo();
todo.set("text",$scope.newTodo.text);
todo.set("done",$scope.newTodo.done)
todo.save(null, {
success: function(result){
$scope.$apply(function(){
$scope.todos.push(todo.toJSON());
$scope.newTodo = {text:"", done: false};
});
}
});
};
$scope.updateTodoState = function(todoParam) {
var Todo = AV.Object.extend("Todo");
var todo = new Todo();
todo.set("objectId",todoParam.objectId);
todo.set("done",todoParam.done);
todo.save(null, {
success: function(result){
}
});
}
$scope.getTodos();
}]);
})();