apollodec/Apollo/assets/js/controllers/universityCtrl.js
venbatechnologies@gmail.com d06b1c0cba status file
2017-12-07 11:31:25 +05:30

195 lines
6.7 KiB
JavaScript
Executable File

'use strict';
/**
* controllers for ng-table
* Simple table with sorting and filtering on AngularJS
*/
app.controller('universityCtrl', ["$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) {
/**
* university details capture
* by : kdk
*/
// get local cliend details
var localDetail = JSON.parse(localStorage.getItem('localObj'));
var localDetails = ipCookie('cookiechk');
$scope.myModel = {
'UniversityID': '',
'UniversityName': '',
'UniversityShortName': '',
'MobileNumber': '',
'EmailID': '',
'Address': '',
'switchsetting': true,
};
$scope.init = function() {
$scope.getUniversityList();
}
// 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
}
$scope.getUniversityList = function () {
$scope.loader = true;
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.loader = false;
$scope.emptyUniversity = true;
$scope.data = response.data.university_details;
} else {
$scope.loader = false;
$scope.emptyUniversity = false;
}
});
}
// check employee Id existing
$scope.checkUnivIdExist = function () {
var checkReq = {
method: 'POST',
url: apiPoint.url + 'chkUnivIdExistDetail/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: $scope.myModel.UniversityID,
check: 'univId'
}
};
$http(checkReq).then(function (response) {
if (response.data.existUniv === true) {
swal("Warning!", response.data.message, "warning");
$scope.myModel.UniversityID = '';
} else {
}
});
}
$scope.setEditId = function (id) {
// alert(id);
$scope.editId = id;
}
$scope.cancel = function () {
$scope.getUniversityList();
$scope.editId = -1;
}
$scope.updateUniversityDetails = function (form, p) {
var firstError = null;
if (form.$invalid) {
var field = null, firstError = null;
for (field in form) {
if (field[0] != '$') {
if (firstError === null && !form[field].$valid) {
firstError = form[field].$name;
}
if (form[field].$pristine) {
form[field].$dirty = true;
}
}
}
angular.element('.ng-invalid[name=' + firstError + ']').focus();
// swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error");
} else {
p.IsActive = p.IsActive === true ? 1 : 0;
var req = {
method: 'POST',
url: apiPoint.url + 'updateUniversityDetail/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: p,
updatedBy: localDetails.localUserID,
}
};
$http(req).then(function (response) {
if (response.data.updateUniversityStatus = true) {
swal("Success!", response.data.message, "success");
$scope.getUniversityList();
$scope.editId = -1;
} else {
// $scope.ldloading1[loading.replace('-', '_')] = false;
swal("Failed!", response.data.message, "error");
}
});
}
}
// add university
$scope.universityForm = {
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 {
$scope.myModel.switchsetting = $scope.myModel.switchsetting === true ? 1 : 0;
var req = {
method: 'POST',
url: apiPoint.url + 'insertUniversity/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: $scope.myModel,
createdBy: localDetails.localUserID,
}
};
$http(req).then(function (response) {
if (response.data.addUniv == true) {
swal("Success!", response.data.message, "success");
$state.go($state.current, {}, { reload: true });
} else {
// $scope.ldloading1[loading.replace('-', '_')] = false;
swal("Failed!", response.data.message, "error");
}
});
}
},
reset: function (form) {
// $scope.myModel = angular.copy($scope.master);
form.$setPristine(true);
$scope.myModel = {
'UniversityID': '',
'UniversityName': '',
'UniversityShortName': '',
'MobileNumber': '',
'EmailID': '',
'Address': '',
};
}
}
}]);