all files / js/search/ search.controller.js

3.7% Statements 2/54
0% Branches 0/10
0% Functions 0/13
3.7% Lines 2/54
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157                                                                                                                                                                                                                                                                                                                     
/**
 * 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');
        }
    };
}