-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
91 lines (66 loc) · 2.27 KB
/
index.js
File metadata and controls
91 lines (66 loc) · 2.27 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
angular.module('angularApp', [])
.controller('MessageController', function($scope, $http) {
$scope.textList = [];
$scope.submitText = function () {
$http.get('/api/textList')
.success(function(data, status, headers, config) {
$scope.textList = data;
//for first item, $scope.textList.length === 0 at this moment
var object = {text: $scope.searchText, likes: 0, index: $scope.textList.length};
if(object.text === "Joseph is awesome") {
object.likes = 9001;
}
$scope.textList.push(object); //now $scope.textList.length === 1
$scope.searchText = '';
$http.post('/api/textList', object).
success(function(data, status, headers, config) {
}).
error(function(data, status, headers, config) {
});
}).
error(function(data, status, headers, config) {
});
};
$scope.like = function(object) {
if(object.likes > -5) {
object.likes += 1;
}
if(object.likes === 10) {
object.text = object.text + " is an awesome idea!"
}
var array = [object.index, object.likes, object.text];
$http.post('/api/textList', array).
success(function(data, status, headers, config) {
}).
error(function(data, status, headers, config) {
});
};
$scope.dislike = function(object) {
if(object.likes < 10) {
object.likes -= 1;
}
if(object.likes === -5) {
object.text += " is";
object.likes
} else if(object.likes === -10) {
object.text += " a really really";
} else if(object.likes === -15) {
object.text += " shitty";
} else if(object.likes === -20) {
object.text += " idea";
}
var array = [object.index, object.likes, object.text];
$http.post('/api/textList', array).
success(function(data, status, headers, config) {
}).
error(function(data, status, headers, config) {
});
};
//loads data when first loaded
$http.get('/api/textList').
success(function(data, status, headers, config) {
$scope.textList = data;
}).
error(function(data, status, headers, config) {
});
});