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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263 | 1×
1×
| angular.module('coopEval').controller('ApplicationController', ApplicationController);
function ApplicationController($scope, $rootScope, $state, $location, $anchorScroll, $window, appService) {
//$scope.statusChanged = function(status) {
// $rootScope.$broadcast("Auth.status", status);
// return this;
//};
//
//$rootScope.$on("Auth.status", function() {
// $state.reload();
//});
//
//// Enumerate routes that don't need authentication
//var routesThatDontRequireAuth = ['/employers/login','/page-not-found','/not-authorized','/error','/logout'];
//
//// Check if current location matches route
//var routeClean = function (currentRoute) {
// for (var i in routesThatDontRequireAuth) {
// if (currentRoute.indexOf(routesThatDontRequireAuth[i]) > -1) {
// return true;
// }
// }
// return false;
//};
//
//// Check if current location matches route
//var canAccess = function (currentRoute, userType) {
// if (userType == 'Student' && currentRoute.indexOf('/students') > -1) {
// return true;
// }
// else if (userType == 'Employer' && currentRoute.indexOf('/employers') > -1) {
// return true;
// }
// else if (userType == 'Admin' && currentRoute.indexOf('/administration') > -1) {
// return true;
// }
// else if (userType == 'Department' && currentRoute.indexOf('/departments') > -1) {
// return true;
// }
// return false;
//};
//
//// Check if current route is a shibbed route
//var isShibbed = function (currentRoute) {
// if (currentRoute.indexOf('/students') > -1) {
// return true;
// }
// else if (currentRoute.indexOf('/administration') > -1) {
// return true;
// }
// else if (currentRoute.indexOf('/departments') > -1) {
// return true;
// }
// return false;
//};
//
////checks if the route is an employer route
//var isEmployerRoute= function (currentRoute) {
// if (currentRoute.indexOf('/employers') > -1) {
// return true;
// }
// return false;
//};
//
//$scope.authenticate = function () {
// if ($rootScope.userType == null && !routeClean($location.url())) {
// return false;
// } else if ($rootScope.userType != 'None' && !routeClean($location.url())) {
// if (!canAccess($location.url(),$rootScope.userType)) {
// $location.path('/not-authorized');
// return false;
// }
// } else if ($rootScope.userType == 'None' && !routeClean($location.url())) {
// if (isShibbed($location.url())) {
// $window.location.href = 'api/ritauth/shibAuthenicate?route='+$location.url();
// return false;
// } else if (isEmployerRoute($location.url())) {
// $location.path('/employers/login');
// return false;
// } else {
// $location.path('/page-not-found');
// return false;
// }
// }
// return true;
//};
//
//// If a message is currently displayed to the user, reset the
//// message when the user navigates away from the page
//$rootScope.$on('$locationChangeStart', function (event) {
// // If the user type is null, get the type of user currently logged in to the system
// if ($rootScope.userType == null && !routeClean($location.url())) {
// appService.getUserType()
// .success(function(result) {
// $rootScope.userType = result.userType;
// if (!$scope.authenticate()) {
// // TODO
// }
// else {
// $scope.statusChanged();
// }
// });
// event.preventDefault();
// return;
// }
// else if (!$scope.authenticate()) {
// event.preventDefault();
// return;
// }
//
// // If a message is displayed to the user, reset the message on location change (if necessary)
// if ($rootScope.message && $rootScope.message.location != $location.path()) {
// $rootScope.message = undefined;
// }
//});
//
// Resets the message when the user closes the alert
$rootScope.closeAlert = function () {
$rootScope.message = undefined;
};
var navTree = {
Student: [
{ name: 'Overview', state: 'students.overview' },
{ name: 'User Manual', state: 'students.user-manual' }
],
Employer: [
{ name: 'Overview', state: 'employers.overview' },
{ name: 'User Manual', state: 'employers.user-manual' }
],
Evaluator: [
{ name: 'Evaluations', state: 'departments.search-evaluations' },
{ name: 'Reports', state: 'departments.reports' },
{ name: 'Emails', state: 'departments.emails' },
{ name: 'User Manual', state: 'departments.user-manual' }
],
Administrator: [
{
name: 'Evaluations',
subItems: [
{ name: 'Search Submitted/Pending Evaluations', state: 'administration.search-evaluations' },
{ name: 'Evaluation Management', state: 'administration.evaluations.manage' }
]
},
{ name: 'Reports', state: 'administration.reports' },
{
name: 'Emails',
subItems: [
{ name: 'Schedule Email Notifications', state: 'administration.emails.schedule' }
//{ name: 'Email Status', href: 'administration/', state: 'administration.emails.status' },
//{ name: 'Student Notification', href: 'administration/', state: 'administration.emails' },
//{ name: 'Student Confirmation', href: 'administration/' },
//{ name: 'Student Rejection', href: 'administration/' },
//{ name: 'Employer Notification', href: 'administration/' },
//{ name: 'Employer Confirmation', href: 'administration/' }
]
},
{
name: 'Users',
subItems: [
{ name: 'Administrators', state: 'administration.user-management-admin' },
{ name: 'Department Users', state: 'administration.user-management-dept' },
{ name: 'Transfer Department Users', state: 'administration.transfer-dept-users' },
{ name: 'College Management', state: 'administration.college-management' },
{ name: 'Department Management', state: 'administration.department-management' }
]
},
{
name: 'Forms',
subItems: [
{ name: 'Assign Form', state: 'administration.assign-form' },
{ name: 'Student Forms', state: 'administration.manage-student-forms' },
{ name: 'Employer Forms', state: 'administration.manage-employer-forms' }
]
},
//{
// name: 'Utilities',
// subItems: [
// { name: 'Initialize Next Term', href: 'administration/' },
// { name: 'Update Status', href: 'administration/' }
// ]
//},
{ name: 'User Manual', state: 'administration.user-manual' }
]
};
// Define navigation items based on user type
$scope.navigationItems = function () {
if ($state.includes('students')) {
return _.result(navTree, 'Student');
}
if ($state.includes('employers')) {
return _.result(navTree, 'Employer');
}
if ($state.includes('departments')) {
return _.result(navTree, 'Evaluator');
}
if ($state.includes('administration')) {
return _.result(navTree, 'Administrator');
}
return [];
};
// Placeholders to avoid "TypeError: Cannot read property ... of undefined" errors
$rootScope.searchCriteria = {
studentEvalStatusList: [],
approvalStatusList: [],
employerEvalStatusList: []
};
/**
* Determines whether the given navigation item should be assigned the "active" CSS class.
* @param navigationItem
* @returns {boolean}
*/
$scope.isActive = function (navigationItem) {
if (navigationItem.href) {
return '/' + navigationItem.href == $location.path();
} else {
if (navigationItem.subItems) {
for (var i = 0; i < navigationItem.subItems.length; i++) {
if ('/' + navigationItem.subItems[i].href == $location.path()) {
return true;
}
}
return false;
}
}
};
/**
* Logs the user currently signed in out of the application.
*/
$scope.logOut = function () {
appService.logOut()
.success(function (result) {
if ($rootScope.userType == 'Employer') {
$rootScope.userType = null;
$location.path('/employers/login');
} else {
$rootScope.userType = null;
$location.path('/logout');
}
});
};
/**
* Scroll to the given id
*
* @param id - href id without a #
*/
$scope.scrollTo = function (id) {
$location.hash(id);
$anchorScroll();
};
appService.getUserInfo().then(function (data) {
$scope.userType = _.result(data, 'roles[0].role');
});
}
|