233 lines
7.0 KiB
JavaScript
Executable File
233 lines
7.0 KiB
JavaScript
Executable File
'use strict';
|
|
/**
|
|
* controllers for ng-table
|
|
* Simple table with sorting and filtering on AngularJS
|
|
*/
|
|
|
|
app.controller('subjectCtrl', ["$scope", "$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state",'ipCookie', function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state,ipCookie) {
|
|
$scope.myModel = {
|
|
|
|
"SubjectCode": "",
|
|
"SubjectNme": "",
|
|
"switchsetting": true,
|
|
|
|
};
|
|
|
|
|
|
/*
|
|
* edit batch details
|
|
* created by subaram
|
|
* */
|
|
$scope.editId = -1;
|
|
$scope.setEditId = function (pid) {
|
|
|
|
$scope.editId = pid;
|
|
$scope.viewId = -1;
|
|
};
|
|
|
|
/*
|
|
* cancel edit div
|
|
* created by subaram
|
|
* */
|
|
$scope.cancel = function () {
|
|
$scope.init();
|
|
$scope.editId = -1;
|
|
|
|
};
|
|
|
|
// 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
|
|
}
|
|
|
|
|
|
/*
|
|
* Submit,update and reset Subject details
|
|
* @params myModel
|
|
*
|
|
* */
|
|
$scope.subjectFORM = {
|
|
submit: function (form, myModel,loading) {
|
|
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.ldloading1 = {};
|
|
|
|
$scope.ldloading1[loading.replace('-', '_')] = true;
|
|
|
|
|
|
var addSubject = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'addSubjectDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
SubjectCode:myModel.SubjectCode,
|
|
SubjectName:myModel.SubjectName,
|
|
Status: myModel.switchsetting,
|
|
createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID
|
|
}
|
|
};
|
|
|
|
$http(addSubject).then(function (response) {
|
|
if (response.data.status==200 && response.data.SubjectStatus) {
|
|
|
|
$scope.ldloading1[loading.replace('-', '_')] = false;
|
|
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 = {
|
|
"SubjectCode": "",
|
|
"SubjectName": "",
|
|
"switchsetting": true
|
|
};
|
|
form.$setPristine(true);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*update subject details
|
|
* * @params myModel*/
|
|
|
|
$scope.updateSubject = function (myModel, form, loading) {
|
|
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].$stop_name;
|
|
}
|
|
|
|
if (form[field].$pristine) {
|
|
form[field].$dirty = true;
|
|
}
|
|
}
|
|
}
|
|
angular.element('.ng-invalid[name=' + firstError + ']').focus();
|
|
} else {
|
|
|
|
|
|
$scope.ldloading = {};
|
|
|
|
$scope.ldloading[loading.replace('-', '_')] = true;
|
|
|
|
|
|
var update = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'updateSubjectDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
|
|
data: {
|
|
|
|
SubjectCode:myModel.SubjectCode,
|
|
SubjectName:myModel.SubjectName,
|
|
Status:myModel.IsActive,
|
|
SubjectID: myModel. SubjectID, //auto id
|
|
updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID
|
|
}
|
|
};
|
|
$http(update).then(function (response) {
|
|
if (response.data.status==200 && response.data.SubjectStatus) {
|
|
$scope.ldloading[loading.replace('-', '_')] = false;
|
|
$scope.init();
|
|
swal("Success!", response.data.message, "success");
|
|
|
|
} else {
|
|
$scope.ldloading[loading.replace('-', '_')] = false;
|
|
$scope.init();
|
|
swal("Failed!", response.data.message, "error");
|
|
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
|
|
/*
|
|
*get Subject details when page loading called from view file
|
|
*
|
|
* created by Srk
|
|
* */
|
|
|
|
$scope.loader='';
|
|
|
|
$rootScope.emptyData='';
|
|
|
|
|
|
$scope.init = function () {
|
|
|
|
$scope.loader='';
|
|
|
|
var getsubject = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getSubjectDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID
|
|
}
|
|
};
|
|
|
|
$http(getsubject).then(function (response) {
|
|
if (response.data.status==200 && response.data.SubjectStatus) {
|
|
|
|
$scope.emptyData=true;
|
|
$scope.loader=true;
|
|
$scope.data = response.data.details;
|
|
|
|
} else {
|
|
$scope.emptyData=false;
|
|
$scope.loader=true;
|
|
$scope.data = response.data.details;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}]);
|