page-scripts.js 3.56 KB
(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>';
	        }
	    }
	});


})();