'use strict'; /*** controller for Wizard Form example***/ app.controller('studyMaterialStatusCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "API_POINTS", "$http", "SweetAlert", "$state", 'md5', 'ipCookie', '$window', "dateListDescService", function ($scope, toaster, $filter, ngTableParams, apiPoint, $http, SweetAlert, $state, md5, ipCookie, $window, dateListDescService) { /** * Study material status update search * by : kdk */ $scope.sort = function (keyname) { $scope.sortKey = keyname; //set the sortKey to the param passed $scope.reverse = !$scope.reverse; //if true make it false and vice versa } $scope.editId = -1; $scope.setEditId = function (P) { $scope.statusUpdationId = -1; $scope.editId = P; } $scope.cancel = function () { $scope.editId = -1; } // get local client details var localDetail = JSON.parse(sessionStorage.getItem('localObj')); var localDetails = ipCookie('cookiechk'); const localUpdateStatus = 'STUDY_MATERIAL'; $scope.localTypeSuperAdmin = false; $scope.localBranchDetails = ''; $scope.init = function () { var logcheck = JSON.parse(sessionStorage.getItem('localObj')); const LOCALTYPE = logcheck.localType; if (logcheck != null && (LOCALTYPE == 'R003' || LOCALTYPE == 'R004' || LOCALTYPE=='R002' || LOCALTYPE == 'R005' )) { console.log("if"); }else { if(logcheck != null && LOCALTYPE !='R001') { console.log("else if"); $state.go('app.dashboard'); } else { console.log("else else"); //ipCookie.remove('cookiechk'); window.sessionStorage.clear(); $state.go('login.signin'); } } if (localDetail != null) { if (localDetails.localType === 'R004') { $scope.localTypeSuperAdmin = true; $scope.getUniversityList(); $scope.getBranchList(); } else { $scope.getUniversityList(); } } 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.searchData = { 'University': '', 'Course': '', 'Batch': '', 'Mobile': '', 'Name': '' } $scope.myStatusModel = { 'semYear': '', 'staus': '', 'dateOn': '', 'comment': '', 'sem': '' } $scope.universityData = ''; // get university list while the page is load $scope.getUniversityList = 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.universityData = response.data.university_details; } else { } }); }; $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; //call service for array list in desc order based on date angular.forEach($scope.batchData,function (values,key) { var parts = values.BatchDate.split("-"); values.givenDateObject=new Date(parts[2], parts[1] - 1, parts[0]); }); $scope.batchData=dateListDescService.getOrderByList($scope.batchData); // end $scope.OpenWindowStatus = false; $scope.getSearch(); }; $scope.getValueChange = function () { $scope.getSearch(); } $scope.searchResultDetails = []; $scope.searchLoading = false; $scope.searchResultLength = 0; // get student list based on the search data $scope.getSearch = function () { $scope.OpenWindowStatus = false; $scope.searchLoading = true; var getSearchDetails = { method: 'POST', url: apiPoint.url + 'getSearchAutoDetails/', headers: { 'Content-Type': 'application/json' }, data: { data: $scope.searchData, requestDetails: localDetails } }; $http(getSearchDetails).then(function (response) { if (response.data.searchResult) { $scope.searchResultStatus = response.data.searchResult; $scope.searchLoading = false; let searchResultDetailsBef = response.data.search_result_details; const filterAddSelect = searchResultDetailsBef.filter(val => { val['Selected'] = false; return val; }); $scope.searchResultDetails = filterAddSelect; $scope.searchResultLength = Object.keys($scope.searchResultDetails).length; } else { $scope.searchLoading = false; } }); } // mobile number search functionlity $scope.mySearchChangeFunc = function (val) { if (val > 0) { // $scope.allSelectedHide = true; // $scope.allSelected('undefined'); // $scope.OpenWindowStatus = false; } else { // $scope.allSelected('undefined'); // $scope.allSelectedHide = false; // $scope.OpenWindowStatus = false; } } // End: mobile number search functionlity // select all or individual functionality // var getAllSelected = function () { // var selectedItems = $scope.searchResultDetails.filter(function (item) { // return item.Selected; // }); // return selectedItems.length === $scope.searchResultDetails.length; // } // var setAllSelected = function (value) { // angular.forEach($scope.searchResultDetails, function (item) { // item.Selected = value; // }); // } // $scope.allSelected = function (value) { // if (value !== undefined) { // return setAllSelected(value); // } else { // return getAllSelected(); // } // } // Select one row in a table once $scope.setOneSelect = function (value) { angular.forEach($scope.searchResultDetails, function (item) { item.Selected = false; }); $scope.editId = -1; $scope.statusUpdationId = value.UNI_ID; value.Selected = true; $scope.OpenWindowStatus = true; $scope.openUpdateWind(); } // End: select all or individual functionality // unselect all the selected items $scope.unSelect = function () { // alert(value.Selected); angular.forEach($scope.searchResultDetails, function (item) { item.Selected = false; }); $scope.statusUpdationId = -1; $scope.openUpdateWind(); } // open popup window onselct checkbox / close popup window uncheck all the selected items $scope.OpenWindowStatus = false; $scope.openUpdateWind = function () { // $location.hash('bottom'); // call $anchorScroll() // alert(document.getElementById('bottom1')); $window.scrollTo(0, 1800); // $window.scrollTo(0, angular.element(document.getElementById('bottom1')).offsetTop); var ItemsSelected = $scope.searchResultDetails.filter(function (item) { if (item.Selected === true) { return true; } }); if (ItemsSelected.length !== 0) { const courseLocal = ItemsSelected[0].CourseID; const selectedStuId = ItemsSelected[0].StudentID; $scope.getSemYearList(courseLocal, selectedStuId); $scope.getStatusList(); $scope.OpenWindowStatus = true; $scope.myStatusModel = { 'semYear': '', 'staus': '', 'dateOn': '', 'comment': '', 'sem': '' } } else { $scope.OpenWindowStatus = false; } } // get status list for this activity $scope.getStatusList = function () { var getStatusL = { method: 'POST', url: apiPoint.url + 'getStatusListForUpdate/', headers: { 'Content-Type': 'application/json' }, data: { statusFor: 'studyMaterial', data: localUpdateStatus, reqBranch: localDetails.localBranchID } }; $http(getStatusL).then(function (response) { if (response.data.statusList) { $scope.statusDetailsList = response.data.statusList_details; // $scope.searchLoading = false; } else { // $scope.searchLoading = false; } }); } // get Sem/Year based on the course select $scope.getSemYearList = function (courseID, StuId) { $scope.semYearList = ''; if (courseID !== '' && courseID !== undefined) { var getSemYear = { method: 'POST', url: apiPoint.url + 'getSemYearForCourse/', headers: { 'Content-Type': 'application/json' }, data: { data: courseID, stuFor: StuId, reqBranch: localDetails.localBranchID } }; $http(getSemYear).then(function (response) { if (response.data.semYearResult) { $scope.semYearList = response.data.semYear_result_details; } else { $scope.semYearList = ''; } }); } else { } } $scope.maxDateForStatusUpdt = ''; $scope.Currentdate= new Date(); $scope.statusCheck = function(sts){ let stas = JSON.parse(sts); $scope.myStatusModel.staus = stas.ListCode; let str = stas.ListName; $scope.myStatusModel.dateOn = ''; if(str.toLowerCase() == "issued" || str.toLowerCase() == "received") { $scope.maxDateForStatusUpdt = new Date(); }else { $scope.maxDateForStatusUpdt = ''; } } $scope.showSingleLateralSemType = false; // sem year show when REGULAR or LATER ENTRY $scope.getSemYearDropShowMethod = function(type) { if(JSON.parse(type).SEM_YEAR_TYPE == "0"){ // type is semester mode $scope.showSingleLateralSemType = false; } else { $scope.showSingleLateralSemType = true; } } $scope.semDetails =[{"id": 1, "type": "SEM 1"}, {"id": 2, "type": "SEM 2"}, {"id": 3, "type": "SEM 3"}, {"id": 4, "type": "SEM 4"}, {"id": 5, "type": "SEM 5"}, {"id": 6, "type": "SEM 6"}, {"id": 7, "type": "SEM 7"}, {"id": 8, "type": "SEM 8"} , {"id": 9, "type": "YEAR 1"}, {"id": 10, "type": "YEAR 2"}, {"id": 11, "type": "YEAR 3"}, {"id": 12, "type": "YEAR 4"}] $scope.statusUpdate = { submit: function (form, myStatusModel, localBranchDetails) { 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(localBranchDetails); localDetails.localBranchID = localBranchDetails !== '' ? localBranchDetails : localDetails.localBranchID ; localDetail.localBranchID = localBranchDetails !== '' ? localBranchDetails : localDetail.localBranchID ; // alert(localDetails.localBranchID); $scope.disableButton = true; var studentForUpdate = []; let formate = "dd-MM-yyyy"; $scope.myStatusModel.dateOn = $filter('date')(new Date($scope.myStatusModel.dateOn), formate); var ItemsSelected = $scope.searchResultDetails.filter(function (item) { if (item.Selected === true) { let getStudentID = new getStudentForUpdateDetails(item.StudentID, item.BranchCode); studentForUpdate.push(getStudentID); return true; } }); function getStudentForUpdateDetails(id, bCode) { this.StudentID = id; var courseID = JSON.parse($scope.myStatusModel.semYear); // eval('var obj='+courseID); // alert(courseID); var val = courseID.ID; this.CourseID = val; this.BranchCode = bCode; this.ListCode = $scope.myStatusModel.staus; this.SDate = $scope.myStatusModel.dateOn; this.Coursedetail = id; this.Comments = $scope.myStatusModel.comment; this.Sem = $scope.myStatusModel.sem === '' ? courseID.Sem_Year : $scope.myStatusModel.sem; } var updateStudyMaterial = { method: 'POST', url: apiPoint.url + 'updateStudentMaterialStatus/', headers: { 'Content-Type': 'application/json' }, data: { data: studentForUpdate, requestDetails: localDetails } }; $http(updateStudyMaterial).then(function (response) { if (response.data.addStatus) { swal(" ", "Updated successfully.", "success"); $scope.disableButton = false; // for success state // $scope.allSelected('undefined'); angular.forEach($scope.searchResultDetails, function (item) { item.Selected = false; }); $scope.OpenWindowStatus = false; } else { swal(" ", response.data.message, "error"); $scope.disableButton = false; } }); } }, reset: function (form) { form.$setPristine(true); $scope.myStatusModel = { 'semYear': '', 'staus': '', 'dateOn': '', 'comment': '', 'sem': '' } } } // check unchek for table values $scope.prevStatusListForStudentCourse = ''; // get previous status details for the student $scope.getPrevStatus = function (p) { $scope.prevStatusListForStudentCourseLoading = true; $scope.prevStatusListForStudentCourseNoRecord = false; $scope.prevStatusListForStudentCourse = ''; var getPrevStatus = { method: 'POST', url: apiPoint.url + 'getPrevStatusDetailsForStu/', headers: { 'Content-Type': 'application/json' }, data: { statusFor: localUpdateStatus, getDetailsFor: { "student": p.StudentID, "CourseID": p.CourseID }, data: localDetail } }; $http(getPrevStatus).then(function (response) { if (response.data.preStatusDetails) { $scope.prevStatusListForStudentCourseLoading = false; $scope.prevStatusListForStudentCourse = response.data.preStatus_details_list; $scope.prevNoRecordFound = false; } else { $scope.prevStatusListForStudentCourseLoading = false; $scope.prevStatusListForStudentCourseNoRecord = true; $scope.prevNoRecordFound = true; } }); } }]); /*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) { $scope.Currentdate = new Date(); console.log($scope.Currentdate); // get student view details var getcourse = { method: 'POST', url: apiPoint.url + 'getStudentBasicInfo/', headers: { 'Content-Type': 'application/json' }, data: { requestedBy :studentDetails.MobileNumber, requestedFrom: 3, branchCode:JSON.parse(sessionStorage.getItem('localObj')).localBranchID } }; $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,type) { var modalInstance1 = $modal.open({ templateUrl: 'assets/views/student/studentPaymentModal.html', controller: 'ModalInstanceCtrl1', // size: size, resolve: { items1: function () { var myvalues = { "values":values, "type":type }; return myvalues; } } }); 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.values; $scope.selectedtype = items1.type; $scope.ok = function () { $modalInstance.close($scope.selected.item); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); 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; }; });