1 | var qUID, parentObjectUID, qName, qTag, qType, qAnswerLength; |
---|
2 | |
---|
3 | function selectAnswerType(){ |
---|
4 | |
---|
5 | var selectBox = document.getElementById("questionType"); |
---|
6 | if (selectBox.value != undefined && selectBox.value != "") { |
---|
7 | qType = selectBox.value; |
---|
8 | } |
---|
9 | else { |
---|
10 | return; |
---|
11 | } |
---|
12 | |
---|
13 | removeWrongAnswerFields(selectBox); |
---|
14 | |
---|
15 | switch (qType) { |
---|
16 | case "int": |
---|
17 | selectIntType(); |
---|
18 | break; |
---|
19 | case "scale": |
---|
20 | selectScaleType(); |
---|
21 | break; |
---|
22 | case "choice": |
---|
23 | //selectChoiceType(); |
---|
24 | break; |
---|
25 | case "text": |
---|
26 | //selectTextType(); |
---|
27 | break; |
---|
28 | default: |
---|
29 | alert("Invalid answer type selected!"); |
---|
30 | break; |
---|
31 | } |
---|
32 | |
---|
33 | } |
---|
34 | |
---|
35 | function createNewElement(tag, type, id, cl, value) { |
---|
36 | var newElement = document.createElement(tag); |
---|
37 | if (type != undefined) newElement.type = type; |
---|
38 | if (id != undefined) newElement.id = id; |
---|
39 | if (cl != undefined) newElement.className = cl; |
---|
40 | if (value != undefined) newElement.value = value; |
---|
41 | return newElement; |
---|
42 | } |
---|
43 | |
---|
44 | function removeWrongAnswerFields(el) { |
---|
45 | while (el.nextSibling) { |
---|
46 | el.parentNode.removeChild(el.nextSibling); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | function selectIntType() { |
---|
54 | var selectBox = document.getElementById("questionType"); |
---|
55 | var content = document.getElementById("questionEditor_questionParams"); |
---|
56 | var minValueBox = createNewElement("input","text","minValueBox", "questionParamField", null); |
---|
57 | content.innerHTML += "<br />Min value: "; |
---|
58 | content.appendChild(minValueBox); |
---|
59 | var maxValueBox = createNewElement("input", "text", "maxValueBox", "questionParamField", null); |
---|
60 | content.innerHTML += "<br />Max value: "; |
---|
61 | content.appendChild(maxValueBox); |
---|
62 | |
---|
63 | // set the selected value, because adding a DOM element to the parent element resets the selected value. |
---|
64 | for (var i = 0; i < selectBox.options.length; i++) { |
---|
65 | if (selectBox.options[i].value == "int") { |
---|
66 | selectBox.selectedValue = i; |
---|
67 | selectBox.selectedText = "Integer"; |
---|
68 | // DIT WERKT NOG NIET, HIJ SELECTEERT HEM NIET, OOK AL IS SELECTED = TRUE |
---|
69 | // MET ANDERE WOORDEN: WTF. |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | function selectScaleType() { |
---|
77 | debugger; |
---|
78 | var selectBox = document.getElementById("questionType"); |
---|
79 | var content = document.getElementById("questionEditor_questionParams"); |
---|
80 | var numChoicesBox = createNewElement("select", null, "numChoicesBox","questionParamField",null); |
---|
81 | content.innerHTML += "<br />Scale size: "; |
---|
82 | for (var i = 0; i < 10; i++) { |
---|
83 | var option = createNewElement("option"); |
---|
84 | option.text = i+1; |
---|
85 | option.value = i+1; |
---|
86 | numChoicesBox.appendChild(option); |
---|
87 | } |
---|
88 | content.appendChild(numChoicesBox); |
---|
89 | numChoicesBox.addEventListener("change", selectScaleSize, false); |
---|
90 | } |
---|
91 | |
---|
92 | function selectScaleSize() { |
---|
93 | var numChoicesBox = document.getElementById("numChoicesBox"); |
---|
94 | var content = document.getElementById("questionEditor_questionParams"); |
---|
95 | for (var i = 0; i < numChoicesBox.value; i++) { |
---|
96 | var newBullet = createNewElement("input", "radio", "bullet"+i, "questionParamField","i"); |
---|
97 | content.appendChild(newBullet); |
---|
98 | } |
---|
99 | |
---|
100 | } |
---|
101 | |
---|