Skip to content
Permalink
c44ba43596
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
135 lines (122 sloc) 4.31 KB
// The user controller will deal with
angular.module('routerApp').controller('userController', function ($q, $window, $scope, $state, $stateParams, $location, $http, $cookies, urlService, $rootScope, HolderService) {
/* Retrieve Url */
var url = urlService.web;
$location.hash("top");
$scope.COOKIE = $cookies.getAll();
// Logging out
$scope.logout = function () {
// $cookies.remove('userid');
// $state.go('user-home');
console.log("Happening");
}
// Customer Information Editing
// Retrieve Data
$scope.getUserInfo = function () {
var customerid = 1;
$scope.user = {};
$http.get("http://localhost:50031/api/GetCustomer?PersonID=" + customerid)
.success(function (response) {
$scope.user = angular.copy(response);
})
}
// Update User Information
$scope.updateUser = function () {
var promise = $http({
method: "post",
url: "http://localhost:50031/api/UpdateCustomer",
headers: {
contentType: "application/json"
},
data: $scope.user
}).
success(function (data, status, headers, config) {
$scope.messages = 'You have successfully updated your information. ';
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
});
}
// Dealing with Search
$scope.columns = [
{ field: 'TrackId', displayName: ' ', cellTemplate: '<center><button data-ng-click="addToCart(12)" class="btn btn-success btn-xs">Purchase</button></center></td>' },
{ field: 'TrackName', displayName: ' Track Name'},
{ field: 'AlbumTitle', displayName: ' Album Title '},
{ field: 'MediaType', displayName: ' Media Type ' },
{ field: 'Genre', displayName: ' Genre ' },
{ field: 'Clip', displayName: ' Sound Clip '},
{ field: 'UnitPrice', displayName: ' Unit Price ' }
];
$scope.gridOptions = {
data: null,
enableSorting: true,
columnDefs: $scope.columns,
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
var cellTemplate = 'ui-grid/selectionRowHeader';
$scope.gridApi.core.addRowHeaderColumn({ name: 'rowHeaderCol', displayName: '', width: 30, cellTemplate: cellTemplate });
}
};
// Search Function
$scope.search = function (token) {
console.log(token);
$http.get("http://localhost:50031/api/Search?search=" + token)
.success(function (response) {
$scope.data = angular.copy(response);
$scope.gridOptions.data = $scope.data.Track;
});
}
/* Begin Function Definitions */
$scope.authenticateUser = function (id, pass) {
return $q(function (resolve, reject) {
var param = id + " " + pass;
var promise = $http.post(url + "/authenticateUser", param)
.success(function (data, status) {
console.log(data);
if (data.STATUS == 555) {
$scope.authenticated = false;
resolve('We did it');
} else {
$scope.authenticated = true;
resolve('We did it');
}
})
.error(function (data, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
reject('We did not do it');
});
})
}
$scope.addToCart = function (trackid) {
console.log(trackid);
}
$scope.logout = function () {
$scope.messages = 'You have been logged out.';
$cookies.remove("PWD");
$cookies.remove("DEPID");
$cookies.remove('LOGIN');
$state.go('user');
}
$scope.myData = [
{
"firstName": "Cox",
"lastName": "Carney",
"company": "Enormo",
"employed": true
},
{
"firstName": "Lorraine",
"lastName": "Wise",
"company": "Comveyer",
"employed": false
},
{
"firstName": "Nancy",
"lastName": "Waters",
"company": "Fuelton",
"employed": false
}
];
/* End Function Definitions */
/* Begin Logic */
});