-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainController.js
72 lines (64 loc) · 2.42 KB
/
mainController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
var punchIn = angular.module('punchIn', ['ngRoute', 'ngMaterial', 'ngResource'])
.config(function($mdThemingProvider){
$mdThemingProvider.theme('default')
.primaryPalette('blue')
.accentPalette('light-blue');
});
punchIn.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/login',{
templateUrl: 'components/login/loginTemplate.html',
controller: 'loginController'
}).
when('/punch',{
templateUrl: 'components/punch/punchTemplate.html',
controller: 'punchController'
}).
when('/admin', {
templateUrl: 'components/admin/adminTemplate.html',
controller: 'adminController'
}).
otherwise({
redirectTo: '/login'
});
}]);
punchIn.controller('MainController', ['$scope', '$resource', '$rootScope', '$location',
function ($scope, $resource, $rootScope, $location) {
$scope.main = {};
$scope.main.admin = false;
$scope.main.logged_in = false;
$scope.main.employee_id = '';
$scope.main.start_time = '';
$scope.main.employee = '';
$scope.main.vacation_time = '';
$scope.main.used_vacation_time = '';
$rootScope.$on("$routeChangeStart", function(event, next, current) {
if(!$scope.main.logged_in){
if (next.templateUrl !== "components/login/loginTemplate.html") {
$location.path("/login");
}
}else if (!$scope.main.admin) {
if (next.templateUrl !== "components/punch/punchTemplate.html") {
$location.path("/punch");
}
}
});
// $scope.main.on_login = function(){
// $rootScope.$broadcast('show');
// };
//
// var Logout = $resource('admin/logout');
// $scope.logout_user = function(){
// Logout.save({}, function(logout){
// $scope.main.logged_in = false;
// $scope.main.login_name = '';
// $scope.main.current_user = '';
// $scope.main.toolbar = '';
// $location.path('/login-register');
// $rootScope.$broadcast('hide');
// });
// };
//
}]);