Permalink
Cannot retrieve contributors at this time
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?
TeamDbAwesome/TeamDBAwesome/TeamDBAwesome/js/userController.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
135 lines (122 sloc)
4.31 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 */ | |
}); |