se-hub/templates/js/controllers/mainController.js

90 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-05-09 19:00:14 +00:00
angular.module('SeHub')
.controller('mainController', ['$scope', '$rootScope', 'dataService','apiService', '$cookies', '$cookieStore', '$location', '$window',
2015-05-09 19:00:14 +00:00
function($scope, $rootScope, dataService, apiService, $cookies, $cookieStore, $location, $window) {
2015-06-17 21:04:36 +00:00
top.setIsEnterd = true;
2015-06-17 17:14:53 +00:00
var token = $cookies['com.sehub.www'];
2015-05-09 19:00:14 +00:00
2015-06-17 17:14:53 +00:00
$scope.loadingData = true;
$scope.isInRegisterMode = false;
apiService.getUserByToken(token).success(function(data) {
if (data.message == 'No User Found') {
console.error("No User Found!");
}
$scope.loadingData = false;
2015-06-17 17:14:53 +00:00
$scope.user = data;
dataService.initService($scope); //Start Data Sync Service (For User)
2015-06-17 17:14:53 +00:00
console.log(data);
if ($scope.user.isFirstLogin) {
$scope.menuObj = {};
$scope.isInRegisterMode = true;
$scope.loadingData = false;
$location.path('/register')
} else {
$location.path('/home')
}
});
2015-05-09 19:00:14 +00:00
2015-06-17 17:14:53 +00:00
$scope.menuItems = [{
"title": "Dash Board",
"icon": "fa fa-tachometer",
"style": "selected",
"route": "/home"
}, {
"title": "My Campuses",
"icon": "fa fa-university",
"style": "",
"route": "/campuses"
}, {
"title": "My Classes",
"icon": "fa fa-graduation-cap",
"style": "",
"route": "/myClasses"
2015-06-17 17:14:53 +00:00
}, {
"title": "My Projects",
"icon": "fa fa-cube",
"style": "",
"route": "/projects"
2015-06-17 17:14:53 +00:00
}, {
"title": "Tasks",
"icon": "fa fa-clipboard",
"style": "",
"route": "/tasks"
2015-06-17 17:14:53 +00:00
}, {
"title": "Settings",
"icon": "fa fa-cogs",
"style": "",
"route": "/Settings"
}, {
"title": "Log Out",
"icon": "fa fa-power-off",
"style": "",
"route": "/logout"
}];
2015-06-17 17:14:53 +00:00
$scope.menuClicked = function(item) {
var route = ""
if (item.title == "Log Out") {
console.info('Logging Out!');
$cookieStore.remove('com.sehub.www');
$window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page
}
2015-06-17 17:14:53 +00:00
for (var i = $scope.menuItems.length - 1; i >= 0; i--) {
if ($scope.menuItems[i].title === item.title) {
$scope.menuItems[i].style = "selected";
route = $scope.menuItems[i].route;
} else {
$scope.menuItems[i].style = "";
}
};
2015-06-17 21:04:36 +00:00
top.setIsEnterd = false;
2015-06-17 17:14:53 +00:00
$location.path(route);
}
2015-06-17 17:14:53 +00:00
}
]);