apollo_developers/assets/js/controllers/courseCtrl.js
venbatechnologies@gmail.com 1809bcf9c9 fixed table for student details
2018-04-23 18:34:11 +05:30

636 lines
22 KiB
JavaScript
Executable File

'use strict';
/**
* controllers for ng-table
* Simple table with sorting and filtering on AngularJS
*/
app.controller('courseCtrl', ["$scope","$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state) {
$scope.myModel = {
"courseCode": "",
"courseName": "",
"universityName":"",
"switchsetting": true,
"ListName": "",
"programListName":"",
"semYear":"",
"feesAmount":"",
"provFess":"",
"transferAmount":"",
"degreeAmount":"",
"migrationAmount":"",
"otherAmount":"",
"specilization1":"",
"specilization2":"",
};
$rootScope.myModel1 = {
"ListName": "",
"programListName":""
};
/*
* edit course details
* created by kms
* */
$rootScope.updateMoreItems = [];
$scope.editId = -1;
$scope.setEditId = function (pid,p) {
$scope.localSubjectDetails="";
$scope.localSubjectDetails = JSON.parse(localStorage.getItem('localSubjectDetails'));
$scope.localUniversityDetails="";
$scope.localUniversityDetails = JSON.parse(localStorage.getItem('localUniversityDetails'));
// getUniversity_FeesDetails();
$rootScope.myModelRegular1="";
$rootScope.myModelLateral1="";
$rootScope.updateMoreItems=[];
// find index for fees type drop down list
angular.forEach(p.feesStructures, function(value, key){
if(value.ProgramType=="P001"){
// single sitting regular course details in model
$rootScope.myModelRegular1 = {
"ID":value.ID,
"FeesType":$scope.feesDetails[0].ListCode,
"FeesName":$scope.feesDetails[0].ListName,
"program":value.ProgramType,
"programName":value.Sem_Year,
"FeesAmount":value.FeesAmount,
};
}
else if(value.ProgramType=="P002"){
// single sitting lateral course details in model
$rootScope.myModelLateral1 = {
"ID":value.ID,
"FeesType":$scope.feesDetails[0].ListCode,
"FeesName":$scope.feesDetails[0].ListName,
"program":value.ProgramType,
"programName":value.Sem_Year,
"FeesAmount":value.FeesAmount,
};
}
else if(value.ProgramType=="Y001"){
// Sem_Year course details in model
$rootScope.updateMoreItems.push({
"ID":value.ID,
"FeesType":$scope.feesDetails[1].ListCode,
"FeesName":$scope.feesDetails[1].ListName,
"program":value.ProgramType,
"programName":value.Sem_Year,
"FeesAmount":value.FeesAmount,
});
}
});
// get inactive university id
var result = $filter('filter')($scope.localUniversityDetails, {'UniversityID':p.UniversityID}) ;
if(result.length==0){
$scope.localUniversityDetails.push({
"UniversityID":p.UniversityID,
"UniversityName":p.UniversityName,
});
}
// get exist subject details
$scope.editSubject = [];
angular.forEach(p.existSubjects, function (values, keys) {
$scope.getDeactiveSub = {
SubjectID: values.SubjectID,
SubjectName: values.SubjectCode +'-'+values.SubjectName
}
$scope.editSubject.push(values.SubjectID);
var subresult = $filter('filter')($scope.localSubjectDetails, $scope.getDeactiveSub);
if(subresult.length==0){
$scope.localSubjectDetails.push($scope.getDeactiveSub);
}
});
$scope.viewSubject = {
list: $scope.editSubject,
}
$scope.editId = pid;
};
/*
* cancel edit div
* created by kms
* */
$scope.cancel = function () {
$rootScope.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
}
/*
* Submit,update and reset course details
* @params myModel
* created by kms
* */
$scope.courseForm = {
submit: function (form, myModel,regularModel,lateralModel,semYearModel,loading,addMoreItems) {
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(semYearModel.program=='Y001' && semYearModel.programName!="" || semYearModel.FeesAmount!=""){
$scope.addMoreItems.push({
program: semYearModel.program,
programName:semYearModel.programName,
FeesName: semYearModel.FeesName,
FeesType:semYearModel.FeesType,
FeesAmount: semYearModel.FeesAmount
});
}
if(regularModel.FeesAmount=='' && lateralModel.FeesAmount=='' && $scope.addMoreItems.length==0){
swal("Failed!", 'Please Enter Single/Sem-Year Fees ', "error");
}
else{
$scope.ldloading1 = {};
$scope.ldloading1[loading.replace('-', '_')] = true;
var addCourse = {
method: 'POST',
url: apiPoint.url + 'addCourseDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
courseCode: myModel.courseCode,
courseName: myModel.courseName,
universityName: myModel.universityName,
feesType:myModel.ListName.ListCode,
status: myModel.switchsetting,
provFess:myModel.provFess,
transferAmount:myModel.transferAmount,
degreeAmount:myModel.degreeAmount,
migrationAmount:myModel.migrationAmount,
otherAmount:myModel.otherAmount,
regularFeesAmounts:regularModel,
lateralFeesAmounts:lateralModel,
semFeesAmounts:$scope.addMoreItems,
createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
specilization1:myModel.specilization1,
specilization2:myModel.specilization2,
subjects:myModel.subject
}
};
$http(addCourse).then(function (response) {
if (response.data.status==200 && response.data.courseStatus) {
$scope.ldloading1[loading.replace('-', '_')] = false;
swal(" ", "Course added successfully.", "success");
$state.go($state.current, {}, {reload: true});
} else {
$scope.addMoreItems.splice($scope.addMoreItems.length-1);
$scope.ldloading1[loading.replace('-', '_')] = false;
swal(" ", response.data.message, "error");
}
});
}
}
},
reset: function (form) {
$scope.addMoreItems = [];
$scope.myModel.ListName=$scope.feesDetails[0];
$scope.myModel.programListName=$scope.myModel.ListName.programType[0].ListCode;
$scope.myModel = angular.copy($scope.master);
form.$setPristine(true);
}
};
/*
* update the course details
* created by kms
* */
$scope.updateCourse = function (myModel, form,regular,lateral,semYear, loading,subjects) {
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 {
if(semYear.programName!="" || semYear.FeesAmount!=""){
$rootScope.updateMoreItems.push({
ID:"",
program: semYear.program,
programName:semYear.programName,
FeesName: semYear.FeesName,
FeesType:semYear.FeesType,
FeesAmount: semYear.FeesAmount
});
}
$scope.ldloading = {};
$scope.ldloading[loading.replace('-', '_')] = true;
var update = {
method: 'POST',
url: apiPoint.url + 'updateCourseDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
courseID: myModel.CourseID,
universityID: myModel.UniversityID,
courseCode: myModel.CourseCode,
courseName: myModel.CourseName,
provFess:myModel.PC,
transferAmount:myModel.TC,
degreeAmount:myModel.DC,
migrationAmount:myModel.MC,
otherAmount:myModel.OtherFees,
feesAmounts:myModel.feesStructures,
regularFeesAmounts:regular,
lateralFeesAmounts:lateral,
semFeesAmounts:$rootScope.updateMoreItems,
status: myModel.IsActive,
updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
specilization1:myModel.Specilization1,
specilization2:myModel.Specilization2,
existCourseID:myModel.CourseID,
subjects:subjects.list
}
};
$http(update).then(function (response) {
if (response.data.status==200 && response.data.courseStatus) {
$scope.ldloading[loading.replace('-', '_')] = false;
$rootScope.updateMoreItems=[];
$rootScope.init();
swal(" ", "Updated successfully.", "success");
$scope.editId = -1;
} else {
$scope.ldloading[loading.replace('-', '_')] = false;
// $rootScope.init();
swal(" ", response.data.message, "error");
}
});
}
};
/*
*get course details when page loading called from view file
*
* created by kms
* */
$scope.loader='';
$scope.emptyData='';
$rootScope.init = function () {
getUniversity_FeesDetails();
$scope.loader='';
var getCourse = {
method: 'POST',
url: apiPoint.url + 'getCourseDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID
}
};
$http(getCourse).then(function (response) {
if (response.data.status==200 && response.data.courseStatus) {
$scope.emptyData=true;
$scope.loader=true;
$scope.data = response.data.details;
// $scope.university=response.data.universityDetails;
// $scope.feesDetails=response.data.feesDetails;
// $scope.myModel.ListName=$scope.feesDetails[0];
// $scope.myModel.programListName=$scope.myModel.ListName.programType[0].ListCode;
// // single sitting regular course details in model
// $scope.myModelRegular = {
// "FeesType":$scope.feesDetails[0].ListCode,
// "FeesName":$scope.feesDetails[0].ListName,
// "program":$scope.feesDetails[0].programType[0].ListCode,
// "programName":$scope.feesDetails[0].programType[0].ListName,
// "FeesAmount":"",
// };
// // single sitting lateral course details in model
// $scope.myModelLateral = {
// "FeesType":$scope.feesDetails[0].ListCode,
// "FeesName":$scope.feesDetails[0].ListName,
// "program":$scope.feesDetails[0].programType[1].ListCode,
// "programName":$scope.feesDetails[0].programType[1].ListName,
// "FeesAmount":"",
// };
// // single sitting Sem_Year course details in model
// $scope.myModelSemYear = {
// "FeesType":$scope.feesDetails[1].ListCode,
// "FeesName":$scope.feesDetails[1].ListName,
// "program":$scope.feesDetails[1].programType[0].ListCode,
// "programName":"",
// "FeesAmount":"",
// };
// $rootScope.myModelSemYear1 = {
// "FeesType":$scope.feesDetails[1].ListCode,
// "FeesName":$scope.feesDetails[1].ListName,
// "program":$scope.feesDetails[1].programType[0].ListCode,
// "programName":"",
// "FeesAmount":"",
// };
} else {
$scope.emptyData=false;
$scope.loader=true;
// getUniversity_FeesDetails();
// $scope.university=response.data.universityDetails;
// $scope.feesDetails=response.data.feesDetails;
// $scope.myModel.ListName=$scope.feesDetails[0];
// $scope.myModel.programListName=$scope.myModel.ListName.programType[0].ListCode;
}
});
};
function getUniversity_FeesDetails() {
localStorage.setItem('localSubjectDetails', '');
localStorage.setItem('localUniversityDetails', '');
$scope.subjectDetails=[];
var getCourseUnivFee = {
method: 'POST',
url: apiPoint.url + 'getCourseUnivFeesDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID
}
};
$http(getCourseUnivFee).then(function (response) {
if (response.data.status==200 && response.data.courseStatus) {
$scope.university=response.data.universityDetails;
$scope.subjectDetails=[];
$scope.feesDetails=response.data.feesDetails;
$scope.myModel.ListName=$scope.feesDetails[0];
$scope.myModel.programListName=$scope.myModel.ListName.programType[0].ListCode;
angular.forEach(response.data.subjectetails, function (values, keys) {
$scope.subData = {
SubjectID: values.SubjectID,
SubjectName: values.SubjectCode +'-'+values.SubjectName
};
$scope.subjectDetails.push($scope.subData);
});
// single sitting regular course details in model
$scope.myModelRegular = {
"FeesType":$scope.feesDetails[0].ListCode,
"FeesName":$scope.feesDetails[0].ListName,
"program":$scope.feesDetails[0].programType[0].ListCode,
"programName":$scope.feesDetails[0].programType[0].ListName,
"FeesAmount":"",
};
// single sitting lateral course details in model
$scope.myModelLateral = {
"FeesType":$scope.feesDetails[0].ListCode,
"FeesName":$scope.feesDetails[0].ListName,
"program":$scope.feesDetails[0].programType[1].ListCode,
"programName":$scope.feesDetails[0].programType[1].ListName,
"FeesAmount":"",
};
// single sitting Sem_Year course details in model
$scope.myModelSemYear = {
"FeesType":$scope.feesDetails[1].ListCode,
"FeesName":$scope.feesDetails[1].ListName,
"program":$scope.feesDetails[1].programType[0].ListCode,
"programName":"",
"FeesAmount":"",
};
$rootScope.myModelSemYear1 = {
"FeesType":$scope.feesDetails[1].ListCode,
"FeesName":$scope.feesDetails[1].ListName,
"program":$scope.feesDetails[1].programType[0].ListCode,
"programName":"",
"FeesAmount":"",
};
} else {
$scope.university=response.data.universityDetails;
$scope.feesDetails=response.data.feesDetails;
$scope.myModel.ListName=$scope.feesDetails[0];
$scope.myModel.programListName=$scope.myModel.ListName.programType[0].ListCode;
}
localStorage.setItem('localUniversityDetails', JSON.stringify($scope.university));
localStorage.setItem('localSubjectDetails', JSON.stringify($scope.subjectDetails));
});
}
/*
* get fees type drop down
* created by kms
* */
$scope.getFeesProgram = function () {
$scope.myModel.programListName=$scope.myModel.ListName.programType[0].ListCode;
$scope.addMoreItems = [];
}
/*
* get add more fees item array
* created by kms
* */
$scope.addMoreItems = [];
$rootScope.addMoreFeesItems = function (model,form) {
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 if(model.programName==''){
swal("Warning!", "Please Enter Sem/Year Name", "warning");
}
else if(model.FeesAmount==''){
swal("Warning!", "Please Enter Fees Amount", "warning");
}
else {
$scope.addMoreItems.push({
program: model.program,
programName:model.programName,
FeesName: model.FeesName,
FeesType:model.FeesType,
FeesAmount: model.FeesAmount
});
$scope.myModelSemYear = {
"FeesType":$scope.feesDetails[1].ListCode,
"FeesName":$scope.feesDetails[1].ListName,
"program":$scope.feesDetails[1].programType[0].ListCode,
"programName":"",
"FeesAmount":"",
};
}
}
/*
* get update more fees item array
* created by kms
* */
$rootScope.updateMoreFeesItems = function (model,form) {
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 if( model==undefined || model.programName==''){
swal("Warning!", "Please Enter Sem/Year Name", "warning");
}
else if(model==undefined || model==undefined){
swal("Warning!", "Please Enter Fees Amount", "warning");
}
else {
$rootScope.updateMoreItems.push({
ID:"",
program: model.program,
programName:model.programName,
FeesName: model.FeesName,
FeesType:model.FeesType,
FeesAmount: model.FeesAmount
});
$rootScope.myModelSemYear1 = {
"FeesType":$scope.feesDetails[1].ListCode,
"FeesName":$scope.feesDetails[1].ListName,
"program":$scope.feesDetails[1].programType[0].ListCode,
"programName":"",
"FeesAmount":"",
};
}
}
}]);