source: Dev/trunk/js/questionEditorScripts.js @ 175

Last change on this file since 175 was 175, checked in by fpvanagthoven, 13 years ago
  • questionEditor toegevoegd, DB-loos opzetje voor de interface daarvan.
  • editorScripts.js is niet meer nodig, alle functies staan al in sequencerScripts.js (Ik maak later nog wel een weloverwogen centrale .js file met alle gedeelde functies (hopelijk met een aantal scripts uit sequencerScripts wat meer gegeneraliseerd en breed toepasbaar!)
  • Wat aanpassingen in awesome.css voor de questionEditor
File size: 3.1 KB
Line 
1var qUID, parentObjectUID, qName, qTag, qType, qAnswerLength;
2
3function 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
35function 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
44function removeWrongAnswerFields(el) {
45    while (el.nextSibling) {
46        el.parentNode.removeChild(el.nextSibling);
47    }
48}
49
50
51
52
53function 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
76function 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
92function 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
Note: See TracBrowser for help on using the repository browser.