apollodec/Apollo/assets/js/controllers/studentStatusUpdateCtrl.js
venbatechnologies@gmail.com 61cf23e152 branch status issue fixed
2017-12-29 18:10:55 +05:30

157 lines
5.0 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("studentStatusUpdateCtrl", ["$scope", "toaster", "$filter", "API_POINTS", "$localStorage", "$http", "$state", function ($scope, toaster, $filter, apiPoint, $localStorage, $http, $state) {
$scope.companies = {
"ActivityID": "",
"ActivityName": "",
"switchsetting": true,
};
/*
* cancel edit div
* created by kms
* */
$scope.cancel = function () {
$scope.init();
$scope.editId = -1;
};
/*
*get Activity details when page loading called from view file
*
* created by karthi
* */
$scope.statusList = [];
$scope.loader = '';
$scope.emptyData = '';
$scope.init = function () {
var getActivity = {
method: 'POST',
url: apiPoint.url + 'getDefaultActivityDetails/',
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.statusList = [];
$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);
})
}
});
};
// 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.editId = -1;
$scope.setEditId = function (p) {
$scope.editId = p.ActivityID;
$scope.editStatusList = [];
angular.forEach(p.statusDetails, function (values, keys) {
$scope.editStatusList.push(values.ListCode);
})
$scope.viewEditStatus = {
list: $scope.editStatusList,
}
};
/*
* update the default Activity details
* created by kms
* */
$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 + 'updateDefaultActivityDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
activityID: myModel.ActivityID,
activityName: myModel.ActivityName,
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("Success!", response.data.message, "success");
$scope.init();
$scope.editId = -1;
} else {
$scope.ldloading3[loading.replace('-', '_')] = false;
swal("Failed!", response.data.message, "error");
}
});
}
};
}]);