/**
* Created by cklimkowsky on 2/27/15.
*/
angular
.module('coopEval')
.controller('SearchController', SearchController);
function SearchController($scope, $rootScope, $location, searchService) {
// Reset the search criteria for the next search
searchService.getSearchCriteria()
.success(function (result) {
$rootScope.searchCriteria = result;
});
// Maintain separate arrays of which departments and terms are selected in the UI
$scope.selectedDepartments = [];
$scope.selectedTerms = [];
// List of all possible student evaluation approval statuses, and an indication of whether or not each one is selected in the UI
$scope.evaluationApprovalStatuses = {
'Approved': false,
'Pending Approval': false,
'Rejected': false
};
// List of all possible employer evaluation statuses, and an indication of whether or not each one is selected in the UI
$scope.employerEvaluationStatuses = {
'Submitted': false,
'Saved': false,
'Open': false,
'Pending': false,
'Manually Completed': false,
'Archived': false
};
/**
* Selects all terms in the list of selectable terms.
*/
$scope.selectAllTerms = function () {
$scope.selectedTerms.splice(0, $scope.selectedTerms.length);
for (var i = 0; i < $scope.searchCriteria.terms.length; i++) {
$scope.selectedTerms.push($scope.searchCriteria.terms[i]);
}
};
/**
* Deselects all terms in the list of selectable terms.
*/
$scope.deselectAllTerms = function () {
$scope.selectedTerms.splice(0, $scope.selectedTerms.length);
};
/**
* Selects all departments in the list of selectable departments.
*/
$scope.selectAllDepartments = function () {
$scope.selectedDepartments.splice(0, $scope.selectedDepartments.length);
for (var i = 0; i < $scope.searchCriteria.departments.length; i++) {
$scope.selectedDepartments.push($scope.searchCriteria.departments[i]);
}
};
/**
* Deselects all departments in the list of selectable departments.
*/
$scope.deselectAllDepartments = function () {
$scope.selectedDepartments.splice(0, $scope.selectedDepartments.length);
};
/**
* Selects or deselects all student evaluation statuses at once.
*/
$scope.selectAllStudentProgressStatuses = function () {
var newValue = !$scope.allStudentProgressStatusesSelected();
for (var i = 0; i < $scope.searchCriteria.studentEvalStatusList.length; i++) {
$scope.searchCriteria.studentEvalStatusList[i].selected = newValue;
}
};
/**
* Determines whether all student evaluation statuses are selected.
* @returns {boolean} True if all statuses are selected, false otherwise.
*/
$scope.allStudentProgressStatusesSelected = function () {
for (var i = 0; i < $scope.searchCriteria.studentEvalStatusList.length; i++) {
if ($scope.searchCriteria.studentEvalStatusList[i].selected == false) {
return false;
}
}
return true;
};
/**
* Selects or deselects all evaluation approval statuses at once.
*/
$scope.selectAllEvaluationApprovalStatuses = function () {
var newValue = !$scope.allEvaluationApprovalStatusesSelected();
for (var i = 0; i < $scope.searchCriteria.approvalStatusList.length; i++) {
$scope.searchCriteria.approvalStatusList[i].selected = newValue;
}
};
/**
* Determines whether all evaluation approval statuses are selected.
* @returns {boolean} True if all statuses are selected, false otherwise.
*/
$scope.allEvaluationApprovalStatusesSelected = function () {
for (var i = 0; i < $scope.searchCriteria.approvalStatusList.length; i++) {
if ($scope.searchCriteria.approvalStatusList[i].selected == false) {
return false;
}
}
return true;
};
/**
* Selects or deselects all employer evaluation statuses at once.
*/
$scope.selectAllEmployerEvaluationStatuses = function () {
var newValue = !$scope.allEmployerEvaluationStatusesSelected();
for (var i = 0; i < $scope.searchCriteria.employerEvalStatusList.length; i++) {
$scope.searchCriteria.employerEvalStatusList[i].selected = newValue;
}
};
/**
* Determines whether all employer evaluation statuses are selected.
* @returns {boolean} True if all statuses are selected, false otherwise.
*/
$scope.allEmployerEvaluationStatusesSelected = function () {
for (var i = 0; i < $scope.searchCriteria.employerEvalStatusList.length; i++) {
if ($scope.searchCriteria.employerEvalStatusList[i].selected == false) {
return false;
}
}
return true;
};
/**
* Redirects to the Search Results page, where the search criteria entered by the user is submitted.
*/
$scope.search = function () {
// Attach the selected terms and departments to the search criteria
$rootScope.searchCriteria.terms = $scope.selectedTerms;
$rootScope.searchCriteria.departments = $scope.selectedDepartments;
if ($rootScope.userType == 'Admin') {
$location.path('/administration/search-results');
} else if ($rootScope.userType== 'Department') {
$location.path('/departments/search-results');
}
};
} |