all files / js/administration/ addQuestionGroupModal.controller.js

9.52% Statements 2/21
0% Branches 0/5
0% Functions 0/5
9.52% Lines 2/21
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                                                                                                                                   
/**
 * Created by cklimkowsky on 4/15/15.
 */
angular
    .module('coopEval')
    .controller('AddQuestionGroupModalController', AddQuestionGroupModalController);
 
function AddQuestionGroupModalController($scope, $modalInstance, questionGroups, administrationService) {
 
    $scope.questionGroups = questionGroups;
 
    // Define the list of positions at which the new question group can be inserted
    $scope.positions = [
        {
            position: 'At beginning',
            index: 0
        }
    ];
 
    // Create the list of available positions from the list of question groups
    for (var i = 0; i < $scope.questionGroups.length; i++) {
        $scope.positions.push(
            {
                position: 'After ' + $scope.questionGroups[i].name,
                index: i + 1
            }
        );
    }
 
    // Define the potential types of question groups
    $scope.likertQuestionTypes = [
        'None',
        'Likert',
        'Double Likert'
    ];
 
    $scope.selectedLikertQuestionType = $scope.likertQuestionTypes[0];
 
    // Get the empty question group object to be populated by the user's input
    administrationService.getEmptyQuestionGroup()
        .success(function (result) {
            result.questions = [];
            $scope.questionGroup = result;
        });
 
    // Create the new question group
    $scope.save = function () {
        if (!$scope.questionGroup.name || !$scope.questionGroup.content || !$scope.questionGroup.questionGroupOrder)
        {
            $scope.errorMessage = 'Please enter or choose a value for all inputs.';
            return;
        }
 
        $scope.questionGroup.questionGroupOrder = $scope.questionGroup.questionGroupOrder.index;
        $modalInstance.close($scope.questionGroup);
    };
 
    // Cancel the creation of the new question group
    $scope.cancel = function () {
        $modalInstance.dismiss();
    };
 
    // Clear the error message, if there is one
    $scope.closeAlert = function () {
        $scope.errorMessage = null;
    }
}