217 lines
7.6 KiB
JavaScript
Executable File
217 lines
7.6 KiB
JavaScript
Executable File
'use strict';
|
|
/**
|
|
* controllers used for the session
|
|
*/
|
|
|
|
app.controller('sessionCtrl', ["$scope", "$localStorage", "$state", 'ipCookie', '$window', '$location', function ($scope, $localStorage, $state, ipCookie, $window, $location) {
|
|
/**
|
|
* checking the session settings and logout for the function
|
|
*/
|
|
|
|
// client side logined details
|
|
var localDetail = JSON.parse(localStorage.getItem('localObj'));
|
|
var localDetails = ipCookie('cookiechk');
|
|
|
|
// $window.location.reload();
|
|
|
|
$scope.getLoginDash = '';
|
|
|
|
if (localDetail != null) {
|
|
if (localDetail.localType == 'R004') {
|
|
$scope.getLoginDash = 'superAdmin';
|
|
} else if (localDetail.localType == 'R003') {
|
|
$scope.getLoginDash = 'Admin';
|
|
$scope.is_active_DayBookAprlAccess = localDetail.is_DayBookApproval_Access;
|
|
} else if (localDetail.localType == 'R002') {
|
|
$scope.getLoginDash = 'staff';
|
|
$scope.is_active_DayBookAprlAccess = localDetail.is_DayBookApproval_Access;
|
|
}
|
|
else if (localDetail.localType == 'R001') {
|
|
$scope.getLoginDash = 'student';
|
|
}else if (localDetail.localType == 'R005') {
|
|
$scope.getLoginDash = 'trainee';
|
|
}
|
|
} else {
|
|
$state.go('login.signin');
|
|
}
|
|
|
|
// logout clear client side details
|
|
$scope.logOut = function () {
|
|
ipCookie.remove('cookiechk');
|
|
$window.localStorage.clear();
|
|
$state.go('login.signin');
|
|
}
|
|
|
|
// check login user as Super Admin
|
|
$scope.checkSuperAdmin = function () {
|
|
var inlocalDetails = JSON.parse(localStorage.getItem('localObj'));
|
|
var inlocalDetailss = ipCookie('cookiechk');
|
|
if (inlocalDetails != null) {
|
|
|
|
if (inlocalDetails.localType == 'R004' && inlocalDetailss.localType == 'R004') {
|
|
} else {
|
|
if (inlocalDetails.localType == '' && inlocalDetailss.localType == '') {
|
|
ipCookie.remove('cookiechk');
|
|
$window.localStorage.clear();
|
|
$state.go('login.signin');
|
|
} else {
|
|
$location.url('/dashboard').replace();
|
|
$window.location.reload();
|
|
$state.go('app.dashboard');
|
|
}
|
|
// alert(inlocalDetails.localType);
|
|
// $state.go('login.signin');
|
|
// $state.go($state.current, {}, { reload: true });
|
|
|
|
}
|
|
} else {
|
|
$state.go('login.signin');
|
|
}
|
|
}
|
|
|
|
// check login user as Admin
|
|
$scope.checkAdmin = function () {
|
|
var inlocalDetails = JSON.parse(localStorage.getItem('localObj'));
|
|
var inlocalDetailss = ipCookie('cookiechk');
|
|
if (inlocalDetails != null) {
|
|
|
|
if (inlocalDetails.localType == 'R003' && inlocalDetailss.localType == 'R003') {
|
|
|
|
// console.log('if')
|
|
} else {
|
|
if (inlocalDetails.localType == '' && inlocalDetailss.localType == '') {
|
|
ipCookie.remove('cookiechk');
|
|
$window.localStorage.clear();
|
|
$state.go('login.signin');
|
|
} else {
|
|
$location.url('/dashboard').replace();
|
|
$window.location.reload();
|
|
$state.go('app.dashboard');
|
|
}
|
|
// alert(inlocalDetails.localType);
|
|
// $state.go('login.signin');
|
|
// $state.go($state.current, {}, { reload: true });
|
|
|
|
}
|
|
} else {
|
|
$state.go('login.signin');
|
|
}
|
|
}
|
|
|
|
// check login user as Staff
|
|
$scope.checkStaff = function () {
|
|
var inlocalDetails = JSON.parse(localStorage.getItem('localObj'));
|
|
var inlocalDetailss = ipCookie('cookiechk');
|
|
console.log(inlocalDetails);
|
|
|
|
if (inlocalDetails != null) {
|
|
|
|
if ((inlocalDetails.localType == 'R002' && inlocalDetailss.localType == 'R002') || (inlocalDetails.localType == 'R005' && inlocalDetailss.localType == 'R005')) {
|
|
console.log('if');
|
|
} else {
|
|
|
|
if (inlocalDetails.localType == '' && inlocalDetailss.localType == '') {
|
|
console.log('else if');
|
|
ipCookie.remove('cookiechk');
|
|
$window.localStorage.clear();
|
|
$state.go('login.signin');
|
|
} else {
|
|
|
|
console.log('else else')
|
|
$location.url('/dashboard').replace();
|
|
$window.location.reload();
|
|
$state.go('app.dashboard');
|
|
}
|
|
// alert(inlocalDetails.localType);
|
|
// $state.go('login.signin');
|
|
// $state.go($state.current, {}, { reload: true });
|
|
|
|
}
|
|
} else {
|
|
$state.go('login.signin');
|
|
}
|
|
}
|
|
}]);
|
|
|
|
app.controller('topnavCtrl', ["$scope", "$http", "API_POINTS", "$localStorage", "$state", 'ipCookie', '$window', function ($scope, $http, apiPoint, $localStorage, $state, ipCookie, $window) {
|
|
/**
|
|
* top nav bar details load
|
|
* by : kdk
|
|
*/
|
|
|
|
var localDetail = JSON.parse(localStorage.getItem('localObj'));
|
|
var localDetails = ipCookie('cookiechk');
|
|
$scope.init = function () {
|
|
// $window.location.reload();
|
|
if (localDetail != null) {
|
|
$scope.getProfile();
|
|
} else {
|
|
|
|
}
|
|
}
|
|
|
|
$scope.loginUser = {
|
|
'staffID': '',
|
|
'fName': '',
|
|
'lName': '',
|
|
'mobileNumber': '',
|
|
'gender': '',
|
|
'branchCode': '',
|
|
'branchList': '',
|
|
};
|
|
|
|
// client side logined details
|
|
$scope.getProfile = function () {
|
|
var req = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'employee/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
employeeLoginID: localDetails.localUserID,
|
|
}
|
|
};
|
|
$http(req).then(function (response) {
|
|
if (response.data.empStatus == true) {
|
|
/*
|
|
* Get Top Nav user details
|
|
*/
|
|
$scope.resultData = response.data.details;
|
|
$scope.loginImage = $scope.resultData.ProfilePicPath;
|
|
$scope.loginUser = {
|
|
'staffID': $scope.resultData.StaffID,
|
|
'fName': $scope.resultData.Firstname,
|
|
'lName': $scope.resultData.Lastname,
|
|
'mobileNumber': $scope.resultData.MobileNumber,
|
|
'gender': $scope.resultData.Gender,
|
|
'branchCode': $scope.resultData.BranchCode,
|
|
'branchList': response.data.branch_details,
|
|
};
|
|
if (response.data.branch_details.length > 0) {
|
|
var currArr = response.data.branch_details;
|
|
$scope.getCurrentBran = currArr.find(item => item.BranchCode === localDetails.localBranchID);
|
|
}
|
|
|
|
} else {
|
|
}
|
|
});
|
|
};
|
|
|
|
|
|
$scope.upDateLocalBran = function (Id, listCode, financeAccess) {
|
|
|
|
localDetail.localBranchID = Id;
|
|
localDetails.localBranchID = Id;
|
|
localDetail.localType = listCode;
|
|
localDetails.localType = listCode;
|
|
localDetail.is_DayBookApproval_Access = financeAccess;
|
|
localDetails.is_DayBookApproval_Access = financeAccess;
|
|
ipCookie('cookiechk', localDetails, { expires: 21 });
|
|
localStorage.setItem('localObj', JSON.stringify(localDetail));
|
|
$window.location.reload();
|
|
// alert(JSON.stringify(localDetail));
|
|
}
|
|
|
|
}]);
|