-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathQuestionSet.js
More file actions
75 lines (61 loc) · 2.59 KB
/
Copy pathQuestionSet.js
File metadata and controls
75 lines (61 loc) · 2.59 KB
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
69
70
71
72
73
74
75
define(['knockout', 'services/Validation', './QuestionSetForm'], function (ko, ValidationService, QuestionSetForm) {
function QuestionSet(id, cohortName, qSetId, qSetName, qSetQuestions, mode) {
const self = this;
self.qsetName = ko.observable(qSetName);
self.setId = ko.observable(qSetId);
self.setQuestions = ko.observableArray(qSetQuestions);
self.mode = ko.observable(mode);
self.questionItems = ko.observableArray([]);
self.questionSetForm = new QuestionSetForm(id, cohortName);
self.goBack = function (parent) {
setTimeout(() => {
parent.valTabMode(parent.default_view);
// if you don't do this, ko complains.
}, 1000);
};
self.resetValues = function (id, cohortName, qSetId, qSetName, qSetQuestions, mode) {
self.qsetName(qSetName);
self.setId(qSetId);
self.setQuestions(qSetQuestions);
self.mode(mode);
self.showSelectedQset();
};
self.submitQsetForm = function (sn) {
return self.questionSetForm.createQuestionSet(sn);
};
self.initialize = function () {
self.questionSetForm.initialize();
};
self.showSelectedQset = function () {
self.questionItems([]);
for (let i = 0; i < self.setQuestions().length; i++) {
let qs = {};
let qsAnswers = [];
let cq = self.setQuestions()[i];
let qnum = "Question " + (i + 1) + ': ';
if (cq !== undefined) {
qs['text'] = qnum + cq.text;
qs['type'] = 'Question Type: ' + cq.type;
qs['caseQ'] = 'Case Question: ' + cq.caseQuestion;
qs['req'] = 'Required: ' + cq.required;
for (let j = 0; j < cq.answers.length; j++) {
if (cq.type !== 'TEXTAREA') {
qsAnswers.push(cq.answers[j].text);
} else {
qsAnswers.push("None");
}
}
} else {
qs['text'] = qnum + '';
qs['type'] = 'Question Type: ' + '';
qs['caseQ'] = 'Case Question: ' + '';
qs['req'] = 'Required: ' + '';
}
qs['answers'] = qsAnswers;
self.questionItems.push(qs);
}
};
}
QuestionSet.prototype.constructor = QuestionSet;
return QuestionSet;
});