apollodec/Apollo/assets/js/controllers/activityCtrl.js
venbatechnologies@gmail.com 6c9b31762d trainee screen access
2018-08-18 14:59:48 +05:30

301 lines
10 KiB
JavaScript
Executable File

'use strict';
/**
* controllers for ng-table
* Simple table with sorting and filtering on AngularJS
*/
// var helloApp = angular.module("helloApp", []);
app.controller("activityCtrl", ["$scope", "toaster", "$filter", "API_POINTS", "$localStorage", "$http", "$state", 'ipCookie', function ($scope, toaster, $filter, apiPoint, $localStorage, $http, $state, ipCookie) {
// get local cliend details
var localDetail = JSON.parse(localStorage.getItem('localObj'));
var localDetails = ipCookie('cookiechk');
// $scope.initHead = function() {
// // alert();
// const LOCALTYPE = localDetail.localType;
// if (localDetail != null && (LOCALTYPE == 'R003' || LOCALTYPE == 'R004' )) {
// }else {
// if((localDetail != null) && (LOCALTYPE !='R001')) {
// $state.go('app.dashboard');
// } else {
// ipCookie.remove('cookiechk');
// window.localStorage.clear();
// $state.go('login.signin');
// }
// }
// }
$scope.companies = {
"ActivityID": "",
"ActivityName": "",
"Description": "",
"switchsetting": true,
"status":""
};
/*
* edit activity details
* created by surendiran
* */
$scope.p = {
"status":""
}
$scope.editId = -1;
$scope.setEditId = function (p) {
$scope.localStatusDetails="";
$scope.localStatusDetails = JSON.parse(localStorage.getItem('localStatusDetails'));
$scope.editId = p.ActivityID;
$scope.editStatusList = [];
angular.forEach(p.statusDetails, function (values, keys) {
$scope.editStatusList.push(values.ListCode);
$scope.editData = {
name: values.ListName,
id: values.ListCode
};
var subresult = $filter('filter')($scope.localStatusDetails, $scope.editData);
if(subresult.length==0){
$scope.localStatusDetails.push($scope.editData);
}
})
$scope.viewEditStatus = {
list: $scope.editStatusList,
}
$scope.viewId = -1;
};
/*
* cancel edit div
* created by surendiran
* */
$scope.cancel = function () {
$scope.init();
$scope.editId = -1;
};
// sorting function for table params
$scope.sort = function(keyname){
$scope.sortKey = keyname; //set the sortKey to the param passed
$scope.reverse = !$scope.reverse; //if true make it false and vice versa
}
$scope.activityForm = {
submit: function (form, myModel,loading) {
var firstError = null;
if (form.$invalid) {
var field = null, firstError = null;
for (field in form) {
if (field[0] != '$') {
if (firstError === null && !form[field].$valid) {
firstError = form[field].$name;
}
if (form[field].$pristine) {
form[field].$dirty = true;
}
}
}
angular.element('.ng-invalid[name=' + firstError + ']').focus();
// swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error");
} else {
if(myModel.status.length > 0) {
$scope.ldloading = {};
$scope.ldloading[loading.replace('-', '_')] = true;
var addactivity = {
method: 'POST',
url: apiPoint.url + 'addActivityDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
activityID: myModel.ActivityID,
activityName: myModel.ActivityName,
description: myModel.Description,
status: myModel.switchsetting,
activityStatus:myModel.status,
createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
branchCode:JSON.parse(localStorage.getItem('localObj')).localBranchID
}
};
$http(addactivity).then(function (response) {
if (response.data.status == 200 && response.data.activityStatus) {
$scope.ldloading[loading.replace('-', '_')] = false;
$scope.init();
swal("","Activity details added successfully.", "success");
$state.go($state.current, {}, { reload: true });
}
else if(response.data.activityStatus==false){
swal("",response.data.message, "warning");
}
else {
$scope.ldloading[loading.replace('-', '_')] = false;
swal(" ", "Something went wrong.please try again.", "error");
}
});
} else {
swal("Warning!", "Status are required", "warning");
$scope.companies.status = "";
}
}
}
};
/*
*get Activity details when page loading called from view file
*
* created by surendiran
* */
$scope.statusList = [];
$scope.loader = '';
$scope.emptyData = '';
$scope.init = function () {
var logcheck = JSON.parse(localStorage.getItem('localObj'));
const LOCALTYPE = logcheck.localType;
if (logcheck != null && (LOCALTYPE == 'R003' || LOCALTYPE == 'R004' || LOCALTYPE =='R002' || LOCALTYPE =='R005' )) {
console.log("if");
}else {
if(logcheck != null && LOCALTYPE !='R001') {
console.log("else if");
$state.go('app.dashboard');
} else {
console.log("else else");
//ipCookie.remove('cookiechk');
window.localStorage.clear();
$state.go('login.signin');
}
}
localStorage.setItem('localStatusDetails', '');
var getActivity = {
method: 'POST',
url: apiPoint.url + 'getActivityDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
branchCode:JSON.parse(localStorage.getItem('localObj')).localBranchID
}
};
$http(getActivity).then(function (response) {
if (response.data.status == 200 && response.data.activityStatus) {
$scope.statusList = [];
$scope.emptyData = true;
$scope.loader = true;
$scope.activityInfo = response.data.details;
$scope.masterActivityStatus=response.data.masterStatusList;
angular.forEach($scope.masterActivityStatus, function (values, keys) {
$scope.statusData = {
name: values.ListName,
id: values.ListCode
};
$scope.statusList.push($scope.statusData);
})
} else {
$scope.emptyData = false;
$scope.loader = false;
$scope.activityInfo = "";
$scope.masterActivityStatus=response.data.masterStatusList;
angular.forEach($scope.masterActivityStatus, function (values, keys) {
$scope.statusData = {
name: values.ListName,
id: values.ListCode
};
$scope.statusList.push($scope.statusData);
})
}
localStorage.setItem('localStatusDetails', JSON.stringify($scope.statusList));
});
};
/*
* update the Activity details
* created by Surendiran
* */
$scope.updateActivity = function (myModel,listStatus, form, loading) {
var firstError = null;
if (form.$invalid) {
var field = null, firstError = null;
for (field in form) {
if (field[0] != '$') {
if (firstError === null && !form[field].$valid) {
firstError = form[field].$stop_name;
}
if (form[field].$pristine) {
form[field].$dirty = true;
}
}
}
angular.element('.ng-invalid[name=' + firstError + ']').focus();
} else {
$scope.ldloading3 = {};
$scope.ldloading3[loading.replace('-', '_')] = true;
var update = {
method: 'POST',
url: apiPoint.url + 'updateActivityDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
activityID: myModel.ActivityID,
activityName: myModel.ActivityName,
description: myModel.Description,
status: myModel.IsActive,
activityStatus:listStatus.list,
updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
branchCode:JSON.parse(localStorage.getItem('localObj')).localBranchID
}
};
$http(update).then(function (response) {
if (response.data.status==200 && response.data.activityStatus) {
$scope.ldloading3[loading.replace('-', '_')] = false;
swal(" "," Updated Successfully", "success");
$scope.init();
$scope.editId = -1;
}
else if(response.data.activityStatus==false){
swal("",response.data.message, "warning");
}
else {
$scope.ldloading3[loading.replace('-', '_')] = false;
swal(" ","Something went wrong.please try again", "error");
}
});
}
};
}]);