205 lines
6.6 KiB
JavaScript
205 lines
6.6 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,
|
|
};
|
|
|
|
// 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 () {
|
|
if (localDetail != null) {
|
|
$scope.currentDate = new Date();
|
|
$scope.getUniversityList();
|
|
|
|
// $scope.currentPage = 1;
|
|
} else {
|
|
}
|
|
}
|
|
|
|
$scope.editId = -1;
|
|
$scope.editBranchId = -1;
|
|
$scope.setEditId = function (id) {
|
|
$scope.editId = id;
|
|
$scope.editBranchId = -1;
|
|
}
|
|
|
|
$scope.setEditBranchId = function (id) {
|
|
$scope.editBranchId = id;
|
|
$scope.editId = -1;
|
|
$scope.branchEditLoading = true;
|
|
}
|
|
|
|
$scope.cancel = function () {
|
|
$scope.editId = -1;
|
|
$scope.editBranchId = -1;
|
|
}
|
|
|
|
|
|
$scope.universityData = '';
|
|
|
|
$scope.getUniversityList = function () {
|
|
var empListreq = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getUniversity/',
|
|
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.courseData = '';
|
|
$scope.batchData = '';
|
|
$scope.courseLoading = false;
|
|
$scope.onSlecetUniv = function() {
|
|
$scope.myModel.course= '';
|
|
$scope.myModel.batch= '';
|
|
$scope.courseLoading = true;
|
|
var univListreq = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getCourseBatchForUniv/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
data: $scope.myModel.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;
|
|
}
|
|
});
|
|
}
|
|
|
|
// add student
|
|
$scope.studentFORM = {
|
|
submit: function (form, myModel) {
|
|
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 formate = "dd-MM-yyyy";
|
|
$scope.myModel.switchsetting = $scope.myModel.switchsetting === true ? 1 : 0;
|
|
$scope.myModel.dateofbirth = $filter('date')(new Date($scope.myModel.dateofbirth), formate);
|
|
var req = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'insertStudent/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
data: $scope.myModel,
|
|
loginBranch: localDetails.localBranchID,
|
|
createdBy: localDetails.localUserID,
|
|
}
|
|
};
|
|
$http(req).then(function (response) {
|
|
if (response.data.addEmpStatus == true) {
|
|
swal("Success!", response.data.message, "success");
|
|
$state.go($state.current, {}, { reload: true });
|
|
} else {
|
|
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,
|
|
};
|
|
}
|
|
}
|
|
|
|
}]);
|