Implement MCQ
This commit is contained in:
parent
7267af8513
commit
00f196bac3
4 changed files with 221 additions and 4 deletions
|
@ -50,6 +50,11 @@ angular.module("AtsebaytApp")
|
|||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("QuestProposal", function($resource) {
|
||||
return $resource("/api/surveys/:surveyId/questions/:questId/proposals", { surveyId: '@id', questId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("User", function($resource) {
|
||||
return $resource("/api/users/:userId", { userId: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
|
@ -314,8 +319,14 @@ angular.module("AtsebaytApp")
|
|||
responses.forEach(function(response) {
|
||||
if (!questions[idxquestions[response.id_question]].response) {
|
||||
if (response.value) {
|
||||
questions[idxquestions[response.id_question]].value = response.value;
|
||||
questions[idxquestions[response.id_question]].response = response;
|
||||
if (questions[idxquestions[response.id_question]].kind == "text") {
|
||||
questions[idxquestions[response.id_question]].value = response.value;
|
||||
} else {
|
||||
response.value.split(",").forEach(function (val) {
|
||||
questions[idxquestions[response.id_question]]["p" + val] = true;
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -326,7 +337,18 @@ angular.module("AtsebaytApp")
|
|||
$scope.submitInProgress = true;
|
||||
var res = [];
|
||||
$scope.questions.forEach(function(q) {
|
||||
res.push({"id_question": q.id, "value": q.value})
|
||||
if (q.kind == "text")
|
||||
res.push({"id_question": q.id, "value": q.value})
|
||||
else {
|
||||
var values = [];
|
||||
Object.keys(q).forEach(function (k) {
|
||||
if (r = k.match(/^p([0-9]+)$/)) {
|
||||
if (q[k])
|
||||
values.push(r[1])
|
||||
}
|
||||
})
|
||||
res.push({"id_question": q.id, "value": values.join(",")})
|
||||
}
|
||||
});
|
||||
$http({
|
||||
url: "/api/surveys/" + $scope.survey.id,
|
||||
|
@ -376,3 +398,29 @@ angular.module("AtsebaytApp")
|
|||
}
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ProposalsController", function($scope, QuestProposal) {
|
||||
$scope.proposals = QuestProposal.query({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
|
||||
$scope.saveProposal = function() {
|
||||
if (this.proposal.id) {
|
||||
this.proposal.$update({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
} else {
|
||||
this.proposal.$save({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
}
|
||||
}
|
||||
|
||||
$scope.addProposal = function() {
|
||||
$scope.proposals.push(new QuestProposal({}))
|
||||
}
|
||||
|
||||
$scope.deleteProposal = function() {
|
||||
if (this.proposal.id) {
|
||||
this.proposal.$remove(function() {
|
||||
$scope.proposals = QuestProposal.query({ surveyId: $scope.survey.id, questId: $scope.question.id });
|
||||
});
|
||||
} else {
|
||||
$scope.proposals.splice($scope.proposals.indexOf(this.proposal), 1);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Reference in a new issue