apollodec/Apollo/assets/js/controllers/studentCtrl.js
2017-12-05 17:02:26 +05:30

634 lines
22 KiB
JavaScript

'use strict';
/**
* controllers for ng-table
* Simple table with sorting and filtering on AngularJS
*/
app.controller('studentCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "$http", "API_POINTS", "$state", '$rootScope', '$cookies', 'md5', 'ipCookie', '$timeout', '$window', function ($scope, toaster, $filter, ngTableParams, $http, apiPoint, $state, $rootScope, $cookies, md5, ipCookie, $timeout, $window) {
/**
* student details capture
* by : kdk
*/
$scope.myModel = {
'primaryPhone': '',
'firstname': '',
'lastname': '',
'fathername': '',
'mothername': '',
'emailId': '',
'secondaryPhone': '',
'dateofbirth': '',
'gender': '',
'aadharNumber': '',
'otherId': '',
'otherIdDetails': '',
'address1': '',
'address2': '',
'caste': '',
'category': '',
'religion': '',
'nationality': '',
'prequalification': '',
'occupation': '',
'designation': '',
'companyname': '',
'referredby': '',
'referredmobilenumber': '',
'switchsetting': true,
};
$scope.myModelCourse = {
'university': '',
'course': '',
'batch': '',
'dateofjoining': '',
'enrollmentid': ''
};
$scope.myModelCourseAdd = {
'university': '',
'course': '',
'batch': '',
'dateofjoining': '',
'enrollmentid': ''
};
$scope.addStudentView = function () {
// $scope.myModelCourseAdd = {
// 'university': '',
// 'course': '',
// 'batch': '',
// 'dateofjoining': '',
// 'enrollmentid': ''
// };
// $scope.courseDataAdd = '';
// $scope.batchDataAdd = '';
}
// 2017-11-23T00:00:00+0530
// 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
}
// get local cliend details
var localDetail = JSON.parse(localStorage.getItem('localObj'));
var localDetails = ipCookie('cookiechk');
// load when html page load
$scope.init = function () {
var nowInMS = new Date().getTime(),
sixteenYearsInMS = 1000 * 60 * 60 * 24 * 365 * 16,
sixteenYearsBeforeNow = new Date(nowInMS - sixteenYearsInMS);
if (localDetail != null) {
$scope.currentDate = new Date(sixteenYearsBeforeNow);
$scope.getStudentList();
$scope.getUniversityList();
$scope.myModel.dateofbirth=$filter('date')($scope.currentDate, 'dd-MM-yyyy');
} else {
}
}
$scope.getStudentList = function () {
$scope.loader = true;
var empListreq = {
method: 'POST',
url: apiPoint.url + 'getStudentList/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: localDetails
}
};
$http(empListreq).then(function (response) {
if (response.data.studentList) {
$scope.loader = false;
$scope.studentData = true;
$scope.data = response.data.student_details;
} else {
$scope.loader = false;
$scope.studentData = false;
}
});
}
$scope.editId = -1;
$scope.editCourseId = -1;
$scope.setEditId = function (id) {
$scope.editId = id;
$scope.editCourseId = -1;
}
$scope.setEditCourseId = function (id) {
$scope.list = false;
$scope.getStudentCourseList(id);
$scope.currentStudentId = id;
// $scope.getStudentCourseDetails(id);
$scope.editCourseId = id;
$scope.editId = -1;
$scope.courseEditLoading = true;
}
$scope.cancel = function () {
$scope.getStudentList();
$scope.editId = -1;
$scope.editCourseId = -1;
}
$scope.cancelCourseDetails = function () {
$scope.getStudentCourseList($scope.currentStudentId);
// $scope.editId = -1;
// $scope.editCourseId = -1;
}
$scope.addStudentCourse = function () {
$scope.myModelCourse = {
'university': '',
'course': '',
'batch': '',
'dateofjoining': '',
'enrollmentid': ''
};
$scope.list = false;
$scope.courseEdit = false;
$scope.courseAdd = true;
}
// add student course
$scope.addCourseFORM = {
submit: function (form, myModelCourse, p) {
// alert();
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 {
// alert(JSON.stringify(p.StudentID));
var formate = "dd-MM-yyyy";
// $scope.myModel.switchsetting = $scope.myModel.switchsetting === true ? 1 : 0;
// $scope.myModel.dateofbirth = $filter('date')(new Date($scope.myModel.dateofbirth), formate);
$scope.myModelCourse.dateofjoining = $filter('date')(new Date($scope.myModelCourse.dateofjoining), formate);
var req = {
method: 'POST',
url: apiPoint.url + 'insertStudentCourse/',
headers: {
'Content-Type': 'application/json'
},
data: {
addStudent: p.StudentID,
coursedata: $scope.myModelCourse,
loginBranch: localDetails.localBranchID,
createdBy: localDetails.localUserID,
}
};
$http(req).then(function (response) {
if (response.data.addStuCourseStatus == true) {
swal("Success!", response.data.message, "success");
$scope.getStudentCourseList($scope.currentStudentId);
} else {
swal("Failed!", response.data.message, "error");
$scope.getStudentCourseList($scope.currentStudentId);
}
});
}
}
}
// get Student Course List
$scope.getStudentCourseList = function (studentId) {
$scope.courseEditLoading = true;
$scope.list = true;
$scope.courseEdit = false;
$scope.courseAdd = false;
var req = {
method: 'POST',
url: apiPoint.url + 'getStudentCourseList/',
headers: {
'Content-Type': 'application/json'
},
data: {
studentID: studentId
}
};
$http(req).then(function (response) {
if (response.data.stuCourseDetails) {
$scope.courseEditLoading = false;
$scope.studentCourseList = response.data.course_details;
// $scope.stucour = $scope.studentCourse[0];
} else {
}
});
}
// get student particular course details : params : studentCourseID
$scope.getStudentCourseDetails = function (studentcourseID) {
$scope.courseEditLoading = true;
$scope.stucour = '';
$scope.list = false;
$scope.courseAdd = false;
$scope.courseEdit = true;
var req = {
method: 'POST',
url: apiPoint.url + 'getStudentCourseDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
studentcourseId: studentcourseID
}
};
$http(req).then(function (response) {
if (response.data.stuCourseDetails) {
$scope.courseEditLoading = false;
$scope.studentCourse = response.data.course_details;
$scope.stucour = $scope.studentCourse[0];
} else {
}
});
}
// update sutdent course details
$scope.updateStudentCourseDetails = function (form, datas) {
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 {
// alert(datas.DOJ);
var formate = "dd-MM-yyyy";
var checkDOJ = $filter('date')(new Date(datas.DOJ), formate);
datas.IsActive = datas.IsActive === true ? 1 : 0;
datas.DOJ = checkDOJ == "NaN-NaN-0NaN" ? datas.DOJ : $filter('date')(new Date(datas.DOJ), formate);
// alert(datas.DOJ);
var req = {
method: 'POST',
url: apiPoint.url + 'updateStudentCourseDetail/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: datas,
updatedBy: localDetails.localUserID,
}
};
$http(req).then(function (response) {
if (response.data.updateStuCourseStatus) {
swal("Success!", response.data.message, "success");
$scope.getStudentCourseList($scope.currentStudentId);
// $scope.editCourseId = false;
} else {
// $scope.ldloading1[loading.replace('-', '_')] = false;
swal("Failed!", response.data.message, "error");
$scope.getStudentCourseList($scope.currentStudentId);
}
});
}
}
$scope.universityData = '';
$scope.getUniversityList = function () {
var empListreq = {
method: 'POST',
url: apiPoint.url + 'getStudentUniversity/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: localDetails
}
};
$http(empListreq).then(function (response) {
if (response.data.univList) {
$scope.universityData = response.data.university_details;
} else {
}
});
}
$scope.onSlecetUnivEdit = function (id) {
$scope.myModelCourse.university = id;
$scope.onSlecetUniv();
}
$scope.onChangeSlecetUnivEdit = function (id) {
$scope.myModelCourse.university = id;
$scope.onSlecetUniv();
$scope.stucour.CourseID = '';
$scope.stucour.BatchCode = '';
}
$scope.courseLoading = false;
$scope.onSlecetUniv = function () {
$scope.courseData = '';
$scope.batchData = '';
$scope.myModelCourse.course = '';
$scope.myModelCourse.batch = '';
$scope.courseLoading = true;
var univListreq = {
method: 'POST',
url: apiPoint.url + 'getCourseBatchForUniv/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: $scope.myModelCourse.university
}
};
$http(univListreq).then(function (response) {
if (response.data.courseStatus) {
$scope.courseLoading = false;
$scope.courseData = response.data.course_details;
$scope.batchData = response.data.batch_details;
} else {
$scope.courseLoading = false;
}
});
}
$scope.onSlecetUnivAdd = function () {
$scope.courseDataAdd = '';
$scope.batchDataAdd = '';
$scope.myModelCourseAdd.course = '';
$scope.myModelCourseAdd.batch = '';
$scope.courseLoading = true;
var univListreq = {
method: 'POST',
url: apiPoint.url + 'getCourseBatchForUniv/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: $scope.myModelCourseAdd.university
}
};
$http(univListreq).then(function (response) {
if (response.data.courseStatus) {
$scope.courseLoading = false;
$scope.courseDataAdd = response.data.course_details;
$scope.batchDataAdd = response.data.batch_details;
} else {
$scope.courseLoading = false;
}
});
}
// check mobile number existing
$scope.checkMobileExist = function () {
var checkReq = {
method: 'POST',
url: apiPoint.url + 'chkStudentExistDetail/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: $scope.myModel.primaryPhone,
check: 'mobileNumber'
}
};
$http(checkReq).then(function (response) {
if (response.data.existMobile == true) {
swal("Warning!", response.data.message, "warning");
$scope.myModel.primaryPhone = '';
} else {
}
});
}
// check emailId existing
$scope.checkEmailExist = function () {
var checkReq = {
method: 'POST',
url: apiPoint.url + 'chkStudentExistDetail/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: $scope.myModel.emailId,
check: 'emailId'
}
};
$http(checkReq).then(function (response) {
if (response.data.existEmailId == true) {
swal("Warning!", response.data.message, "warning");
$scope.myModel.emailId = '';
} else {
}
});
}
// add student
$scope.studentFORM = {
submit: function (form, myModel, myModelCourseAdd) {
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 {
$scope.disableButton = true;
var formate = "dd-MM-yyyy";
$scope.myModel.switchsetting = $scope.myModel.switchsetting === true ? 1 : 0;
$scope.myModel.dateofbirth = $filter('date')(new Date($scope.myModel.dateofbirth), formate);
$scope.myModelCourseAdd.dateofjoining = $filter('date')(new Date($scope.myModelCourseAdd.dateofjoining), formate);
var req = {
method: 'POST',
url: apiPoint.url + 'insertStudent/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: $scope.myModel,
coursedata: $scope.myModelCourseAdd,
loginBranch: localDetails.localBranchID,
createdBy: localDetails.localUserID,
}
};
$http(req).then(function (response) {
if (response.data.addStudentStatus == true) {
swal("Success!", response.data.message, "success");
$scope.disableButton = false;
$state.go($state.current, {}, { reload: true });
} else {
$scope.disableButton = false;
swal("Failed!", response.data.message, "error");
}
});
}
},
reset: function (form) {
// $scope.myModel = angular.copy($scope.master);
form.$setPristine(true);
$scope.myModel = {
'employeeId': '',
'firstname': '',
'lastname': '',
'fathername': '',
'mothername': '',
'emailId': '',
'primaryPhone': '',
'secondaryPhone': '',
'dateofbirth': '',
'gender': '',
'qualificaion': '',
'aadharNumber': '',
'otherId': '',
'otherIdDetails': '',
'address1': '',
'address2': '',
'homeBranch': '',
'dateofjoining': '',
'dateofjoining': '',
'role': '',
'switchsetting': true,
};
}, resetCourse: function (form) {
form.$setPristine(true);
$scope.myModelCourse = {
'university': '',
'course': '',
'batch': '',
'dateofjoining': '',
'enrollmentid': ''
};
}
}
// update check mobile exist
$scope.updateCheckMobileExist = function (p) {
var checkReq = {
method: 'POST',
url: apiPoint.url + 'chkUpdateStuExistDetail/',
headers: {
'Content-Type': 'application/json'
},
data: {
exceptId: p.StudentID,
datas: p.MobileNumber,
check: 'mobileNumber'
}
};
$http(checkReq).then(function (response) {
if (response.data.existMobile == true) {
swal("Warning!", response.data.message, "warning");
p.MobileNumber = response.data.resetValue.MobileNumber;
} else {
}
});
}
// update check email id exist
$scope.updateCheckEmailExist = function (p) {
var checkReq = {
method: 'POST',
url: apiPoint.url + 'chkUpdateStuExistDetail/',
headers: {
'Content-Type': 'application/json'
},
data: {
exceptId: p.StudentID,
datas: p.EmailID,
check: 'emailId'
}
};
$http(checkReq).then(function (response) {
if (response.data.existEmailId == true) {
swal("Warning!", response.data.message, "warning");
p.EmailID = response.data.resetValue.EmailID;
} else {
}
});
}
// update student details
$scope.updateStuDetails = function (form, p) {
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 {
// alert(p.DOB);
var formate = "dd-MM-yyyy";
var checkDOB = $filter('date')(new Date(p.DOB), formate);
p.IsActive = p.IsActive === true ? 1 : 0;
p.DOB = checkDOB == "NaN-NaN-0NaN" ? p.DOB : $filter('date')(new Date(p.DOB), formate);
var req = {
method: 'POST',
url: apiPoint.url + 'updateStudentExistDetail/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: p,
updatedBy: localDetails.localUserID,
}
};
$http(req).then(function (response) {
if (response.data.updateStuStatus = true) {
swal("Success!", response.data.message, "success");
$scope.getStudentList();
$scope.editId = -1;
} else {
// $scope.ldloading1[loading.replace('-', '_')] = false;
swal("Failed!", response.data.message, "error");
}
});
}
}
}]);