This repository has been archived on 2024-12-23. You can view files and clone it, but cannot push or open issues or pull requests.
se-hub/templates/js/controllers/profileController.js

76 lines
2.1 KiB
JavaScript
Raw Normal View History

angular.module('SeHub')
.controller('profileController', ['$scope', '$rootScope', 'dataService', 'apiService',
'$cookies', '$location', '$routeParams',
function($scope, $rootScope, dataService, apiService, $cookies, $location, $routeParams) {
2015-06-17 19:46:26 +00:00
var token = $cookies['com.sehub.www'];
var id = $routeParams.id;
2015-06-17 19:46:26 +00:00
$scope.loadingData = true;
$scope.isInRegisterMode = false;
$scope.userExists = false;
$scope.isUser = false;
$scope.title = "Profile";
apiService.getUserById(token, id).success(function(data) {
if (!data) {
2015-06-17 19:46:26 +00:00
console.error("No User Found!");
$scope.loadingData = false;
return;
2015-06-17 19:46:26 +00:00
}
$scope.user = data;
$scope.userExists = true;
apiService.getCampusesByUserId(token, id)
.success(function(data) {
$scope.campuses = data;
console.log(data);
apiService.getCoursesByUserID(token, id)
.success(function(data) {
$scope.courses = data;
}).error(function(err) {
console.error('In apiService.getCoursesByUserID', err);
});
$scope.loadingData = false;
}).error(function(err) {
console.error(err);
console.error("++++++++++++++++++++");
});
$scope.labels = data.stats.labels;
//$scope.series = ['Project A', 'Project B'];
$scope.data = data.stats.data;
$scope.isUser = $scope.$parent.user.id.toString() /*The Actual User*/ === $routeParams.id /*The Profile User*/ ;
2015-06-17 19:46:26 +00:00
});
2015-06-17 19:46:26 +00:00
$scope.isEditMode = false;
$scope.profileMode = "Edit Profile";
$scope.profileModeIcon = "fa fa-pencil";
2015-06-17 19:46:26 +00:00
$scope.changeProfileMode = function() {
$scope.isEditMode = !$scope.isEditMode;
if ($scope.isEditMode) {
$scope.profileMode = "Save Profile";
$scope.profileModeIcon = "fa fa-floppy-o";
} else {
apiService.updateUser(token, $scope.user).success(function(data) {
console.info('User Saved');
dataService.userBrodcast($scope.user);
}).error(function(e) {
console.error('Fail To Save User');
});
2015-06-17 19:46:26 +00:00
$scope.profileMode = "Edit Profile";
$scope.profileModeIcon = "fa fa-pencil";
}
}
2015-06-17 19:46:26 +00:00
}
]);