apollodec/Apollo/assets/js/controllers/courseCtrl.js
2018-01-08 11:56:21 +05:30

482 lines
16 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":""
};
$rootScope.myModel1 = {
"ListName": "",
"programListName":""
};
/*
* edit course details
* created by kms
* */
$rootScope.updateMoreItems = [];
$scope.editId = -1;
$rootScope.setEditId = function (pid,p) {
$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,
});
}
});
$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
});
}
$scope.ldloading1 = {};
$scope.ldloading1[loading.replace('-', '_')] = true;
var addCourse = {
method: 'POST',
url: apiPoint.url + 'addCourseDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
courseID: 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
}
};
$http(addCourse).then(function (response) {
if (response.data.status==200 && response.data.courseStatus) {
$scope.ldloading1[loading.replace('-', '_')] = false;
swal("Success!", response.data.message, "success");
$state.go($state.current, {}, {reload: true});
} else {
$scope.addMoreItems.splice($scope.addMoreItems.length-1);
$scope.ldloading1[loading.replace('-', '_')] = false;
swal("Failed!", 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) {
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: {
courseCode: myModel.CourseID,
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
}
};
$http(update).then(function (response) {
if (response.data.status==200 && response.data.courseStatus) {
$scope.ldloading[loading.replace('-', '_')] = false;
$rootScope.updateMoreItems=[];
$rootScope.init();
swal("Success!", response.data.message, "success");
$scope.editId = -1;
} else {
$scope.ldloading[loading.replace('-', '_')] = false;
$rootScope.init();
swal("Failed!", response.data.message, "error");
}
});
}
};
/*
*get course details when page loading called from view file
*
* created by kms
* */
$scope.loader='';
$scope.emptyData='';
$rootScope.init = function () {
$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;
$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;
}
});
};
/*
* 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":"",
};
}
}
}]);