This repository has been archived by the owner on Feb 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
todoListCtrl.js
76 lines (69 loc) · 2.4 KB
/
todoListCtrl.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
angular.module('todoApp')
.controller('todoListCtrl', ['$scope', '$location', 'todoListSvc', 'adalAuthenticationService', function ($scope, $location, todoListSvc, adalService) {
$scope.error = "";
$scope.loadingMessage = "Loading...";
$scope.todoList = null;
$scope.editingInProgress = false;
$scope.newTodoCaption = "";
$scope.editInProgressTodo = {
Description: "",
ID: 0
};
$scope.editSwitch = function (todo) {
todo.edit = !todo.edit;
if (todo.edit) {
$scope.editInProgressTodo.Description = todo.Description;
$scope.editInProgressTodo.ID = todo.ID;
$scope.editingInProgress = true;
} else {
$scope.editingInProgress = false;
}
};
$scope.populate = function () {
todoListSvc.getItems().success(function (results) {
$scope.todoList = results;
$scope.loadingMessage = "";
}).error(function (err) {
if (err.access_token)
{
// Re-request the token with additional claims (supposing here the service only returns the claims parameter)
adalService.acquireTokenRedirect('/api/TodoList', null, JSON.stringify(err));
}
$scope.error = err;
$scope.loadingMessage = "";
})
};
$scope.delete = function (id) {
todoListSvc.deleteItem(id).success(function (results) {
$scope.loadingMessage = "";
$scope.populate();
}).error(function (err) {
$scope.error = err;
$scope.loadingMessage = "";
})
};
$scope.update = function (todo) {
todoListSvc.putItem($scope.editInProgressTodo).success(function (results) {
$scope.loadingMsg = "";
$scope.populate();
$scope.editSwitch(todo);
}).error(function (err) {
$scope.error = err;
$scope.loadingMessage = "";
})
};
$scope.add = function () {
todoListSvc.postItem({
'Description': $scope.newTodoCaption,
'Owner': adalService.userInfo.userName
}).success(function (results) {
$scope.loadingMsg = "";
$scope.newTodoCaption = "";
$scope.populate();
}).error(function (err) {
$scope.error = err;
$scope.loadingMsg = "";
})
};
}]);