all files / js/form/ openForm.directive.js

16.67% Statements 2/12
0% Branches 0/4
0% Functions 0/5
16.67% Lines 2/12
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                                                                                           
/**
 * Created by cklimkowsky on 3/16/15.
 */
angular
    .module('coopEval')
    .directive('ceOpenForm', openForm);
 
function openForm() {
    return {
        restrict: 'E',
        scope: {
            formType: '@',
            evaluation: '=',
            form: '=',
            submitted: '='
        },
        link: function (scope, element, attr, ctrl) {
            /**
             * Determines whether a question of the given question type exists in the given question group.
             * @param questionGroup
             * @param questionType
             * @returns {boolean} True if questionGroup contains a question of type questionType, false otherwise.
             */
            scope.questionGroupContainsQuestionType = function (questionGroup, questionType) {
                if (questionGroup) {
                    for (var i = 0; i < questionGroup.questions.length; i++) {
                        if (questionGroup.questions[i].questionType == questionType) {
                            return true;
                        }
                    }
                }
                return false;
            };
 
            /**
             * Filters out any questions in a question group that do not have the specified question type.
             * @param questionType The type of questions that are desired
             * @returns {Function}
             */
            scope.questionTypeFilter = function (questionType) {
                return function (question) {
                    return question.questionType == questionType;
                }
            };
        },
        templateUrl: 'partials/form/open-form.html'
    }
}