247 lines
8.1 KiB
JavaScript
Executable File
247 lines
8.1 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", function ($scope, toaster, $filter, apiPoint, $localStorage, $http, $state) {
|
|
|
|
$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
|
|
}
|
|
};
|
|
$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 {
|
|
$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 () {
|
|
localStorage.setItem('localStatusDetails', '');
|
|
|
|
var getActivity = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getActivityDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID
|
|
}
|
|
};
|
|
$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
|
|
}
|
|
};
|
|
$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 {
|
|
$scope.ldloading3[loading.replace('-', '_')] = false;
|
|
swal(" ","Something went wrong.please try again", "error");
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
}]); |