/**
* Created by cklimkowsky on 5/5/15.
*/
angular
.module('coopEval')
.controller('AssignFormController', AssignFormController);
function AssignFormController($scope, $rootScope, $location, administrationService) {
// Get the list of all colleges in the system
administrationService.getColleges()
.success(function (result) {
$scope.colleges = result;
$scope.selectedCollege = $scope.colleges[0];
});
// Get the list of all future terms in the system
administrationService.getFutureTerms()
.success(function (result) {
$scope.futureTerms = result;
});
// Get the list of all Student forms in the system
administrationService.getStudentForms()
.success(function (result) {
$scope.studentForms = result;
$scope.forms = $scope.studentForms;
});
// Get the list of all Employer forms in the system
administrationService.getEmployerForms()
.success(function (result) {
$scope.employerForms = result;
});
// The form type that is currently selected in the UI (default is Student)
$scope.formType = 0;
// The name of the form currently assigned to the selected department and term (default is None)
$scope.currentFormName = 'None';
// When the user selects another colleges, get the departments for the newly selected college
$scope.$watch('selectedCollege', function () {
if ($scope.selectedCollege) {
administrationService.getDepartments($scope.selectedCollege.collegeId)
.success(function (result) {
$scope.departments = result;
$scope.selectedDepartment = $scope.departments[0];
});
}
});
// When the user selects a term, get the name of the form currently
// assigned to the selected department for that term
$scope.$watch('selectedTerm', function () {
if ($scope.selectedDepartment) {
if ($scope.formType == 0 && $scope.selectedDepartment.currentStudentFormName) {
$scope.currentFormName = $scope.selectedDepartment.currentStudentFormName.name;
} else if ($scope.formType == 1 && $scope.selectedDepartment.currentEmployerFormName) {
$scope.currentFormName = $scope.selectedDepartment.currentEmployerFormName.name;
} else {
$scope.currentFormName = 'None';
}
}
});
// When the selected form type changes, use the appropriate list of forms
$scope.$watch('formType', function () {
if ($scope.formType == 0) {
$scope.forms = $scope.studentForms;
} else {
$scope.forms = $scope.employerForms;
}
});
/**
* Assigns the selected form to the selected department for the given term.
*/
$scope.assignForm = function () {
// If the user has not yet selected a term and/or form, display
// an error message and cancel the assignment
if ((!$scope.selectedTerm) || (!$scope.selectedForm)) {
$rootScope.message = {
type: 'danger',
content: 'You must select a semester and form before assigning a form to a department.',
location: $location.path()
};
return;
}
// Compile the data selected in the UI to be sent to the back-end
$scope.form = {
isStudentForm: $scope.formType == 0 ? '1' : '0',
department: $scope.selectedDepartment,
termCode: $scope.selectedTerm,
form: $scope.selectedForm
};
administrationService.assignForm($scope.form)
.success(function (result) {
$rootScope.message = {
type: 'success',
content: 'The form ' + $scope.form.form.name +
' was successfully assigned to the department ' +
$scope.form.department.departmentCode + ' - ' + $scope.form.department.departmentName + '.',
location: $location.path()
};
// Reset the selections in the UI
$scope.selectedTerm = undefined;
$scope.selectedForm = undefined;
$scope.selectedCollege = $scope.colleges[0];
});
};
} |