357 lines
12 KiB
JavaScript
Executable File
357 lines
12 KiB
JavaScript
Executable File
'use strict';
|
|
/**
|
|
* controllers used for the session
|
|
*/
|
|
|
|
app.controller('sessionCtrl', ["$scope", "$sessionStorage", "$state", 'ipCookie', '$window', '$location', function ($scope, $sessionStorage, $state, ipCookie, $window, $location) {
|
|
/**
|
|
* checking the session settings and logout for the function
|
|
*/
|
|
|
|
// client side logined details
|
|
var localDetail = JSON.parse(sessionStorage.getItem('localObj'));
|
|
var localDetails = ipCookie('cookiechk');
|
|
|
|
// $window.location.reload();
|
|
|
|
$scope.getLoginDash = '';
|
|
$scope.is_active_CallTrackAccess = '0';
|
|
|
|
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;
|
|
$scope.is_active_CallTrackAccess = localDetail.is_CalltrackApproval_Access;
|
|
|
|
} else if (localDetail.localType == 'R002') {
|
|
$scope.getLoginDash = 'staff';
|
|
$scope.is_active_DayBookAprlAccess = localDetail.is_DayBookApproval_Access;
|
|
$scope.is_active_CallTrackAccess = localDetail.is_CalltrackApproval_Access;
|
|
}
|
|
else if (localDetail.localType == 'R001') {
|
|
$scope.getLoginDash = 'student';
|
|
}else if (localDetail.localType == 'R005') {
|
|
$scope.getLoginDash = 'trainee';
|
|
$scope.is_active_CallTrackAccess = localDetail.is_CalltrackApproval_Access;
|
|
}
|
|
|
|
// console.log($scope.is_active_CallTrackAccess);
|
|
} else {
|
|
$state.go('login.signin');
|
|
}
|
|
|
|
// logout clear client side details
|
|
$scope.logOut = function () {
|
|
ipCookie.remove('cookiechk');
|
|
$window.sessionStorage.clear();
|
|
$state.go('login.signin');
|
|
}
|
|
|
|
// check login user as Super Admin
|
|
$scope.checkSuperAdmin = function () {
|
|
var inlocalDetails = JSON.parse(sessionStorage.getItem('localObj'));
|
|
var inlocalDetailss = ipCookie('cookiechk');
|
|
|
|
|
|
|
|
var idletime = '';
|
|
|
|
this.lastActiveTime = new Date();
|
|
window.onclick = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onmousemove = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onkeypress = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onscroll = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
|
|
let idleTimer_k = window.setInterval(CheckIdleTime, 10000);
|
|
|
|
function CheckIdleTime() {
|
|
//returns idle time every 10 seconds
|
|
let dateNowTime = new Date().getTime();
|
|
let lastActiveTime = new Date(this.lastActiveTime).getTime();
|
|
let remTime = Math.floor((dateNowTime-lastActiveTime)/ 1000);
|
|
idletime = remTime;
|
|
// converting from milliseconds to seconds
|
|
// console.log("Idle since "+remTime+" Seconds Last active at "+this.lastActiveTime);
|
|
if(remTime>'10800')
|
|
{
|
|
console.log('inremtime')
|
|
ipCookie.remove('cookiechk');
|
|
$window.sessionStorage.clear();
|
|
$state.go('login.signin');
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inlocalDetails != null) {
|
|
|
|
if (inlocalDetails.localType == 'R004' && inlocalDetailss.localType == 'R004') {
|
|
} else {
|
|
if (inlocalDetails.localType == '' && inlocalDetailss.localType == '') {
|
|
ipCookie.remove('cookiechk');
|
|
$window.sessionStorage.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(sessionStorage.getItem('localObj'));
|
|
var inlocalDetailss = ipCookie('cookiechk');
|
|
|
|
|
|
var idletime = '';
|
|
|
|
this.lastActiveTime = new Date();
|
|
window.onclick = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onmousemove = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onkeypress = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onscroll = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
|
|
let idleTimer_k = window.setInterval(CheckIdleTime, 10000);
|
|
|
|
function CheckIdleTime() {
|
|
//returns idle time every 10 seconds
|
|
let dateNowTime = new Date().getTime();
|
|
let lastActiveTime = new Date(this.lastActiveTime).getTime();
|
|
let remTime = Math.floor((dateNowTime-lastActiveTime)/ 1000);
|
|
idletime = remTime;
|
|
// converting from milliseconds to seconds
|
|
//console.log("Idle since "+remTime+" Seconds Last active at "+this.lastActiveTime);
|
|
if(remTime>'10800')
|
|
{
|
|
console.log('inremtime')
|
|
ipCookie.remove('cookiechk');
|
|
$window.sessionStorage.clear();
|
|
$state.go('login.signin');
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (inlocalDetails != null) {
|
|
|
|
if (inlocalDetails.localType == 'R003' && inlocalDetailss.localType == 'R003') {
|
|
|
|
// console.log('if')
|
|
} else {
|
|
if (inlocalDetails.localType == '' && inlocalDetailss.localType == '') {
|
|
ipCookie.remove('cookiechk');
|
|
$window.sessionStorage.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(sessionStorage.getItem('localObj'));
|
|
var inlocalDetailss = ipCookie('cookiechk');
|
|
|
|
|
|
var idletime = '';
|
|
|
|
this.lastActiveTime = new Date();
|
|
window.onclick = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onmousemove = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onkeypress = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
window.onscroll = function () {
|
|
this.lastActiveTime= new Date();
|
|
};
|
|
|
|
let idleTimer_k = window.setInterval(CheckIdleTime, 10000);
|
|
|
|
function CheckIdleTime() {
|
|
//returns idle time every 10 seconds
|
|
let dateNowTime = new Date().getTime();
|
|
let lastActiveTime = new Date(this.lastActiveTime).getTime();
|
|
let remTime = Math.floor((dateNowTime-lastActiveTime)/ 1000);
|
|
idletime = remTime;
|
|
// converting from milliseconds to seconds
|
|
//console.log("Idle since "+remTime+" Seconds Last active at "+this.lastActiveTime);
|
|
if(remTime>'10800')
|
|
{
|
|
console.log('inremtime')
|
|
ipCookie.remove('cookiechk');
|
|
$window.sessionStorage.clear();
|
|
$state.go('login.signin');
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (inlocalDetails != null) {
|
|
|
|
if ((inlocalDetails.localType == 'R002' && inlocalDetailss.localType == 'R002') || (inlocalDetails.localType == 'R005' && inlocalDetailss.localType == 'R005')) {
|
|
} else {
|
|
|
|
if (inlocalDetails.localType == '' && inlocalDetailss.localType == '') {
|
|
ipCookie.remove('cookiechk');
|
|
$window.sessionStorage.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');
|
|
}
|
|
};
|
|
}]);
|
|
|
|
app.controller('topnavCtrl', ["$scope", "$http", "API_POINTS", "$sessionStorage", "$state", 'ipCookie', '$window', function ($scope, $http, apiPoint, $sessionStorage, $state, ipCookie, $window) {
|
|
/**
|
|
* top nav bar details load
|
|
* by : kdk
|
|
*/
|
|
|
|
var localDetail = JSON.parse(sessionStorage.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);
|
|
}
|
|
|
|
//console.log($scope.loginUser);return false;
|
|
|
|
} else {
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.upDateLocalBran = function (Id, listCode, financeAccess,calltrackAccess) {
|
|
//console.log(calltrackAccess);return false;
|
|
var call = calltrackAccess;
|
|
|
|
//alert(call)
|
|
localDetail.localBranchID = Id;
|
|
localDetails.localBranchID = Id;
|
|
localDetail.localType = listCode;
|
|
localDetails.localType = listCode;
|
|
localDetail.is_DayBookApproval_Access = financeAccess;
|
|
localDetails.is_DayBookApproval_Access = financeAccess;
|
|
localDetail.is_CalltrackApproval_Access = call;
|
|
localDetails.is_CalltrackApproval_Access = call;
|
|
|
|
ipCookie('cookiechk', localDetails, { expires: 21 });
|
|
sessionStorage.setItem('localObj', JSON.stringify(localDetail));
|
|
$window.location.reload();
|
|
//alert(JSON.stringify(localDetail));
|
|
|
|
}
|
|
|
|
}]);
|