page-scripts.js
3.56 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
(function () {
'use strict';
//Initiate module
var app = angular.module("appStore",['ngRoute']);
app.config(['$routeProvider',
function ($routeProvider) {
$routeProvider
.when('/', {
controller: 'appController',
templateUrl: '/home/home-partial.html'
})
.when('/about', {
controller: 'aboutController',
templateUrl: '/about/about-partial.html'
})
.otherwise('/')
}]);
app.controller("pageController",function($scope, $location){
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};
});
app.controller("appController", function($scope, $http){
//Call to get top 5 apps
$http.get('http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topfreeapplications/sf=143441/limit=25/json').
success(function(data, status, headers, config) {
$scope.appData = data.feed.entry;
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
if(localStorage.getItem("Cart")) {
$scope.Cart = JSON.parse(localStorage.getItem("Cart"));
}
else {
$scope.Cart={
Items: []
};
}
$scope.addtofav = addtofav;
function addtofav(item){
var index = $scope.Cart.Items.indexOf(item);
if(index==-1) {
$scope.Cart.Items.push(item);
}
else
alert("Item Already Added");
debugger;
localStorage.setItem("Cart", JSON.stringify($scope.Cart));
}
$scope.removeApp = removeApp;
function removeApp(item) {
var index = $scope.Cart.Items.indexOf(item);
$scope.Cart.Items.splice(index, 1);
localStorage.setItem("Cart", JSON.stringify($scope.Cart));
}
});
app.controller("aboutController",function($scope, $http){
$http.get('http://localhost:8080/todolist').success(function(response) {
//console.log("I got the data I requested");
$scope.todolist = response;
});
$scope.task = {
taskname: "",
Done: false,
details: ""
}
$scope.addTask = function() {
$http.post('http://localhost:8080/todolist', $scope.task).success(function(response){
$http.get('http://localhost:8080/todolist').success(function(response) {
$scope.todolist = response;
});
console.log(response);
$scope.task = {
taskname: "",
Done: false,
details: ""
}
});
};
$scope.updateTask = function(task) {
$http.put('http://localhost:8080/todolist/'+task._id,task).success(function(response) {
});
};
$scope.deleteTask = function(id) {
var x=confirm("Are you sure?")
if(x==true){
$http.delete('http://localhost:8080/todolist/' + id).success(function(response) {
console.log(response);
$http.get('http://localhost:8080/todolist').success(function(response) {
$scope.todolist = response;
});
});
}
}
});
app.filter('Truncate', function () {
return function (text, length, end) {
if (!text) {
return '';
}
if (isNaN(length))
length = 10;
if (end === undefined)
end = "";
if (text.length <= length || text.length - end.length <= length)
{ return text; }
else
{
return String(text).substring(0, length - end.length) + end;
//return '<h1 ng-click="chutiya=true">Bokachoda</h1><span ng-show="chutiya==true">Chutiyapa ka limit</span>';
}
}
});
})();