/**
* 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;
}
}
|