all files / js/department/ viewEvaluations.controller.js

4.17% Statements 2/48
0% Branches 0/18
0% Functions 0/7
4.17% Lines 2/48
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                                                                                                                                                                                                                           
/**
 * Created by cklimkowsky on 4/22/15.
 */
angular
    .module('coopEval')
    .controller('ViewEvaluationsController', ViewEvaluationsController);
 
function ViewEvaluationsController($scope, $stateParams, $rootScope, $location, formService) {
 
    // Indicates the current view mode on the View Evaluations page
    $scope.currentEvaluationsView = 'Both';
 
    // Get the student work report and employer evaluation for a particular placement
    if ($stateParams.placementId) {
        formService.getStudentWorkReport($stateParams.placementId)
            .success(function (result) {
                $scope.studentEvaluation = result;
 
                for (var i = 0; i < $scope.studentEvaluation.questionGroups.length; i++) {
                    for (var j = 0; j < $scope.studentEvaluation.questionGroups[i].questions.length; j++) {
                        $scope.studentEvaluation.questionGroups[i].questions[j].isCommentAllowed = parseInt($scope.studentEvaluation.questionGroups[i].questions[j].isCommentAllowed);
                        $scope.studentEvaluation.questionGroups[i].questions[j].isRequired = parseInt($scope.studentEvaluation.questionGroups[i].questions[j].isRequired);
 
                        if ($scope.studentEvaluation.questionGroups[i].questions[j].questionType == 'Numeric') {
                            if ($scope.studentEvaluation.questionGroups[i].questions[j].answer) {
                                $scope.studentEvaluation.questionGroups[i].questions[j].answer = parseFloat($scope.studentEvaluation.questionGroups[i].questions[j].answer);
                            }
                        } else if ($scope.studentEvaluation.questionGroups[i].questions[j].questionType == 'DoubleLikert') {
                            if ($scope.studentEvaluation.questionGroups[i].questions[j].answer) {
                                var answers = $scope.studentEvaluation.questionGroups[i].questions[j].answer.split(',');
                                $scope.studentEvaluation.questionGroups[i].questions[j].answer = answers[0];
                                $scope.studentEvaluation.questionGroups[i].questions[j].answer2 = answers[1];
                                $scope.studentEvaluation.questionGroups[i].questions[j].answer3 = answers[2];
                            } else {
                                $scope.studentEvaluation.questionGroups[i].questions[j].answer = null;
                                $scope.studentEvaluation.questionGroups[i].questions[j].answer2 = null;
                                $scope.studentEvaluation.questionGroups[i].questions[j].answer3 = false;
                            }
                        }
                    }
                }
            });
        formService.getEmployerEvaluation($stateParams.placementId)
            .success(function (result) {
                $scope.employerEvaluation = result;
 
                for (var i = 0; i < $scope.employerEvaluation.questionGroups.length; i++) {
                    for (var j = 0; j < $scope.employerEvaluation.questionGroups[i].questions.length; j++) {
                        $scope.employerEvaluation.questionGroups[i].questions[j].isCommentAllowed = parseInt($scope.employerEvaluation.questionGroups[i].questions[j].isCommentAllowed);
                        $scope.employerEvaluation.questionGroups[i].questions[j].isRequired = parseInt($scope.employerEvaluation.questionGroups[i].questions[j].isRequired);
 
                        if ($scope.employerEvaluation.questionGroups[i].questions[j].questionType == 'Numeric') {
                            if ($scope.employerEvaluation.questionGroups[i].questions[j].answer) {
                                $scope.employerEvaluation.questionGroups[i].questions[j].answer = parseFloat($scope.employerEvaluation.questionGroups[i].questions[j].answer);
                            }
                        } else if ($scope.employerEvaluation.questionGroups[i].questions[j].questionType == 'DoubleLikert') {
                            if ($scope.employerEvaluation.questionGroups[i].questions[j].answer) {
                                var answers = $scope.employerEvaluation.questionGroups[i].questions[j].answer.split(',');
                                $scope.employerEvaluation.questionGroups[i].questions[j].answer = answers[0];
                                $scope.employerEvaluation.questionGroups[i].questions[j].answer2 = answers[1];
                                $scope.employerEvaluation.questionGroups[i].questions[j].answer3 = answers[2];
                            } else {
                                $scope.employerEvaluation.questionGroups[i].questions[j].answer = null;
                                $scope.employerEvaluation.questionGroups[i].questions[j].answer2 = null;
                                $scope.employerEvaluation.questionGroups[i].questions[j].answer3 = false;
                            }
                        }
                    }
                }
            });
    }
 
    /**
     * Approves the current student evaluation.
     */
    $scope.approveEvaluation = function () {
        formService.approveEvaluation($scope.studentEvaluation)
            .success(function (result) {
                $rootScope.message = {
                    type: 'success',
                    content: '<strong>Evaluation for ' +
                    $scope.studentEvaluation.studentFirstName + ' ' +
                    $scope.studentEvaluation.studentLastName + ', term ' +
                    $scope.studentEvaluation.termCode + ' was successfully approved.</strong><br>' +
                    'An email was successfully sent to the student informing them of this approval.',
                    location: $location.path()
                };
                $scope.studentEvaluation.evaluationApproval.approvalStatus = 'Approved';
            });
    };
 
    /**
     * Rejects the current student evaluation.
     */
    $scope.rejectEvaluation = function () {
        formService.rejectEvaluation($scope.studentEvaluation)
            .success(function (result) {
                $rootScope.message = {
                    type: 'danger',
                    content: '<strong>Evaluation for ' +
                    $scope.studentEvaluation.studentFirstName + ' ' +
                    $scope.studentEvaluation.studentLastName + ', term ' +
                    $scope.studentEvaluation.termCode + ' was rejected.</strong><br>' +
                    'An email was successfully sent to the student informing them of this rejection, ' +
                    'requesting they update their work report for re-evaluation.',
                    location: $location.path()
                };
                $scope.studentEvaluation.evaluationApproval.approvalStatus = 'Rejected';
            });
    };
}