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

Last change on this file since 230 was 230, checked in by jkraaijeveld, 13 years ago

Made most functionality from the demo branch work with new database.

File size: 6.5 KB
Line 
1//////////////////////
2/* HELPER FUNCTIONS */
3//////////////////////
4
5function hasClass(ele,cls) {
6    if (ele.className)
7        return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
8}
9 
10function addClass(ele,cls) {
11    if (!this.hasClass(ele,cls)) ele.className += " "+cls;
12}
13 
14function removeClass(ele,cls) {
15    if (hasClass(ele,cls)) {
16        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
17        ele.className=ele.className.replace(reg,' ');
18    }
19}
20
21//////////////////////////
22/* END HELPER FUNCTIONS */
23//////////////////////////
24
25
26var qUID, parentObjectUID, qName, qTag, qType, qAnswerLength;
27
28function selectAnswerType(){
29    var selectBox = document.getElementById("questionType");
30    if (selectBox.value != undefined && selectBox.value != "") {
31        qType = selectBox.value;
32    }
33    else {
34        return;
35    }
36    removeWrongAnswerFields(selectBox);
37    switch (qType) {
38        case "int":
39            selectIntType();
40            break;
41        case "scale":
42            selectScaleType();
43            break;
44        case "choice":
45            //selectChoiceType();
46            break;
47        case "text":
48            //selectTextType();
49            break;
50        default:
51            alert("Invalid answer type selected!");
52            break;
53    }
54   
55}
56
57function createNewElement(tag, type, id, cl, value) {
58    var newElement = document.createElement(tag);
59    if (type != undefined) newElement.type = type;
60    if (id != undefined) newElement.id = id;
61    if (cl != undefined) newElement.className = cl;
62    if (value != undefined) {
63        newElement.value = value;
64        newElement.text = value;
65    }
66    return newElement;
67}
68
69function createNewInputLabel(text, target) {
70    var newLabel = document.createElement("label");
71    if (target) newLabel.setAttribute("for",target);
72    newLabel.innerHTML = text;
73    return newLabel;
74}
75
76function removeWrongAnswerFields(el) {
77    while (el.nextSibling) {
78        el.parentNode.removeChild(el.nextSibling);
79    }
80}
81
82function updateIdentifier() {
83    var identField = document.getElementById("questionIdentifierField");
84    if (identField.value == undefined && identField.value == "") {
85        return;
86    }
87    var headerField = document.getElementById("header_identifier");
88    headerField.innerHTML = identField.value;
89}
90
91
92///////////////////
93/* INT SELECTION */
94///////////////////
95
96function selectIntType() {
97    var selectBox = document.getElementById("questionType");
98    var content = document.getElementById("questionEditor_questionParams");
99    // Add minimum value input
100    var minValueBox = createNewElement("input","text","minValueBox", "questionParamField", null);
101    var minValueBoxLabel = createNewInputLabel("Minimum value:", "minValueBox");
102    addClass(minValueBoxLabel, "formLineBreak");
103    content.appendChild(minValueBoxLabel);
104    content.appendChild(minValueBox);
105    // Add maximum value input
106    var maxValueBox = createNewElement("input", "text", "maxValueBox", "questionParamField", null);
107    var maxValueBoxLabel = createNewInputLabel("Maximum value:","maxValueBox");
108    addClass(maxValueBoxLabel, "formLineBreak");
109    content.appendChild(maxValueBoxLabel);
110    content.appendChild(maxValueBox);
111}
112
113/////////////////////
114/* SCALE SELECTION */
115/////////////////////
116
117function selectScaleType() {
118    // I heard you like walls of text!
119    var content = document.getElementById("questionEditor_questionParams");
120    // Add number of choices input
121    var numChoicesBox = createNewElement("select", null, "numChoicesBox","questionParamField",null);
122    var numChoicesBoxLabel = createNewInputLabel("Scale size:","numChoicesBox");
123    for (var i = 0; i < 10; i++) {
124        var option = createNewElement("option");
125        option.text = i+1;
126        option.value = i+1;
127        numChoicesBox.appendChild(option);
128    }
129    addClass(numChoicesBoxLabel, "formLineBreak");
130    content.appendChild(numChoicesBoxLabel);
131    content.appendChild(numChoicesBox);
132    // Add legends enabled input
133    var legendsEnabledCheckBox = createNewElement("input","checkbox","legendsEnabledCheckbox","questionParamField",null);
134    var legendsEnabledCheckBoxLabel = createNewInputLabel("Enable legends","legendsEnabledCheckBox");
135    addClass(legendsEnabledCheckBoxLabel, "formLineBreak");
136    content.appendChild(legendsEnabledCheckBoxLabel);
137    content.appendChild(legendsEnabledCheckBox);
138    // Add legend labels boxes
139    var upperLegendBox = createNewElement("input","text","upperLegendBox","questionParamField");
140    var lowerLegendBox = createNewElement("input","text","lowerLegendBox","questionParamField");
141    var lowerLegendBoxLabel = createNewInputLabel("Lower legend","lowerLegendBox");
142    var upperLegendBoxLabel = createNewInputLabel("Upper legend","upperLegendBox");
143    addClass(lowerLegendBoxLabel,"formLineBreak");
144    content.appendChild(lowerLegendBoxLabel);
145    content.appendChild(lowerLegendBox);
146    addClass(upperLegendBoxLabel,"formLineBreak");
147    content.appendChild(upperLegendBoxLabel);
148    content.appendChild(upperLegendBox);
149    // Disable these boxes, since the checkbox is unchecked by default
150    lowerLegendBox.disabled = true;
151    upperLegendBox.disabled = true;
152    if (legendsEnabledCheckBox.addEventListener) {
153        legendsEnabledCheckBox.addEventListener("click", toggleScaleLegends, true);
154    }
155}
156
157function toggleScaleLegends() {
158    var content = document.getElementById("questionEditor_questionParams");
159    var checkbox = document.getElementById("legendsEnabledCheckbox");
160    var upperLegendBox = document.getElementById("upperLegendBox");
161    var lowerLegendBox = document.getElementById("lowerLegendBox");
162    if (checkbox.checked == true) {
163        upperLegendBox.disabled = false;
164        lowerLegendBox.disabled = false;
165    }
166    else {
167        upperLegendBox.disabled = true;
168        lowerLegendBox.disabled = true;
169    }
170}
171
172///////////////////////////////
173/* MULTIPLE CHOICE SELECTION */
174///////////////////////////////
175
176function selectChoiceType() {
177    var selectionBox = document.getElementById("questionType");
178    var content = document.getElementById("questionEditor_questionParams");
179}
180
181function resizeTextArea() {
182    var textArea = document.getElementById("questionEditor_bodyText");
183    if (document.getElementById("hiddenScalingDiv")) {
184        var hiddenDiv = document.getElementById("hiddenScalingDiv");
185    }
186    else {
187        var hiddenDiv = document.createElement("div");
188        hiddenDiv.style.visibility = "hidden";
189        textArea.appendChild(hiddenDiv);
190    }
191   
192    debugger;
193    hiddenDiv.innerHTML = "";
194    var userText = textArea.firstChild;
195    alert(userText);
196}
Note: See TracBrowser for help on using the repository browser.