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