'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', "flowFactory", "$interval", 'SweetAlert', function ($scope, toaster, $filter, ngTableParams, $http, apiPoint, $state, $rootScope, $cookies, md5, ipCookie, $timeout, $window, flowFactory, $interval, SweetAlert) { /** * 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, 'DeactiveComments': '', 'Comments': '' }; $scope.myModelCourse = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; $scope.myModelCourseAdd = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; $scope.inActiveBranchStatus = false; $scope.addStudentView = function () { // check the local branch is active for add a new student for this branch var checkBranchActiveForStuAdd = { method: 'POST', url: apiPoint.url + 'getBranchActiveStatusforStuAdd/', headers: { 'Content-Type': 'application/json' }, data: { data: localDetails } }; $http(checkBranchActiveForStuAdd).then(function (response) { if (response.data) { var checkStatus = response.data.branch_active_status; if (checkStatus == "0") { $scope.inActiveBranchStatus = true; swal(" ", "Cannot create a new Student for In-Active Branch", "warning"); } else { $scope.inActiveBranchStatus = false; } } else { } }); // $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 client details var localDetail = JSON.parse(localStorage.getItem('localObj')); var localDetails = ipCookie('cookiechk'); // load when html page load $scope.init = function () { $scope.todayDate = new Date(); var nowInMS = new Date().getTime(), sixteenYearsInMS = 1000 * 60 * 60 * 24 * 365 * 16, sixteenYearsBeforeNow = new Date(nowInMS - sixteenYearsInMS); if (localDetail != null) { if (localDetails.localType === 'R003' || localDetails.localType === 'R002') { $scope.currentDate = new Date(sixteenYearsBeforeNow); $scope.getStudentList(); $scope.getUniversityList(); $scope.getUniversitySearchList(); // $scope.myModel.dateofbirth = $filter('date')($scope.currentDate, 'dd-MM-yyyy'); } else { ipCookie.remove('cookiechk'); $window.localStorage.clear(); $state.go('login.signin'); } } else { } } // get University List $scope.universitySearchData = ''; $scope.getUniversitySearchList = function () { var empListreq = { method: 'POST', url: apiPoint.url + 'getUniveCourseBratch/', headers: { 'Content-Type': 'application/json' }, data: { data: localDetails } }; $http(empListreq).then(function (response) { if (response.data.univList) { $scope.universitySearchData = response.data.university_details; // alert() } else { } }); }; $scope.searchData = { "University": "", "Course": "", "Status": "" } $scope.myUnivSearch = ""; $scope.getUniveId = function (univ) { if (univ === '') { $scope.myUnivSearch = ""; $scope.searchData.University = ''; $scope.searchData.Course = ''; $scope.searchData.Batch = ''; $scope.courseData = name.Course; $scope.batchData = name.Batch; $scope.OpenWindowStatus = false; $scope.getStudentList(); } else { let name = JSON.parse(univ); $scope.searchData.University = name.UniversityID; $scope.searchData.Course = ''; $scope.searchData.Batch = ''; $scope.courseData = name.Course; $scope.batchData = name.Batch; $scope.OpenWindowStatus = false; $scope.getStudentList(); } }; $scope.getValueChange = function () { // $scope.searchData = { // "University": "", // "Course": "", // "Status": "" // } $scope.getStudentList(); } $scope.studentListLength = 0; $scope.getStudentList = function () { $scope.loader = true; var empListreq = { method: 'POST', url: apiPoint.url + 'getStudentList/', headers: { 'Content-Type': 'application/json' }, data: { data: localDetails, search: $scope.searchData } }; $http(empListreq).then(function (response) { if (response.data.studentList) { $scope.loader = false; $scope.studentData = true; $scope.data = response.data.student_details; $scope.studentListLength = $scope.data.length; } else { $scope.loader = false; $scope.studentData = false; } }); } $scope.editId = -1; $scope.editCourseId = -1; $scope.setEditId = function (id) { $scope.editId = id; $scope.editCourseId = -1; $scope.studentViewPage = -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(" ", "Student course added successfully.", "success"); $scope.getStudentCourseList($scope.currentStudentId); } else { swal(" ", 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, updatedBy: localDetails, } }; $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, hidedoj) { 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 = datas.DOJ == hidedoj ? 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(" ", "Updated successfully.", "success"); $scope.getStudentCourseList($scope.currentStudentId); // $scope.editCourseId = false; } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal(" ", 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; } }); } $scope.existingStudentView = false; $scope.existingStudentId = ''; // 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) { if (response.data.details.type === 'R001') { // swal("Warning!", response.data.message, "warning"); $scope.myModel.primaryPhone = ''; // student registration find student previously exist // $scope.existingStudentView = true; // $scope.existingStudentId = response.data.details.studentId; SweetAlert.swal({ title: "Warning!", text: "Student exist with this same number." + "\n Do you want to enroll new course!", type: "warning", showCancelButton: true, confirmButtonColor: "#007aff", confirmButtonText: "Yes!" }, function (res) { if (res === true) { $scope.existingStudentView = true; $scope.existingStudentId = response.data.details.studentId; } }); } else if (response.data.details.type === 'R002' || response.data.details.type === 'R003') { swal("Warning!", response.data.message, "warning"); $scope.myModel.primaryPhone = ''; } else { swal("Warning!", response.data.message, "warning"); $scope.myModel.primaryPhone = ''; } } else { } }); } $scope.stuExistingDetailsShowLoading = false; $scope.getExistStudentDetails = function () { // alert($scope.existingStudentId); $scope.stuExistingDetailsShowLoading = true; var checkExisReq = { method: 'POST', url: apiPoint.url + 'getExistingStudentDetails/', headers: { 'Content-Type': 'application/json' }, data: { data: $scope.existingStudentId, reqDetails: localDetails } }; $http(checkExisReq).then(function (response) { if (response.data.existingStudentDetailsStatus == true) { $scope.existingStuPersonalDetails = response.data.personalDetails[0]; $scope.existingStuCourseDetails = response.data.courseDetails; $scope.stuExistingDetailsShowLoading = false; } else { $scope.stuExistingDetailsShowLoading = false; } }); } $scope.cancelExisStudentView = function () { $scope.existingStudentView = false; } // add student course for existing student $scope.addCourseExistingStudent = { submit: function (form, myModelCourse, 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(JSON.stringify(p.StudentID)); // alert(JSON.stringify(myModelCourse)); var formate = "dd-MM-yyyy"; $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(" ", "Student course added successfully. ", "success"); $state.go($state.current, {}, { reload: true }); // $scope.getStudentCourseList($scope.currentStudentId); } else { swal(" ", response.data.message, "error"); // $scope.getStudentCourseList($scope.currentStudentId); $scope.myModelCourse.dateofjoining = ''; } }); } }, cancel: function () { $scope.myModelCourse = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; } } // 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 { } }); } //--------------------------------------------------------------> // getting for image to show //--------------------------------------------------------------> $scope.stepsModel = []; $scope.imageUpload = function (event) { var files = event.target.files; //FileList object for (var i = 0; i < files.length; i++) { var file = files[i]; var reader = new FileReader(); reader.onload = $scope.imageIsLoaded; reader.readAsDataURL(file); } } $scope.imageIsLoaded = function (e) { $scope.$apply(function () { // $scope.stepsModel.push(e.target.result); $scope.stepsModel[0] = e.target.result; }); } //an array of files selected $scope.files = []; //listen for the file selected event $scope.$on("fileSelected", function (event, args) { $scope.$apply(function () { //add the file object to the scope's files collection $scope.files[0] = args.file; }); }); // reset image $scope.resetImage = function () { $scope.files.length = 0; $scope.stepsModel.length = 0; } // $scope.getChangeDate = function () { // // alert(); // try { // var formate = "dd-MM-yyyy"; // $scope.myModel.dateofbirth = $filter('date')(new Date($scope.myModel.dateofbirth), formate); // // alert($scope.myModel.dateofbirth); // // var myDate = new Date($scope.myModel.dateofbirth); // // alert(myDate); // // if(typeof myDate === 'function') { // // alert("true") // // } else { // // alert("error") // // } // } // catch(e) { // // alert('error'); // // alert(err); // } // } // 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.dateofbirth = $filter('date')(new Date($scope.myModel.dateofbirth), formate); $scope.myModel.switchsetting = $scope.myModel.switchsetting === true ? 1 : 0; $scope.myModelCourseAdd.dateofjoining = $filter('date')(new Date($scope.myModelCourseAdd.dateofjoining), formate); var idStuProof = $scope.files[0]; // alert(JSON.stringify($scope.myModel)); if (idStuProof !== undefined) { var formData = new FormData(); var idProof = $scope.files[0]; // alert(idProof); formData.append("data", JSON.stringify($scope.myModel)); formData.append("coursedata", JSON.stringify($scope.myModelCourseAdd)); formData.append("createdBy", localDetails.localUserID); formData.append("loginBranch", localDetails.localBranchID); formData.append('idStuProof', idStuProof); $http.post(apiPoint.url + 'insertStudentImg/', formData, { transformRequest: angular.identity, headers: { 'Content-Type': undefined, 'Process-Data': false }, }).success(function (data) { if (data.addStudentStatus == true) { swal(" ", "Student added successfully.", "success"); $scope.disableButton = false; $state.go($state.current, {}, { reload: true }); } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal(" ", data.message, "error"); // $scope.disableButton = false; } }); } else { 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(" ", "Student added successfully.", "success"); $scope.disableButton = false; $state.go($state.current, {}, { reload: true }); } else { // $scope.disableButton = false; swal(" ", response.data.message, "error"); } }); } } }, reset: function (form) { // $scope.myModel = angular.copy($scope.master); form.$setPristine(true); $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, 'DeactiveComments': '', 'Comments': '' }; $scope.myModelCourseAdd = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; }, 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 { } }); } // start : entrollment document upload ============================= $scope.studentDocumentsList = ''; // get Student Document Details $scope.getStuEntrollDocDetails = function (stuId) { // $scope.studentDocumentsList = ''; var getStudentDocDetails = { method: 'POST', url: apiPoint.url + 'getListofStuDocDetails/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: stuId, localData: localDetail } }; $http(getStudentDocDetails).then(function (response) { if (response.data.docListStatus == true) { $scope.docNotFound = false; $scope.studentDocumentsList = response.data.student_doc_details; } else { $scope.docNotFound = true; $scope.studentDocumentsList.call(); } }); } $scope.deleteDocDetails = function (id, stuID) { SweetAlert.swal({ title: "Warning!", text: "Want to Delete this file ?", type: "warning", showCancelButton: true, confirmButtonColor: "#007aff", confirmButtonText: "Yes!" }, function (res) { if (res === true) { // alert(id); // alert(stuId); $scope.documentAddDetailsLoading = true; var deleteDocEntry = { method: 'POST', url: apiPoint.url + 'deleteStuDocDetails/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: stuID, docDetailsID: id, localData: localDetail } }; $http(deleteDocEntry).then(function (response) { if (response.data.deleteStatus == true) { // swal("Success!", response.data.message, "success"); $scope.documentAddDetailsLoading = false; $scope.studentDocumentsList = ''; $scope.getStuEntrollDocDetails(stuID); } else { swal(" ", res.data.message, "error"); $scope.documentAddDetailsLoading = false; } }); } }); } $scope.myModelAddDocuments = { "documentName": "", "documentComments": "" } //an array of documents selected $scope.filesDocuments = []; //listen for the document selected event $scope.$on("fileSelectedDocument", function (event, args) { $scope.$apply(function () { //add the file object to the scope's files collection $scope.filesDocuments[0] = args.file; }); }); $scope.documentAddDetailsLoading = false; $scope.studentEntrollDocFORM = { submit: function (form, myModelAddDocuments, stuID) { 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 ($scope.filesDocuments[0] == undefined || $scope.filesDocuments[0] == null || $scope.filesDocuments.length === 0) { swal("Warning!", "Choose the File.", "warning"); } else { $scope.documentAddDetailsLoading = true; var formData = new FormData(); var stuDocProof = $scope.filesDocuments[0]; var stuDocProofStatus = $scope.filesDocuments[0] !== undefined ? true : false; formData.append("data", JSON.stringify(myModelAddDocuments)); formData.append("studentID", stuID); formData.append("updatedBy", localDetails.localUserID); formData.append('stuDocProof', stuDocProof); formData.append('stuDocProof_Status', stuDocProofStatus); $http.post(apiPoint.url + 'addStudentEntrollDocDetails/', formData, { transformRequest: angular.identity, headers: { 'Content-Type': undefined, 'Process-Data': false }, }).success(function (res) { if (res.stuDocUpdateStatus == true) { $scope.getStuEntrollDocDetails(stuID); // swal(" ", "Updated successfully.", "success"); $scope.documentAddDetailsLoading = false; $scope.filesDocuments[0] = undefined; form.$setPristine(true); angular.element("input[type='file']").val(null); $scope.myModelAddDocuments = { "documentName": "", "documentComments": "" } // $scope.getStudentList(); // $scope.editId = -1; // $scope.editSaveButtonDisable = false; } else { swal(" ", res.data.message, "error"); $scope.documentAddDetailsLoading = false; // $scope.editSaveButtonDisable = false; } }); } } }, reset: function (form) { $scope.filesDocuments[0] = undefined; form.$setPristine(true); angular.element("input[type='file']").val(null); } } // $scope.PendingDocNotFound = false; // student pending document details $scope.getStudentPendingEntrolDocDetails = function(stuId) { // $scope.studentDocumentsList = ''; var getStudentPendingDocDetails = { method: 'POST', url: apiPoint.url + 'getListofStuPendingDocDetails/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: stuId, localData: localDetail } }; $http(getStudentPendingDocDetails).then(function (response) { if (response.data.PendingDocListStatus == true) { // $scope.PendingDocNotFound = false; $scope.studentPendingDocumentsDetails = response.data.student_pending_doc_details; } else { // $scope.PendingDocNotFound = true; } }); } $scope.myModelAddPendingDocDetails = { "documentDetails": "", "checkTracking": false } $scope.documentTrackAddDetailsLoading = false; $scope.studentEntrollPendingDocFORM = { submit: function (form, myModelAddPendingDocDetails, stuID) { $scope.documentTrackAddDetailsLoading = true; 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 { var ModelDetails = { "student" : stuID, "doc_Details": myModelAddPendingDocDetails.documentDetails, "checkTracking": myModelAddPendingDocDetails.checkTracking }; var updateStudentPendingDocDetails = { method: 'POST', url: apiPoint.url + 'addStudentEnrollPendingDocDetails/', headers: { 'Content-Type': 'application/json' }, data: { updateDetails: ModelDetails, localData: localDetail } }; $http(updateStudentPendingDocDetails).then(function (response) { if (response.data.AddStuPendingDocStatus == true) { $scope.getStudentPendingEntrolDocDetails(stuID); $scope.documentTrackAddDetailsLoading = false; $scope.myModelAddPendingDocDetails = { "documentDetails": "", "checkTracking": false } } else { swal(" ", res.data.message, "error"); $scope.documentTrackAddDetailsLoading = false; } }); } }, reset: function (form) { $scope.myModelAddPendingDocDetails = { "documentDetails": "", "checkTracking": false } } } $scope.deletePendingDocDetails = function(details, StuID, Url) { // alert(JSON.stringify(details)); SweetAlert.swal({ title: "Warning!", text: "Want to Delete this Entry ?", type: "warning", showCancelButton: true, confirmButtonColor: "#007aff", confirmButtonText: "Yes!" }, function (res) { if (res === true) { $scope.documentTrackAddDetailsLoading = true; var deleteDocEntry = { method: 'POST', url: apiPoint.url + 'deleteDocPendingDetails/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: details.ID, localData: localDetail } }; $http(deleteDocEntry).then(function (response) { if (response.data.deleteStatus == true) { // swal("Success!", response.data.message, "success"); $scope.documentTrackAddDetailsLoading = false; // $scope.studentDocumentsList = ''; $scope.getStudentPendingEntrolDocDetails(StuID); } else { swal(" ", res.data.message, "error"); $scope.documentTrackAddDetailsLoading = false; } }); } }); } // end : entrollment document upload ==================================== $scope.stepsModelEdit = []; $scope.imageUploadEdit = function (event) { var files = event.target.files; //FileList object for (var i = 0; i < files.length; i++) { var file = files[i]; var reader = new FileReader(); reader.onload = $scope.imageIsLoadedEdit; reader.readAsDataURL(file); } } $scope.imageIsLoadedEdit = function (e) { $scope.$apply(function () { // $scope.stepsModel.push(e.target.result); $scope.stepsModelEdit[0] = e.target.result; }); } //an array of files selected $scope.filesEdit = []; //listen for the file selected event $scope.$on("fileSelectedEdit", function (event, args) { $scope.$apply(function () { //add the file object to the scope's files collection $scope.filesEdit[0] = args.file; }); }); // reset image for Edit $scope.resetImageEdit = function () { $scope.filesEdit.length = 0; $scope.stepsModelEdit.length = 0; } $scope.editSaveButtonDisable = false; // update student details $scope.updateStuDetails = function (form, p, hidedob) { $scope.editSaveButtonDisable = true; 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 idProof = $scope.filesEdit[0]; var formate = "dd-MM-yyyy"; var checkDOB = $filter('date')(new Date(p.DOB), formate); p.IsActive = p.IsActive === true ? 1 : 0; p.DOB = p.DOB == hidedob ? p.DOB : $filter('date')(new Date(p.DOB), formate); if (idProof == undefined) { // alert(idProof); 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(" ", "Updated successfully.", "success"); $scope.getStudentList(); $scope.editId = -1; $scope.editSaveButtonDisable = false; } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal(" ", response.data.message, "error"); $scope.editSaveButtonDisable = false; } }); } else { // alert(); var formData = new FormData(); var idStuUpProof = $scope.filesEdit[0]; // alert(idProof); formData.append("data", JSON.stringify(p)); formData.append("updatedBy", localDetails.localUserID); formData.append('idStuUpProof', idStuUpProof); $http.post(apiPoint.url + 'updateStudentImgDetails/', formData, { transformRequest: angular.identity, headers: { 'Content-Type': undefined, 'Process-Data': false }, }).success(function (res) { // alert(JSON.stringify(res)); if (res.updateStuStatus == true) { swal(" ", "Updated successfully.", "success"); $scope.getStudentList(); $scope.editId = -1; $scope.editSaveButtonDisable = false; } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal(" ", response.data.message, "error"); $scope.editSaveButtonDisable = false; } }); } } } }]); // Student datails for super admin : Start app.controller('studentSuperAdminCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "$http", "API_POINTS", "$state", '$rootScope', '$cookies', 'md5', 'ipCookie', '$timeout', '$window', "flowFactory", "SweetAlert", function ($scope, toaster, $filter, ngTableParams, $http, apiPoint, $state, $rootScope, $cookies, md5, ipCookie, $timeout, $window, flowFactory, SweetAlert) { /** * student details capture * by : kdk */ // get local client details var localDetail = JSON.parse(localStorage.getItem('localObj')); var localDetails = ipCookie('cookiechk'); $scope.localBranchDetails = ""; $scope.loader = false; $scope.viewStudentDetailsPage = false; // load when html page load $scope.init = function () { if (localDetail != null) { if (localDetails.localType === 'R004') { $scope.getBranchList(); } else { ipCookie.remove('cookiechk'); $window.localStorage.clear(); $state.go('login.signin'); } } else { } } $scope.getBranchList = function () { $scope.loader = true; var empListreq = { method: 'POST', url: apiPoint.url + 'getBranchListDetails/', headers: { 'Content-Type': 'application/json' }, data: { data: localDetails } }; $http(empListreq).then(function (response) { if (response.data.branDetailstatus) { $scope.loader = false; $scope.branchList_data = response.data.branch_details; } else { } }); } $scope.changeBranch = function () { $scope.viewStudentDetailsPage = false; localDetails.localBranchID = $scope.localBranchDetails; localDetail.localBranchID = $scope.localBranchDetails; getDetails() } function getDetails() { $scope.todayDate = new Date(); var nowInMS = new Date().getTime(), sixteenYearsInMS = 1000 * 60 * 60 * 24 * 365 * 16, sixteenYearsBeforeNow = new Date(nowInMS - sixteenYearsInMS); $scope.currentDate = new Date(sixteenYearsBeforeNow); $scope.getStudentList(); $scope.getUniversityList(); $scope.getUniversitySearchList(); // $scope.myModel.dateofbirth = $filter('date')($scope.currentDate, 'dd-MM-yyyy'); $scope.viewStudentDetailsPage = true; } $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, 'DeactiveComments': '', 'Comments': '' }; $scope.myModelCourse = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; $scope.myModelCourseAdd = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; $scope.inActiveBranchStatus = false; $scope.addStudentView = function () { // check the local branch is active for add a new student for this branch // alert(); var checkBranchActiveForStuAdd = { method: 'POST', url: apiPoint.url + 'getBranchActiveStatusforStuAdd/', headers: { 'Content-Type': 'application/json' }, data: { data: localDetails } }; $http(checkBranchActiveForStuAdd).then(function (response) { if (response.data) { var checkStatus = response.data.branch_active_status; if (checkStatus == "0") { $scope.inActiveBranchStatus = true; swal(" ", "Cannot create a new Student for In-Active Branch", "warning"); } else { // $scope.inActiveBranchStatus = false; } } else { } }); // $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 University List $scope.universitySearchData = ''; $scope.getUniversitySearchList = function () { var empListreq = { method: 'POST', url: apiPoint.url + 'getUniveCourseBratch/', headers: { 'Content-Type': 'application/json' }, data: { data: localDetails } }; $http(empListreq).then(function (response) { if (response.data.univList) { $scope.universitySearchData = response.data.university_details; // alert() } else { } }); }; $scope.searchData = { "University": "", "Course": "", "Status": "" } $scope.myUnivSearch = ""; $scope.getUniveId = function (univ) { let name = JSON.parse(univ); $scope.searchData.University = name.UniversityID; $scope.searchData.Course = ''; $scope.searchData.Batch = ''; $scope.courseData = name.Course; $scope.batchData = name.Batch; $scope.OpenWindowStatus = false; $scope.getStudentList(); }; $scope.getValueChange = function () { // $scope.searchData = { // "University": "", // "Course": "", // "Status": "" // } $scope.getStudentList(); } $scope.Searchloader = false; $scope.studentListLength = 0; $scope.getStudentList = function () { $scope.Searchloader = true; var empListreq = { method: 'POST', url: apiPoint.url + 'getStudentList/', headers: { 'Content-Type': 'application/json' }, data: { data: localDetails, search: $scope.searchData } }; $http(empListreq).then(function (response) { if (response.data.studentList) { $scope.Searchloader = false; $scope.studentData = true; $scope.data = response.data.student_details; $scope.studentListLength = $scope.data.length; } else { $scope.Searchloader = 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(" ", "Student course added successfully. ", "success"); $scope.getStudentCourseList($scope.currentStudentId); } else { swal(" ", 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, updatedBy: localDetails, } }; $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, hidedoj) { 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 = datas.DOJ == hidedoj ? 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("", "Updated successfully.", "success"); $scope.getStudentCourseList($scope.currentStudentId); // $scope.editCourseId = false; } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal(" ", 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; } }); } $scope.existingStudentView = false; $scope.existingStudentId = ''; // 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 { // } if (response.data.existMobile == true) { if (response.data.details.type === 'R001') { // swal("Warning!", response.data.message, "warning"); $scope.myModel.primaryPhone = ''; // student registration find student previously exist // $scope.existingStudentView = true; // $scope.existingStudentId = response.data.details.studentId; SweetAlert.swal({ title: "Warning!", text: "Student exist with this same Number." + "\n Do you want to Enroll New Course!", type: "warning", showCancelButton: true, confirmButtonColor: "#007aff", confirmButtonText: "Yes!" }, function (res) { if (res === true) { $scope.existingStudentView = true; $scope.existingStudentId = response.data.details.studentId; } }); } else if (response.data.details.type === 'R002' || response.data.details.type === 'R003') { swal("Warning!", response.data.message, "warning"); $scope.myModel.primaryPhone = ''; } else { swal("Warning!", response.data.message, "warning"); $scope.myModel.primaryPhone = ''; } } else { } }); } $scope.stuExistingDetailsShowLoading = false; $scope.getExistStudentDetails = function () { // alert($scope.existingStudentId); $scope.stuExistingDetailsShowLoading = true; var checkExisReq = { method: 'POST', url: apiPoint.url + 'getExistingStudentDetails/', headers: { 'Content-Type': 'application/json' }, data: { data: $scope.existingStudentId, reqDetails: localDetails } }; $http(checkExisReq).then(function (response) { if (response.data.existingStudentDetailsStatus == true) { $scope.existingStuPersonalDetails = response.data.personalDetails[0]; $scope.existingStuCourseDetails = response.data.courseDetails; $scope.stuExistingDetailsShowLoading = false; } else { $scope.stuExistingDetailsShowLoading = false; } }); } $scope.cancelExisStudentView = function () { $scope.existingStudentView = false; } // add student course for existing student $scope.addCourseExistingStudent = { submit: function (form, myModelCourse, 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(JSON.stringify(p.StudentID)); // alert(JSON.stringify(myModelCourse)); var formate = "dd-MM-yyyy"; $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(" ", "Student course added successfully. ", "success"); $scope.disableButton = false; $scope.viewStudentDetailsPage = false; $scope.myActivateDiv(); // $state.go($state.current, {}, { reload: true }); // $scope.getStudentCourseList($scope.currentStudentId); } else { swal(" ", response.data.message, "error"); // $scope.getStudentCourseList($scope.currentStudentId); $scope.myModelCourse.dateofjoining = ''; } }); } }, cancel: function () { $scope.myModelCourse = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; } } // 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 { } }); } //--------------------------------------------------------------> // getting for image to show //--------------------------------------------------------------> $scope.stepsModel = []; $scope.imageUpload = function (event) { var files = event.target.files; //FileList object for (var i = 0; i < files.length; i++) { var file = files[i]; var reader = new FileReader(); reader.onload = $scope.imageIsLoaded; reader.readAsDataURL(file); } } $scope.imageIsLoaded = function (e) { $scope.$apply(function () { // $scope.stepsModel.push(e.target.result); $scope.stepsModel[0] = e.target.result; }); } //an array of files selected $scope.files = []; //listen for the file selected event $scope.$on("fileSelected", function (event, args) { $scope.$apply(function () { //add the file object to the scope's files collection $scope.files[0] = args.file; }); }); // reset image $scope.resetImage = function () { $scope.files.length = 0; $scope.stepsModel.length = 0; } // $scope.getChangeDate = function () { // var formate = "dd-MM-yyyy"; // $scope.myModel.dateofbirth = $filter('date')(new Date($scope.myModel.dateofbirth), formate); // } $scope.tabactive1 = false; $scope.tabactive2 = false; $scope.tabActive = function (val) { if (val === 'tabactive1') { $scope.tabactive1 = true; $scope.tabactive2 = false; } else if (val === 'tabactive2') { $scope.tabactive2 = true; $scope.tabactive1 = false; } } $scope.myActivateDiv = function () { $scope.viewStudentDetailsPage = false; $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, 'DeactiveComments': '', 'Comments': '' }; $scope.myModelCourseAdd = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; $timeout(function () { getDetails(); }, 1000); } // add student $scope.studentFORM = { submit: function (form, myModel, myModelCourseAdd) { // alert(JSON.stringify(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.dateofbirth = $filter('date')(new Date($scope.myModel.dateofbirth), formate); myModel.switchsetting = myModel.switchsetting === true ? 1 : 0; myModelCourseAdd.dateofjoining = $filter('date')(new Date(myModelCourseAdd.dateofjoining), formate); var idStuProof = $scope.files[0]; if (idStuProof !== undefined) { var formData = new FormData(); var idProof = $scope.files[0]; // alert(idProof); formData.append("data", JSON.stringify(myModel)); formData.append("coursedata", JSON.stringify(myModelCourseAdd)); formData.append("createdBy", localDetails.localUserID); formData.append("loginBranch", localDetails.localBranchID); formData.append('idStuProof', idStuProof); $http.post(apiPoint.url + 'insertStudentImg/', formData, { transformRequest: angular.identity, headers: { 'Content-Type': undefined, 'Process-Data': false }, }).success(function (data) { if (data.addStudentStatus == true) { swal(" ", "Student picture added successfully.", "success"); $scope.disableButton = false; $scope.viewStudentDetailsPage = false; // $state.go($state.current, {}, { reload: true }); $scope.myActivateDiv(); // $scope.tabactive2 = false; // $scope.viewStudentDetailsPage = false; // $scope.tabActive('tabactive1'); } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal(" ", data.message, "error"); $scope.disableButton = false; } }); } else { var req = { method: 'POST', url: apiPoint.url + 'insertStudent/', headers: { 'Content-Type': 'application/json' }, data: { data: myModel, coursedata: myModelCourseAdd, loginBranch: localDetails.localBranchID, createdBy: localDetails.localUserID, } }; $http(req).then(function (response) { if (response.data.addStudentStatus == true) { swal("", "Student added successfully.", "success"); $scope.disableButton = false; $scope.viewStudentDetailsPage = false; // $state.go($state.current, {}, { reload: true }); $scope.myActivateDiv(); // $scope.tabactive1 = true; // $scope.tabactive2 = false; // $scope.tabActive('tabactive1'); } else { $scope.disableButton = false; swal(" ", response.data.message, "error"); } }); } } }, reset: function (form) { // $scope.myModel = angular.copy($scope.master); form.$setPristine(true); $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, 'DeactiveComments': '', 'Comments': '' }; $scope.myModelCourseAdd = { 'university': '', 'course': '', 'batch': '', 'dateofjoining': '', 'enrollmentid': '' }; }, 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 { } }); } // start : entrollment document upload ============================= $scope.studentDocumentsList = ''; // get Student Document Details $scope.getStuEntrollDocDetails = function (stuId) { // $scope.studentDocumentsList = ''; var getStudentDocDetails = { method: 'POST', url: apiPoint.url + 'getListofStuDocDetails/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: stuId, localData: localDetail } }; $http(getStudentDocDetails).then(function (response) { if (response.data.docListStatus == true) { $scope.docNotFound = false; $scope.studentDocumentsList = response.data.student_doc_details; } else { $scope.docNotFound = true; // $scope.studentDocumentsList.call(); } }); } $scope.deleteDocDetails = function (id, stuID) { SweetAlert.swal({ title: "Warning!", text: "Want to Delete this file ?", type: "warning", showCancelButton: true, confirmButtonColor: "#007aff", confirmButtonText: "Yes!" }, function (res) { if (res === true) { // alert(id); // alert(stuId); $scope.documentAddDetailsLoading = true; var deleteDocEntry = { method: 'POST', url: apiPoint.url + 'deleteStuDocDetails/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: stuID, docDetailsID: id, localData: localDetail } }; $http(deleteDocEntry).then(function (response) { if (response.data.deleteStatus == true) { // swal("Success!", response.data.message, "success"); $scope.documentAddDetailsLoading = false; $scope.studentDocumentsList = ''; $scope.getStuEntrollDocDetails(stuID); } else { swal(" ", res.data.message, "error"); $scope.documentAddDetailsLoading = false; } }); } }); } $scope.myModelAddDocuments = { "documentName": "", "documentComments": "" } //an array of documents selected $scope.filesDocuments = []; //listen for the document selected event $scope.$on("fileSelectedDocument", function (event, args) { $scope.$apply(function () { //add the file object to the scope's files collection $scope.filesDocuments[0] = args.file; }); }); $scope.documentAddDetailsLoading = false; $scope.studentEntrollDocFORM = { submit: function (form, myModelAddDocuments, stuID) { 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 ($scope.filesDocuments[0] == undefined || $scope.filesDocuments[0] == null || $scope.filesDocuments.length === 0) { swal("Warning!", "Choose the File.", "warning"); } else { $scope.documentAddDetailsLoading = true; var formData = new FormData(); var stuDocProof = $scope.filesDocuments[0]; var stuDocProofStatus = $scope.filesDocuments[0] !== undefined ? true : false; formData.append("data", JSON.stringify(myModelAddDocuments)); formData.append("studentID", stuID); formData.append("updatedBy", localDetails.localUserID); formData.append('stuDocProof', stuDocProof); formData.append('stuDocProof_Status', stuDocProofStatus); $http.post(apiPoint.url + 'addStudentEntrollDocDetails/', formData, { transformRequest: angular.identity, headers: { 'Content-Type': undefined, 'Process-Data': false }, }).success(function (res) { if (res.stuDocUpdateStatus == true) { $scope.getStuEntrollDocDetails(stuID); // swal(" ", "Updated successfully.", "success"); $scope.documentAddDetailsLoading = false; $scope.filesDocuments[0] = undefined; form.$setPristine(true); angular.element("input[type='file']").val(null); $scope.myModelAddDocuments = { "documentName": "", "documentComments": "" } // $scope.getStudentList(); // $scope.editId = -1; // $scope.editSaveButtonDisable = false; } else { swal(" ", res.data.message, "error"); $scope.documentAddDetailsLoading = false; // $scope.editSaveButtonDisable = false; } }); } } }, reset: function (form) { $scope.filesDocuments[0] = undefined; form.$setPristine(true); angular.element("input[type='file']").val(null); } } // $scope.PendingDocNotFound = false; // student pending document details $scope.getStudentPendingEntrolDocDetails = function(stuId) { // $scope.studentDocumentsList = ''; var getStudentPendingDocDetails = { method: 'POST', url: apiPoint.url + 'getListofStuPendingDocDetails/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: stuId, localData: localDetail } }; $http(getStudentPendingDocDetails).then(function (response) { if (response.data.PendingDocListStatus == true) { // $scope.PendingDocNotFound = false; $scope.studentPendingDocumentsDetails = response.data.student_pending_doc_details; } else { // $scope.PendingDocNotFound = true; } }); } $scope.myModelAddPendingDocDetails = { "documentDetails": "", "checkTracking": false } $scope.documentTrackAddDetailsLoading = false; $scope.studentEntrollPendingDocFORM = { submit: function (form, myModelAddPendingDocDetails, stuID) { $scope.documentTrackAddDetailsLoading = true; 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 { var ModelDetails = { "student" : stuID, "doc_Details": myModelAddPendingDocDetails.documentDetails, "checkTracking": myModelAddPendingDocDetails.checkTracking }; var updateStudentPendingDocDetails = { method: 'POST', url: apiPoint.url + 'addStudentEnrollPendingDocDetails/', headers: { 'Content-Type': 'application/json' }, data: { updateDetails: ModelDetails, localData: localDetail } }; $http(updateStudentPendingDocDetails).then(function (response) { if (response.data.AddStuPendingDocStatus == true) { $scope.getStudentPendingEntrolDocDetails(stuID); $scope.documentTrackAddDetailsLoading = false; $scope.myModelAddPendingDocDetails = { "documentDetails": "", "checkTracking": false } } else { swal(" ", res.data.message, "error"); $scope.documentTrackAddDetailsLoading = false; } }); } }, reset: function (form) { $scope.myModelAddPendingDocDetails = { "documentDetails": "", "checkTracking": false } } } $scope.deletePendingDocDetails = function(details, StuID, Url) { // alert(JSON.stringify(details)); SweetAlert.swal({ title: "Warning!", text: "Want to Delete this Entry ?", type: "warning", showCancelButton: true, confirmButtonColor: "#007aff", confirmButtonText: "Yes!" }, function (res) { if (res === true) { $scope.documentTrackAddDetailsLoading = true; var deleteDocEntry = { method: 'POST', url: apiPoint.url + 'deleteDocPendingDetails/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: details.ID, localData: localDetail } }; $http(deleteDocEntry).then(function (response) { if (response.data.deleteStatus == true) { // swal("Success!", response.data.message, "success"); $scope.documentTrackAddDetailsLoading = false; // $scope.studentDocumentsList = ''; $scope.getStudentPendingEntrolDocDetails(StuID); } else { swal(" ", res.data.message, "error"); $scope.documentTrackAddDetailsLoading = false; } }); } }); } // end : entrollment document upload ==================================== $scope.stepsModelEdit = []; $scope.imageUploadEdit = function (event) { var files = event.target.files; //FileList object for (var i = 0; i < files.length; i++) { var file = files[i]; var reader = new FileReader(); reader.onload = $scope.imageIsLoadedEdit; reader.readAsDataURL(file); } } $scope.imageIsLoadedEdit = function (e) { $scope.$apply(function () { // $scope.stepsModel.push(e.target.result); $scope.stepsModelEdit[0] = e.target.result; }); } //an array of files selected $scope.filesEdit = []; //listen for the file selected event $scope.$on("fileSelectedEdit", function (event, args) { $scope.$apply(function () { //add the file object to the scope's files collection $scope.filesEdit[0] = args.file; }); }); // reset image for Edit $scope.resetImageEdit = function () { $scope.filesEdit.length = 0; $scope.stepsModelEdit.length = 0; } $scope.editSaveButtonDisable = false; // update student details $scope.updateStuDetails = function (form, p, hidedob) { var firstError = null; $scope.editSaveButtonDisable = true; if (form.$invalid) { alert("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 idProof = $scope.filesEdit[0]; var formate = "dd-MM-yyyy"; var checkDOB = $filter('date')(new Date(p.DOB), formate); p.IsActive = p.IsActive === true ? 1 : 0; p.DOB = p.DOB == hidedob ? p.DOB : $filter('date')(new Date(p.DOB), formate); if (idProof == undefined) { // alert(idProof); 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("", "Updated successfully.", "success"); $scope.getStudentList(); $scope.editId = -1; $scope.editSaveButtonDisable = false; } else { // $scope.ldloading1[loading.replace('-', '_')] = false; // alert(response.data.message); swal("", response.data.message, "error"); $scope.editSaveButtonDisable = false; } }); } else { var formData = new FormData(); var idStuUpProof = $scope.filesEdit[0]; // alert(idProof); formData.append("data", JSON.stringify(p)); formData.append("updatedBy", localDetails.localUserID); formData.append('idStuUpProof', idStuUpProof); $http.post(apiPoint.url + 'updateStudentImgDetails/', formData, { transformRequest: angular.identity, headers: { 'Content-Type': undefined, 'Process-Data': false }, }).success(function (response) { if (response.updateStuStatus == true) { swal("", "Updated successfully.", "success"); $scope.getStudentList(); $scope.editId = -1; $scope.editSaveButtonDisable = false; } else { // $scope.ldloading1[loading.replace('-', '_')] = false; // swal("", data.message, "error"); swal("", response.data.message, "error"); $scope.editSaveButtonDisable = false; } }); } } } }]); // file upload directive app.directive('fileUpload', function () { return { scope: true, //create a new scope link: function (scope, el, attrs) { el.bind('change', function (event) { var files = event.target.files; //iterate files since 'multiple' may be specified on the element for (var i = 0; i < files.length; i++) { //emit event upward scope.$emit("fileSelected", { file: files[i] }); } }); } }; }); // file upload directive app.directive('fileUploadEdit', function () { return { scope: true, //create a new scope link: function (scope, el, attrs) { el.bind('change', function (event) { var files = event.target.files; //iterate files since 'multiple' may be specified on the element for (var i = 0; i < files.length; i++) { //emit event upward scope.$emit("fileSelectedEdit", { file: files[i] }); } }); } }; }); // file upload directive - file-upload-document app.directive('fileUploadDocument', function () { return { scope: true, //create a new scope link: function (scope, el, attrs) { el.bind('change', function (event) { var files = event.target.files; //iterate files since 'multiple' may be specified on the element for (var i = 0; i < files.length; i++) { //emit event upward scope.$emit("fileSelectedDocument", { file: files[i] }); } }); } }; }); app.filter('unique', function () { return function (collection, primaryKey, secondaryKey) { //optional secondary key var output = [], keys = []; angular.forEach(collection, function (item) { var key; secondaryKey === undefined ? key = item[primaryKey] : key = item[primaryKey][secondaryKey]; if (keys.indexOf(key) === -1) { keys.push(key); output.push(item); } }); return output; }; }); /*modal controller * */ app.controller('studentModalDemoCtrl', ["$scope", "$modal", "$log", "API_POINTS", "$http", function ($scope, $modal, $log, apiPoint, $http) { //Tooltip for print button $scope.dynamicTooltip = 'Student View'; // $scope.items = ['item1', 'item2', 'item3']; $scope.open = function (studentDetails) { // get student view details var getcourse = { method: 'POST', url: apiPoint.url + 'getStudentBasicInfo/', headers: { 'Content-Type': 'application/json' }, data: { requestedBy: studentDetails.StudentID, requestedFrom: 1 } }; $http(getcourse).then(function (response) { if (response.data.status == 200 && response.data.studentStatus == true) { $scope.courseEditLoading = false; // $scope.studentDetails = response.data.studentDetails; $scope.studentDetails = response.data; // $scope.courseDetails = response.data.courseDetails; var modalInstance = $modal.open({ templateUrl: 'assets/views/student/studentDetailsModal.html', controller: 'ModalInstanceCtrl', // size: size, resolve: { items: function () { return $scope.studentDetails; } } }); modalInstance.result.then(function (selectedItem) { $scope.selected = selectedItem; }, function () { $log.info('Modal dismissed at: ' + new Date()); }); } else { swal("Failed!", "This student is not registerd", "warning"); $scope.courseEditLoading = false; $scope.studentDetails = ""; $scope.courseDetails = ""; } }); }; $scope.open1 = function (values) { var modalInstance1 = $modal.open({ templateUrl: 'assets/views/student/studentPaymentModal.html', controller: 'ModalInstanceCtrl1', // size: size, resolve: { items1: function () { return values; } } }); modalInstance1.result.then(function (selectedItem) { $scope.selected = selectedItem; }, function () { $log.info('Modal dismissed at: ' + new Date()); }); }; }]); // Please note that $modalInstance represents a modal window (instance) dependency. // It is not the same as the $modal service used above. app.controller('ModalInstanceCtrl', ["$scope", "$modalInstance", "items", "WordsService", function ($scope, $modalInstance, items, WordsService) { $scope.items = items; $scope.selected = { item: $scope.items[0] }; $scope.ok = function () { $modalInstance.close($scope.selected.item); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); app.controller('ModalInstanceCtrl1', ["$scope", "$modalInstance", "items1", "WordsService", function ($scope, $modalInstance, items1, WordsService) { $scope.items1 = items1; $scope.ok = function () { $modalInstance.close($scope.selected.item); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); // Hook in a directive app.directive('fileDownload', function($window){ // alert(path); return { restrict: 'E', // applied on 'element' scope: { fileurl: '@fileurl', linktext: '@linktext' }, controller: function($scope) { $scope.path = $window.location.origin + $window.location.pathname + 'images/'; }, template: '', // need this so that the inner HTML can be re-used link: function(scope, elem, attrs) { /* Ref: https://thinkster.io/egghead/isolate-scope-at * This block is used when we have * scope: { fileurl: '=fileurl', linktext: '=linktext' } scope.fileurl = attrs.fileurl; scope.linktext = attrs.linktext;*/ } } }) app.directive('capitalizeFirst', function($parse) { return { require: 'ngModel', link: function(scope, element, attrs, modelCtrl) { var capitalize = function(inputValue) { if (inputValue === undefined) { inputValue = ''; } var capitalized = inputValue.charAt(0).toUpperCase() + inputValue.substring(1); if(capitalized !== inputValue) { modelCtrl.$setViewValue(capitalized); modelCtrl.$render(); } return capitalized; } modelCtrl.$parsers.push(capitalize); capitalize($parse(attrs.ngModel)(scope)); // capitalize initial value } }; });