all files / js/administration/ addQuestionModal.controller.js

6.67% Statements 2/30
0% Branches 0/25
0% Functions 0/7
6.67% Lines 2/30
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                                                                                                                                                                                     
/**
 * Created by cklimkowsky on 4/15/15.
 */
angular
    .module('coopEval')
    .controller('AddQuestionModalController', AddQuestionModalController);
 
function AddQuestionModalController($scope, $uibModalInstance, questionGroups, administrationService) {
 
    $scope.questionGroups = questionGroups;
 
    // Get the empty question object to be populated by the user's input
    administrationService.getEmptyQuestion()
        .success(function (result) {
            $scope.question = result;
        });
 
    // Get the list of all possible question categories
    administrationService.getAllQuestionCategories()
        .success(function (result) {
            $scope.questionCategories = result;
        });
 
    // Get the list of all possible question types
    administrationService.getAllQuestionTypes()
        .success(function (result) {
            $scope.questionTypes = result;
        });
 
    // Create the new question
    $scope.save = function () {
        if (!$scope.question.questionType || !$scope.question.questionGroup ||
            !$scope.question.text || !$scope.question.category)
        {
            $scope.errorMessage = 'Please enter or choose a value for all inputs.';
            return;
        }
 
        $scope.question.questionGroupOrder = $scope.question.questionGroup.questionGroupOrder;
 
        if ($scope.question.questionGroup.likertScale2) {
            // Only Double Likert questions can be added to a question group containing Double Likert questions
            switch ($scope.question.questionType) {
                case 'Text':
                case 'Paragraph':
                case 'Date':
                case 'Numeric':
                case 'Email':
                case 'Likert':
                case 'YesNo':
                    $scope.errorMessage = 'A question of that type can\'t be added to ' +
                        $scope.question.questionGroup.name + '.';
                    return;
            }
        }
        else if ($scope.question.questionGroup.likertScale1) {
            // Only Likert and Yes/No questions can be added to a question group containing Likert questions
            switch ($scope.question.questionType) {
                case 'Text':
                case 'Paragraph':
                case 'Date':
                case 'Numeric':
                case 'Email':
                case 'DoubleLikert':
                    $scope.errorMessage = 'A question of that type can\'t be added to ' +
                        $scope.question.questionGroup.name + '.';
                    return;
            }
        } else {
            // Likert and Double Likert questions can't be added to a question group not containing the same type
            switch ($scope.question.questionType) {
                case 'Likert':
                case 'DoubleLikert':
                    $scope.errorMessage = 'A question of that type can\'t be added to ' +
                        $scope.question.questionGroup.name + '.';
                    return;
            }
        }
 
      $uibModalInstance.close($scope.question);
    };
 
    // Cancel the creation of the new question
    $scope.cancel = function () {
      $uibModalInstance.dismiss();
    };
 
    // Clear the error message, if there is one
    $scope.closeAlert = function () {
        $scope.errorMessage = null;
    }
}