-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
117 lines (99 loc) · 3.59 KB
/
app.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
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
angular.module('kinder-app', [
'ui.bootstrap',
'ui.utils',
'ngRoute',
'ngAnimate',
'ui.select',
'ngFileUpload',
'firebase',
'ngMaterial',
'ngCookies',
'ngResource',
'ui.router']);
angular.module('kinder-app').config(function ($routeProvider) {
$routeProvider.when('/add-branch', {templateUrl: 'branch/view/add_branch.html'});
$routeProvider.when('/add-school', {templateUrl: 'school/views/add/school-add.html'});
$routeProvider.when('/update-school/:schoolId', {templateUrl: 'school/views/update/school-update.html'});
$routeProvider.when('/list-schools', {templateUrl: 'school/views/list/schools-list.html'});
$routeProvider.when('/admin-signup', {templateUrl: 'admin/views/signup/admin-signup.html'});
$routeProvider.when('/admin-login', {templateUrl: 'admin/views/login/admin-login.html'});
$routeProvider.otherwise({redirectTo: '/admin-login'});
});
angular.module('kinder-app').config(function ($stateProvider, USER_ROLES) {
$stateProvider.state('dashboard', {
url: '/dashboard',
templateUrl: 'dashboard/index.html',
data: {
authorizedRoles: [USER_ROLES.admin, USER_ROLES.editor]
}
});
});
var appSettings = {
};
angular.module('kinder-app').run(function ($rootScope, $location, AUTH_EVENTS, AuthService) {
$rootScope.appSettings = _.defaults(appSettings, {});
$rootScope.safeApply = function (fn) {
var phase = $rootScope.$$phase;
if (phase === '$apply' || phase === '$digest') {
if (fn && (typeof(fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
$rootScope.$on('$stateChangeStart', function (event, next) {
var authorizedRoles = next.data.authorizedRoles;
if (!AuthService.isAuthorized(authorizedRoles)) {
event.preventDefault();
if (AuthService.isAuthenticated()) {
// user is not allowed
$rootScope.$broadcast(AUTH_EVENTS.notAuthorized);
} else {
// user is not logged in
$rootScope.$broadcast(AUTH_EVENTS.notAuthenticated);
}
}
});
});
angular.module('kinder-app').config(function ($httpProvider) {
$httpProvider.interceptors.push([
'$injector',
function ($injector) {
return $injector.get('AuthInterceptor');
}
]);
});
angular.module('kinder-app').factory('AuthInterceptor', function ($rootScope, $q,
AUTH_EVENTS) {
return {
responseError: function (response) {
$rootScope.$broadcast({
401: AUTH_EVENTS.notAuthenticated,
403: AUTH_EVENTS.notAuthorized,
419: AUTH_EVENTS.sessionTimeout,
440: AUTH_EVENTS.sessionTimeout
}[response.status], response);
return $q.reject(response);
}
};
});
angular.module('kinder-app').service('TranslationService', function($resource) {
this.getTranslation = function($scope, language) {
var languageFilePath = 'translation/translation_' + language + '.json';
$resource(languageFilePath).get(function (data) {
$scope.translation = data;
});
};
});
// Manual bootstrap of the application
angular.element(document).ready(function() {
var $http = angular.bootstrap().get('$http');
// Overwrites default settings if a local-settings.json file exists in the top root folder
$http
.get("local-settings.json")
.then(function (response) {
appSettings = response.data;
angular.bootstrap(document, ['kinder-app']);
});
});